@swapkit/helpers 1.0.0-rc.73 → 1.0.0-rc.75
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 +4 -0
- package/dist/index.es.js +91 -78
- package/dist/index.es.js.map +1 -1
- package/package.json +6 -6
- package/src/helpers/__tests__/memo.test.ts +11 -1
- package/src/helpers/others.ts +16 -0
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var _ = (e, t, n) => (
|
|
1
|
+
var ve = Object.defineProperty;
|
|
2
|
+
var $e = (e, t, n) => t in e ? ve(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var _ = (e, t, n) => ($e(e, typeof t != "symbol" ? t + "" : t, n), n), Ie = (e, t, n) => {
|
|
4
4
|
if (!t.has(e))
|
|
5
5
|
throw TypeError("Cannot " + n);
|
|
6
6
|
};
|
|
@@ -65,9 +65,9 @@ class pe extends Error {
|
|
|
65
65
|
}), this.name = "TimeoutError", this.request = t;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
const
|
|
68
|
+
const k = (e) => e !== null && typeof e == "object", x = (...e) => {
|
|
69
69
|
for (const t of e)
|
|
70
|
-
if ((!
|
|
70
|
+
if ((!k(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 M = (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 (k(r)) {
|
|
84
84
|
for (let [s, i] of Object.entries(r))
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
k(i) && s in t && (i = se(t[s], i)), t = { ...t, [s]: i };
|
|
86
|
+
k(r.headers) && (n = me(n, r.headers), t.headers = n);
|
|
87
87
|
}
|
|
88
88
|
return t;
|
|
89
89
|
}, He = (() => {
|
|
@@ -97,13 +97,13 @@ const M = (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", Me = typeof globalThis.ReadableStream == "function", ke = 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",
|
|
104
104
|
arrayBuffer: "*/*",
|
|
105
105
|
blob: "*/*"
|
|
106
|
-
},
|
|
106
|
+
}, Y = 2147483647, fe = Symbol("stop"), We = {
|
|
107
107
|
json: !0,
|
|
108
108
|
parseJson: !0,
|
|
109
109
|
searchParams: !0,
|
|
@@ -130,11 +130,11 @@ const M = (e) => e !== null && typeof e == "object", x = (...e) => {
|
|
|
130
130
|
window: !0,
|
|
131
131
|
dispatcher: !0,
|
|
132
132
|
duplex: !0
|
|
133
|
-
}, je = (e) => _e.includes(e) ? e.toUpperCase() : e, qe = ["get", "put", "head", "delete", "options", "trace"], Fe = [408, 413, 429, 500, 502, 503, 504],
|
|
133
|
+
}, je = (e) => _e.includes(e) ? e.toUpperCase() : e, qe = ["get", "put", "head", "delete", "options", "trace"], Fe = [408, 413, 429, 500, 502, 503, 504], Te = [413, 429, 503], ce = {
|
|
134
134
|
limit: 2,
|
|
135
135
|
methods: qe,
|
|
136
136
|
statusCodes: Fe,
|
|
137
|
-
afterStatusCodes:
|
|
137
|
+
afterStatusCodes: Te,
|
|
138
138
|
maxRetryAfter: Number.POSITIVE_INFINITY,
|
|
139
139
|
backoffLimit: Number.POSITIVE_INFINITY,
|
|
140
140
|
delay: (e) => 0.3 * 2 ** (e - 1) * 1e3
|
|
@@ -151,7 +151,7 @@ const M = (e) => e !== null && typeof e == "object", x = (...e) => {
|
|
|
151
151
|
return {
|
|
152
152
|
...ce,
|
|
153
153
|
...e,
|
|
154
|
-
afterStatusCodes:
|
|
154
|
+
afterStatusCodes: Te
|
|
155
155
|
};
|
|
156
156
|
};
|
|
157
157
|
async function Xe(e, t, n, r) {
|
|
@@ -175,7 +175,7 @@ async function Ke(e, { signal: t }) {
|
|
|
175
175
|
}, e);
|
|
176
176
|
});
|
|
177
177
|
}
|
|
178
|
-
const
|
|
178
|
+
const Ye = (e, t) => {
|
|
179
179
|
const n = {};
|
|
180
180
|
for (const r in t)
|
|
181
181
|
!(r in Ue) && !(r in We) && !(r in e) && (n[r] = t[r]);
|
|
@@ -184,8 +184,8 @@ const Je = (e, t) => {
|
|
|
184
184
|
class W {
|
|
185
185
|
static create(t, n) {
|
|
186
186
|
const r = new W(t, n), s = async () => {
|
|
187
|
-
if (typeof r._options.timeout == "number" && r._options.timeout >
|
|
188
|
-
throw new RangeError(`The \`timeout\` option cannot be greater than ${
|
|
187
|
+
if (typeof r._options.timeout == "number" && r._options.timeout > Y)
|
|
188
|
+
throw new RangeError(`The \`timeout\` option cannot be greater than ${Y}`);
|
|
189
189
|
await Promise.resolve();
|
|
190
190
|
let o = await r._fetch();
|
|
191
191
|
for (const c of r._options.hooks.afterResponse) {
|
|
@@ -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 (!Me)
|
|
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
|
}
|
|
@@ -284,7 +284,7 @@ class W {
|
|
|
284
284
|
}
|
|
285
285
|
if (He && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
|
|
286
286
|
const r = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), s = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, r);
|
|
287
|
-
(
|
|
287
|
+
(ke && 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(s, { ...this.request }), this._options);
|
|
288
288
|
}
|
|
289
289
|
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 }));
|
|
290
290
|
}
|
|
@@ -313,7 +313,7 @@ class W {
|
|
|
313
313
|
try {
|
|
314
314
|
return await t();
|
|
315
315
|
} catch (n) {
|
|
316
|
-
const r = Math.min(this._calculateRetryDelay(n),
|
|
316
|
+
const r = Math.min(this._calculateRetryDelay(n), Y);
|
|
317
317
|
if (r !== 0 && this._retryCount > 0) {
|
|
318
318
|
await Ke(r, { signal: this._options.signal });
|
|
319
319
|
for (const s of this._options.hooks.beforeRetry)
|
|
@@ -322,7 +322,7 @@ class W {
|
|
|
322
322
|
options: this._options,
|
|
323
323
|
error: n,
|
|
324
324
|
retryCount: this._retryCount
|
|
325
|
-
}) ===
|
|
325
|
+
}) === fe)
|
|
326
326
|
return;
|
|
327
327
|
return this._retry(t);
|
|
328
328
|
}
|
|
@@ -339,7 +339,7 @@ class W {
|
|
|
339
339
|
if (r instanceof Response)
|
|
340
340
|
return r;
|
|
341
341
|
}
|
|
342
|
-
const t =
|
|
342
|
+
const t = Ye(this.request, this._options);
|
|
343
343
|
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Xe(this.request.clone(), t, this.abortController, this._options);
|
|
344
344
|
}
|
|
345
345
|
/* istanbul ignore next */
|
|
@@ -381,10 +381,10 @@ const z = (e) => {
|
|
|
381
381
|
const t = (n, r) => W.create(n, x(e, r));
|
|
382
382
|
for (const n of _e)
|
|
383
383
|
t[n] = (r, s) => W.create(r, x(e, s, { method: n }));
|
|
384
|
-
return t.create = (n) => z(x(n)), t.extend = (n) => z(x(e, n)), t.stop =
|
|
384
|
+
return t.create = (n) => z(x(n)), t.extend = (n) => z(x(e, n)), t.stop = fe, t;
|
|
385
385
|
}, ge = z();
|
|
386
386
|
let L;
|
|
387
|
-
const
|
|
387
|
+
const T = {
|
|
388
388
|
CachedPrices: `${S.ThorswapApi}/tokenlist/cached-price`,
|
|
389
389
|
GasRates: `${S.ThorswapApi}/resource-worker/gasPrice/getAll`,
|
|
390
390
|
Quote: `${S.ThorswapApi}/aggregator/tokens/quote`,
|
|
@@ -392,39 +392,39 @@ const f = {
|
|
|
392
392
|
TokenlistProviders: `${S.ThorswapApi}/tokenlist/providers`,
|
|
393
393
|
TokenList: `${S.ThorswapStatic}/token-list`,
|
|
394
394
|
Thorname: `${S.ThorswapApi}/thorname`
|
|
395
|
-
}, Ae = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, le = () => L || (L = ge.create({ headers: Ae }), L),
|
|
395
|
+
}, Ae = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, le = () => L || (L = ge.create({ headers: Ae }), L), Tt = ({ apiKey: e, ...t }) => {
|
|
396
396
|
L = ge.create({
|
|
397
397
|
...t,
|
|
398
398
|
headers: { ...Ae, ...t.headers, "x-api-key": e }
|
|
399
399
|
});
|
|
400
|
-
},
|
|
400
|
+
}, f = {
|
|
401
401
|
get: (e, t) => le().get(e, t).json(),
|
|
402
402
|
post: (e, t) => le().post(e, t).json()
|
|
403
|
-
},
|
|
403
|
+
}, Je = ({ tokens: e, ...t }) => {
|
|
404
404
|
const n = new URLSearchParams(), r = e.filter(
|
|
405
405
|
(s, i, o) => o.findIndex((c) => c === s) === i
|
|
406
406
|
);
|
|
407
407
|
for (const s of r)
|
|
408
408
|
n.append("tokens", JSON.stringify(s));
|
|
409
|
-
return t.metadata && n.append("metadata", "true"), t.lookup && n.append("lookup", "true"), t.sparkline && n.append("sparkline", "true"),
|
|
409
|
+
return t.metadata && n.append("metadata", "true"), t.lookup && n.append("lookup", "true"), t.sparkline && n.append("sparkline", "true"), f.post(T.CachedPrices, {
|
|
410
410
|
body: n.toString(),
|
|
411
411
|
headers: { "Content-Type": "application/x-www-form-urlencoded" }
|
|
412
412
|
});
|
|
413
413
|
}, gt = {
|
|
414
|
-
getCachedPrices:
|
|
415
|
-
getQuote: (e) =>
|
|
416
|
-
getGasRates: () =>
|
|
417
|
-
getTxnDetails: (e) =>
|
|
418
|
-
getTokenlistProviders: () =>
|
|
419
|
-
getTokenList: (e) =>
|
|
420
|
-
getThornameAddresses: (e) =>
|
|
421
|
-
getThornameRegisteredChains: (e) =>
|
|
422
|
-
getThornameRlookup: (e, t) =>
|
|
414
|
+
getCachedPrices: Je,
|
|
415
|
+
getQuote: (e) => f.get(T.Quote, { searchParams: e }),
|
|
416
|
+
getGasRates: () => f.get(T.GasRates),
|
|
417
|
+
getTxnDetails: (e) => f.get(T.Txn, { searchParams: e }),
|
|
418
|
+
getTokenlistProviders: () => f.get(T.TokenlistProviders),
|
|
419
|
+
getTokenList: (e) => f.get(`${T.TokenList}/${e}.json`),
|
|
420
|
+
getThornameAddresses: (e) => f.get(`${T.Thorname}/${e}`),
|
|
421
|
+
getThornameRegisteredChains: (e) => f.get(`${T.Thorname}/chains/${e}`),
|
|
422
|
+
getThornameRlookup: (e, t) => f.get(`${T.Thorname}/rlookup`, { searchParams: { address: e, chain: t } })
|
|
423
423
|
};
|
|
424
424
|
var Qe = /* @__PURE__ */ ((e) => (e.SWAP_TC_TO_TC = "SWAP:TC-TC", e.SWAP_ETH_TO_TC = "SWAP:ERC20-TC", e.SWAP_TC_TO_ETH = "SWAP:TC-ERC20", e.SWAP_ETH_TO_ETH = "SWAP:ERC20-ERC20", e.SWAP_AVAX_TO_TC = "SWAP:AVAX-TC", e.SWAP_TC_TO_AVAX = "SWAP:TC-AVAX", e.SWAP_AVAX_TO_AVAX = "SWAP:AVAX-AVAX", e.SWAP_ETH_TO_AVAX = "SWAP:ETH-AVAX", e.SWAP_AVAX_TO_ETH = "SWAP:AVAX-ETH", e.SWAP_TC_TO_GAIA = "SWAP:TC-GAIA", e.SWAP_GAIA_TO_TC = "SWAP:GAIA-TC", e.SWAP_TC_TO_BNB = "SWAP:TC-BNB", e.SWAP_BNB_TO_TC = "SWAP:BNB-TC", e.SWAP_TC_TO_BTC = "SWAP:TC-BTC", e.SWAP_BTC_TO_TC = "SWAP:BTC-TC", e.SWAP_TC_TO_BCH = "SWAP:TC-BCH", e.SWAP_BCH_TO_TC = "SWAP:BCH-TC", e.SWAP_TC_TO_LTC = "SWAP:TC-LTC", e.SWAP_LTC_TO_TC = "SWAP:LTC-TC", e.SWAP_TC_TO_DOGE = "SWAP:TC-DOGE", e.SWAP_DOGE_TO_TC = "SWAP:DOGE-TC", e.TC_STATUS = "TC:STATUS", e.TC_TRANSFER = "TC:TRANSFER", e.TC_DEPOSIT = "TC:DEPOSIT", e.TC_SEND = "TC:SEND", e.TC_SWITCH = "TC:SWITCH", e.TC_LP_ADD = "TC:ADDLIQUIDITY", e.TC_LP_WITHDRAW = "TC:WITHDRAW", e.TC_TNS_CREATE = "TC:TNS-CREATE", e.TC_TNS_EXTEND = "TC:TNS-EXTEND", e.TC_TNS_UPDATE = "TC:TNS-UPDATE", e.TC_SAVINGS_ADD = "TC:ADDSAVINGS", e.TC_SAVINGS_WITHDRAW = "TC:WITHDRAWSAVINGS", e.TC_LENDING_OPEN = "TC:LENDINGOPEN", e.TC_LENDING_CLOSE = "TC:LENDINGCLOSE", e.ETH_APPROVAL = "ETH:APPROVAL", e.ETH_STATUS = "ETH:STATUS", e.ETH_TRANSFER_TO_TC = "ETH:TRANSFER:IN", e.ETH_TRANSFER_FROM_TC = "ETH:TRANSFER:OUT", e.AVAX_APPROVAL = "AVAX:APPROVAL", e.AVAX_STATUS = "AVAX:STATUS", e.AVAX_TRANSFER_TO_TC = "AVAX:TRANSFER:IN", e.AVAX_TRANSFER_FROM_TC = "AVAX:TRANSFER:OUT", e.BSC_APPROVAL = "BSC:APPROVAL", e.BSC_STATUS = "BSC:STATUS", e.BSC_TRANSFER_TO_TC = "BSC:TRANSFER:IN", e.BSC_TRANSFER_FROM_TC = "BSC:TRANSFER:OUT", e.APPROVAL = "APPROVAL", e.STATUS = "STATUS", e.TRANSFER_TO_TC = "TRANSFER:IN", e.TRANSFER_FROM_TC = "TRANSFER:OUT", e.UNSUPPORTED = "UNSUPPORTED", e.TC_LENDING = "TC:LENDING", e))(Qe || {}), ze = /* @__PURE__ */ ((e) => (e.PENDING = "pending", e.SUCCESS = "success", e.CANCELLED = "cancelled", e.REFUNDED = "refunded", e.REPLACED = "replaced", e.ERROR = "error", e.UNKNOWN = "unknown", e.NOT_STARTED = "not_started", e.NOT_FOUND = "not_found", e.RETRIES_EXCEEDED = "retries_exceeded", e.STREAMING = "streaming", e))(ze || {}), Ze = /* @__PURE__ */ ((e) => (e[e.NOT_STARTED = 0] = "NOT_STARTED", e[e.SUCCESS = 1] = "SUCCESS", e[e.REFUNDED = 2] = "REFUNDED", e))(Ze || {});
|
|
425
425
|
const et = "0x313ce567", Ce = async ({ chain: e, to: t }) => {
|
|
426
426
|
try {
|
|
427
|
-
const { result: n } = await
|
|
427
|
+
const { result: n } = await f.post(Be[e], {
|
|
428
428
|
headers: {
|
|
429
429
|
accept: "*/*",
|
|
430
430
|
"content-type": "application/json",
|
|
@@ -560,8 +560,8 @@ function ut({
|
|
|
560
560
|
poolUnits: t,
|
|
561
561
|
assetDepth: n
|
|
562
562
|
}) {
|
|
563
|
-
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), u = r.mul(r), h = o.mul(c.sub(a).add(u)),
|
|
564
|
-
return h.div(
|
|
563
|
+
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), u = r.mul(r), h = o.mul(c.sub(a).add(u)), v = s.mul(s).mul(s);
|
|
564
|
+
return h.div(v);
|
|
565
565
|
}
|
|
566
566
|
function bt({
|
|
567
567
|
percent: e,
|
|
@@ -571,7 +571,7 @@ function bt({
|
|
|
571
571
|
}) {
|
|
572
572
|
return lt({ runeDepth: t, liquidityUnits: n, poolUnits: r }).mul(e);
|
|
573
573
|
}
|
|
574
|
-
function
|
|
574
|
+
function wt({
|
|
575
575
|
percent: e,
|
|
576
576
|
assetDepth: t,
|
|
577
577
|
liquidityUnits: n,
|
|
@@ -593,7 +593,7 @@ function ht({
|
|
|
593
593
|
runeAmount: m(n).mul(e).div(t)
|
|
594
594
|
};
|
|
595
595
|
}
|
|
596
|
-
function
|
|
596
|
+
function yt({
|
|
597
597
|
liquidityUnits: e,
|
|
598
598
|
poolUnits: t,
|
|
599
599
|
runeDepth: n,
|
|
@@ -614,7 +614,7 @@ function Rt({
|
|
|
614
614
|
runeAmount: s,
|
|
615
615
|
assetAmount: i
|
|
616
616
|
}) {
|
|
617
|
-
const o = new g({ value: e, decimal: 8 }), c = new g({ value: n, decimal: 8 }), a = new g({ value: t, decimal: 8 }), u = new g({ value: s, decimal: 8 }), h = new g({ value: i, decimal: 8 }),
|
|
617
|
+
const o = new g({ value: e, decimal: 8 }), c = new g({ value: n, decimal: 8 }), a = new g({ value: t, decimal: 8 }), u = new g({ value: s, decimal: 8 }), h = new g({ value: i, decimal: 8 }), v = u.mul(c), ie = h.mul(o), ye = u.mul(h), Re = o.mul(c), Ee = a.mul(v.add(ie.add(ye.mul(2)))), Pe = v.add(ie.add(Re.mul(2))), oe = Ee.div(Pe), X = m(r).add(oe);
|
|
618
618
|
if (oe.getBaseValue("number") === 0)
|
|
619
619
|
return X.div(a).getBaseValue("number");
|
|
620
620
|
const Oe = a.add(X);
|
|
@@ -679,13 +679,24 @@ function Ot(e) {
|
|
|
679
679
|
throw new Error("Invalid number of year");
|
|
680
680
|
return 10 + e;
|
|
681
681
|
}
|
|
682
|
+
function vt(e) {
|
|
683
|
+
if (e < 0)
|
|
684
|
+
throw new Error("Invalid number of year");
|
|
685
|
+
return Math.round((10 + e * 1.0512) * 1e10) / 1e10;
|
|
686
|
+
}
|
|
682
687
|
function $t(e) {
|
|
683
688
|
if (e.length > 30)
|
|
684
689
|
return !1;
|
|
685
690
|
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
686
691
|
return !!e.match(t);
|
|
687
692
|
}
|
|
688
|
-
function
|
|
693
|
+
function It(e) {
|
|
694
|
+
if (e.length > 30)
|
|
695
|
+
return !1;
|
|
696
|
+
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
697
|
+
return !!e.match(t);
|
|
698
|
+
}
|
|
699
|
+
function Nt([e, t, n, r, s]) {
|
|
689
700
|
return `${e}'/${t}'/${n}'/${r}${typeof s != "number" ? "" : `/${s}`}`;
|
|
690
701
|
}
|
|
691
702
|
const ue = [...Object.values(l), "TERRA"];
|
|
@@ -700,7 +711,7 @@ function dt(e = "") {
|
|
|
700
711
|
`Invalid identifier: ${e}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
701
712
|
);
|
|
702
713
|
}
|
|
703
|
-
const B = 8,
|
|
714
|
+
const B = 8, w = (e) => 10n ** BigInt(e), $ = (e) => Math.log10(parseFloat(e.toString()));
|
|
704
715
|
function U({
|
|
705
716
|
value: e,
|
|
706
717
|
bigIntDecimal: t = B,
|
|
@@ -719,10 +730,10 @@ function U({
|
|
|
719
730
|
""
|
|
720
731
|
);
|
|
721
732
|
}
|
|
722
|
-
var
|
|
733
|
+
var y, I, b, E, j, be, V, Z, H, ee;
|
|
723
734
|
const q = class q {
|
|
724
735
|
constructor(t) {
|
|
725
|
-
R(this,
|
|
736
|
+
R(this, y);
|
|
726
737
|
R(this, b);
|
|
727
738
|
R(this, j);
|
|
728
739
|
R(this, V);
|
|
@@ -731,7 +742,7 @@ const q = class q {
|
|
|
731
742
|
_(this, "bigIntValue", 0n);
|
|
732
743
|
_(this, "decimal");
|
|
733
744
|
const n = te(t), r = typeof t == "object";
|
|
734
|
-
this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier :
|
|
745
|
+
this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier : w(Math.max(he(M(n)), this.decimal || 0)), p(this, j, be).call(this, n);
|
|
735
746
|
}
|
|
736
747
|
static fromBigInt(t, n) {
|
|
737
748
|
return new q({
|
|
@@ -745,7 +756,7 @@ const q = class q {
|
|
|
745
756
|
to: r
|
|
746
757
|
}) {
|
|
747
758
|
return q.fromBigInt(
|
|
748
|
-
t.getBaseValue("bigint") *
|
|
759
|
+
t.getBaseValue("bigint") * w(r) / w(n),
|
|
749
760
|
r
|
|
750
761
|
);
|
|
751
762
|
}
|
|
@@ -753,16 +764,16 @@ const q = class q {
|
|
|
753
764
|
return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
|
|
754
765
|
}
|
|
755
766
|
add(...t) {
|
|
756
|
-
return p(this,
|
|
767
|
+
return p(this, y, I).call(this, "add", ...t);
|
|
757
768
|
}
|
|
758
769
|
sub(...t) {
|
|
759
|
-
return p(this,
|
|
770
|
+
return p(this, y, I).call(this, "sub", ...t);
|
|
760
771
|
}
|
|
761
772
|
mul(...t) {
|
|
762
|
-
return p(this,
|
|
773
|
+
return p(this, y, I).call(this, "mul", ...t);
|
|
763
774
|
}
|
|
764
775
|
div(...t) {
|
|
765
|
-
return p(this,
|
|
776
|
+
return p(this, y, I).call(this, "div", ...t);
|
|
766
777
|
}
|
|
767
778
|
gt(t) {
|
|
768
779
|
return p(this, b, E).call(this, "gt", t);
|
|
@@ -783,7 +794,7 @@ const q = class q {
|
|
|
783
794
|
getValue(t) {
|
|
784
795
|
const n = this.formatBigIntToSafeValue(
|
|
785
796
|
this.bigIntValue,
|
|
786
|
-
this.decimal ||
|
|
797
|
+
this.decimal || $(this.decimalMultiplier)
|
|
787
798
|
);
|
|
788
799
|
switch (t) {
|
|
789
800
|
case "number":
|
|
@@ -796,7 +807,7 @@ const q = class q {
|
|
|
796
807
|
}
|
|
797
808
|
// @ts-expect-error
|
|
798
809
|
getBaseValue(t) {
|
|
799
|
-
const n = this.decimalMultiplier /
|
|
810
|
+
const n = this.decimalMultiplier / w(this.decimal || d.THOR), r = this.bigIntValue / n;
|
|
800
811
|
switch (t) {
|
|
801
812
|
case "number":
|
|
802
813
|
return Number(r);
|
|
@@ -809,7 +820,7 @@ const q = class q {
|
|
|
809
820
|
getBigIntValue(t, n) {
|
|
810
821
|
if (!n && typeof t == "object")
|
|
811
822
|
return t.bigIntValue;
|
|
812
|
-
const r = te(t), s =
|
|
823
|
+
const r = te(t), s = M(r);
|
|
813
824
|
return s === "0" || s === "undefined" ? 0n : p(this, H, ee).call(this, s, n);
|
|
814
825
|
}
|
|
815
826
|
toSignificant(t = 6) {
|
|
@@ -858,7 +869,7 @@ const q = class q {
|
|
|
858
869
|
formatBigIntToSafeValue(t, n) {
|
|
859
870
|
const r = n || this.decimal || B, s = Math.max(
|
|
860
871
|
r,
|
|
861
|
-
|
|
872
|
+
$(this.decimalMultiplier)
|
|
862
873
|
), i = t < 0n, o = t.toString().substring(i ? 1 : 0), c = s - (o.length - 1), a = c > 0 ? "0".repeat(c) + o : o, u = a.length - s;
|
|
863
874
|
let h = a.slice(-s);
|
|
864
875
|
return parseInt(h[r]) >= 5 ? h = `${h.substring(0, r - 1)}${(parseInt(h[r - 1]) + 1).toString()}` : h = h.substring(0, r), `${i ? "-" : ""}${a.slice(
|
|
@@ -867,8 +878,8 @@ const q = class q {
|
|
|
867
878
|
)}.${h}`.replace(/\.?0*$/, "");
|
|
868
879
|
}
|
|
869
880
|
};
|
|
870
|
-
|
|
871
|
-
const r = p(this, V, Z).call(this, this, ...n), s = Math.max(r,
|
|
881
|
+
y = new WeakSet(), I = function(t, ...n) {
|
|
882
|
+
const r = p(this, V, Z).call(this, this, ...n), s = Math.max(r, $(this.decimalMultiplier)), i = w(s), o = n.reduce(
|
|
872
883
|
(a, u) => {
|
|
873
884
|
const h = this.getBigIntValue(u, s);
|
|
874
885
|
switch (t) {
|
|
@@ -895,7 +906,7 @@ w = new WeakSet(), I = function(t, ...n) {
|
|
|
895
906
|
value: o
|
|
896
907
|
});
|
|
897
908
|
return new this.constructor({
|
|
898
|
-
decimalMultiplier:
|
|
909
|
+
decimalMultiplier: w(s),
|
|
899
910
|
decimal: this.decimal,
|
|
900
911
|
value: c,
|
|
901
912
|
identifier: this.toString()
|
|
@@ -915,13 +926,13 @@ w = new WeakSet(), I = function(t, ...n) {
|
|
|
915
926
|
return i === s;
|
|
916
927
|
}
|
|
917
928
|
}, j = new WeakSet(), be = function(t) {
|
|
918
|
-
const n =
|
|
929
|
+
const n = M(t) || "0";
|
|
919
930
|
this.bigIntValue = p(this, H, ee).call(this, n);
|
|
920
931
|
}, V = new WeakSet(), Z = function(...t) {
|
|
921
|
-
const n = t.map((r) => typeof r == "object" ? r.decimal ||
|
|
932
|
+
const n = t.map((r) => typeof r == "object" ? r.decimal || $(r.decimalMultiplier) : he(M(r))).filter(Boolean);
|
|
922
933
|
return Math.max(...n, B);
|
|
923
934
|
}, H = new WeakSet(), ee = function(t, n) {
|
|
924
|
-
const r = n ?
|
|
935
|
+
const r = n ? w(n) : this.decimalMultiplier, s = $(r), [i = "", o = ""] = t.split(".");
|
|
925
936
|
return BigInt(`${i}${o.padEnd(s, "0")}`);
|
|
926
937
|
};
|
|
927
938
|
let D = q;
|
|
@@ -929,7 +940,7 @@ const pt = Intl.NumberFormat("fullwide", {
|
|
|
929
940
|
useGrouping: !1,
|
|
930
941
|
maximumFractionDigits: 20
|
|
931
942
|
});
|
|
932
|
-
function
|
|
943
|
+
function M(e) {
|
|
933
944
|
const n = `${typeof e == "number" ? pt.format(e) : te(e)}`.replaceAll(",", ".").split(".");
|
|
934
945
|
return n.length > 1 ? `${n.slice(0, -1).join("")}.${n.at(-1)}` : n[0];
|
|
935
946
|
}
|
|
@@ -994,13 +1005,13 @@ class A extends D {
|
|
|
994
1005
|
if (!(s && i))
|
|
995
1006
|
throw new Error("Invalid asset url");
|
|
996
1007
|
const c = s === l.THORChain && o ? `${s}.${i}/${o}` : n;
|
|
997
|
-
return
|
|
1008
|
+
return J(c, r);
|
|
998
1009
|
}
|
|
999
1010
|
static fromString(n, r = 0) {
|
|
1000
|
-
return
|
|
1011
|
+
return J(n, r);
|
|
1001
1012
|
}
|
|
1002
1013
|
static fromIdentifier(n, r = 0) {
|
|
1003
|
-
return
|
|
1014
|
+
return J(n, r);
|
|
1004
1015
|
}
|
|
1005
1016
|
static fromStringSync(n, r = 0) {
|
|
1006
1017
|
const { chain: s, isSynthetic: i } = N(n), o = P.get(n.toUpperCase());
|
|
@@ -1078,7 +1089,7 @@ class A extends D {
|
|
|
1078
1089
|
);
|
|
1079
1090
|
}
|
|
1080
1091
|
}
|
|
1081
|
-
function
|
|
1092
|
+
function Bt(e) {
|
|
1082
1093
|
const t = A.fromChainOrSignature(e);
|
|
1083
1094
|
switch (e) {
|
|
1084
1095
|
case l.Bitcoin:
|
|
@@ -1099,7 +1110,7 @@ function It(e) {
|
|
|
1099
1110
|
return t.set(1e-8);
|
|
1100
1111
|
}
|
|
1101
1112
|
}
|
|
1102
|
-
async function
|
|
1113
|
+
async function J(e, t = 0) {
|
|
1103
1114
|
dt(e);
|
|
1104
1115
|
const n = P.get(e.toUpperCase()), r = (n == null ? void 0 : n.decimal) || await st(N(e));
|
|
1105
1116
|
return n || P.set(e.toUpperCase(), { identifier: e, decimal: r }), new A({ decimal: r, value: O(t, r), identifier: e });
|
|
@@ -1204,49 +1215,51 @@ const mt = {
|
|
|
1204
1215
|
*/
|
|
1205
1216
|
helpers_number_different_decimals: 99101
|
|
1206
1217
|
};
|
|
1207
|
-
class
|
|
1218
|
+
class we extends Error {
|
|
1208
1219
|
constructor(t, n) {
|
|
1209
1220
|
n && console.error(n, {
|
|
1210
1221
|
stack: n == null ? void 0 : n.stack,
|
|
1211
1222
|
message: n == null ? void 0 : n.message
|
|
1212
1223
|
}), super(t, {
|
|
1213
1224
|
cause: { code: mt[t], message: t }
|
|
1214
|
-
}), Object.setPrototypeOf(this,
|
|
1225
|
+
}), Object.setPrototypeOf(this, we.prototype);
|
|
1215
1226
|
}
|
|
1216
1227
|
}
|
|
1217
1228
|
export {
|
|
1218
|
-
|
|
1229
|
+
T as ApiEndpoints,
|
|
1219
1230
|
A as AssetValue,
|
|
1220
1231
|
D as BigIntArithmetics,
|
|
1221
|
-
|
|
1232
|
+
f as RequestClient,
|
|
1222
1233
|
Ze as StreamingSwapProgressStatus,
|
|
1223
1234
|
gt as SwapKitApi,
|
|
1224
|
-
|
|
1235
|
+
we as SwapKitError,
|
|
1225
1236
|
g as SwapKitNumber,
|
|
1226
1237
|
Qe as TransactionType,
|
|
1227
1238
|
ze as TxStatus,
|
|
1228
1239
|
Ct as assetFromString,
|
|
1229
1240
|
Ae as defaultRequestHeaders,
|
|
1230
|
-
|
|
1241
|
+
Nt as derivationPathToString,
|
|
1231
1242
|
St as filterAssets,
|
|
1232
1243
|
U as formatBigIntToSafeValue,
|
|
1233
1244
|
At as gasFeeMultiplier,
|
|
1234
1245
|
ot as getAssetType,
|
|
1235
1246
|
ut as getAsymmetricAssetShare,
|
|
1236
|
-
|
|
1247
|
+
wt as getAsymmetricAssetWithdrawAmount,
|
|
1237
1248
|
lt as getAsymmetricRuneShare,
|
|
1238
1249
|
bt as getAsymmetricRuneWithdrawAmount,
|
|
1239
1250
|
it as getCommonAssetInfo,
|
|
1240
1251
|
st as getDecimal,
|
|
1241
1252
|
Rt as getEstimatedPoolShare,
|
|
1242
1253
|
Et as getLiquiditySlippage,
|
|
1254
|
+
vt as getMAYANameCost,
|
|
1243
1255
|
Pt as getMemoFor,
|
|
1244
|
-
|
|
1256
|
+
Bt as getMinAmountByChain,
|
|
1245
1257
|
ht as getSymmetricPoolShare,
|
|
1246
|
-
|
|
1258
|
+
yt as getSymmetricWithdraw,
|
|
1247
1259
|
Ot as getTHORNameCost,
|
|
1248
1260
|
Se as isGasAsset,
|
|
1249
|
-
|
|
1261
|
+
Tt as setRequestClientConfig,
|
|
1262
|
+
It as validateMAYAName,
|
|
1250
1263
|
$t as validateTHORName
|
|
1251
1264
|
};
|
|
1252
1265
|
//# sourceMappingURL=index.es.js.map
|