@swapkit/helpers
Advanced tools
Comparing version 1.0.0-rc.27 to 1.0.0-rc.28
@@ -1,17 +0,17 @@ | ||
var gt = Object.defineProperty; | ||
var bt = (r, t, e) => t in r ? gt(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e; | ||
var p = (r, t, e) => (bt(r, typeof t != "symbol" ? t + "" : t, e), e), yt = (r, t, e) => { | ||
if (!t.has(r)) | ||
var _t = Object.defineProperty; | ||
var gt = (s, t, e) => t in s ? _t(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e; | ||
var p = (s, t, e) => (gt(s, typeof t != "symbol" ? t + "" : t, e), e), bt = (s, t, e) => { | ||
if (!t.has(s)) | ||
throw TypeError("Cannot " + e); | ||
}; | ||
var T = (r, t, e) => { | ||
if (t.has(r)) | ||
var T = (s, t, e) => { | ||
if (t.has(s)) | ||
throw TypeError("Cannot add the same private member more than once"); | ||
t instanceof WeakSet ? t.add(r) : t.set(r, e); | ||
t instanceof WeakSet ? t.add(s) : t.set(s, e); | ||
}; | ||
var f = (r, t, e) => (yt(r, t, "access private method"), e); | ||
import { FeeOption as H, BaseDecimal as d, Chain as o, EVMChainList as wt, ChainToRPC as At, MemoType as g } from "@swapkit/types"; | ||
const vt = "0x313ce567", nt = async ({ chain: r, to: t }) => { | ||
var f = (s, t, e) => (bt(s, t, "access private method"), e); | ||
import { FeeOption as H, BaseDecimal as d, Chain as o, EVMChainList as yt, ChainToRPC as wt, MemoType as g } from "@swapkit/types"; | ||
const At = "0x313ce567", st = async ({ chain: s, to: t }) => { | ||
try { | ||
const { result: e } = await Xt.post(At[r], { | ||
const { result: e } = await Qt.post(wt[s], { | ||
headers: { | ||
@@ -26,3 +26,3 @@ accept: "*/*", | ||
method: "eth_call", | ||
params: [{ to: t.toLowerCase(), data: vt }, "latest"] | ||
params: [{ to: t.toLowerCase(), data: At }, "latest"] | ||
}) | ||
@@ -32,29 +32,29 @@ }); | ||
} catch (e) { | ||
return console.error(e), d[r]; | ||
return console.error(e), d[s]; | ||
} | ||
}, Tt = async (r) => { | ||
if (r === o.Ethereum) | ||
}, vt = async (s) => { | ||
if (s === o.Ethereum) | ||
return d.ETH; | ||
const [, t] = r.split("-"); | ||
return t != null && t.startsWith("0x") ? nt({ chain: o.Ethereum, to: t }) : d.ETH; | ||
}, $t = async (r) => { | ||
const [, t] = r.split("-"); | ||
return t != null && t.startsWith("0x") ? nt({ chain: o.Avalanche, to: t.toLowerCase() }) : d.AVAX; | ||
}, Rt = async (r) => r === o.BinanceSmartChain ? d.BSC : d.BSC, St = async ({ chain: r, symbol: t }) => { | ||
switch (r) { | ||
const [, t] = s.split("-"); | ||
return t != null && t.startsWith("0x") ? st({ chain: o.Ethereum, to: t }) : d.ETH; | ||
}, Tt = async (s) => { | ||
const [, t] = s.split("-"); | ||
return t != null && t.startsWith("0x") ? st({ chain: o.Avalanche, to: t.toLowerCase() }) : d.AVAX; | ||
}, $t = async (s) => s === o.BinanceSmartChain ? d.BSC : d.BSC, Rt = async ({ chain: s, symbol: t }) => { | ||
switch (s) { | ||
case o.Ethereum: | ||
return vt(t); | ||
case o.Avalanche: | ||
return Tt(t); | ||
case o.Avalanche: | ||
case o.BinanceSmartChain: | ||
return $t(t); | ||
case o.BinanceSmartChain: | ||
return Rt(t); | ||
default: | ||
return d[r]; | ||
return d[s]; | ||
} | ||
}, ne = { | ||
}, se = { | ||
[H.Average]: 1.2, | ||
[H.Fast]: 1.5, | ||
[H.Fastest]: 2 | ||
}, it = ({ chain: r, symbol: t }) => { | ||
switch (r) { | ||
}, nt = ({ chain: s, symbol: t }) => { | ||
switch (s) { | ||
case o.Bitcoin: | ||
@@ -67,3 +67,3 @@ case o.BitcoinCash: | ||
case o.Avalanche: | ||
return t === r; | ||
return t === s; | ||
case o.Arbitrum: | ||
@@ -85,4 +85,4 @@ case o.Optimism: | ||
} | ||
}, Ct = (r) => { | ||
switch (r) { | ||
}, St = (s) => { | ||
switch (s) { | ||
case "ETH.THOR": | ||
@@ -93,7 +93,7 @@ return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 }; | ||
case o.Cosmos: | ||
return { identifier: "GAIA.ATOM", decimal: d[r] }; | ||
return { identifier: "GAIA.ATOM", decimal: d[s] }; | ||
case o.THORChain: | ||
return { identifier: "THOR.RUNE", decimal: d[r] }; | ||
return { identifier: "THOR.RUNE", decimal: d[s] }; | ||
case o.BinanceSmartChain: | ||
return { identifier: "BSC.BNB", decimal: d[r] }; | ||
return { identifier: "BSC.BNB", decimal: d[s] }; | ||
case o.Maya: | ||
@@ -114,8 +114,8 @@ return { identifier: "MAYA.CACAO", decimal: d.MAYA }; | ||
case o.Ethereum: | ||
return { identifier: `${r}.${r}`, decimal: d[r] }; | ||
return { identifier: `${s}.${s}`, decimal: d[s] }; | ||
} | ||
}, It = ({ chain: r, symbol: t }) => { | ||
}, Ct = ({ chain: s, symbol: t }) => { | ||
if (t.includes("/")) | ||
return "Synth"; | ||
switch (r) { | ||
switch (s) { | ||
case o.Bitcoin: | ||
@@ -147,114 +147,114 @@ case o.BitcoinCash: | ||
} | ||
}, ie = (r) => { | ||
}, ne = (s) => { | ||
var c; | ||
const [t, ...e] = r.split("."), s = r.includes("/"), n = e.join("."), i = (c = n == null ? void 0 : n.split("-")) == null ? void 0 : c[0]; | ||
return { chain: t, symbol: n, ticker: i, synth: s }; | ||
}, Et = new RegExp( | ||
const [t, ...e] = s.split("."), r = s.includes("/"), n = e.join("."), i = (c = n == null ? void 0 : n.split("-")) == null ? void 0 : c[0]; | ||
return { chain: t, symbol: n, ticker: i, synth: r }; | ||
}, It = new RegExp( | ||
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/, | ||
"gmi" | ||
), Ot = (r) => { | ||
const [t, e] = r.split("."); | ||
if (!wt.includes(t)) | ||
), Et = (s) => { | ||
const [t, e] = s.split("."); | ||
if (!yt.includes(t)) | ||
return !0; | ||
const [, s] = e.split("-"); | ||
return it({ chain: t, symbol: e }) || !!s; | ||
}, oe = (r) => r.filter((t) => { | ||
const [, r] = e.split("-"); | ||
return nt({ chain: t, symbol: e }) || !!r; | ||
}, ie = (s) => s.filter((t) => { | ||
const e = `${t.chain}.${t.symbol}`; | ||
return !Et.test(e) && Ot(e) && t.value !== "0"; | ||
}), Bt = ({ | ||
liquidityUnits: r, | ||
return !It.test(e) && Et(e) && t.value !== "0"; | ||
}), Ot = ({ | ||
liquidityUnits: s, | ||
poolUnits: t, | ||
runeDepth: e | ||
}) => { | ||
const s = m(r), n = m(t), i = m(e), c = s.mul(i), a = n.mul(n).mul(2), u = n.mul(s).mul(2), l = s.mul(s), h = n.mul(n).mul(n); | ||
const r = m(s), n = m(t), i = m(e), c = r.mul(i), a = n.mul(n).mul(2), u = n.mul(r).mul(2), l = r.mul(r), h = n.mul(n).mul(n); | ||
return c.mul(a.sub(u).add(l)).div(h); | ||
}, Mt = ({ | ||
liquidityUnits: r, | ||
}, Bt = ({ | ||
liquidityUnits: s, | ||
poolUnits: t, | ||
assetDepth: e | ||
}) => { | ||
const s = m(r), n = m(t), i = m(e), c = s.mul(i), a = n.mul(n).mul(2), u = n.mul(s).mul(2), l = s.mul(s), h = c.mul(a.sub(u).add(l)), _ = n.mul(n).mul(n); | ||
const r = m(s), n = m(t), i = m(e), c = r.mul(i), a = n.mul(n).mul(2), u = n.mul(r).mul(2), l = r.mul(r), h = c.mul(a.sub(u).add(l)), _ = n.mul(n).mul(n); | ||
return h.div(_); | ||
}, ae = ({ | ||
percent: r, | ||
}, oe = ({ | ||
percent: s, | ||
runeDepth: t, | ||
liquidityUnits: e, | ||
poolUnits: s | ||
}) => Bt({ runeDepth: t, liquidityUnits: e, poolUnits: s }).mul(r), ce = ({ | ||
percent: r, | ||
poolUnits: r | ||
}) => Ot({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), ae = ({ | ||
percent: s, | ||
assetDepth: t, | ||
liquidityUnits: e, | ||
poolUnits: s | ||
}) => Mt({ assetDepth: t, liquidityUnits: e, poolUnits: s }).mul(r), m = (r) => b.fromBigInt(BigInt(r), d.THOR), Vt = ({ | ||
liquidityUnits: r, | ||
poolUnits: r | ||
}) => Bt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), m = (s) => b.fromBigInt(BigInt(s), d.THOR), Mt = ({ | ||
liquidityUnits: s, | ||
poolUnits: t, | ||
runeDepth: e, | ||
assetDepth: s | ||
assetDepth: r | ||
}) => ({ | ||
assetAmount: m(s).mul(r).div(t), | ||
runeAmount: m(e).mul(r).div(t) | ||
}), ue = ({ | ||
liquidityUnits: r, | ||
assetAmount: m(r).mul(s).div(t), | ||
runeAmount: m(e).mul(s).div(t) | ||
}), ce = ({ | ||
liquidityUnits: s, | ||
poolUnits: t, | ||
runeDepth: e, | ||
assetDepth: s, | ||
assetDepth: r, | ||
percent: n | ||
}) => Object.fromEntries( | ||
Object.entries(Vt({ liquidityUnits: r, poolUnits: t, runeDepth: e, assetDepth: s })).map( | ||
Object.entries(Mt({ liquidityUnits: s, poolUnits: t, runeDepth: e, assetDepth: r })).map( | ||
([i, c]) => [i, c.mul(n)] | ||
) | ||
), le = ({ | ||
runeDepth: r, | ||
), ue = ({ | ||
runeDepth: s, | ||
poolUnits: t, | ||
assetDepth: e, | ||
liquidityUnits: s, | ||
liquidityUnits: r, | ||
runeAmount: n, | ||
assetAmount: i | ||
}) => { | ||
const c = new b({ value: r, decimal: 8 }), a = new b({ value: e, decimal: 8 }), u = new b({ value: t, decimal: 8 }), l = new b({ value: n, decimal: 8 }), h = new b({ value: i, decimal: 8 }), _ = l.mul(a), A = h.mul(c), N = l.mul(h), mt = c.mul(a), pt = u.mul(_.add(A.add(N.mul(2)))), ft = _.add(A.add(mt.mul(2))), J = pt.div(ft), j = m(s).add(J); | ||
const c = new b({ value: s, decimal: 8 }), a = new b({ value: e, decimal: 8 }), u = new b({ value: t, decimal: 8 }), l = new b({ value: n, decimal: 8 }), h = new b({ value: i, decimal: 8 }), _ = l.mul(a), A = h.mul(c), N = l.mul(h), dt = c.mul(a), mt = u.mul(_.add(A.add(N.mul(2)))), pt = _.add(A.add(dt.mul(2))), J = mt.div(pt), j = m(r).add(J); | ||
if (J.getBaseValue("number") === 0) | ||
return j.div(u).getBaseValue("number"); | ||
const _t = u.add(j); | ||
return j.div(_t).getBaseValue("number"); | ||
}, he = ({ | ||
runeAmount: r, | ||
const ft = u.add(j); | ||
return j.div(ft).getBaseValue("number"); | ||
}, le = ({ | ||
runeAmount: s, | ||
assetAmount: t, | ||
runeDepth: e, | ||
assetDepth: s | ||
assetDepth: r | ||
}) => { | ||
if (r === "0" || t === "0" || e === "0" || s === "0") | ||
if (s === "0" || t === "0" || e === "0" || r === "0") | ||
return 0; | ||
const n = m(e), i = m(s), c = m(t), a = m(r), u = c.mul(n).sub(i.mul(a)), l = i.mul(a).add(n.mul(i)); | ||
const n = m(e), i = m(r), c = m(t), a = m(s), u = c.mul(n).sub(i.mul(a)), l = i.mul(a).add(n.mul(i)); | ||
return Math.abs(u.div(l).getBaseValue("number")); | ||
}, qt = ({ | ||
symbol: r, | ||
}, Vt = ({ | ||
symbol: s, | ||
ticker: t, | ||
chain: e | ||
}) => e === "ETH" && t !== "ETH" ? `${t}-${r.slice(-3)}` : r, de = (r, t) => { | ||
switch (r) { | ||
}) => e === "ETH" && t !== "ETH" ? `${t}-${s.slice(-3)}` : s, he = (s, t) => { | ||
switch (s) { | ||
case g.LEAVE: | ||
case g.BOND: { | ||
const { address: e } = t; | ||
return `${r}:${e}`; | ||
return `${s}:${e}`; | ||
} | ||
case g.UNBOND: { | ||
const { address: e, unbondAmount: s } = t; | ||
return `${r}:${e}:${s * 10 ** 8}`; | ||
const { address: e, unbondAmount: r } = t; | ||
return `${s}:${e}:${r * 10 ** 8}`; | ||
} | ||
case g.THORNAME_REGISTER: { | ||
const { name: e, chain: s, address: n, owner: i } = t; | ||
return `${r}:${e}:${s}:${n}${i ? `:${i}` : ""}`; | ||
const { name: e, chain: r, address: n, owner: i } = t; | ||
return `${s}:${e}:${r}:${n}${i ? `:${i}` : ""}`; | ||
} | ||
case g.DEPOSIT: { | ||
const { chain: e, symbol: s, address: n, singleSide: i } = t; | ||
return i ? `${r}:${e}/${s}::t:0` : `${r}:${e}.${s}:${n || ""}:t:0`; | ||
const { chain: e, symbol: r, address: n, singleSide: i } = t; | ||
return i ? `${s}:${e}/${r}::t:0` : `${s}:${e}.${r}:${n || ""}:t:0`; | ||
} | ||
case g.WITHDRAW: { | ||
const { chain: e, ticker: s, symbol: n, basisPoints: i, targetAssetString: c, singleSide: a } = t, u = !a && c ? `:${c}` : "", l = qt({ chain: e, symbol: n, ticker: s }); | ||
return `${r}:${e}${a ? "/" : "."}${l}:${i}${u}`; | ||
const { chain: e, ticker: r, symbol: n, basisPoints: i, targetAssetString: c, singleSide: a } = t, u = !a && c ? `:${c}` : "", l = Vt({ chain: e, symbol: n, ticker: r }); | ||
return `${s}:${e}${a ? "/" : "."}${l}:${i}${u}`; | ||
} | ||
case g.OPEN_LOAN: | ||
case g.CLOSE_LOAN: { | ||
const { asset: e, address: s } = t; | ||
return `${r}:${e}:${s}`; | ||
const { asset: e, address: r } = t; | ||
return `${s}:${e}:${r}`; | ||
} | ||
@@ -264,14 +264,14 @@ default: | ||
} | ||
}, me = (r) => { | ||
if (r < 0) | ||
}, de = (s) => { | ||
if (s < 0) | ||
throw new Error("Invalid number of year"); | ||
return 10 + r; | ||
}, pe = (r) => { | ||
if (r.length > 30) | ||
return 10 + s; | ||
}, me = (s) => { | ||
if (s.length > 30) | ||
return !1; | ||
const t = /^[a-zA-Z0-9+_-]+$/g; | ||
return !!r.match(t); | ||
}, fe = ([r, t, e, s, n]) => `${r}'/${t}'/${e}'/${s}${typeof n != "number" ? "" : `/${n}`}`; | ||
return !!s.match(t); | ||
}, pe = ([s, t, e, r, n]) => `${s}'/${t}'/${e}'/${r}${typeof n != "number" ? "" : `/${n}`}`; | ||
class K extends Error { | ||
constructor(t, e, s) { | ||
constructor(t, e, r) { | ||
const n = t.status || t.status === 0 ? t.status : "", i = t.statusText || "", c = `${n} ${i}`.trim(), a = c ? `status code ${c}` : "an unknown error"; | ||
@@ -293,6 +293,6 @@ super(`Request failed with ${a}`), Object.defineProperty(this, "response", { | ||
value: void 0 | ||
}), this.name = "HTTPError", this.response = t, this.request = e, this.options = s; | ||
}), this.name = "HTTPError", this.response = t, this.request = e, this.options = r; | ||
} | ||
} | ||
class ot extends Error { | ||
class it extends Error { | ||
constructor(t) { | ||
@@ -307,27 +307,27 @@ super("Request timed out"), Object.defineProperty(this, "request", { | ||
} | ||
const M = (r) => r !== null && typeof r == "object", O = (...r) => { | ||
for (const t of r) | ||
const M = (s) => s !== null && typeof s == "object", O = (...s) => { | ||
for (const t of s) | ||
if ((!M(t) || Array.isArray(t)) && t !== void 0) | ||
throw new TypeError("The `options` argument must be an object"); | ||
return Y({}, ...r); | ||
}, at = (r = {}, t = {}) => { | ||
const e = new globalThis.Headers(r), s = t instanceof globalThis.Headers, n = new globalThis.Headers(t); | ||
return Y({}, ...s); | ||
}, ot = (s = {}, t = {}) => { | ||
const e = new globalThis.Headers(s), r = t instanceof globalThis.Headers, n = new globalThis.Headers(t); | ||
for (const [i, c] of n.entries()) | ||
s && c === "undefined" || c === void 0 ? e.delete(i) : e.set(i, c); | ||
r && c === "undefined" || c === void 0 ? e.delete(i) : e.set(i, c); | ||
return e; | ||
}, Y = (...r) => { | ||
}, Y = (...s) => { | ||
let t = {}, e = {}; | ||
for (const s of r) | ||
if (Array.isArray(s)) | ||
Array.isArray(t) || (t = []), t = [...t, ...s]; | ||
else if (M(s)) { | ||
for (let [n, i] of Object.entries(s)) | ||
for (const r of s) | ||
if (Array.isArray(r)) | ||
Array.isArray(t) || (t = []), t = [...t, ...r]; | ||
else if (M(r)) { | ||
for (let [n, i] of Object.entries(r)) | ||
M(i) && n in t && (i = Y(t[n], i)), t = { ...t, [n]: i }; | ||
M(s.headers) && (e = at(e, s.headers), t.headers = e); | ||
M(r.headers) && (e = ot(e, r.headers), t.headers = e); | ||
} | ||
return t; | ||
}, xt = (() => { | ||
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", { | ||
}, qt = (() => { | ||
let s = !1, t = !1; | ||
const e = typeof globalThis.ReadableStream == "function", r = typeof globalThis.Request == "function"; | ||
return e && r && (t = new globalThis.Request("https://empty.invalid", { | ||
body: new globalThis.ReadableStream(), | ||
@@ -337,6 +337,6 @@ method: "POST", | ||
get duplex() { | ||
return r = !0, "half"; | ||
return s = !0, "half"; | ||
} | ||
}).headers.has("Content-Type")), r && !t; | ||
})(), kt = typeof globalThis.AbortController == "function", Pt = typeof globalThis.ReadableStream == "function", Nt = typeof globalThis.FormData == "function", ct = ["get", "post", "put", "patch", "head", "delete"], jt = { | ||
}).headers.has("Content-Type")), s && !t; | ||
})(), xt = typeof globalThis.AbortController == "function", kt = typeof globalThis.ReadableStream == "function", Pt = typeof globalThis.FormData == "function", at = ["get", "post", "put", "patch", "head", "delete"], Nt = { | ||
json: "application/json", | ||
@@ -347,3 +347,3 @@ text: "text/*", | ||
blob: "*/*" | ||
}, L = 2147483647, ut = Symbol("stop"), Ht = { | ||
}, L = 2147483647, ct = Symbol("stop"), jt = { | ||
json: !0, | ||
@@ -359,3 +359,3 @@ parseJson: !0, | ||
fetch: !0 | ||
}, Lt = { | ||
}, Ht = { | ||
method: !0, | ||
@@ -376,32 +376,32 @@ headers: !0, | ||
duplex: !0 | ||
}, Dt = (r) => ct.includes(r) ? r.toUpperCase() : r, Ut = ["get", "put", "head", "delete", "options", "trace"], Ft = [408, 413, 429, 500, 502, 503, 504], lt = [413, 429, 503], Q = { | ||
}, Lt = (s) => at.includes(s) ? s.toUpperCase() : s, Dt = ["get", "put", "head", "delete", "options", "trace"], Ut = [408, 413, 429, 500, 502, 503, 504], ut = [413, 429, 503], Q = { | ||
limit: 2, | ||
methods: Ut, | ||
statusCodes: Ft, | ||
afterStatusCodes: lt, | ||
methods: Dt, | ||
statusCodes: Ut, | ||
afterStatusCodes: ut, | ||
maxRetryAfter: Number.POSITIVE_INFINITY, | ||
backoffLimit: Number.POSITIVE_INFINITY, | ||
delay: (r) => 0.3 * 2 ** (r - 1) * 1e3 | ||
}, Wt = (r = {}) => { | ||
if (typeof r == "number") | ||
delay: (s) => 0.3 * 2 ** (s - 1) * 1e3 | ||
}, Ft = (s = {}) => { | ||
if (typeof s == "number") | ||
return { | ||
...Q, | ||
limit: r | ||
limit: s | ||
}; | ||
if (r.methods && !Array.isArray(r.methods)) | ||
if (s.methods && !Array.isArray(s.methods)) | ||
throw new Error("retry.methods must be an array"); | ||
if (r.statusCodes && !Array.isArray(r.statusCodes)) | ||
if (s.statusCodes && !Array.isArray(s.statusCodes)) | ||
throw new Error("retry.statusCodes must be an array"); | ||
return { | ||
...Q, | ||
...r, | ||
afterStatusCodes: lt | ||
...s, | ||
afterStatusCodes: ut | ||
}; | ||
}; | ||
async function Gt(r, t, e, s) { | ||
async function Wt(s, t, e, r) { | ||
return new Promise((n, i) => { | ||
const c = setTimeout(() => { | ||
e && e.abort(), i(new ot(r)); | ||
}, s.timeout); | ||
s.fetch(r, t).then(n).catch(i).then(() => { | ||
e && e.abort(), i(new it(s)); | ||
}, r.timeout); | ||
r.fetch(s, t).then(n).catch(i).then(() => { | ||
clearTimeout(c); | ||
@@ -411,17 +411,17 @@ }); | ||
} | ||
async function Yt(r, { signal: t }) { | ||
return new Promise((e, s) => { | ||
async function Gt(s, { signal: t }) { | ||
return new Promise((e, r) => { | ||
t && (t.throwIfAborted(), t.addEventListener("abort", n, { once: !0 })); | ||
function n() { | ||
clearTimeout(i), s(t.reason); | ||
clearTimeout(i), r(t.reason); | ||
} | ||
const i = setTimeout(() => { | ||
t == null || t.removeEventListener("abort", n), e(); | ||
}, r); | ||
}, s); | ||
}); | ||
} | ||
const zt = (r, t) => { | ||
const Yt = (s, t) => { | ||
const e = {}; | ||
for (const s in t) | ||
!(s in Lt) && !(s in Ht) && !(s in r) && (e[s] = t[s]); | ||
for (const r in t) | ||
!(r in Ht) && !(r in jt) && !(r in s) && (e[r] = t[r]); | ||
return e; | ||
@@ -431,29 +431,29 @@ }; | ||
static create(t, e) { | ||
const s = new x(t, e), n = async () => { | ||
if (typeof s._options.timeout == "number" && s._options.timeout > L) | ||
const r = new x(t, e), n = async () => { | ||
if (typeof r._options.timeout == "number" && r._options.timeout > L) | ||
throw new RangeError(`The \`timeout\` option cannot be greater than ${L}`); | ||
await Promise.resolve(); | ||
let a = await s._fetch(); | ||
for (const u of s._options.hooks.afterResponse) { | ||
const l = await u(s.request, s._options, s._decorateResponse(a.clone())); | ||
let a = await r._fetch(); | ||
for (const u of r._options.hooks.afterResponse) { | ||
const l = await u(r.request, r._options, r._decorateResponse(a.clone())); | ||
l instanceof globalThis.Response && (a = l); | ||
} | ||
if (s._decorateResponse(a), !a.ok && s._options.throwHttpErrors) { | ||
let u = new K(a, s.request, s._options); | ||
for (const l of s._options.hooks.beforeError) | ||
if (r._decorateResponse(a), !a.ok && r._options.throwHttpErrors) { | ||
let u = new K(a, r.request, r._options); | ||
for (const l of r._options.hooks.beforeError) | ||
u = await l(u); | ||
throw u; | ||
} | ||
if (s._options.onDownloadProgress) { | ||
if (typeof s._options.onDownloadProgress != "function") | ||
if (r._options.onDownloadProgress) { | ||
if (typeof r._options.onDownloadProgress != "function") | ||
throw new TypeError("The `onDownloadProgress` option must be a function"); | ||
if (!Pt) | ||
if (!kt) | ||
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing."); | ||
return s._stream(a.clone(), s._options.onDownloadProgress); | ||
return r._stream(a.clone(), r._options.onDownloadProgress); | ||
} | ||
return a; | ||
}, c = s._options.retry.methods.includes(s.request.method.toLowerCase()) ? s._retry(n) : n(); | ||
for (const [a, u] of Object.entries(jt)) | ||
}, c = r._options.retry.methods.includes(r.request.method.toLowerCase()) ? r._retry(n) : n(); | ||
for (const [a, u] of Object.entries(Nt)) | ||
c[a] = async () => { | ||
s.request.headers.set("accept", s.request.headers.get("accept") || u); | ||
r.request.headers.set("accept", r.request.headers.get("accept") || u); | ||
const h = (await c).clone(); | ||
@@ -501,3 +501,3 @@ if (a === "json") { | ||
...e, | ||
headers: at(this._input.headers, e.headers), | ||
headers: ot(this._input.headers, e.headers), | ||
hooks: Y({ | ||
@@ -509,6 +509,6 @@ beforeRequest: [], | ||
}, e.hooks), | ||
method: Dt(e.method ?? this._input.method), | ||
method: Lt(e.method ?? this._input.method), | ||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||
prefixUrl: String(e.prefixUrl || ""), | ||
retry: Wt(e.retry), | ||
retry: Ft(e.retry), | ||
throwHttpErrors: e.throwHttpErrors !== !1, | ||
@@ -524,7 +524,7 @@ timeout: e.timeout ?? 1e4, | ||
} | ||
if (kt) { | ||
if (xt) { | ||
if (this.abortController = new globalThis.AbortController(), this._options.signal) { | ||
const s = this._options.signal; | ||
const r = this._options.signal; | ||
this._options.signal.addEventListener("abort", () => { | ||
this.abortController.abort(s.reason); | ||
this.abortController.abort(r.reason); | ||
}); | ||
@@ -534,5 +534,5 @@ } | ||
} | ||
if (xt && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) { | ||
if (qt && (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()), i = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, n); | ||
(Nt && 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(i, { ...this.request }), this._options); | ||
(Pt && 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(i, { ...this.request }), this._options); | ||
} | ||
@@ -542,10 +542,10 @@ 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(t) { | ||
if (this._retryCount++, this._retryCount < this._options.retry.limit && !(t instanceof ot)) { | ||
if (this._retryCount++, this._retryCount < this._options.retry.limit && !(t instanceof it)) { | ||
if (t instanceof K) { | ||
if (!this._options.retry.statusCodes.includes(t.response.status)) | ||
return 0; | ||
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; | ||
const r = t.response.headers.get("Retry-After"); | ||
if (r && this._options.retry.afterStatusCodes.includes(t.response.status)) { | ||
let n = Number(r); | ||
return Number.isNaN(n) ? n = Date.parse(r) - Date.now() : n *= 1e3, this._options.retry.maxRetryAfter !== void 0 && n > this._options.retry.maxRetryAfter ? 0 : n; | ||
} | ||
@@ -567,5 +567,5 @@ if (t.response.status === 413) | ||
} catch (e) { | ||
const s = Math.min(this._calculateRetryDelay(e), L); | ||
if (s !== 0 && this._retryCount > 0) { | ||
await Yt(s, { signal: this._options.signal }); | ||
const r = Math.min(this._calculateRetryDelay(e), L); | ||
if (r !== 0 && this._retryCount > 0) { | ||
await Gt(r, { signal: this._options.signal }); | ||
for (const n of this._options.hooks.beforeRetry) | ||
@@ -577,3 +577,3 @@ if (await n({ | ||
retryCount: this._retryCount | ||
}) === ut) | ||
}) === ct) | ||
return; | ||
@@ -587,18 +587,18 @@ return this._retry(t); | ||
for (const e of this._options.hooks.beforeRequest) { | ||
const s = await e(this.request, this._options); | ||
if (s instanceof Request) { | ||
this.request = s; | ||
const r = await e(this.request, this._options); | ||
if (r instanceof Request) { | ||
this.request = r; | ||
break; | ||
} | ||
if (s instanceof Response) | ||
return s; | ||
if (r instanceof Response) | ||
return r; | ||
} | ||
const t = zt(this.request, this._options); | ||
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Gt(this.request.clone(), t, this.abortController, this._options); | ||
const t = Yt(this.request, this._options); | ||
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Wt(this.request.clone(), t, this.abortController, this._options); | ||
} | ||
/* istanbul ignore next */ | ||
_stream(t, e) { | ||
const s = Number(t.headers.get("content-length")) || 0; | ||
const r = Number(t.headers.get("content-length")) || 0; | ||
let n = 0; | ||
return t.status === 204 ? (e && e({ percent: 1, totalBytes: s, transferredBytes: n }, new Uint8Array()), new globalThis.Response(null, { | ||
return t.status === 204 ? (e && e({ percent: 1, totalBytes: r, transferredBytes: n }, new Uint8Array()), new globalThis.Response(null, { | ||
status: t.status, | ||
@@ -610,3 +610,3 @@ statusText: t.statusText, | ||
const c = t.body.getReader(); | ||
e && e({ percent: 0, transferredBytes: 0, totalBytes: s }, new Uint8Array()); | ||
e && e({ percent: 0, transferredBytes: 0, totalBytes: r }, new Uint8Array()); | ||
async function a() { | ||
@@ -620,4 +620,4 @@ const { done: u, value: l } = await c.read(); | ||
n += l.byteLength; | ||
const h = s === 0 ? 0 : n / s; | ||
e({ percent: h, transferredBytes: n, totalBytes: s }, l); | ||
const h = r === 0 ? 0 : n / r; | ||
e({ percent: h, transferredBytes: n, totalBytes: r }, l); | ||
} | ||
@@ -636,28 +636,28 @@ i.enqueue(l), await a(); | ||
/*! MIT License © Sindre Sorhus */ | ||
const D = (r) => { | ||
const t = (e, s) => x.create(e, O(r, s)); | ||
for (const e of ct) | ||
t[e] = (s, n) => x.create(s, O(r, n, { method: e })); | ||
return t.create = (e) => D(O(e)), t.extend = (e) => D(O(r, e)), t.stop = ut, t; | ||
}, Jt = D(), Kt = Jt, Qt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, X = Kt.create({ headers: Qt }), Xt = { | ||
get: (r, t) => X.get(r, t).json(), | ||
post: (r, t) => X.post(r, t).json() | ||
}, Z = Object.values(o), Zt = (r = "") => { | ||
const t = r.toUpperCase(), [e] = t.split("."); | ||
const D = (s) => { | ||
const t = (e, r) => x.create(e, O(s, r)); | ||
for (const e of at) | ||
t[e] = (r, n) => x.create(r, O(s, n, { method: e })); | ||
return t.create = (e) => D(O(e)), t.extend = (e) => D(O(s, e)), t.stop = ct, t; | ||
}, zt = D(), Jt = zt, Kt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, X = Jt.create({ headers: Kt }), Qt = { | ||
get: (s, t) => X.get(s, t).json(), | ||
post: (s, t) => X.post(s, t).json() | ||
}, Z = Object.values(o), Xt = (s = "") => { | ||
const t = s.toUpperCase(), [e] = t.split("."); | ||
if (Z.includes(e)) | ||
return !0; | ||
const [s] = t.split("/"); | ||
if (Z.includes(s)) | ||
const [r] = t.split("/"); | ||
if (Z.includes(r)) | ||
return !0; | ||
throw new Error( | ||
`Invalid identifier: ${r}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>` | ||
`Invalid identifier: ${s}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>` | ||
); | ||
}, S = 8, v = (r) => 10n ** BigInt(r), $ = (r) => Math.log10(parseFloat(r.toString())); | ||
}, S = 8, v = (s) => 10n ** BigInt(s), $ = (s) => Math.log10(parseFloat(s.toString())); | ||
function k({ | ||
value: r, | ||
value: s, | ||
bigIntDecimal: t = S, | ||
decimal: e = S | ||
}) { | ||
const s = r < 0n; | ||
let n = r.toString().substring(s ? 1 : 0); | ||
const r = s < 0n; | ||
let n = s.toString().substring(r ? 1 : 0); | ||
const i = e - (n.length - 1); | ||
@@ -667,3 +667,3 @@ i > 0 && (n = "0".repeat(i) + n); | ||
let a = n.slice(-e); | ||
return parseInt(a[t]) >= 5 ? a = `${a.substring(0, t - 1)}${(parseInt(a[t - 1]) + 1).toString()}` : a = a.substring(0, t), `${s ? "-" : ""}${n.slice(0, c)}.${a}`.replace( | ||
return parseInt(a[t]) >= 5 ? a = `${a.substring(0, t - 1)}${(parseInt(a[t - 1]) + 1).toString()}` : a = a.substring(0, t), `${r ? "-" : ""}${n.slice(0, c)}.${a}`.replace( | ||
/\.?0*$/, | ||
@@ -673,3 +673,3 @@ "" | ||
} | ||
var w, R, I, U, P, ht, E, F; | ||
var w, R, I, U, P, lt, E, F; | ||
const z = class z { | ||
@@ -698,7 +698,7 @@ constructor(t) { | ||
from: e, | ||
to: s | ||
to: r | ||
}) { | ||
return this.fromBigInt( | ||
t.getBaseValue("bigint") * v(s) / v(e), | ||
s | ||
t.getBaseValue("bigint") * v(r) / v(e), | ||
r | ||
); | ||
@@ -751,10 +751,10 @@ } | ||
getBaseValue(t) { | ||
const e = this.decimalMultiplier / v(this.decimal || d.THOR), s = this.bigIntValue / e; | ||
const e = this.decimalMultiplier / v(this.decimal || d.THOR), r = this.bigIntValue / e; | ||
switch (t) { | ||
case "number": | ||
return Number(s); | ||
return Number(r); | ||
case "string": | ||
return s.toString(); | ||
return r.toString(); | ||
default: | ||
return s; | ||
return r; | ||
} | ||
@@ -765,12 +765,12 @@ } | ||
return t.bigIntValue; | ||
const s = V(t), n = B(s); | ||
const r = V(t), n = B(r); | ||
return n === "0" || n === "undefined" ? 0n : f(this, E, F).call(this, n, e); | ||
} | ||
formatBigIntToSafeValue(t, e) { | ||
const s = e || this.decimal || S, n = Math.max( | ||
s, | ||
const r = e || this.decimal || S, n = Math.max( | ||
r, | ||
$(this.decimalMultiplier) | ||
), i = t < 0n, c = t.toString().substring(i ? 1 : 0), a = n - (c.length - 1), u = a > 0 ? "0".repeat(a) + c : c, l = u.length - n; | ||
let h = u.slice(-n); | ||
return parseInt(h[s]) >= 5 ? h = `${h.substring(0, s - 1)}${(parseInt(h[s - 1]) + 1).toString()}` : h = h.substring(0, s), `${i ? "-" : ""}${u.slice( | ||
return parseInt(h[r]) >= 5 ? h = `${h.substring(0, r - 1)}${(parseInt(h[r - 1]) + 1).toString()}` : h = h.substring(0, r), `${i ? "-" : ""}${u.slice( | ||
0, | ||
@@ -781,3 +781,3 @@ l | ||
toSignificant(t = 6) { | ||
const [e, s] = this.getValue("string").split("."), n = e || "", i = s || ""; | ||
const [e, r] = this.getValue("string").split("."), n = e || "", i = r || ""; | ||
if ((parseInt(n) ? n.length + i.length : i.length) <= t) | ||
@@ -799,3 +799,3 @@ return this.getValue("string"); | ||
toFixed(t = 6) { | ||
const [e, s] = this.getValue("string").split("."), n = e || "", i = s || ""; | ||
const [e, r] = this.getValue("string").split("."), n = e || "", i = r || ""; | ||
if (parseInt(n)) | ||
@@ -810,3 +810,3 @@ return `${n}.${i.slice(0, t)}`.padEnd(t, "0"); | ||
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), i = s[n]; | ||
const e = this.getValue("number"), r = ["", "K", "M", "B", "T", "Q", "Qi", "S"], n = Math.floor(Math.log10(Math.abs(e)) / 3), i = r[n]; | ||
if (!i) | ||
@@ -819,7 +819,7 @@ return this.getValue("string"); | ||
currencyPosition: e = "start", | ||
decimal: s = 2, | ||
decimal: r = 2, | ||
decimalSeparator: n = ".", | ||
thousandSeparator: i = "," | ||
} = {}) { | ||
const c = this.getValue("number"), [a, u = ""] = c.toFixed(6).split("."), l = a.replace(/\B(?=(\d{3})+(?!\d))/g, i), h = !a && !u ? "0.00" : a === "0" ? `${parseFloat(`0.${u}`)}`.replace(".", n) : `${l}${u ? `${n}${u.slice(0, s)}` : ""}`; | ||
const c = this.getValue("number"), [a, u = ""] = c.toFixed(6).split("."), l = a.replace(/\B(?=(\d{3})+(?!\d))/g, i), h = !a && !u ? "0.00" : a === "0" ? `${parseFloat(`0.${u}`)}`.replace(".", n) : `${l}${u ? `${n}${u.slice(0, r)}` : ""}`; | ||
return `${e === "start" ? t : ""}${h}${e === "end" ? t : ""}`; | ||
@@ -829,5 +829,5 @@ } | ||
w = new WeakSet(), R = function(t, ...e) { | ||
const s = f(this, P, ht).call(this, this, ...e), n = v(s), i = e.reduce( | ||
const r = f(this, P, lt).call(this, this, ...e), n = v(r), i = e.reduce( | ||
(a, u) => { | ||
const l = this.getBigIntValue(u, s); | ||
const l = this.getBigIntValue(u, r); | ||
switch (t) { | ||
@@ -852,4 +852,4 @@ case "add": | ||
), c = k({ | ||
bigIntDecimal: s, | ||
decimal: Math.max(s, $(this.decimalMultiplier)), | ||
bigIntDecimal: r, | ||
decimal: Math.max(r, $(this.decimalMultiplier)), | ||
value: i | ||
@@ -861,44 +861,42 @@ }); | ||
this.bigIntValue = f(this, E, F).call(this, e); | ||
}, P = new WeakSet(), ht = function(...t) { | ||
}, P = new WeakSet(), lt = function(...t) { | ||
const e = t.map( | ||
(s) => typeof s == "object" ? s.decimal || $(s.decimalMultiplier) : tt(B(s)) | ||
(r) => typeof r == "object" ? r.decimal || $(r.decimalMultiplier) : tt(B(r)) | ||
).filter(Boolean); | ||
return Math.max(...e, S); | ||
}, E = new WeakSet(), F = function(t, e) { | ||
const s = e ? v(e) : this.decimalMultiplier, n = $(s), [i = "", c = ""] = t.split("."); | ||
const r = e ? v(e) : this.decimalMultiplier, n = $(r), [i = "", c = ""] = t.split("."); | ||
return BigInt(`${i}${c.padEnd(n, "0")}`); | ||
}; | ||
let C = z; | ||
const te = Intl.NumberFormat("fullwide", { | ||
const Zt = Intl.NumberFormat("fullwide", { | ||
useGrouping: !1, | ||
maximumFractionDigits: 20 | ||
}); | ||
function B(r) { | ||
const e = `${typeof r == "number" ? te.format(r) : V(r)}`.replaceAll(",", ".").split("."); | ||
function B(s) { | ||
const e = `${typeof s == "number" ? Zt.format(s) : V(s)}`.replaceAll(",", ".").split("."); | ||
return e.length > 1 ? `${e.slice(0, -1).join("")}.${e.at(-1)}` : e[0]; | ||
} | ||
function tt(r) { | ||
function tt(s) { | ||
var e; | ||
const t = ((e = r.split(".")[1]) == null ? void 0 : e.length) || 0; | ||
const t = ((e = s.split(".")[1]) == null ? void 0 : e.length) || 0; | ||
return Math.max(t, S); | ||
} | ||
function V(r) { | ||
return typeof r == "object" ? "getValue" in r ? r.getValue("string") : r.value : r; | ||
function V(s) { | ||
return typeof s == "object" ? "getValue" in s ? s.getValue("string") : s.value : s; | ||
} | ||
const q = (r, t) => typeof r == "bigint" ? k({ value: r, bigIntDecimal: t, decimal: t }) : r; | ||
const q = (s, t) => typeof s == "bigint" ? k({ value: s, bigIntDecimal: t, decimal: t }) : s; | ||
let W; | ||
const et = (r) => { | ||
const et = (s) => { | ||
if (!W) | ||
throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first"); | ||
return W.get(r.toUpperCase()) || { decimal: d.THOR, identifier: "" }; | ||
}, st = async (r, t = 0) => { | ||
Zt(r); | ||
const e = await St(G(r)), s = q(t, e); | ||
return new y({ decimal: e, value: s, identifier: r }); | ||
}, rt = /* @__PURE__ */ new Map(); | ||
return W.get(s.toUpperCase()) || { decimal: d.THOR, identifier: "" }; | ||
}, rt = async (s, t = 0) => { | ||
Xt(s); | ||
const e = await Rt(G(s)), r = q(t, e); | ||
return new y({ decimal: e, value: r, identifier: s }); | ||
}; | ||
class y extends C { | ||
constructor(e) { | ||
const s = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`, n = rt.get(s); | ||
if (n) | ||
return n.set(e.value); | ||
const r = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`; | ||
super( | ||
@@ -910,16 +908,12 @@ e.value instanceof C ? e.value : { decimal: e.decimal, value: e.value } | ||
p(this, "isGasAsset", !1); | ||
// @ts-expect-error cache is false positive on that case | ||
p(this, "chain"); | ||
// @ts-expect-error cache is false positive on that case | ||
p(this, "symbol"); | ||
// @ts-expect-error cache is false positive on that case | ||
p(this, "ticker"); | ||
// @ts-expect-error cache is false positive on that case | ||
p(this, "type"); | ||
const i = G(s); | ||
this.type = It(i), this.chain = i.chain, this.ticker = i.ticker, this.symbol = i.symbol, this.address = i.address, this.isSynthetic = i.isSynthetic, this.isGasAsset = i.isGasAsset, rt.set(s, this); | ||
const n = G(r); | ||
this.type = Ct(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; | ||
} | ||
toString(e = !1) { | ||
const s = this.isSynthetic ? this.symbol.split("-")[0] : this.ticker; | ||
return e ? s : ( | ||
const r = this.isSynthetic ? this.symbol.split("-")[0] : this.ticker; | ||
return e ? r : ( | ||
// THOR.ETH/ETH | ETH.USDT-0x1234567890 | ||
@@ -929,23 +923,23 @@ `${this.chain}.${this.symbol}` | ||
} | ||
eq({ chain: e, symbol: s }) { | ||
return this.chain === e && this.symbol === s; | ||
eq({ chain: e, symbol: r }) { | ||
return this.chain === e && this.symbol === r; | ||
} | ||
static async fromString(e, s = 0) { | ||
return st(e, s); | ||
static async fromString(e, r = 0) { | ||
return rt(e, r); | ||
} | ||
static fromStringSync(e, s = 0) { | ||
static fromStringSync(e, r = 0) { | ||
const { isSynthetic: n } = G(e), { decimal: i, identifier: c } = et( | ||
e | ||
), a = q(s, i); | ||
), a = q(r, i); | ||
return c ? new y({ decimal: i, identifier: c, value: a }) : n ? new y({ decimal: 8, identifier: e, value: a }) : void 0; | ||
} | ||
static async fromIdentifier(e, s = 0) { | ||
return st(e, s); | ||
static async fromIdentifier(e, r = 0) { | ||
return rt(e, r); | ||
} | ||
static fromIdentifierSync(e, s = 0) { | ||
const { decimal: n, identifier: i } = et(e), c = q(s, n); | ||
static fromIdentifierSync(e, r = 0) { | ||
const { decimal: n, identifier: i } = et(e), c = q(r, n); | ||
return new y({ decimal: n, identifier: i, value: c }); | ||
} | ||
static fromChainOrSignature(e, s = 0) { | ||
const { decimal: n, identifier: i } = Ct(e), c = q(s, n); | ||
static fromChainOrSignature(e, r = 0) { | ||
const { decimal: n, identifier: i } = St(e), c = q(r, n); | ||
return new y({ value: c, decimal: n, identifier: i }); | ||
@@ -955,3 +949,3 @@ } | ||
return new Promise( | ||
async (e, s) => { | ||
async (e, r) => { | ||
try { | ||
@@ -973,3 +967,3 @@ const { | ||
} catch (n) { | ||
console.error(n), s({ | ||
console.error(n), r({ | ||
ok: !1, | ||
@@ -984,5 +978,5 @@ error: n, | ||
} | ||
const _e = (r) => { | ||
const t = y.fromChainOrSignature(r); | ||
switch (r) { | ||
const fe = (s) => { | ||
const t = y.fromChainOrSignature(s); | ||
switch (s) { | ||
case o.Bitcoin: | ||
@@ -1003,8 +997,8 @@ case o.Litecoin: | ||
} | ||
}, G = (r) => { | ||
const t = r.slice(0, 14).includes("/"), [e, s] = r.split(".").pop().split("/"), n = r.includes(".") && !t ? r : `${o.THORChain}.${s}`, [i, c] = n.split("."), [a, u] = (t ? s : c).split("-"); | ||
}, G = (s) => { | ||
const t = s.slice(0, 14).includes("/"), [e, r] = s.split(".").pop().split("/"), n = s.includes(".") && !t ? s : `${o.THORChain}.${r}`, [i, c] = n.split("."), [a, u] = (t ? r : c).split("-"); | ||
return { | ||
address: u == null ? void 0 : u.toLowerCase(), | ||
chain: i, | ||
isGasAsset: it({ chain: i, symbol: c }), | ||
isGasAsset: nt({ chain: i, symbol: c }), | ||
isSynthetic: t, | ||
@@ -1014,3 +1008,3 @@ symbol: (t ? `${e}/` : "") + (u ? `${a}-${(u == null ? void 0 : u.toLowerCase()) ?? ""}` : c), | ||
}; | ||
}, ee = { | ||
}, te = { | ||
/** | ||
@@ -1072,5 +1066,5 @@ * Core | ||
}; | ||
class dt extends Error { | ||
class ht extends Error { | ||
constructor(t, e) { | ||
console.error(e), super(t, { cause: { code: ee[t], message: t } }), Object.setPrototypeOf(this, dt.prototype); | ||
console.error(e), super(t, { cause: { code: te[t], message: t } }), Object.setPrototypeOf(this, ht.prototype); | ||
} | ||
@@ -1092,26 +1086,26 @@ } | ||
C as BigIntArithmetics, | ||
Xt as RequestClient, | ||
dt as SwapKitError, | ||
Qt as RequestClient, | ||
ht as SwapKitError, | ||
b as SwapKitNumber, | ||
ie as assetFromString, | ||
fe as derivationPathToString, | ||
oe as filterAssets, | ||
ne as assetFromString, | ||
pe as derivationPathToString, | ||
ie as filterAssets, | ||
k as formatBigIntToSafeValue, | ||
ne as gasFeeMultiplier, | ||
It as getAssetType, | ||
Mt as getAsymmetricAssetShare, | ||
ce as getAsymmetricAssetWithdrawAmount, | ||
Bt as getAsymmetricRuneShare, | ||
ae as getAsymmetricRuneWithdrawAmount, | ||
Ct as getCommonAssetInfo, | ||
St as getDecimal, | ||
le as getEstimatedPoolShare, | ||
he as getLiquiditySlippage, | ||
de as getMemoFor, | ||
_e as getMinAmountByChain, | ||
Vt as getSymmetricPoolShare, | ||
ue as getSymmetricWithdraw, | ||
me as getTHORNameCost, | ||
it as isGasAsset, | ||
pe as validateTHORName | ||
se as gasFeeMultiplier, | ||
Ct as getAssetType, | ||
Bt as getAsymmetricAssetShare, | ||
ae as getAsymmetricAssetWithdrawAmount, | ||
Ot as getAsymmetricRuneShare, | ||
oe as getAsymmetricRuneWithdrawAmount, | ||
St as getCommonAssetInfo, | ||
Rt as getDecimal, | ||
ue as getEstimatedPoolShare, | ||
le as getLiquiditySlippage, | ||
he as getMemoFor, | ||
fe as getMinAmountByChain, | ||
Mt as getSymmetricPoolShare, | ||
ce as getSymmetricWithdraw, | ||
de as getTHORNameCost, | ||
nt as isGasAsset, | ||
me as validateTHORName | ||
}; |
@@ -12,4 +12,4 @@ { | ||
"@internal/config": "0.0.0-rc.1", | ||
"@swapkit/tokens": "1.0.0-rc.9", | ||
"@swapkit/types": "1.0.0-rc.9" | ||
"@swapkit/tokens": "1.0.0-rc.10", | ||
"@swapkit/types": "1.0.0-rc.10" | ||
}, | ||
@@ -20,4 +20,4 @@ "eslintConfig": { | ||
"peerDependencies": { | ||
"@swapkit/tokens": "1.0.0-rc.9", | ||
"@swapkit/types": "1.0.0-rc.9" | ||
"@swapkit/tokens": "1.0.0-rc.10", | ||
"@swapkit/types": "1.0.0-rc.10" | ||
}, | ||
@@ -47,3 +47,3 @@ "exports": { | ||
"types": "./dist/index.d.ts", | ||
"version": "1.0.0-rc.27", | ||
"version": "1.0.0-rc.28", | ||
"scripts": { | ||
@@ -50,0 +50,0 @@ "build": "vite build", |
@@ -69,4 +69,2 @@ import type { | ||
const cacheAssetValue = new Map<string, AssetValue>(); | ||
export class AssetValue extends BigIntArithmetics { | ||
@@ -77,5 +75,2 @@ constructor(params: AssetValueParams) { | ||
const cachedAsset = cacheAssetValue.get(identifier); | ||
if (cachedAsset) return cachedAsset.set(params.value); | ||
super( | ||
@@ -95,4 +90,2 @@ params.value instanceof BigIntArithmetics | ||
this.isGasAsset = assetInfo.isGasAsset; | ||
cacheAssetValue.set(identifier, this); | ||
} | ||
@@ -103,9 +96,5 @@ | ||
isGasAsset = false; | ||
// @ts-expect-error cache is false positive on that case | ||
chain: Chain; | ||
// @ts-expect-error cache is false positive on that case | ||
symbol: string; | ||
// @ts-expect-error cache is false positive on that case | ||
ticker: string; | ||
// @ts-expect-error cache is false positive on that case | ||
type: ReturnType<typeof getAssetType>; | ||
@@ -112,0 +101,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
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
195518
3604