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.1 to 1.0.2

10

dist/dex-math.d.ts

@@ -37,2 +37,4 @@ import { BigNumber } from 'bignumber.js';

export declare function calculateFunding(settings: AmmSettings, amm: AmmState, fundingSettings: FundingSettings): BN;
export declare function calculateQuoteAssetWeight(amm: AmmState, terminalPrice: BN): {

@@ -49,2 +51,10 @@ quoteAssetWeight: BN;

export declare type FundingSettings = {
lowFundingFnA: Numeric;
lowFundingFnB: Numeric;
highFundingFnA: Numeric;
highFundingFnB: Numeric;
inflectionPoint: Numeric;
};
export declare function getAdjustedAmmState(amm: AmmState, terminalPrice: BN): AmmState;

@@ -51,0 +61,0 @@

548

dist/dex-math.js

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

var xe = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i, we = Math.ceil, Z = Math.floor, b = "[BigNumber Error] ", Oe = b + "Number primitive has more than 15 significant digits: ", ee = 1e14, R = 14, Ne = 9007199254740991, Ee = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13], se = 1e7, U = 1e9;
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, E, p = d.prototype = { constructor: d, toString: null, valueOf: null }, P = new d(1), O = 20, N = 4, _ = -7, M = 21, L = -1e7, q = 1e7, k = !1, Q = 1, G = 0, X = {
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 = {
prefix: "",

@@ -13,3 +13,3 @@ groupSize: 3,

suffix: ""
}, $ = "0123456789abcdefghijklmnopqrstuvwxyz", re = !0;
}, $ = "0123456789abcdefghijklmnopqrstuvwxyz", se = !0;
function d(e, t) {

@@ -21,3 +21,3 @@ var n, u, r, o, l, i, s, a, f = this;

if (e && e._isBigNumber === !0) {
f.s = e.s, !e.c || e.e > q ? f.c = f.e = null : e.e < L ? f.c = [f.e = 0] : (f.e = e.e, f.c = e.c.slice());
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());
return;

@@ -35,3 +35,3 @@ }

if (!xe.test(a = String(e)))
return E(f, a, i);
return N(f, a, i);
f.s = a.charCodeAt(0) == 45 ? (a = a.slice(1), -1) : 1;

@@ -41,9 +41,9 @@ }

} else {
if (D(t, 2, $.length, "Base"), t == 10 && re)
return f = new d(e), W(f, O + f.e + 1, N);
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") {
if (e * 0 != 0)
return E(f, a, i, t);
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)
throw Error(Oe + e);
throw Error(Ee + e);
} else

@@ -62,3 +62,3 @@ f.s = a.charCodeAt(0) === 45 ? (a = a.slice(1), -1) : 1;

}
return E(f, String(e), i, t);
return N(f, String(e), i, t);
}

@@ -72,13 +72,13 @@ i = !1, a = v(a, t, 10, f.s), (o = a.indexOf(".")) > -1 ? a = a.replace(".", "") : o = a.length;

