@swapkit/helpers 1.0.0-rc.77 → 1.0.0-rc.79
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.d.ts +8 -0
- package/dist/index.es.js +60 -52
- package/dist/index.es.js.map +1 -1
- package/package.json +6 -6
- package/src/helpers/__tests__/others.test.ts +27 -0
- package/src/helpers/asset.ts +25 -0
package/dist/index.es.js
CHANGED
|
@@ -65,9 +65,9 @@ class pe extends Error {
|
|
|
65
65
|
}), this.name = "TimeoutError", this.request = t;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
const
|
|
68
|
+
const M = (e) => e !== null && typeof e == "object", x = (...e) => {
|
|
69
69
|
for (const t of e)
|
|
70
|
-
if ((!
|
|
70
|
+
if ((!M(t) || Array.isArray(t)) && t !== void 0)
|
|
71
71
|
throw new TypeError("The `options` argument must be an object");
|
|
72
72
|
return se({}, ...e);
|
|
73
73
|
}, me = (e = {}, t = {}) => {
|
|
@@ -80,10 +80,10 @@ const k = (e) => e !== null && typeof e == "object", x = (...e) => {
|
|
|
80
80
|
for (const r of e)
|
|
81
81
|
if (Array.isArray(r))
|
|
82
82
|
Array.isArray(t) || (t = []), t = [...t, ...r];
|
|
83
|
-
else if (
|
|
83
|
+
else if (M(r)) {
|
|
84
84
|
for (let [s, i] of Object.entries(r))
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
M(i) && s in t && (i = se(t[s], i)), t = { ...t, [s]: i };
|
|
86
|
+
M(r.headers) && (n = me(n, r.headers), t.headers = n);
|
|
87
87
|
}
|
|
88
88
|
return t;
|
|
89
89
|
}, He = (() => {
|
|
@@ -97,7 +97,7 @@ const k = (e) => e !== null && typeof e == "object", x = (...e) => {
|
|
|
97
97
|
return e = !0, "half";
|
|
98
98
|
}
|
|
99
99
|
}).headers.has("Content-Type")), e && !t;
|
|
100
|
-
})(), xe = typeof globalThis.AbortController == "function",
|
|
100
|
+
})(), xe = typeof globalThis.AbortController == "function", ke = typeof globalThis.ReadableStream == "function", Me = typeof globalThis.FormData == "function", _e = ["get", "post", "put", "patch", "head", "delete"], Le = {
|
|
101
101
|
json: "application/json",
|
|
102
102
|
text: "text/*",
|
|
103
103
|
formData: "multipart/form-data",
|
|
@@ -201,7 +201,7 @@ class W {
|
|
|
201
201
|
if (r._options.onDownloadProgress) {
|
|
202
202
|
if (typeof r._options.onDownloadProgress != "function")
|
|
203
203
|
throw new TypeError("The `onDownloadProgress` option must be a function");
|
|
204
|
-
if (!
|
|
204
|
+
if (!ke)
|
|
205
205
|
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
|
|
206
206
|
return r._stream(o.clone(), r._options.onDownloadProgress);
|
|
207
207
|
}
|
|
@@ -285,7 +285,7 @@ class W {
|
|
|
285
285
|
}
|
|
286
286
|
if (He && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
|
|
287
287
|
const s = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), i = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, s);
|
|
288
|
-
(
|
|
288
|
+
(Me && 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);
|
|
289
289
|
}
|
|
290
290
|
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 }));
|
|
291
291
|
}
|
|
@@ -548,6 +548,13 @@ const et = "0x313ce567", Ce = async ({ chain: e, to: t }) => {
|
|
|
548
548
|
const s = `${t}.${r}`;
|
|
549
549
|
return !at.test(s) && ct(s) && n !== "0";
|
|
550
550
|
});
|
|
551
|
+
async function bt(e) {
|
|
552
|
+
const t = await import("@swapkit/tokens");
|
|
553
|
+
for (const n of Object.values(t))
|
|
554
|
+
for (const { identifier: r, chain: s, ...i } of n.tokens)
|
|
555
|
+
if ("identifier" in e && r === e.identifier || "address" in i && "chain" in e && s === e.chain && i.address.toLowerCase() === e.contract.toLowerCase())
|
|
556
|
+
return r;
|
|
557
|
+
}
|
|
551
558
|
function ut({
|
|
552
559
|
liquidityUnits: e,
|
|
553
560
|
poolUnits: t,
|
|
@@ -564,7 +571,7 @@ function lt({
|
|
|
564
571
|
const r = m(e), s = m(t), i = m(n), o = r.mul(i), c = s.mul(s).mul(2), a = s.mul(r).mul(2), l = r.mul(r), h = o.mul(c.sub(a).add(l)), N = s.mul(s).mul(s);
|
|
565
572
|
return h.div(N);
|
|
566
573
|
}
|
|
567
|
-
function
|
|
574
|
+
function wt({
|
|
568
575
|
percent: e,
|
|
569
576
|
runeDepth: t,
|
|
570
577
|
liquidityUnits: n,
|
|
@@ -594,7 +601,7 @@ function ht({
|
|
|
594
601
|
runeAmount: m(n).mul(e).div(t)
|
|
595
602
|
};
|
|
596
603
|
}
|
|
597
|
-
function
|
|
604
|
+
function Rt({
|
|
598
605
|
liquidityUnits: e,
|
|
599
606
|
poolUnits: t,
|
|
600
607
|
runeDepth: n,
|
|
@@ -607,7 +614,7 @@ function wt({
|
|
|
607
614
|
)
|
|
608
615
|
);
|
|
609
616
|
}
|
|
610
|
-
function
|
|
617
|
+
function Et({
|
|
611
618
|
runeDepth: e,
|
|
612
619
|
poolUnits: t,
|
|
613
620
|
assetDepth: n,
|
|
@@ -615,13 +622,13 @@ function Rt({
|
|
|
615
622
|
runeAmount: s,
|
|
616
623
|
assetAmount: i
|
|
617
624
|
}) {
|
|
618
|
-
const o = new g({ value: e, decimal: 8 }), c = new g({ value: n, decimal: 8 }), a = new g({ value: t, decimal: 8 }), l = new g({ value: s, decimal: 8 }), h = new g({ value: i, decimal: 8 }), N = l.mul(c), ie = h.mul(o),
|
|
625
|
+
const o = new g({ value: e, decimal: 8 }), c = new g({ value: n, decimal: 8 }), a = new g({ value: t, decimal: 8 }), l = new g({ value: s, decimal: 8 }), h = new g({ value: i, decimal: 8 }), N = l.mul(c), ie = h.mul(o), ye = l.mul(h), Re = o.mul(c), Ee = a.mul(N.add(ie.add(ye.mul(2)))), Pe = N.add(ie.add(Re.mul(2))), oe = Ee.div(Pe), X = m(r).add(oe);
|
|
619
626
|
if (oe.getBaseValue("number") === 0)
|
|
620
627
|
return X.div(a).getBaseValue("number");
|
|
621
628
|
const Oe = a.add(X);
|
|
622
629
|
return X.div(Oe).getBaseValue("number");
|
|
623
630
|
}
|
|
624
|
-
function
|
|
631
|
+
function Pt({
|
|
625
632
|
runeAmount: e,
|
|
626
633
|
assetAmount: t,
|
|
627
634
|
runeDepth: n,
|
|
@@ -632,7 +639,7 @@ function Et({
|
|
|
632
639
|
const s = m(n), i = m(r), o = m(t), c = m(e), a = o.mul(s).sub(i.mul(c)), l = i.mul(c).add(s.mul(i));
|
|
633
640
|
return Math.abs(a.div(l).getBaseValue("number"));
|
|
634
641
|
}
|
|
635
|
-
const
|
|
642
|
+
const Ot = (e, t) => {
|
|
636
643
|
switch (e) {
|
|
637
644
|
case C.LEAVE:
|
|
638
645
|
case C.BOND: {
|
|
@@ -675,29 +682,29 @@ const Pt = (e, t) => {
|
|
|
675
682
|
return "";
|
|
676
683
|
}
|
|
677
684
|
};
|
|
678
|
-
function
|
|
685
|
+
function Nt(e) {
|
|
679
686
|
if (e < 0)
|
|
680
687
|
throw new Error("Invalid number of year");
|
|
681
688
|
return 10 + e;
|
|
682
689
|
}
|
|
683
|
-
function
|
|
690
|
+
function vt(e) {
|
|
684
691
|
if (e < 0)
|
|
685
692
|
throw new Error("Invalid number of year");
|
|
686
693
|
return Math.round((10 + e * 1.0512) * 1e10) / 1e10;
|
|
687
694
|
}
|
|
688
|
-
function
|
|
695
|
+
function $t(e) {
|
|
689
696
|
if (e.length > 30)
|
|
690
697
|
return !1;
|
|
691
698
|
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
692
699
|
return !!e.match(t);
|
|
693
700
|
}
|
|
694
|
-
function
|
|
701
|
+
function It(e) {
|
|
695
702
|
if (e.length > 30)
|
|
696
703
|
return !1;
|
|
697
704
|
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
698
705
|
return !!e.match(t);
|
|
699
706
|
}
|
|
700
|
-
function
|
|
707
|
+
function Bt([e, t, n, r, s]) {
|
|
701
708
|
return `${e}'/${t}'/${n}'/${r}${typeof s != "number" ? "" : `/${s}`}`;
|
|
702
709
|
}
|
|
703
710
|
const le = [...Object.values(u), "TERRA"];
|
|
@@ -712,7 +719,7 @@ function dt(e = "") {
|
|
|
712
719
|
`Invalid identifier: ${e}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
713
720
|
);
|
|
714
721
|
}
|
|
715
|
-
const B = 8,
|
|
722
|
+
const B = 8, w = (e) => 10n ** BigInt(e), v = (e) => Math.log10(Number.parseFloat(e.toString()));
|
|
716
723
|
function U({
|
|
717
724
|
value: e,
|
|
718
725
|
bigIntDecimal: t = B,
|
|
@@ -731,10 +738,10 @@ function U({
|
|
|
731
738
|
""
|
|
732
739
|
);
|
|
733
740
|
}
|
|
734
|
-
var
|
|
741
|
+
var y, $, b, E, j, be, V, Z, H, ee;
|
|
735
742
|
const q = class q {
|
|
736
743
|
constructor(t) {
|
|
737
|
-
R(this,
|
|
744
|
+
R(this, y);
|
|
738
745
|
R(this, b);
|
|
739
746
|
R(this, j);
|
|
740
747
|
R(this, V);
|
|
@@ -743,7 +750,7 @@ const q = class q {
|
|
|
743
750
|
_(this, "bigIntValue", 0n);
|
|
744
751
|
_(this, "decimal");
|
|
745
752
|
const n = te(t), r = typeof t == "object";
|
|
746
|
-
this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier :
|
|
753
|
+
this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier : w(Math.max(he(k(n)), this.decimal || 0)), p(this, j, be).call(this, n);
|
|
747
754
|
}
|
|
748
755
|
static fromBigInt(t, n) {
|
|
749
756
|
return new q({
|
|
@@ -757,7 +764,7 @@ const q = class q {
|
|
|
757
764
|
to: r
|
|
758
765
|
}) {
|
|
759
766
|
return q.fromBigInt(
|
|
760
|
-
t.getBaseValue("bigint") *
|
|
767
|
+
t.getBaseValue("bigint") * w(r) / w(n),
|
|
761
768
|
r
|
|
762
769
|
);
|
|
763
770
|
}
|
|
@@ -765,16 +772,16 @@ const q = class q {
|
|
|
765
772
|
return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
|
|
766
773
|
}
|
|
767
774
|
add(...t) {
|
|
768
|
-
return p(this,
|
|
775
|
+
return p(this, y, $).call(this, "add", ...t);
|
|
769
776
|
}
|
|
770
777
|
sub(...t) {
|
|
771
|
-
return p(this,
|
|
778
|
+
return p(this, y, $).call(this, "sub", ...t);
|
|
772
779
|
}
|
|
773
780
|
mul(...t) {
|
|
774
|
-
return p(this,
|
|
781
|
+
return p(this, y, $).call(this, "mul", ...t);
|
|
775
782
|
}
|
|
776
783
|
div(...t) {
|
|
777
|
-
return p(this,
|
|
784
|
+
return p(this, y, $).call(this, "div", ...t);
|
|
778
785
|
}
|
|
779
786
|
gt(t) {
|
|
780
787
|
return p(this, b, E).call(this, "gt", t);
|
|
@@ -808,7 +815,7 @@ const q = class q {
|
|
|
808
815
|
}
|
|
809
816
|
// @ts-expect-error
|
|
810
817
|
getBaseValue(t) {
|
|
811
|
-
const n = this.decimalMultiplier /
|
|
818
|
+
const n = this.decimalMultiplier / w(this.decimal || d.THOR), r = this.bigIntValue / n;
|
|
812
819
|
switch (t) {
|
|
813
820
|
case "number":
|
|
814
821
|
return Number(r);
|
|
@@ -821,7 +828,7 @@ const q = class q {
|
|
|
821
828
|
getBigIntValue(t, n) {
|
|
822
829
|
if (!n && typeof t == "object")
|
|
823
830
|
return t.bigIntValue;
|
|
824
|
-
const r = te(t), s =
|
|
831
|
+
const r = te(t), s = k(r);
|
|
825
832
|
return s === "0" || s === "undefined" ? 0n : p(this, H, ee).call(this, s, n);
|
|
826
833
|
}
|
|
827
834
|
toSignificant(t = 6) {
|
|
@@ -879,8 +886,8 @@ const q = class q {
|
|
|
879
886
|
)}.${h}`.replace(/\.?0*$/, "");
|
|
880
887
|
}
|
|
881
888
|
};
|
|
882
|
-
|
|
883
|
-
const r = p(this, V, Z).call(this, this, ...n), s = Math.max(r, v(this.decimalMultiplier)), i =
|
|
889
|
+
y = new WeakSet(), $ = function(t, ...n) {
|
|
890
|
+
const r = p(this, V, Z).call(this, this, ...n), s = Math.max(r, v(this.decimalMultiplier)), i = w(s), o = n.reduce(
|
|
884
891
|
(a, l) => {
|
|
885
892
|
const h = this.getBigIntValue(l, s);
|
|
886
893
|
switch (t) {
|
|
@@ -907,7 +914,7 @@ w = new WeakSet(), $ = function(t, ...n) {
|
|
|
907
914
|
value: o
|
|
908
915
|
});
|
|
909
916
|
return new this.constructor({
|
|
910
|
-
decimalMultiplier:
|
|
917
|
+
decimalMultiplier: w(s),
|
|
911
918
|
decimal: this.decimal,
|
|
912
919
|
value: c,
|
|
913
920
|
identifier: this.toString()
|
|
@@ -927,13 +934,13 @@ w = new WeakSet(), $ = function(t, ...n) {
|
|
|
927
934
|
return i === s;
|
|
928
935
|
}
|
|
929
936
|
}, j = new WeakSet(), be = function(t) {
|
|
930
|
-
const n =
|
|
937
|
+
const n = k(t) || "0";
|
|
931
938
|
this.bigIntValue = p(this, H, ee).call(this, n);
|
|
932
939
|
}, V = new WeakSet(), Z = function(...t) {
|
|
933
|
-
const n = t.map((r) => typeof r == "object" ? r.decimal || v(r.decimalMultiplier) : he(
|
|
940
|
+
const n = t.map((r) => typeof r == "object" ? r.decimal || v(r.decimalMultiplier) : he(k(r))).filter(Boolean);
|
|
934
941
|
return Math.max(...n, B);
|
|
935
942
|
}, H = new WeakSet(), ee = function(t, n) {
|
|
936
|
-
const r = n ?
|
|
943
|
+
const r = n ? w(n) : this.decimalMultiplier, s = v(r), [i = "", o = ""] = t.split(".");
|
|
937
944
|
return BigInt(`${i}${o.padEnd(s, "0")}`);
|
|
938
945
|
};
|
|
939
946
|
let D = q;
|
|
@@ -941,7 +948,7 @@ const pt = Intl.NumberFormat("fullwide", {
|
|
|
941
948
|
useGrouping: !1,
|
|
942
949
|
maximumFractionDigits: 20
|
|
943
950
|
});
|
|
944
|
-
function
|
|
951
|
+
function k(e) {
|
|
945
952
|
const n = `${typeof e == "number" ? pt.format(e) : te(e)}`.replaceAll(",", ".").split(".");
|
|
946
953
|
return n.length > 1 ? `${n.slice(0, -1).join("")}.${n.at(-1)}` : n[0];
|
|
947
954
|
}
|
|
@@ -1090,7 +1097,7 @@ class A extends D {
|
|
|
1090
1097
|
);
|
|
1091
1098
|
}
|
|
1092
1099
|
}
|
|
1093
|
-
function
|
|
1100
|
+
function Dt(e) {
|
|
1094
1101
|
const t = A.fromChainOrSignature(e);
|
|
1095
1102
|
switch (e) {
|
|
1096
1103
|
case u.Bitcoin:
|
|
@@ -1216,14 +1223,14 @@ const mt = {
|
|
|
1216
1223
|
*/
|
|
1217
1224
|
helpers_number_different_decimals: 99101
|
|
1218
1225
|
};
|
|
1219
|
-
class
|
|
1226
|
+
class we extends Error {
|
|
1220
1227
|
constructor(t, n) {
|
|
1221
1228
|
n && console.error(n, {
|
|
1222
1229
|
stack: n == null ? void 0 : n.stack,
|
|
1223
1230
|
message: n == null ? void 0 : n.message
|
|
1224
1231
|
}), super(t, {
|
|
1225
1232
|
cause: { code: mt[t], message: t }
|
|
1226
|
-
}), Object.setPrototypeOf(this,
|
|
1233
|
+
}), Object.setPrototypeOf(this, we.prototype);
|
|
1227
1234
|
}
|
|
1228
1235
|
}
|
|
1229
1236
|
export {
|
|
@@ -1233,34 +1240,35 @@ export {
|
|
|
1233
1240
|
f as RequestClient,
|
|
1234
1241
|
Ze as StreamingSwapProgressStatus,
|
|
1235
1242
|
gt as SwapKitApi,
|
|
1236
|
-
|
|
1243
|
+
we as SwapKitError,
|
|
1237
1244
|
g as SwapKitNumber,
|
|
1238
1245
|
Qe as TransactionType,
|
|
1239
1246
|
ze as TxStatus,
|
|
1240
1247
|
Ct as assetFromString,
|
|
1241
1248
|
Ae as defaultRequestHeaders,
|
|
1242
|
-
|
|
1249
|
+
Bt as derivationPathToString,
|
|
1243
1250
|
St as filterAssets,
|
|
1251
|
+
bt as findAssetBy,
|
|
1244
1252
|
U as formatBigIntToSafeValue,
|
|
1245
1253
|
At as gasFeeMultiplier,
|
|
1246
1254
|
ot as getAssetType,
|
|
1247
1255
|
lt as getAsymmetricAssetShare,
|
|
1248
1256
|
yt as getAsymmetricAssetWithdrawAmount,
|
|
1249
1257
|
ut as getAsymmetricRuneShare,
|
|
1250
|
-
|
|
1258
|
+
wt as getAsymmetricRuneWithdrawAmount,
|
|
1251
1259
|
it as getCommonAssetInfo,
|
|
1252
1260
|
st as getDecimal,
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1261
|
+
Et as getEstimatedPoolShare,
|
|
1262
|
+
Pt as getLiquiditySlippage,
|
|
1263
|
+
vt as getMAYANameCost,
|
|
1264
|
+
Ot as getMemoFor,
|
|
1265
|
+
Dt as getMinAmountByChain,
|
|
1258
1266
|
ht as getSymmetricPoolShare,
|
|
1259
|
-
|
|
1260
|
-
|
|
1267
|
+
Rt as getSymmetricWithdraw,
|
|
1268
|
+
Nt as getTHORNameCost,
|
|
1261
1269
|
Se as isGasAsset,
|
|
1262
1270
|
Tt as setRequestClientConfig,
|
|
1263
|
-
|
|
1264
|
-
|
|
1271
|
+
It as validateMAYAName,
|
|
1272
|
+
$t as validateTHORName
|
|
1265
1273
|
};
|
|
1266
1274
|
//# sourceMappingURL=index.es.js.map
|