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.25 to 1.0.0-rc.26

485

dist/index.es.js

@@ -1,8 +0,8 @@

var yt = Object.defineProperty;
var wt = (r, t, e) => t in r ? yt(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
var f = (r, t, e) => (wt(r, typeof t != "symbol" ? t + "" : t, e), e), At = (r, t, e) => {
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))
throw TypeError("Cannot " + e);
};
var y = (r, t, e) => {
var T = (r, t, e) => {
if (t.has(r))

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

};
var d = (r, t, e) => (At(r, t, "access private method"), e);
import { FeeOption as D, BaseDecimal as p, Chain as o, EVMChainList as vt, ChainToRPC as Tt, MemoType as g } from "@swapkit/types";
const $t = "0x313ce567", ot = async ({ chain: r, to: t }) => {
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 }) => {
try {
const { result: e } = await te.post(Tt[r], {
const { result: e } = await Xt.post(At[r], {
headers: {

@@ -27,3 +27,3 @@ accept: "*/*",

method: "eth_call",
params: [{ to: t.toLowerCase(), data: $t }, "latest"]
params: [{ to: t.toLowerCase(), data: vt }, "latest"]
})

@@ -33,28 +33,28 @@ });

} catch (e) {
return console.error(e), p[r];
return console.error(e), d[r];
}
}, Rt = async (r) => {
}, Tt = async (r) => {
if (r === o.Ethereum)
return p.ETH;
return d.ETH;
const [, t] = r.split("-");
return t != null && t.startsWith("0x") ? ot({ chain: o.Ethereum, to: t }) : p.ETH;
}, St = async (r) => {
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") ? ot({ chain: o.Avalanche, to: t.toLowerCase() }) : p.AVAX;
}, Ct = async (r) => r === o.BinanceSmartChain ? p.BSC : p.BSC, It = async ({ chain: r, symbol: t }) => {
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) {
case o.Ethereum:
return Rt(t);
return Tt(t);
case o.Avalanche:
return St(t);
return $t(t);
case o.BinanceSmartChain:
return Ct(t);
return Rt(t);
default:
return p[r];
return d[r];
}
}, ie = {
[D.Average]: 1.2,
[D.Fast]: 1.5,
[D.Fastest]: 2
}, at = ({ chain: r, symbol: t }) => {
}, ne = {
[H.Average]: 1.2,
[H.Fast]: 1.5,
[H.Fastest]: 2
}, it = ({ chain: r, symbol: t }) => {
switch (r) {

@@ -85,3 +85,3 @@ case o.Bitcoin:

}
}, Et = (r) => {
}, Ct = (r) => {
switch (r) {

@@ -93,9 +93,9 @@ case "ETH.THOR":

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

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

case o.Ethereum:
return { identifier: `${r}.${r}`, decimal: p[r] };
return { identifier: `${r}.${r}`, decimal: d[r] };
}
}, Ot = ({ chain: r, symbol: t }) => {
}, It = ({ chain: r, symbol: t }) => {
if (t.includes("/"))

@@ -147,19 +147,19 @@ return "Synth";

}
}, oe = (r) => {
}, ie = (r) => {
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 };
}, Bt = new RegExp(
}, Et = new RegExp(
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
"gmi"
), Mt = (r) => {
), Ot = (r) => {
const [t, e] = r.split(".");
if (!vt.includes(t))
if (!wt.includes(t))
return !0;
const [, s] = e.split("-");
return at({ chain: t, symbol: e }) || !!s;
}, ae = (r) => r.filter((t) => {
return it({ chain: t, symbol: e }) || !!s;
}, oe = (r) => r.filter((t) => {
const e = `${t.chain}.${t.symbol}`;
return !Bt.test(e) && Mt(e) && t.value !== "0";
}), Vt = ({
return !Et.test(e) && Ot(e) && t.value !== "0";
}), Bt = ({
liquidityUnits: r,

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

return c.mul(a.sub(u).add(l)).div(h);
}, qt = ({
}, Mt = ({
liquidityUnits: r,

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

return h.div(_);
}, ce = ({
}, ae = ({
percent: r,

@@ -185,3 +185,3 @@ runeDepth: t,

poolUnits: s
}) => Vt({ runeDepth: t, liquidityUnits: e, poolUnits: s }).mul(r), ue = ({
}) => Bt({ runeDepth: t, liquidityUnits: e, poolUnits: s }).mul(r), ce = ({
percent: r,

@@ -191,3 +191,3 @@ assetDepth: t,

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

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

runeAmount: m(e).mul(r).div(t)
}), le = ({
}), ue = ({
liquidityUnits: r,

@@ -208,6 +208,6 @@ poolUnits: t,

}) => Object.fromEntries(
Object.entries(xt({ liquidityUnits: r, poolUnits: t, runeDepth: e, assetDepth: s })).map(
Object.entries(Vt({ liquidityUnits: r, poolUnits: t, runeDepth: e, assetDepth: s })).map(
([i, c]) => [i, c.mul(n)]
)
), he = ({
), le = ({
runeDepth: r,

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

}) => {
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), H = l.mul(h), ft = c.mul(a), _t = u.mul(_.add(T.add(H.mul(2)))), gt = _.add(T.add(ft.mul(2))), X = _t.div(gt), L = m(s).add(X);
if (X.getBaseValue("number") === 0)
return L.div(u).getBaseValue("number");
const bt = u.add(L);
return L.div(bt).getBaseValue("number");
}, de = ({
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);
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,

@@ -236,7 +236,7 @@ assetAmount: t,

return Math.abs(u.div(l).getBaseValue("number"));
}, kt = ({
}, qt = ({
symbol: r,
ticker: t,
chain: e
}) => e === "ETH" && t !== "ETH" ? `${t}-${r.slice(-3)}` : r, pe = (r, t) => {
}) => e === "ETH" && t !== "ETH" ? `${t}-${r.slice(-3)}` : r, de = (r, t) => {
switch (r) {

@@ -261,3 +261,3 @@ case g.LEAVE:

case g.WITHDRAW: {
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 });
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}`;

@@ -277,3 +277,3 @@ }

return 10 + r;
}, fe = (r) => {
}, pe = (r) => {
if (r.length > 30)

@@ -283,4 +283,4 @@ return !1;

return !!r.match(t);
}, _e = ([r, t, e, s, n]) => `${r}'/${t}'/${e}'/${s}${typeof n != "number" ? "" : `/${n}`}`;
class Z extends Error {
}, fe = ([r, t, e, s, n]) => `${r}'/${t}'/${e}'/${s}${typeof n != "number" ? "" : `/${n}`}`;
class K extends Error {
constructor(t, e, s) {

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

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

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

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

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

return e;
}, K = (...r) => {
}, Y = (...r) => {
let t = {}, e = {};

@@ -334,9 +334,9 @@ for (const s of r)

Array.isArray(t) || (t = []), t = [...t, ...s];
else if (x(s)) {
else if (M(s)) {
for (let [n, i] of Object.entries(s))
x(i) && n in t && (i = K(t[n], i)), t = { ...t, [n]: i };
x(s.headers) && (e = ut(e, s.headers), t.headers = e);
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);
}
return t;
}, Pt = (() => {
}, xt = (() => {
let r = !1, t = !1;

@@ -352,3 +352,3 @@ const e = typeof globalThis.ReadableStream == "function", s = typeof globalThis.Request == "function";

}).headers.has("Content-Type")), r && !t;
})(), Nt = typeof globalThis.AbortController == "function", jt = typeof globalThis.ReadableStream == "function", Ht = typeof globalThis.FormData == "function", lt = ["get", "post", "put", "patch", "head", "delete"], Lt = {
})(), kt = typeof globalThis.AbortController == "function", Pt = typeof globalThis.ReadableStream == "function", Nt = typeof globalThis.FormData == "function", ct = ["get", "post", "put", "patch", "head", "delete"], jt = {
json: "application/json",

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

blob: "*/*"
}, U = 2147483647, ht = Symbol("stop"), Dt = {
}, L = 2147483647, ut = Symbol("stop"), Ht = {
json: !0,

@@ -371,3 +371,3 @@ parseJson: !0,

fetch: !0
}, Ut = {
}, Lt = {
method: !0,

@@ -388,14 +388,14 @@ headers: !0,

duplex: !0
}, Ft = (r) => lt.includes(r) ? r.toUpperCase() : r, Wt = ["get", "put", "head", "delete", "options", "trace"], Gt = [408, 413, 429, 500, 502, 503, 504], dt = [413, 429, 503], tt = {
}, 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 = {
limit: 2,
methods: Wt,
statusCodes: Gt,
afterStatusCodes: dt,
methods: Ut,
statusCodes: Ft,
afterStatusCodes: lt,
maxRetryAfter: Number.POSITIVE_INFINITY,
backoffLimit: Number.POSITIVE_INFINITY,
delay: (r) => 0.3 * 2 ** (r - 1) * 1e3
}, Yt = (r = {}) => {
}, Wt = (r = {}) => {
if (typeof r == "number")
return {
...tt,
...Q,
limit: r

@@ -408,11 +408,11 @@ };

return {
...tt,
...Q,
...r,
afterStatusCodes: dt
afterStatusCodes: lt
};
};
async function zt(r, t, e, s) {
async function Gt(r, t, e, s) {
return new Promise((n, i) => {
const c = setTimeout(() => {
e && e.abort(), i(new ct(r));
e && e.abort(), i(new ot(r));
}, s.timeout);

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

}
async function Jt(r, { signal: t }) {
async function Yt(r, { signal: t }) {
return new Promise((e, s) => {

@@ -436,13 +436,13 @@ t && (t.throwIfAborted(), t.addEventListener("abort", n, { once: !0 }));

}
const Kt = (r, t) => {
const zt = (r, t) => {
const e = {};
for (const s in t)
!(s in Ut) && !(s in Dt) && !(s in r) && (e[s] = t[s]);
!(s in Lt) && !(s in Ht) && !(s in r) && (e[s] = t[s]);
return e;
};
class P {
class x {
static create(t, e) {
const s = new P(t, e), n = async () => {
if (typeof s._options.timeout == "number" && s._options.timeout > U)
throw new RangeError(`The \`timeout\` option cannot be greater than ${U}`);
const s = new x(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();

@@ -455,3 +455,3 @@ let a = await s._fetch();

if (s._decorateResponse(a), !a.ok && s._options.throwHttpErrors) {
let u = new Z(a, s.request, s._options);
let u = new K(a, s.request, s._options);
for (const l of s._options.hooks.beforeError)

@@ -464,3 +464,3 @@ u = await l(u);

throw new TypeError("The `onDownloadProgress` option must be a function");
if (!jt)
if (!Pt)
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");

@@ -471,3 +471,3 @@ return s._stream(a.clone(), s._options.onDownloadProgress);

}, c = s._options.retry.methods.includes(s.request.method.toLowerCase()) ? s._retry(n) : n();
for (const [a, u] of Object.entries(Lt))
for (const [a, u] of Object.entries(jt))
c[a] = async () => {

@@ -517,4 +517,4 @@ s.request.headers.set("accept", s.request.headers.get("accept") || u);

...e,
headers: ut(this._input.headers, e.headers),
hooks: K({
headers: at(this._input.headers, e.headers),
hooks: Y({
beforeRequest: [],

@@ -525,6 +525,6 @@ beforeRetry: [],

}, e.hooks),
method: Ft(e.method ?? this._input.method),
method: Dt(e.method ?? this._input.method),
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
prefixUrl: String(e.prefixUrl || ""),
retry: Yt(e.retry),
retry: Wt(e.retry),
throwHttpErrors: e.throwHttpErrors !== !1,

@@ -540,3 +540,3 @@ timeout: e.timeout ?? 1e4,

}
if (Nt) {
if (kt) {
if (this.abortController = new globalThis.AbortController(), this._options.signal) {

@@ -550,5 +550,5 @@ const s = this._options.signal;

}
if (Pt && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
if (xt && (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);
(Ht && this._options.body instanceof globalThis.FormData || this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers["content-type"]) && this.request.headers.delete("content-type"), this.request = new globalThis.Request(new globalThis.Request(i, { ...this.request }), this._options);
(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);
}

@@ -558,4 +558,4 @@ 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 ct)) {
if (t instanceof Z) {
if (this._retryCount++, this._retryCount < this._options.retry.limit && !(t instanceof ot)) {
if (t instanceof K) {
if (!this._options.retry.statusCodes.includes(t.response.status))

@@ -583,5 +583,5 @@ return 0;

} catch (e) {
const s = Math.min(this._calculateRetryDelay(e), U);
const s = Math.min(this._calculateRetryDelay(e), L);
if (s !== 0 && this._retryCount > 0) {
await Jt(s, { signal: this._options.signal });
await Yt(s, { signal: this._options.signal });
for (const n of this._options.hooks.beforeRetry)

@@ -593,3 +593,3 @@ if (await n({

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

@@ -611,4 +611,4 @@ return this._retry(t);

}
const t = Kt(this.request, this._options);
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : zt(this.request.clone(), t, this.abortController, this._options);
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);
}

@@ -650,16 +650,16 @@ /* istanbul ignore next */

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

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

);
}, I = 8, $ = (r) => 10n ** BigInt(r), R = (r) => Math.log10(parseFloat(r.toString()));
function N({
}, S = 8, v = (r) => 10n ** BigInt(r), $ = (r) => Math.log10(parseFloat(r.toString()));
function k({
value: r,
bigIntDecimal: t = I,
decimal: e = I
bigIntDecimal: t = S,
decimal: e = S
}) {

@@ -687,23 +687,21 @@ const s = r < 0n;

}
var A, S, O, W, j, pt, B, G, v, C, M, Y;
const Q = class Q {
var w, R, I, U, P, ht, E, F;
const z = class z {
constructor(t) {
y(this, A);
y(this, O);
y(this, j);
y(this, B);
y(this, v);
y(this, M);
f(this, "decimalMultiplier", 10n ** 8n);
f(this, "bigIntValue", 0n);
f(this, "decimal");
const e = q(t);
this.decimal = typeof t == "object" ? t.decimal : void 0, this.decimalMultiplier = $(
Math.max(d(this, M, Y).call(this, d(this, v, C).call(this, e)), this.decimal || 0)
), d(this, O, W).call(this, e);
T(this, w);
T(this, I);
T(this, P);
T(this, E);
p(this, "decimalMultiplier", 10n ** 8n);
p(this, "bigIntValue", 0n);
p(this, "decimal");
const e = V(t);
this.decimal = typeof t == "object" ? t.decimal : void 0, this.decimalMultiplier = v(
Math.max(tt(B(e)), this.decimal || 0)
), f(this, I, U).call(this, e);
}
static fromBigInt(t, e) {
return new Q({
return new z({
decimal: e,
value: N({ value: t, bigIntDecimal: e, decimal: e })
value: k({ value: t, bigIntDecimal: e, decimal: e })
});

@@ -717,3 +715,3 @@ }

return this.fromBigInt(
t.getBaseValue("bigint") * $(s) / $(e),
t.getBaseValue("bigint") * v(s) / v(e),
s

@@ -723,15 +721,15 @@ );

set(t) {
return d(this, O, W).call(this, q(t)), this;
return f(this, I, U).call(this, V(t)), this;
}
add(...t) {
return d(this, A, S).call(this, "add", ...t);
return f(this, w, R).call(this, "add", ...t);
}
sub(...t) {
return d(this, A, S).call(this, "sub", ...t);
return f(this, w, R).call(this, "sub", ...t);
}
mul(...t) {
return d(this, A, S).call(this, "mul", ...t);
return f(this, w, R).call(this, "mul", ...t);
}
div(...t) {
return d(this, A, S).call(this, "div", ...t);
return f(this, w, R).call(this, "div", ...t);
}

@@ -756,3 +754,3 @@ gt(t) {

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

@@ -769,3 +767,3 @@ switch (t) {

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

@@ -783,9 +781,9 @@ case "number":

return t.bigIntValue;
const s = q(t), n = d(this, v, C).call(this, s);
return n === "0" || n === "undefined" ? 0n : d(this, B, G).call(this, n, e);
const s = V(t), n = B(s);
return n === "0" || n === "undefined" ? 0n : f(this, E, F).call(this, n, e);
}
formatBigIntToSafeValue(t, e) {
const s = e || this.decimal || I, n = Math.max(
const s = e || this.decimal || S, n = Math.max(
s,
R(this.decimalMultiplier)
$(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;

@@ -842,4 +840,4 @@ let h = u.slice(-n);

};
A = new WeakSet(), S = function(t, ...e) {
const s = d(this, j, pt).call(this, this, ...e), n = $(s), i = e.reduce(
w = new WeakSet(), R = function(t, ...e) {
const s = f(this, P, ht).call(this, this, ...e), n = v(s), i = e.reduce(
(a, u) => {

@@ -865,66 +863,69 @@ const l = this.getBigIntValue(u, s);

this.bigIntValue * n / this.decimalMultiplier
), c = N({
), c = k({
bigIntDecimal: s,
decimal: Math.max(s, R(this.decimalMultiplier)),
decimal: Math.max(s, $(this.decimalMultiplier)),
value: i
});
return new this.constructor({ decimal: this.decimal, value: c, identifier: this.toString() });
}, O = new WeakSet(), W = function(t) {
const e = d(this, v, C).call(this, t) || "0";
this.bigIntValue = d(this, B, G).call(this, e);
}, j = new WeakSet(), pt = function(...t) {
}, I = new WeakSet(), U = function(t) {
const e = B(t) || "0";
this.bigIntValue = f(this, E, F).call(this, e);
}, P = new WeakSet(), ht = function(...t) {
const e = t.map(
(s) => typeof s == "object" ? s.decimal || R(s.decimalMultiplier) : d(this, M, Y).call(this, d(this, v, C).call(this, s))
(s) => typeof s == "object" ? s.decimal || $(s.decimalMultiplier) : tt(B(s))
).filter(Boolean);
return Math.max(...e, I);
}, B = new WeakSet(), G = function(t, e) {
const s = e ? $(e) : this.decimalMultiplier, n = R(s), [i = "", c = ""] = t.split(".");
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(".");
return BigInt(`${i}${c.padEnd(n, "0")}`);
}, v = new WeakSet(), C = function(t) {
const s = `${typeof t == "number" ? Number(t).toLocaleString("fullwide", {
useGrouping: !1,
maximumFractionDigits: 20
}) : q(t)}`.replaceAll(",", ".").split(".");
return s.length > 1 ? `${s.slice(0, -1).join("")}.${s.at(-1)}` : s[0];
}, M = new WeakSet(), Y = function(t) {
var s;
const e = ((s = t.split(".")[1]) == null ? void 0 : s.length) || 0;
return Math.max(e, I);
};
let E = Q;
function q(r) {
let C = z;
const te = Intl.NumberFormat("fullwide", {
useGrouping: !1,
maximumFractionDigits: 20
});
function B(r) {
const e = `${typeof r == "number" ? te.format(r) : V(r)}`.replaceAll(",", ".").split(".");
return e.length > 1 ? `${e.slice(0, -1).join("")}.${e.at(-1)}` : e[0];
}
function tt(r) {
var e;
const t = ((e = r.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;
}
const k = (r, t) => typeof r == "bigint" ? N({ value: r, bigIntDecimal: t, decimal: t }) : r;
let z;
const rt = (r) => {
if (!z)
const q = (r, t) => typeof r == "bigint" ? k({ value: r, bigIntDecimal: t, decimal: t }) : r;
let W;
const et = (r) => {
if (!W)
throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");
return z.get(r.toUpperCase()) || { decimal: p.THOR, identifier: "" };
}, nt = async (r, t = 0) => {
ee(r);
const e = await It(J(r)), s = k(t, e);
return new w({ decimal: e, value: s, identifier: r });
}, it = /* @__PURE__ */ new Map();
class w extends E {
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();
class y extends C {
constructor(e) {
const s = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`, n = it.get(s);
const s = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`, n = rt.get(s);
if (n)
return n.set(e.value);
super(
e.value instanceof E ? e.value : { decimal: e.decimal, value: e.value }
e.value instanceof C ? e.value : { decimal: e.decimal, value: e.value }
);
f(this, "address");
f(this, "isSynthetic", !1);
f(this, "isGasAsset", !1);
p(this, "address");
p(this, "isSynthetic", !1);
p(this, "isGasAsset", !1);
// @ts-expect-error cache is false positive on that case
f(this, "chain");
p(this, "chain");
// @ts-expect-error cache is false positive on that case
f(this, "symbol");
p(this, "symbol");
// @ts-expect-error cache is false positive on that case
f(this, "ticker");
p(this, "ticker");
// @ts-expect-error cache is false positive on that case
f(this, "type");
const i = J(s);
this.type = Ot(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, it.set(s, this);
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);
}

@@ -942,20 +943,20 @@ toString(e = !1) {

static async fromString(e, s = 0) {
return nt(e, s);
return st(e, s);
}
static fromStringSync(e, s = 0) {
const { isSynthetic: n } = J(e), { decimal: i, identifier: c } = rt(
const { isSynthetic: n } = G(e), { decimal: i, identifier: c } = et(
e
), a = k(s, i);
return c ? new w({ decimal: i, identifier: c, value: a }) : n ? new w({ decimal: 8, identifier: e, value: a }) : void 0;
), a = q(s, 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 nt(e, s);
return st(e, s);
}
static fromIdentifierSync(e, s = 0) {
const { decimal: n, identifier: i } = rt(e), c = k(s, n);
return new w({ decimal: n, identifier: i, value: c });
const { decimal: n, identifier: i } = et(e), c = q(s, n);
return new y({ decimal: n, identifier: i, value: c });
}
static fromChainOrSignature(e, s = 0) {
const { decimal: n, identifier: i } = Et(e), c = k(s, n);
return new w({ value: c, decimal: n, identifier: i });
const { decimal: n, identifier: i } = Ct(e), c = q(s, n);
return new y({ value: c, decimal: n, identifier: i });
}

@@ -973,6 +974,6 @@ static async loadStaticAssets() {

} = await import("@swapkit/tokens");
z = [i, ...Object.values(c)].reduce(
(u, { tokens: l }) => (l.forEach(({ identifier: h, chain: _, ...T }) => {
const H = "decimals" in T ? T.decimals : p[_];
u.set(h, { identifier: h, decimal: H });
W = [i, ...Object.values(c)].reduce(
(u, { tokens: l }) => (l.forEach(({ identifier: h, chain: _, ...A }) => {
const N = "decimals" in A ? A.decimals : d[_];
u.set(h, { identifier: h, decimal: N });
}), u),

@@ -992,4 +993,4 @@ /* @__PURE__ */ new Map()

}
const ge = (r) => {
const t = w.fromChainOrSignature(r);
const _e = (r) => {
const t = y.fromChainOrSignature(r);
switch (r) {

@@ -1011,3 +1012,3 @@ case o.Bitcoin:

}
}, J = (r) => {
}, 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("-");

@@ -1017,3 +1018,3 @@ return {

chain: i,
isGasAsset: at({ chain: i, symbol: c }),
isGasAsset: it({ chain: i, symbol: c }),
isSynthetic: t,

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

};
}, se = {
}, ee = {
/**

@@ -1081,8 +1082,8 @@ * Core

};
class mt extends Error {
class dt extends Error {
constructor(t, e) {
console.error(e), super(t, { cause: { code: se[t], message: t } }), Object.setPrototypeOf(this, mt.prototype);
console.error(e), super(t, { cause: { code: ee[t], message: t } }), Object.setPrototypeOf(this, dt.prototype);
}
}
class b extends E {
class b extends C {
eq(t) {

@@ -1094,3 +1095,3 @@ return this.eqValue(t);

decimal: e,
value: N({ value: t, bigIntDecimal: e, decimal: e })
value: k({ value: t, bigIntDecimal: e, decimal: e })
});

@@ -1100,28 +1101,28 @@ }

export {
w as AssetValue,
E as BigIntArithmetics,
te as RequestClient,
mt as SwapKitError,
y as AssetValue,
C as BigIntArithmetics,
Xt as RequestClient,
dt as SwapKitError,
b as SwapKitNumber,
oe as assetFromString,
_e as derivationPathToString,
ae as filterAssets,
N as formatBigIntToSafeValue,
ie as gasFeeMultiplier,
Ot as getAssetType,
qt as getAsymmetricAssetShare,
ue as getAsymmetricAssetWithdrawAmount,
Vt as getAsymmetricRuneShare,
ce as getAsymmetricRuneWithdrawAmount,
Et as getCommonAssetInfo,
It as getDecimal,
he as getEstimatedPoolShare,
de as getLiquiditySlippage,
pe as getMemoFor,
ge as getMinAmountByChain,
xt as getSymmetricPoolShare,
le as getSymmetricWithdraw,
ie as assetFromString,
fe as derivationPathToString,
oe 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,
at as isGasAsset,
fe as validateTHORName
it as isGasAsset,
pe as validateTHORName
};

@@ -45,3 +45,3 @@ {

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

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

@@ -90,3 +90,3 @@ import { BaseDecimal } from '@swapkit/types';

this.decimalMultiplier = toMultiplier(
Math.max(this.#getFloatDecimals(this.#toSafeValue(value)), this.decimal || 0),
Math.max(getFloatDecimals(toSafeValue(value)), this.decimal || 0),
);

@@ -168,3 +168,3 @@ this.#setValue(value);

const stringValue = getStringValue(value);
const safeValue = this.#toSafeValue(stringValue);
const safeValue = toSafeValue(stringValue);

@@ -341,3 +341,3 @@ if (safeValue === '0' || safeValue === 'undefined') return 0n;

#setValue(value: InitialisationValueType) {
const safeValue = this.#toSafeValue(value) || '0';
const safeValue = toSafeValue(value) || '0';
this.bigIntValue = this.#toBigInt(safeValue);

@@ -351,3 +351,3 @@ }

? arg.decimal || decimalFromMultiplier(arg.decimalMultiplier)
: this.#getFloatDecimals(this.#toSafeValue(arg)),
: getFloatDecimals(toSafeValue(arg)),
)

@@ -365,31 +365,30 @@ .filter(Boolean) as number[];

}
}
#toSafeValue(value: InitialisationValueType) {
const parsedValue =
typeof value === 'number'
? Number(value).toLocaleString('fullwide', {
useGrouping: false,
maximumFractionDigits: 20,
})
: getStringValue(value);
const numberFormatter = Intl.NumberFormat('fullwide', {
useGrouping: false,
maximumFractionDigits: 20,
});
const splitValue = `${parsedValue}`.replaceAll(',', '.').split('.');
function toSafeValue(value: InitialisationValueType) {
const parsedValue =
typeof value === 'number' ? numberFormatter.format(value) : getStringValue(value);
const splitValue = `${parsedValue}`.replaceAll(',', '.').split('.');
return splitValue.length > 1
? `${splitValue.slice(0, -1).join('')}.${splitValue.at(-1)}`
: splitValue[0];
}
return splitValue.length > 1
? `${splitValue.slice(0, -1).join('')}.${splitValue.at(-1)}`
: splitValue[0];
}
#getFloatDecimals(value: string) {
const decimals = value.split('.')[1]?.length || 0;
return Math.max(decimals, DEFAULT_DECIMAL);
}
function getFloatDecimals(value: string) {
const decimals = value.split('.')[1]?.length || 0;
return Math.max(decimals, DEFAULT_DECIMAL);
}
function getStringValue(value: SKBigIntParams) {
return typeof value === 'object'
? 'getValue' in value
? value.getValue('string')
: value.value
: value;
function getStringValue(param: SKBigIntParams) {
return typeof param === 'object'
? 'getValue' in param
? param.getValue('string')
: param.value
: param;
}

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