if (a = a.slice(l, ++s)) {
if (s -= l, i && d.DEBUG && s > 15 && (e > Ne || e !== Z(e)))
throw Error(Oe + f.s * e);
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 < L)
else if (o < T)
f.c = [f.e = 0];
else {
if (f.e = o, f.c = [], l = (o + 1) % R, o < 0 && (l += R), l < s) {
for (l && f.c.push(+a.slice(0, l)), s -= R; l < s; )
f.c.push(+a.slice(l, l += R));
l = R - (a = a.slice(l)).length;
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;
} else

@@ -97,7 +97,7 @@ l -= s;

if (typeof e == "object") {
if (e.hasOwnProperty(t = "DECIMAL_PLACES") && (n = e[t], D(n, 0, U, t), O = n), e.hasOwnProperty(t = "ROUNDING_MODE") && (n = e[t], D(n, 0, 8, t), N = n), e.hasOwnProperty(t = "EXPONENTIAL_AT") && (n = e[t], n && n.pop ? (D(n[0], -U, 0, t), D(n[1], 0, U, t), _ = n[0], M = n[1]) : (D(n, -U, U, t), _ = -(M = 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], I = n[1]) : (F(n, -U, U, t), _ = -(I = n < 0 ? -n : n))), e.hasOwnProperty(t = "RANGE"))
if (n = e[t], n && n.pop)
D(n[0], -U, -1, t), D(n[1], 1, U, t), L = n[0], q = n[1];
else if (D(n, -U, U, t), n)
L = -(q = n < 0 ? -n : n);
F(n[0], -U, -1, t), F(n[1], 1, U, t), T = n[0], q = n[1];
else if (F(n, -U, U, t), n)
T = -(q = n < 0 ? -n : n);
else

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

throw Error(b + t + " not true or false: " + n);
if (e.hasOwnProperty(t = "MODULO_MODE") && (n = e[t], D(n, 0, 9, t), Q = n), e.hasOwnProperty(t = "POW_PRECISION") && (n = e[t], D(n, 0, U, t), G = n), e.hasOwnProperty(t = "FORMAT"))
if (e.hasOwnProperty(t = "MODULO_MODE") && (n = e[t], F(n, 0, 9, t), Q = n), e.hasOwnProperty(t = "POW_PRECISION") && (n = e[t], F(n, 0, U, t), G = n), e.hasOwnProperty(t = "FORMAT"))
if (n = e[t], typeof n == "object")

@@ -124,3 +124,3 @@ X = n;

if (n = e[t], typeof n == "string" && !/^.?$|[+\-.\s]|(.).*\1/.test(n))
re = n.slice(0, 10) == "0123456789", $ = n;
se = n.slice(0, 10) == "0123456789", $ = n;
else

@@ -131,6 +131,6 @@ throw Error(b + t + " invalid: " + n);

return {
DECIMAL_PLACES: O,
ROUNDING_MODE: N,
EXPONENTIAL_AT: [_, M],
RANGE: [L, q],
DECIMAL_PLACES: E,
ROUNDING_MODE: O,
EXPONENTIAL_AT: [_, I],
RANGE: [T, q],
CRYPTO: k,

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

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

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

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

@@ -175,3 +175,3 @@ if (n !== 0)

var e = 9007199254740992, t = Math.random() * e & 2097151 ? function() {
return Z(Math.random() * e);
return K(Math.random() * e);
} : function() {

@@ -181,4 +181,4 @@ 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(P);
if (n == null ? n = O : D(n, 0, U), l = we(n / R), k)
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)
if (crypto.getRandomValues) {

@@ -197,3 +197,3 @@ for (u = crypto.getRandomValues(new Uint32Array(l *= 2)); s < l; )

i = t(), i < 9e15 && (a[s++] = i % 1e14);
for (l = a[--s], n %= R, l && n && (i = Ee[R - n], a[s] = Z(l / i) * i); a[s] === 0; a.pop(), s--)
for (l = a[--s], n %= P, l && n && (i = Oe[P - n], a[s] = K(l / i) * i); a[s] === 0; a.pop(), s--)
;

@@ -203,7 +203,7 @@ if (s < 0)

else {
for (o = -1; a[0] === 0; a.splice(0, 1), o -= R)
for (o = -1; a[0] === 0; a.splice(0, 1), o -= P)
;
for (s = 1, i = a[0]; i >= 10; i /= 10, s++)
;
s < R && (o -= R - s);
s < P && (o -= P - s);
}

@@ -228,21 +228,21 @@ return f.e = o, f.c = a, f;

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

@@ -255,5 +255,5 @@ n = ie(n, a, i.charAt(0));

function e(u, r, o) {
var l, i, s, a, f = 0, h = u.length, m = r % se, A = r / se | 0;
var l, i, s, a, f = 0, h = u.length, m = r % oe, w = r / oe | 0;
for (u = u.slice(); h--; )
s = u[h] % se, a = u[h] / se | 0, l = A * s + a * m, i = m * s + l % se * se + f, f = (i / o | 0) + (l / se | 0) + A * a, u[h] = i % o;
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;

@@ -280,42 +280,42 @@ }

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

@@ -325,7 +325,7 @@ }();

var r, o, l, i, s;
if (n == null ? n = N : D(n, 0, 8), !e.c)
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 = K(e.c), s = u == 1 || u == 2 && (l <= _ || l >= M) ? pe(s, l) : ie(s, l, "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 <= _)) {
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 <= _)) {
for (; i < t; s += "0", i++)

@@ -345,3 +345,3 @@ ;

for (var n, u, r = 1, o = new d(e[0]); r < e.length; r++)
u = new d(e[r]), (!u.s || (n = ue(o, u)) === t || n === 0 && o.s === t) && (o = u);
u = new d(e[r]), (!u.s || (n = ce(o, u)) === t || n === 0 && o.s === t) && (o = u);
return o;

@@ -354,5 +354,5 @@ }

;
return (n = u + n * R - 1) > q ? e.c = e.e = null : n < L ? e.c = [e.e = 0] : (e.e = n, e.c = t), e;
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;
}
E = /* @__PURE__ */ function() {
N = /* @__PURE__ */ function() {
var e = /^(-?)0([xbo])(?=\w[\w.]*$)/i, t = /^([^.]+)\.$/, n = /^\.([^.]+)$/, u = /^-?(Infinity|NaN)$/, r = /^\s*\+(?=[\w.])|^\s+|\s+$/g;

@@ -364,4 +364,4 @@ return function(o, l, i, s) {

else {
if (!i && (f = f.replace(e, function(h, m, A) {
return a = (A = A.toLowerCase()) == "x" ? 16 : A == "b" ? 2 : 8, !s || s == a ? m : h;
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))

@@ -377,3 +377,3 @@ return new d(f, a);

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

@@ -384,8 +384,8 @@ e: {

if (o = t - r, o < 0)
o += R, l = t, s = h[a = 0], f = Z(s / m[r - l - 1] % 10);
else if (a = we((o + 1) / R), a >= h.length)
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)
if (u) {
for (; h.length <= a; h.push(0))
;
s = f = 0, r = 1, o %= R, l = o - R + 1;
s = f = 0, r = 1, o %= P, l = o - P + 1;
} else

@@ -396,3 +396,3 @@ break e;

;
o %= R, l = o - R + r, f = l < 0 ? 0 : Z(s / m[r - l - 1] % 10);
o %= P, l = o - P + r, f = l < 0 ? 0 : K(s / m[r - l - 1] % 10);
}

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

(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[(R - t % R) % R], 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[R - o], h[a] = l > 0 ? Z(s / m[r - l] % m[l]) * i : 0), u)
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)
for (; ; )

@@ -423,9 +423,9 @@ if (a == 0) {

}
e.e > q ? e.c = e.e = null : e.e < L && (e.c = [e.e = 0]);
e.e > q ? e.c = e.e = null : e.e < T && (e.c = [e.e = 0]);
}
return e;
}
function F(e) {
function C(e) {
var t, n = e.e;
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);
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);
}

@@ -436,10 +436,10 @@ return p.absoluteValue = p.abs = function() {

}, p.comparedTo = function(e, t) {
return ue(this, new d(e, t));
return ce(this, new d(e, t));
}, p.decimalPlaces = p.dp = function(e, t) {
var n, u, r, o = this;
if (e != null)
return D(e, 0, U), t == null ? t = N : D(t, 0, 8), W(new d(o), e + o.e + 1, t);
return F(e, 0, U), t == null ? t = O : F(t, 0, 8), W(new d(o), e + o.e + 1, t);
if (!(n = o.c))
return null;
if (u = ((r = n.length - 1) - j(this.e / R)) * R, r = n[r])
if (u = ((r = n.length - 1) - j(this.e / P)) * P, r = n[r])
for (; r % 10 == 0; r /= 10, u--)

@@ -449,3 +449,3 @@ ;

}, p.dividedBy = p.div = function(e, t) {
return g(this, new d(e, t), O, N);
return g(this, new d(e, t), E, O);
}, p.dividedToIntegerBy = p.idiv = function(e, t) {

@@ -456,5 +456,5 @@ return g(this, new d(e, t), 0, 1);

if (e = new d(e), e.c && !e.isInteger())
throw Error(b + "Exponent not an integer: " + F(e));
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(+F(h), i ? e.s * (2 - ge(e)) : +F(e))), t ? f.mod(t) : f;
return f = new d(Math.pow(+C(h), i ? e.s * (2 - ge(e)) : +C(e))), t ? f.mod(t) : f;
if (s = e.s < 0, t) {

@@ -467,5 +467,5 @@ 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 = we(G / R + 2));
G && (o = Ae(G / P + 2));
}
for (i ? (n = new d(0.5), s && (e.s = 1), a = ge(e)) : (r = Math.abs(+F(e)), a = r % 2), f = new d(P); ; ) {
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) {

@@ -477,3 +477,3 @@ if (f = f.times(h), !f.c)

if (r) {
if (r = Z(r / 2), r === 0)
if (r = K(r / 2), r === 0)
break;

@@ -484,3 +484,3 @@ a = r % 2;

else {
if (r = +F(e), r === 0)
if (r = +C(e), r === 0)
break;

@@ -491,20 +491,20 @@ a = r % 2;

}
return u ? f : (s && (f = P.div(f)), t ? f.mod(t) : o ? W(f, G, N, l) : f);
return u ? f : (s && (f = R.div(f)), t ? f.mod(t) : o ? W(f, G, O, l) : f);
}, p.integerValue = function(e) {
var t = new d(this);
return e == null ? e = N : D(e, 0, 8), W(t, t.e + 1, e);
return e == null ? e = O : F(e, 0, 8), W(t, t.e + 1, e);
}, p.isEqualTo = p.eq = function(e, t) {
return ue(this, new d(e, t)) === 0;
return ce(this, new d(e, t)) === 0;
}, p.isFinite = function() {
return !!this.c;
}, p.isGreaterThan = p.gt = function(e, t) {
return ue(this, new d(e, t)) > 0;
return ce(this, new d(e, t)) > 0;
}, p.isGreaterThanOrEqualTo = p.gte = function(e, t) {
return (t = ue(this, new d(e, t))) === 1 || t === 0;
return (t = ce(this, new d(e, t))) === 1 || t === 0;
}, p.isInteger = function() {
return !!this.c && j(this.e / R) > this.c.length - 2;
return !!this.c && j(this.e / P) > this.c.length - 2;
}, p.isLessThan = p.lt = function(e, t) {
return ue(this, new d(e, t)) < 0;
return ce(this, new d(e, t)) < 0;
}, p.isLessThanOrEqualTo = p.lte = function(e, t) {
return (t = ue(this, new d(e, t))) === -1 || t === 0;
return (t = ce(this, new d(e, t))) === -1 || t === 0;
}, p.isNaN = function() {

@@ -524,3 +524,3 @@ return !this.s;

return e.s = -t, l.plus(e);
var s = l.e / R, a = e.e / R, f = l.c, h = e.c;
var s = l.e / P, a = e.e / P, f = l.c, h = e.c;
if (!s || !a) {

@@ -532,3 +532,3 @@ if (!f || !h)

// IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity
N == 3 ? -0 : 0
O == 3 ? -0 : 0
));

@@ -559,3 +559,3 @@ }

