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.17 to 1.0.0-rc.18

6

dist/index.d.ts

@@ -44,4 +44,2 @@ import { Chain } from '@swapkit/types';

static fromChainOrSignature(assetString: CommonAssetString, value?: NumberPrimitives): AssetValue;
static fromTCQuote(identifier: TCTokenNames, value?: NumberPrimitives): Promise<AssetValue>;
static fromTCQuoteStatic(identifier: TCTokenNames, value?: NumberPrimitives): AssetValue;
static loadStaticAssets(): Promise<{

@@ -73,3 +71,3 @@ ok: true;

static shiftDecimals({ value, from, to, }: {
value: InitialisationValueType;
value: InstanceType<typeof SwapKitNumber>;
from: number;

@@ -91,3 +89,3 @@ to: number;

get baseValueBigInt(): bigint;
set(value: SKBigIntParams): any;
set(value: SKBigIntParams): this;
add(...args: InitialisationValueType[]): this;

@@ -94,0 +92,0 @@ sub(...args: InitialisationValueType[]): this;

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

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

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

};
var m = (s, t, e) => (wt(s, t, "access private method"), e);
import { FeeOption as U, BaseDecimal as d, Chain as o, ChainToRPC as At, MemoType as b } from "@swapkit/types";
const Tt = "0x313ce567", nt = async ({ chain: s, to: t }) => {
var m = (s, t, e) => (yt(s, t, "access private method"), e);
import { FeeOption as L, BaseDecimal as d, Chain as o, ChainToRPC as wt, MemoType as g } from "@swapkit/types";
const At = "0x313ce567", nt = async ({ chain: s, to: t }) => {
try {
const { result: e } = await Qt.post(At[s], {
const { result: e } = await Qt.post(wt[s], {
headers: {

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

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

@@ -35,3 +35,3 @@ });

}
}, vt = async (s) => {
}, Tt = async (s) => {
if (s === o.Ethereum)

@@ -41,11 +41,11 @@ return d.ETH;

return t != null && t.startsWith("0x") ? nt({ chain: o.Ethereum, to: t }) : d.ETH;
}, Rt = async (s) => {
}, vt = async (s) => {
const [, t] = s.split("-");
return t != null && t.startsWith("0x") ? nt({ chain: o.Avalanche, to: t.toLowerCase() }) : d.AVAX;
}, St = async (s) => s === o.BinanceSmartChain ? d.BSC : d.BSC, it = async ({ chain: s, symbol: t }) => {
}, St = async (s) => s === o.BinanceSmartChain ? d.BSC : d.BSC, Rt = async ({ chain: s, symbol: t }) => {
switch (s) {
case o.Ethereum:
return Tt(t);
case o.Avalanche:
return vt(t);
case o.Avalanche:
return Rt(t);
case o.BinanceSmartChain:

@@ -57,5 +57,5 @@ return St(t);

}, re = {
[U.Average]: 1.2,
[U.Fast]: 1.5,
[U.Fastest]: 2
[L.Average]: 1.2,
[L.Fast]: 1.5,
[L.Fastest]: 2
}, $t = ({ chain: s, symbol: t }) => {

@@ -155,3 +155,3 @@ switch (s) {

(t) => !Et.test(t.toString()) && !t.toString().includes("undefined")
), Ot = ({
), Bt = ({
liquidityUnits: s,

@@ -161,5 +161,5 @@ poolUnits: t,

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

@@ -169,4 +169,4 @@ poolUnits: t,

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

@@ -177,3 +177,3 @@ percent: s,

poolUnits: r
}) => Ot({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), oe = ({
}) => Bt({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), oe = ({
percent: s,

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

poolUnits: r
}) => Bt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), f = (s) => y.fromBigInt(BigInt(s), d.THOR), Vt = ({
}) => Ot({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), p = (s) => b.fromBigInt(BigInt(s), d.THOR), Vt = ({
liquidityUnits: s,

@@ -190,4 +190,4 @@ poolUnits: t,

}) => ({
assetAmount: f(r).mul(s).div(t),
runeAmount: f(e).mul(s).div(t)
assetAmount: p(r).mul(s).div(t),
runeAmount: p(e).mul(s).div(t)
}), ae = ({

@@ -211,7 +211,7 @@ liquidityUnits: s,

}) => {
const a = new y({ value: s, decimal: 8 }), c = new y({ value: e, decimal: 8 }), u = new y({ value: t, decimal: 8 }), l = new y({ value: n, decimal: 8 }), h = new y({ value: i, decimal: 8 }), g = l.mul(c), v = h.mul(a), L = l.mul(h), ft = a.mul(c), pt = u.mul(g.add(v.add(L.mul(2)))), _t = g.add(v.add(ft.mul(2))), X = pt.div(_t), D = f(r).add(X);
if (X.getBaseValue("number") === 0)
return D.div(u).getBaseValue("number");
const gt = u.add(D);
return D.div(gt).getBaseValue("number");
const a = new b({ value: s, decimal: 8 }), c = 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(c), v = h.mul(a), j = l.mul(h), mt = a.mul(c), pt = u.mul(_.add(v.add(j.mul(2)))), ft = _.add(v.add(mt.mul(2))), Q = pt.div(ft), H = p(r).add(Q);
if (Q.getBaseValue("number") === 0)
return H.div(u).getBaseValue("number");
const _t = u.add(H);
return H.div(_t).getBaseValue("number");
}, ue = ({

@@ -225,3 +225,3 @@ runeAmount: s,

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

@@ -234,25 +234,25 @@ }, Mt = ({

switch (s) {
case b.LEAVE:
case b.BOND: {
case g.LEAVE:
case g.BOND: {
const { address: e } = t;
return `${s}:${e}`;
}
case b.UNBOND: {
case g.UNBOND: {
const { address: e, unbondAmount: r } = t;
return `${s}:${e}:${r * 10 ** 8}`;
}
case b.THORNAME_REGISTER: {
case g.THORNAME_REGISTER: {
const { name: e, chain: r, address: n, owner: i } = t;
return `${s}:${e}:${r}:${n}${i ? `:${i}` : ""}`;
}
case b.DEPOSIT: {
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`;
}
case b.WITHDRAW: {
case g.WITHDRAW: {
const { chain: e, ticker: r, symbol: n, basisPoints: i, targetAssetString: a, singleSide: c } = t, u = !c && a ? `:${a}` : "", l = Mt({ chain: e, symbol: n, ticker: r });
return `${s}:${e}${c ? "/" : "."}${l}:${i}${u}`;
}
case b.OPEN_LOAN:
case b.CLOSE_LOAN: {
case g.OPEN_LOAN:
case g.CLOSE_LOAN: {
const { asset: e, address: r } = t;

@@ -274,3 +274,3 @@ return `${s}:${e}:${r}`;

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

@@ -296,3 +296,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 ot extends Error {
class it extends Error {
constructor(t) {

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

throw new TypeError("The `options` argument must be an object");
return Q({}, ...s);
}, at = (s = {}, t = {}) => {
return J({}, ...s);
}, ot = (s = {}, t = {}) => {
const e = new globalThis.Headers(s), r = t instanceof globalThis.Headers, n = new globalThis.Headers(t);

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

return e;
}, Q = (...s) => {
}, J = (...s) => {
let t = {}, e = {};

@@ -326,4 +326,4 @@ for (const r of s)

for (let [n, i] of Object.entries(r))
M(i) && n in t && (i = Q(t[n], i)), t = { ...t, [n]: i };
M(r.headers) && (e = at(e, r.headers), t.headers = e);
M(i) && n in t && (i = J(t[n], i)), t = { ...t, [n]: i };
M(r.headers) && (e = ot(e, r.headers), t.headers = e);
}

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

}).headers.has("Content-Type")), s && !t;
})(), qt = typeof globalThis.AbortController == "function", xt = typeof globalThis.ReadableStream == "function", Pt = typeof globalThis.FormData == "function", ct = ["get", "post", "put", "patch", "head", "delete"], Nt = {
})(), qt = typeof globalThis.AbortController == "function", xt = typeof globalThis.ReadableStream == "function", Pt = typeof globalThis.FormData == "function", at = ["get", "post", "put", "patch", "head", "delete"], Nt = {
json: "application/json",

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

blob: "*/*"
}, F = 2147483647, ut = Symbol("stop"), Ht = {
}, D = 2147483647, ct = Symbol("stop"), jt = {
json: !0,

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

fetch: !0
}, jt = {
}, Ht = {
method: !0,

@@ -378,7 +378,7 @@ headers: !0,

duplex: !0
}, Lt = (s) => ct.includes(s) ? s.toUpperCase() : s, Dt = ["get", "put", "head", "delete", "options", "trace"], Ut = [408, 413, 429, 500, 502, 503, 504], lt = [413, 429, 503], tt = {
}, Lt = (s) => at.includes(s) ? s.toUpperCase() : s, Dt = ["get", "put", "head", "delete", "options", "trace"], Ut = [408, 413, 429, 500, 502, 503, 504], ut = [413, 429, 503], Z = {
limit: 2,
methods: Dt,
statusCodes: Ut,
afterStatusCodes: lt,
afterStatusCodes: ut,
maxRetryAfter: Number.POSITIVE_INFINITY,

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

return {
...tt,
...Z,
limit: s

@@ -399,5 +399,5 @@ };

return {
...tt,
...Z,
...s,
afterStatusCodes: lt
afterStatusCodes: ut
};

@@ -408,3 +408,3 @@ };

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

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

for (const r in t)
!(r in jt) && !(r in Ht) && !(r in s) && (e[r] = t[r]);
!(r in Ht) && !(r in jt) && !(r in s) && (e[r] = t[r]);
return e;
};
class x {
class q {
static create(t, e) {
const r = new x(t, e), n = async () => {
if (typeof r._options.timeout == "number" && r._options.timeout > F)
throw new RangeError(`The \`timeout\` option cannot be greater than ${F}`);
const r = new q(t, e), n = async () => {
if (typeof r._options.timeout == "number" && r._options.timeout > D)
throw new RangeError(`The \`timeout\` option cannot be greater than ${D}`);
await Promise.resolve();

@@ -446,3 +446,3 @@ let c = await r._fetch();

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

@@ -506,4 +506,4 @@ u = await l(u);

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

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

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

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

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

@@ -579,3 +579,3 @@ await Gt(r, { signal: this._options.signal });

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

@@ -635,16 +635,16 @@ return this._retry(t);

/*! MIT License © Sindre Sorhus */
const Y = (s) => {
const t = (e, r) => x.create(e, V(s, r));
for (const e of ct)
t[e] = (r, n) => x.create(r, V(s, n, { method: e }));
return t.create = (e) => Y(V(e)), t.extend = (e) => Y(V(s, e)), t.stop = ut, t;
}, zt = Y(), Jt = zt, Kt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, et = Jt.create({ headers: Kt }), Qt = {
get: (s, t) => et.get(s, t).json(),
post: (s, t) => et.post(s, t).json()
}, rt = Object.values(o), Xt = (s = "") => {
const F = (s) => {
const t = (e, r) => q.create(e, V(s, r));
for (const e of at)
t[e] = (r, n) => q.create(r, V(s, n, { method: e }));
return t.create = (e) => F(V(e)), t.extend = (e) => F(V(s, e)), t.stop = ct, t;
}, zt = F(), Jt = zt, Kt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, tt = Jt.create({ headers: Kt }), Qt = {
get: (s, t) => tt.get(s, t).json(),
post: (s, t) => tt.post(s, t).json()
}, et = Object.values(o), Xt = (s = "") => {
const t = s.toUpperCase(), [e] = t.split(".");
if (rt.includes(e))
if (et.includes(e))
return !0;
const [r] = t.split("/");
if (rt.includes(r))
if (et.includes(r))
return !0;

@@ -654,4 +654,4 @@ throw new Error(

);
}, I = 8, R = (s) => 10n ** BigInt(s), S = (s) => Math.log10(parseFloat(s.toString()));
function P({
}, I = 8, S = (s) => 10n ** BigInt(s), R = (s) => Math.log10(parseFloat(s.toString()));
function x({
value: s,

@@ -672,23 +672,23 @@ bigIntDecimal: t = I,

}
var A, $, N, ht, H, dt, O, z, T, C, B, J;
const j = class j {
var A, $, P, lt, N, ht, B, W, T, C, O, G;
const K = class K {
constructor(t) {
w(this, A);
w(this, N);
w(this, H);
w(this, O);
w(this, T);
w(this, B);
p(this, "decimalMultiplier", 10n ** 8n);
p(this, "bigIntValue", 0n);
p(this, "decimal");
const e = W(t);
this.decimal = typeof t == "object" ? t.decimal : void 0, this.decimalMultiplier = R(
Math.max(m(this, B, J).call(this, m(this, T, C).call(this, e)), this.decimal || 0)
), m(this, N, ht).call(this, e);
y(this, A);
y(this, P);
y(this, N);
y(this, B);
y(this, T);
y(this, O);
f(this, "decimalMultiplier", 10n ** 8n);
f(this, "bigIntValue", 0n);
f(this, "decimal");
const e = U(t);
this.decimal = typeof t == "object" ? t.decimal : void 0, this.decimalMultiplier = S(
Math.max(m(this, O, G).call(this, m(this, T, C).call(this, e)), this.decimal || 0)
), m(this, P, lt).call(this, e);
}
static fromBigInt(t, e) {
return new j({
return new K({
decimal: e,
value: P({ value: t, bigIntDecimal: e, decimal: e })
value: x({ value: t, bigIntDecimal: e, decimal: e })
});

@@ -702,3 +702,3 @@ }

return this.fromBigInt(
new j(t).bigIntValue * R(r) / R(e),
t.getBaseValue("bigint") * S(r) / S(e),
r

@@ -758,3 +758,3 @@ );

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

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

getBaseValue(t) {
const e = this.decimalMultiplier / R(this.decimal || d.THOR), r = this.bigIntValue / e;
const e = this.decimalMultiplier / S(this.decimal || d.THOR), r = this.bigIntValue / e;
switch (t) {

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

return t.bigIntValue;
const r = W(t), n = m(this, T, C).call(this, r);
return n === "0" || n === "undefined" ? 0n : m(this, O, z).call(this, n, e);
const r = U(t), n = m(this, T, C).call(this, r);
return n === "0" || n === "undefined" ? 0n : m(this, B, W).call(this, n, e);
}

@@ -792,3 +792,3 @@ formatBigIntToSafeValue(t, e) {

r,
S(this.decimalMultiplier)
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, l = u.length - n;

@@ -837,3 +837,3 @@ let h = u.slice(-n);

A = new WeakSet(), $ = function(t, ...e) {
const r = m(this, H, dt).call(this, this, ...e), n = R(r), i = e.reduce(
const r = m(this, N, ht).call(this, this, ...e), n = S(r), i = e.reduce(
(c, u) => {

@@ -859,18 +859,18 @@ const l = this.getBigIntValue(u, r);

this.bigIntValue * n / this.decimalMultiplier
), a = P({
), a = x({
bigIntDecimal: r,
decimal: Math.max(r, S(this.decimalMultiplier)),
decimal: Math.max(r, R(this.decimalMultiplier)),
value: i
});
return new this.constructor({ decimal: this.decimal, value: a, identifier: this.toString() });
}, N = new WeakSet(), ht = function(t) {
}, P = new WeakSet(), lt = function(t) {
const e = m(this, T, C).call(this, t) || "0";
this.bigIntValue = m(this, O, z).call(this, e);
}, H = new WeakSet(), dt = function(...t) {
this.bigIntValue = m(this, B, W).call(this, e);
}, N = new WeakSet(), ht = function(...t) {
const e = t.map(
(r) => typeof r == "object" ? r.decimal || S(r.decimalMultiplier) : m(this, B, J).call(this, m(this, T, C).call(this, r))
(r) => typeof r == "object" ? r.decimal || R(r.decimalMultiplier) : m(this, O, G).call(this, m(this, T, C).call(this, r))
).filter(Boolean);
return Math.max(...e, I);
}, O = new WeakSet(), z = function(t, e) {
const r = e ? R(e) : this.decimalMultiplier, n = S(r), [i = "", a = ""] = t.split(".");
}, B = new WeakSet(), W = function(t, e) {
const r = e ? S(e) : this.decimalMultiplier, n = R(r), [i = "", a = ""] = t.split(".");
return BigInt(`${i}${a.padEnd(n, "0")}`);

@@ -881,5 +881,5 @@ }, T = new WeakSet(), C = function(t) {

maximumFractionDigits: 20
}) : W(t)}`.replaceAll(",", ".").split(".");
}) : U(t)}`.replaceAll(",", ".").split(".");
return r.length > 1 ? `${r.slice(0, -1).join("")}.${r.at(-1)}` : r[0];
}, B = new WeakSet(), J = function(t) {
}, O = new WeakSet(), G = function(t) {
var r;

@@ -889,18 +889,18 @@ const e = ((r = t.split(".")[1]) == null ? void 0 : r.length) || 0;

};
let E = j;
function W(s) {
let E = K;
function U(s) {
return typeof s == "object" ? "getValue" in s ? s.getValue("string") : s.value : s;
}
const k = (s, t) => typeof s == "bigint" ? P({ value: s, bigIntDecimal: t, decimal: t }) : s;
let K;
const G = (s) => {
if (!K)
const k = (s, t) => typeof s == "bigint" ? x({ value: s, bigIntDecimal: t, decimal: t }) : s;
let Y;
const rt = (s) => {
if (!Y)
throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");
return K.get(s.toUpperCase()) || { decimal: d.THOR, identifier: "" };
return Y.get(s.toUpperCase()) || { decimal: d.THOR, identifier: "" };
}, st = async (s, t = 0) => {
Xt(s);
const e = await it(q(s)), r = k(t, e);
return new _({ decimal: e, value: r, identifier: s });
const e = await Rt(z(s)), r = k(t, e);
return new w({ decimal: e, value: r, identifier: s });
};
class _ extends E {
class w extends E {
constructor(e) {

@@ -910,10 +910,10 @@ super(

);
p(this, "address");
p(this, "chain");
p(this, "isSynthetic", !1);
p(this, "isGasAsset", !1);
p(this, "symbol");
p(this, "ticker");
p(this, "type");
const r = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`, n = q(r);
f(this, "address");
f(this, "chain");
f(this, "isSynthetic", !1);
f(this, "isGasAsset", !1);
f(this, "symbol");
f(this, "ticker");
f(this, "type");
const r = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`, n = z(r);
this.type = It(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;

@@ -938,6 +938,6 @@ }

static fromStringSync(e, r = 0) {
const { isSynthetic: n } = q(e), { decimal: i, identifier: a } = G(
const { isSynthetic: n } = z(e), { decimal: i, identifier: a } = rt(
e
), c = k(r, i);
return a ? new _({ decimal: i, identifier: a, value: c }) : n ? new _({ decimal: 8, identifier: e, value: c }) : void 0;
return a ? new w({ decimal: i, identifier: a, value: c }) : n ? new w({ decimal: 8, identifier: e, value: c }) : void 0;
}

@@ -948,21 +948,9 @@ static async fromIdentifier(e, r = 0) {

static fromIdentifierSync(e, r = 0) {
const { decimal: n, identifier: i } = G(e), a = k(r, n);
return new _({ decimal: n, identifier: i, value: a });
const { decimal: n, identifier: i } = rt(e), a = k(r, n);
return new w({ decimal: n, identifier: i, value: a });
}
static fromChainOrSignature(e, r = 0) {
const { decimal: n, identifier: i } = Ct(e), a = k(r, n);
return new _({ value: a, decimal: n, identifier: i });
return new w({ value: a, decimal: n, identifier: i });
}
static async fromTCQuote(e, r = 0) {
const n = await it(q(e)), i = this.shiftDecimals({ value: r, from: d.THOR, to: n });
return new _({ value: i, identifier: e, decimal: n });
}
static fromTCQuoteStatic(e, r = 0) {
const n = G(e), i = this.shiftDecimals({
value: r,
from: d.THOR,
to: n.decimal
});
return new _({ ...n, value: i });
}
static async loadStaticAssets() {

@@ -979,6 +967,6 @@ return new Promise(

} = await import("@swapkit/tokens");
K = [i, ...Object.values(a)].reduce(
(u, { tokens: l }) => (l.forEach(({ identifier: h, chain: g, ...v }) => {
const L = "decimals" in v ? v.decimals : d[g];
u.set(h, { identifier: h, decimal: L });
Y = [i, ...Object.values(a)].reduce(
(u, { tokens: l }) => (l.forEach(({ identifier: h, chain: _, ...v }) => {
const j = "decimals" in v ? v.decimals : d[_];
u.set(h, { identifier: h, decimal: j });
}), u),

@@ -998,4 +986,4 @@ /* @__PURE__ */ new Map()

}
const fe = (s) => {
const t = _.fromChainOrSignature(s);
const pe = (s) => {
const t = w.fromChainOrSignature(s);
switch (s) {

@@ -1017,3 +1005,3 @@ case o.Bitcoin:

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

@@ -1085,8 +1073,8 @@ return {

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

@@ -1096,5 +1084,5 @@ return this.eqValue(t);

static fromBigInt(t, e) {
return new y({
return new b({
decimal: e,
value: P({ value: t, bigIntDecimal: e, decimal: e })
value: x({ value: t, bigIntDecimal: e, decimal: e })
});

@@ -1104,23 +1092,23 @@ }

export {
_ as AssetValue,
w as AssetValue,
E as BigIntArithmetics,
Qt as RequestClient,
mt as SwapKitError,
y as SwapKitNumber,
dt as SwapKitError,
b as SwapKitNumber,
se as assetFromString,
me as derivationPathToString,
ne as filterAssets,
P as formatBigIntToSafeValue,
x as formatBigIntToSafeValue,
re as gasFeeMultiplier,
It as getAssetType,
Bt as getAsymmetricAssetShare,
Ot as getAsymmetricAssetShare,
oe as getAsymmetricAssetWithdrawAmount,
Ot as getAsymmetricRuneShare,
Bt as getAsymmetricRuneShare,
ie as getAsymmetricRuneWithdrawAmount,
Ct as getCommonAssetInfo,
it as getDecimal,
Rt as getDecimal,
ce as getEstimatedPoolShare,
ue as getLiquiditySlippage,
le as getMemoFor,
fe as getMinAmountByChain,
pe as getMinAmountByChain,
Vt as getSymmetricPoolShare,

@@ -1127,0 +1115,0 @@ ae as getSymmetricWithdraw,

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

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

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

@@ -56,8 +56,8 @@ import { describe, expect, test } from 'vitest';

value: skNumber,
from: 6,
to: 8,
from: 8,
to: 6,
});
expect(shiftedSkNumber.getValue('string')).toBe('100');
expect(shiftedSkNumber.getBaseValue('bigint')).toBe(10000000000n);
expect(shiftedSkNumber.getValue('string')).toBe('1');
expect(shiftedSkNumber.getBaseValue('bigint')).toBe(1000000n);
});

@@ -79,2 +79,15 @@

});
test('shift eth from 18 to 8', () => {
const skNumber = new SwapKitNumber({ value: '0.2', decimal: 18 });
const shiftedSkNumber = SwapKitNumber.shiftDecimals({
value: skNumber,
from: 18,
to: 8,
});
expect(shiftedSkNumber.getValue('string')).toBe('0.2');
expect(shiftedSkNumber.getBaseValue('bigint')).toBe(20000000n);
});
});

@@ -81,0 +94,0 @@

@@ -158,20 +158,2 @@ import type {

static async fromTCQuote(identifier: TCTokenNames, value: NumberPrimitives = 0) {
const decimal = await getDecimal(getAssetInfo(identifier));
const shiftedValue = this.shiftDecimals({ value, from: BaseDecimal.THOR, to: decimal });
return new AssetValue({ value: shiftedValue, identifier, decimal });
}
static fromTCQuoteStatic(identifier: TCTokenNames, value: NumberPrimitives = 0) {
const tokenInfo = getStaticToken(identifier);
const shiftedValue = this.shiftDecimals({
value,
from: BaseDecimal.THOR,
to: tokenInfo.decimal,
});
return new AssetValue({ ...tokenInfo, value: shiftedValue });
}
static async loadStaticAssets() {

@@ -178,0 +160,0 @@ return new Promise<{ ok: true } | { ok: false; message: string; error: any }>(

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

}: {
value: InitialisationValueType;
value: InstanceType<typeof SwapKitNumber>;
from: number;

@@ -80,3 +80,3 @@ to: number;

return this.fromBigInt(
(new BigIntArithmetics(value).bigIntValue * toMultiplier(to)) / toMultiplier(from),
(value.getBaseValue('bigint') * toMultiplier(to)) / toMultiplier(from),
to,

@@ -116,3 +116,3 @@ );

set(value: SKBigIntParams) {
set(value: SKBigIntParams): this {
// @ts-expect-error False positive

@@ -119,0 +119,0 @@ return new this.constructor({ decimal: this.decimal, value, identifier: this.toString() });

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