Socket
Socket
Sign inDemoInstall

@swapkit/helpers

Package Overview
Dependencies
Maintainers
1
Versions
203
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.16 to 1.0.0-rc.17

264

dist/index.es.js

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

};
var y = (s, t, e) => {
var w = (s, t, e) => {
if (t.has(s))

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

};
var f = (s, t, e) => (wt(s, t, "access private method"), e);
import { FeeOption as L, BaseDecimal as m, Chain as o, ChainToRPC as At, MemoType as b } from "@swapkit/types";
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 }) => {

@@ -33,13 +33,13 @@ try {

} catch (e) {
return console.error(e), m[s];
return console.error(e), d[s];
}
}, vt = async (s) => {
if (s === o.Ethereum)
return m.ETH;
return d.ETH;
const [, t] = s.split("-");
return t != null && t.startsWith("0x") ? nt({ chain: o.Ethereum, to: t }) : m.ETH;
return t != null && t.startsWith("0x") ? nt({ chain: o.Ethereum, to: t }) : d.ETH;
}, Rt = async (s) => {
const [, t] = s.split("-");
return t != null && t.startsWith("0x") ? nt({ chain: o.Avalanche, to: t.toLowerCase() }) : m.AVAX;
}, St = async (s) => s === o.BinanceSmartChain ? m.BSC : m.BSC, it = async ({ chain: s, symbol: t }) => {
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 }) => {
switch (s) {

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

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

@@ -93,9 +93,9 @@ switch (s) {

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

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

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

@@ -161,5 +161,5 @@ }, It = ({ chain: s, symbol: t }) => {

}) => {
const r = d(s), n = d(t), i = d(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 = 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);
return a.mul(c.sub(u).add(l)).div(h);
}, Vt = ({
}, Bt = ({
liquidityUnits: s,

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

}) => {
const r = d(s), n = d(t), i = d(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);
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);

@@ -182,3 +182,3 @@ }, ie = ({

poolUnits: r
}) => Vt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), d = (s) => new Q({ value: s, decimal: m.THOR }), Bt = ({
}) => Bt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), f = (s) => y.fromBigInt(BigInt(s), d.THOR), Vt = ({
liquidityUnits: s,

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

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

@@ -199,3 +199,3 @@ liquidityUnits: s,

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

@@ -211,7 +211,7 @@ )

}) => {
const a = d(s), c = d(e), u = d(t), l = d(n), h = d(i), g = l.mul(c), T = h.mul(a), j = l.mul(h), ft = a.mul(c), pt = u.mul(g.add(T.add(j.mul(2)))), _t = g.add(T.add(ft.mul(2))), X = pt.div(_t), D = d(r).add(X);
if (X.baseValueNumber === 0)
return D.div(u).baseValueNumber;
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).baseValueNumber;
return D.div(gt).getBaseValue("number");
}, ue = ({

@@ -223,4 +223,6 @@ runeAmount: s,

}) => {
const n = d(e), i = d(r), a = d(t), c = d(s), u = a.mul(n).sub(i.mul(c)), l = i.mul(c).add(n.mul(i));
return Math.abs(u.div(l).baseValueNumber);
if (s === "0" || t === "0" || e === "0" || r === "0")
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));
return Math.abs(u.div(l).getBaseValue("number"));
}, Mt = ({

@@ -302,7 +304,7 @@ symbol: s,

}
const B = (s) => s !== null && typeof s == "object", V = (...s) => {
const M = (s) => s !== null && typeof s == "object", V = (...s) => {
for (const t of s)
if ((!B(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({}, ...s);
return Q({}, ...s);
}, at = (s = {}, t = {}) => {

@@ -313,3 +315,3 @@ const e = new globalThis.Headers(s), r = t instanceof globalThis.Headers, n = new globalThis.Headers(t);

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

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

Array.isArray(t) || (t = []), t = [...t, ...r];
else if (B(r)) {
else if (M(r)) {
for (let [n, i] of Object.entries(r))
B(i) && n in t && (i = K(t[n], i)), t = { ...t, [n]: i };
B(r.headers) && (e = at(e, r.headers), t.headers = e);
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);
}

@@ -343,3 +345,3 @@ return t;

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

@@ -371,5 +373,5 @@ parseJson: !0,

duplex: !0
}, Dt = (s) => ct.includes(s) ? s.toUpperCase() : s, Lt = ["get", "put", "head", "delete", "options", "trace"], Ut = [408, 413, 429, 500, 502, 503, 504], lt = [413, 429, 503], tt = {
}, 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 = {
limit: 2,
methods: Lt,
methods: Dt,
statusCodes: Ut,

@@ -423,7 +425,7 @@ afterStatusCodes: lt,

};
class q {
class x {
static create(t, e) {
const r = new q(t, e), n = async () => {
if (typeof r._options.timeout == "number" && r._options.timeout > U)
throw new RangeError(`The \`timeout\` option cannot be greater than ${U}`);
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}`);
await Promise.resolve();

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

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

@@ -503,3 +505,3 @@ beforeRetry: [],

}, e.hooks),
method: Dt(e.method ?? this._input.method),
method: Lt(e.method ?? this._input.method),
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing

@@ -558,3 +560,3 @@ prefixUrl: String(e.prefixUrl || ""),

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

@@ -623,8 +625,8 @@ await Gt(r, { signal: this._options.signal });

/*! MIT License © Sindre Sorhus */
const G = (s) => {
const t = (e, r) => q.create(e, V(s, r));
const Y = (s) => {
const t = (e, r) => x.create(e, V(s, r));
for (const e of ct)
t[e] = (r, n) => q.create(r, V(s, n, { method: e }));
return t.create = (e) => G(V(e)), t.extend = (e) => G(V(s, e)), t.stop = ut, t;
}, zt = G(), Jt = zt, Kt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, et = Jt.create({ headers: Kt }), Qt = {
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(),

@@ -642,7 +644,7 @@ post: (s, t) => et.post(s, t).json()

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

@@ -660,23 +662,23 @@ const r = s < 0n;

}
var w, S, P, ht, N, dt, E, Y, A, $, O, z;
const H = class H {
var A, $, N, ht, H, dt, O, z, T, C, B, J;
const j = class j {
constructor(t) {
y(this, w);
y(this, P);
y(this, N);
y(this, E);
y(this, A);
y(this, O);
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 = F(t);
this.decimal = typeof t == "object" ? t.decimal : void 0, this.decimalMultiplier = v(
Math.max(f(this, O, z).call(this, f(this, A, $).call(this, e)), this.decimal || 0)
), f(this, P, ht).call(this, e);
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);
}
static fromBigInt(t, e) {
return new H({
return new j({
decimal: e,
value: x({ value: t, bigIntDecimal: e, decimal: e })
value: P({ value: t, bigIntDecimal: e, decimal: e })
});

@@ -690,3 +692,3 @@ }

return this.fromBigInt(
new H(t).bigIntValue * v(r) / v(e),
new j(t).bigIntValue * R(r) / R(e),
r

@@ -717,12 +719,12 @@ );

add(...t) {
return f(this, w, S).call(this, "add", ...t);
return m(this, A, $).call(this, "add", ...t);
}
sub(...t) {
return f(this, w, S).call(this, "sub", ...t);
return m(this, A, $).call(this, "sub", ...t);
}
mul(...t) {
return f(this, w, S).call(this, "mul", ...t);
return m(this, A, $).call(this, "mul", ...t);
}
div(...t) {
return f(this, w, S).call(this, "div", ...t);
return m(this, A, $).call(this, "div", ...t);
}

@@ -747,3 +749,3 @@ gt(t) {

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

@@ -760,3 +762,3 @@ switch (t) {

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

@@ -774,9 +776,9 @@ case "number":

return t.bigIntValue;
const r = F(t), n = f(this, A, $).call(this, r);
return n === "0" || n === "undefined" ? 0n : f(this, E, Y).call(this, n, e);
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);
}
formatBigIntToSafeValue(t, e) {
const r = e || this.decimal || C, n = Math.max(
const r = e || this.decimal || I, n = Math.max(
r,
R(this.decimalMultiplier)
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, l = u.length - n;

@@ -790,4 +792,4 @@ let h = u.slice(-n);

toSignificant(t = 6) {
const [e, r] = this.getValue("string").split("."), n = e || "", i = r || "", a = parseInt(n) ? n.length + i.length : i.length;
if (a <= t)
const [e, r] = this.getValue("string").split("."), n = e || "", i = r || "";
if ((parseInt(n) ? n.length + i.length : i.length) <= t)
return this.getValue("string");

@@ -798,3 +800,3 @@ if (n.length >= t)

return `${n}.${i.slice(0, t - n.length)}`.padEnd(
a - t,
t - n.length,
"0"

@@ -826,4 +828,4 @@ );

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

@@ -849,49 +851,49 @@ const l = this.getBigIntValue(u, r);

this.bigIntValue * n / this.decimalMultiplier
), a = x({
), a = P({
bigIntDecimal: r,
decimal: Math.max(r, R(this.decimalMultiplier)),
decimal: Math.max(r, S(this.decimalMultiplier)),
value: i
});
return new this.constructor({ decimal: this.decimal, value: a, identifier: this.toString() });
}, P = new WeakSet(), ht = function(t) {
const e = f(this, A, $).call(this, t) || "0";
this.bigIntValue = f(this, E, Y).call(this, e);
}, N = new WeakSet(), dt = function(...t) {
}, N = new WeakSet(), ht = 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) {
const e = t.map(
(r) => typeof r == "object" ? r.decimal || R(r.decimalMultiplier) : f(this, O, z).call(this, f(this, A, $).call(this, r))
(r) => typeof r == "object" ? r.decimal || S(r.decimalMultiplier) : m(this, B, J).call(this, m(this, T, C).call(this, r))
).filter(Boolean);
return Math.max(...e, C);
}, E = new WeakSet(), Y = function(t, e) {
const r = e ? v(e) : this.decimalMultiplier, n = R(r), [i = "", a = ""] = t.split(".");
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(".");
return BigInt(`${i}${a.padEnd(n, "0")}`);
}, A = new WeakSet(), $ = function(t) {
}, T = new WeakSet(), C = function(t) {
const r = `${typeof t == "number" ? Number(t).toLocaleString("fullwide", {
useGrouping: !1,
maximumFractionDigits: 20
}) : F(t)}`.replaceAll(",", ".").split(".");
}) : W(t)}`.replaceAll(",", ".").split(".");
return r.length > 1 ? `${r.slice(0, -1).join("")}.${r.at(-1)}` : r[0];
}, O = new WeakSet(), z = function(t) {
}, B = new WeakSet(), J = function(t) {
var r;
const e = ((r = t.split(".")[1]) == null ? void 0 : r.length) || 0;
return Math.max(e, C);
return Math.max(e, I);
};
let I = H;
function F(s) {
let E = j;
function W(s) {
return typeof s == "object" ? "getValue" in s ? s.getValue("string") : s.value : s;
}
const M = (s, t) => typeof s == "bigint" ? x({ value: s, bigIntDecimal: t, decimal: t }) : s;
let J;
const W = (s) => {
if (!J)
const k = (s, t) => typeof s == "bigint" ? P({ value: s, bigIntDecimal: t, decimal: t }) : s;
let K;
const G = (s) => {
if (!K)
throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");
return J.get(s.toUpperCase()) || { decimal: m.THOR, identifier: "" };
return K.get(s.toUpperCase()) || { decimal: d.THOR, identifier: "" };
}, st = async (s, t = 0) => {
Xt(s);
const e = await it(k(s)), r = M(t, e);
const e = await it(q(s)), r = k(t, e);
return new _({ decimal: e, value: r, identifier: s });
};
class _ extends I {
class _ extends E {
constructor(e) {
super(
e.value instanceof I ? e.value : { decimal: e.decimal, value: e.value }
e.value instanceof E ? e.value : { decimal: e.decimal, value: e.value }
);

@@ -905,3 +907,3 @@ p(this, "address");

p(this, "type");
const r = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`, n = k(r);
const r = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`, n = q(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;

@@ -926,5 +928,5 @@ }

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

@@ -936,17 +938,17 @@ }

static fromIdentifierSync(e, r = 0) {
const { decimal: n, identifier: i } = W(e), a = M(r, n);
const { decimal: n, identifier: i } = G(e), a = k(r, n);
return new _({ decimal: n, identifier: i, value: a });
}
static fromChainOrSignature(e, r = 0) {
const { decimal: n, identifier: i } = Ct(e), a = M(r, n);
const { decimal: n, identifier: i } = Ct(e), a = k(r, n);
return new _({ value: a, decimal: n, identifier: i });
}
static async fromTCQuote(e, r = 0) {
const n = await it(k(e)), i = this.shiftDecimals({ value: r, from: m.THOR, to: n });
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 = W(e), i = this.shiftDecimals({
const n = G(e), i = this.shiftDecimals({
value: r,
from: m.THOR,
from: d.THOR,
to: n.decimal

@@ -967,6 +969,6 @@ });

} = await import("@swapkit/tokens");
J = [i, ...Object.values(a)].reduce(
(u, { tokens: l }) => (l.forEach(({ identifier: h, chain: g, ...T }) => {
const j = "decimals" in T ? T.decimals : m[g];
u.set(h, { identifier: h, decimal: j });
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 });
}), u),

@@ -1004,3 +1006,3 @@ /* @__PURE__ */ new Map()

}
}, k = (s) => {
}, q = (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("-");

@@ -1077,3 +1079,3 @@ return {

}
class Q extends I {
class y extends E {
eq(t) {

@@ -1083,5 +1085,5 @@ return this.eqValue(t);

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

@@ -1092,13 +1094,13 @@ }

_ as AssetValue,
I as BigIntArithmetics,
E as BigIntArithmetics,
Qt as RequestClient,
mt as SwapKitError,
Q as SwapKitNumber,
y as SwapKitNumber,
se as assetFromString,
me as derivationPathToString,
ne as filterAssets,
x as formatBigIntToSafeValue,
P as formatBigIntToSafeValue,
re as gasFeeMultiplier,
It as getAssetType,
Vt as getAsymmetricAssetShare,
Bt as getAsymmetricAssetShare,
oe as getAsymmetricAssetWithdrawAmount,

@@ -1113,3 +1115,3 @@ Ot as getAsymmetricRuneShare,

fe as getMinAmountByChain,
Bt as getSymmetricPoolShare,
Vt as getSymmetricPoolShare,
ae as getSymmetricWithdraw,

@@ -1116,0 +1118,0 @@ he as getTHORNameCost,

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

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

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

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

const toTCSwapKitNumber = (value: string) =>
new SwapKitNumber({ value, decimal: BaseDecimal.THOR });
SwapKitNumber.fromBigInt(BigInt(value), BaseDecimal.THOR);

@@ -130,7 +130,7 @@ export const getSymmetricPoolShare = ({

}>) => {
const R = toTCSwapKitNumber(runeDepth);
const A = toTCSwapKitNumber(assetDepth);
const P = toTCSwapKitNumber(poolUnits);
const runeAddAmount = toTCSwapKitNumber(runeAmount);
const assetAddAmount = toTCSwapKitNumber(assetAmount);
const R = new SwapKitNumber({ value: runeDepth, decimal: 8 });
const A = new SwapKitNumber({ value: assetDepth, decimal: 8 });
const P = new SwapKitNumber({ value: poolUnits, decimal: 8 });
const runeAddAmount = new SwapKitNumber({ value: runeAmount, decimal: 8 });
const assetAddAmount = new SwapKitNumber({ value: assetAmount, decimal: 8 });

@@ -147,4 +147,4 @@ // liquidityUnits = P * (r*A + a*R + 2*r*a) / (r*A + a*R + 2*R*A)

if (liquidityUnitsAfterAdd.baseValueNumber === 0) {
return estimatedLiquidityUnits.div(P).baseValueNumber;
if (liquidityUnitsAfterAdd.getBaseValue('number') === 0) {
return estimatedLiquidityUnits.div(P).getBaseValue('number');
}

@@ -155,3 +155,3 @@

return estimatedLiquidityUnits.div(newPoolUnits).baseValueNumber;
return estimatedLiquidityUnits.div(newPoolUnits).getBaseValue('number');
};

@@ -165,2 +165,4 @@

}: PoolParams) => {
if (runeAmount === '0' || assetAmount === '0' || runeDepth === '0' || assetDepth === '0')
return 0;
// formula: (t * R - T * r)/ (T*r + R*T)

@@ -176,3 +178,3 @@ const R = toTCSwapKitNumber(runeDepth);

// set absolute value of percent, no negative allowed
return Math.abs(numerator.div(denominator).baseValueNumber);
return Math.abs(numerator.div(denominator).getBaseValue('number'));
};

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

return `${integer}.${decimal.slice(0, significantDigits - integer.length)}`.padEnd(
valueLength - significantDigits,
significantDigits - integer.length,
'0',

@@ -244,0 +244,0 @@ );

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