;
return f[0] ? ne(e, f, a) : (e.s = N == 3 ? -1 : 1, e.c = [e.e = 0], e);
return f[0] ? ne(e, f, a) : (e.s = O == 3 ? -1 : 1, e.c = [e.e = 0], e);
}, p.modulo = p.mod = function(e, t) {

@@ -565,10 +565,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, A, B, T, C, 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))
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))
;
for (T = ee, C = se, r = h; --r >= 0; ) {
for (n = 0, m = y[r] % C, A = y[r] / C | 0, l = s, o = r + l; o > r; )
a = I[--l] % C, f = I[l] / C | 0, i = A * a + f * m, a = m * a + i % C * C + B[o] + n, n = (a / T | 0) + (i / C | 0) + A * f, B[o--] = a % T;
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;
B[o] = n;

@@ -586,3 +586,3 @@ }

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

@@ -605,6 +605,6 @@ if (!i || !s)

if (e != null && e !== !!e)
return D(e, 1, U), t == null ? t = N : D(t, 0, 8), W(new d(o), e, t);
return F(e, 1, U), t == null ? t = O : F(t, 0, 8), W(new d(o), e, t);
if (!(n = o.c))
return null;
if (r = n.length - 1, u = r * R + 1, r = n[r]) {
if (r = n.length - 1, u = r * P + 1, r = n[r]) {
for (; r % 10 == 0; r /= 10, u--)

@@ -617,12 +617,12 @@ ;

}, p.shiftedBy = function(e) {
return D(e, -Ne, Ne), this.times("1e" + e);
return F(e, -Ne, Ne), this.times("1e" + e);
}, p.squareRoot = p.sqrt = function() {
var e, t, n, u, r, o = this, l = o.c, i = o.s, s = o.e, a = O + 4, f = new d("0.5");
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(+F(o)), i == 0 || i == 1 / 0 ? (t = K(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]) {
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))), K(r.c).slice(0, i) === (t = K(n.c)).slice(0, i))
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))
if (n.e < s && --i, t = t.slice(i - 3, i + 1), t == "9999" || !u && t == "4999") {
if (!u && (W(r, r.e + O + 2, 0), r.times(r).eq(o))) {
if (!u && (W(r, r.e + E + 2, 0), r.times(r).eq(o))) {
n = r;

@@ -633,11 +633,11 @@ break;

} else {
(!+t || !+t.slice(1) && t.charAt(0) == "5") && (W(n, n.e + O + 2, 1), e = !n.times(n).eq(o));
(!+t || !+t.slice(1) && t.charAt(0) == "5") && (W(n, n.e + E + 2, 1), e = !n.times(n).eq(o));
break;
}
}
return W(n, n.e + O + 1, N, e);
return W(n, n.e + E + 1, O, e);
}, p.toExponential = function(e, t) {
return e != null && (D(e, 0, U), e++), H(this, e, t, 1);
return e != null && (F(e, 0, U), e++), H(this, e, t, 1);
}, p.toFixed = function(e, t) {
return e != null && (D(e, 0, U), e = e + this.e + 1), H(this, e, t);
return e != null && (F(e, 0, U), e = e + this.e + 1), H(this, e, t);
}, p.toFormat = function(e, t, n) {

@@ -650,7 +650,7 @@ var u, r = this;

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, A = m ? f.slice(1) : f, B = A.length;
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;
if (s && (o = i, i = s, s = o, B -= o), i > 0 && B > 0) {
for (o = B % i || i, f = A.substr(0, o); o < B; o += i)
f += a + A.substr(o, i);
s > 0 && (f += a + A.slice(o)), m && (f = "-" + f);
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);
}

