Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@swapkit/helpers

Package Overview
Dependencies
Maintainers
1
Versions
221
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@swapkit/helpers - npm Package Compare versions

Comparing version 1.0.0-rc.46 to 1.0.0-rc.47

347

dist/index.es.js

@@ -7,3 +7,3 @@ var bt = Object.defineProperty;

};
var $ = (r, t, e) => {
var T = (r, t, e) => {
if (t.has(r))

@@ -14,4 +14,4 @@ throw TypeError("Cannot add the same private member more than once");

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", it = async ({ chain: r, to: t }) => {
import { FeeOption as H, BaseDecimal as h, 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 {

@@ -33,13 +33,13 @@ const { result: e } = await Zt.post(vt[r], {

} catch (e) {
return console.error(e), d[r];
return console.error(e), h[r];
}
}, $t = async (r) => {
if (r === o.Ethereum)
return d.ETH;
return h.ETH;
const [, t] = r.split("-");
return t != null && t.startsWith("0x") ? it({ chain: o.Ethereum, to: t }) : d.ETH;
return t != null && t.startsWith("0x") ? nt({ chain: o.Ethereum, to: t }) : h.ETH;
}, Rt = async (r) => {
const [, t] = r.split("-");
return t != null && t.startsWith("0x") ? it({ chain: o.Avalanche, to: t.toLowerCase() }) : d.AVAX;
}, St = async (r) => r === o.BinanceSmartChain ? d.BSC : d.BSC, Ct = async ({ chain: r, symbol: t }) => {
return t != null && t.startsWith("0x") ? nt({ chain: o.Avalanche, to: t.toLowerCase() }) : h.AVAX;
}, St = async (r) => r === o.BinanceSmartChain ? h.BSC : h.BSC, Ct = async ({ chain: r, symbol: t }) => {
switch (r) {

@@ -53,9 +53,9 @@ case o.Ethereum:

default:
return d[r];
return h[r];
}
}, ie = {
[L.Average]: 1.2,
[L.Fast]: 1.5,
[L.Fastest]: 2
}, ot = ({ chain: r, symbol: t }) => {
[H.Average]: 1.2,
[H.Fast]: 1.5,
[H.Fastest]: 2
}, it = ({ chain: r, symbol: t }) => {
switch (r) {

@@ -93,9 +93,9 @@ case o.Bitcoin:

case o.Cosmos:
return { identifier: "GAIA.ATOM", decimal: d[r] };
return { identifier: "GAIA.ATOM", decimal: h[r] };
case o.THORChain:
return { identifier: "THOR.RUNE", decimal: d[r] };
return { identifier: "THOR.RUNE", decimal: h[r] };
case o.BinanceSmartChain:
return { identifier: "BSC.BNB", decimal: d[r] };
return { identifier: "BSC.BNB", decimal: h[r] };
case o.Maya:
return { identifier: "MAYA.CACAO", decimal: d.MAYA };
return { identifier: "MAYA.CACAO", decimal: h.MAYA };
case "MAYA.MAYA":

@@ -114,3 +114,3 @@ return { identifier: "MAYA.MAYA", decimal: 4 };

case o.Ethereum:
return { identifier: `${r}.${r}`, decimal: d[r] };
return { identifier: `${r}.${r}`, decimal: h[r] };
}

@@ -159,3 +159,3 @@ }, Ot = ({ chain: r, symbol: t }) => {

const [, s] = e.split("-");
return ot({ chain: t, symbol: e }) || !!s;
return it({ chain: t, symbol: e }) || !!s;
}, ae = (r) => r.filter((t) => {

@@ -169,4 +169,4 @@ const e = `${t.chain}.${t.symbol}`;

}) => {
const s = p(r), n = p(t), i = p(e), a = s.mul(i), c = n.mul(n).mul(2), u = n.mul(s).mul(2), h = s.mul(s), l = n.mul(n).mul(n);
return a.mul(c.sub(u).add(h)).div(l);
const s = p(r), n = p(t), i = p(e), a = s.mul(i), c = n.mul(n).mul(2), u = n.mul(s).mul(2), d = s.mul(s), l = n.mul(n).mul(n);
return a.mul(c.sub(u).add(d)).div(l);
}, xt = ({

@@ -177,3 +177,3 @@ liquidityUnits: r,

}) => {
const s = p(r), n = p(t), i = p(e), a = s.mul(i), c = n.mul(n).mul(2), u = n.mul(s).mul(2), h = s.mul(s), l = a.mul(c.sub(u).add(h)), _ = n.mul(n).mul(n);
const s = p(r), n = p(t), i = p(e), a = s.mul(i), c = n.mul(n).mul(2), u = n.mul(s).mul(2), d = s.mul(s), l = a.mul(c.sub(u).add(d)), _ = n.mul(n).mul(n);
return l.div(_);

@@ -190,3 +190,3 @@ }, ce = ({

poolUnits: s
}) => xt({ assetDepth: t, liquidityUnits: e, poolUnits: s }).mul(r), p = (r) => b.fromBigInt(BigInt(r), d.THOR), qt = ({
}) => xt({ assetDepth: t, liquidityUnits: e, poolUnits: s }).mul(r), p = (r) => b.fromBigInt(BigInt(r), h.THOR), qt = ({
liquidityUnits: r,

@@ -209,3 +209,3 @@ poolUnits: t,

)
), he = ({
), de = ({
runeDepth: r,

@@ -218,8 +218,8 @@ poolUnits: t,

}) => {
const a = new b({ value: r, decimal: 8 }), c = new b({ value: e, decimal: 8 }), u = new b({ value: t, decimal: 8 }), h = new b({ value: n, decimal: 8 }), l = new b({ value: i, decimal: 8 }), _ = h.mul(c), T = l.mul(a), j = h.mul(l), pt = a.mul(c), 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 gt = u.add(H);
return H.div(gt).getBaseValue("number");
}, de = ({
const a = new b({ value: r, decimal: 8 }), c = new b({ value: e, decimal: 8 }), u = new b({ value: t, decimal: 8 }), d = new b({ value: n, decimal: 8 }), l = new b({ value: i, decimal: 8 }), _ = d.mul(c), N = l.mul(a), mt = d.mul(l), pt = a.mul(c), ft = u.mul(_.add(N.add(mt.mul(2)))), _t = _.add(N.add(pt.mul(2))), K = ft.div(_t), j = p(s).add(K);
if (K.getBaseValue("number") === 0)
return j.div(u).getBaseValue("number");
const gt = u.add(j);
return j.div(gt).getBaseValue("number");
}, he = ({
runeAmount: r,

@@ -232,4 +232,4 @@ assetAmount: t,

return 0;
const n = p(e), i = p(s), a = p(t), c = p(r), u = a.mul(n).sub(i.mul(c)), h = i.mul(c).add(n.mul(i));
return Math.abs(u.div(h).getBaseValue("number"));
const n = p(e), i = p(s), a = p(t), c = p(r), u = a.mul(n).sub(i.mul(c)), d = i.mul(c).add(n.mul(i));
return Math.abs(u.div(d).getBaseValue("number"));
}, kt = ({

@@ -259,4 +259,4 @@ symbol: r,

case g.WITHDRAW: {
const { chain: e, ticker: s, symbol: n, basisPoints: i, targetAssetString: a, singleSide: c } = t, u = !c && a ? `:${a}` : "", h = kt({ chain: e, symbol: n, ticker: s });
return `${r}:${e}${c ? "/" : "."}${h}:${i}${u}`;
const { chain: e, ticker: s, symbol: n, basisPoints: i, targetAssetString: a, singleSide: c } = t, u = !c && a ? `:${a}` : "", d = kt({ chain: e, symbol: n, ticker: s });
return `${r}:${e}${c ? "/" : "."}${d}:${i}${u}`;
}

@@ -281,3 +281,3 @@ case g.OPEN_LOAN:

}, _e = ([r, t, e, s, n]) => `${r}'/${t}'/${e}'/${s}${typeof n != "number" ? "" : `/${n}`}`;
class X extends Error {
class Q extends Error {
constructor(t, e, s) {

@@ -303,3 +303,3 @@ const n = t.status || t.status === 0 ? t.status : "", i = t.statusText || "", a = `${n} ${i}`.trim(), c = a ? `status code ${a}` : "an unknown error";

}
class at extends Error {
class ot extends Error {
constructor(t) {

@@ -314,8 +314,8 @@ super("Request timed out"), Object.defineProperty(this, "request", {

}
const q = (r) => r !== null && typeof r == "object", B = (...r) => {
const x = (r) => r !== null && typeof r == "object", M = (...r) => {
for (const t of r)
if ((!q(t) || Array.isArray(t)) && t !== void 0)
if ((!x(t) || Array.isArray(t)) && t !== void 0)
throw new TypeError("The `options` argument must be an object");
return J({}, ...r);
}, ct = (r = {}, t = {}) => {
return z({}, ...r);
}, at = (r = {}, t = {}) => {
const e = new globalThis.Headers(r), s = t instanceof globalThis.Headers, n = new globalThis.Headers(t);

@@ -325,3 +325,3 @@ for (const [i, a] of n.entries())

return e;
}, J = (...r) => {
}, z = (...r) => {
let t = {}, e = {};

@@ -331,6 +331,6 @@ for (const s of r)

Array.isArray(t) || (t = []), t = [...t, ...s];
else if (q(s)) {
else if (x(s)) {
for (let [n, i] of Object.entries(s))
q(i) && n in t && (i = J(t[n], i)), t = { ...t, [n]: i };
q(s.headers) && (e = ct(e, s.headers), t.headers = e);
x(i) && n in t && (i = z(t[n], i)), t = { ...t, [n]: i };
x(s.headers) && (e = at(e, s.headers), t.headers = e);
}

@@ -349,3 +349,3 @@ return t;

}).headers.has("Content-Type")), r && !t;
})(), Pt = typeof globalThis.AbortController == "function", Nt = typeof globalThis.ReadableStream == "function", jt = typeof globalThis.FormData == "function", ut = ["get", "post", "put", "patch", "head", "delete"], Ht = {
})(), 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",

@@ -356,3 +356,3 @@ text: "text/*",

blob: "*/*"
}, D = 2147483647, lt = Symbol("stop"), Lt = {
}, L = 2147483647, ut = Symbol("stop"), Lt = {
json: !0,

@@ -384,7 +384,7 @@ parseJson: !0,

duplex: !0
}, Ut = (r) => ut.includes(r) ? r.toUpperCase() : r, Ft = ["get", "put", "head", "delete", "options", "trace"], Wt = [408, 413, 429, 500, 502, 503, 504], ht = [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], X = {
limit: 2,
methods: Ft,
statusCodes: Wt,
afterStatusCodes: ht,
afterStatusCodes: lt,
maxRetryAfter: Number.POSITIVE_INFINITY,

@@ -396,3 +396,3 @@ backoffLimit: Number.POSITIVE_INFINITY,

return {
...Z,
...X,
limit: r

@@ -405,5 +405,5 @@ };

return {
...Z,
...X,
...r,
afterStatusCodes: ht
afterStatusCodes: lt
};

@@ -414,3 +414,3 @@ };

const a = setTimeout(() => {
e && e.abort(), i(new at(r));
e && e.abort(), i(new ot(r));
}, s.timeout);

@@ -439,17 +439,17 @@ s.fetch(r, t).then(n).catch(i).then(() => {

};
class V {
class k {
static create(t, e) {
const s = new V(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}`);
const s = new k(t, e), n = async () => {
if (typeof s._options.timeout == "number" && s._options.timeout > L)
throw new RangeError(`The \`timeout\` option cannot be greater than ${L}`);
await Promise.resolve();
let c = await s._fetch();
for (const u of s._options.hooks.afterResponse) {
const h = await u(s.request, s._options, s._decorateResponse(c.clone()));
h instanceof globalThis.Response && (c = h);
const d = await u(s.request, s._options, s._decorateResponse(c.clone()));
d instanceof globalThis.Response && (c = d);
}
if (s._decorateResponse(c), !c.ok && s._options.throwHttpErrors) {
let u = new X(c, s.request, s._options);
for (const h of s._options.hooks.beforeError)
u = await h(u);
let u = new Q(c, s.request, s._options);
for (const d of s._options.hooks.beforeError)
u = await d(u);
throw u;

@@ -511,4 +511,4 @@ }

...e,
headers: ct(this._input.headers, e.headers),
hooks: J({
headers: at(this._input.headers, e.headers),
hooks: z({
beforeRequest: [],

@@ -549,4 +549,4 @@ beforeRetry: [],

_calculateRetryDelay(t) {
if (this._retryCount++, this._retryCount < this._options.retry.limit && !(t instanceof at)) {
if (t instanceof X) {
if (this._retryCount++, this._retryCount < this._options.retry.limit && !(t instanceof ot)) {
if (t instanceof Q) {
if (!this._options.retry.statusCodes.includes(t.response.status))

@@ -574,3 +574,3 @@ return 0;

} catch (e) {
const s = Math.min(this._calculateRetryDelay(e), D);
const s = Math.min(this._calculateRetryDelay(e), L);
if (s !== 0 && this._retryCount > 0) {

@@ -584,3 +584,3 @@ await zt(s, { signal: this._options.signal });

retryCount: this._retryCount
}) === lt)
}) === ut)
return;

@@ -618,3 +618,3 @@ return this._retry(t);

async function c() {
const { done: u, value: h } = await a.read();
const { done: u, value: d } = await a.read();
if (u) {

@@ -625,7 +625,7 @@ i.close();

if (e) {
n += h.byteLength;
n += d.byteLength;
const l = s === 0 ? 0 : n / s;
e({ percent: l, transferredBytes: n, totalBytes: s }, h);
e({ percent: l, transferredBytes: n, totalBytes: s }, d);
}
i.enqueue(h), await c();
i.enqueue(d), await c();
}

@@ -642,16 +642,16 @@ await c();

/*! MIT License © Sindre Sorhus */
const U = (r) => {
const t = (e, s) => V.create(e, B(r, s));
for (const e of ut)
t[e] = (s, n) => V.create(s, B(r, n, { method: e }));
return t.create = (e) => U(B(e)), t.extend = (e) => U(B(r, e)), t.stop = lt, t;
}, Kt = U(), Qt = Kt, Xt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, tt = Qt.create({ headers: Xt }), Zt = {
get: (r, t) => tt.get(r, t).json(),
post: (r, t) => tt.post(r, t).json()
}, et = Object.values(o), te = (r = "") => {
const D = (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) => D(M(e)), t.extend = (e) => D(M(r, e)), t.stop = ut, t;
}, Kt = D(), Qt = Kt, Xt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, Z = Qt.create({ headers: Xt }), Zt = {
get: (r, t) => Z.get(r, t).json(),
post: (r, t) => Z.post(r, t).json()
}, tt = Object.values(o), te = (r = "") => {
const t = r.toUpperCase(), [e] = t.split(".");
if (et.includes(e))
if (tt.includes(e))
return !0;
const [s] = t.split("/");
if (et.includes(s))
if (tt.includes(s))
return !0;

@@ -661,7 +661,7 @@ throw new Error(

);
}, I = 8, w = (r) => 10n ** BigInt(r), S = (r) => Math.log10(parseFloat(r.toString()));
function P({
}, C = 8, w = (r) => 10n ** BigInt(r), R = (r) => Math.log10(parseFloat(r.toString()));
function V({
value: r,
bigIntDecimal: t = I,
decimal: e = I
bigIntDecimal: t = C,
decimal: e = C
}) {

@@ -679,20 +679,20 @@ const s = r < 0n;

}
var v, C, y, R, N, dt, E, F, M, W;
const K = class K {
var v, S, y, $, P, dt, O, U, E, F;
const J = class J {
constructor(t) {
$(this, v);
$(this, y);
$(this, N);
$(this, E);
$(this, M);
T(this, v);
T(this, y);
T(this, P);
T(this, O);
T(this, E);
f(this, "decimalMultiplier", 10n ** 8n);
f(this, "bigIntValue", 0n);
f(this, "decimal");
const e = G(t), s = typeof t == "object";
this.decimal = s ? t.decimal : void 0, this.decimalMultiplier = s && "decimalMultiplier" in t ? t.decimalMultiplier : w(Math.max(st(x(e)), this.decimal || 0)), m(this, N, dt).call(this, e);
const e = W(t), s = typeof t == "object";
this.decimal = s ? t.decimal : void 0, this.decimalMultiplier = s && "decimalMultiplier" in t ? t.decimalMultiplier : w(Math.max(et(B(e)), this.decimal || 0)), m(this, P, dt).call(this, e);
}
static fromBigInt(t, e) {
return new K({
return new J({
decimal: e,
value: P({ value: t, bigIntDecimal: e, decimal: e })
value: V({ value: t, bigIntDecimal: e, decimal: e })
});

@@ -714,27 +714,27 @@ }

add(...t) {
return m(this, v, C).call(this, "add", ...t);
return m(this, v, S).call(this, "add", ...t);
}
sub(...t) {
return m(this, v, C).call(this, "sub", ...t);
return m(this, v, S).call(this, "sub", ...t);
}
mul(...t) {
return m(this, v, C).call(this, "mul", ...t);
return m(this, v, S).call(this, "mul", ...t);
}
div(...t) {
return m(this, v, C).call(this, "div", ...t);
return m(this, v, S).call(this, "div", ...t);
}
gt(t) {
return m(this, y, R).call(this, "gt", t);
return m(this, y, $).call(this, "gt", t);
}
gte(t) {
return m(this, y, R).call(this, "gte", t);
return m(this, y, $).call(this, "gte", t);
}
lt(t) {
return m(this, y, R).call(this, "lt", t);
return m(this, y, $).call(this, "lt", t);
}
lte(t) {
return m(this, y, R).call(this, "lte", t);
return m(this, y, $).call(this, "lte", t);
}
eqValue(t) {
return m(this, y, R).call(this, "eqValue", t);
return m(this, y, $).call(this, "eqValue", t);
}

@@ -745,3 +745,3 @@ // @ts-expect-error False positive

this.bigIntValue,
this.decimal || S(this.decimalMultiplier)
this.decimal || R(this.decimalMultiplier)
);

@@ -759,3 +759,3 @@ switch (t) {

getBaseValue(t) {
const e = this.decimalMultiplier / w(this.decimal || d.THOR), s = this.bigIntValue / e;
const e = this.decimalMultiplier / w(this.decimal || h.THOR), s = this.bigIntValue / e;
switch (t) {

@@ -773,4 +773,4 @@ case "number":

return t.bigIntValue;
const s = G(t), n = x(s);
return n === "0" || n === "undefined" ? 0n : m(this, M, W).call(this, n, e);
const s = W(t), n = B(s);
return n === "0" || n === "undefined" ? 0n : m(this, E, F).call(this, n, e);
}

@@ -817,21 +817,21 @@ toSignificant(t = 6) {

} = {}) {
const a = this.getValue("number"), [c, u = ""] = a.toFixed(6).split("."), h = c.replace(/\B(?=(\d{3})+(?!\d))/g, i), l = !c && !u ? "0.00" : c === "0" ? `${parseFloat(`0.${u}`)}`.replace(".", n) : `${h}${parseInt(u) ? `${n}${u.slice(0, s)}` : ""}`;
const a = this.getValue("number"), [c, u = ""] = a.toFixed(6).split("."), d = c.replace(/\B(?=(\d{3})+(?!\d))/g, i), l = !c && !u ? "0.00" : c === "0" ? `${parseFloat(`0.${u}`)}`.replace(".", n) : `${d}${parseInt(u) ? `${n}${u.slice(0, s)}` : ""}`;
return `${e === "start" ? t : ""}${l}${e === "end" ? t : ""}`;
}
formatBigIntToSafeValue(t, e) {
const s = e || this.decimal || I, n = Math.max(
const s = e || this.decimal || C, n = Math.max(
s,
S(this.decimalMultiplier)
), i = t < 0n, a = t.toString().substring(i ? 1 : 0), c = n - (a.length - 1), u = c > 0 ? "0".repeat(c) + a : a, h = u.length - n;
R(this.decimalMultiplier)
), i = t < 0n, a = t.toString().substring(i ? 1 : 0), c = n - (a.length - 1), u = c > 0 ? "0".repeat(c) + a : a, d = u.length - n;
let l = u.slice(-n);
return parseInt(l[s]) >= 5 ? l = `${l.substring(0, s - 1)}${(parseInt(l[s - 1]) + 1).toString()}` : l = l.substring(0, s), `${i ? "-" : ""}${u.slice(
0,
h
d
)}.${l}`.replace(/\.?0*$/, "");
}
};
v = new WeakSet(), C = function(t, ...e) {
const s = m(this, E, F).call(this, this, ...e), n = Math.max(s, S(this.decimalMultiplier)), i = w(n), a = e.reduce(
(u, h) => {
const l = this.getBigIntValue(h, n);
v = new WeakSet(), S = function(t, ...e) {
const s = m(this, O, U).call(this, this, ...e), n = Math.max(s, R(this.decimalMultiplier)), i = w(n), a = e.reduce(
(u, d) => {
const l = this.getBigIntValue(d, n);
switch (t) {

@@ -855,3 +855,3 @@ case "add":

this.bigIntValue * i / this.decimalMultiplier
), c = P({
), c = V({
bigIntDecimal: n,

@@ -867,4 +867,4 @@ decimal: n,

});
}, y = new WeakSet(), R = function(t, ...e) {
const s = m(this, E, F).call(this, this, ...e), n = this.getBigIntValue(e[0], s), i = this.getBigIntValue(this, s);
}, y = new WeakSet(), $ = function(t, ...e) {
const s = m(this, O, U).call(this, this, ...e), n = this.getBigIntValue(e[0], s), i = this.getBigIntValue(this, s);
switch (t) {

@@ -882,13 +882,13 @@ case "gt":

}
}, N = new WeakSet(), dt = function(t) {
const e = x(t) || "0";
this.bigIntValue = m(this, M, W).call(this, e);
}, E = new WeakSet(), F = function(...t) {
const e = t.map((s) => typeof s == "object" ? s.decimal || S(s.decimalMultiplier) : st(x(s))).filter(Boolean);
return Math.max(...e, I);
}, M = new WeakSet(), W = function(t, e) {
const s = e ? w(e) : this.decimalMultiplier, n = S(s), [i = "", a = ""] = t.split(".");
}, P = new WeakSet(), dt = function(t) {
const e = B(t) || "0";
this.bigIntValue = m(this, E, F).call(this, e);
}, O = new WeakSet(), U = function(...t) {
const e = t.map((s) => typeof s == "object" ? s.decimal || R(s.decimalMultiplier) : et(B(s))).filter(Boolean);
return Math.max(...e, C);
}, E = new WeakSet(), F = function(t, e) {
const s = e ? w(e) : this.decimalMultiplier, n = R(s), [i = "", a = ""] = t.split(".");
return BigInt(`${i}${a.padEnd(n, "0")}`);
};
let O = K;
let I = J;
const ee = Intl.NumberFormat("fullwide", {

@@ -898,30 +898,30 @@ useGrouping: !1,

});
function x(r) {
const e = `${typeof r == "number" ? ee.format(r) : G(r)}`.replaceAll(",", ".").split(".");
function B(r) {
const e = `${typeof r == "number" ? ee.format(r) : W(r)}`.replaceAll(",", ".").split(".");
return e.length > 1 ? `${e.slice(0, -1).join("")}.${e.at(-1)}` : e[0];
}
function st(r) {
function et(r) {
var e;
const t = ((e = r.split(".")[1]) == null ? void 0 : e.length) || 0;
return Math.max(t, I);
return Math.max(t, C);
}
function G(r) {
function W(r) {
return typeof r == "object" ? "getValue" in r ? r.getValue("string") : r.value : r;
}
const k = (r, t) => typeof r == "bigint" ? P({ value: r, bigIntDecimal: t, decimal: t }) : r;
let Y;
const rt = (r) => {
if (!Y)
const q = (r, t) => typeof r == "bigint" ? V({ value: r, bigIntDecimal: t, decimal: t }) : r;
let G;
const st = (r) => {
if (!G)
throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");
return Y.get(r.toUpperCase()) || { decimal: d.THOR, identifier: "" };
}, nt = async (r, t = 0) => {
return G.get(r.toUpperCase()) || { decimal: h.THOR, identifier: "" };
}, rt = async (r, t = 0) => {
te(r);
const e = await Ct(z(r)), s = k(t, e);
const e = await Ct(Y(r)), s = q(t, e);
return new A({ decimal: e, value: s, identifier: r });
};
class A extends O {
class A extends I {
constructor(e) {
const s = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`;
super(
e.value instanceof O ? e.value : { decimal: e.decimal, value: e.value }
e.value instanceof I ? e.value : { decimal: e.decimal, value: e.value }
);

@@ -936,3 +936,3 @@ f(this, "address");

f(this, "type");
const n = z(s);
const n = Y(s);
this.type = Ot(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;

@@ -957,21 +957,21 @@ }

static async fromString(e, s = 0) {
return nt(e, s);
return rt(e, s);
}
static fromStringSync(e, s = 0) {
const { isSynthetic: n } = z(e), {
const { isSynthetic: n } = Y(e), {
tax: i,
decimal: a,
identifier: c
} = rt(e), u = k(s, a);
} = st(e), u = q(s, a);
return c ? new A({ tax: i, decimal: a, identifier: c, value: u }) : n ? new A({ tax: i, decimal: 8, identifier: e, value: u }) : void 0;
}
static async fromIdentifier(e, s = 0) {
return nt(e, s);
return rt(e, s);
}
static fromIdentifierSync(e, s = 0) {
const { decimal: n, identifier: i } = rt(e), a = k(s, n);
const { decimal: n, identifier: i } = st(e), a = q(s, n);
return new A({ decimal: n, identifier: i, value: a });
}
static fromChainOrSignature(e, s = 0) {
const { decimal: n, identifier: i } = It(e), a = k(s, n);
const { decimal: n, identifier: i } = It(e), a = q(s, n);
return new A({ value: a, decimal: n, identifier: i });

@@ -983,16 +983,7 @@ }

try {
const {
// Omit ThorchainList from import to avoid decimals conflict (TC uses 8 for all)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
ThorchainList: n,
NativeList: i,
...a
} = await import("@swapkit/tokens");
Y = [i, ...Object.values(a)].reduce(
(u, { tokens: h }) => (h.forEach(({ identifier: l, chain: _, ...T }) => {
const j = "decimals" in T ? T.decimals : d[_];
u.set(l, { identifier: l, decimal: j });
}), u),
/* @__PURE__ */ new Map()
), e({ ok: !0 });
const n = await import("@swapkit/tokens");
G = Object.values(n).reduce((a, { tokens: c }) => (c.forEach(({ identifier: u, chain: d, ...l }) => {
const _ = "decimals" in l ? l.decimals : h[d];
a.set(u, { identifier: u, decimal: _ });
}), a), /* @__PURE__ */ new Map()), e({ ok: !0 });
} catch (n) {

@@ -1027,3 +1018,3 @@ console.error(n), s({

}
}, z = (r) => {
}, Y = (r) => {
const t = r.slice(0, 14).includes("/"), [e, s] = r.split(".").pop().split("/"), n = r.includes(".") && !t ? r : `${o.THORChain}.${s}`, [i, a] = n.split("."), [c, u] = (t ? s : a).split("-");

@@ -1033,3 +1024,3 @@ return {

chain: i,
isGasAsset: ot({ chain: i, symbol: a }),
isGasAsset: it({ chain: i, symbol: a }),
isSynthetic: t,

@@ -1097,8 +1088,8 @@ symbol: (t ? `${e}/` : "") + (u ? `${c}-${(u == null ? void 0 : u.toLowerCase()) ?? ""}` : a),

};
class mt extends Error {
class ht 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: se[t], message: t } }), Object.setPrototypeOf(this, mt.prototype);
console.error(e, { stack: e == null ? void 0 : e.stack, message: e == null ? void 0 : e.message }), super(t, { cause: { code: se[t], message: t } }), Object.setPrototypeOf(this, ht.prototype);
}
}
class b extends O {
class b extends I {
eq(t) {

@@ -1110,3 +1101,3 @@ return this.eqValue(t);

decimal: e,
value: P({ value: t, bigIntDecimal: e, decimal: e })
value: V({ value: t, bigIntDecimal: e, decimal: e })
});

@@ -1117,5 +1108,5 @@ }

A as AssetValue,
O as BigIntArithmetics,
I as BigIntArithmetics,
Zt as RequestClient,
mt as SwapKitError,
ht as SwapKitError,
b as SwapKitNumber,

@@ -1125,3 +1116,3 @@ oe as assetFromString,

ae as filterAssets,
P as formatBigIntToSafeValue,
V as formatBigIntToSafeValue,
ie as gasFeeMultiplier,

@@ -1135,4 +1126,4 @@ Ot as getAssetType,

Ct as getDecimal,
he as getEstimatedPoolShare,
de as getLiquiditySlippage,
de as getEstimatedPoolShare,
he as getLiquiditySlippage,
me as getMemoFor,

@@ -1143,4 +1134,4 @@ ge as getMinAmountByChain,

pe as getTHORNameCost,
ot as isGasAsset,
it as isGasAsset,
fe as validateTHORName
};

@@ -11,5 +11,5 @@ {

"vitest": "0.34.6",
"@internal/config": "0.0.0-rc.10",
"@swapkit/tokens": "1.0.0-rc.26",
"@swapkit/types": "1.0.0-rc.24"
"@internal/config": "0.0.0-rc.11",
"@swapkit/tokens": "1.0.0-rc.27",
"@swapkit/types": "1.0.0-rc.25"
},

@@ -20,4 +20,4 @@ "eslintConfig": {

"peerDependencies": {
"@swapkit/tokens": "1.0.0-rc.26",
"@swapkit/types": "1.0.0-rc.24"
"@swapkit/tokens": "1.0.0-rc.27",
"@swapkit/types": "1.0.0-rc.25"
},

@@ -47,3 +47,3 @@ "exports": {

"types": "./dist/index.d.ts",
"version": "1.0.0-rc.46",
"version": "1.0.0-rc.47",
"scripts": {

@@ -50,0 +50,0 @@ "build": "vite build",

@@ -172,21 +172,12 @@ import type {

try {
const {
// Omit ThorchainList from import to avoid decimals conflict (TC uses 8 for all)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
ThorchainList: _ThorchainList,
NativeList,
...tokensPackage
} = await import('@swapkit/tokens');
const tokensMap = [NativeList, ...Object.values(tokensPackage)].reduce(
(acc, { tokens }) => {
tokens.forEach(({ identifier, chain, ...rest }) => {
const decimal = 'decimals' in rest ? rest.decimals : BaseDecimal[chain as Chain];
const tokenPackages = await import('@swapkit/tokens');
const tokensMap = Object.values(tokenPackages).reduce((acc, { tokens }) => {
tokens.forEach(({ identifier, chain, ...rest }) => {
const decimal = 'decimals' in rest ? rest.decimals : BaseDecimal[chain as Chain];
acc.set(identifier as TokenNames, { identifier, decimal });
});
acc.set(identifier as TokenNames, { identifier, decimal });
});
return acc;
},
new Map<TokenNames, { decimal: number; identifier: string }>(),
);
return acc;
}, new Map<TokenNames, { decimal: number; identifier: string }>());

@@ -193,0 +184,0 @@ staticTokensMap = tokensMap;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc