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

@storm-trade/dex-math

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@storm-trade/dex-math - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

16

dist/dex-math.d.ts

@@ -5,14 +5,8 @@ import { BigNumber } from 'bignumber.js';

export declare type AmmSettings = {
oracleAddress: string;
oracleKey: string;
minInitMarginRatio: Numeric;
maintenanceMarginRatio: Numeric;
initMarginRatio: Numeric;
maxPriceImpact: Numeric;
maxPriceSpread: Numeric;
fee: Numeric;
maxOpenNotional: Numeric;
rolloverFee: Numeric;
oracleMode: OracleMode;
positionMode: PositionMode;
};

@@ -159,7 +153,2 @@

export declare enum OracleMode {
Plain = 1,
JIT = 2
}
export declare type Position = {

@@ -175,7 +164,2 @@ size: Numeric;

export declare enum PositionMode {
direct = 1,
indirect = 2
}
export declare function swapInput(amm: AmmState, quoteAssetIn: Numeric, decimals?: BigNumber): {

@@ -182,0 +166,0 @@ baseAssetOutput: BigNumber;

706

dist/dex-math.js

@@ -1,4 +0,4 @@

var xe = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i, Ae = Math.ceil, K = Math.floor, b = "[BigNumber Error] ", Ee = b + "Number primitive has more than 15 significant digits: ", ee = 1e14, P = 14, Ne = 9007199254740991, Oe = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13], oe = 1e7, U = 1e9;
function Pe(c) {
var g, v, N, p = d.prototype = { constructor: d, toString: null, valueOf: null }, R = new d(1), E = 20, O = 4, _ = -7, I = 21, T = -1e7, q = 1e7, k = !1, Q = 1, G = 0, X = {
var xe = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i, Ae = Math.ceil, J = Math.floor, b = "[BigNumber Error] ", Ee = b + "Number primitive has more than 15 significant digits: ", ee = 1e14, R = 14, Ne = 9007199254740991, Oe = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13], oe = 1e7, U = 1e9;
function Re(a) {
var g, v, N, p = d.prototype = { constructor: d, toString: null, valueOf: null }, P = new d(1), E = 20, O = 4, _ = -7, M = 21, z = -1e7, q = 1e7, k = !1, Q = 1, G = 0, X = {
prefix: "",

@@ -15,83 +15,83 @@ groupSize: 3,

function d(e, t) {
var n, u, r, o, l, i, s, a, f = this;
if (!(f instanceof d))
var n, u, r, o, f, i, s, l, c = this;
if (!(c instanceof d))
return new d(e, t);
if (t == null) {
if (e && e._isBigNumber === !0) {
f.s = e.s, !e.c || e.e > q ? f.c = f.e = null : e.e < T ? f.c = [f.e = 0] : (f.e = e.e, f.c = e.c.slice());
c.s = e.s, !e.c || e.e > q ? c.c = c.e = null : e.e < z ? c.c = [c.e = 0] : (c.e = e.e, c.c = e.c.slice());
return;
}
if ((i = typeof e == "number") && e * 0 == 0) {
if (f.s = 1 / e < 0 ? (e = -e, -1) : 1, e === ~~e) {
for (o = 0, l = e; l >= 10; l /= 10, o++)
if (c.s = 1 / e < 0 ? (e = -e, -1) : 1, e === ~~e) {
for (o = 0, f = e; f >= 10; f /= 10, o++)
;
o > q ? f.c = f.e = null : (f.e = o, f.c = [e]);
o > q ? c.c = c.e = null : (c.e = o, c.c = [e]);
return;
}
a = String(e);
l = String(e);
} else {
if (!xe.test(a = String(e)))
return N(f, a, i);
f.s = a.charCodeAt(0) == 45 ? (a = a.slice(1), -1) : 1;
if (!xe.test(l = String(e)))
return N(c, l, i);
c.s = l.charCodeAt(0) == 45 ? (l = l.slice(1), -1) : 1;
}
(o = a.indexOf(".")) > -1 && (a = a.replace(".", "")), (l = a.search(/e/i)) > 0 ? (o < 0 && (o = l), o += +a.slice(l + 1), a = a.substring(0, l)) : o < 0 && (o = a.length);
(o = l.indexOf(".")) > -1 && (l = l.replace(".", "")), (f = l.search(/e/i)) > 0 ? (o < 0 && (o = f), o += +l.slice(f + 1), l = l.substring(0, f)) : o < 0 && (o = l.length);
} else {
if (F(t, 2, $.length, "Base"), t == 10 && se)
return f = new d(e), W(f, E + f.e + 1, O);
if (a = String(e), i = typeof e == "number") {
return c = new d(e), W(c, E + c.e + 1, O);
if (l = String(e), i = typeof e == "number") {
if (e * 0 != 0)
return N(f, a, i, t);
if (f.s = 1 / e < 0 ? (a = a.slice(1), -1) : 1, d.DEBUG && a.replace(/^0\.0*|\./, "").length > 15)
return N(c, l, i, t);
if (c.s = 1 / e < 0 ? (l = l.slice(1), -1) : 1, d.DEBUG && l.replace(/^0\.0*|\./, "").length > 15)
throw Error(Ee + e);
} else
f.s = a.charCodeAt(0) === 45 ? (a = a.slice(1), -1) : 1;
for (n = $.slice(0, t), o = l = 0, s = a.length; l < s; l++)
if (n.indexOf(u = a.charAt(l)) < 0) {
c.s = l.charCodeAt(0) === 45 ? (l = l.slice(1), -1) : 1;
for (n = $.slice(0, t), o = f = 0, s = l.length; f < s; f++)
if (n.indexOf(u = l.charAt(f)) < 0) {
if (u == ".") {
if (l > o) {
if (f > o) {
o = s;
continue;
}
} else if (!r && (a == a.toUpperCase() && (a = a.toLowerCase()) || a == a.toLowerCase() && (a = a.toUpperCase()))) {
r = !0, l = -1, o = 0;
} else if (!r && (l == l.toUpperCase() && (l = l.toLowerCase()) || l == l.toLowerCase() && (l = l.toUpperCase()))) {
r = !0, f = -1, o = 0;
continue;
}
return N(f, String(e), i, t);
return N(c, String(e), i, t);
}
i = !1, a = v(a, t, 10, f.s), (o = a.indexOf(".")) > -1 ? a = a.replace(".", "") : o = a.length;
i = !1, l = v(l, t, 10, c.s), (o = l.indexOf(".")) > -1 ? l = l.replace(".", "") : o = l.length;
}
for (l = 0; a.charCodeAt(l) === 48; l++)
for (f = 0; l.charCodeAt(f) === 48; f++)
;
for (s = a.length; a.charCodeAt(--s) === 48; )
for (s = l.length; l.charCodeAt(--s) === 48; )
;
if (a = a.slice(l, ++s)) {
if (s -= l, i && d.DEBUG && s > 15 && (e > Ne || e !== K(e)))
throw Error(Ee + f.s * e);
if ((o = o - l - 1) > q)
f.c = f.e = null;
else if (o < T)
f.c = [f.e = 0];
if (l = l.slice(f, ++s)) {
if (s -= f, i && d.DEBUG && s > 15 && (e > Ne || e !== J(e)))
throw Error(Ee + c.s * e);
if ((o = o - f - 1) > q)
c.c = c.e = null;
else if (o < z)
c.c = [c.e = 0];
else {
if (f.e = o, f.c = [], l = (o + 1) % P, o < 0 && (l += P), l < s) {
for (l && f.c.push(+a.slice(0, l)), s -= P; l < s; )
f.c.push(+a.slice(l, l += P));
l = P - (a = a.slice(l)).length;
if (c.e = o, c.c = [], f = (o + 1) % R, o < 0 && (f += R), f < s) {
for (f && c.c.push(+l.slice(0, f)), s -= R; f < s; )
c.c.push(+l.slice(f, f += R));
f = R - (l = l.slice(f)).length;
} else
l -= s;
for (; l--; a += "0")
f -= s;
for (; f--; l += "0")
;
f.c.push(+a);
c.c.push(+l);
}
} else
f.c = [f.e = 0];
c.c = [c.e = 0];
}
d.clone = Pe, d.ROUND_UP = 0, d.ROUND_DOWN = 1, d.ROUND_CEIL = 2, d.ROUND_FLOOR = 3, d.ROUND_HALF_UP = 4, d.ROUND_HALF_DOWN = 5, d.ROUND_HALF_EVEN = 6, d.ROUND_HALF_CEIL = 7, d.ROUND_HALF_FLOOR = 8, d.EUCLID = 9, d.config = d.set = function(e) {
d.clone = Re, d.ROUND_UP = 0, d.ROUND_DOWN = 1, d.ROUND_CEIL = 2, d.ROUND_FLOOR = 3, d.ROUND_HALF_UP = 4, d.ROUND_HALF_DOWN = 5, d.ROUND_HALF_EVEN = 6, d.ROUND_HALF_CEIL = 7, d.ROUND_HALF_FLOOR = 8, d.EUCLID = 9, d.config = d.set = function(e) {
var t, n;
if (e != null)
if (typeof e == "object") {
if (e.hasOwnProperty(t = "DECIMAL_PLACES") && (n = e[t], F(n, 0, U, t), E = n), e.hasOwnProperty(t = "ROUNDING_MODE") && (n = e[t], F(n, 0, 8, t), O = n), e.hasOwnProperty(t = "EXPONENTIAL_AT") && (n = e[t], n && n.pop ? (F(n[0], -U, 0, t), F(n[1], 0, U, t), _ = n[0], I = n[1]) : (F(n, -U, U, t), _ = -(I = n < 0 ? -n : n))), e.hasOwnProperty(t = "RANGE"))
if (e.hasOwnProperty(t = "DECIMAL_PLACES") && (n = e[t], F(n, 0, U, t), E = n), e.hasOwnProperty(t = "ROUNDING_MODE") && (n = e[t], F(n, 0, 8, t), O = n), e.hasOwnProperty(t = "EXPONENTIAL_AT") && (n = e[t], n && n.pop ? (F(n[0], -U, 0, t), F(n[1], 0, U, t), _ = n[0], M = n[1]) : (F(n, -U, U, t), _ = -(M = n < 0 ? -n : n))), e.hasOwnProperty(t = "RANGE"))
if (n = e[t], n && n.pop)
F(n[0], -U, -1, t), F(n[1], 1, U, t), T = n[0], q = n[1];
F(n[0], -U, -1, t), F(n[1], 1, U, t), z = n[0], q = n[1];
else if (F(n, -U, U, t), n)
T = -(q = n < 0 ? -n : n);
z = -(q = n < 0 ? -n : n);
else

@@ -125,4 +125,4 @@ throw Error(b + t + " cannot be zero: " + n);

ROUNDING_MODE: O,
EXPONENTIAL_AT: [_, I],
RANGE: [T, q],
EXPONENTIAL_AT: [_, M],
RANGE: [z, q],
CRYPTO: k,

@@ -142,3 +142,3 @@ MODULO_MODE: Q,

if ({}.toString.call(u) == "[object Array]") {
if ((o === 1 || o === -1) && r >= -U && r <= U && r === K(r)) {
if ((o === 1 || o === -1) && r >= -U && r <= U && r === J(r)) {
if (u[0] === 0) {

@@ -149,5 +149,5 @@ if (r === 0 && u.length === 1)

}
if (t = (r + 1) % P, t < 1 && (t += P), String(u[0]).length == t) {
if (t = (r + 1) % R, t < 1 && (t += R), String(u[0]).length == t) {
for (t = 0; t < u.length; t++)
if (n = u[t], n < 0 || n >= ee || n !== K(n))
if (n = u[t], n < 0 || n >= ee || n !== J(n))
break e;

@@ -162,8 +162,8 @@ if (n !== 0)

}, d.maximum = d.max = function() {
return J(arguments, -1);
return Y(arguments, -1);
}, d.minimum = d.min = function() {
return J(arguments, 1);
return Y(arguments, 1);
}, d.random = function() {
var e = 9007199254740992, t = Math.random() * e & 2097151 ? function() {
return K(Math.random() * e);
return J(Math.random() * e);
} : function() {

@@ -173,29 +173,29 @@ return (Math.random() * 1073741824 | 0) * 8388608 + (Math.random() * 8388608 | 0);

return function(n) {
var u, r, o, l, i, s = 0, a = [], f = new d(R);
if (n == null ? n = E : F(n, 0, U), l = Ae(n / P), k)
var u, r, o, f, i, s = 0, l = [], c = new d(P);
if (n == null ? n = E : F(n, 0, U), f = Ae(n / R), k)
if (crypto.getRandomValues) {
for (u = crypto.getRandomValues(new Uint32Array(l *= 2)); s < l; )
i = u[s] * 131072 + (u[s + 1] >>> 11), i >= 9e15 ? (r = crypto.getRandomValues(new Uint32Array(2)), u[s] = r[0], u[s + 1] = r[1]) : (a.push(i % 1e14), s += 2);
s = l / 2;
for (u = crypto.getRandomValues(new Uint32Array(f *= 2)); s < f; )
i = u[s] * 131072 + (u[s + 1] >>> 11), i >= 9e15 ? (r = crypto.getRandomValues(new Uint32Array(2)), u[s] = r[0], u[s + 1] = r[1]) : (l.push(i % 1e14), s += 2);
s = f / 2;
} else if (crypto.randomBytes) {
for (u = crypto.randomBytes(l *= 7); s < l; )
i = (u[s] & 31) * 281474976710656 + u[s + 1] * 1099511627776 + u[s + 2] * 4294967296 + u[s + 3] * 16777216 + (u[s + 4] << 16) + (u[s + 5] << 8) + u[s + 6], i >= 9e15 ? crypto.randomBytes(7).copy(u, s) : (a.push(i % 1e14), s += 7);
s = l / 7;
for (u = crypto.randomBytes(f *= 7); s < f; )
i = (u[s] & 31) * 281474976710656 + u[s + 1] * 1099511627776 + u[s + 2] * 4294967296 + u[s + 3] * 16777216 + (u[s + 4] << 16) + (u[s + 5] << 8) + u[s + 6], i >= 9e15 ? crypto.randomBytes(7).copy(u, s) : (l.push(i % 1e14), s += 7);
s = f / 7;
} else
throw k = !1, Error(b + "crypto unavailable");
if (!k)
for (; s < l; )
i = t(), i < 9e15 && (a[s++] = i % 1e14);
for (l = a[--s], n %= P, l && n && (i = Oe[P - n], a[s] = K(l / i) * i); a[s] === 0; a.pop(), s--)
for (; s < f; )
i = t(), i < 9e15 && (l[s++] = i % 1e14);
for (f = l[--s], n %= R, f && n && (i = Oe[R - n], l[s] = J(f / i) * i); l[s] === 0; l.pop(), s--)
;
if (s < 0)
a = [o = 0];
l = [o = 0];
else {
for (o = -1; a[0] === 0; a.splice(0, 1), o -= P)
for (o = -1; l[0] === 0; l.splice(0, 1), o -= R)
;
for (s = 1, i = a[0]; i >= 10; i /= 10, s++)
for (s = 1, i = l[0]; i >= 10; i /= 10, s++)
;
s < P && (o -= P - s);
s < R && (o -= R - s);
}
return f.e = o, f.c = a, f;
return c.e = o, c.c = l, c;
};

@@ -209,32 +209,32 @@ }(), d.sum = function() {

function t(n, u, r, o) {
for (var l, i = [0], s, a = 0, f = n.length; a < f; ) {
for (var f, i = [0], s, l = 0, c = n.length; l < c; ) {
for (s = i.length; s--; i[s] *= u)
;
for (i[0] += o.indexOf(n.charAt(a++)), l = 0; l < i.length; l++)
i[l] > r - 1 && (i[l + 1] == null && (i[l + 1] = 0), i[l + 1] += i[l] / r | 0, i[l] %= r);
for (i[0] += o.indexOf(n.charAt(l++)), f = 0; f < i.length; f++)
i[f] > r - 1 && (i[f + 1] == null && (i[f + 1] = 0), i[f + 1] += i[f] / r | 0, i[f] %= r);
}
return i.reverse();
}
return function(n, u, r, o, l) {
var i, s, a, f, h, m, w, B, D = n.indexOf("."), z = E, x = O;
for (D >= 0 && (f = G, G = 0, n = n.replace(".", ""), B = new d(u), m = B.pow(n.length - D), G = f, B.c = t(
ie(Z(m.c), m.e, "0"),
return function(n, u, r, o, f) {
var i, s, l, c, h, m, w, B, D = n.indexOf("."), T = E, x = O;
for (D >= 0 && (c = G, G = 0, n = n.replace(".", ""), B = new d(u), m = B.pow(n.length - D), G = c, B.c = t(
ie(K(m.c), m.e, "0"),
10,
r,
e
), B.e = B.c.length), w = t(n, u, r, l ? (i = $, e) : (i = e, $)), a = f = w.length; w[--f] == 0; w.pop())
), B.e = B.c.length), w = t(n, u, r, f ? (i = $, e) : (i = e, $)), l = c = w.length; w[--c] == 0; w.pop())
;
if (!w[0])
return i.charAt(0);
if (D < 0 ? --a : (m.c = w, m.e = a, m.s = o, m = g(m, B, z, x, r), w = m.c, h = m.r, a = m.e), s = a + z + 1, D = w[s], f = r / 2, h = h || s < 0 || w[s + 1] != null, h = x < 4 ? (D != null || h) && (x == 0 || x == (m.s < 0 ? 3 : 2)) : D > f || D == f && (x == 4 || h || x == 6 && w[s - 1] & 1 || x == (m.s < 0 ? 8 : 7)), s < 1 || !w[0])
n = h ? ie(i.charAt(1), -z, i.charAt(0)) : i.charAt(0);
if (D < 0 ? --l : (m.c = w, m.e = l, m.s = o, m = g(m, B, T, x, r), w = m.c, h = m.r, l = m.e), s = l + T + 1, D = w[s], c = r / 2, h = h || s < 0 || w[s + 1] != null, h = x < 4 ? (D != null || h) && (x == 0 || x == (m.s < 0 ? 3 : 2)) : D > c || D == c && (x == 4 || h || x == 6 && w[s - 1] & 1 || x == (m.s < 0 ? 8 : 7)), s < 1 || !w[0])
n = h ? ie(i.charAt(1), -T, i.charAt(0)) : i.charAt(0);
else {
if (w.length = s, h)
for (--r; ++w[--s] > r; )
w[s] = 0, s || (++a, w = [1].concat(w));
for (f = w.length; !w[--f]; )
w[s] = 0, s || (++l, w = [1].concat(w));
for (c = w.length; !w[--c]; )
;
for (D = 0, n = ""; D <= f; n += i.charAt(w[D++]))
for (D = 0, n = ""; D <= c; n += i.charAt(w[D++]))
;
n = ie(n, a, i.charAt(0));
n = ie(n, l, i.charAt(0));
}

@@ -245,11 +245,11 @@ return n;

function e(u, r, o) {
var l, i, s, a, f = 0, h = u.length, m = r % oe, w = r / oe | 0;
var f, i, s, l, c = 0, h = u.length, m = r % oe, w = r / oe | 0;
for (u = u.slice(); h--; )
s = u[h] % oe, a = u[h] / oe | 0, l = w * s + a * m, i = m * s + l % oe * oe + f, f = (i / o | 0) + (l / oe | 0) + w * a, u[h] = i % o;
return f && (u = [f].concat(u)), u;
s = u[h] % oe, l = u[h] / oe | 0, f = w * s + l * m, i = m * s + f % oe * oe + c, c = (i / o | 0) + (f / oe | 0) + w * l, u[h] = i % o;
return c && (u = [c].concat(u)), u;
}
function t(u, r, o, l) {
function t(u, r, o, f) {
var i, s;
if (o != l)
s = o > l ? 1 : -1;
if (o != f)
s = o > f ? 1 : -1;
else

@@ -263,10 +263,10 @@ for (i = s = 0; i < o; i++)

}
function n(u, r, o, l) {
function n(u, r, o, f) {
for (var i = 0; o--; )
u[o] -= i, i = u[o] < r[o] ? 1 : 0, u[o] = i * l + u[o] - r[o];
u[o] -= i, i = u[o] < r[o] ? 1 : 0, u[o] = i * f + u[o] - r[o];
for (; !u[0] && u.length > 1; u.splice(0, 1))
;
}
return function(u, r, o, l, i) {
var s, a, f, h, m, w, B, D, z, x, M, y, he, me, we, te, le, Y = u.s == r.s ? 1 : -1, V = u.c, L = r.c;
return function(u, r, o, f, i) {
var s, l, c, h, m, w, B, D, T, x, I, y, he, me, we, te, le, Z = u.s == r.s ? 1 : -1, V = u.c, L = r.c;
if (!V || !V[0] || !L || !L[0])

@@ -277,35 +277,35 @@ return new d(

// Return ±0 if x is ±0 or y is ±Infinity, or return ±Infinity as y is ±0.
V && V[0] == 0 || !L ? Y * 0 : Y / 0
V && V[0] == 0 || !L ? Z * 0 : Z / 0
)
);
for (D = new d(Y), z = D.c = [], a = u.e - r.e, Y = o + a + 1, i || (i = ee, a = j(u.e / P) - j(r.e / P), Y = Y / P | 0), f = 0; L[f] == (V[f] || 0); f++)
for (D = new d(Z), T = D.c = [], l = u.e - r.e, Z = o + l + 1, i || (i = ee, l = j(u.e / R) - j(r.e / R), Z = Z / R | 0), c = 0; L[c] == (V[c] || 0); c++)
;
if (L[f] > (V[f] || 0) && a--, Y < 0)
z.push(1), h = !0;
if (L[c] > (V[c] || 0) && l--, Z < 0)
T.push(1), h = !0;
else {
for (me = V.length, te = L.length, f = 0, Y += 2, m = K(i / (L[0] + 1)), m > 1 && (L = e(L, m, i), V = e(V, m, i), te = L.length, me = V.length), he = te, x = V.slice(0, te), M = x.length; M < te; x[M++] = 0)
for (me = V.length, te = L.length, c = 0, Z += 2, m = J(i / (L[0] + 1)), m > 1 && (L = e(L, m, i), V = e(V, m, i), te = L.length, me = V.length), he = te, x = V.slice(0, te), I = x.length; I < te; x[I++] = 0)
;
le = L.slice(), le = [0].concat(le), we = L[0], L[1] >= i / 2 && we++;
do {
if (m = 0, s = t(L, x, te, M), s < 0) {
if (y = x[0], te != M && (y = y * i + (x[1] || 0)), m = K(y / we), m > 1)
for (m >= i && (m = i - 1), w = e(L, m, i), B = w.length, M = x.length; t(w, x, B, M) == 1; )
if (m = 0, s = t(L, x, te, I), s < 0) {
if (y = x[0], te != I && (y = y * i + (x[1] || 0)), m = J(y / we), m > 1)
for (m >= i && (m = i - 1), w = e(L, m, i), B = w.length, I = x.length; t(w, x, B, I) == 1; )
m--, n(w, te < B ? le : L, B, i), B = w.length, s = 1;
else
m == 0 && (s = m = 1), w = L.slice(), B = w.length;
if (B < M && (w = [0].concat(w)), n(x, w, M, i), M = x.length, s == -1)
for (; t(L, x, te, M) < 1; )
m++, n(x, te < M ? le : L, M, i), M = x.length;
if (B < I && (w = [0].concat(w)), n(x, w, I, i), I = x.length, s == -1)
for (; t(L, x, te, I) < 1; )
m++, n(x, te < I ? le : L, I, i), I = x.length;
} else
s === 0 && (m++, x = [0]);
z[f++] = m, x[0] ? x[M++] = V[he] || 0 : (x = [V[he]], M = 1);
} while ((he++ < me || x[0] != null) && Y--);
h = x[0] != null, z[0] || z.splice(0, 1);
T[c++] = m, x[0] ? x[I++] = V[he] || 0 : (x = [V[he]], I = 1);
} while ((he++ < me || x[0] != null) && Z--);
h = x[0] != null, T[0] || T.splice(0, 1);
}
if (i == ee) {
for (f = 1, Y = z[0]; Y >= 10; Y /= 10, f++)
for (c = 1, Z = T[0]; Z >= 10; Z /= 10, c++)
;
W(D, o + (D.e = f + a * P - 1) + 1, l, h);
W(D, o + (D.e = c + l * R - 1) + 1, f, h);
} else
D.e = a, D.r = +h;
D.e = l, D.r = +h;
return D;

@@ -315,12 +315,12 @@ };

function H(e, t, n, u) {
var r, o, l, i, s;
var r, o, f, i, s;
if (n == null ? n = O : F(n, 0, 8), !e.c)
return e.toString();
if (r = e.c[0], l = e.e, t == null)
s = Z(e.c), s = u == 1 || u == 2 && (l <= _ || l >= I) ? pe(s, l) : ie(s, l, "0");
else if (e = W(new d(e), t, n), o = e.e, s = Z(e.c), i = s.length, u == 1 || u == 2 && (t <= o || o <= _)) {
if (r = e.c[0], f = e.e, t == null)
s = K(e.c), s = u == 1 || u == 2 && (f <= _ || f >= M) ? pe(s, f) : ie(s, f, "0");
else if (e = W(new d(e), t, n), o = e.e, s = K(e.c), i = s.length, u == 1 || u == 2 && (t <= o || o <= _)) {
for (; i < t; s += "0", i++)
;
s = pe(s, o);
} else if (t -= l, s = ie(s, o, "0"), o + 1 > i) {
} else if (t -= f, s = ie(s, o, "0"), o + 1 > i) {
if (--t > 0)

@@ -334,3 +334,3 @@ for (s += "."; t--; s += "0")

}
function J(e, t) {
function Y(e, t) {
for (var n, u, r = 1, o = new d(e[0]); r < e.length; r++)

@@ -345,17 +345,17 @@ u = new d(e[r]), (!u.s || (n = ce(o, u)) === t || n === 0 && o.s === t) && (o = u);

;
return (n = u + n * P - 1) > q ? e.c = e.e = null : n < T ? e.c = [e.e = 0] : (e.e = n, e.c = t), e;
return (n = u + n * R - 1) > q ? e.c = e.e = null : n < z ? e.c = [e.e = 0] : (e.e = n, e.c = t), e;
}
N = /* @__PURE__ */ function() {
var e = /^(-?)0([xbo])(?=\w[\w.]*$)/i, t = /^([^.]+)\.$/, n = /^\.([^.]+)$/, u = /^-?(Infinity|NaN)$/, r = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
return function(o, l, i, s) {
var a, f = i ? l : l.replace(r, "");
if (u.test(f))
o.s = isNaN(f) ? null : f < 0 ? -1 : 1;
return function(o, f, i, s) {
var l, c = i ? f : f.replace(r, "");
if (u.test(c))
o.s = isNaN(c) ? null : c < 0 ? -1 : 1;
else {
if (!i && (f = f.replace(e, function(h, m, w) {
return a = (w = w.toLowerCase()) == "x" ? 16 : w == "b" ? 2 : 8, !s || s == a ? m : h;
}), s && (a = s, f = f.replace(t, "$1").replace(n, "0.$1")), l != f))
return new d(f, a);
if (!i && (c = c.replace(e, function(h, m, w) {
return l = (w = w.toLowerCase()) == "x" ? 16 : w == "b" ? 2 : 8, !s || s == l ? m : h;
}), s && (l = s, c = c.replace(t, "$1").replace(n, "0.$1")), f != c))
return new d(c, l);
if (d.DEBUG)
throw Error(b + "Not a" + (s ? " base " + s : "") + " number: " + l);
throw Error(b + "Not a" + (s ? " base " + s : "") + " number: " + f);
o.s = null;

@@ -367,3 +367,3 @@ }

function W(e, t, n, u) {
var r, o, l, i, s, a, f, h = e.c, m = Oe;
var r, o, f, i, s, l, c, h = e.c, m = Oe;
if (h) {

@@ -374,14 +374,14 @@ e: {

if (o = t - r, o < 0)
o += P, l = t, s = h[a = 0], f = K(s / m[r - l - 1] % 10);
else if (a = Ae((o + 1) / P), a >= h.length)
o += R, f = t, s = h[l = 0], c = J(s / m[r - f - 1] % 10);
else if (l = Ae((o + 1) / R), l >= h.length)
if (u) {
for (; h.length <= a; h.push(0))
for (; h.length <= l; h.push(0))
;
s = f = 0, r = 1, o %= P, l = o - P + 1;
s = c = 0, r = 1, o %= R, f = o - R + 1;
} else
break e;
else {
for (s = i = h[a], r = 1; i >= 10; i /= 10, r++)
for (s = i = h[l], r = 1; i >= 10; i /= 10, r++)
;
o %= P, l = o - P + r, f = l < 0 ? 0 : K(s / m[r - l - 1] % 10);
o %= R, f = o - R + r, c = f < 0 ? 0 : J(s / m[r - f - 1] % 10);
}

@@ -391,11 +391,11 @@ if (u = u || t < 0 || // Are there any non-zero digits after the rounding digit?

// of the digit at j, e.g. if n is 908714 and j is 2, the expression gives 714.
h[a + 1] != null || (l < 0 ? s : s % m[r - l - 1]), u = n < 4 ? (f || u) && (n == 0 || n == (e.s < 0 ? 3 : 2)) : f > 5 || f == 5 && (n == 4 || u || n == 6 && // Check whether the digit to the left of the rounding digit is odd.
(o > 0 ? l > 0 ? s / m[r - l] : 0 : h[a - 1]) % 10 & 1 || n == (e.s < 0 ? 8 : 7)), t < 1 || !h[0])
return h.length = 0, u ? (t -= e.e + 1, h[0] = m[(P - t % P) % P], e.e = -t || 0) : h[0] = e.e = 0, e;
if (o == 0 ? (h.length = a, i = 1, a--) : (h.length = a + 1, i = m[P - o], h[a] = l > 0 ? K(s / m[r - l] % m[l]) * i : 0), u)
h[l + 1] != null || (f < 0 ? s : s % m[r - f - 1]), u = n < 4 ? (c || u) && (n == 0 || n == (e.s < 0 ? 3 : 2)) : c > 5 || c == 5 && (n == 4 || u || n == 6 && // Check whether the digit to the left of the rounding digit is odd.
(o > 0 ? f > 0 ? s / m[r - f] : 0 : h[l - 1]) % 10 & 1 || n == (e.s < 0 ? 8 : 7)), t < 1 || !h[0])
return h.length = 0, u ? (t -= e.e + 1, h[0] = m[(R - t % R) % R], e.e = -t || 0) : h[0] = e.e = 0, e;
if (o == 0 ? (h.length = l, i = 1, l--) : (h.length = l + 1, i = m[R - o], h[l] = f > 0 ? J(s / m[r - f] % m[f]) * i : 0), u)
for (; ; )
if (a == 0) {
for (o = 1, l = h[0]; l >= 10; l /= 10, o++)
if (l == 0) {
for (o = 1, f = h[0]; f >= 10; f /= 10, o++)
;
for (l = h[0] += i, i = 1; l >= 10; l /= 10, i++)
for (f = h[0] += i, i = 1; f >= 10; f /= 10, i++)
;

@@ -405,5 +405,5 @@ o != i && (e.e++, h[0] == ee && (h[0] = 1));

} else {
if (h[a] += i, h[a] != ee)
if (h[l] += i, h[l] != ee)
break;
h[a--] = 0, i = 1;
h[l--] = 0, i = 1;
}

@@ -413,3 +413,3 @@ for (o = h.length; h[--o] === 0; h.pop())

}
e.e > q ? e.c = e.e = null : e.e < T && (e.c = [e.e = 0]);
e.e > q ? e.c = e.e = null : e.e < z && (e.c = [e.e = 0]);
}

@@ -420,3 +420,3 @@ return e;

var t, n = e.e;
return n === null ? e.toString() : (t = Z(e.c), t = n <= _ || n >= I ? pe(t, n) : ie(t, n, "0"), e.s < 0 ? "-" + t : t);
return n === null ? e.toString() : (t = K(e.c), t = n <= _ || n >= M ? pe(t, n) : ie(t, n, "0"), e.s < 0 ? "-" + t : t);
}

@@ -434,3 +434,3 @@ return p.absoluteValue = p.abs = function() {

return null;
if (u = ((r = n.length - 1) - j(this.e / P)) * P, r = n[r])
if (u = ((r = n.length - 1) - j(this.e / R)) * R, r = n[r])
for (; r % 10 == 0; r /= 10, u--)

@@ -444,7 +444,7 @@ ;

}, p.exponentiatedBy = p.pow = function(e, t) {
var n, u, r, o, l, i, s, a, f, h = this;
var n, u, r, o, f, i, s, l, c, h = this;
if (e = new d(e), e.c && !e.isInteger())
throw Error(b + "Exponent not an integer: " + C(e));
if (t != null && (t = new d(t)), i = e.e > 14, !h.c || !h.c[0] || h.c[0] == 1 && !h.e && h.c.length == 1 || !e.c || !e.c[0])
return f = new d(Math.pow(+C(h), i ? e.s * (2 - ge(e)) : +C(e))), t ? f.mod(t) : f;
return c = new d(Math.pow(+C(h), i ? e.s * (2 - ge(e)) : +C(e))), t ? c.mod(t) : c;
if (s = e.s < 0, t) {

@@ -457,24 +457,24 @@ if (t.c ? !t.c[0] : !t.s)

return o = h.s < 0 && ge(e) ? -0 : 0, h.e > -1 && (o = 1 / o), new d(s ? 1 / o : o);
G && (o = Ae(G / P + 2));
G && (o = Ae(G / R + 2));
}
for (i ? (n = new d(0.5), s && (e.s = 1), a = ge(e)) : (r = Math.abs(+C(e)), a = r % 2), f = new d(R); ; ) {
if (a) {
if (f = f.times(h), !f.c)
for (i ? (n = new d(0.5), s && (e.s = 1), l = ge(e)) : (r = Math.abs(+C(e)), l = r % 2), c = new d(P); ; ) {
if (l) {
if (c = c.times(h), !c.c)
break;
o ? f.c.length > o && (f.c.length = o) : u && (f = f.mod(t));
o ? c.c.length > o && (c.c.length = o) : u && (c = c.mod(t));
}
if (r) {
if (r = K(r / 2), r === 0)
if (r = J(r / 2), r === 0)
break;
a = r % 2;
l = r % 2;
} else if (e = e.times(n), W(e, e.e + 1, 1), e.e > 14)
a = ge(e);
l = ge(e);
else {
if (r = +C(e), r === 0)
break;
a = r % 2;
l = r % 2;
}
h = h.times(h), o ? h.c && h.c.length > o && (h.c.length = o) : u && (h = h.mod(t));
}
return u ? f : (s && (f = R.div(f)), t ? f.mod(t) : o ? W(f, G, O, l) : f);
return u ? c : (s && (c = P.div(c)), t ? c.mod(t) : o ? W(c, G, O, f) : c);
}, p.integerValue = function(e) {

@@ -492,3 +492,3 @@ var t = new d(this);

}, p.isInteger = function() {
return !!this.c && j(this.e / P) > this.c.length - 2;
return !!this.c && j(this.e / R) > this.c.length - 2;
}, p.isLessThan = p.lt = function(e, t) {

@@ -507,13 +507,13 @@ return ce(this, new d(e, t)) < 0;

}, p.minus = function(e, t) {
var n, u, r, o, l = this, i = l.s;
var n, u, r, o, f = this, i = f.s;
if (e = new d(e, t), t = e.s, !i || !t)
return new d(NaN);
if (i != t)
return e.s = -t, l.plus(e);
var s = l.e / P, a = e.e / P, f = l.c, h = e.c;
if (!s || !a) {
if (!f || !h)
return f ? (e.s = -t, e) : new d(h ? l : NaN);
if (!f[0] || !h[0])
return h[0] ? (e.s = -t, e) : new d(f[0] ? l : (
return e.s = -t, f.plus(e);
var s = f.e / R, l = e.e / R, c = f.c, h = e.c;
if (!s || !l) {
if (!c || !h)
return c ? (e.s = -t, e) : new d(h ? f : NaN);
if (!c[0] || !h[0])
return h[0] ? (e.s = -t, e) : new d(c[0] ? f : (
// IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity

@@ -523,26 +523,26 @@ O == 3 ? -0 : 0

}
if (s = j(s), a = j(a), f = f.slice(), i = s - a) {
for ((o = i < 0) ? (i = -i, r = f) : (a = s, r = h), r.reverse(), t = i; t--; r.push(0))
if (s = j(s), l = j(l), c = c.slice(), i = s - l) {
for ((o = i < 0) ? (i = -i, r = c) : (l = s, r = h), r.reverse(), t = i; t--; r.push(0))
;
r.reverse();
} else
for (u = (o = (i = f.length) < (t = h.length)) ? i : t, i = t = 0; t < u; t++)
if (f[t] != h[t]) {
o = f[t] < h[t];
for (u = (o = (i = c.length) < (t = h.length)) ? i : t, i = t = 0; t < u; t++)
if (c[t] != h[t]) {
o = c[t] < h[t];
break;
}
if (o && (r = f, f = h, h = r, e.s = -e.s), t = (u = h.length) - (n = f.length), t > 0)
for (; t--; f[n++] = 0)
if (o && (r = c, c = h, h = r, e.s = -e.s), t = (u = h.length) - (n = c.length), t > 0)
for (; t--; c[n++] = 0)
;
for (t = ee - 1; u > i; ) {
if (f[--u] < h[u]) {
for (n = u; n && !f[--n]; f[n] = t)
if (c[--u] < h[u]) {
for (n = u; n && !c[--n]; c[n] = t)
;
--f[n], f[u] += ee;
--c[n], c[u] += ee;
}
f[u] -= h[u];
c[u] -= h[u];
}
for (; f[0] == 0; f.splice(0, 1), --a)
for (; c[0] == 0; c.splice(0, 1), --l)
;
return f[0] ? ne(e, f, a) : (e.s = O == 3 ? -1 : 1, e.c = [e.e = 0], e);
return c[0] ? ne(e, c, l) : (e.s = O == 3 ? -1 : 1, e.c = [e.e = 0], e);
}, p.modulo = p.mod = function(e, t) {

@@ -552,10 +552,10 @@ var n, u, r = this;

}, p.multipliedBy = p.times = function(e, t) {
var n, u, r, o, l, i, s, a, f, h, m, w, B, D, z, x = this, M = x.c, y = (e = new d(e, t)).c;
if (!M || !y || !M[0] || !y[0])
return !x.s || !e.s || M && !M[0] && !y || y && !y[0] && !M ? e.c = e.e = e.s = null : (e.s *= x.s, !M || !y ? e.c = e.e = null : (e.c = [0], e.e = 0)), e;
for (u = j(x.e / P) + j(e.e / P), e.s *= x.s, s = M.length, h = y.length, s < h && (B = M, M = y, y = B, r = s, s = h, h = r), r = s + h, B = []; r--; B.push(0))
var n, u, r, o, f, i, s, l, c, h, m, w, B, D, T, x = this, I = x.c, y = (e = new d(e, t)).c;
if (!I || !y || !I[0] || !y[0])
return !x.s || !e.s || I && !I[0] && !y || y && !y[0] && !I ? e.c = e.e = e.s = null : (e.s *= x.s, !I || !y ? e.c = e.e = null : (e.c = [0], e.e = 0)), e;
for (u = j(x.e / R) + j(e.e / R), e.s *= x.s, s = I.length, h = y.length, s < h && (B = I, I = y, y = B, r = s, s = h, h = r), r = s + h, B = []; r--; B.push(0))
;
for (D = ee, z = oe, r = h; --r >= 0; ) {
for (n = 0, m = y[r] % z, w = y[r] / z | 0, l = s, o = r + l; o > r; )
a = M[--l] % z, f = M[l] / z | 0, i = w * a + f * m, a = m * a + i % z * z + B[o] + n, n = (a / D | 0) + (i / z | 0) + w * f, B[o--] = a % D;
for (D = ee, T = oe, r = h; --r >= 0; ) {
for (n = 0, m = y[r] % T, w = y[r] / T | 0, f = s, o = r + f; o > r; )
l = I[--f] % T, c = I[f] / T | 0, i = w * l + c * m, l = m * l + i % T * T + B[o] + n, n = (l / D | 0) + (i / T | 0) + w * c, B[o--] = l % D;
B[o] = n;

@@ -573,4 +573,4 @@ }

return e.s = -t, u.minus(e);
var o = u.e / P, l = e.e / P, i = u.c, s = e.c;
if (!o || !l) {
var o = u.e / R, f = e.e / R, i = u.c, s = e.c;
if (!o || !f) {
if (!i || !s)

@@ -581,4 +581,4 @@ return new d(r / 0);

}
if (o = j(o), l = j(l), i = i.slice(), r = o - l) {
for (r > 0 ? (l = o, n = s) : (r = -r, n = i), n.reverse(); r--; n.push(0))
if (o = j(o), f = j(f), i = i.slice(), r = o - f) {
for (r > 0 ? (f = o, n = s) : (r = -r, n = i), n.reverse(); r--; n.push(0))
;

@@ -589,3 +589,3 @@ n.reverse();

r = (i[--t] = i[t] + s[t] + r) / ee | 0, i[t] = ee === i[t] ? 0 : i[t] % ee;
return r && (i = [r].concat(i), ++l), ne(e, i, l);
return r && (i = [r].concat(i), ++f), ne(e, i, f);
}, p.precision = p.sd = function(e, t) {

@@ -597,3 +597,3 @@ var n, u, r, o = this;

return null;
if (r = n.length - 1, u = r * P + 1, r = n[r]) {
if (r = n.length - 1, u = r * R + 1, r = n[r]) {
for (; r % 10 == 0; r /= 10, u--)

@@ -608,8 +608,8 @@ ;

}, p.squareRoot = p.sqrt = function() {
var e, t, n, u, r, o = this, l = o.c, i = o.s, s = o.e, a = E + 4, f = new d("0.5");
if (i !== 1 || !l || !l[0])
return new d(!i || i < 0 && (!l || l[0]) ? NaN : l ? o : 1 / 0);
if (i = Math.sqrt(+C(o)), i == 0 || i == 1 / 0 ? (t = Z(l), (t.length + s) % 2 == 0 && (t += "0"), i = Math.sqrt(+t), s = j((s + 1) / 2) - (s < 0 || s % 2), i == 1 / 0 ? t = "5e" + s : (t = i.toExponential(), t = t.slice(0, t.indexOf("e") + 1) + s), n = new d(t)) : n = new d(i + ""), n.c[0]) {
for (s = n.e, i = s + a, i < 3 && (i = 0); ; )
if (r = n, n = f.times(r.plus(g(o, r, a, 1))), Z(r.c).slice(0, i) === (t = Z(n.c)).slice(0, i))
var e, t, n, u, r, o = this, f = o.c, i = o.s, s = o.e, l = E + 4, c = new d("0.5");
if (i !== 1 || !f || !f[0])
return new d(!i || i < 0 && (!f || f[0]) ? NaN : f ? o : 1 / 0);
if (i = Math.sqrt(+C(o)), i == 0 || i == 1 / 0 ? (t = K(f), (t.length + s) % 2 == 0 && (t += "0"), i = Math.sqrt(+t), s = j((s + 1) / 2) - (s < 0 || s % 2), i == 1 / 0 ? t = "5e" + s : (t = i.toExponential(), t = t.slice(0, t.indexOf("e") + 1) + s), n = new d(t)) : n = new d(i + ""), n.c[0]) {
for (s = n.e, i = s + l, i < 3 && (i = 0); ; )
if (r = n, n = c.times(r.plus(g(o, r, l, 1))), K(r.c).slice(0, i) === (t = K(n.c)).slice(0, i))
if (n.e < s && --i, t = t.slice(i - 3, i + 1), t == "9999" || !u && t == "4999") {

@@ -620,3 +620,3 @@ if (!u && (W(r, r.e + E + 2, 0), r.times(r).eq(o))) {

}
a += 4, i += 4, u = 1;
l += 4, i += 4, u = 1;
} else {

@@ -639,25 +639,25 @@ (!+t || !+t.slice(1) && t.charAt(0) == "5") && (W(n, n.e + E + 2, 1), e = !n.times(n).eq(o));

if (u = r.toFixed(e, t), r.c) {
var o, l = u.split("."), i = +n.groupSize, s = +n.secondaryGroupSize, a = n.groupSeparator || "", f = l[0], h = l[1], m = r.s < 0, w = m ? f.slice(1) : f, B = w.length;
var o, f = u.split("."), i = +n.groupSize, s = +n.secondaryGroupSize, l = n.groupSeparator || "", c = f[0], h = f[1], m = r.s < 0, w = m ? c.slice(1) : c, B = w.length;
if (s && (o = i, i = s, s = o, B -= o), i > 0 && B > 0) {
for (o = B % i || i, f = w.substr(0, o); o < B; o += i)
f += a + w.substr(o, i);
s > 0 && (f += a + w.slice(o)), m && (f = "-" + f);
for (o = B % i || i, c = w.substr(0, o); o < B; o += i)
c += l + w.substr(o, i);
s > 0 && (c += l + w.slice(o)), m && (c = "-" + c);
}
u = h ? f + (n.decimalSeparator || "") + ((s = +n.fractionGroupSize) ? h.replace(
u = h ? c + (n.decimalSeparator || "") + ((s = +n.fractionGroupSize) ? h.replace(
new RegExp("\\d{" + s + "}\\B", "g"),
"$&" + (n.fractionGroupSeparator || "")
) : h) : f;
) : h) : c;
}
return (n.prefix || "") + u + (n.suffix || "");
}, p.toFraction = function(e) {
var t, n, u, r, o, l, i, s, a, f, h, m, w = this, B = w.c;
if (e != null && (i = new d(e), !i.isInteger() && (i.c || i.s !== 1) || i.lt(R)))
var t, n, u, r, o, f, i, s, l, c, h, m, w = this, B = w.c;
if (e != null && (i = new d(e), !i.isInteger() && (i.c || i.s !== 1) || i.lt(P)))
throw Error(b + "Argument " + (i.isInteger() ? "out of range: " : "not an integer: ") + C(i));
if (!B)
return new d(w);
for (t = new d(R), a = n = new d(R), u = s = new d(R), m = Z(B), o = t.e = m.length - w.e - 1, t.c[0] = Oe[(l = o % P) < 0 ? P + l : l], e = !e || i.comparedTo(t) > 0 ? o > 0 ? t : a : i, l = q, q = 1 / 0, i = new d(m), s.c[0] = 0; f = g(i, t, 0, 1), r = n.plus(f.times(u)), r.comparedTo(e) != 1; )
n = u, u = r, a = s.plus(f.times(r = a)), s = r, t = i.minus(f.times(r = t)), i = r;
return r = g(e.minus(n), u, 0, 1), s = s.plus(r.times(a)), n = n.plus(r.times(u)), s.s = a.s = w.s, o = o * 2, h = g(a, u, o, O).minus(w).abs().comparedTo(
for (t = new d(P), l = n = new d(P), u = s = new d(P), m = K(B), o = t.e = m.length - w.e - 1, t.c[0] = Oe[(f = o % R) < 0 ? R + f : f], e = !e || i.comparedTo(t) > 0 ? o > 0 ? t : l : i, f = q, q = 1 / 0, i = new d(m), s.c[0] = 0; c = g(i, t, 0, 1), r = n.plus(c.times(u)), r.comparedTo(e) != 1; )
n = u, u = r, l = s.plus(c.times(r = l)), s = r, t = i.minus(c.times(r = t)), i = r;
return r = g(e.minus(n), u, 0, 1), s = s.plus(r.times(l)), n = n.plus(r.times(u)), s.s = l.s = w.s, o = o * 2, h = g(l, u, o, O).minus(w).abs().comparedTo(
g(s, n, o, O).minus(w).abs()
) < 1 ? [a, u] : [s, n], q = l, h;
) < 1 ? [l, u] : [s, n], q = f, h;
}, p.toNumber = function() {

@@ -669,50 +669,50 @@ return +C(this);

var t, n = this, u = n.s, r = n.e;
return r === null ? u ? (t = "Infinity", u < 0 && (t = "-" + t)) : t = "NaN" : (e == null ? t = r <= _ || r >= I ? pe(Z(n.c), r) : ie(Z(n.c), r, "0") : e === 10 && se ? (n = W(new d(n), E + r + 1, O), t = ie(Z(n.c), n.e, "0")) : (F(e, 2, $.length, "Base"), t = v(ie(Z(n.c), r, "0"), 10, e, u, !0)), u < 0 && n.c[0] && (t = "-" + t)), t;
return r === null ? u ? (t = "Infinity", u < 0 && (t = "-" + t)) : t = "NaN" : (e == null ? t = r <= _ || r >= M ? pe(K(n.c), r) : ie(K(n.c), r, "0") : e === 10 && se ? (n = W(new d(n), E + r + 1, O), t = ie(K(n.c), n.e, "0")) : (F(e, 2, $.length, "Base"), t = v(ie(K(n.c), r, "0"), 10, e, u, !0)), u < 0 && n.c[0] && (t = "-" + t)), t;
}, p.valueOf = p.toJSON = function() {
return C(this);
}, p._isBigNumber = !0, p[Symbol.toStringTag] = "BigNumber", p[Symbol.for("nodejs.util.inspect.custom")] = p.valueOf, c != null && d.set(c), d;
}, p._isBigNumber = !0, p[Symbol.toStringTag] = "BigNumber", p[Symbol.for("nodejs.util.inspect.custom")] = p.valueOf, a != null && d.set(a), d;
}
function j(c) {
var g = c | 0;
return c > 0 || c === g ? g : g - 1;
function j(a) {
var g = a | 0;
return a > 0 || a === g ? g : g - 1;
}
function Z(c) {
for (var g, v, N = 1, p = c.length, R = c[0] + ""; N < p; ) {
for (g = c[N++] + "", v = P - g.length; v--; g = "0" + g)
function K(a) {
for (var g, v, N = 1, p = a.length, P = a[0] + ""; N < p; ) {
for (g = a[N++] + "", v = R - g.length; v--; g = "0" + g)
;
R += g;
P += g;
}
for (p = R.length; R.charCodeAt(--p) === 48; )
for (p = P.length; P.charCodeAt(--p) === 48; )
;
return R.slice(0, p + 1 || 1);
return P.slice(0, p + 1 || 1);
}
function ce(c, g) {
var v, N, p = c.c, R = g.c, E = c.s, O = g.s, _ = c.e, I = g.e;
function ce(a, g) {
var v, N, p = a.c, P = g.c, E = a.s, O = g.s, _ = a.e, M = g.e;
if (!E || !O)
return null;
if (v = p && !p[0], N = R && !R[0], v || N)
if (v = p && !p[0], N = P && !P[0], v || N)
return v ? N ? 0 : -O : E;
if (E != O)
return E;
if (v = E < 0, N = _ == I, !p || !R)
if (v = E < 0, N = _ == M, !p || !P)
return N ? 0 : !p ^ v ? 1 : -1;
if (!N)
return _ > I ^ v ? 1 : -1;
for (O = (_ = p.length) < (I = R.length) ? _ : I, E = 0; E < O; E++)
if (p[E] != R[E])
return p[E] > R[E] ^ v ? 1 : -1;
return _ == I ? 0 : _ > I ^ v ? 1 : -1;
return _ > M ^ v ? 1 : -1;
for (O = (_ = p.length) < (M = P.length) ? _ : M, E = 0; E < O; E++)
if (p[E] != P[E])
return p[E] > P[E] ^ v ? 1 : -1;
return _ == M ? 0 : _ > M ^ v ? 1 : -1;
}
function F(c, g, v, N) {
if (c < g || c > v || c !== K(c))
throw Error(b + (N || "Argument") + (typeof c == "number" ? c < g || c > v ? " out of range: " : " not an integer: " : " not a primitive number: ") + String(c));
function F(a, g, v, N) {
if (a < g || a > v || a !== J(a))
throw Error(b + (N || "Argument") + (typeof a == "number" ? a < g || a > v ? " out of range: " : " not an integer: " : " not a primitive number: ") + String(a));
}
function ge(c) {
var g = c.c.length - 1;
return j(c.e / P) == g && c.c[g] % 2 != 0;
function ge(a) {
var g = a.c.length - 1;
return j(a.e / R) == g && a.c[g] % 2 != 0;
}
function pe(c, g) {
return (c.length > 1 ? c.charAt(0) + "." + c.slice(1) : c) + (g < 0 ? "e" : "e+") + g;
function pe(a, g) {
return (a.length > 1 ? a.charAt(0) + "." + a.slice(1) : a) + (g < 0 ? "e" : "e+") + g;
}
function ie(c, g, v) {
function ie(a, g, v) {
var N, p;

@@ -722,155 +722,155 @@ if (g < 0) {

;
c = p + c;
} else if (N = c.length, ++g > N) {
a = p + a;
} else if (N = a.length, ++g > N) {
for (p = v, g -= N; --g; p += v)
;
c += p;
a += p;
} else
g < N && (c = c.slice(0, g) + "." + c.slice(g));
return c;
g < N && (a = a.slice(0, g) + "." + a.slice(g));
return a;
}
var re = Pe();
var re = Re();
const ae = new re(0), Be = 9, S = A(A(10).pow(Be));
function A(c) {
return new re(c);
function A(a) {
return new re(a);
}
function ue(c) {
return new re(c).integerValue().toNumber();
function ue(a) {
return new re(a).integerValue().toNumber();
}
function Te(c) {
return ue(c) / 1e9;
function De(a) {
return ue(a) / 1e9;
}
var Ie = /* @__PURE__ */ ((c) => (c[c.Plain = 1] = "Plain", c[c.JIT = 2] = "JIT", c))(Ie || {}), Me = /* @__PURE__ */ ((c) => (c[c.direct = 1] = "direct", c[c.indirect = 2] = "indirect", c))(Me || {}), _e = /* @__PURE__ */ ((c) => (c.base = "base", c.coinm = "coinm", c.prelaunch = "prelaunch", c))(_e || {});
function fe(c, g = S) {
return A(c.quoteAssetReserve).times(c.quoteAssetReserveWeight).div(A(c.baseAssetReserve).times(g)).times(g);
var Me = /* @__PURE__ */ ((a) => (a.base = "base", a.coinm = "coinm", a.prelaunch = "prelaunch", a))(Me || {});
function fe(a, g = S) {
return A(a.quoteAssetReserve).times(a.quoteAssetReserveWeight).div(A(a.baseAssetReserve).times(g)).times(g);
}
function ze(c, g, v) {
const N = new re(g.openInterestLong).minus(g.openInterestShort), p = N.abs().div(c.maxOpenNotional);
let R = new re(0);
function Le(a, g, v) {
const N = new re(g.openInterestLong).minus(g.openInterestShort), p = N.abs().div(a.maxOpenNotional);
let P = new re(0);
if (p.isZero())
return new re(0);
p.lte(v.inflectionPoint) ? R = p.times(v.lowFundingFnB).plus(v.lowFundingFnA) : R = p.times(v.highFundingFnB).plus(v.highFundingFnA);
let E = R.times(fe(g));
p.lte(v.inflectionPoint) ? P = p.times(v.lowFundingFnB).plus(v.lowFundingFnA) : P = p.times(v.highFundingFnB).plus(v.highFundingFnA);
let E = P.times(fe(g));
return N.isNegative() && (E = E.negated()), E;
}
function qe(c, g) {
function Ie(a, g) {
return {
quoteAssetWeight: g.times(c.baseAssetReserve).div(c.quoteAssetReserve),
quoteAssetWeight: g.times(a.baseAssetReserve).div(a.quoteAssetReserve),
baseAssetWeight: S
};
}
function Fe(c, g) {
const v = A(c.baseAssetReserve).div(S), N = A(c.totalPositionSize).div(S), p = A(c.quoteAssetReserve).div(S), R = g.div(S), E = p.times(v), O = v.plus(N), I = E.div(O).div(O);
return R.div(I).times(S);
function _e(a, g) {
const v = A(a.baseAssetReserve).div(S), N = A(a.totalPositionSize).div(S), p = A(a.quoteAssetReserve).div(S), P = g.div(S), E = p.times(v), O = v.plus(N), M = E.div(O).div(O);
return P.div(M).times(S);
}
function De(c, g) {
if (A(c.totalPositionSize).eq(ae)) {
const { quoteAssetWeight: v } = qe(c, g);
return { ...c, quoteAssetReserveWeight: v };
function qe(a, g) {
if (A(a.totalPositionSize).eq(ae)) {
const { quoteAssetWeight: v } = Ie(a, g);
return { ...a, quoteAssetReserveWeight: v };
} else {
const v = Fe(c, g);
return { ...c, quoteAssetReserveWeight: v };
const v = _e(a, g);
return { ...a, quoteAssetReserveWeight: v };
}
}
function Ce(c, g, v = 1) {
return A(c).times(g).times(v).div(S);
function ze(a, g, v = 1) {
return A(a).times(g).times(v).div(S);
}
function Re(c) {
return A(c.openNotional).div(c.size).abs();
function Pe(a) {
return A(a.openNotional).div(a.size).abs();
}
function Ue(c) {
const { leverage: g, feeRate: v, amount: N, decimals: p = S } = c, R = A(N), E = A(g).times(v), O = R.div(A(p).plus(E).div(p));
return R.abs().minus(O.abs());
function Te(a) {
const { leverage: g, feeRate: v, amount: N, decimals: p = S } = a, P = A(N), E = A(g).times(v), O = P.div(A(p).plus(E).div(p));
return P.abs().minus(O.abs());
}
function de(c, g) {
const v = A(c.size).gt(0) ? g.latestLongPremiumFraction : g.latestShortPremiumFraction;
return A(v).minus(c.fraction).times(c.size).div(S).negated();
function de(a, g) {
const v = A(a.size).gt(0) ? g.latestLongPremiumFraction : g.latestShortPremiumFraction;
return A(v).minus(a.fraction).times(a.size).div(S).negated();
}
function ke(c) {
const g = De(
function Ce(a) {
const g = qe(
{
...c,
totalPositionSize: A(c.totalPositionSize).negated()
...a,
totalPositionSize: A(a.totalPositionSize).negated()
},
fe(c)
fe(a)
);
return fe(g);
}
function Le(c, g = 1) {
return A(c.openNotional).div(c.margin).div(g);
function Fe(a, g = 1) {
return A(a.openNotional).div(a.margin).div(g);
}
function ve(c, g, v = {}) {
const { blockTimestamp: N = /* @__PURE__ */ new Date(), decimals: p = S } = v, R = Math.floor(
(N.getTime() - c.timestamp.getTime()) / 1e3 / 60
function ve(a, g, v = {}) {
const { blockTimestamp: N = /* @__PURE__ */ new Date(), decimals: p = S } = v, P = Math.floor(
(N.getTime() - a.timestamp.getTime()) / 1e3 / 60
);
return A(c.margin).times(R).times(A(g.rolloverFee).div(p)).div(525600);
return A(a.margin).times(P).times(A(g.rolloverFee).div(p)).div(525600);
}
function Qe(c, g, v, N = 1, p = {}) {
const { isSettleBySpotPrice: R = !1 } = p, E = A(c.openNotional).div(S), O = A(v.maintenanceMarginRatio).div(S), _ = A(g.quoteAssetReserve).div(S), I = A(g.baseAssetReserve).div(S), T = A(g.totalPositionSize).div(S), q = A(c.margin).div(S), k = A(c.size).div(S), Q = de(c, g).div(S), G = ve(c, v, p).div(S), X = Le(c, N).decimalPlaces(9), $ = Q, se = G, d = q, H = _, J = I, ne = T, W = k;
function Ue(a, g, v, N = 1, p = {}) {
const { isSettleBySpotPrice: P = !1 } = p, E = A(a.openNotional).div(S), O = A(v.maintenanceMarginRatio).div(S), _ = A(g.quoteAssetReserve).div(S), M = A(g.baseAssetReserve).div(S), z = A(g.totalPositionSize).div(S), q = A(a.margin).div(S), k = A(a.size).div(S), Q = de(a, g).div(S), G = ve(a, v, p).div(S), X = Fe(a, N).decimalPlaces(9), $ = Q, se = G, d = q, H = _, Y = M, ne = z, W = k;
let C = A(N), e = O;
const t = J.div(J.plus(W)).gt(1);
const t = Y.div(Y.plus(W)).gt(1);
if (X.eq(1))
return t ? Re(c).div(O).times(S) : Re(c).times(O).times(S);
return t ? Pe(a).div(O).times(S) : Pe(a).times(O).times(S);
if (X.lt(1))
return ae;
const n = H.times(J), u = n.div(J.plus(ne)).div(J.plus(ne)), r = n.div(J.plus(W)).minus(H), o = $.minus(se).plus(d);
let l, i;
return t ? (l = E, i = e.plus(1)) : (l = E.negated(), i = e.minus(1).negated()), R && (C = l.times(u).div(i.abs().times(r).minus(o.times(u)))), l.plus(o.times(C)).div(i).div(r).times(u).times(S).abs();
const n = H.times(Y), u = n.div(Y.plus(ne)).div(Y.plus(ne)), r = n.div(Y.plus(W)).minus(H), o = $.minus(se).plus(d);
let f, i;
return t ? (f = E, i = e.plus(1)) : (f = E.negated(), i = e.minus(1).negated()), P && (C = f.times(u).div(i.abs().times(r).minus(o.times(u)))), f.plus(o.times(C)).div(i).div(r).times(u).times(S).abs();
}
function Se(c, g, v = S) {
const N = A(c.baseAssetReserve).div(v), p = A(g).div(v), R = A(c.quoteAssetReserve).div(v), E = A(c.quoteAssetReserveWeight).div(v), O = R.times(N), _ = re.max(N.plus(p), 1e-8), I = O.div(_), q = I.minus(R).times(E).times(v), k = fe(c, v), Q = q.abs().div(g).times(v).abs(), G = k.minus(Q).abs(), X = 1 - Q.dividedBy(Q.plus(G)).toNumber();
function Se(a, g, v = S) {
const N = A(a.baseAssetReserve).div(v), p = A(g).div(v), P = A(a.quoteAssetReserve).div(v), E = A(a.quoteAssetReserveWeight).div(v), O = P.times(N), _ = re.max(N.plus(p), 1e-8), M = O.div(_), q = M.minus(P).times(E).times(v), k = fe(a, v), Q = q.abs().div(g).times(v).abs(), G = k.minus(Q).abs(), X = 1 - Q.dividedBy(Q.plus(G)).toNumber();
return {
quoteAssetOutput: q,
baseAssetAfter: _.times(v),
quoteAssetAfter: I.times(v),
quoteAssetAfter: M.times(v),
priceImpact: X
};
}
function We(c, g, v, N = 1, p = {}) {
const R = de(c, g), E = ve(c, v, p), { quoteAssetOutput: O } = Se(g, c.size), T = (O.gt(ae) ? A(c.openNotional).minus(O.integerValue()) : A(c.openNotional).plus(O.integerValue()).negated()).div(N).plus(R).minus(E).plus(c.margin), q = O.abs();
return T.times(N).div(q).times(p.decimals ?? S);
function ke(a, g, v, N = 1, p = {}) {
const P = de(a, g), E = ve(a, v, p), { quoteAssetOutput: O } = Se(g, a.size), z = (O.gt(ae) ? A(a.openNotional).minus(O.integerValue()) : A(a.openNotional).plus(O.integerValue()).negated()).div(N).plus(P).minus(E).plus(a.margin), q = O.abs();
return z.times(N).div(q).times(p.decimals ?? S);
}
function Ge(c) {
return c ? Math.floor(1 / A(c.initMarginRatio).div(S).toNumber()) : 0;
function Qe(a) {
return a ? Math.floor(1 / A(a.initMarginRatio).div(S).toNumber()) : 0;
}
function ye(c, g = S) {
return c ? Math.max(
function We(a, g = S) {
return a ? Math.max(
1,
A(1 / A(c.minInitMarginRatio).div(g).toNumber()).integerValue(re.ROUND_UP).toNumber()
A(1 / A(a.minInitMarginRatio).div(g).toNumber()).integerValue(re.ROUND_UP).toNumber()
) : 1;
}
function Ve(c, g, v, N, p = 1, R = {}) {
const { isSettleBySpotPrice: E = !1 } = R, O = A(g.openNotional).div(S), _ = A(v.quoteAssetReserve).div(S), I = A(v.baseAssetReserve).div(S), T = A(v.totalPositionSize).div(S), q = A(g.margin).div(S), k = A(g.size).div(S), Q = de(g, v).div(S), G = ve(g, N, R).div(S), X = Q, $ = G, se = q, d = _, H = I, J = T, ne = k, W = A(c);
function Ge(a, g, v, N, p = 1, P = {}) {
const { isSettleBySpotPrice: E = !1 } = P, O = A(g.openNotional).div(S), _ = A(v.quoteAssetReserve).div(S), M = A(v.baseAssetReserve).div(S), z = A(v.totalPositionSize).div(S), q = A(g.margin).div(S), k = A(g.size).div(S), Q = de(g, v).div(S), G = ve(g, N, P).div(S), X = Q, $ = G, se = q, d = _, H = M, Y = z, ne = k, W = A(a);
let C = A(p);
const e = H.div(H.plus(ne)).gt(1), t = d.times(H), n = t.div(H.plus(J)).div(H.plus(J)), u = t.div(H.plus(ne)).minus(d), r = X.minus($).plus(se), l = se.times(C).times(W), i = O;
const e = H.div(H.plus(ne)).gt(1), t = d.times(H), n = t.div(H.plus(Y)).div(H.plus(Y)), u = t.div(H.plus(ne)).minus(d), r = X.minus($).plus(se), f = se.times(C).times(W), i = O;
if (e) {
E && (C = i.minus(l).div(u.abs().div(n).minus(r)));
const s = i.minus(l).plus(r.times(C)).div(u.abs()).times(n);
E && (C = i.minus(f).div(u.abs().div(n).minus(r)));
const s = i.minus(f).plus(r.times(C)).div(u.abs()).times(n);
return s.lte(0) ? ae : s.times(S);
} else
return E && (C = i.plus(l).div(u.abs().div(n).plus(r))), i.plus(l).minus(r.times(C)).div(u.abs()).times(n).times(S);
return E && (C = i.plus(f).div(u.abs().div(n).plus(r))), i.plus(f).minus(r.times(C)).div(u.abs()).times(n).times(S);
}
function be(c, g) {
return A(g).minus(c).div(c).abs();
function ye(a, g) {
return A(g).minus(a).div(a).abs();
}
function $e(c) {
const g = fe(c), v = g.plus(c.indexPrice).div(2);
return A(c.indexPrice).minus(g).abs().div(v);
function Ve(a) {
const g = fe(a), v = g.plus(a.indexPrice).div(2);
return A(a.indexPrice).minus(g).abs().div(v);
}
function He(c, g, v, N = 1, p = {}) {
const R = de(c, g), E = ve(c, v, p), { quoteAssetOutput: O } = Se(g, c.size), I = (O.gt(ae) ? A(c.openNotional).minus(O.integerValue()) : A(c.openNotional).plus(O.integerValue()).negated()).div(N), T = I.plus(R).minus(E).plus(c.margin), q = O.abs(), k = T.times(N).div(q).times(p.decimals ?? S);
function be(a, g, v, N = 1, p = {}) {
const P = de(a, g), E = ve(a, v, p), { quoteAssetOutput: O } = Se(g, a.size), M = (O.gt(ae) ? A(a.openNotional).minus(O.integerValue()) : A(a.openNotional).plus(O.integerValue()).negated()).div(N), z = M.plus(P).minus(E).plus(a.margin), q = O.abs(), k = z.times(N).div(q).times(p.decimals ?? S);
return {
remainMargin: ue(T),
remainMargin: ue(z),
marginRatio: ue(k),
positionNotional: ue(q),
fundingPayment: ue(R),
fundingPayment: ue(P),
rolloverFee: ue(E),
unrealizedPnl: ue(I),
badDebt: ue(re.min(0, T))
unrealizedPnl: ue(M),
badDebt: ue(re.min(0, z))
};
}
function Xe(c, g, v = S) {
const N = A(c.baseAssetReserve).div(v), p = A(g).div(c.quoteAssetReserveWeight), R = A(c.quoteAssetReserve).div(v), E = N.times(R), O = R.plus(p), I = E.div(O).minus(N), T = I.times(v), q = N.plus(I).times(v), k = O.times(v), Q = fe(c, v), G = A(g).abs().div(T.abs()).times(v), X = Q.minus(G).abs(), $ = 1 - Q.dividedBy(Q.plus(X)).toNumber();
function $e(a, g, v = S) {
const N = A(a.baseAssetReserve).div(v), p = A(g).div(a.quoteAssetReserveWeight), P = A(a.quoteAssetReserve).div(v), E = N.times(P), O = P.plus(p), M = E.div(O).minus(N), z = M.times(v), q = N.plus(M).times(v), k = O.times(v), Q = fe(a, v), G = A(g).abs().div(z.abs()).times(v), X = Q.minus(G).abs(), $ = 1 - Q.dividedBy(Q.plus(X)).toNumber();
return {
baseAssetOutput: T,
baseAssetOutput: z,
baseAssetAfter: q,

@@ -884,32 +884,30 @@ quoteAssetAfter: k,

S as DECIMAL_UNIT,
_e as MarketType,
Ie as OracleMode,
Me as PositionMode,
Me as MarketType,
ae as ZERO,
A as bn,
ze as calculateFunding,
qe as calculateQuoteAssetWeight,
Te as decimalValue,
De as getAdjustedAmmState,
Ce as getCloseFee,
Re as getEntryPrice,
Ue as getFee,
Le as calculateFunding,
Ie as calculateQuoteAssetWeight,
De as decimalValue,
qe as getAdjustedAmmState,
ze as getCloseFee,
Pe as getEntryPrice,
Te as getFee,
de as getFundingPremium,
ke as getIndexPrice,
Le as getLeverage,
Qe as getLiquidationPrice,
We as getMarginRatio,
Ce as getIndexPrice,
Fe as getLeverage,
Ue as getLiquidationPrice,
ke as getMarginRatio,
fe as getMarketPrice,
Ge as getMaximumLeverage,
ye as getMinimumLeverage,
Ve as getPriceByProfitRate,
be as getPriceImpact,
$e as getPriceSpread,
Fe as getQuoteAssetWeight,
He as getRemainMarginWithFundingPayment,
Qe as getMaximumLeverage,
We as getMinimumLeverage,
Ge as getPriceByProfitRate,
ye as getPriceImpact,
Ve as getPriceSpread,
_e as getQuoteAssetWeight,
be as getRemainMarginWithFundingPayment,
ve as getRolloverFee,
ue as integerValue,
Xe as swapInput,
$e as swapInput,
Se as swapOutput
};
//# sourceMappingURL=dex-math.js.map
{
"name": "@storm-trade/dex-math",
"private": false,
"version": "1.0.2",
"version": "1.0.3",
"type": "module",

@@ -6,0 +6,0 @@ "files": [

Sorry, the diff of this file is not supported yet

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