@swapkit/helpers
Advanced tools
Comparing version 1.0.0-rc.0 to 1.0.0-rc.1
@@ -231,6 +231,5 @@ import { Chain } from '@swapkit/types'; | ||
export declare const getSymmetricWithdraw: ({ liquidityUnits, poolUnits, runeDepth, assetDepth, percent, }: ShareParams<{ | ||
export declare const getSymmetricPoolShare: ({ liquidityUnits, poolUnits, runeDepth, assetDepth, }: ShareParams<{ | ||
runeDepth: string; | ||
assetDepth: string; | ||
percent: number; | ||
}>) => { | ||
@@ -241,2 +240,10 @@ assetAmount: SwapKitNumber; | ||
export declare const getSymmetricWithdraw: ({ liquidityUnits, poolUnits, runeDepth, assetDepth, percent, }: ShareParams<{ | ||
runeDepth: string; | ||
assetDepth: string; | ||
percent: number; | ||
}>) => { | ||
[k: string]: SwapKitNumber; | ||
}; | ||
export declare const getTHORNameCost: (year: number) => number; | ||
@@ -243,0 +250,0 @@ |
@@ -18,3 +18,3 @@ var rt = Object.defineProperty; | ||
return 10 + n; | ||
}, St = (n) => { | ||
}, Ct = (n) => { | ||
if (n.length > 30) | ||
@@ -24,3 +24,3 @@ return !1; | ||
return !!n.match(t); | ||
}, Ct = ([n, t, e, r, s]) => `${n}'/${t}'/${e}'/${r}${typeof s != "number" ? "" : `/${s}`}`, Tt = async (n, t) => { | ||
}, yt = ([n, t, e, r, s]) => `${n}'/${t}'/${e}'/${r}${typeof s != "number" ? "" : `/${s}`}`, Tt = async (n, t) => { | ||
const e = Object.entries(t || {}).reduce( | ||
@@ -78,3 +78,3 @@ (s, [a, c]) => (c && (s[a] = c), s), | ||
} | ||
}, yt = { | ||
}, Bt = { | ||
[x.Average]: 1.2, | ||
@@ -163,3 +163,3 @@ [x.Fast]: 1.5, | ||
} | ||
}, Bt = (n) => { | ||
}, Mt = (n) => { | ||
var c; | ||
@@ -182,3 +182,3 @@ const [t, ...e] = n.split("."), r = n.includes("/"), s = e.join("."), a = (c = s == null ? void 0 : s.split("-")) == null ? void 0 : c[0]; | ||
return g.div($); | ||
}, Mt = ({ | ||
}, Et = ({ | ||
percent: n, | ||
@@ -188,3 +188,3 @@ runeDepth: t, | ||
poolUnits: r | ||
}) => gt({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(n), Et = ({ | ||
}) => gt({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(n), Ot = ({ | ||
percent: n, | ||
@@ -194,12 +194,21 @@ assetDepth: t, | ||
poolUnits: r | ||
}) => pt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(n), m = (n) => new wt({ value: n, decimal: h.THOR }), Vt = ({ | ||
}) => pt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(n), m = (n) => new bt({ value: n, decimal: h.THOR }), ft = ({ | ||
liquidityUnits: n, | ||
poolUnits: t, | ||
runeDepth: e, | ||
assetDepth: r | ||
}) => ({ | ||
assetAmount: m(r).mul(n).div(t), | ||
runeAmount: m(e).mul(n).div(t) | ||
}), Vt = ({ | ||
liquidityUnits: n, | ||
poolUnits: t, | ||
runeDepth: e, | ||
assetDepth: r, | ||
percent: s | ||
}) => ({ | ||
assetAmount: m(r).mul(n).div(t).mul(s), | ||
runeAmount: m(e).mul(n).div(t).mul(s) | ||
}), Ot = ({ | ||
}) => Object.fromEntries( | ||
Object.entries(ft({ liquidityUnits: n, poolUnits: t, runeDepth: e, assetDepth: r })).map( | ||
([a, c]) => [a, c.mul(s)] | ||
) | ||
), Nt = ({ | ||
runeDepth: n, | ||
@@ -212,3 +221,3 @@ poolUnits: t, | ||
}) => { | ||
const c = m(n), o = m(e), l = m(t), u = m(s), g = m(a), $ = u.mul(o), S = g.mul(c), D = u.mul(g), K = c.mul(o), tt = l.mul($.add(S.add(D.mul(2)))), et = $.add(S.add(K.mul(2))), G = tt.div(et), H = m(r).add(G); | ||
const c = m(n), o = m(e), l = m(t), u = m(s), g = m(a), $ = u.mul(o), v = g.mul(c), D = u.mul(g), K = c.mul(o), tt = l.mul($.add(v.add(D.mul(2)))), et = $.add(v.add(K.mul(2))), G = tt.div(et), H = m(r).add(G); | ||
if (G.baseValueNumber === 0) | ||
@@ -218,3 +227,3 @@ return H.div(l).baseValueNumber; | ||
return H.div(nt).baseValueNumber; | ||
}, Nt = ({ | ||
}, Rt = ({ | ||
runeAmount: n, | ||
@@ -227,7 +236,7 @@ assetAmount: t, | ||
return Math.abs(l.div(u).baseValueNumber); | ||
}, ft = ({ | ||
}, At = ({ | ||
symbol: n, | ||
ticker: t, | ||
chain: e | ||
}) => e === "ETH" && t !== "ETH" ? `${t}-${n.slice(-3)}` : n, Rt = (n, t) => { | ||
}) => e === "ETH" && t !== "ETH" ? `${t}-${n.slice(-3)}` : n, kt = (n, t) => { | ||
switch (n) { | ||
@@ -252,3 +261,3 @@ case f.LEAVE: | ||
case f.WITHDRAW: { | ||
const { chain: e, ticker: r, symbol: s, basisPoints: a, targetAssetString: c, singleSide: o } = t, l = !o && c ? `:${c}` : "", u = ft({ chain: e, symbol: s, ticker: r }); | ||
const { chain: e, ticker: r, symbol: s, basisPoints: a, targetAssetString: c, singleSide: o } = t, l = !o && c ? `:${c}` : "", u = At({ chain: e, symbol: s, ticker: r }); | ||
return `${n}:${e}${o ? "/" : "."}${u}:${a}${l}`; | ||
@@ -279,3 +288,3 @@ } | ||
); | ||
}, W = Object.values(i), At = (n = "") => { | ||
}, W = Object.values(i), $t = (n = "") => { | ||
const t = n.toUpperCase(), [e] = t.split("."); | ||
@@ -290,4 +299,4 @@ if (W.includes(e)) | ||
); | ||
}, I = (n) => 10n ** BigInt(n), C = (n) => Math.log10(parseFloat(n.toString())); | ||
var w, T, R, J, k, Q, V, P, b, y, O, q, v, N; | ||
}, S = (n) => 10n ** BigInt(n), C = (n) => Math.log10(parseFloat(n.toString())); | ||
var w, y, R, J, k, Q, O, L, b, T, V, j, I, N; | ||
const M = class M { | ||
@@ -298,6 +307,6 @@ constructor(t) { | ||
p(this, k); | ||
p(this, O); | ||
p(this, b); | ||
p(this, V); | ||
p(this, b); | ||
p(this, O); | ||
p(this, v); | ||
p(this, I); | ||
_(this, "decimalMultiplier", 10n ** 8n); | ||
@@ -307,4 +316,4 @@ _(this, "bigIntValue", 0n); | ||
const e = typeof t == "object", r = e ? t.value : t; | ||
this.decimal = e ? t.decimal : void 0, this.decimalMultiplier = I( | ||
Math.max(d(this, O, q).call(this, d(this, b, y).call(this, r)), this.decimal || 0) | ||
this.decimal = e ? t.decimal : void 0, this.decimalMultiplier = S( | ||
Math.max(d(this, V, j).call(this, d(this, b, T).call(this, r)), this.decimal || 0) | ||
), d(this, R, J).call(this, r); | ||
@@ -324,3 +333,3 @@ } | ||
return M.fromBigInt( | ||
new M(t).bigIntValue * I(r) / I(e), | ||
new M(t).bigIntValue * S(r) / S(e), | ||
r | ||
@@ -333,9 +342,9 @@ ); | ||
get baseValue() { | ||
return d(this, v, N).call(this, "string"); | ||
return d(this, I, N).call(this, "string"); | ||
} | ||
get baseValueNumber() { | ||
return d(this, v, N).call(this, "number"); | ||
return d(this, I, N).call(this, "number"); | ||
} | ||
get baseValueBigInt() { | ||
return d(this, v, N).call(this, "number"); | ||
return d(this, I, N).call(this, "number"); | ||
} | ||
@@ -349,12 +358,12 @@ get value() { | ||
add(...t) { | ||
return d(this, w, T).call(this, "add", ...t); | ||
return d(this, w, y).call(this, "add", ...t); | ||
} | ||
sub(...t) { | ||
return d(this, w, T).call(this, "sub", ...t); | ||
return d(this, w, y).call(this, "sub", ...t); | ||
} | ||
mul(...t) { | ||
return d(this, w, T).call(this, "mul", ...t); | ||
return d(this, w, y).call(this, "mul", ...t); | ||
} | ||
div(...t) { | ||
return d(this, w, T).call(this, "div", ...t); | ||
return d(this, w, y).call(this, "div", ...t); | ||
} | ||
@@ -377,3 +386,3 @@ gt(t) { | ||
getBigIntValue(t, e) { | ||
return !e && typeof t == "object" ? t.bigIntValue : (t = typeof t == "object" ? t.value : t, d(this, V, P).call(this, d(this, b, y).call(this, t), e)); | ||
return !e && typeof t == "object" ? t.bigIntValue : (t = typeof t == "object" ? t.value : t, d(this, O, L).call(this, d(this, b, T).call(this, t), e)); | ||
} | ||
@@ -403,4 +412,4 @@ formatBigIntToSafeValue(t, e) { | ||
}; | ||
w = new WeakSet(), T = function(t, ...e) { | ||
const r = d(this, k, Q).call(this, this, ...e), s = I(r), a = e.reduce( | ||
w = new WeakSet(), y = function(t, ...e) { | ||
const r = d(this, k, Q).call(this, this, ...e), s = S(r), a = e.reduce( | ||
(o, l) => { | ||
@@ -421,13 +430,13 @@ const u = this.getBigIntValue(l, r); | ||
}, R = new WeakSet(), J = function(t, e) { | ||
const r = d(this, b, y).call(this, t) || "0"; | ||
this.bigIntValue = e || d(this, V, P).call(this, r); | ||
const r = d(this, b, T).call(this, t) || "0"; | ||
this.bigIntValue = e || d(this, O, L).call(this, r); | ||
}, k = new WeakSet(), Q = function(...t) { | ||
const e = t.map( | ||
(r) => typeof r == "object" ? r.decimal || C(r.decimalMultiplier) : d(this, O, q).call(this, d(this, b, y).call(this, r)) | ||
(r) => typeof r == "object" ? r.decimal || C(r.decimalMultiplier) : d(this, V, j).call(this, d(this, b, T).call(this, r)) | ||
).filter(Boolean); | ||
return Math.max(...e, B); | ||
}, V = new WeakSet(), P = function(t, e) { | ||
const r = e ? I(e) : this.decimalMultiplier, s = C(r), [a, c = ""] = t.split("."); | ||
}, O = new WeakSet(), L = function(t, e) { | ||
const r = e ? S(e) : this.decimalMultiplier, s = C(r), [a, c = ""] = t.split("."); | ||
return BigInt(`${a}${c.padEnd(s, "0")}`); | ||
}, b = new WeakSet(), y = function(t) { | ||
}, b = new WeakSet(), T = function(t) { | ||
const r = `${typeof t == "number" ? Number(t).toLocaleString("fullwide", { | ||
@@ -438,8 +447,8 @@ useGrouping: !1, | ||
return r.length > 1 ? `${r.slice(0, -1).join("")}.${r.at(-1)}` : r[0]; | ||
}, O = new WeakSet(), q = function(t) { | ||
}, V = new WeakSet(), j = function(t) { | ||
var r; | ||
const e = ((r = t.split(".")[1]) == null ? void 0 : r.length) || 0; | ||
return Math.max(e, B); | ||
}, v = new WeakSet(), N = function(t) { | ||
const e = this.decimalMultiplier / I(this.decimal || 0), r = this.bigIntValue / e; | ||
}, I = new WeakSet(), N = function(t) { | ||
const e = this.decimalMultiplier / S(this.decimal || 0), r = this.bigIntValue / e; | ||
switch (t) { | ||
@@ -454,9 +463,9 @@ case "number": | ||
}; | ||
let E = M, j; | ||
const L = (n) => { | ||
if (!j) | ||
let E = M, q; | ||
const P = (n) => { | ||
if (!q) | ||
throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first"); | ||
return j.get(n.toUpperCase()) || { decimal: h.THOR, identifier: "" }; | ||
return q.get(n.toUpperCase()) || { decimal: h.THOR, identifier: "" }; | ||
}, Y = async (n, t = 0) => { | ||
At(n); | ||
$t(n); | ||
const e = await X(F(n)); | ||
@@ -484,3 +493,3 @@ return new A({ decimal: e, value: t, identifier: n }); | ||
static fromStringSync(e, r = 0) { | ||
const { decimal: s, identifier: a } = L( | ||
const { decimal: s, identifier: a } = P( | ||
e | ||
@@ -494,3 +503,3 @@ ); | ||
static fromIdentifierSync(e, r = 0) { | ||
const { decimal: s, identifier: a } = L(e); | ||
const { decimal: s, identifier: a } = P(e); | ||
return new A({ decimal: s, identifier: a, value: r }); | ||
@@ -507,3 +516,3 @@ } | ||
static fromTCQuoteStatic(e, r = 0) { | ||
const s = L(e), a = this.shiftDecimals({ | ||
const s = P(e), a = this.shiftDecimals({ | ||
value: r, | ||
@@ -525,6 +534,6 @@ from: h.THOR, | ||
...c | ||
} = await import("./index.es-8503fb04.js"); | ||
j = [a, ...Object.values(c)].reduce( | ||
(l, { tokens: u }) => (u.forEach(({ identifier: g, chain: $, ...S }) => { | ||
const D = "decimals" in S ? S.decimals : h[$]; | ||
} = await import("@swapkit/tokens"); | ||
q = [a, ...Object.values(c)].reduce( | ||
(l, { tokens: u }) => (u.forEach(({ identifier: g, chain: $, ...v }) => { | ||
const D = "decimals" in v ? v.decimals : h[$]; | ||
l.set(g, { identifier: g, decimal: D }); | ||
@@ -554,3 +563,3 @@ }), l), | ||
} | ||
const kt = (n) => { | ||
const Dt = (n) => { | ||
const t = A.fromChainOrSignature(n); | ||
@@ -583,3 +592,3 @@ switch (n) { | ||
}; | ||
}, $t = { | ||
}, wt = { | ||
/** | ||
@@ -643,6 +652,6 @@ * Core | ||
constructor(t, e) { | ||
console.error(e), super(t, { cause: { code: $t[t], message: t } }), Object.setPrototypeOf(this, Z.prototype); | ||
console.error(e), super(t, { cause: { code: wt[t], message: t } }), Object.setPrototypeOf(this, Z.prototype); | ||
} | ||
} | ||
class wt extends E { | ||
class bt extends E { | ||
eq(t) { | ||
@@ -659,19 +668,20 @@ return this.eqValue(t); | ||
Z as SwapKitError, | ||
wt as SwapKitNumber, | ||
Bt as assetFromString, | ||
Ct as derivationPathToString, | ||
bt as SwapKitNumber, | ||
Mt as assetFromString, | ||
yt as derivationPathToString, | ||
U as formatBigIntToSafeValue, | ||
yt as gasFeeMultiplier, | ||
Bt as gasFeeMultiplier, | ||
_t as getAssetType, | ||
pt as getAsymmetricAssetShare, | ||
Et as getAsymmetricAssetWithdrawAmount, | ||
Ot as getAsymmetricAssetWithdrawAmount, | ||
gt as getAsymmetricRuneShare, | ||
Mt as getAsymmetricRuneWithdrawAmount, | ||
Et as getAsymmetricRuneWithdrawAmount, | ||
ht as getCommonAssetInfo, | ||
X as getDecimal, | ||
Ot as getEstimatedPoolShare, | ||
Nt as getLiquiditySlippage, | ||
Rt as getMemoFor, | ||
kt as getMinAmountByChain, | ||
Nt as getEstimatedPoolShare, | ||
Rt as getLiquiditySlippage, | ||
kt as getMemoFor, | ||
Dt as getMinAmountByChain, | ||
Tt as getRequest, | ||
ft as getSymmetricPoolShare, | ||
Vt as getSymmetricWithdraw, | ||
@@ -681,3 +691,3 @@ vt as getTHORNameCost, | ||
ct as postRequest, | ||
St as validateTHORName | ||
Ct as validateTHORName | ||
}; |
@@ -16,2 +16,3 @@ { | ||
"peerDependencies": { | ||
"@swapkit/tokens": "1.0.0-rc.0", | ||
"@swapkit/types": "1.0.0-rc.0" | ||
@@ -42,3 +43,3 @@ }, | ||
"types": "./dist/index.d.ts", | ||
"version": "1.0.0-rc.0", | ||
"version": "1.0.0-rc.1", | ||
"scripts": { | ||
@@ -45,0 +46,0 @@ "build": "vite build", |
@@ -86,2 +86,15 @@ import { BaseDecimal } from '@swapkit/types'; | ||
export const getSymmetricPoolShare = ({ | ||
liquidityUnits, | ||
poolUnits, | ||
runeDepth, | ||
assetDepth, | ||
}: ShareParams<{ | ||
runeDepth: string; | ||
assetDepth: string; | ||
}>) => ({ | ||
assetAmount: toTCSwapKitNumber(assetDepth).mul(liquidityUnits).div(poolUnits), | ||
runeAmount: toTCSwapKitNumber(runeDepth).mul(liquidityUnits).div(poolUnits), | ||
}); | ||
export const getSymmetricWithdraw = ({ | ||
@@ -97,6 +110,8 @@ liquidityUnits, | ||
percent: number; | ||
}>) => ({ | ||
assetAmount: toTCSwapKitNumber(assetDepth).mul(liquidityUnits).div(poolUnits).mul(percent), | ||
runeAmount: toTCSwapKitNumber(runeDepth).mul(liquidityUnits).div(poolUnits).mul(percent), | ||
}); | ||
}>) => | ||
Object.fromEntries( | ||
Object.entries(getSymmetricPoolShare({ liquidityUnits, poolUnits, runeDepth, assetDepth })).map( | ||
([name, value]) => [name, value.mul(percent)], | ||
), | ||
); | ||
@@ -103,0 +118,0 @@ export const getEstimatedPoolShare = ({ |
@@ -23,7 +23,17 @@ import { BaseDecimal, Chain } from '@swapkit/types'; | ||
symbol: 'ETH/ETH', | ||
decimal: 18, | ||
decimal: 8, | ||
value: 1234567890, | ||
}); | ||
expect(ethSynth.assetValue).toBe('1234567890 ETH/ETH'); | ||
expect(ethSynth.toString()).toBe('THOR.ETH/ETH'); | ||
const atomDerived = new AssetValue({ | ||
identifier: 'THOR.ATOM', | ||
decimal: 6, | ||
value: 123456789, | ||
}); | ||
expect(atomDerived.assetValue).toBe('123456789 ATOM'); | ||
expect(atomDerived.toString()).toBe('THOR.ATOM'); | ||
}); | ||
@@ -30,0 +40,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
145363
2
22
2837
7