@swapkit/helpers
Advanced tools
Comparing version 1.0.0-rc.23 to 1.0.0-rc.24
@@ -162,3 +162,13 @@ import { Chain } from '@swapkit/types'; | ||
export declare const filterAssets: (assets: AssetValue[]) => AssetValue[]; | ||
export declare const filterAssets: (tokens: { | ||
value: string; | ||
decimal: number; | ||
chain: Chain; | ||
symbol: string; | ||
}[]) => { | ||
value: string; | ||
decimal: number; | ||
chain: Chain; | ||
symbol: string; | ||
}[]; | ||
@@ -165,0 +175,0 @@ export declare function formatBigIntToSafeValue({ value, bigIntDecimal, decimal, }: { |
@@ -1,17 +0,17 @@ | ||
var gt = Object.defineProperty; | ||
var bt = (s, t, e) => t in s ? gt(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e; | ||
var f = (s, t, e) => (bt(s, typeof t != "symbol" ? t + "" : t, e), e), yt = (s, t, e) => { | ||
if (!t.has(s)) | ||
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 f = (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 y = (s, t, e) => { | ||
if (t.has(s)) | ||
var y = (r, t, e) => { | ||
if (t.has(r)) | ||
throw TypeError("Cannot add the same private member more than once"); | ||
t instanceof WeakSet ? t.add(s) : t.set(s, e); | ||
t instanceof WeakSet ? t.add(r) : t.set(r, e); | ||
}; | ||
var m = (s, t, e) => (yt(s, t, "access private method"), e); | ||
import { FeeOption as L, BaseDecimal as d, Chain as o, EVMChainList as wt, ChainToRPC as At, MemoType as g } from "@swapkit/types"; | ||
const vt = "0x313ce567", nt = async ({ chain: s, to: t }) => { | ||
var m = (r, t, e) => (wt(r, t, "access private method"), e); | ||
import { FeeOption as L, BaseDecimal as d, Chain as o, EVMChainList as At, ChainToRPC as vt, MemoType as g } from "@swapkit/types"; | ||
const Tt = "0x313ce567", nt = async ({ chain: r, to: t }) => { | ||
try { | ||
const { result: e } = await Zt.post(At[s], { | ||
const { result: e } = await Zt.post(vt[r], { | ||
headers: { | ||
@@ -26,3 +26,3 @@ accept: "*/*", | ||
method: "eth_call", | ||
params: [{ to: t.toLowerCase(), data: vt }, "latest"] | ||
params: [{ to: t.toLowerCase(), data: Tt }, "latest"] | ||
}) | ||
@@ -32,22 +32,22 @@ }); | ||
} catch (e) { | ||
return console.error(e), d[s]; | ||
return console.error(e), d[r]; | ||
} | ||
}, Tt = async (s) => { | ||
if (s === o.Ethereum) | ||
}, $t = async (r) => { | ||
if (r === o.Ethereum) | ||
return d.ETH; | ||
const [, t] = s.split("-"); | ||
const [, t] = r.split("-"); | ||
return t != null && t.startsWith("0x") ? nt({ chain: o.Ethereum, to: t }) : d.ETH; | ||
}, $t = async (s) => { | ||
const [, t] = s.split("-"); | ||
}, Rt = async (r) => { | ||
const [, t] = r.split("-"); | ||
return t != null && t.startsWith("0x") ? nt({ chain: o.Avalanche, to: t.toLowerCase() }) : d.AVAX; | ||
}, Rt = async (s) => s === o.BinanceSmartChain ? d.BSC : d.BSC, St = async ({ chain: s, symbol: t }) => { | ||
switch (s) { | ||
}, St = async (r) => r === o.BinanceSmartChain ? d.BSC : d.BSC, Ct = async ({ chain: r, symbol: t }) => { | ||
switch (r) { | ||
case o.Ethereum: | ||
return Tt(t); | ||
return $t(t); | ||
case o.Avalanche: | ||
return $t(t); | ||
return Rt(t); | ||
case o.BinanceSmartChain: | ||
return Rt(t); | ||
return St(t); | ||
default: | ||
return d[s]; | ||
return d[r]; | ||
} | ||
@@ -58,4 +58,4 @@ }, ne = { | ||
[L.Fastest]: 2 | ||
}, Ct = ({ chain: s, symbol: t }) => { | ||
switch (s) { | ||
}, it = ({ chain: r, symbol: t }) => { | ||
switch (r) { | ||
case o.Bitcoin: | ||
@@ -68,3 +68,3 @@ case o.BitcoinCash: | ||
case o.Avalanche: | ||
return t === s; | ||
return t === r; | ||
case o.Arbitrum: | ||
@@ -86,4 +86,4 @@ case o.Optimism: | ||
} | ||
}, It = (s) => { | ||
switch (s) { | ||
}, It = (r) => { | ||
switch (r) { | ||
case "ETH.THOR": | ||
@@ -94,7 +94,7 @@ return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 }; | ||
case o.Cosmos: | ||
return { identifier: "GAIA.ATOM", decimal: d[s] }; | ||
return { identifier: "GAIA.ATOM", decimal: d[r] }; | ||
case o.THORChain: | ||
return { identifier: "THOR.RUNE", decimal: d[s] }; | ||
return { identifier: "THOR.RUNE", decimal: d[r] }; | ||
case o.BinanceSmartChain: | ||
return { identifier: "BSC.BNB", decimal: d[s] }; | ||
return { identifier: "BSC.BNB", decimal: d[r] }; | ||
case o.Maya: | ||
@@ -115,8 +115,8 @@ return { identifier: "MAYA.CACAO", decimal: d.MAYA }; | ||
case o.Ethereum: | ||
return { identifier: `${s}.${s}`, decimal: d[s] }; | ||
return { identifier: `${r}.${r}`, decimal: d[r] }; | ||
} | ||
}, Et = ({ chain: s, symbol: t }) => { | ||
}, Et = ({ chain: r, symbol: t }) => { | ||
if (t.includes("/")) | ||
return "Synth"; | ||
switch (s) { | ||
switch (r) { | ||
case o.Bitcoin: | ||
@@ -148,107 +148,114 @@ case o.BitcoinCash: | ||
} | ||
}, ie = (s) => { | ||
}, ie = (r) => { | ||
var c; | ||
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 }; | ||
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 }; | ||
}, Ot = new RegExp( | ||
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/, | ||
"gmi" | ||
), Bt = (s) => wt.includes(s.chain) ? !s.isGasAsset && s.address && !Number.isNaN(s.decimal) : !0, oe = (s) => s.filter( | ||
(t) => !t.toString().includes("undefined") && !Ot.test(t.toString()) && Bt(t) | ||
), Mt = ({ | ||
liquidityUnits: s, | ||
), Bt = (r) => { | ||
const [t, e] = r.split("."); | ||
if (!At.includes(t)) | ||
return !0; | ||
const [, s] = e.split("-"); | ||
return it({ chain: t, symbol: e }) || !!s; | ||
}, oe = (r) => r.filter((t) => { | ||
const e = `${t.chain}.${t.symbol}`; | ||
return !Ot.test(e) && Bt(e); | ||
}), Mt = ({ | ||
liquidityUnits: r, | ||
poolUnits: t, | ||
runeDepth: e | ||
}) => { | ||
const r = p(s), n = p(t), i = p(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); | ||
const s = p(r), n = p(t), i = p(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); | ||
return c.mul(a.sub(u).add(l)).div(h); | ||
}, Vt = ({ | ||
liquidityUnits: s, | ||
liquidityUnits: r, | ||
poolUnits: t, | ||
assetDepth: e | ||
}) => { | ||
const r = p(s), n = p(t), i = p(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); | ||
const s = p(r), n = p(t), i = p(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); | ||
return h.div(_); | ||
}, ae = ({ | ||
percent: s, | ||
percent: r, | ||
runeDepth: t, | ||
liquidityUnits: e, | ||
poolUnits: r | ||
}) => Mt({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), ce = ({ | ||
percent: s, | ||
poolUnits: s | ||
}) => Mt({ runeDepth: t, liquidityUnits: e, poolUnits: s }).mul(r), ce = ({ | ||
percent: r, | ||
assetDepth: t, | ||
liquidityUnits: e, | ||
poolUnits: r | ||
}) => Vt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), p = (s) => b.fromBigInt(BigInt(s), d.THOR), kt = ({ | ||
liquidityUnits: s, | ||
poolUnits: s | ||
}) => Vt({ assetDepth: t, liquidityUnits: e, poolUnits: s }).mul(r), p = (r) => b.fromBigInt(BigInt(r), d.THOR), qt = ({ | ||
liquidityUnits: r, | ||
poolUnits: t, | ||
runeDepth: e, | ||
assetDepth: r | ||
assetDepth: s | ||
}) => ({ | ||
assetAmount: p(r).mul(s).div(t), | ||
runeAmount: p(e).mul(s).div(t) | ||
assetAmount: p(s).mul(r).div(t), | ||
runeAmount: p(e).mul(r).div(t) | ||
}), ue = ({ | ||
liquidityUnits: s, | ||
liquidityUnits: r, | ||
poolUnits: t, | ||
runeDepth: e, | ||
assetDepth: r, | ||
assetDepth: s, | ||
percent: n | ||
}) => Object.fromEntries( | ||
Object.entries(kt({ liquidityUnits: s, poolUnits: t, runeDepth: e, assetDepth: r })).map( | ||
Object.entries(qt({ liquidityUnits: r, poolUnits: t, runeDepth: e, assetDepth: s })).map( | ||
([i, c]) => [i, c.mul(n)] | ||
) | ||
), le = ({ | ||
runeDepth: s, | ||
runeDepth: r, | ||
poolUnits: t, | ||
assetDepth: e, | ||
liquidityUnits: r, | ||
liquidityUnits: s, | ||
runeAmount: n, | ||
assetAmount: i | ||
}) => { | ||
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), T = h.mul(c), j = l.mul(h), mt = c.mul(a), pt = u.mul(_.add(T.add(j.mul(2)))), ft = _.add(T.add(mt.mul(2))), Q = pt.div(ft), H = p(r).add(Q); | ||
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), T = h.mul(c), j = l.mul(h), pt = c.mul(a), ft = u.mul(_.add(T.add(j.mul(2)))), _t = _.add(T.add(pt.mul(2))), Q = ft.div(_t), H = p(s).add(Q); | ||
if (Q.getBaseValue("number") === 0) | ||
return H.div(u).getBaseValue("number"); | ||
const _t = u.add(H); | ||
return H.div(_t).getBaseValue("number"); | ||
const gt = u.add(H); | ||
return H.div(gt).getBaseValue("number"); | ||
}, he = ({ | ||
runeAmount: s, | ||
runeAmount: r, | ||
assetAmount: t, | ||
runeDepth: e, | ||
assetDepth: r | ||
assetDepth: s | ||
}) => { | ||
if (s === "0" || t === "0" || e === "0" || r === "0") | ||
if (r === "0" || t === "0" || e === "0" || s === "0") | ||
return 0; | ||
const n = p(e), i = p(r), c = p(t), a = p(s), u = c.mul(n).sub(i.mul(a)), l = i.mul(a).add(n.mul(i)); | ||
const n = p(e), i = p(s), c = p(t), a = p(r), 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: s, | ||
}, kt = ({ | ||
symbol: r, | ||
ticker: t, | ||
chain: e | ||
}) => e === "ETH" && t !== "ETH" ? `${t}-${s.slice(-3)}` : s, de = (s, t) => { | ||
switch (s) { | ||
}) => e === "ETH" && t !== "ETH" ? `${t}-${r.slice(-3)}` : r, de = (r, t) => { | ||
switch (r) { | ||
case g.LEAVE: | ||
case g.BOND: { | ||
const { address: e } = t; | ||
return `${s}:${e}`; | ||
return `${r}:${e}`; | ||
} | ||
case g.UNBOND: { | ||
const { address: e, unbondAmount: r } = t; | ||
return `${s}:${e}:${r * 10 ** 8}`; | ||
const { address: e, unbondAmount: s } = t; | ||
return `${r}:${e}:${s * 10 ** 8}`; | ||
} | ||
case g.THORNAME_REGISTER: { | ||
const { name: e, chain: r, address: n, owner: i } = t; | ||
return `${s}:${e}:${r}:${n}${i ? `:${i}` : ""}`; | ||
const { name: e, chain: s, address: n, owner: i } = t; | ||
return `${r}:${e}:${s}:${n}${i ? `:${i}` : ""}`; | ||
} | ||
case g.DEPOSIT: { | ||
const { chain: e, symbol: r, address: n, singleSide: i } = t; | ||
return i ? `${s}:${e}/${r}::t:0` : `${s}:${e}.${r}:${n || ""}:t:0`; | ||
const { chain: e, symbol: s, address: n, singleSide: i } = t; | ||
return i ? `${r}:${e}/${s}::t:0` : `${r}:${e}.${s}:${n || ""}:t:0`; | ||
} | ||
case g.WITHDRAW: { | ||
const { chain: e, ticker: r, symbol: n, basisPoints: i, targetAssetString: c, singleSide: a } = t, u = !a && c ? `:${c}` : "", l = qt({ chain: e, symbol: n, ticker: r }); | ||
return `${s}:${e}${a ? "/" : "."}${l}:${i}${u}`; | ||
const { chain: e, ticker: s, symbol: n, basisPoints: i, targetAssetString: c, singleSide: a } = t, u = !a && c ? `:${c}` : "", l = kt({ chain: e, symbol: n, ticker: s }); | ||
return `${r}:${e}${a ? "/" : "."}${l}:${i}${u}`; | ||
} | ||
case g.OPEN_LOAN: | ||
case g.CLOSE_LOAN: { | ||
const { asset: e, address: r } = t; | ||
return `${s}:${e}:${r}`; | ||
const { asset: e, address: s } = t; | ||
return `${r}:${e}:${s}`; | ||
} | ||
@@ -258,14 +265,14 @@ default: | ||
} | ||
}, me = (s) => { | ||
if (s < 0) | ||
}, me = (r) => { | ||
if (r < 0) | ||
throw new Error("Invalid number of year"); | ||
return 10 + s; | ||
}, pe = (s) => { | ||
if (s.length > 30) | ||
return 10 + r; | ||
}, pe = (r) => { | ||
if (r.length > 30) | ||
return !1; | ||
const t = /^[a-zA-Z0-9+_-]+$/g; | ||
return !!s.match(t); | ||
}, fe = ([s, t, e, r, n]) => `${s}'/${t}'/${e}'/${r}${typeof n != "number" ? "" : `/${n}`}`; | ||
return !!r.match(t); | ||
}, fe = ([r, t, e, s, n]) => `${r}'/${t}'/${e}'/${s}${typeof n != "number" ? "" : `/${n}`}`; | ||
class X extends Error { | ||
constructor(t, e, r) { | ||
constructor(t, e, s) { | ||
const n = t.status || t.status === 0 ? t.status : "", i = t.statusText || "", c = `${n} ${i}`.trim(), a = c ? `status code ${c}` : "an unknown error"; | ||
@@ -287,6 +294,6 @@ super(`Request failed with ${a}`), Object.defineProperty(this, "response", { | ||
value: void 0 | ||
}), this.name = "HTTPError", this.response = t, this.request = e, this.options = r; | ||
}), this.name = "HTTPError", this.response = t, this.request = e, this.options = s; | ||
} | ||
} | ||
class it extends Error { | ||
class ot extends Error { | ||
constructor(t) { | ||
@@ -301,27 +308,27 @@ super("Request timed out"), Object.defineProperty(this, "request", { | ||
} | ||
const V = (s) => s !== null && typeof s == "object", M = (...s) => { | ||
for (const t of s) | ||
const V = (r) => r !== null && typeof r == "object", M = (...r) => { | ||
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 J({}, ...s); | ||
}, ot = (s = {}, t = {}) => { | ||
const e = new globalThis.Headers(s), r = t instanceof globalThis.Headers, n = new globalThis.Headers(t); | ||
return J({}, ...r); | ||
}, at = (r = {}, t = {}) => { | ||
const e = new globalThis.Headers(r), s = t instanceof globalThis.Headers, n = new globalThis.Headers(t); | ||
for (const [i, c] of n.entries()) | ||
r && c === "undefined" || c === void 0 ? e.delete(i) : e.set(i, c); | ||
s && c === "undefined" || c === void 0 ? e.delete(i) : e.set(i, c); | ||
return e; | ||
}, J = (...s) => { | ||
}, J = (...r) => { | ||
let t = {}, e = {}; | ||
for (const r of s) | ||
if (Array.isArray(r)) | ||
Array.isArray(t) || (t = []), t = [...t, ...r]; | ||
else if (V(r)) { | ||
for (let [n, i] of Object.entries(r)) | ||
for (const s of r) | ||
if (Array.isArray(s)) | ||
Array.isArray(t) || (t = []), t = [...t, ...s]; | ||
else if (V(s)) { | ||
for (let [n, i] of Object.entries(s)) | ||
V(i) && n in t && (i = J(t[n], i)), t = { ...t, [n]: i }; | ||
V(r.headers) && (e = ot(e, r.headers), t.headers = e); | ||
V(s.headers) && (e = at(e, s.headers), t.headers = e); | ||
} | ||
return t; | ||
}, xt = (() => { | ||
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", { | ||
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(), | ||
@@ -331,6 +338,6 @@ method: "POST", | ||
get duplex() { | ||
return s = !0, "half"; | ||
return r = !0, "half"; | ||
} | ||
}).headers.has("Content-Type")), s && !t; | ||
})(), Pt = typeof globalThis.AbortController == "function", Nt = typeof globalThis.ReadableStream == "function", jt = typeof globalThis.FormData == "function", at = ["get", "post", "put", "patch", "head", "delete"], Ht = { | ||
}).headers.has("Content-Type")), r && !t; | ||
})(), Pt = typeof globalThis.AbortController == "function", Nt = typeof globalThis.ReadableStream == "function", jt = typeof globalThis.FormData == "function", ct = ["get", "post", "put", "patch", "head", "delete"], Ht = { | ||
json: "application/json", | ||
@@ -341,3 +348,3 @@ text: "text/*", | ||
blob: "*/*" | ||
}, D = 2147483647, ct = Symbol("stop"), Lt = { | ||
}, D = 2147483647, ut = Symbol("stop"), Lt = { | ||
json: !0, | ||
@@ -369,32 +376,32 @@ parseJson: !0, | ||
duplex: !0 | ||
}, Ut = (s) => at.includes(s) ? s.toUpperCase() : s, Ft = ["get", "put", "head", "delete", "options", "trace"], Wt = [408, 413, 429, 500, 502, 503, 504], ut = [413, 429, 503], Z = { | ||
}, Ut = (r) => ct.includes(r) ? r.toUpperCase() : r, Ft = ["get", "put", "head", "delete", "options", "trace"], Wt = [408, 413, 429, 500, 502, 503, 504], lt = [413, 429, 503], Z = { | ||
limit: 2, | ||
methods: Ft, | ||
statusCodes: Wt, | ||
afterStatusCodes: ut, | ||
afterStatusCodes: lt, | ||
maxRetryAfter: Number.POSITIVE_INFINITY, | ||
backoffLimit: Number.POSITIVE_INFINITY, | ||
delay: (s) => 0.3 * 2 ** (s - 1) * 1e3 | ||
}, Gt = (s = {}) => { | ||
if (typeof s == "number") | ||
delay: (r) => 0.3 * 2 ** (r - 1) * 1e3 | ||
}, Gt = (r = {}) => { | ||
if (typeof r == "number") | ||
return { | ||
...Z, | ||
limit: s | ||
limit: r | ||
}; | ||
if (s.methods && !Array.isArray(s.methods)) | ||
if (r.methods && !Array.isArray(r.methods)) | ||
throw new Error("retry.methods must be an array"); | ||
if (s.statusCodes && !Array.isArray(s.statusCodes)) | ||
if (r.statusCodes && !Array.isArray(r.statusCodes)) | ||
throw new Error("retry.statusCodes must be an array"); | ||
return { | ||
...Z, | ||
...s, | ||
afterStatusCodes: ut | ||
...r, | ||
afterStatusCodes: lt | ||
}; | ||
}; | ||
async function Yt(s, t, e, r) { | ||
async function Yt(r, t, e, s) { | ||
return new Promise((n, i) => { | ||
const c = setTimeout(() => { | ||
e && e.abort(), i(new it(s)); | ||
}, r.timeout); | ||
r.fetch(s, t).then(n).catch(i).then(() => { | ||
e && e.abort(), i(new ot(r)); | ||
}, s.timeout); | ||
s.fetch(r, t).then(n).catch(i).then(() => { | ||
clearTimeout(c); | ||
@@ -404,48 +411,48 @@ }); | ||
} | ||
async function zt(s, { signal: t }) { | ||
return new Promise((e, r) => { | ||
async function zt(r, { signal: t }) { | ||
return new Promise((e, s) => { | ||
t && (t.throwIfAborted(), t.addEventListener("abort", n, { once: !0 })); | ||
function n() { | ||
clearTimeout(i), r(t.reason); | ||
clearTimeout(i), s(t.reason); | ||
} | ||
const i = setTimeout(() => { | ||
t == null || t.removeEventListener("abort", n), e(); | ||
}, s); | ||
}, r); | ||
}); | ||
} | ||
const Jt = (s, t) => { | ||
const Jt = (r, t) => { | ||
const e = {}; | ||
for (const r in t) | ||
!(r in Dt) && !(r in Lt) && !(r in s) && (e[r] = t[r]); | ||
for (const s in t) | ||
!(s in Dt) && !(s in Lt) && !(s in r) && (e[s] = t[s]); | ||
return e; | ||
}; | ||
class q { | ||
class k { | ||
static create(t, e) { | ||
const r = new q(t, e), n = async () => { | ||
if (typeof r._options.timeout == "number" && r._options.timeout > D) | ||
const s = new k(t, e), n = async () => { | ||
if (typeof s._options.timeout == "number" && s._options.timeout > D) | ||
throw new RangeError(`The \`timeout\` option cannot be greater than ${D}`); | ||
await Promise.resolve(); | ||
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())); | ||
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())); | ||
l instanceof globalThis.Response && (a = l); | ||
} | ||
if (r._decorateResponse(a), !a.ok && r._options.throwHttpErrors) { | ||
let u = new X(a, r.request, r._options); | ||
for (const l of r._options.hooks.beforeError) | ||
if (s._decorateResponse(a), !a.ok && s._options.throwHttpErrors) { | ||
let u = new X(a, s.request, s._options); | ||
for (const l of s._options.hooks.beforeError) | ||
u = await l(u); | ||
throw u; | ||
} | ||
if (r._options.onDownloadProgress) { | ||
if (typeof r._options.onDownloadProgress != "function") | ||
if (s._options.onDownloadProgress) { | ||
if (typeof s._options.onDownloadProgress != "function") | ||
throw new TypeError("The `onDownloadProgress` option must be a function"); | ||
if (!Nt) | ||
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing."); | ||
return r._stream(a.clone(), r._options.onDownloadProgress); | ||
return s._stream(a.clone(), s._options.onDownloadProgress); | ||
} | ||
return a; | ||
}, c = r._options.retry.methods.includes(r.request.method.toLowerCase()) ? r._retry(n) : n(); | ||
}, c = s._options.retry.methods.includes(s.request.method.toLowerCase()) ? s._retry(n) : n(); | ||
for (const [a, u] of Object.entries(Ht)) | ||
c[a] = async () => { | ||
r.request.headers.set("accept", r.request.headers.get("accept") || u); | ||
s.request.headers.set("accept", s.request.headers.get("accept") || u); | ||
const h = (await c).clone(); | ||
@@ -493,3 +500,3 @@ if (a === "json") { | ||
...e, | ||
headers: ot(this._input.headers, e.headers), | ||
headers: at(this._input.headers, e.headers), | ||
hooks: J({ | ||
@@ -517,5 +524,5 @@ beforeRequest: [], | ||
if (this.abortController = new globalThis.AbortController(), this._options.signal) { | ||
const r = this._options.signal; | ||
const s = this._options.signal; | ||
this._options.signal.addEventListener("abort", () => { | ||
this.abortController.abort(r.reason); | ||
this.abortController.abort(s.reason); | ||
}); | ||
@@ -532,10 +539,10 @@ } | ||
_calculateRetryDelay(t) { | ||
if (this._retryCount++, this._retryCount < this._options.retry.limit && !(t instanceof it)) { | ||
if (this._retryCount++, this._retryCount < this._options.retry.limit && !(t instanceof ot)) { | ||
if (t instanceof X) { | ||
if (!this._options.retry.statusCodes.includes(t.response.status)) | ||
return 0; | ||
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; | ||
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; | ||
} | ||
@@ -557,5 +564,5 @@ if (t.response.status === 413) | ||
} catch (e) { | ||
const r = Math.min(this._calculateRetryDelay(e), D); | ||
if (r !== 0 && this._retryCount > 0) { | ||
await zt(r, { signal: this._options.signal }); | ||
const s = Math.min(this._calculateRetryDelay(e), D); | ||
if (s !== 0 && this._retryCount > 0) { | ||
await zt(s, { signal: this._options.signal }); | ||
for (const n of this._options.hooks.beforeRetry) | ||
@@ -567,3 +574,3 @@ if (await n({ | ||
retryCount: this._retryCount | ||
}) === ct) | ||
}) === ut) | ||
return; | ||
@@ -577,9 +584,9 @@ return this._retry(t); | ||
for (const e of this._options.hooks.beforeRequest) { | ||
const r = await e(this.request, this._options); | ||
if (r instanceof Request) { | ||
this.request = r; | ||
const s = await e(this.request, this._options); | ||
if (s instanceof Request) { | ||
this.request = s; | ||
break; | ||
} | ||
if (r instanceof Response) | ||
return r; | ||
if (s instanceof Response) | ||
return s; | ||
} | ||
@@ -591,5 +598,5 @@ const t = Jt(this.request, this._options); | ||
_stream(t, e) { | ||
const r = Number(t.headers.get("content-length")) || 0; | ||
const s = Number(t.headers.get("content-length")) || 0; | ||
let n = 0; | ||
return t.status === 204 ? (e && e({ percent: 1, totalBytes: r, transferredBytes: n }, new Uint8Array()), new globalThis.Response(null, { | ||
return t.status === 204 ? (e && e({ percent: 1, totalBytes: s, transferredBytes: n }, new Uint8Array()), new globalThis.Response(null, { | ||
status: t.status, | ||
@@ -601,3 +608,3 @@ statusText: t.statusText, | ||
const c = t.body.getReader(); | ||
e && e({ percent: 0, transferredBytes: 0, totalBytes: r }, new Uint8Array()); | ||
e && e({ percent: 0, transferredBytes: 0, totalBytes: s }, new Uint8Array()); | ||
async function a() { | ||
@@ -611,4 +618,4 @@ const { done: u, value: l } = await c.read(); | ||
n += l.byteLength; | ||
const h = r === 0 ? 0 : n / r; | ||
e({ percent: h, transferredBytes: n, totalBytes: r }, l); | ||
const h = s === 0 ? 0 : n / s; | ||
e({ percent: h, transferredBytes: n, totalBytes: s }, l); | ||
} | ||
@@ -627,28 +634,28 @@ i.enqueue(l), await a(); | ||
/*! MIT License © Sindre Sorhus */ | ||
const F = (s) => { | ||
const t = (e, r) => q.create(e, M(s, r)); | ||
for (const e of at) | ||
t[e] = (r, n) => q.create(r, M(s, n, { method: e })); | ||
return t.create = (e) => F(M(e)), t.extend = (e) => F(M(s, e)), t.stop = ct, t; | ||
const F = (r) => { | ||
const t = (e, s) => k.create(e, M(r, s)); | ||
for (const e of ct) | ||
t[e] = (s, n) => k.create(s, M(r, n, { method: e })); | ||
return t.create = (e) => F(M(e)), t.extend = (e) => F(M(r, e)), t.stop = ut, t; | ||
}, Kt = F(), Qt = Kt, Xt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, tt = Qt.create({ headers: Xt }), Zt = { | ||
get: (s, t) => tt.get(s, t).json(), | ||
post: (s, t) => tt.post(s, t).json() | ||
}, et = Object.values(o), te = (s = "") => { | ||
const t = s.toUpperCase(), [e] = t.split("."); | ||
get: (r, t) => tt.get(r, t).json(), | ||
post: (r, t) => tt.post(r, t).json() | ||
}, et = Object.values(o), te = (r = "") => { | ||
const t = r.toUpperCase(), [e] = t.split("."); | ||
if (et.includes(e)) | ||
return !0; | ||
const [r] = t.split("/"); | ||
if (et.includes(r)) | ||
const [s] = t.split("/"); | ||
if (et.includes(s)) | ||
return !0; | ||
throw new Error( | ||
`Invalid identifier: ${s}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>` | ||
`Invalid identifier: ${r}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>` | ||
); | ||
}, I = 8, $ = (s) => 10n ** BigInt(s), R = (s) => Math.log10(parseFloat(s.toString())); | ||
}, I = 8, $ = (r) => 10n ** BigInt(r), R = (r) => Math.log10(parseFloat(r.toString())); | ||
function x({ | ||
value: s, | ||
value: r, | ||
bigIntDecimal: t = I, | ||
decimal: e = I | ||
}) { | ||
const r = s < 0n; | ||
let n = s.toString().substring(r ? 1 : 0); | ||
const s = r < 0n; | ||
let n = r.toString().substring(s ? 1 : 0); | ||
const i = e - (n.length - 1); | ||
@@ -658,3 +665,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), `${r ? "-" : ""}${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), `${s ? "-" : ""}${n.slice(0, c)}.${a}`.replace( | ||
/\.?0*$/, | ||
@@ -664,3 +671,3 @@ "" | ||
} | ||
var A, S, P, lt, N, ht, O, W, v, C, B, G; | ||
var A, S, P, ht, N, dt, O, W, v, C, B, G; | ||
const K = class K { | ||
@@ -680,3 +687,3 @@ constructor(t) { | ||
Math.max(m(this, B, G).call(this, m(this, v, C).call(this, e)), this.decimal || 0) | ||
), m(this, P, lt).call(this, e); | ||
), m(this, P, ht).call(this, e); | ||
} | ||
@@ -692,7 +699,7 @@ static fromBigInt(t, e) { | ||
from: e, | ||
to: r | ||
to: s | ||
}) { | ||
return this.fromBigInt( | ||
t.getBaseValue("bigint") * $(r) / $(e), | ||
r | ||
t.getBaseValue("bigint") * $(s) / $(e), | ||
s | ||
); | ||
@@ -745,10 +752,10 @@ } | ||
getBaseValue(t) { | ||
const e = this.decimalMultiplier / $(this.decimal || d.THOR), r = this.bigIntValue / e; | ||
const e = this.decimalMultiplier / $(this.decimal || d.THOR), s = this.bigIntValue / e; | ||
switch (t) { | ||
case "number": | ||
return Number(r); | ||
return Number(s); | ||
case "string": | ||
return r.toString(); | ||
return s.toString(); | ||
default: | ||
return r; | ||
return s; | ||
} | ||
@@ -759,12 +766,12 @@ } | ||
return t.bigIntValue; | ||
const r = U(t), n = m(this, v, C).call(this, r); | ||
const s = U(t), n = m(this, v, C).call(this, s); | ||
return n === "0" || n === "undefined" ? 0n : m(this, O, W).call(this, n, e); | ||
} | ||
formatBigIntToSafeValue(t, e) { | ||
const r = e || this.decimal || I, n = Math.max( | ||
r, | ||
const s = e || this.decimal || I, n = Math.max( | ||
s, | ||
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[r]) >= 5 ? h = `${h.substring(0, r - 1)}${(parseInt(h[r - 1]) + 1).toString()}` : h = h.substring(0, r), `${i ? "-" : ""}${u.slice( | ||
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( | ||
0, | ||
@@ -775,3 +782,3 @@ l | ||
toSignificant(t = 6) { | ||
const [e, r] = this.getValue("string").split("."), n = e || "", i = r || ""; | ||
const [e, s] = this.getValue("string").split("."), n = e || "", i = s || ""; | ||
if ((parseInt(n) ? n.length + i.length : i.length) <= t) | ||
@@ -793,3 +800,3 @@ return this.getValue("string"); | ||
toFixed(t = 6) { | ||
const [e, r] = this.getValue("string").split("."), n = e || "", i = r || ""; | ||
const [e, s] = this.getValue("string").split("."), n = e || "", i = s || ""; | ||
if (parseInt(n)) | ||
@@ -804,3 +811,3 @@ return `${n}.${i.slice(0, t)}`.padEnd(t, "0"); | ||
toAbbreviation(t = 2) { | ||
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]; | ||
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]; | ||
if (!i) | ||
@@ -813,7 +820,7 @@ return this.getValue("string"); | ||
currencyPosition: e = "start", | ||
decimal: r = 2, | ||
decimal: s = 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, r)}` : ""}`; | ||
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)}` : ""}`; | ||
return `${e === "start" ? t : ""}${h}${e === "end" ? t : ""}`; | ||
@@ -823,5 +830,5 @@ } | ||
A = new WeakSet(), S = function(t, ...e) { | ||
const r = m(this, N, ht).call(this, this, ...e), n = $(r), i = e.reduce( | ||
const s = m(this, N, dt).call(this, this, ...e), n = $(s), i = e.reduce( | ||
(a, u) => { | ||
const l = this.getBigIntValue(u, r); | ||
const l = this.getBigIntValue(u, s); | ||
switch (t) { | ||
@@ -846,46 +853,47 @@ case "add": | ||
), c = x({ | ||
bigIntDecimal: r, | ||
decimal: Math.max(r, R(this.decimalMultiplier)), | ||
bigIntDecimal: s, | ||
decimal: Math.max(s, R(this.decimalMultiplier)), | ||
value: i | ||
}); | ||
return new this.constructor({ decimal: this.decimal, value: c, identifier: this.toString() }); | ||
}, P = new WeakSet(), lt = function(t) { | ||
}, P = new WeakSet(), ht = function(t) { | ||
const e = m(this, v, C).call(this, t) || "0"; | ||
this.bigIntValue = m(this, O, W).call(this, e); | ||
}, N = new WeakSet(), ht = function(...t) { | ||
}, N = new WeakSet(), dt = function(...t) { | ||
const e = t.map( | ||
(r) => typeof r == "object" ? r.decimal || R(r.decimalMultiplier) : m(this, B, G).call(this, m(this, v, C).call(this, r)) | ||
(s) => typeof s == "object" ? s.decimal || R(s.decimalMultiplier) : m(this, B, G).call(this, m(this, v, C).call(this, s)) | ||
).filter(Boolean); | ||
return Math.max(...e, I); | ||
}, O = new WeakSet(), W = function(t, e) { | ||
const r = e ? $(e) : this.decimalMultiplier, n = R(r), [i = "", c = ""] = t.split("."); | ||
const s = e ? $(e) : this.decimalMultiplier, n = R(s), [i = "", c = ""] = t.split("."); | ||
return BigInt(`${i}${c.padEnd(n, "0")}`); | ||
}, v = new WeakSet(), C = function(t) { | ||
const r = `${typeof t == "number" ? Number(t).toLocaleString("fullwide", { | ||
const s = `${typeof t == "number" ? Number(t).toLocaleString("fullwide", { | ||
useGrouping: !1, | ||
maximumFractionDigits: 20 | ||
}) : U(t)}`.replaceAll(",", ".").split("."); | ||
return r.length > 1 ? `${r.slice(0, -1).join("")}.${r.at(-1)}` : r[0]; | ||
return s.length > 1 ? `${s.slice(0, -1).join("")}.${s.at(-1)}` : s[0]; | ||
}, B = new WeakSet(), G = function(t) { | ||
var r; | ||
const e = ((r = t.split(".")[1]) == null ? void 0 : r.length) || 0; | ||
var s; | ||
const e = ((s = t.split(".")[1]) == null ? void 0 : s.length) || 0; | ||
return Math.max(e, I); | ||
}; | ||
let E = K; | ||
function U(s) { | ||
return typeof s == "object" ? "getValue" in s ? s.getValue("string") : s.value : s; | ||
function U(r) { | ||
return typeof r == "object" ? "getValue" in r ? r.getValue("string") : r.value : r; | ||
} | ||
const k = (s, t) => typeof s == "bigint" ? x({ value: s, bigIntDecimal: t, decimal: t }) : s; | ||
const q = (r, t) => typeof r == "bigint" ? x({ value: r, bigIntDecimal: t, decimal: t }) : r; | ||
let Y; | ||
const rt = (s) => { | ||
const st = (r) => { | ||
if (!Y) | ||
throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first"); | ||
return Y.get(s.toUpperCase()) || { decimal: d.THOR, identifier: "" }; | ||
}, st = async (s, t = 0) => { | ||
te(s); | ||
const e = await St(z(s)), r = k(t, e); | ||
return new w({ decimal: e, value: r, identifier: s }); | ||
return Y.get(r.toUpperCase()) || { decimal: d.THOR, identifier: "" }; | ||
}, rt = async (r, t = 0) => { | ||
te(r); | ||
const e = await Ct(z(r)), s = q(t, e); | ||
return new w({ decimal: e, value: s, identifier: r }); | ||
}; | ||
class w extends E { | ||
constructor(e) { | ||
const s = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`; | ||
super( | ||
@@ -901,3 +909,3 @@ e.value instanceof E ? e.value : { decimal: e.decimal, value: e.value } | ||
f(this, "type"); | ||
const r = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`, n = z(r); | ||
const n = z(s); | ||
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; | ||
@@ -909,4 +917,4 @@ } | ||
toString(e = !1) { | ||
const r = this.isSynthetic ? this.symbol.split("-")[0] : `${this.chain}.${this.ticker}`; | ||
return e ? r : ( | ||
const s = this.isSynthetic ? this.symbol.split("-")[0] : `${this.chain}.${this.ticker}`; | ||
return e ? s : ( | ||
// THOR.ETH/ETH | ETH.USDT-0x1234567890 | ||
@@ -916,23 +924,23 @@ `${this.chain}.${this.symbol}` | ||
} | ||
eq({ chain: e, symbol: r }) { | ||
return this.chain === e && this.symbol === r; | ||
eq({ chain: e, symbol: s }) { | ||
return this.chain === e && this.symbol === s; | ||
} | ||
static async fromString(e, r = 0) { | ||
return st(e, r); | ||
static async fromString(e, s = 0) { | ||
return rt(e, s); | ||
} | ||
static fromStringSync(e, r = 0) { | ||
const { isSynthetic: n } = z(e), { decimal: i, identifier: c } = rt( | ||
static fromStringSync(e, s = 0) { | ||
const { isSynthetic: n } = z(e), { decimal: i, identifier: c } = st( | ||
e | ||
), a = k(r, i); | ||
), a = q(s, i); | ||
return c ? new w({ decimal: i, identifier: c, value: a }) : n ? new w({ decimal: 8, identifier: e, value: a }) : void 0; | ||
} | ||
static async fromIdentifier(e, r = 0) { | ||
return st(e, r); | ||
static async fromIdentifier(e, s = 0) { | ||
return rt(e, s); | ||
} | ||
static fromIdentifierSync(e, r = 0) { | ||
const { decimal: n, identifier: i } = rt(e), c = k(r, n); | ||
static fromIdentifierSync(e, s = 0) { | ||
const { decimal: n, identifier: i } = st(e), c = q(s, n); | ||
return new w({ decimal: n, identifier: i, value: c }); | ||
} | ||
static fromChainOrSignature(e, r = 0) { | ||
const { decimal: n, identifier: i } = It(e), c = k(r, n); | ||
static fromChainOrSignature(e, s = 0) { | ||
const { decimal: n, identifier: i } = It(e), c = q(s, n); | ||
return new w({ value: c, decimal: n, identifier: i }); | ||
@@ -942,3 +950,3 @@ } | ||
return new Promise( | ||
async (e, r) => { | ||
async (e, s) => { | ||
try { | ||
@@ -960,3 +968,3 @@ const { | ||
} catch (n) { | ||
console.error(n), r({ | ||
console.error(n), s({ | ||
ok: !1, | ||
@@ -971,5 +979,5 @@ error: n, | ||
} | ||
const _e = (s) => { | ||
const t = w.fromChainOrSignature(s); | ||
switch (s) { | ||
const _e = (r) => { | ||
const t = w.fromChainOrSignature(r); | ||
switch (r) { | ||
case o.Bitcoin: | ||
@@ -990,8 +998,8 @@ case o.Litecoin: | ||
} | ||
}, z = (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("-"); | ||
}, z = (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("-"); | ||
return { | ||
address: u == null ? void 0 : u.toLowerCase(), | ||
chain: i, | ||
isGasAsset: Ct({ chain: i, symbol: c }), | ||
isGasAsset: it({ chain: i, symbol: c }), | ||
isSynthetic: t, | ||
@@ -1058,5 +1066,5 @@ symbol: (t ? `${e}/` : "") + (u ? `${a}-${(u == null ? void 0 : u.toLowerCase()) ?? ""}` : c), | ||
}; | ||
class dt extends Error { | ||
class mt 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: ee[t], message: t } }), Object.setPrototypeOf(this, mt.prototype); | ||
} | ||
@@ -1079,3 +1087,3 @@ } | ||
Zt as RequestClient, | ||
dt as SwapKitError, | ||
mt as SwapKitError, | ||
b as SwapKitNumber, | ||
@@ -1093,3 +1101,3 @@ ie as assetFromString, | ||
It as getCommonAssetInfo, | ||
St as getDecimal, | ||
Ct as getDecimal, | ||
le as getEstimatedPoolShare, | ||
@@ -1099,7 +1107,7 @@ he as getLiquiditySlippage, | ||
_e as getMinAmountByChain, | ||
kt as getSymmetricPoolShare, | ||
qt as getSymmetricPoolShare, | ||
ue as getSymmetricWithdraw, | ||
me as getTHORNameCost, | ||
Ct as isGasAsset, | ||
it as isGasAsset, | ||
pe as validateTHORName | ||
}; |
@@ -45,3 +45,3 @@ { | ||
"types": "./dist/index.d.ts", | ||
"version": "1.0.0-rc.23", | ||
"version": "1.0.0-rc.24", | ||
"scripts": { | ||
@@ -48,0 +48,0 @@ "build": "vite build", |
import type { EVMChain } from '@swapkit/types'; | ||
import { BaseDecimal, Chain, ChainToRPC, EVMChainList, FeeOption } from '@swapkit/types'; | ||
import { type AssetValue, RequestClient } from '../index.ts'; | ||
import { RequestClient } from '../index.ts'; | ||
@@ -190,14 +190,22 @@ const getDecimalMethodHex = '0x313ce567'; | ||
const evmAssetHasAddress = (asset: AssetValue) => { | ||
if (!EVMChainList.includes(asset.chain as EVMChain)) return true; | ||
const evmAssetHasAddress = (assetString: string) => { | ||
const [chain, symbol] = assetString.split('.') as [EVMChain, string]; | ||
if (!EVMChainList.includes(chain as EVMChain)) return true; | ||
const [, address] = symbol.split('-') as [string, string?]; | ||
return !asset.isGasAsset && asset.address && !Number.isNaN(asset.decimal); | ||
return isGasAsset({ chain: chain as Chain, symbol }) || !!address; | ||
}; | ||
export const filterAssets = (assets: AssetValue[]) => | ||
assets.filter( | ||
(asset) => | ||
!asset.toString().includes('undefined') && | ||
!potentialScamRegex.test(asset.toString()) && | ||
evmAssetHasAddress(asset), | ||
); | ||
export const filterAssets = ( | ||
tokens: { | ||
value: string; | ||
decimal: number; | ||
chain: Chain; | ||
symbol: string; | ||
}[], | ||
) => | ||
tokens.filter((token) => { | ||
const assetString = `${token.chain}.${token.symbol}`; | ||
return !potentialScamRegex.test(assetString) && evmAssetHasAddress(assetString); | ||
}); |
@@ -79,2 +79,4 @@ import type { | ||
constructor(params: AssetValueParams) { | ||
const identifier = | ||
'identifier' in params ? params.identifier : `${params.chain}.${params.symbol}`; | ||
super( | ||
@@ -86,6 +88,3 @@ params.value instanceof BigIntArithmetics | ||
const identifier = | ||
'identifier' in params ? params.identifier : `${params.chain}.${params.symbol}`; | ||
const assetInfo = getAssetInfo(identifier); | ||
this.type = getAssetType(assetInfo); | ||
@@ -132,3 +131,3 @@ this.chain = assetInfo.chain; | ||
return tokenIdentifier | ||
const asset = tokenIdentifier | ||
? new AssetValue({ decimal, identifier: tokenIdentifier, value: parsedValue }) | ||
@@ -138,2 +137,4 @@ : isSynthetic | ||
: undefined; | ||
return asset; | ||
} | ||
@@ -140,0 +141,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
196849
3614