@coinmasters/helpers
Advanced tools
Comparing version 11.0.25 to 11.0.26
@@ -167,3 +167,3 @@ var be = Object.defineProperty; | ||
"gmi" | ||
), Be = (r) => { | ||
), Me = (r) => { | ||
const [e, t] = r.split("."); | ||
@@ -176,4 +176,4 @@ if (!Ae.includes(e)) | ||
const t = `${e.chain}.${e.symbol}`; | ||
return !Oe.test(t) && Be(t) && e.value !== "0"; | ||
}), Me = ({ | ||
return !Oe.test(t) && Me(t) && e.value !== "0"; | ||
}), Be = ({ | ||
liquidityUnits: r, | ||
@@ -183,3 +183,3 @@ poolUnits: e, | ||
}) => { | ||
const s = p(r), n = p(e), i = p(t), a = s.mul(i), c = n.mul(n).mul(2), u = n.mul(s).mul(2), h = s.mul(s), l = n.mul(n).mul(n); | ||
const s = f(r), n = f(e), i = f(t), a = s.mul(i), c = n.mul(n).mul(2), u = n.mul(s).mul(2), h = s.mul(s), l = n.mul(n).mul(n); | ||
return a.mul(c.sub(u).add(h)).div(l); | ||
@@ -191,4 +191,4 @@ }, ke = ({ | ||
}) => { | ||
const s = p(r), n = p(e), i = p(t), a = s.mul(i), c = n.mul(n).mul(2), u = n.mul(s).mul(2), h = s.mul(s), l = a.mul(c.sub(u).add(h)), f = n.mul(n).mul(n); | ||
return l.div(f); | ||
const s = f(r), n = f(e), i = f(t), a = s.mul(i), c = n.mul(n).mul(2), u = n.mul(s).mul(2), h = s.mul(s), l = a.mul(c.sub(u).add(h)), p = n.mul(n).mul(n); | ||
return l.div(p); | ||
}, ut = ({ | ||
@@ -199,3 +199,3 @@ percent: r, | ||
poolUnits: s | ||
}) => Me({ runeDepth: e, liquidityUnits: t, poolUnits: s }).mul(r), lt = ({ | ||
}) => Be({ runeDepth: e, liquidityUnits: t, poolUnits: s }).mul(r), lt = ({ | ||
percent: r, | ||
@@ -205,3 +205,3 @@ assetDepth: e, | ||
poolUnits: s | ||
}) => ke({ assetDepth: e, liquidityUnits: t, poolUnits: s }).mul(r), p = (r) => y.fromBigInt(BigInt(r), d.THOR), xe = ({ | ||
}) => ke({ assetDepth: e, liquidityUnits: t, poolUnits: s }).mul(r), f = (r) => y.fromBigInt(BigInt(r), d.THOR), xe = ({ | ||
liquidityUnits: r, | ||
@@ -212,4 +212,4 @@ poolUnits: e, | ||
}) => ({ | ||
assetAmount: p(s).mul(r).div(e), | ||
runeAmount: p(t).mul(r).div(e) | ||
assetAmount: f(s).mul(r).div(e), | ||
runeAmount: f(t).mul(r).div(e) | ||
}), ht = ({ | ||
@@ -233,3 +233,3 @@ liquidityUnits: r, | ||
}) => { | ||
const a = new y({ value: r, decimal: 8 }), c = new y({ value: t, decimal: 8 }), u = new y({ value: e, decimal: 8 }), h = new y({ value: n, decimal: 8 }), l = new y({ value: i, decimal: 8 }), f = h.mul(c), g = l.mul(a), A = h.mul(l), R = a.mul(c), fe = u.mul(f.add(g.add(A.mul(2)))), _e = f.add(g.add(R.mul(2))), X = fe.div(_e), D = p(s).add(X); | ||
const a = new y({ value: r, decimal: 8 }), c = new y({ value: t, decimal: 8 }), u = new y({ value: e, decimal: 8 }), h = new y({ value: n, decimal: 8 }), l = new y({ value: i, decimal: 8 }), p = h.mul(c), g = l.mul(a), A = h.mul(l), R = a.mul(c), fe = u.mul(p.add(g.add(A.mul(2)))), _e = p.add(g.add(R.mul(2))), X = fe.div(_e), D = f(s).add(X); | ||
if (X.getBaseValue("number") === 0) | ||
@@ -247,3 +247,3 @@ return D.div(u).getBaseValue("number"); | ||
return 0; | ||
const n = p(t), i = p(s), a = p(e), c = p(r), u = a.mul(n).sub(i.mul(c)), h = i.mul(c).add(n.mul(i)); | ||
const n = f(t), i = f(s), a = f(e), c = f(r), u = a.mul(n).sub(i.mul(c)), h = i.mul(c).add(n.mul(i)); | ||
return Math.abs(u.div(h).getBaseValue("number")); | ||
@@ -697,3 +697,3 @@ }, Ve = ({ | ||
} | ||
var $, E, w, C, j, me, M, G, k, W; | ||
var $, E, w, C, j, me, B, G, k, W; | ||
const Z = class Z { | ||
@@ -704,3 +704,3 @@ constructor(e) { | ||
S(this, j); | ||
S(this, M); | ||
S(this, B); | ||
S(this, k); | ||
@@ -855,3 +855,3 @@ _(this, "decimalMultiplier", 10n ** 8n); | ||
$ = new WeakSet(), E = function(e, ...t) { | ||
const s = m(this, M, G).call(this, this, ...t), n = Math.max(s, I(this.decimalMultiplier)), i = v(n), a = t.reduce( | ||
const s = m(this, B, G).call(this, this, ...t), n = Math.max(s, I(this.decimalMultiplier)), i = v(n), a = t.reduce( | ||
(u, h) => { | ||
@@ -888,3 +888,3 @@ const l = this.getBigIntValue(h, n); | ||
}, w = new WeakSet(), C = function(e, ...t) { | ||
const s = m(this, M, G).call(this, this, ...t), n = this.getBigIntValue(t[0], s), i = this.getBigIntValue(this, s); | ||
const s = m(this, B, G).call(this, this, ...t), n = this.getBigIntValue(t[0], s), i = this.getBigIntValue(this, s); | ||
switch (e) { | ||
@@ -905,3 +905,3 @@ case "gt": | ||
this.bigIntValue = m(this, k, W).call(this, t); | ||
}, M = new WeakSet(), G = function(...e) { | ||
}, B = new WeakSet(), G = function(...e) { | ||
const t = e.map((s) => typeof s == "object" ? s.decimal || I(s.decimalMultiplier) : re(V(s))).filter(Boolean); | ||
@@ -913,3 +913,3 @@ return Math.max(...t, O); | ||
}; | ||
let B = Z; | ||
let M = Z; | ||
const st = Intl.NumberFormat("fullwide", { | ||
@@ -931,3 +931,9 @@ useGrouping: !1, | ||
} | ||
const P = (r, e) => typeof r == "bigint" ? H({ value: r, bigIntDecimal: e, decimal: e }) : r; | ||
function P(r, e) { | ||
try { | ||
return typeof r == "bigint" ? H({ value: r, bigIntDecimal: e, decimal: e }) : r; | ||
} catch (t) { | ||
return console.error("Error in safeValue:", t), 0; | ||
} | ||
} | ||
let z; | ||
@@ -943,3 +949,3 @@ const ne = (r) => { | ||
}; | ||
class T extends B { | ||
class T extends M { | ||
constructor(t) { | ||
@@ -949,3 +955,3 @@ const s = "identifier" in t ? t.identifier : `${t.chain}.${t.symbol}`; | ||
let n; | ||
t.value instanceof B ? n = t.value : n = { decimal: t.decimal, value: t.value }, console.log("value: ", n); | ||
t.value instanceof M ? n = t.value : n = { decimal: t.decimal, value: t.value }, console.log("value: ", n); | ||
super(n); | ||
@@ -1031,7 +1037,7 @@ _(this, "address"); | ||
tax: l, | ||
decimal: f, | ||
decimal: p, | ||
identifier: g | ||
} = ne(t); | ||
console.log("getStaticToken: ", { tax: l, decimal: f, tokenIdentifier: g }); | ||
const A = s === 0 ? BigInt(0) : P(s, f); | ||
console.log("getStaticToken: ", { tax: l, decimal: p, tokenIdentifier: g }), console.log("value: ", s), console.log("decimal: ", p); | ||
const A = P(s, p); | ||
console.log("parsedValue: ", A); | ||
@@ -1041,3 +1047,3 @@ let R; | ||
tax: l, | ||
decimal: f, | ||
decimal: p, | ||
identifier: g, | ||
@@ -1079,4 +1085,4 @@ value: A | ||
z = [i, ...Object.values(a)].reduce( | ||
(u, { tokens: h }) => (h.forEach(({ identifier: l, chain: f, ...g }) => { | ||
const A = "decimals" in g ? g.decimals : d[f]; | ||
(u, { tokens: h }) => (h.forEach(({ identifier: l, chain: p, ...g }) => { | ||
const A = "decimals" in g ? g.decimals : d[p]; | ||
u.set(l, { identifier: l, decimal: A }); | ||
@@ -1193,3 +1199,3 @@ }), u), | ||
} | ||
class y extends B { | ||
class y extends M { | ||
eq(e) { | ||
@@ -1207,3 +1213,3 @@ return this.eqValue(e); | ||
T as AssetValue, | ||
B as BigIntArithmetics, | ||
M as BigIntArithmetics, | ||
et as RequestClient, | ||
@@ -1220,3 +1226,3 @@ pe as SwapKitError, | ||
lt as getAsymmetricAssetWithdrawAmount, | ||
Me as getAsymmetricRuneShare, | ||
Be as getAsymmetricRuneShare, | ||
ut as getAsymmetricRuneWithdrawAmount, | ||
@@ -1223,0 +1229,0 @@ Ie as getCommonAssetInfo, |
@@ -11,5 +11,5 @@ { | ||
"vitest": "0.34.6", | ||
"@internal/config": "2.7.25", | ||
"@coinmasters/types": "4.7.25", | ||
"@coinmasters/tokens": "3.7.25" | ||
"@internal/config": "2.7.26", | ||
"@coinmasters/tokens": "3.7.26", | ||
"@coinmasters/types": "4.7.26" | ||
}, | ||
@@ -20,4 +20,4 @@ "eslintConfig": { | ||
"peerDependencies": { | ||
"@coinmasters/tokens": "3.7.25", | ||
"@coinmasters/types": "4.7.25" | ||
"@coinmasters/tokens": "3.7.26", | ||
"@coinmasters/types": "4.7.26" | ||
}, | ||
@@ -47,3 +47,3 @@ "exports": { | ||
"types": "./dist/index.d.ts", | ||
"version": "11.0.25", | ||
"version": "11.0.26", | ||
"scripts": { | ||
@@ -50,0 +50,0 @@ "build": "vite build", |
@@ -27,7 +27,19 @@ import type { | ||
const safeValue = (value: NumberPrimitives, decimal: number) => | ||
typeof value === 'bigint' | ||
? formatBigIntToSafeValue({ value, bigIntDecimal: decimal, decimal }) | ||
: value; | ||
function safeValue(value: NumberPrimitives, decimal: number) { | ||
try { | ||
if (typeof value === 'bigint') { | ||
return formatBigIntToSafeValue({ value, bigIntDecimal: decimal, decimal }); | ||
} | ||
return value; | ||
} catch (error) { | ||
console.error('Error in safeValue:', error); | ||
return 0; | ||
} | ||
} | ||
// const safeValue = (value: NumberPrimitives, decimal: number) => | ||
// typeof value === 'bigint' | ||
// ? formatBigIntToSafeValue({ value, bigIntDecimal: decimal, decimal }) | ||
// : value; | ||
type AssetValueParams = { decimal: number; value: SwapKitValueType; tax?: TokenTax } & ( | ||
@@ -197,3 +209,5 @@ | { chain: Chain; symbol: string } | ||
console.log('getStaticToken: ', { tax, decimal, tokenIdentifier }); | ||
const parsedValue = value === 0 ? BigInt(0) : safeValue(value, decimal); | ||
console.log('value: ', value); | ||
console.log('decimal: ', decimal); | ||
const parsedValue = safeValue(value, decimal); | ||
console.log('parsedValue: ', parsedValue); | ||
@@ -200,0 +214,0 @@ let asset: AssetValue | undefined; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
239003
4030