@coinmasters/helpers
Advanced tools
Comparing version 11.0.18 to 11.0.20
@@ -1,17 +0,17 @@ | ||
var be = Object.defineProperty; | ||
var ye = (r, e, t) => e in r ? be(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t; | ||
var _ = (r, e, t) => (ye(r, typeof e != "symbol" ? e + "" : e, t), t), we = (r, e, t) => { | ||
if (!e.has(r)) | ||
throw TypeError("Cannot " + t); | ||
var bt = Object.defineProperty; | ||
var yt = (r, t, e) => t in r ? bt(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e; | ||
var _ = (r, t, e) => (yt(r, typeof t != "symbol" ? t + "" : t, e), e), wt = (r, t, e) => { | ||
if (!t.has(r)) | ||
throw TypeError("Cannot " + e); | ||
}; | ||
var S = (r, e, t) => { | ||
if (e.has(r)) | ||
var S = (r, t, e) => { | ||
if (t.has(r)) | ||
throw TypeError("Cannot add the same private member more than once"); | ||
e instanceof WeakSet ? e.add(r) : e.set(r, t); | ||
t instanceof WeakSet ? t.add(r) : t.set(r, e); | ||
}; | ||
var m = (r, e, t) => (we(r, e, "access private method"), t); | ||
import { FeeOption as L, BaseDecimal as d, Chain as i, EVMChainList as Ae, ChainToRPC as ve, MemoType as b } from "@coinmasters/types"; | ||
const Te = "0x313ce567", ae = async ({ chain: r, to: e }) => { | ||
var m = (r, t, e) => (wt(r, t, "access private method"), e); | ||
import { FeeOption as L, BaseDecimal as d, Chain as i, EVMChainList as At, ChainToRPC as vt, MemoType as b } from "@coinmasters/types"; | ||
const Tt = "0x313ce567", at = async ({ chain: r, to: t }) => { | ||
try { | ||
const { result: t } = await et.post(ve[r], { | ||
const { result: e } = await te.post(vt[r], { | ||
headers: { | ||
@@ -26,33 +26,33 @@ accept: "*/*", | ||
method: "eth_call", | ||
params: [{ to: e.toLowerCase(), data: Te }, "latest"] | ||
params: [{ to: t.toLowerCase(), data: Tt }, "latest"] | ||
}) | ||
}); | ||
return parseInt(BigInt(t).toString()); | ||
} catch (t) { | ||
return console.error(t), d[r]; | ||
return parseInt(BigInt(e).toString()); | ||
} catch (e) { | ||
return console.error(e), d[r]; | ||
} | ||
}, $e = async (r) => { | ||
}, $t = async (r) => { | ||
if (r === i.Ethereum) | ||
return d.ETH; | ||
const [, e] = r.split("-"); | ||
return e != null && e.startsWith("0x") ? ae({ chain: i.Ethereum, to: e }) : d.ETH; | ||
}, Re = async (r) => { | ||
const [, e] = r.split("-"); | ||
return e != null && e.startsWith("0x") ? ae({ chain: i.Avalanche, to: e.toLowerCase() }) : d.AVAX; | ||
}, Se = async (r) => r === i.BinanceSmartChain ? d.BSC : d.BSC, Ce = async ({ chain: r, symbol: e }) => { | ||
const [, t] = r.split("-"); | ||
return t != null && t.startsWith("0x") ? at({ chain: i.Ethereum, to: t }) : d.ETH; | ||
}, Rt = async (r) => { | ||
const [, t] = r.split("-"); | ||
return t != null && t.startsWith("0x") ? at({ chain: i.Avalanche, to: t.toLowerCase() }) : d.AVAX; | ||
}, St = async (r) => r === i.BinanceSmartChain ? d.BSC : d.BSC, Ct = async ({ chain: r, symbol: t }) => { | ||
switch (r) { | ||
case i.Ethereum: | ||
return $e(e); | ||
return $t(t); | ||
case i.Avalanche: | ||
return Re(e); | ||
return Rt(t); | ||
case i.BinanceSmartChain: | ||
return Se(e); | ||
return St(t); | ||
default: | ||
return d[r]; | ||
} | ||
}, at = { | ||
}, ae = { | ||
[L.Average]: 1.2, | ||
[L.Fast]: 1.5, | ||
[L.Fastest]: 2 | ||
}, oe = ({ chain: r, symbol: e }) => { | ||
}, ot = ({ chain: r, symbol: t }) => { | ||
switch (r) { | ||
@@ -70,21 +70,21 @@ case i.Bitcoin: | ||
case i.Avalanche: | ||
return e === r; | ||
return t === r; | ||
case i.Arbitrum: | ||
case i.Optimism: | ||
case i.Base: | ||
return e === "ETH"; | ||
return t === "ETH"; | ||
case i.Mayachain: | ||
return e === "CACAO"; | ||
return t === "CACAO"; | ||
case i.Kujira: | ||
return e === "KUJI"; | ||
return t === "KUJI"; | ||
case i.Cosmos: | ||
return e === "ATOM"; | ||
return t === "ATOM"; | ||
case i.Polygon: | ||
return e === "MATIC"; | ||
return t === "MATIC"; | ||
case i.BinanceSmartChain: | ||
return e === "BNB"; | ||
return t === "BNB"; | ||
case i.THORChain: | ||
return e === "RUNE"; | ||
return t === "RUNE"; | ||
} | ||
}, Ie = (r) => { | ||
}, It = (r) => { | ||
switch (r) { | ||
@@ -126,4 +126,4 @@ case "ETH.THOR": | ||
} | ||
}, Ee = ({ chain: r, symbol: e }) => { | ||
if (e.includes("/")) | ||
}, Et = ({ chain: r, symbol: t }) => { | ||
if (t.includes("/")) | ||
return "Synth"; | ||
@@ -143,84 +143,84 @@ switch (r) { | ||
case i.Cosmos: | ||
return e === "ATOM" ? "Native" : i.Cosmos; | ||
return t === "ATOM" ? "Native" : i.Cosmos; | ||
case i.Kujira: | ||
return e === i.Kujira ? "Native" : i.Kujira; | ||
return t === i.Kujira ? "Native" : i.Kujira; | ||
case i.Binance: | ||
return e === i.Binance ? "Native" : "BEP2"; | ||
return t === i.Binance ? "Native" : "BEP2"; | ||
case i.BinanceSmartChain: | ||
return e === i.Binance ? "Native" : "BEP20"; | ||
return t === i.Binance ? "Native" : "BEP20"; | ||
case i.Ethereum: | ||
return e === i.Ethereum ? "Native" : "ERC20"; | ||
return t === i.Ethereum ? "Native" : "ERC20"; | ||
case i.Avalanche: | ||
return e === i.Avalanche ? "Native" : i.Avalanche; | ||
return t === i.Avalanche ? "Native" : i.Avalanche; | ||
case i.Polygon: | ||
return e === i.Polygon ? "Native" : "POLYGON"; | ||
return t === i.Polygon ? "Native" : "POLYGON"; | ||
case i.Base: | ||
return e === i.Ethereum ? "Native" : "ERC20"; | ||
return t === i.Ethereum ? "Native" : "ERC20"; | ||
case i.Arbitrum: | ||
return [i.Ethereum, i.Arbitrum].includes(e) ? "Native" : "ARBITRUM"; | ||
return [i.Ethereum, i.Arbitrum].includes(t) ? "Native" : "ARBITRUM"; | ||
case i.Optimism: | ||
return [i.Ethereum, i.Optimism].includes(e) ? "Native" : "OPTIMISM"; | ||
return [i.Ethereum, i.Optimism].includes(t) ? "Native" : "OPTIMISM"; | ||
} | ||
}, ot = (r) => { | ||
}, oe = (r) => { | ||
var o; | ||
const [e, ...t] = r.split("."), s = r.includes("/"), n = t.join("."), a = (o = n == null ? void 0 : n.split("-")) == null ? void 0 : o[0]; | ||
return { chain: e, symbol: n, ticker: a, synth: s }; | ||
}, Oe = new RegExp( | ||
const [t, ...e] = r.split("."), s = r.includes("/"), n = e.join("."), a = (o = n == null ? void 0 : n.split("-")) == null ? void 0 : o[0]; | ||
return { chain: t, symbol: n, ticker: a, synth: s }; | ||
}, Ot = new RegExp( | ||
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/, | ||
"gmi" | ||
), Be = (r) => { | ||
const [e, t] = r.split("."); | ||
if (!Ae.includes(e)) | ||
), Bt = (r) => { | ||
const [t, e] = r.split("."); | ||
if (!At.includes(t)) | ||
return !0; | ||
const [, s] = t.split("-"); | ||
return oe({ chain: e, symbol: t }) || !!s; | ||
}, ct = (r) => r.filter((e) => { | ||
const t = `${e.chain}.${e.symbol}`; | ||
return !Oe.test(t) && Be(t) && e.value !== "0"; | ||
}), Me = ({ | ||
const [, s] = e.split("-"); | ||
return ot({ chain: t, symbol: e }) || !!s; | ||
}, ce = (r) => r.filter((t) => { | ||
const e = `${t.chain}.${t.symbol}`; | ||
return !Ot.test(e) && Bt(e) && t.value !== "0"; | ||
}), Mt = ({ | ||
liquidityUnits: r, | ||
poolUnits: e, | ||
runeDepth: t | ||
poolUnits: t, | ||
runeDepth: e | ||
}) => { | ||
const s = p(r), n = p(e), a = p(t), o = s.mul(a), c = n.mul(n).mul(2), u = n.mul(s).mul(2), h = s.mul(s), l = n.mul(n).mul(n); | ||
const s = p(r), n = p(t), a = p(e), o = s.mul(a), c = n.mul(n).mul(2), u = n.mul(s).mul(2), h = s.mul(s), l = n.mul(n).mul(n); | ||
return o.mul(c.sub(u).add(h)).div(l); | ||
}, ke = ({ | ||
}, kt = ({ | ||
liquidityUnits: r, | ||
poolUnits: e, | ||
assetDepth: t | ||
poolUnits: t, | ||
assetDepth: e | ||
}) => { | ||
const s = p(r), n = p(e), a = p(t), o = s.mul(a), c = n.mul(n).mul(2), u = n.mul(s).mul(2), h = s.mul(s), l = o.mul(c.sub(u).add(h)), f = n.mul(n).mul(n); | ||
const s = p(r), n = p(t), a = p(e), o = s.mul(a), c = n.mul(n).mul(2), u = n.mul(s).mul(2), h = s.mul(s), l = o.mul(c.sub(u).add(h)), f = n.mul(n).mul(n); | ||
return l.div(f); | ||
}, ut = ({ | ||
}, ue = ({ | ||
percent: r, | ||
runeDepth: e, | ||
liquidityUnits: t, | ||
runeDepth: t, | ||
liquidityUnits: e, | ||
poolUnits: s | ||
}) => Me({ runeDepth: e, liquidityUnits: t, poolUnits: s }).mul(r), lt = ({ | ||
}) => Mt({ runeDepth: t, liquidityUnits: e, poolUnits: s }).mul(r), le = ({ | ||
percent: r, | ||
assetDepth: e, | ||
liquidityUnits: t, | ||
assetDepth: t, | ||
liquidityUnits: e, | ||
poolUnits: s | ||
}) => ke({ assetDepth: e, liquidityUnits: t, poolUnits: s }).mul(r), p = (r) => y.fromBigInt(BigInt(r), d.THOR), xe = ({ | ||
}) => kt({ assetDepth: t, liquidityUnits: e, poolUnits: s }).mul(r), p = (r) => y.fromBigInt(BigInt(r), d.THOR), xt = ({ | ||
liquidityUnits: r, | ||
poolUnits: e, | ||
runeDepth: t, | ||
poolUnits: t, | ||
runeDepth: e, | ||
assetDepth: s | ||
}) => ({ | ||
assetAmount: p(s).mul(r).div(e), | ||
runeAmount: p(t).mul(r).div(e) | ||
}), ht = ({ | ||
assetAmount: p(s).mul(r).div(t), | ||
runeAmount: p(e).mul(r).div(t) | ||
}), he = ({ | ||
liquidityUnits: r, | ||
poolUnits: e, | ||
runeDepth: t, | ||
poolUnits: t, | ||
runeDepth: e, | ||
assetDepth: s, | ||
percent: n | ||
}) => Object.fromEntries( | ||
Object.entries(xe({ liquidityUnits: r, poolUnits: e, runeDepth: t, assetDepth: s })).map( | ||
Object.entries(xt({ liquidityUnits: r, poolUnits: t, runeDepth: e, assetDepth: s })).map( | ||
([a, o]) => [a, o.mul(n)] | ||
) | ||
), dt = ({ | ||
), de = ({ | ||
runeDepth: r, | ||
poolUnits: e, | ||
assetDepth: t, | ||
poolUnits: t, | ||
assetDepth: e, | ||
liquidityUnits: s, | ||
@@ -230,48 +230,48 @@ runeAmount: n, | ||
}) => { | ||
const o = 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: a, decimal: 8 }), f = h.mul(c), g = l.mul(o), A = h.mul(l), R = o.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 o = new y({ value: r, decimal: 8 }), c = new y({ value: e, decimal: 8 }), u = new y({ value: t, decimal: 8 }), h = new y({ value: n, decimal: 8 }), l = new y({ value: a, decimal: 8 }), f = h.mul(c), g = l.mul(o), A = h.mul(l), R = o.mul(c), ft = u.mul(f.add(g.add(A.mul(2)))), _t = f.add(g.add(R.mul(2))), X = ft.div(_t), D = p(s).add(X); | ||
if (X.getBaseValue("number") === 0) | ||
return D.div(u).getBaseValue("number"); | ||
const ge = u.add(D); | ||
return D.div(ge).getBaseValue("number"); | ||
}, mt = ({ | ||
const gt = u.add(D); | ||
return D.div(gt).getBaseValue("number"); | ||
}, me = ({ | ||
runeAmount: r, | ||
assetAmount: e, | ||
runeDepth: t, | ||
assetAmount: t, | ||
runeDepth: e, | ||
assetDepth: s | ||
}) => { | ||
if (r === "0" || e === "0" || t === "0" || s === "0") | ||
if (r === "0" || t === "0" || e === "0" || s === "0") | ||
return 0; | ||
const n = p(t), a = p(s), o = p(e), c = p(r), u = o.mul(n).sub(a.mul(c)), h = a.mul(c).add(n.mul(a)); | ||
const n = p(e), a = p(s), o = p(t), c = p(r), u = o.mul(n).sub(a.mul(c)), h = a.mul(c).add(n.mul(a)); | ||
return Math.abs(u.div(h).getBaseValue("number")); | ||
}, qe = ({ | ||
}, qt = ({ | ||
symbol: r, | ||
ticker: e, | ||
chain: t | ||
}) => t === "ETH" && e !== "ETH" ? `${e}-${r.slice(-3)}` : r, pt = (r, e) => { | ||
ticker: t, | ||
chain: e | ||
}) => e === "ETH" && t !== "ETH" ? `${t}-${r.slice(-3)}` : r, pe = (r, t) => { | ||
switch (r) { | ||
case b.LEAVE: | ||
case b.BOND: { | ||
const { address: t } = e; | ||
return `${r}:${t}`; | ||
const { address: e } = t; | ||
return `${r}:${e}`; | ||
} | ||
case b.UNBOND: { | ||
const { address: t, unbondAmount: s } = e; | ||
return `${r}:${t}:${s * 10 ** 8}`; | ||
const { address: e, unbondAmount: s } = t; | ||
return `${r}:${e}:${s * 10 ** 8}`; | ||
} | ||
case b.THORNAME_REGISTER: { | ||
const { name: t, chain: s, address: n, owner: a } = e; | ||
return `${r}:${t}:${s}:${n}${a ? `:${a}` : ""}`; | ||
const { name: e, chain: s, address: n, owner: a } = t; | ||
return `${r}:${e}:${s}:${n}${a ? `:${a}` : ""}`; | ||
} | ||
case b.DEPOSIT: { | ||
const { chain: t, symbol: s, address: n, singleSide: a } = e; | ||
return a ? `${r}:${t}/${s}::t:0` : `${r}:${t}.${s}:${n || ""}:t:0`; | ||
const { chain: e, symbol: s, address: n, singleSide: a } = t; | ||
return a ? `${r}:${e}/${s}::t:0` : `${r}:${e}.${s}:${n || ""}:t:0`; | ||
} | ||
case b.WITHDRAW: { | ||
const { chain: t, ticker: s, symbol: n, basisPoints: a, targetAssetString: o, singleSide: c } = e, u = !c && o ? `:${o}` : "", h = qe({ chain: t, symbol: n, ticker: s }); | ||
return `${r}:${t}${c ? "/" : "."}${h}:${a}${u}`; | ||
const { chain: e, ticker: s, symbol: n, basisPoints: a, targetAssetString: o, singleSide: c } = t, u = !c && o ? `:${o}` : "", h = qt({ chain: e, symbol: n, ticker: s }); | ||
return `${r}:${e}${c ? "/" : "."}${h}:${a}${u}`; | ||
} | ||
case b.OPEN_LOAN: | ||
case b.CLOSE_LOAN: { | ||
const { asset: t, address: s } = e; | ||
return `${r}:${t}:${s}`; | ||
const { asset: e, address: s } = t; | ||
return `${r}:${e}:${s}`; | ||
} | ||
@@ -281,15 +281,15 @@ default: | ||
} | ||
}, ft = (r) => { | ||
}, fe = (r) => { | ||
if (r < 0) | ||
throw new Error("Invalid number of year"); | ||
return 10 + r; | ||
}, _t = (r) => { | ||
}, _e = (r) => { | ||
if (r.length > 30) | ||
return !1; | ||
const e = /^[a-zA-Z0-9+_-]+$/g; | ||
return !!r.match(e); | ||
}, gt = ([r, e, t, s, n]) => `${r}'/${e}'/${t}'/${s}${typeof n != "number" ? "" : `/${n}`}`; | ||
const t = /^[a-zA-Z0-9+_-]+$/g; | ||
return !!r.match(t); | ||
}, ge = ([r, t, e, s, n]) => `${r}'/${t}'/${e}'/${s}${typeof n != "number" ? "" : `/${n}`}`; | ||
class Q extends Error { | ||
constructor(e, t, s) { | ||
const n = e.status || e.status === 0 ? e.status : "", a = e.statusText || "", o = `${n} ${a}`.trim(), c = o ? `status code ${o}` : "an unknown error"; | ||
constructor(t, e, s) { | ||
const n = t.status || t.status === 0 ? t.status : "", a = t.statusText || "", o = `${n} ${a}`.trim(), c = o ? `status code ${o}` : "an unknown error"; | ||
super(`Request failed with ${c}`), Object.defineProperty(this, "response", { | ||
@@ -310,7 +310,7 @@ enumerable: !0, | ||
value: void 0 | ||
}), this.name = "HTTPError", this.response = e, this.request = t, this.options = s; | ||
}), this.name = "HTTPError", this.response = t, this.request = e, this.options = s; | ||
} | ||
} | ||
class ce extends Error { | ||
constructor(e) { | ||
class ct extends Error { | ||
constructor(t) { | ||
super("Request timed out"), Object.defineProperty(this, "request", { | ||
@@ -321,30 +321,30 @@ enumerable: !0, | ||
value: void 0 | ||
}), this.name = "TimeoutError", this.request = e; | ||
}), this.name = "TimeoutError", this.request = t; | ||
} | ||
} | ||
const V = (r) => r !== null && typeof r == "object", x = (...r) => { | ||
for (const e of r) | ||
if ((!V(e) || Array.isArray(e)) && e !== void 0) | ||
for (const t of r) | ||
if ((!V(t) || Array.isArray(t)) && t !== void 0) | ||
throw new TypeError("The `options` argument must be an object"); | ||
return K({}, ...r); | ||
}, ue = (r = {}, e = {}) => { | ||
const t = new globalThis.Headers(r), s = e instanceof globalThis.Headers, n = new globalThis.Headers(e); | ||
}, ut = (r = {}, t = {}) => { | ||
const e = new globalThis.Headers(r), s = t instanceof globalThis.Headers, n = new globalThis.Headers(t); | ||
for (const [a, o] of n.entries()) | ||
s && o === "undefined" || o === void 0 ? t.delete(a) : t.set(a, o); | ||
return t; | ||
s && o === "undefined" || o === void 0 ? e.delete(a) : e.set(a, o); | ||
return e; | ||
}, K = (...r) => { | ||
let e = {}, t = {}; | ||
let t = {}, e = {}; | ||
for (const s of r) | ||
if (Array.isArray(s)) | ||
Array.isArray(e) || (e = []), e = [...e, ...s]; | ||
Array.isArray(t) || (t = []), t = [...t, ...s]; | ||
else if (V(s)) { | ||
for (let [n, a] of Object.entries(s)) | ||
V(a) && n in e && (a = K(e[n], a)), e = { ...e, [n]: a }; | ||
V(s.headers) && (t = ue(t, s.headers), e.headers = t); | ||
V(a) && n in t && (a = K(t[n], a)), t = { ...t, [n]: a }; | ||
V(s.headers) && (e = ut(e, s.headers), t.headers = e); | ||
} | ||
return e; | ||
}, Ve = (() => { | ||
let r = !1, e = !1; | ||
const t = typeof globalThis.ReadableStream == "function", s = typeof globalThis.Request == "function"; | ||
return t && s && (e = new globalThis.Request("https://empty.invalid", { | ||
return t; | ||
}, Vt = (() => { | ||
let r = !1, t = !1; | ||
const e = typeof globalThis.ReadableStream == "function", s = typeof globalThis.Request == "function"; | ||
return e && s && (t = new globalThis.Request("https://empty.invalid", { | ||
body: new globalThis.ReadableStream(), | ||
@@ -356,4 +356,4 @@ method: "POST", | ||
} | ||
}).headers.has("Content-Type")), r && !e; | ||
})(), Pe = typeof globalThis.AbortController == "function", Ne = typeof globalThis.ReadableStream == "function", He = typeof globalThis.FormData == "function", le = ["get", "post", "put", "patch", "head", "delete"], je = { | ||
}).headers.has("Content-Type")), r && !t; | ||
})(), Pt = typeof globalThis.AbortController == "function", Nt = typeof globalThis.ReadableStream == "function", Ht = typeof globalThis.FormData == "function", lt = ["get", "post", "put", "patch", "head", "delete"], jt = { | ||
json: "application/json", | ||
@@ -364,3 +364,3 @@ text: "text/*", | ||
blob: "*/*" | ||
}, U = 2147483647, he = Symbol("stop"), De = { | ||
}, U = 2147483647, ht = Symbol("stop"), Dt = { | ||
json: !0, | ||
@@ -376,3 +376,3 @@ parseJson: !0, | ||
fetch: !0 | ||
}, Le = { | ||
}, Lt = { | ||
method: !0, | ||
@@ -393,14 +393,14 @@ headers: !0, | ||
duplex: !0 | ||
}, Ue = (r) => le.includes(r) ? r.toUpperCase() : r, Fe = ["get", "put", "head", "delete", "options", "trace"], Ge = [408, 413, 429, 500, 502, 503, 504], de = [413, 429, 503], ee = { | ||
}, Ut = (r) => lt.includes(r) ? r.toUpperCase() : r, Ft = ["get", "put", "head", "delete", "options", "trace"], Gt = [408, 413, 429, 500, 502, 503, 504], dt = [413, 429, 503], tt = { | ||
limit: 2, | ||
methods: Fe, | ||
statusCodes: Ge, | ||
afterStatusCodes: de, | ||
methods: Ft, | ||
statusCodes: Gt, | ||
afterStatusCodes: dt, | ||
maxRetryAfter: Number.POSITIVE_INFINITY, | ||
backoffLimit: Number.POSITIVE_INFINITY, | ||
delay: (r) => 0.3 * 2 ** (r - 1) * 1e3 | ||
}, We = (r = {}) => { | ||
}, Wt = (r = {}) => { | ||
if (typeof r == "number") | ||
return { | ||
...ee, | ||
...tt, | ||
limit: r | ||
@@ -413,13 +413,13 @@ }; | ||
return { | ||
...ee, | ||
...tt, | ||
...r, | ||
afterStatusCodes: de | ||
afterStatusCodes: dt | ||
}; | ||
}; | ||
async function Ye(r, e, t, s) { | ||
async function Yt(r, t, e, s) { | ||
return new Promise((n, a) => { | ||
const o = setTimeout(() => { | ||
t && t.abort(), a(new ce(r)); | ||
e && e.abort(), a(new ct(r)); | ||
}, s.timeout); | ||
s.fetch(r, e).then(n).catch(a).then(() => { | ||
s.fetch(r, t).then(n).catch(a).then(() => { | ||
clearTimeout(o); | ||
@@ -429,22 +429,22 @@ }); | ||
} | ||
async function ze(r, { signal: e }) { | ||
return new Promise((t, s) => { | ||
e && (e.throwIfAborted(), e.addEventListener("abort", n, { once: !0 })); | ||
async function zt(r, { signal: t }) { | ||
return new Promise((e, s) => { | ||
t && (t.throwIfAborted(), t.addEventListener("abort", n, { once: !0 })); | ||
function n() { | ||
clearTimeout(a), s(e.reason); | ||
clearTimeout(a), s(t.reason); | ||
} | ||
const a = setTimeout(() => { | ||
e == null || e.removeEventListener("abort", n), t(); | ||
t == null || t.removeEventListener("abort", n), e(); | ||
}, r); | ||
}); | ||
} | ||
const Je = (r, e) => { | ||
const t = {}; | ||
for (const s in e) | ||
!(s in Le) && !(s in De) && !(s in r) && (t[s] = e[s]); | ||
return t; | ||
const Jt = (r, t) => { | ||
const e = {}; | ||
for (const s in t) | ||
!(s in Lt) && !(s in Dt) && !(s in r) && (e[s] = t[s]); | ||
return e; | ||
}; | ||
class N { | ||
static create(e, t) { | ||
const s = new N(e, t), n = async () => { | ||
static create(t, e) { | ||
const s = new N(t, e), n = async () => { | ||
if (typeof s._options.timeout == "number" && s._options.timeout > U) | ||
@@ -467,3 +467,3 @@ throw new RangeError(`The \`timeout\` option cannot be greater than ${U}`); | ||
throw new TypeError("The `onDownloadProgress` option must be a function"); | ||
if (!Ne) | ||
if (!Nt) | ||
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing."); | ||
@@ -474,3 +474,3 @@ return s._stream(c.clone(), s._options.onDownloadProgress); | ||
}, o = s._options.retry.methods.includes(s.request.method.toLowerCase()) ? s._retry(n) : n(); | ||
for (const [c, u] of Object.entries(je)) | ||
for (const [c, u] of Object.entries(jt)) | ||
o[c] = async () => { | ||
@@ -482,4 +482,4 @@ s.request.headers.set("accept", s.request.headers.get("accept") || u); | ||
return ""; | ||
if (t.parseJson) | ||
return t.parseJson(await l.text()); | ||
if (e.parseJson) | ||
return e.parseJson(await l.text()); | ||
} | ||
@@ -491,3 +491,3 @@ return l[c](); | ||
// eslint-disable-next-line complexity | ||
constructor(e, t = {}) { | ||
constructor(t, e = {}) { | ||
if (Object.defineProperty(this, "request", { | ||
@@ -518,7 +518,7 @@ enumerable: !0, | ||
value: void 0 | ||
}), this._input = e, this._options = { | ||
}), this._input = t, this._options = { | ||
// TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208 | ||
credentials: this._input.credentials || "same-origin", | ||
...t, | ||
headers: ue(this._input.headers, t.headers), | ||
...e, | ||
headers: ut(this._input.headers, e.headers), | ||
hooks: K({ | ||
@@ -529,10 +529,10 @@ beforeRequest: [], | ||
afterResponse: [] | ||
}, t.hooks), | ||
method: Ue(t.method ?? this._input.method), | ||
}, e.hooks), | ||
method: Ut(e.method ?? this._input.method), | ||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||
prefixUrl: String(t.prefixUrl || ""), | ||
retry: We(t.retry), | ||
throwHttpErrors: t.throwHttpErrors !== !1, | ||
timeout: t.timeout ?? 1e4, | ||
fetch: t.fetch ?? globalThis.fetch.bind(globalThis) | ||
prefixUrl: String(e.prefixUrl || ""), | ||
retry: Wt(e.retry), | ||
throwHttpErrors: e.throwHttpErrors !== !1, | ||
timeout: e.timeout ?? 1e4, | ||
fetch: e.fetch ?? globalThis.fetch.bind(globalThis) | ||
}, typeof this._input != "string" && !(this._input instanceof URL || this._input instanceof globalThis.Request)) | ||
@@ -545,3 +545,3 @@ throw new TypeError("`input` must be a string, URL, or Request"); | ||
} | ||
if (Pe) { | ||
if (Pt) { | ||
if (this.abortController = new globalThis.AbortController(), this._options.signal) { | ||
@@ -555,36 +555,36 @@ const s = this._options.signal; | ||
} | ||
if (Ve && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) { | ||
if (Vt && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) { | ||
const n = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), a = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, n); | ||
(He && this._options.body instanceof globalThis.FormData || this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers["content-type"]) && this.request.headers.delete("content-type"), this.request = new globalThis.Request(new globalThis.Request(a, { ...this.request }), this._options); | ||
(Ht && this._options.body instanceof globalThis.FormData || this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers["content-type"]) && this.request.headers.delete("content-type"), this.request = new globalThis.Request(new globalThis.Request(a, { ...this.request }), this._options); | ||
} | ||
this._options.json !== void 0 && (this._options.body = JSON.stringify(this._options.json), this.request.headers.set("content-type", this._options.headers.get("content-type") ?? "application/json"), this.request = new globalThis.Request(this.request, { body: this._options.body })); | ||
} | ||
_calculateRetryDelay(e) { | ||
if (this._retryCount++, this._retryCount < this._options.retry.limit && !(e instanceof ce)) { | ||
if (e instanceof Q) { | ||
if (!this._options.retry.statusCodes.includes(e.response.status)) | ||
_calculateRetryDelay(t) { | ||
if (this._retryCount++, this._retryCount < this._options.retry.limit && !(t instanceof ct)) { | ||
if (t instanceof Q) { | ||
if (!this._options.retry.statusCodes.includes(t.response.status)) | ||
return 0; | ||
const s = e.response.headers.get("Retry-After"); | ||
if (s && this._options.retry.afterStatusCodes.includes(e.response.status)) { | ||
const s = t.response.headers.get("Retry-After"); | ||
if (s && this._options.retry.afterStatusCodes.includes(t.response.status)) { | ||
let n = Number(s); | ||
return Number.isNaN(n) ? n = Date.parse(s) - Date.now() : n *= 1e3, this._options.retry.maxRetryAfter !== void 0 && n > this._options.retry.maxRetryAfter ? 0 : n; | ||
} | ||
if (e.response.status === 413) | ||
if (t.response.status === 413) | ||
return 0; | ||
} | ||
const t = this._options.retry.delay(this._retryCount); | ||
return Math.min(this._options.retry.backoffLimit, t); | ||
const e = this._options.retry.delay(this._retryCount); | ||
return Math.min(this._options.retry.backoffLimit, e); | ||
} | ||
return 0; | ||
} | ||
_decorateResponse(e) { | ||
return this._options.parseJson && (e.json = async () => this._options.parseJson(await e.text())), e; | ||
_decorateResponse(t) { | ||
return this._options.parseJson && (t.json = async () => this._options.parseJson(await t.text())), t; | ||
} | ||
async _retry(e) { | ||
async _retry(t) { | ||
try { | ||
return await e(); | ||
} catch (t) { | ||
const s = Math.min(this._calculateRetryDelay(t), U); | ||
return await t(); | ||
} catch (e) { | ||
const s = Math.min(this._calculateRetryDelay(e), U); | ||
if (s !== 0 && this._retryCount > 0) { | ||
await ze(s, { signal: this._options.signal }); | ||
await zt(s, { signal: this._options.signal }); | ||
for (const n of this._options.hooks.beforeRetry) | ||
@@ -594,14 +594,14 @@ if (await n({ | ||
options: this._options, | ||
error: t, | ||
error: e, | ||
retryCount: this._retryCount | ||
}) === he) | ||
}) === ht) | ||
return; | ||
return this._retry(e); | ||
return this._retry(t); | ||
} | ||
throw t; | ||
throw e; | ||
} | ||
} | ||
async _fetch() { | ||
for (const t of this._options.hooks.beforeRequest) { | ||
const s = await t(this.request, this._options); | ||
for (const e of this._options.hooks.beforeRequest) { | ||
const s = await e(this.request, this._options); | ||
if (s instanceof Request) { | ||
@@ -614,17 +614,17 @@ this.request = s; | ||
} | ||
const e = Je(this.request, this._options); | ||
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), e) : Ye(this.request.clone(), e, this.abortController, this._options); | ||
const t = Jt(this.request, this._options); | ||
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Yt(this.request.clone(), t, this.abortController, this._options); | ||
} | ||
/* istanbul ignore next */ | ||
_stream(e, t) { | ||
const s = Number(e.headers.get("content-length")) || 0; | ||
_stream(t, e) { | ||
const s = Number(t.headers.get("content-length")) || 0; | ||
let n = 0; | ||
return e.status === 204 ? (t && t({ percent: 1, totalBytes: s, transferredBytes: n }, new Uint8Array()), new globalThis.Response(null, { | ||
status: e.status, | ||
statusText: e.statusText, | ||
headers: e.headers | ||
return t.status === 204 ? (e && e({ percent: 1, totalBytes: s, transferredBytes: n }, new Uint8Array()), new globalThis.Response(null, { | ||
status: t.status, | ||
statusText: t.statusText, | ||
headers: t.headers | ||
})) : new globalThis.Response(new globalThis.ReadableStream({ | ||
async start(a) { | ||
const o = e.body.getReader(); | ||
t && t({ percent: 0, transferredBytes: 0, totalBytes: s }, new Uint8Array()); | ||
const o = t.body.getReader(); | ||
e && e({ percent: 0, transferredBytes: 0, totalBytes: s }, new Uint8Array()); | ||
async function c() { | ||
@@ -636,6 +636,6 @@ const { done: u, value: h } = await o.read(); | ||
} | ||
if (t) { | ||
if (e) { | ||
n += h.byteLength; | ||
const l = s === 0 ? 0 : n / s; | ||
t({ percent: l, transferredBytes: n, totalBytes: s }, h); | ||
e({ percent: l, transferredBytes: n, totalBytes: s }, h); | ||
} | ||
@@ -647,5 +647,5 @@ a.enqueue(h), await c(); | ||
}), { | ||
status: e.status, | ||
statusText: e.statusText, | ||
headers: e.headers | ||
status: t.status, | ||
statusText: t.statusText, | ||
headers: t.headers | ||
}); | ||
@@ -656,11 +656,11 @@ } | ||
const F = (r) => { | ||
const e = (t, s) => N.create(t, x(r, s)); | ||
for (const t of le) | ||
e[t] = (s, n) => N.create(s, x(r, n, { method: t })); | ||
return e.create = (t) => F(x(t)), e.extend = (t) => F(x(r, t)), e.stop = he, e; | ||
}, Ke = F(), Ze = Ke, Xe = typeof window < "u" ? {} : { | ||
const t = (e, s) => N.create(e, x(r, s)); | ||
for (const e of lt) | ||
t[e] = (s, n) => N.create(s, x(r, n, { method: e })); | ||
return t.create = (e) => F(x(e)), t.extend = (e) => F(x(r, e)), t.stop = ht, t; | ||
}, Kt = F(), Zt = Kt, Xt = typeof window < "u" ? {} : { | ||
Referrer: "https://sk.thorswap.net", | ||
Referer: "https://sk.thorswap.net" | ||
}, Qe = { | ||
headers: Xe, | ||
}, Qt = { | ||
headers: Xt, | ||
timeout: 3e4, | ||
@@ -676,12 +676,12 @@ // Example: 10000 milliseconds = 10 seconds | ||
} | ||
}, te = Ze.create(Qe), et = { | ||
get: async (r, e) => te.get(r, e).json(), | ||
post: async (r, e) => te.post(r, e).json() | ||
}, et = Zt.create(Qt), te = { | ||
get: async (r, t) => et.get(r, t).json(), | ||
post: async (r, t) => et.post(r, t).json() | ||
// Implement other methods (put, delete, patch, head) as needed | ||
}, se = Object.values(i), tt = (r = "") => { | ||
const e = r.toUpperCase(), [t] = e.split("."); | ||
if (se.includes(t)) | ||
}, st = Object.values(i), ee = (r = "") => { | ||
const t = r.toUpperCase(), [e] = t.split("."); | ||
if (st.includes(e)) | ||
return !0; | ||
const [s] = e.split("/"); | ||
if (se.includes(s)) | ||
const [s] = t.split("/"); | ||
if (st.includes(s)) | ||
return !0; | ||
@@ -694,12 +694,12 @@ throw new Error( | ||
value: r, | ||
bigIntDecimal: e = O, | ||
decimal: t = O | ||
bigIntDecimal: t = O, | ||
decimal: e = O | ||
}) { | ||
const s = r < 0n; | ||
let n = r.toString().substring(s ? 1 : 0); | ||
const a = t - (n.length - 1); | ||
const a = e - (n.length - 1); | ||
a > 0 && (n = "0".repeat(a) + n); | ||
const o = n.length - t; | ||
let c = n.slice(-t); | ||
return parseInt(c[e]) >= 5 ? c = `${c.substring(0, e - 1)}${(parseInt(c[e - 1]) + 1).toString()}` : c = c.substring(0, e), `${s ? "-" : ""}${n.slice(0, o)}.${c}`.replace( | ||
const o = n.length - e; | ||
let c = n.slice(-e); | ||
return parseInt(c[t]) >= 5 ? c = `${c.substring(0, t - 1)}${(parseInt(c[t - 1]) + 1).toString()}` : c = c.substring(0, t), `${s ? "-" : ""}${n.slice(0, o)}.${c}`.replace( | ||
/\.?0*$/, | ||
@@ -709,5 +709,5 @@ "" | ||
} | ||
var $, E, w, C, j, me, M, G, k, W; | ||
var $, E, w, C, j, mt, M, G, k, W; | ||
const Z = class Z { | ||
constructor(e) { | ||
constructor(t) { | ||
S(this, $); | ||
@@ -721,62 +721,62 @@ S(this, w); | ||
_(this, "decimal"); | ||
const t = Y(e), s = typeof e == "object"; | ||
this.decimal = s ? e.decimal : void 0, this.decimalMultiplier = s && "decimalMultiplier" in e ? e.decimalMultiplier : v(Math.max(re(q(t)), this.decimal || 0)), m(this, j, me).call(this, t); | ||
const e = Y(t), s = typeof t == "object"; | ||
this.decimal = s ? t.decimal : void 0, this.decimalMultiplier = s && "decimalMultiplier" in t ? t.decimalMultiplier : v(Math.max(rt(q(e)), this.decimal || 0)), m(this, j, mt).call(this, e); | ||
} | ||
static fromBigInt(e, t) { | ||
static fromBigInt(t, e) { | ||
return new Z({ | ||
decimal: t, | ||
value: H({ value: e, bigIntDecimal: t, decimal: t }) | ||
decimal: e, | ||
value: H({ value: t, bigIntDecimal: e, decimal: e }) | ||
}); | ||
} | ||
static shiftDecimals({ | ||
value: e, | ||
from: t, | ||
value: t, | ||
from: e, | ||
to: s | ||
}) { | ||
return this.fromBigInt( | ||
e.getBaseValue("bigint") * v(s) / v(t), | ||
t.getBaseValue("bigint") * v(s) / v(e), | ||
s | ||
); | ||
} | ||
set(e) { | ||
return new this.constructor({ decimal: this.decimal, value: e, identifier: this.toString() }); | ||
set(t) { | ||
return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() }); | ||
} | ||
add(...e) { | ||
return m(this, $, E).call(this, "add", ...e); | ||
add(...t) { | ||
return m(this, $, E).call(this, "add", ...t); | ||
} | ||
sub(...e) { | ||
return m(this, $, E).call(this, "sub", ...e); | ||
sub(...t) { | ||
return m(this, $, E).call(this, "sub", ...t); | ||
} | ||
mul(...e) { | ||
return m(this, $, E).call(this, "mul", ...e); | ||
mul(...t) { | ||
return m(this, $, E).call(this, "mul", ...t); | ||
} | ||
div(...e) { | ||
return m(this, $, E).call(this, "div", ...e); | ||
div(...t) { | ||
return m(this, $, E).call(this, "div", ...t); | ||
} | ||
gt(e) { | ||
return m(this, w, C).call(this, "gt", e); | ||
gt(t) { | ||
return m(this, w, C).call(this, "gt", t); | ||
} | ||
gte(e) { | ||
return m(this, w, C).call(this, "gte", e); | ||
gte(t) { | ||
return m(this, w, C).call(this, "gte", t); | ||
} | ||
lt(e) { | ||
return m(this, w, C).call(this, "lt", e); | ||
lt(t) { | ||
return m(this, w, C).call(this, "lt", t); | ||
} | ||
lte(e) { | ||
return m(this, w, C).call(this, "lte", e); | ||
lte(t) { | ||
return m(this, w, C).call(this, "lte", t); | ||
} | ||
eqValue(e) { | ||
return m(this, w, C).call(this, "eqValue", e); | ||
eqValue(t) { | ||
return m(this, w, C).call(this, "eqValue", t); | ||
} | ||
// @ts-expect-error False positive | ||
getValue(e) { | ||
const t = this.formatBigIntToSafeValue( | ||
getValue(t) { | ||
const e = this.formatBigIntToSafeValue( | ||
this.bigIntValue, | ||
this.decimal || I(this.decimalMultiplier) | ||
); | ||
switch (e) { | ||
switch (t) { | ||
case "number": | ||
return Number(t); | ||
return Number(e); | ||
case "string": | ||
return t; | ||
return e; | ||
case "bigint": | ||
@@ -787,5 +787,5 @@ return this.bigIntValue * 10n ** BigInt(this.decimal || 8n) / this.decimalMultiplier; | ||
// @ts-expect-error | ||
getBaseValue(e) { | ||
const t = this.decimalMultiplier / v(this.decimal || d.THOR), s = this.bigIntValue / t; | ||
switch (e) { | ||
getBaseValue(t) { | ||
const e = this.decimalMultiplier / v(this.decimal || d.THOR), s = this.bigIntValue / e; | ||
switch (t) { | ||
case "number": | ||
@@ -799,20 +799,20 @@ return Number(s); | ||
} | ||
getBigIntValue(e, t) { | ||
if (!t && typeof e == "object") | ||
return e.bigIntValue; | ||
const s = Y(e), n = q(s); | ||
return n === "0" || n === "undefined" ? 0n : m(this, k, W).call(this, n, t); | ||
getBigIntValue(t, e) { | ||
if (!e && typeof t == "object") | ||
return t.bigIntValue; | ||
const s = Y(t), n = q(s); | ||
return n === "0" || n === "undefined" ? 0n : m(this, k, W).call(this, n, e); | ||
} | ||
toSignificant(e = 6) { | ||
const [t, s] = this.getValue("string").split("."), n = t || "", a = s || ""; | ||
if ((parseInt(n) ? n.length + a.length : a.length) <= e) | ||
toSignificant(t = 6) { | ||
const [e, s] = this.getValue("string").split("."), n = e || "", a = s || ""; | ||
if ((parseInt(n) ? n.length + a.length : a.length) <= t) | ||
return this.getValue("string"); | ||
if (n.length >= e) | ||
return n.slice(0, e).padEnd(n.length, "0"); | ||
if (n.length >= t) | ||
return n.slice(0, t).padEnd(n.length, "0"); | ||
if (parseInt(n)) | ||
return `${n}.${a.slice(0, e - n.length)}`.padEnd( | ||
e - n.length, | ||
return `${n}.${a.slice(0, t - n.length)}`.padEnd( | ||
t - n.length, | ||
"0" | ||
); | ||
const c = parseInt(a), u = `${c}`.slice(0, e); | ||
const c = parseInt(a), u = `${c}`.slice(0, t); | ||
return `0.${u.padStart( | ||
@@ -823,7 +823,7 @@ a.length - `${c}`.length + u.length, | ||
} | ||
toFixed(e = 6) { | ||
const [t, s] = this.getValue("string").split("."), n = t || "", a = s || ""; | ||
toFixed(t = 6) { | ||
const [e, s] = this.getValue("string").split("."), n = e || "", a = s || ""; | ||
if (parseInt(n)) | ||
return `${n}.${a.slice(0, e)}`.padEnd(e, "0"); | ||
const o = parseInt(a), c = `${o}`.slice(0, e); | ||
return `${n}.${a.slice(0, t)}`.padEnd(t, "0"); | ||
const o = parseInt(a), c = `${o}`.slice(0, t); | ||
return `0.${c.padStart( | ||
@@ -834,11 +834,11 @@ a.length - `${o}`.length + c.length, | ||
} | ||
toAbbreviation(e = 2) { | ||
const t = this.getValue("number"), s = ["", "K", "M", "B", "T", "Q", "Qi", "S"], n = Math.floor(Math.log10(Math.abs(t)) / 3), a = s[n]; | ||
toAbbreviation(t = 2) { | ||
const e = this.getValue("number"), s = ["", "K", "M", "B", "T", "Q", "Qi", "S"], n = Math.floor(Math.log10(Math.abs(e)) / 3), a = s[n]; | ||
if (!a) | ||
return this.getValue("string"); | ||
const o = 10 ** (n * 3); | ||
return `${(t / o).toFixed(e)}${a}`; | ||
return `${(e / o).toFixed(t)}${a}`; | ||
} | ||
toCurrency(e = "$", { | ||
currencyPosition: t = "start", | ||
toCurrency(t = "$", { | ||
currencyPosition: e = "start", | ||
decimal: s = 2, | ||
@@ -849,9 +849,9 @@ decimalSeparator: n = ".", | ||
const o = this.getValue("number"), [c, u = ""] = o.toFixed(6).split("."), h = c.replace(/\B(?=(\d{3})+(?!\d))/g, a), l = !c && !u ? "0.00" : c === "0" ? `${parseFloat(`0.${u}`)}`.replace(".", n) : `${h}${parseInt(u) ? `${n}${u.slice(0, s)}` : ""}`; | ||
return `${t === "start" ? e : ""}${l}${t === "end" ? e : ""}`; | ||
return `${e === "start" ? t : ""}${l}${e === "end" ? t : ""}`; | ||
} | ||
formatBigIntToSafeValue(e, t) { | ||
const s = t || this.decimal || O, n = Math.max( | ||
formatBigIntToSafeValue(t, e) { | ||
const s = e || this.decimal || O, n = Math.max( | ||
s, | ||
I(this.decimalMultiplier) | ||
), a = e < 0n, o = e.toString().substring(a ? 1 : 0), c = n - (o.length - 1), u = c > 0 ? "0".repeat(c) + o : o, h = u.length - n; | ||
), a = t < 0n, o = t.toString().substring(a ? 1 : 0), c = n - (o.length - 1), u = c > 0 ? "0".repeat(c) + o : o, h = u.length - n; | ||
let l = u.slice(-n); | ||
@@ -864,7 +864,7 @@ return parseInt(l[s]) >= 5 ? l = `${l.substring(0, s - 1)}${(parseInt(l[s - 1]) + 1).toString()}` : l = l.substring(0, s), `${a ? "-" : ""}${u.slice( | ||
}; | ||
$ = new WeakSet(), E = function(e, ...t) { | ||
const s = m(this, M, G).call(this, this, ...t), n = Math.max(s, I(this.decimalMultiplier)), a = v(n), o = t.reduce( | ||
$ = new WeakSet(), E = function(t, ...e) { | ||
const s = m(this, M, G).call(this, this, ...e), n = Math.max(s, I(this.decimalMultiplier)), a = v(n), o = e.reduce( | ||
(u, h) => { | ||
const l = this.getBigIntValue(h, n); | ||
switch (e) { | ||
switch (t) { | ||
case "add": | ||
@@ -898,5 +898,5 @@ return u + l; | ||
}); | ||
}, w = new WeakSet(), C = function(e, ...t) { | ||
const s = m(this, M, G).call(this, this, ...t), n = this.getBigIntValue(t[0], s), a = this.getBigIntValue(this, s); | ||
switch (e) { | ||
}, w = new WeakSet(), C = function(t, ...e) { | ||
const s = m(this, M, G).call(this, this, ...e), n = this.getBigIntValue(e[0], s), a = this.getBigIntValue(this, s); | ||
switch (t) { | ||
case "gt": | ||
@@ -913,14 +913,14 @@ return a > n; | ||
} | ||
}, j = new WeakSet(), me = function(e) { | ||
const t = q(e) || "0"; | ||
this.bigIntValue = m(this, k, W).call(this, t); | ||
}, M = new WeakSet(), G = function(...e) { | ||
const t = e.map((s) => typeof s == "object" ? s.decimal || I(s.decimalMultiplier) : re(q(s))).filter(Boolean); | ||
return Math.max(...t, O); | ||
}, k = new WeakSet(), W = function(e, t) { | ||
const s = t ? v(t) : this.decimalMultiplier, n = I(s), [a = "", o = ""] = e.split("."); | ||
}, j = new WeakSet(), mt = function(t) { | ||
const e = q(t) || "0"; | ||
this.bigIntValue = m(this, k, W).call(this, e); | ||
}, M = new WeakSet(), G = function(...t) { | ||
const e = t.map((s) => typeof s == "object" ? s.decimal || I(s.decimalMultiplier) : rt(q(s))).filter(Boolean); | ||
return Math.max(...e, O); | ||
}, k = new WeakSet(), W = function(t, e) { | ||
const s = e ? v(e) : this.decimalMultiplier, n = I(s), [a = "", o = ""] = t.split("."); | ||
return BigInt(`${a}${o.padEnd(n, "0")}`); | ||
}; | ||
let B = Z; | ||
const st = Intl.NumberFormat("fullwide", { | ||
const se = Intl.NumberFormat("fullwide", { | ||
useGrouping: !1, | ||
@@ -930,9 +930,9 @@ maximumFractionDigits: 20 | ||
function q(r) { | ||
const t = `${typeof r == "number" ? st.format(r) : Y(r)}`.replaceAll(",", ".").split("."); | ||
return t.length > 1 ? `${t.slice(0, -1).join("")}.${t.at(-1)}` : t[0]; | ||
const e = `${typeof r == "number" ? se.format(r) : Y(r)}`.replaceAll(",", ".").split("."); | ||
return e.length > 1 ? `${e.slice(0, -1).join("")}.${e.at(-1)}` : e[0]; | ||
} | ||
function re(r) { | ||
var t; | ||
const e = ((t = r.split(".")[1]) == null ? void 0 : t.length) || 0; | ||
return Math.max(e, O); | ||
function rt(r) { | ||
var e; | ||
const t = ((e = r.split(".")[1]) == null ? void 0 : e.length) || 0; | ||
return Math.max(t, O); | ||
} | ||
@@ -942,18 +942,18 @@ function Y(r) { | ||
} | ||
const P = (r, e) => typeof r == "bigint" ? H({ value: r, bigIntDecimal: e, decimal: e }) : r; | ||
const P = (r, t) => typeof r == "bigint" ? H({ value: r, bigIntDecimal: t, decimal: t }) : r; | ||
let z; | ||
const ne = (r) => { | ||
const nt = (r) => { | ||
if (!z) | ||
throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first"); | ||
return z.get(r.toUpperCase()) || { decimal: d.THOR, identifier: "" }; | ||
}, ie = async (r, e = 0) => { | ||
tt(r); | ||
const t = await Ce(J(r)), s = P(e, t); | ||
return new T({ decimal: t, value: s, identifier: r }); | ||
}, it = async (r, t = 0) => { | ||
ee(r); | ||
const e = await Ct(J(r)), s = P(t, e); | ||
return new T({ decimal: e, value: s, identifier: r }); | ||
}; | ||
class T extends B { | ||
constructor(t) { | ||
const s = "identifier" in t ? t.identifier : `${t.chain}.${t.symbol}`; | ||
constructor(e) { | ||
const s = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`; | ||
super( | ||
t.value instanceof B ? t.value : { decimal: t.decimal, value: t.value } | ||
e.value instanceof B ? e.value : { decimal: e.decimal, value: e.value } | ||
); | ||
@@ -970,7 +970,7 @@ _(this, "address"); | ||
const n = J(s); | ||
console.log("assetInfo: ", n), this.type = Ee(n), this.chain = n.chain, this.ticker = n.ticker, this.symbol = n.symbol, this.address = n.address, this.isSynthetic = n.isSynthetic, this.isGasAsset = n.isGasAsset, this.tax = t.tax; | ||
console.log("assetInfo: ", n), this.type = Et(n), this.chain = n.chain, this.ticker = n.ticker, this.symbol = n.symbol, this.address = n.address, this.isSynthetic = n.isSynthetic, this.isGasAsset = n.isGasAsset, this.tax = e.tax; | ||
} | ||
toString(t = !1) { | ||
toString(e = !1) { | ||
const s = this.isSynthetic ? this.symbol : this.ticker; | ||
return t ? ( | ||
return e ? ( | ||
// ETH/THOR-0xa5f2211b9b8170f694421f2046281775e8468044 | USDT | ||
@@ -986,10 +986,54 @@ s | ||
} | ||
eq({ chain: t, symbol: s }) { | ||
return this.chain === t && this.symbol === s; | ||
eq({ chain: e, symbol: s }) { | ||
return this.chain === e && this.symbol === s; | ||
} | ||
static async fromString(t, s = 0) { | ||
return ie(t, s); | ||
static async fromString(e, s = 0) { | ||
return it(e, s); | ||
} | ||
static fromStringSync(t, s = 0) { | ||
const { isSynthetic: n, symbol: a, chain: o, isGasAsset: c, ticker: u, address: h } = J(t); | ||
// static fromStringSync(assetString: string, value: NumberPrimitives = 0) { | ||
// const { isSynthetic, symbol, chain, isGasAsset, ticker, address } = getAssetInfo(assetString); | ||
// console.log('getAssetInfo: ', { isSynthetic, symbol, chain, isGasAsset, ticker, address }); | ||
// const { tax, decimal, identifier: tokenIdentifier } = getStaticToken(assetString as unknown as TokenNames); | ||
// console.log('getStaticToken: ', { tax, decimal, tokenIdentifier }); | ||
// | ||
// // Convert value to a BigInt if necessary | ||
// let safeValue = (val: NumberPrimitives, decimal: number): BigInt => { | ||
// if (typeof val === 'bigint') { | ||
// return val; | ||
// } else if (typeof val === 'number') { | ||
// return BigInt(val * Math.pow(10, decimal)); | ||
// } else { | ||
// return BigInt(0); | ||
// } | ||
// }; | ||
// | ||
// const parsedValue = safeValue(value, decimal); | ||
// console.log('parsedValue: ', parsedValue); | ||
// | ||
// let asset: AssetValue | undefined; | ||
// | ||
// if (tokenIdentifier) { | ||
// console.log('tokenIdentifier is truthy'); // Indicates tokenIdentifier has a value considered true in a boolean context | ||
// asset = new AssetValue({ | ||
// tax, | ||
// decimal, | ||
// identifier: tokenIdentifier, | ||
// value: parsedValue, | ||
// }); | ||
// } else if (isSynthetic) { | ||
// console.log('isSynthetic is true'); // Indicates the asset is synthetic | ||
// asset = new AssetValue({ | ||
// tax, | ||
// decimal: 8, // Synthetic assets use a fixed decimal value | ||
// identifier: assetString, | ||
// value: parsedValue, | ||
// }); | ||
// } else { | ||
// asset = undefined; | ||
// } | ||
// | ||
// return asset; | ||
// } | ||
static fromStringSync(e, s = 0) { | ||
const { isSynthetic: n, symbol: a, chain: o, isGasAsset: c, ticker: u, address: h } = J(e); | ||
console.log("getAssetInfo: ", { isSynthetic: n, symbol: a, chain: o, isGasAsset: c, ticker: u, address: h }); | ||
@@ -1000,5 +1044,5 @@ const { | ||
identifier: g | ||
} = ne(t); | ||
} = nt(e); | ||
console.log("getStaticToken: ", { tax: l, decimal: f, tokenIdentifier: g }); | ||
const A = P(s, f); | ||
const A = s === 0 ? BigInt(0) : P(s, f); | ||
console.log("parsedValue: ", A); | ||
@@ -1015,17 +1059,17 @@ let R; | ||
// Synthetic assets use a fixed decimal value | ||
identifier: t, | ||
identifier: e, | ||
value: A | ||
})) : R = void 0, R; | ||
} | ||
static async fromIdentifier(t, s = 0) { | ||
return ie(t, s); | ||
static async fromIdentifier(e, s = 0) { | ||
return it(e, s); | ||
} | ||
static fromIdentifierSync(t, s = 0) { | ||
const { decimal: n, identifier: a } = ne(t), o = P(s, n); | ||
static fromIdentifierSync(e, s = 0) { | ||
const { decimal: n, identifier: a } = nt(e), o = P(s, n); | ||
return new T({ decimal: n, identifier: a, value: o }); | ||
} | ||
static fromChainOrSignature(t, s = 0) { | ||
const { decimal: n, identifier: a } = Ie(t); | ||
static fromChainOrSignature(e, s = 0) { | ||
const { decimal: n, identifier: a } = It(e); | ||
if (!n || !a) | ||
throw Error("unknown coin! " + t); | ||
throw Error("unknown coin! " + e); | ||
const o = P(s, n); | ||
@@ -1036,3 +1080,3 @@ return new T({ value: o, decimal: n, identifier: a }); | ||
return new Promise( | ||
async (t, s) => { | ||
async (e, s) => { | ||
try { | ||
@@ -1052,3 +1096,3 @@ const { | ||
/* @__PURE__ */ new Map() | ||
), t({ ok: !0 }); | ||
), e({ ok: !0 }); | ||
} catch (n) { | ||
@@ -1065,4 +1109,4 @@ console.error(n), s({ | ||
} | ||
const bt = (r) => { | ||
const e = T.fromChainOrSignature(r); | ||
const be = (r) => { | ||
const t = T.fromChainOrSignature(r); | ||
switch (r) { | ||
@@ -1074,5 +1118,5 @@ case i.Bitcoin: | ||
case i.BitcoinCash: | ||
return e.set(10001e-8); | ||
return t.set(10001e-8); | ||
case i.Dogecoin: | ||
return e.set(1.00000001); | ||
return t.set(1.00000001); | ||
case i.Base: | ||
@@ -1082,20 +1126,20 @@ case i.Arbitrum: | ||
case i.Ethereum: | ||
return e.set(1e-8); | ||
return t.set(1e-8); | ||
case i.THORChain: | ||
case i.Mayachain: | ||
return e.set(1e-10); | ||
return t.set(1e-10); | ||
default: | ||
return e.set(1e-8); | ||
return t.set(1e-8); | ||
} | ||
}, J = (r) => { | ||
const e = r.slice(0, 14).includes("/"), [t, s] = r.split(".").pop().split("/"), n = r.includes(".") && !e ? r : `${i.THORChain}.${s}`, [a, o] = n.split("."), [c, u] = (e ? s : o).split("-"); | ||
const t = r.slice(0, 14).includes("/"), [e, s] = r.split(".").pop().split("/"), n = r.includes(".") && !t ? r : `${i.THORChain}.${s}`, [a, o] = n.split("."), [c, u] = (t ? s : o).split("-"); | ||
return { | ||
address: u == null ? void 0 : u.toLowerCase(), | ||
chain: a, | ||
isGasAsset: oe({ chain: a, symbol: o }), | ||
isSynthetic: e, | ||
symbol: (e ? `${t}/` : "") + (u ? `${c}-${(u == null ? void 0 : u.toLowerCase()) ?? ""}` : o), | ||
isGasAsset: ot({ chain: a, symbol: o }), | ||
isSynthetic: t, | ||
symbol: (t ? `${e}/` : "") + (u ? `${c}-${(u == null ? void 0 : u.toLowerCase()) ?? ""}` : o), | ||
ticker: c | ||
}; | ||
}, rt = { | ||
}, re = { | ||
/** | ||
@@ -1159,15 +1203,15 @@ * Core | ||
}; | ||
class pe extends Error { | ||
constructor(e, t) { | ||
console.error(t, { stack: t == null ? void 0 : t.stack, message: t == null ? void 0 : t.message }), super(e, { cause: { code: rt[e], message: e } }), Object.setPrototypeOf(this, pe.prototype); | ||
class pt extends Error { | ||
constructor(t, e) { | ||
console.error(e, { stack: e == null ? void 0 : e.stack, message: e == null ? void 0 : e.message }), super(t, { cause: { code: re[t], message: t } }), Object.setPrototypeOf(this, pt.prototype); | ||
} | ||
} | ||
class y extends B { | ||
eq(e) { | ||
return this.eqValue(e); | ||
eq(t) { | ||
return this.eqValue(t); | ||
} | ||
static fromBigInt(e, t) { | ||
static fromBigInt(t, e) { | ||
return new y({ | ||
decimal: t, | ||
value: H({ value: e, bigIntDecimal: t, decimal: t }) | ||
decimal: e, | ||
value: H({ value: t, bigIntDecimal: e, decimal: e }) | ||
}); | ||
@@ -1179,26 +1223,26 @@ } | ||
B as BigIntArithmetics, | ||
et as RequestClient, | ||
pe as SwapKitError, | ||
te as RequestClient, | ||
pt as SwapKitError, | ||
y as SwapKitNumber, | ||
ot as assetFromString, | ||
gt as derivationPathToString, | ||
ct as filterAssets, | ||
oe as assetFromString, | ||
ge as derivationPathToString, | ||
ce as filterAssets, | ||
H as formatBigIntToSafeValue, | ||
at as gasFeeMultiplier, | ||
Ee as getAssetType, | ||
ke as getAsymmetricAssetShare, | ||
lt as getAsymmetricAssetWithdrawAmount, | ||
Me as getAsymmetricRuneShare, | ||
ut as getAsymmetricRuneWithdrawAmount, | ||
Ie as getCommonAssetInfo, | ||
Ce as getDecimal, | ||
dt as getEstimatedPoolShare, | ||
mt as getLiquiditySlippage, | ||
pt as getMemoFor, | ||
bt as getMinAmountByChain, | ||
xe as getSymmetricPoolShare, | ||
ht as getSymmetricWithdraw, | ||
ft as getTHORNameCost, | ||
oe as isGasAsset, | ||
_t as validateTHORName | ||
ae as gasFeeMultiplier, | ||
Et as getAssetType, | ||
kt as getAsymmetricAssetShare, | ||
le as getAsymmetricAssetWithdrawAmount, | ||
Mt as getAsymmetricRuneShare, | ||
ue as getAsymmetricRuneWithdrawAmount, | ||
It as getCommonAssetInfo, | ||
Ct as getDecimal, | ||
de as getEstimatedPoolShare, | ||
me as getLiquiditySlippage, | ||
pe as getMemoFor, | ||
be as getMinAmountByChain, | ||
xt as getSymmetricPoolShare, | ||
he as getSymmetricWithdraw, | ||
fe as getTHORNameCost, | ||
ot as isGasAsset, | ||
_e as validateTHORName | ||
}; |
@@ -11,5 +11,5 @@ { | ||
"vitest": "0.34.6", | ||
"@internal/config": "2.7.18", | ||
"@coinmasters/tokens": "3.7.18", | ||
"@coinmasters/types": "4.7.18" | ||
"@internal/config": "2.7.20", | ||
"@coinmasters/types": "4.7.20", | ||
"@coinmasters/tokens": "3.7.20" | ||
}, | ||
@@ -20,4 +20,4 @@ "eslintConfig": { | ||
"peerDependencies": { | ||
"@coinmasters/tokens": "3.7.18", | ||
"@coinmasters/types": "4.7.18" | ||
"@coinmasters/types": "4.7.20", | ||
"@coinmasters/tokens": "3.7.20" | ||
}, | ||
@@ -47,3 +47,3 @@ "exports": { | ||
"types": "./dist/index.d.ts", | ||
"version": "11.0.18", | ||
"version": "11.0.20", | ||
"scripts": { | ||
@@ -50,0 +50,0 @@ "build": "vite build", |
@@ -133,2 +133,48 @@ import type { | ||
// static fromStringSync(assetString: string, value: NumberPrimitives = 0) { | ||
// const { isSynthetic, symbol, chain, isGasAsset, ticker, address } = getAssetInfo(assetString); | ||
// console.log('getAssetInfo: ', { isSynthetic, symbol, chain, isGasAsset, ticker, address }); | ||
// const { tax, decimal, identifier: tokenIdentifier } = getStaticToken(assetString as unknown as TokenNames); | ||
// console.log('getStaticToken: ', { tax, decimal, tokenIdentifier }); | ||
// | ||
// // Convert value to a BigInt if necessary | ||
// let safeValue = (val: NumberPrimitives, decimal: number): BigInt => { | ||
// if (typeof val === 'bigint') { | ||
// return val; | ||
// } else if (typeof val === 'number') { | ||
// return BigInt(val * Math.pow(10, decimal)); | ||
// } else { | ||
// return BigInt(0); | ||
// } | ||
// }; | ||
// | ||
// const parsedValue = safeValue(value, decimal); | ||
// console.log('parsedValue: ', parsedValue); | ||
// | ||
// let asset: AssetValue | undefined; | ||
// | ||
// if (tokenIdentifier) { | ||
// console.log('tokenIdentifier is truthy'); // Indicates tokenIdentifier has a value considered true in a boolean context | ||
// asset = new AssetValue({ | ||
// tax, | ||
// decimal, | ||
// identifier: tokenIdentifier, | ||
// value: parsedValue, | ||
// }); | ||
// } else if (isSynthetic) { | ||
// console.log('isSynthetic is true'); // Indicates the asset is synthetic | ||
// asset = new AssetValue({ | ||
// tax, | ||
// decimal: 8, // Synthetic assets use a fixed decimal value | ||
// identifier: assetString, | ||
// value: parsedValue, | ||
// }); | ||
// } else { | ||
// asset = undefined; | ||
// } | ||
// | ||
// return asset; | ||
// } | ||
static fromStringSync(assetString: string, value: NumberPrimitives = 0) { | ||
@@ -143,3 +189,3 @@ const { isSynthetic, symbol, chain, isGasAsset, ticker, address } = getAssetInfo(assetString); | ||
console.log('getStaticToken: ', { tax, decimal, tokenIdentifier }); | ||
const parsedValue = safeValue(value, decimal); | ||
const parsedValue = value === 0 ? BigInt(0) : safeValue(value, decimal); | ||
console.log('parsedValue: ', parsedValue); | ||
@@ -146,0 +192,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
236728
3984