@@ -664,21 +664,21 @@ u = h ? f + (n.decimalSeparator || "") + ((s = +n.fractionGroupSize) ? h.replace(

}, p.toFraction = function(e) {
var t, n, u, r, o, l, i, s, a, f, h, m, A = this, B = A.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: ") + F(i));
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)))
throw Error(b + "Argument " + (i.isInteger() ? "out of range: " : "not an integer: ") + C(i));
if (!B)
return new d(A);
for (t = new d(P), a = n = new d(P), u = s = new d(P), m = K(B), o = t.e = m.length - A.e - 1, t.c[0] = Ee[(l = o % R) < 0 ? R + 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; )
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 = A.s, o = o * 2, h = g(a, u, o, N).minus(A).abs().comparedTo(
g(s, n, o, N).minus(A).abs()
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(
g(s, n, o, O).minus(w).abs()
) < 1 ? [a, u] : [s, n], q = l, h;
}, p.toNumber = function() {
return +F(this);
return +C(this);
}, p.toPrecision = function(e, t) {
return e != null && D(e, 1, U), H(this, e, t, 2);
return e != null && F(e, 1, U), H(this, e, t, 2);
}, p.toString = function(e) {
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 >= M ? pe(K(n.c), r) : ie(K(n.c), r, "0") : e === 10 && re ? (n = W(new d(n), O + r + 1, N), t = ie(K(n.c), n.e, "0")) : (D(e, 2, $.length, "Base"), t = v(ie(K(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 >= 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;
}, p.valueOf = p.toJSON = function() {
return F(this);
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;

@@ -690,36 +690,36 @@ }

}
function K(c) {
for (var g, v, E = 1, p = c.length, P = c[0] + ""; E < p; ) {
for (g = c[E++] + "", v = R - g.length; v--; g = "0" + g)
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)
;
P += g;
R += g;
}
for (p = P.length; P.charCodeAt(--p) === 48; )
for (p = R.length; R.charCodeAt(--p) === 48; )
;
return P.slice(0, p + 1 || 1);
return R.slice(0, p + 1 || 1);
}
function ue(c, g) {
var v, E, p = c.c, P = g.c, O = c.s, N = g.s, _ = c.e, M = g.e;
if (!O || !N)
function ce(c, g) {
var v, N, p = c.c, R = g.c, E = c.s, O = g.s, _ = c.e, I = g.e;
if (!E || !O)
return null;
if (v = p && !p[0], E = P && !P[0], v || E)
return v ? E ? 0 : -N : O;
if (O != N)
return O;
if (v = O < 0, E = _ == M, !p || !P)
return E ? 0 : !p ^ v ? 1 : -1;
if (!E)
return _ > M ^ v ? 1 : -1;
for (N = (_ = p.length) < (M = P.length) ? _ : M, O = 0; O < N; O++)
if (p[O] != P[O])
return p[O] > P[O] ^ v ? 1 : -1;
return _ == M ? 0 : _ > M ^ v ? 1 : -1;
if (v = p && !p[0], N = R && !R[0], v || N)
return v ? N ? 0 : -O : E;
if (E != O)
return E;
if (v = E < 0, N = _ == I, !p || !R)
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;
}
function D(c, g, v, E) {
if (c < g || c > v || c !== Z(c))
throw Error(b + (E || "Argument") + (typeof c == "number" ? c < g || c > v ? " out of range: " : " not an integer: " : " not a primitive number: ") + String(c));
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 ge(c) {
var g = c.c.length - 1;
return j(c.e / R) == g && c.c[g] % 2 != 0;
return j(c.e / P) == g && c.c[g] % 2 != 0;
}

@@ -730,3 +730,3 @@ function pe(c, g) {

function ie(c, g, v) {
var E, p;
var N, p;
if (g < 0) {

@@ -736,22 +736,34 @@ for (p = v + "."; ++g; p += v)

c = p + c;
} else if (E = c.length, ++g > E) {
for (p = v, g -= E; --g; p += v)
} else if (N = c.length, ++g > N) {
for (p = v, g -= N; --g; p += v)
;
c += p;
} else
g < E && (c = c.slice(0, g) + "." + c.slice(g));
g < N && (c = c.slice(0, g) + "." + c.slice(g));
return c;
}
var ce = Pe();
const ae = new ce(0), Be = 9, S = w(w(10).pow(Be));
function w(c) {
return new ce(c);
var re = Pe();
const ae = new re(0), Be = 9, S = A(A(10).pow(Be));
function A(c) {
return new re(c);
}
function oe(c) {
return new ce(c).integerValue().toNumber();
function ue(c) {
return new re(c).integerValue().toNumber();
}
function Le(c) {
return oe(c) / 1e9;
function Te(c) {
return ue(c) / 1e9;
}
var Me = /* @__PURE__ */ ((c) => (c[c.Plain = 1] = "Plain", c[c.JIT = 2] = "JIT", c))(Me || {}), Ie = /* @__PURE__ */ ((c) => (c[c.direct = 1] = "direct", c[c.indirect = 2] = "indirect", c))(Ie || {}), _e = /* @__PURE__ */ ((c) => (c.base = "base", c.coinm = "coinm", c.prelaunch = "prelaunch", c))(_e || {});
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);
}
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);
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));
return N.isNegative() && (E = E.negated()), E;
}
function qe(c, g) {

@@ -763,12 +775,12 @@ return {

}
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 De(c, g) {
const v = w(c.baseAssetReserve).div(S), E = w(c.totalPositionSize).div(S), p = w(c.quoteAssetReserve).div(S), P = g.div(S), O = p.times(v), N = v.plus(E), M = O.div(N).div(N);
return P.div(M).times(S);
}
function Te(c, g) {
if (w(c.totalPositionSize).eq(ae)) {
if (A(c.totalPositionSize).eq(ae)) {
const { quoteAssetWeight: v } = qe(c, g);
return { ...c, quoteAssetReserveWeight: v };
} else {
const v = De(c, g);
const v = Fe(c, g);
return { ...c, quoteAssetReserveWeight: v };

@@ -778,105 +790,102 @@ }

function Ce(c, g, v = 1) {
return w(c).times(g).times(v).div(S);
return A(c).times(g).times(v).div(S);
}
function Re(c) {
return w(c.openNotional).div(c.size).abs();
return A(c.openNotional).div(c.size).abs();
}
function Fe(c) {
const { leverage: g, feeRate: v, amount: E, decimals: p = S } = c, P = w(E), O = w(g).times(v), N = P.div(w(p).plus(O).div(p));
return P.abs().minus(N.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 de(c, g) {
const v = w(c.size).gt(0) ? g.latestLongPremiumFraction : g.latestShortPremiumFraction;
return w(v).minus(c.fraction).times(c.size).div(S).negated();
const v = A(c.size).gt(0) ? g.latestLongPremiumFraction : g.latestShortPremiumFraction;
return A(v).minus(c.fraction).times(c.size).div(S).negated();
}
function le(c, g = S) {
return w(c.quoteAssetReserve).times(c.quoteAssetReserveWeight).div(w(c.baseAssetReserve).times(g)).times(g);
}
function Ue(c) {
const g = Te(
function ke(c) {
const g = De(
{
...c,
totalPositionSize: w(c.totalPositionSize).negated()
totalPositionSize: A(c.totalPositionSize).negated()
},
le(c)
fe(c)
);
return le(g);
return fe(g);
}
function ze(c, g = 1) {
return w(c.openNotional).div(c.margin).div(g);
function Le(c, g = 1) {
return A(c.openNotional).div(c.margin).div(g);
}
function ve(c, g, v = {}) {
const { blockTimestamp: E = /* @__PURE__ */ new Date(), decimals: p = S } = v, P = Math.floor(
(E.getTime() - c.timestamp.getTime()) / 1e3 / 60
const { blockTimestamp: N = /* @__PURE__ */ new Date(), decimals: p = S } = v, R = Math.floor(
(N.getTime() - c.timestamp.getTime()) / 1e3 / 60
);
return w(c.margin).times(P).times(w(g.rolloverFee).div(p)).div(525600);
return A(c.margin).times(R).times(A(g.rolloverFee).div(p)).div(525600);
}
function ke(c, g, v, E = 1, p = {}) {
const { isSettleBySpotPrice: P = !1 } = p, O = w(c.openNotional).div(S), N = w(v.maintenanceMarginRatio).div(S), _ = w(g.quoteAssetReserve).div(S), M = w(g.baseAssetReserve).div(S), L = w(g.totalPositionSize).div(S), q = w(c.margin).div(S), k = w(c.size).div(S), Q = de(c, g).div(S), G = ve(c, v, p).div(S), X = ze(c, E).decimalPlaces(9), $ = Q, re = G, d = q, H = _, J = M, ne = L, W = k;
let F = w(E), e = N;
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;
let C = A(N), e = O;
const t = J.div(J.plus(W)).gt(1);
if (X.eq(1))
return t ? Re(c).div(N).times(S) : Re(c).times(N).times(S);
return t ? Re(c).div(O).times(S) : Re(c).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(re).plus(d);
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 = O, i = e.plus(1)) : (l = O.negated(), i = e.minus(1).negated()), P && (F = l.times(u).div(i.abs().times(r).minus(o.times(u)))), l.plus(o.times(F)).div(i).div(r).times(u).times(S).abs();
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();
}
function Se(c, g, v = S) {
const E = w(c.baseAssetReserve).div(v), p = w(g).div(v), P = w(c.quoteAssetReserve).div(v), O = w(c.quoteAssetReserveWeight).div(v), N = P.times(E), _ = ce.max(E.plus(p), 1e-8), M = N.div(_), q = M.minus(P).times(O).times(v), k = le(c, v), Q = q.abs().div(g).times(v).abs(), G = k.minus(Q).abs(), X = 1 - Q.dividedBy(Q.plus(G)).toNumber();
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();
return {
quoteAssetOutput: q,
baseAssetAfter: _.times(v),
quoteAssetAfter: M.times(v),
quoteAssetAfter: I.times(v),
priceImpact: X
};
}
function Qe(c, g, v, E = 1, p = {}) {
const P = de(c, g), O = ve(c, v, p), { quoteAssetOutput: N } = Se(g, c.size), L = (N.gt(ae) ? w(c.openNotional).minus(N.integerValue()) : w(c.openNotional).plus(N.integerValue()).negated()).div(E).plus(P).minus(O).plus(c.margin), q = N.abs();
return L.times(E).div(q).times(p.decimals ?? S);
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 We(c) {
return c ? Math.floor(1 / w(c.initMarginRatio).div(S).toNumber()) : 0;
function Ge(c) {
return c ? Math.floor(1 / A(c.initMarginRatio).div(S).toNumber()) : 0;
}
function Ge(c, g = S) {
function ye(c, g = S) {
return c ? Math.max(
1,
w(1 / w(c.minInitMarginRatio).div(g).toNumber()).integerValue(ce.ROUND_UP).toNumber()
A(1 / A(c.minInitMarginRatio).div(g).toNumber()).integerValue(re.ROUND_UP).toNumber()
) : 1;
}
function ye(c, g, v, E, p = 1, P = {}) {
const { isSettleBySpotPrice: O = !1 } = P, N = w(g.openNotional).div(S), _ = w(v.quoteAssetReserve).div(S), M = w(v.baseAssetReserve).div(S), L = w(v.totalPositionSize).div(S), q = w(g.margin).div(S), k = w(g.size).div(S), Q = de(g, v).div(S), G = ve(g, E, P).div(S), X = Q, $ = G, re = q, d = _, H = M, J = L, ne = k, W = w(c);
let F = w(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(re), l = re.times(F).times(W), i = N;
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);
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;
if (e) {
O && (F = i.minus(l).div(u.abs().div(n).minus(r)));
const s = i.minus(l).plus(r.times(F)).div(u.abs()).times(n);
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);
return s.lte(0) ? ae : s.times(S);
} else
return O && (F = i.plus(l).div(u.abs().div(n).plus(r))), i.plus(l).minus(r.times(F)).div(u.abs()).times(n).times(S);
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);
}
function Ve(c, g) {
return w(g).minus(c).div(c).abs();
function be(c, g) {
return A(g).minus(c).div(c).abs();
}
function be(c) {
const g = le(c), v = g.plus(c.indexPrice).div(2);
return w(c.indexPrice).minus(g).abs().div(v);
function $e(c) {
const g = fe(c), v = g.plus(c.indexPrice).div(2);
return A(c.indexPrice).minus(g).abs().div(v);
}
function $e(c, g, v, E = 1, p = {}) {
const P = de(c, g), O = ve(c, v, p), { quoteAssetOutput: N } = Se(g, c.size), M = (N.gt(ae) ? w(c.openNotional).minus(N.integerValue()) : w(c.openNotional).plus(N.integerValue()).negated()).div(E), L = M.plus(P).minus(O).plus(c.margin), q = N.abs(), k = L.times(E).div(q).times(p.decimals ?? S);
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);
return {
remainMargin: oe(L),
marginRatio: oe(k),
positionNotional: oe(q),
fundingPayment: oe(P),
rolloverFee: oe(O),
unrealizedPnl: oe(M),
badDebt: oe(ce.min(0, L))
remainMargin: ue(T),
marginRatio: ue(k),
positionNotional: ue(q),
fundingPayment: ue(R),
rolloverFee: ue(E),
unrealizedPnl: ue(I),
badDebt: ue(re.min(0, T))
};
}
function He(c, g, v = S) {
const E = w(c.baseAssetReserve).div(v), p = w(g).div(c.quoteAssetReserveWeight), P = w(c.quoteAssetReserve).div(v), O = E.times(P), N = P.plus(p), M = O.div(N).minus(E), L = M.times(v), q = E.plus(M).times(v), k = N.times(v), Q = le(c, v), G = w(g).abs().div(L.abs()).times(v), X = Q.minus(G).abs(), $ = 1 - Q.dividedBy(Q.plus(X)).toNumber();
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();
return {
baseAssetOutput: L,
baseAssetOutput: T,
baseAssetAfter: q,

@@ -891,30 +900,31 @@ quoteAssetAfter: k,

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