@swapkit/helpers 1.0.0-rc.56 → 1.0.0-rc.57
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.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.es.js +44 -39
- package/dist/index.es.js.map +1 -1
- package/package.json +1 -1
- package/src/modules/assetValue.ts +14 -3
package/dist/index.es.js
CHANGED
|
@@ -10,7 +10,7 @@ var v = (s, t, e) => {
|
|
|
10
10
|
t instanceof WeakSet ? t.add(s) : t.set(s, e);
|
|
11
11
|
};
|
|
12
12
|
var m = (s, t, e) => (wt(s, t, "access private method"), e);
|
|
13
|
-
import { FeeOption as
|
|
13
|
+
import { FeeOption as U, BaseDecimal as d, Chain as o, EVMChainList as At, ChainToRPC as $t, MemoType as _ } from "@swapkit/types";
|
|
14
14
|
const vt = "0x313ce567", nt = async ({ chain: s, to: t }) => {
|
|
15
15
|
try {
|
|
16
16
|
const { result: e } = await Xt.post($t[s], {
|
|
@@ -35,24 +35,24 @@ const vt = "0x313ce567", nt = async ({ chain: s, to: t }) => {
|
|
|
35
35
|
return d.ETH;
|
|
36
36
|
const [, t] = s.split("-");
|
|
37
37
|
return t != null && t.startsWith("0x") ? nt({ chain: o.Ethereum, to: t }) : d.ETH;
|
|
38
|
-
},
|
|
38
|
+
}, Ct = async (s) => {
|
|
39
39
|
const [, t] = s.split("-");
|
|
40
40
|
return t != null && t.startsWith("0x") ? nt({ chain: o.Avalanche, to: t.toLowerCase() }) : d.AVAX;
|
|
41
|
-
},
|
|
41
|
+
}, Rt = async (s) => s === o.BinanceSmartChain ? d.BSC : d.BSC, St = async ({ chain: s, symbol: t }) => {
|
|
42
42
|
switch (s) {
|
|
43
43
|
case o.Ethereum:
|
|
44
44
|
return Tt(t);
|
|
45
45
|
case o.Avalanche:
|
|
46
|
-
return Rt(t);
|
|
47
|
-
case o.BinanceSmartChain:
|
|
48
46
|
return Ct(t);
|
|
47
|
+
case o.BinanceSmartChain:
|
|
48
|
+
return Rt(t);
|
|
49
49
|
default:
|
|
50
50
|
return d[s];
|
|
51
51
|
}
|
|
52
52
|
}, ne = {
|
|
53
|
-
[
|
|
54
|
-
[
|
|
55
|
-
[
|
|
53
|
+
[U.Average]: 1.2,
|
|
54
|
+
[U.Fast]: 1.5,
|
|
55
|
+
[U.Fastest]: 2
|
|
56
56
|
}, it = ({ chain: s, symbol: t }) => {
|
|
57
57
|
switch (s) {
|
|
58
58
|
case o.Bitcoin:
|
|
@@ -359,13 +359,13 @@ const q = (s) => s !== null && typeof s == "object", M = (...s) => {
|
|
|
359
359
|
return s = !0, "half";
|
|
360
360
|
}
|
|
361
361
|
}).headers.has("Content-Type")), s && !t;
|
|
362
|
-
})(), Vt = typeof globalThis.AbortController == "function", kt = typeof globalThis.ReadableStream == "function",
|
|
362
|
+
})(), Vt = typeof globalThis.AbortController == "function", kt = typeof globalThis.ReadableStream == "function", jt = typeof globalThis.FormData == "function", ct = ["get", "post", "put", "patch", "head", "delete"], Nt = {
|
|
363
363
|
json: "application/json",
|
|
364
364
|
text: "text/*",
|
|
365
365
|
formData: "multipart/form-data",
|
|
366
366
|
arrayBuffer: "*/*",
|
|
367
367
|
blob: "*/*"
|
|
368
|
-
},
|
|
368
|
+
}, L = 2147483647, ut = Symbol("stop"), Ht = {
|
|
369
369
|
json: !0,
|
|
370
370
|
parseJson: !0,
|
|
371
371
|
searchParams: !0,
|
|
@@ -392,9 +392,9 @@ const q = (s) => s !== null && typeof s == "object", M = (...s) => {
|
|
|
392
392
|
window: !0,
|
|
393
393
|
dispatcher: !0,
|
|
394
394
|
duplex: !0
|
|
395
|
-
},
|
|
395
|
+
}, Ut = (s) => ct.includes(s) ? s.toUpperCase() : s, Lt = ["get", "put", "head", "delete", "options", "trace"], Ft = [408, 413, 429, 500, 502, 503, 504], lt = [413, 429, 503], Z = {
|
|
396
396
|
limit: 2,
|
|
397
|
-
methods:
|
|
397
|
+
methods: Lt,
|
|
398
398
|
statusCodes: Ft,
|
|
399
399
|
afterStatusCodes: lt,
|
|
400
400
|
maxRetryAfter: Number.POSITIVE_INFINITY,
|
|
@@ -446,8 +446,8 @@ const zt = (s, t) => {
|
|
|
446
446
|
class V {
|
|
447
447
|
static create(t, e) {
|
|
448
448
|
const r = new V(t, e), n = async () => {
|
|
449
|
-
if (typeof r._options.timeout == "number" && r._options.timeout >
|
|
450
|
-
throw new RangeError(`The \`timeout\` option cannot be greater than ${
|
|
449
|
+
if (typeof r._options.timeout == "number" && r._options.timeout > L)
|
|
450
|
+
throw new RangeError(`The \`timeout\` option cannot be greater than ${L}`);
|
|
451
451
|
await Promise.resolve();
|
|
452
452
|
let a = await r._fetch();
|
|
453
453
|
for (const u of r._options.hooks.afterResponse) {
|
|
@@ -469,7 +469,7 @@ class V {
|
|
|
469
469
|
}
|
|
470
470
|
return a;
|
|
471
471
|
}, c = r._options.retry.methods.includes(r.request.method.toLowerCase()) ? r._retry(n) : n();
|
|
472
|
-
for (const [a, u] of Object.entries(
|
|
472
|
+
for (const [a, u] of Object.entries(Nt))
|
|
473
473
|
c[a] = async () => {
|
|
474
474
|
r.request.headers.set("accept", r.request.headers.get("accept") || u);
|
|
475
475
|
const h = (await c).clone();
|
|
@@ -521,7 +521,7 @@ class V {
|
|
|
521
521
|
beforeError: [],
|
|
522
522
|
afterResponse: []
|
|
523
523
|
}, e.hooks),
|
|
524
|
-
method:
|
|
524
|
+
method: Ut(e.method ?? this._input.method),
|
|
525
525
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
526
526
|
prefixUrl: String(e.prefixUrl || ""),
|
|
527
527
|
retry: Wt(e.retry),
|
|
@@ -546,7 +546,7 @@ class V {
|
|
|
546
546
|
}
|
|
547
547
|
if (Pt && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
|
|
548
548
|
const n = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), i = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, n);
|
|
549
|
-
(
|
|
549
|
+
(jt && this._options.body instanceof globalThis.FormData || this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers["content-type"]) && this.request.headers.delete("content-type"), this.request = new globalThis.Request(new globalThis.Request(i, { ...this.request }), this._options);
|
|
550
550
|
}
|
|
551
551
|
this._options.json !== void 0 && (this._options.body = JSON.stringify(this._options.json), this.request.headers.set("content-type", this._options.headers.get("content-type") ?? "application/json"), this.request = new globalThis.Request(this.request, { body: this._options.body }));
|
|
552
552
|
}
|
|
@@ -575,7 +575,7 @@ class V {
|
|
|
575
575
|
try {
|
|
576
576
|
return await t();
|
|
577
577
|
} catch (e) {
|
|
578
|
-
const r = Math.min(this._calculateRetryDelay(e),
|
|
578
|
+
const r = Math.min(this._calculateRetryDelay(e), L);
|
|
579
579
|
if (r !== 0 && this._retryCount > 0) {
|
|
580
580
|
await Yt(r, { signal: this._options.signal });
|
|
581
581
|
for (const n of this._options.hooks.beforeRetry)
|
|
@@ -659,7 +659,7 @@ function Zt(s = "") {
|
|
|
659
659
|
`Invalid identifier: ${s}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
660
660
|
);
|
|
661
661
|
}
|
|
662
|
-
const O = 8, y = (s) => 10n ** BigInt(s),
|
|
662
|
+
const O = 8, y = (s) => 10n ** BigInt(s), C = (s) => Math.log10(parseFloat(s.toString()));
|
|
663
663
|
function k({
|
|
664
664
|
value: s,
|
|
665
665
|
bigIntDecimal: t = O,
|
|
@@ -678,19 +678,19 @@ function k({
|
|
|
678
678
|
""
|
|
679
679
|
);
|
|
680
680
|
}
|
|
681
|
-
var w,
|
|
681
|
+
var w, R, b, T, N, ht, E, G, B, Y;
|
|
682
682
|
const K = class K {
|
|
683
683
|
constructor(t) {
|
|
684
684
|
v(this, w);
|
|
685
685
|
v(this, b);
|
|
686
|
-
v(this,
|
|
686
|
+
v(this, N);
|
|
687
687
|
v(this, E);
|
|
688
688
|
v(this, B);
|
|
689
689
|
f(this, "decimalMultiplier", 10n ** 8n);
|
|
690
690
|
f(this, "bigIntValue", 0n);
|
|
691
691
|
f(this, "decimal");
|
|
692
692
|
const e = z(t), r = typeof t == "object";
|
|
693
|
-
this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier : y(Math.max(rt(x(e)), this.decimal || 0)), m(this,
|
|
693
|
+
this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier : y(Math.max(rt(x(e)), this.decimal || 0)), m(this, N, ht).call(this, e);
|
|
694
694
|
}
|
|
695
695
|
static fromBigInt(t, e) {
|
|
696
696
|
return new K({
|
|
@@ -712,16 +712,16 @@ const K = class K {
|
|
|
712
712
|
return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
|
|
713
713
|
}
|
|
714
714
|
add(...t) {
|
|
715
|
-
return m(this, w,
|
|
715
|
+
return m(this, w, R).call(this, "add", ...t);
|
|
716
716
|
}
|
|
717
717
|
sub(...t) {
|
|
718
|
-
return m(this, w,
|
|
718
|
+
return m(this, w, R).call(this, "sub", ...t);
|
|
719
719
|
}
|
|
720
720
|
mul(...t) {
|
|
721
|
-
return m(this, w,
|
|
721
|
+
return m(this, w, R).call(this, "mul", ...t);
|
|
722
722
|
}
|
|
723
723
|
div(...t) {
|
|
724
|
-
return m(this, w,
|
|
724
|
+
return m(this, w, R).call(this, "div", ...t);
|
|
725
725
|
}
|
|
726
726
|
gt(t) {
|
|
727
727
|
return m(this, b, T).call(this, "gt", t);
|
|
@@ -742,7 +742,7 @@ const K = class K {
|
|
|
742
742
|
getValue(t) {
|
|
743
743
|
const e = this.formatBigIntToSafeValue(
|
|
744
744
|
this.bigIntValue,
|
|
745
|
-
this.decimal ||
|
|
745
|
+
this.decimal || C(this.decimalMultiplier)
|
|
746
746
|
);
|
|
747
747
|
switch (t) {
|
|
748
748
|
case "number":
|
|
@@ -817,7 +817,7 @@ const K = class K {
|
|
|
817
817
|
formatBigIntToSafeValue(t, e) {
|
|
818
818
|
const r = e || this.decimal || O, n = Math.max(
|
|
819
819
|
r,
|
|
820
|
-
|
|
820
|
+
C(this.decimalMultiplier)
|
|
821
821
|
), i = t < 0n, c = t.toString().substring(i ? 1 : 0), a = n - (c.length - 1), u = a > 0 ? "0".repeat(a) + c : c, l = u.length - n;
|
|
822
822
|
let h = u.slice(-n);
|
|
823
823
|
return parseInt(h[r]) >= 5 ? h = `${h.substring(0, r - 1)}${(parseInt(h[r - 1]) + 1).toString()}` : h = h.substring(0, r), `${i ? "-" : ""}${u.slice(
|
|
@@ -826,8 +826,8 @@ const K = class K {
|
|
|
826
826
|
)}.${h}`.replace(/\.?0*$/, "");
|
|
827
827
|
}
|
|
828
828
|
};
|
|
829
|
-
w = new WeakSet(),
|
|
830
|
-
const r = m(this, E, G).call(this, this, ...e), n = Math.max(r,
|
|
829
|
+
w = new WeakSet(), R = function(t, ...e) {
|
|
830
|
+
const r = m(this, E, G).call(this, this, ...e), n = Math.max(r, C(this.decimalMultiplier)), i = y(n), c = e.reduce(
|
|
831
831
|
(u, l) => {
|
|
832
832
|
const h = this.getBigIntValue(l, n);
|
|
833
833
|
switch (t) {
|
|
@@ -873,17 +873,17 @@ w = new WeakSet(), C = function(t, ...e) {
|
|
|
873
873
|
case "eqValue":
|
|
874
874
|
return i === n;
|
|
875
875
|
}
|
|
876
|
-
},
|
|
876
|
+
}, N = new WeakSet(), ht = function(t) {
|
|
877
877
|
const e = x(t) || "0";
|
|
878
878
|
this.bigIntValue = m(this, B, Y).call(this, e);
|
|
879
879
|
}, E = new WeakSet(), G = function(...t) {
|
|
880
|
-
const e = t.map((r) => typeof r == "object" ? r.decimal ||
|
|
880
|
+
const e = t.map((r) => typeof r == "object" ? r.decimal || C(r.decimalMultiplier) : rt(x(r))).filter(Boolean);
|
|
881
881
|
return Math.max(...e, O);
|
|
882
882
|
}, B = new WeakSet(), Y = function(t, e) {
|
|
883
|
-
const r = e ? y(e) : this.decimalMultiplier, n =
|
|
883
|
+
const r = e ? y(e) : this.decimalMultiplier, n = C(r), [i = "", c = ""] = t.split(".");
|
|
884
884
|
return BigInt(`${i}${c.padEnd(n, "0")}`);
|
|
885
885
|
};
|
|
886
|
-
let
|
|
886
|
+
let j = K;
|
|
887
887
|
const te = Intl.NumberFormat("fullwide", {
|
|
888
888
|
useGrouping: !1,
|
|
889
889
|
maximumFractionDigits: 20
|
|
@@ -901,7 +901,7 @@ function z(s) {
|
|
|
901
901
|
return typeof s == "object" ? "getValue" in s ? s.getValue("string") : s.value : s;
|
|
902
902
|
}
|
|
903
903
|
const S = /* @__PURE__ */ new Map();
|
|
904
|
-
class A extends
|
|
904
|
+
class A extends j {
|
|
905
905
|
constructor({
|
|
906
906
|
value: e,
|
|
907
907
|
decimal: r,
|
|
@@ -1026,7 +1026,9 @@ async function F(s, t = 0) {
|
|
|
1026
1026
|
return e || S.set(s.toUpperCase(), { identifier: s, decimal: r }), new A({ decimal: r, value: I(t, r), identifier: s });
|
|
1027
1027
|
}
|
|
1028
1028
|
function st(s, t = 0) {
|
|
1029
|
-
const [e, r] = s.split("/");
|
|
1029
|
+
const [e, r] = s.split(".")[0].toUpperCase() === o.THORChain ? s.split(".").slice(1).join().split("/") : s.split("/");
|
|
1030
|
+
if (!e || !r)
|
|
1031
|
+
throw new Error("Invalid asset identifier");
|
|
1030
1032
|
return new A({
|
|
1031
1033
|
decimal: 8,
|
|
1032
1034
|
value: I(t, 8),
|
|
@@ -1037,7 +1039,10 @@ function I(s, t) {
|
|
|
1037
1039
|
return typeof s == "bigint" ? k({ value: s, bigIntDecimal: t, decimal: t }) : s;
|
|
1038
1040
|
}
|
|
1039
1041
|
function P(s) {
|
|
1040
|
-
const t = s.slice(0, 14).includes("/"), [e, r] = s.split(".").
|
|
1042
|
+
const t = s.slice(0, 14).includes("/"), [e, r] = s.split(".")[0].toUpperCase() === o.THORChain ? s.split(".").slice(1).join().split("/") : s.split("/");
|
|
1043
|
+
if (t && (!e || !r))
|
|
1044
|
+
throw new Error("Invalid asset identifier");
|
|
1045
|
+
const n = s.includes(".") && !t ? s : `${o.THORChain}.${r}`, [i, c] = n.split("."), [a, u] = (t ? r : c).split("-");
|
|
1041
1046
|
return {
|
|
1042
1047
|
address: u == null ? void 0 : u.toLowerCase(),
|
|
1043
1048
|
chain: i,
|
|
@@ -1110,7 +1115,7 @@ class dt extends Error {
|
|
|
1110
1115
|
console.error(e, { stack: e == null ? void 0 : e.stack, message: e == null ? void 0 : e.message }), super(t, { cause: { code: ee[t], message: t } }), Object.setPrototypeOf(this, dt.prototype);
|
|
1111
1116
|
}
|
|
1112
1117
|
}
|
|
1113
|
-
class g extends
|
|
1118
|
+
class g extends j {
|
|
1114
1119
|
eq(t) {
|
|
1115
1120
|
return this.eqValue(t);
|
|
1116
1121
|
}
|
|
@@ -1123,7 +1128,7 @@ class g extends N {
|
|
|
1123
1128
|
}
|
|
1124
1129
|
export {
|
|
1125
1130
|
A as AssetValue,
|
|
1126
|
-
|
|
1131
|
+
j as BigIntArithmetics,
|
|
1127
1132
|
Xt as RequestClient,
|
|
1128
1133
|
dt as SwapKitError,
|
|
1129
1134
|
g as SwapKitNumber,
|