@swapkit/helpers 1.0.0-rc.51 → 1.0.0-rc.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js
CHANGED
|
@@ -35,17 +35,17 @@ const Tt = "0x313ce567", nt = async ({ chain: r, to: t }) => {
|
|
|
35
35
|
return h.ETH;
|
|
36
36
|
const [, t] = r.split("-");
|
|
37
37
|
return t != null && t.startsWith("0x") ? nt({ chain: o.Ethereum, to: t }) : h.ETH;
|
|
38
|
-
},
|
|
38
|
+
}, St = async (r) => {
|
|
39
39
|
const [, t] = r.split("-");
|
|
40
40
|
return t != null && t.startsWith("0x") ? nt({ chain: o.Avalanche, to: t.toLowerCase() }) : h.AVAX;
|
|
41
|
-
},
|
|
41
|
+
}, Rt = async (r) => r === o.BinanceSmartChain ? h.BSC : h.BSC, Ct = async ({ chain: r, symbol: t }) => {
|
|
42
42
|
switch (r) {
|
|
43
43
|
case o.Ethereum:
|
|
44
44
|
return $t(t);
|
|
45
45
|
case o.Avalanche:
|
|
46
|
-
return Rt(t);
|
|
47
|
-
case o.BinanceSmartChain:
|
|
48
46
|
return St(t);
|
|
47
|
+
case o.BinanceSmartChain:
|
|
48
|
+
return Rt(t);
|
|
49
49
|
default:
|
|
50
50
|
return h[r];
|
|
51
51
|
}
|
|
@@ -636,12 +636,14 @@ const U = (r) => {
|
|
|
636
636
|
throw new Error(
|
|
637
637
|
`Invalid identifier: ${r}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
638
638
|
);
|
|
639
|
-
}, C = 8, w = (r) => 10n ** BigInt(r),
|
|
639
|
+
}, C = 8, w = (r) => 10n ** BigInt(r), S = (r) => Math.log10(parseFloat(r.toString()));
|
|
640
640
|
function k({
|
|
641
641
|
value: r,
|
|
642
642
|
bigIntDecimal: t = C,
|
|
643
643
|
decimal: e = C
|
|
644
644
|
}) {
|
|
645
|
+
if (e === 0)
|
|
646
|
+
return r.toString();
|
|
645
647
|
const s = r < 0n;
|
|
646
648
|
let n = r.toString().substring(s ? 1 : 0);
|
|
647
649
|
const i = e - (n.length - 1);
|
|
@@ -653,7 +655,7 @@ function k({
|
|
|
653
655
|
""
|
|
654
656
|
);
|
|
655
657
|
}
|
|
656
|
-
var v,
|
|
658
|
+
var v, R, y, $, P, dt, O, F, E, W;
|
|
657
659
|
const K = class K {
|
|
658
660
|
constructor(t) {
|
|
659
661
|
T(this, v);
|
|
@@ -687,16 +689,16 @@ const K = class K {
|
|
|
687
689
|
return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
|
|
688
690
|
}
|
|
689
691
|
add(...t) {
|
|
690
|
-
return m(this, v,
|
|
692
|
+
return m(this, v, R).call(this, "add", ...t);
|
|
691
693
|
}
|
|
692
694
|
sub(...t) {
|
|
693
|
-
return m(this, v,
|
|
695
|
+
return m(this, v, R).call(this, "sub", ...t);
|
|
694
696
|
}
|
|
695
697
|
mul(...t) {
|
|
696
|
-
return m(this, v,
|
|
698
|
+
return m(this, v, R).call(this, "mul", ...t);
|
|
697
699
|
}
|
|
698
700
|
div(...t) {
|
|
699
|
-
return m(this, v,
|
|
701
|
+
return m(this, v, R).call(this, "div", ...t);
|
|
700
702
|
}
|
|
701
703
|
gt(t) {
|
|
702
704
|
return m(this, y, $).call(this, "gt", t);
|
|
@@ -717,7 +719,7 @@ const K = class K {
|
|
|
717
719
|
getValue(t) {
|
|
718
720
|
const e = this.formatBigIntToSafeValue(
|
|
719
721
|
this.bigIntValue,
|
|
720
|
-
this.decimal ||
|
|
722
|
+
this.decimal || S(this.decimalMultiplier)
|
|
721
723
|
);
|
|
722
724
|
switch (t) {
|
|
723
725
|
case "number":
|
|
@@ -792,7 +794,7 @@ const K = class K {
|
|
|
792
794
|
formatBigIntToSafeValue(t, e) {
|
|
793
795
|
const s = e || this.decimal || C, n = Math.max(
|
|
794
796
|
s,
|
|
795
|
-
|
|
797
|
+
S(this.decimalMultiplier)
|
|
796
798
|
), i = t < 0n, c = t.toString().substring(i ? 1 : 0), a = n - (c.length - 1), u = a > 0 ? "0".repeat(a) + c : c, d = u.length - n;
|
|
797
799
|
let l = u.slice(-n);
|
|
798
800
|
return parseInt(l[s]) >= 5 ? l = `${l.substring(0, s - 1)}${(parseInt(l[s - 1]) + 1).toString()}` : l = l.substring(0, s), `${i ? "-" : ""}${u.slice(
|
|
@@ -801,8 +803,8 @@ const K = class K {
|
|
|
801
803
|
)}.${l}`.replace(/\.?0*$/, "");
|
|
802
804
|
}
|
|
803
805
|
};
|
|
804
|
-
v = new WeakSet(),
|
|
805
|
-
const s = m(this, O, F).call(this, this, ...e), n = Math.max(s,
|
|
806
|
+
v = new WeakSet(), R = function(t, ...e) {
|
|
807
|
+
const s = m(this, O, F).call(this, this, ...e), n = Math.max(s, S(this.decimalMultiplier)), i = w(n), c = e.reduce(
|
|
806
808
|
(u, d) => {
|
|
807
809
|
const l = this.getBigIntValue(d, n);
|
|
808
810
|
switch (t) {
|
|
@@ -852,10 +854,10 @@ v = new WeakSet(), S = function(t, ...e) {
|
|
|
852
854
|
const e = B(t) || "0";
|
|
853
855
|
this.bigIntValue = m(this, E, W).call(this, e);
|
|
854
856
|
}, O = new WeakSet(), F = function(...t) {
|
|
855
|
-
const e = t.map((s) => typeof s == "object" ? s.decimal ||
|
|
857
|
+
const e = t.map((s) => typeof s == "object" ? s.decimal || S(s.decimalMultiplier) : st(B(s))).filter(Boolean);
|
|
856
858
|
return Math.max(...e, C);
|
|
857
859
|
}, E = new WeakSet(), W = function(t, e) {
|
|
858
|
-
const s = e ? w(e) : this.decimalMultiplier, n =
|
|
860
|
+
const s = e ? w(e) : this.decimalMultiplier, n = S(s), [i = "", c = ""] = t.split(".");
|
|
859
861
|
return BigInt(`${i}${c.padEnd(n, "0")}`);
|
|
860
862
|
};
|
|
861
863
|
let I = K;
|