@swapkit/helpers 1.0.0-rc.74 → 1.0.0-rc.76
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/LICENSE +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.es.js +196 -182
- package/dist/index.es.js.map +1 -1
- package/package.json +7 -7
- package/src/helpers/__tests__/memo.test.ts +11 -1
- package/src/helpers/asset.ts +1 -1
- package/src/helpers/others.ts +16 -0
- package/src/modules/bigIntArithmetics.ts +13 -12
- package/src/modules/swapKitError.ts +1 -1
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
var ve = (e, t, n) => t in e ?
|
|
3
|
-
var _ = (e, t, n) => (ve(e, typeof t != "symbol" ? t + "" : t, n), n),
|
|
1
|
+
var Ne = Object.defineProperty;
|
|
2
|
+
var ve = (e, t, n) => t in e ? Ne(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var _ = (e, t, n) => (ve(e, typeof t != "symbol" ? t + "" : t, n), n), $e = (e, t, n) => {
|
|
4
4
|
if (!t.has(e))
|
|
5
5
|
throw TypeError("Cannot " + n);
|
|
6
6
|
};
|
|
@@ -9,8 +9,8 @@ var R = (e, t, n) => {
|
|
|
9
9
|
throw TypeError("Cannot add the same private member more than once");
|
|
10
10
|
t instanceof WeakSet ? t.add(e) : t.set(e, n);
|
|
11
11
|
};
|
|
12
|
-
var p = (e, t, n) => (
|
|
13
|
-
import { FeeOption as K, BaseDecimal as d, Chain as
|
|
12
|
+
var p = (e, t, n) => ($e(e, t, "access private method"), n);
|
|
13
|
+
import { FeeOption as K, BaseDecimal as d, Chain as u, EVMChains as Ie, ChainToRPC as Be, MemoType as C, ChainToChainId as De } from "@swapkit/types";
|
|
14
14
|
var F = /* @__PURE__ */ ((e) => (e.Arbitrum = "ARB", e.Avalanche = "AVAX", e.Binance = "BNB", e.BinanceSmartChain = "BSC", e.Bitcoin = "BTC", e.BitcoinCash = "BCH", e.Cosmos = "GAIA", e.Dash = "DASH", e.Dogecoin = "DOGE", e.Ethereum = "ETH", e.Kujira = "KUJI", e.Litecoin = "LTC", e.Maya = "MAYA", e.Optimism = "OP", e.Polkadot = "DOT", e.Chainflip = "FLIP", e.Polygon = "MATIC", e.THORChain = "THOR", e))(F || {}), ne = /* @__PURE__ */ ((e) => (e.Arbitrum = "42161", e.ArbitrumHex = "0xa4b1", e.Avalanche = "43114", e.AvalancheHex = "0xa86a", e.Binance = "Binance-Chain-Tigris", e.BinanceSmartChain = "56", e.BinanceSmartChainHex = "0x38", e.Bitcoin = "bitcoin", e.BitcoinCash = "bitcoincash", e.Chainflip = "chainflip", e.Cosmos = "cosmoshub-4", e.Dash = "dash", e.Dogecoin = "dogecoin", e.Kujira = "kaiyo-1", e.Ethereum = "1", e.EthereumHex = "0x1", e.Litecoin = "litecoin", e.Maya = "mayachain-mainnet-v1", e.MayaStagenet = "mayachain-stagenet-v1", e.Optimism = "10", e.OptimismHex = "0xa", e.Polkadot = "polkadot", e.Polygon = "137", e.PolygonHex = "0x89", e.THORChain = "thorchain-mainnet-v1", e.THORChainStagenet = "thorchain-stagenet-v2", e))(ne || {}), de = /* @__PURE__ */ ((e) => (e.Arbitrum = "https://arb1.arbitrum.io/rpc", e.Avalanche = "https://node-router.thorswap.net/avalanche-c", e.Binance = "", e.BinanceSmartChain = "https://bsc-dataseed.binance.org", e.Bitcoin = "https://node-router.thorswap.net/bitcoin", e.BitcoinCash = "https://node-router.thorswap.net/bitcoin-cash", e.Chainflip = "wss://mainnet-archive.chainflip.io", e.Cosmos = "https://node-router.thorswap.net/cosmos/rpc", e.Dash = "https://node-router.thorswap.net/dash", e.Dogecoin = "https://node-router.thorswap.net/dogecoin", e.Ethereum = "https://node-router.thorswap.net/ethereum", e.Kujira = "https://rpc-kujira.synergynodes.com/", e.Litecoin = "https://node-router.thorswap.net/litecoin", e.Maya = "https://tendermint.mayachain.info", e.MayaStagenet = "https://stagenet.tendermint.mayachain.info", e.Optimism = "https://mainnet.optimism.io", e.Polkadot = "wss://rpc.polkadot.io", e.Polygon = "https://polygon-rpc.com", e.THORChain = "https://rpc.thorswap.net", e.THORChainStagenet = "https://stagenet-rpc.ninerealms.com", e))(de || {}), S = /* @__PURE__ */ ((e) => (e.Cosmos = "https://node-router.thorswap.net/cosmos/rest", e.Kujira = "https://lcd-kujira.synergynodes.com/", e.MayanodeMainnet = "https://mayanode.mayachain.info", e.MayanodeStagenet = "https://stagenet.mayanode.mayachain.info", e.ThornodeMainnet = "https://thornode.thorswap.net", e.ThornodeStagenet = "https://stagenet-thornode.ninerealms.com", e.ThorswapApi = "https://api.thorswap.net", e.ThorswapStatic = "https://static.thorswap.net", e))(S || {});
|
|
15
15
|
const G = Object.values(F), Ve = Object.keys(F), re = G.reduce(
|
|
16
16
|
(e, t) => {
|
|
@@ -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
|
}
|
|
@@ -223,7 +223,7 @@ class W {
|
|
|
223
223
|
}
|
|
224
224
|
// eslint-disable-next-line complexity
|
|
225
225
|
constructor(t, n = {}) {
|
|
226
|
-
|
|
226
|
+
Object.defineProperty(this, "request", {
|
|
227
227
|
enumerable: !0,
|
|
228
228
|
configurable: !0,
|
|
229
229
|
writable: !0,
|
|
@@ -248,9 +248,10 @@ class W {
|
|
|
248
248
|
configurable: !0,
|
|
249
249
|
writable: !0,
|
|
250
250
|
value: void 0
|
|
251
|
-
}), this._input = t
|
|
252
|
-
|
|
253
|
-
|
|
251
|
+
}), this._input = t;
|
|
252
|
+
const r = "credentials" in Request.prototype;
|
|
253
|
+
if (this._options = {
|
|
254
|
+
credentials: r ? this._input.credentials : void 0,
|
|
254
255
|
...n,
|
|
255
256
|
headers: me(this._input.headers, n.headers),
|
|
256
257
|
hooks: se({
|
|
@@ -275,16 +276,16 @@ class W {
|
|
|
275
276
|
}
|
|
276
277
|
if (xe) {
|
|
277
278
|
if (this.abortController = new globalThis.AbortController(), this._options.signal) {
|
|
278
|
-
const
|
|
279
|
+
const s = this._options.signal;
|
|
279
280
|
this._options.signal.addEventListener("abort", () => {
|
|
280
|
-
this.abortController.abort(
|
|
281
|
+
this.abortController.abort(s.reason);
|
|
281
282
|
});
|
|
282
283
|
}
|
|
283
284
|
this._options.signal = this.abortController.signal;
|
|
284
285
|
}
|
|
285
286
|
if (He && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
|
|
286
|
-
const
|
|
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
|
+
(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(i, { ...this.request }), this._options);
|
|
288
289
|
}
|
|
289
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 }));
|
|
290
291
|
}
|
|
@@ -313,7 +314,7 @@ class W {
|
|
|
313
314
|
try {
|
|
314
315
|
return await t();
|
|
315
316
|
} catch (n) {
|
|
316
|
-
const r = Math.min(this._calculateRetryDelay(n),
|
|
317
|
+
const r = Math.min(this._calculateRetryDelay(n), Y);
|
|
317
318
|
if (r !== 0 && this._retryCount > 0) {
|
|
318
319
|
await Ke(r, { signal: this._options.signal });
|
|
319
320
|
for (const s of this._options.hooks.beforeRetry)
|
|
@@ -322,7 +323,7 @@ class W {
|
|
|
322
323
|
options: this._options,
|
|
323
324
|
error: n,
|
|
324
325
|
retryCount: this._retryCount
|
|
325
|
-
}) ===
|
|
326
|
+
}) === fe)
|
|
326
327
|
return;
|
|
327
328
|
return this._retry(t);
|
|
328
329
|
}
|
|
@@ -339,7 +340,7 @@ class W {
|
|
|
339
340
|
if (r instanceof Response)
|
|
340
341
|
return r;
|
|
341
342
|
}
|
|
342
|
-
const t =
|
|
343
|
+
const t = Ye(this.request, this._options);
|
|
343
344
|
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Xe(this.request.clone(), t, this.abortController, this._options);
|
|
344
345
|
}
|
|
345
346
|
/* istanbul ignore next */
|
|
@@ -355,17 +356,17 @@ class W {
|
|
|
355
356
|
const o = t.body.getReader();
|
|
356
357
|
n && n({ percent: 0, transferredBytes: 0, totalBytes: r }, new Uint8Array());
|
|
357
358
|
async function c() {
|
|
358
|
-
const { done: a, value:
|
|
359
|
+
const { done: a, value: l } = await o.read();
|
|
359
360
|
if (a) {
|
|
360
361
|
i.close();
|
|
361
362
|
return;
|
|
362
363
|
}
|
|
363
364
|
if (n) {
|
|
364
|
-
s +=
|
|
365
|
+
s += l.byteLength;
|
|
365
366
|
const h = r === 0 ? 0 : s / r;
|
|
366
|
-
n({ percent: h, transferredBytes: s, totalBytes: r },
|
|
367
|
+
n({ percent: h, transferredBytes: s, totalBytes: r }, l);
|
|
367
368
|
}
|
|
368
|
-
i.enqueue(
|
|
369
|
+
i.enqueue(l), await c();
|
|
369
370
|
}
|
|
370
371
|
await c();
|
|
371
372
|
}
|
|
@@ -381,10 +382,10 @@ const z = (e) => {
|
|
|
381
382
|
const t = (n, r) => W.create(n, x(e, r));
|
|
382
383
|
for (const n of _e)
|
|
383
384
|
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 =
|
|
385
|
+
return t.create = (n) => z(x(n)), t.extend = (n) => z(x(e, n)), t.stop = fe, t;
|
|
385
386
|
}, ge = z();
|
|
386
387
|
let L;
|
|
387
|
-
const
|
|
388
|
+
const T = {
|
|
388
389
|
CachedPrices: `${S.ThorswapApi}/tokenlist/cached-price`,
|
|
389
390
|
GasRates: `${S.ThorswapApi}/resource-worker/gasPrice/getAll`,
|
|
390
391
|
Quote: `${S.ThorswapApi}/aggregator/tokens/quote`,
|
|
@@ -392,39 +393,39 @@ const f = {
|
|
|
392
393
|
TokenlistProviders: `${S.ThorswapApi}/tokenlist/providers`,
|
|
393
394
|
TokenList: `${S.ThorswapStatic}/token-list`,
|
|
394
395
|
Thorname: `${S.ThorswapApi}/thorname`
|
|
395
|
-
}, Ae = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" },
|
|
396
|
+
}, Ae = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, ue = () => L || (L = ge.create({ headers: Ae }), L), Tt = ({ apiKey: e, ...t }) => {
|
|
396
397
|
L = ge.create({
|
|
397
398
|
...t,
|
|
398
399
|
headers: { ...Ae, ...t.headers, "x-api-key": e }
|
|
399
400
|
});
|
|
400
|
-
},
|
|
401
|
-
get: (e, t) =>
|
|
402
|
-
post: (e, t) =>
|
|
403
|
-
},
|
|
401
|
+
}, f = {
|
|
402
|
+
get: (e, t) => ue().get(e, t).json(),
|
|
403
|
+
post: (e, t) => ue().post(e, t).json()
|
|
404
|
+
}, Je = ({ tokens: e, ...t }) => {
|
|
404
405
|
const n = new URLSearchParams(), r = e.filter(
|
|
405
406
|
(s, i, o) => o.findIndex((c) => c === s) === i
|
|
406
407
|
);
|
|
407
408
|
for (const s of r)
|
|
408
409
|
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"),
|
|
410
|
+
return t.metadata && n.append("metadata", "true"), t.lookup && n.append("lookup", "true"), t.sparkline && n.append("sparkline", "true"), f.post(T.CachedPrices, {
|
|
410
411
|
body: n.toString(),
|
|
411
412
|
headers: { "Content-Type": "application/x-www-form-urlencoded" }
|
|
412
413
|
});
|
|
413
414
|
}, 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) =>
|
|
415
|
+
getCachedPrices: Je,
|
|
416
|
+
getQuote: (e) => f.get(T.Quote, { searchParams: e }),
|
|
417
|
+
getGasRates: () => f.get(T.GasRates),
|
|
418
|
+
getTxnDetails: (e) => f.get(T.Txn, { searchParams: e }),
|
|
419
|
+
getTokenlistProviders: () => f.get(T.TokenlistProviders),
|
|
420
|
+
getTokenList: (e) => f.get(`${T.TokenList}/${e}.json`),
|
|
421
|
+
getThornameAddresses: (e) => f.get(`${T.Thorname}/${e}`),
|
|
422
|
+
getThornameRegisteredChains: (e) => f.get(`${T.Thorname}/chains/${e}`),
|
|
423
|
+
getThornameRlookup: (e, t) => f.get(`${T.Thorname}/rlookup`, { searchParams: { address: e, chain: t } })
|
|
423
424
|
};
|
|
424
425
|
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
426
|
const et = "0x313ce567", Ce = async ({ chain: e, to: t }) => {
|
|
426
427
|
try {
|
|
427
|
-
const { result: n } = await
|
|
428
|
+
const { result: n } = await f.post(Be[e], {
|
|
428
429
|
headers: {
|
|
429
430
|
accept: "*/*",
|
|
430
431
|
"content-type": "application/json",
|
|
@@ -437,25 +438,25 @@ const et = "0x313ce567", Ce = async ({ chain: e, to: t }) => {
|
|
|
437
438
|
params: [{ to: t.toLowerCase(), data: et }, "latest"]
|
|
438
439
|
})
|
|
439
440
|
});
|
|
440
|
-
return parseInt(BigInt(n).toString());
|
|
441
|
+
return Number.parseInt(BigInt(n).toString());
|
|
441
442
|
} catch (n) {
|
|
442
443
|
return console.error(n), d[e];
|
|
443
444
|
}
|
|
444
445
|
}, tt = (e) => {
|
|
445
|
-
if (e ===
|
|
446
|
+
if (e === u.Ethereum)
|
|
446
447
|
return d.ETH;
|
|
447
448
|
const [, t] = e.split("-");
|
|
448
|
-
return t != null && t.startsWith("0x") ? Ce({ chain:
|
|
449
|
+
return t != null && t.startsWith("0x") ? Ce({ chain: u.Ethereum, to: t }) : d.ETH;
|
|
449
450
|
}, nt = (e) => {
|
|
450
451
|
const [, t] = e.split("-");
|
|
451
|
-
return t != null && t.startsWith("0x") ? Ce({ chain:
|
|
452
|
-
}, rt = (e) => e ===
|
|
452
|
+
return t != null && t.startsWith("0x") ? Ce({ chain: u.Avalanche, to: t.toLowerCase() }) : d.AVAX;
|
|
453
|
+
}, rt = (e) => e === u.BinanceSmartChain ? d.BSC : d.BSC, st = ({ chain: e, symbol: t }) => {
|
|
453
454
|
switch (e) {
|
|
454
|
-
case
|
|
455
|
+
case u.Ethereum:
|
|
455
456
|
return tt(t);
|
|
456
|
-
case
|
|
457
|
+
case u.Avalanche:
|
|
457
458
|
return nt(t);
|
|
458
|
-
case
|
|
459
|
+
case u.BinanceSmartChain:
|
|
459
460
|
return rt(t);
|
|
460
461
|
default:
|
|
461
462
|
return d[e];
|
|
@@ -466,42 +467,42 @@ const et = "0x313ce567", Ce = async ({ chain: e, to: t }) => {
|
|
|
466
467
|
[K.Fastest]: 2
|
|
467
468
|
}, Se = ({ chain: e, symbol: t }) => {
|
|
468
469
|
switch (e) {
|
|
469
|
-
case
|
|
470
|
-
case
|
|
470
|
+
case u.Arbitrum:
|
|
471
|
+
case u.Optimism:
|
|
471
472
|
return t === "ETH";
|
|
472
|
-
case
|
|
473
|
+
case u.Maya:
|
|
473
474
|
return t === "CACAO";
|
|
474
|
-
case
|
|
475
|
+
case u.Kujira:
|
|
475
476
|
return t === "KUJI";
|
|
476
|
-
case
|
|
477
|
+
case u.Cosmos:
|
|
477
478
|
return t === "ATOM";
|
|
478
|
-
case
|
|
479
|
+
case u.Polygon:
|
|
479
480
|
return t === "MATIC";
|
|
480
|
-
case
|
|
481
|
+
case u.BinanceSmartChain:
|
|
481
482
|
return t === "BNB";
|
|
482
|
-
case
|
|
483
|
+
case u.THORChain:
|
|
483
484
|
return t === "RUNE";
|
|
484
485
|
default:
|
|
485
486
|
return t === e;
|
|
486
487
|
}
|
|
487
488
|
}, it = (e) => {
|
|
488
489
|
switch (e) {
|
|
489
|
-
case `${
|
|
490
|
+
case `${u.Ethereum}.THOR`:
|
|
490
491
|
return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
|
|
491
|
-
case `${
|
|
492
|
+
case `${u.Ethereum}.vTHOR`:
|
|
492
493
|
return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
|
|
493
|
-
case
|
|
494
|
+
case u.Cosmos:
|
|
494
495
|
return { identifier: "GAIA.ATOM", decimal: d[e] };
|
|
495
|
-
case
|
|
496
|
+
case u.THORChain:
|
|
496
497
|
return { identifier: "THOR.RUNE", decimal: d[e] };
|
|
497
|
-
case
|
|
498
|
+
case u.BinanceSmartChain:
|
|
498
499
|
return { identifier: "BSC.BNB", decimal: d[e] };
|
|
499
|
-
case
|
|
500
|
+
case u.Maya:
|
|
500
501
|
return { identifier: "MAYA.CACAO", decimal: d.MAYA };
|
|
501
|
-
case `${
|
|
502
|
+
case `${u.Maya}.MAYA`:
|
|
502
503
|
return { identifier: "MAYA.MAYA", decimal: 4 };
|
|
503
|
-
case `${
|
|
504
|
-
return { identifier: `${
|
|
504
|
+
case `${u.Kujira}.USK`:
|
|
505
|
+
return { identifier: `${u.Kujira}.USK`, decimal: 6 };
|
|
505
506
|
default:
|
|
506
507
|
return { identifier: `${e}.${e}`, decimal: d[e] };
|
|
507
508
|
}
|
|
@@ -509,24 +510,24 @@ const et = "0x313ce567", Ce = async ({ chain: e, to: t }) => {
|
|
|
509
510
|
if (t.includes("/"))
|
|
510
511
|
return "Synth";
|
|
511
512
|
switch (e) {
|
|
512
|
-
case
|
|
513
|
-
return t === "ATOM" ? "Native" :
|
|
514
|
-
case
|
|
515
|
-
return t ===
|
|
516
|
-
case
|
|
517
|
-
return t ===
|
|
518
|
-
case
|
|
519
|
-
return t ===
|
|
520
|
-
case
|
|
521
|
-
return t ===
|
|
522
|
-
case
|
|
523
|
-
return t ===
|
|
524
|
-
case
|
|
525
|
-
return t ===
|
|
526
|
-
case
|
|
527
|
-
return [
|
|
528
|
-
case
|
|
529
|
-
return [
|
|
513
|
+
case u.Cosmos:
|
|
514
|
+
return t === "ATOM" ? "Native" : u.Cosmos;
|
|
515
|
+
case u.Kujira:
|
|
516
|
+
return t === u.Kujira ? "Native" : u.Kujira;
|
|
517
|
+
case u.Binance:
|
|
518
|
+
return t === u.Binance ? "Native" : "BEP2";
|
|
519
|
+
case u.BinanceSmartChain:
|
|
520
|
+
return t === u.Binance ? "Native" : "BEP20";
|
|
521
|
+
case u.Ethereum:
|
|
522
|
+
return t === u.Ethereum ? "Native" : "ERC20";
|
|
523
|
+
case u.Avalanche:
|
|
524
|
+
return t === u.Avalanche ? "Native" : u.Avalanche;
|
|
525
|
+
case u.Polygon:
|
|
526
|
+
return t === u.Polygon ? "Native" : "POLYGON";
|
|
527
|
+
case u.Arbitrum:
|
|
528
|
+
return [u.Ethereum, u.Arbitrum].includes(t) ? "Native" : "ARBITRUM";
|
|
529
|
+
case u.Optimism:
|
|
530
|
+
return [u.Ethereum, u.Optimism].includes(t) ? "Native" : "OPTIMISM";
|
|
530
531
|
default:
|
|
531
532
|
return "Native";
|
|
532
533
|
}
|
|
@@ -539,7 +540,7 @@ const et = "0x313ce567", Ce = async ({ chain: e, to: t }) => {
|
|
|
539
540
|
"gmi"
|
|
540
541
|
), ct = (e) => {
|
|
541
542
|
const [t, n] = e.split(".");
|
|
542
|
-
if (!
|
|
543
|
+
if (!Ie.includes(t))
|
|
543
544
|
return !0;
|
|
544
545
|
const [, r] = n.split("-");
|
|
545
546
|
return Se({ chain: t, symbol: n }) || !!r;
|
|
@@ -547,21 +548,21 @@ const et = "0x313ce567", Ce = async ({ chain: e, to: t }) => {
|
|
|
547
548
|
const s = `${t}.${r}`;
|
|
548
549
|
return !at.test(s) && ct(s) && n !== "0";
|
|
549
550
|
});
|
|
550
|
-
function
|
|
551
|
+
function ut({
|
|
551
552
|
liquidityUnits: e,
|
|
552
553
|
poolUnits: t,
|
|
553
554
|
runeDepth: n
|
|
554
555
|
}) {
|
|
555
|
-
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),
|
|
556
|
-
return o.mul(c.sub(a).add(
|
|
556
|
+
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 = s.mul(s).mul(s);
|
|
557
|
+
return o.mul(c.sub(a).add(l)).div(h);
|
|
557
558
|
}
|
|
558
|
-
function
|
|
559
|
+
function lt({
|
|
559
560
|
liquidityUnits: e,
|
|
560
561
|
poolUnits: t,
|
|
561
562
|
assetDepth: n
|
|
562
563
|
}) {
|
|
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),
|
|
564
|
-
return h.div(
|
|
564
|
+
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
|
+
return h.div(N);
|
|
565
566
|
}
|
|
566
567
|
function bt({
|
|
567
568
|
percent: e,
|
|
@@ -569,7 +570,7 @@ function bt({
|
|
|
569
570
|
liquidityUnits: n,
|
|
570
571
|
poolUnits: r
|
|
571
572
|
}) {
|
|
572
|
-
return
|
|
573
|
+
return ut({ runeDepth: t, liquidityUnits: n, poolUnits: r }).mul(e);
|
|
573
574
|
}
|
|
574
575
|
function yt({
|
|
575
576
|
percent: e,
|
|
@@ -577,7 +578,7 @@ function yt({
|
|
|
577
578
|
liquidityUnits: n,
|
|
578
579
|
poolUnits: r
|
|
579
580
|
}) {
|
|
580
|
-
return
|
|
581
|
+
return lt({ assetDepth: t, liquidityUnits: n, poolUnits: r }).mul(e);
|
|
581
582
|
}
|
|
582
583
|
function m(e) {
|
|
583
584
|
return g.fromBigInt(BigInt(e), d.THOR);
|
|
@@ -614,7 +615,7 @@ function Rt({
|
|
|
614
615
|
runeAmount: s,
|
|
615
616
|
assetAmount: i
|
|
616
617
|
}) {
|
|
617
|
-
const o = new g({ value: e, decimal: 8 }), c = new g({ value: n, decimal: 8 }), a = new g({ value: t, decimal: 8 }),
|
|
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), we = l.mul(h), Re = o.mul(c), Ee = a.mul(N.add(ie.add(we.mul(2)))), Pe = N.add(ie.add(Re.mul(2))), oe = Ee.div(Pe), X = m(r).add(oe);
|
|
618
619
|
if (oe.getBaseValue("number") === 0)
|
|
619
620
|
return X.div(a).getBaseValue("number");
|
|
620
621
|
const Oe = a.add(X);
|
|
@@ -628,8 +629,8 @@ function Et({
|
|
|
628
629
|
}) {
|
|
629
630
|
if (e === "0" || t === "0" || n === "0" || r === "0")
|
|
630
631
|
return 0;
|
|
631
|
-
const s = m(n), i = m(r), o = m(t), c = m(e), a = o.mul(s).sub(i.mul(c)),
|
|
632
|
-
return Math.abs(a.div(
|
|
632
|
+
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
|
+
return Math.abs(a.div(l).getBaseValue("number"));
|
|
633
634
|
}
|
|
634
635
|
const Pt = (e, t) => {
|
|
635
636
|
switch (e) {
|
|
@@ -650,11 +651,11 @@ const Pt = (e, t) => {
|
|
|
650
651
|
const { chain: n, symbol: r, address: s, singleSide: i } = t;
|
|
651
652
|
return i ? `${e}:${n}/${r}` : `${e}:${((c, a) => {
|
|
652
653
|
switch (c) {
|
|
653
|
-
case
|
|
654
|
+
case u.Litecoin:
|
|
654
655
|
return "l";
|
|
655
|
-
case
|
|
656
|
+
case u.Dogecoin:
|
|
656
657
|
return "d";
|
|
657
|
-
case
|
|
658
|
+
case u.BitcoinCash:
|
|
658
659
|
return "c";
|
|
659
660
|
default:
|
|
660
661
|
return `${c}.${a}`;
|
|
@@ -662,8 +663,8 @@ const Pt = (e, t) => {
|
|
|
662
663
|
})(n, r)}:${s || ""}`;
|
|
663
664
|
}
|
|
664
665
|
case C.WITHDRAW: {
|
|
665
|
-
const { chain: n, ticker: r, symbol: s, basisPoints: i, targetAssetString: o, singleSide: c } = t, a = n === "ETH" && r !== "ETH" ? `${r}-${s.slice(-3)}` : s,
|
|
666
|
-
return `${e}:${n}${c ? "/" : "."}${a}:${i}${
|
|
666
|
+
const { chain: n, ticker: r, symbol: s, basisPoints: i, targetAssetString: o, singleSide: c } = t, a = n === "ETH" && r !== "ETH" ? `${r}-${s.slice(-3)}` : s, l = !c && o ? `:${o}` : "";
|
|
667
|
+
return `${e}:${n}${c ? "/" : "."}${a}:${i}${l}`;
|
|
667
668
|
}
|
|
668
669
|
case C.OPEN_LOAN:
|
|
669
670
|
case C.CLOSE_LOAN: {
|
|
@@ -679,28 +680,39 @@ function Ot(e) {
|
|
|
679
680
|
throw new Error("Invalid number of year");
|
|
680
681
|
return 10 + e;
|
|
681
682
|
}
|
|
683
|
+
function Nt(e) {
|
|
684
|
+
if (e < 0)
|
|
685
|
+
throw new Error("Invalid number of year");
|
|
686
|
+
return Math.round((10 + e * 1.0512) * 1e10) / 1e10;
|
|
687
|
+
}
|
|
688
|
+
function vt(e) {
|
|
689
|
+
if (e.length > 30)
|
|
690
|
+
return !1;
|
|
691
|
+
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
692
|
+
return !!e.match(t);
|
|
693
|
+
}
|
|
682
694
|
function $t(e) {
|
|
683
695
|
if (e.length > 30)
|
|
684
696
|
return !1;
|
|
685
697
|
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
686
698
|
return !!e.match(t);
|
|
687
699
|
}
|
|
688
|
-
function
|
|
700
|
+
function It([e, t, n, r, s]) {
|
|
689
701
|
return `${e}'/${t}'/${n}'/${r}${typeof s != "number" ? "" : `/${s}`}`;
|
|
690
702
|
}
|
|
691
|
-
const
|
|
703
|
+
const le = [...Object.values(u), "TERRA"];
|
|
692
704
|
function dt(e = "") {
|
|
693
705
|
const t = e.toUpperCase(), [n] = t.split(".");
|
|
694
|
-
if (
|
|
706
|
+
if (le.includes(n))
|
|
695
707
|
return !0;
|
|
696
708
|
const [r] = t.split("/");
|
|
697
|
-
if (
|
|
709
|
+
if (le.includes(r))
|
|
698
710
|
return !0;
|
|
699
711
|
throw new Error(
|
|
700
712
|
`Invalid identifier: ${e}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
701
713
|
);
|
|
702
714
|
}
|
|
703
|
-
const B = 8, y = (e) => 10n ** BigInt(e), v = (e) => Math.log10(parseFloat(e.toString()));
|
|
715
|
+
const B = 8, y = (e) => 10n ** BigInt(e), v = (e) => Math.log10(Number.parseFloat(e.toString()));
|
|
704
716
|
function U({
|
|
705
717
|
value: e,
|
|
706
718
|
bigIntDecimal: t = B,
|
|
@@ -714,12 +726,12 @@ function U({
|
|
|
714
726
|
i > 0 && (s = "0".repeat(i) + s);
|
|
715
727
|
const o = s.length - n;
|
|
716
728
|
let c = s.slice(-n);
|
|
717
|
-
return parseInt(c[t]) >= 5 ? c = `${c.substring(0, t - 1)}${(parseInt(c[t - 1]) + 1).toString()}` : c = c.substring(0, t), `${r ? "-" : ""}${s.slice(0, o)}.${c}`.replace(
|
|
729
|
+
return Number.parseInt(c[t]) >= 5 ? c = `${c.substring(0, t - 1)}${(Number.parseInt(c[t - 1]) + 1).toString()}` : c = c.substring(0, t), `${r ? "-" : ""}${s.slice(0, o)}.${c}`.replace(
|
|
718
730
|
/\.?0*$/,
|
|
719
731
|
""
|
|
720
732
|
);
|
|
721
733
|
}
|
|
722
|
-
var w,
|
|
734
|
+
var w, $, b, E, j, be, V, Z, H, ee;
|
|
723
735
|
const q = class q {
|
|
724
736
|
constructor(t) {
|
|
725
737
|
R(this, w);
|
|
@@ -731,7 +743,7 @@ const q = class q {
|
|
|
731
743
|
_(this, "bigIntValue", 0n);
|
|
732
744
|
_(this, "decimal");
|
|
733
745
|
const n = te(t), r = typeof t == "object";
|
|
734
|
-
this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier : y(Math.max(he(
|
|
746
|
+
this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier : y(Math.max(he(M(n)), this.decimal || 0)), p(this, j, be).call(this, n);
|
|
735
747
|
}
|
|
736
748
|
static fromBigInt(t, n) {
|
|
737
749
|
return new q({
|
|
@@ -753,16 +765,16 @@ const q = class q {
|
|
|
753
765
|
return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
|
|
754
766
|
}
|
|
755
767
|
add(...t) {
|
|
756
|
-
return p(this, w,
|
|
768
|
+
return p(this, w, $).call(this, "add", ...t);
|
|
757
769
|
}
|
|
758
770
|
sub(...t) {
|
|
759
|
-
return p(this, w,
|
|
771
|
+
return p(this, w, $).call(this, "sub", ...t);
|
|
760
772
|
}
|
|
761
773
|
mul(...t) {
|
|
762
|
-
return p(this, w,
|
|
774
|
+
return p(this, w, $).call(this, "mul", ...t);
|
|
763
775
|
}
|
|
764
776
|
div(...t) {
|
|
765
|
-
return p(this, w,
|
|
777
|
+
return p(this, w, $).call(this, "div", ...t);
|
|
766
778
|
}
|
|
767
779
|
gt(t) {
|
|
768
780
|
return p(this, b, E).call(this, "gt", t);
|
|
@@ -809,21 +821,21 @@ const q = class q {
|
|
|
809
821
|
getBigIntValue(t, n) {
|
|
810
822
|
if (!n && typeof t == "object")
|
|
811
823
|
return t.bigIntValue;
|
|
812
|
-
const r = te(t), s =
|
|
824
|
+
const r = te(t), s = M(r);
|
|
813
825
|
return s === "0" || s === "undefined" ? 0n : p(this, H, ee).call(this, s, n);
|
|
814
826
|
}
|
|
815
827
|
toSignificant(t = 6) {
|
|
816
828
|
const [n, r] = this.getValue("string").split("."), s = n || "", i = r || "";
|
|
817
|
-
if ((parseInt(s) ? s.length + i.length : i.length) <= t)
|
|
829
|
+
if ((Number.parseInt(s) ? s.length + i.length : i.length) <= t)
|
|
818
830
|
return this.getValue("string");
|
|
819
831
|
if (s.length >= t)
|
|
820
832
|
return s.slice(0, t).padEnd(s.length, "0");
|
|
821
|
-
if (parseInt(s))
|
|
833
|
+
if (Number.parseInt(s))
|
|
822
834
|
return `${s}.${i.slice(0, t - s.length)}`.padEnd(
|
|
823
835
|
t - s.length,
|
|
824
836
|
"0"
|
|
825
837
|
);
|
|
826
|
-
const c = parseInt(i), a = `${c}`.slice(0, t);
|
|
838
|
+
const c = Number.parseInt(i), a = `${c}`.slice(0, t);
|
|
827
839
|
return `0.${a.padStart(
|
|
828
840
|
i.length - `${c}`.length + a.length,
|
|
829
841
|
"0"
|
|
@@ -831,9 +843,9 @@ const q = class q {
|
|
|
831
843
|
}
|
|
832
844
|
toFixed(t = 6) {
|
|
833
845
|
const [n, r] = this.getValue("string").split("."), s = n || "", i = r || "";
|
|
834
|
-
if (parseInt(s))
|
|
846
|
+
if (Number.parseInt(s))
|
|
835
847
|
return `${s}.${i.slice(0, t)}`.padEnd(t, "0");
|
|
836
|
-
const o = parseInt(i), c = `${o}`.slice(0, t);
|
|
848
|
+
const o = Number.parseInt(i), c = `${o}`.slice(0, t);
|
|
837
849
|
return `0.${c.padStart(
|
|
838
850
|
i.length - `${o}`.length + c.length,
|
|
839
851
|
"0"
|
|
@@ -852,25 +864,25 @@ const q = class q {
|
|
|
852
864
|
decimalSeparator: s = ".",
|
|
853
865
|
thousandSeparator: i = ","
|
|
854
866
|
} = {}) {
|
|
855
|
-
const o = this.getValue("number"), [c, a = ""] = o.toFixed(6).split("."),
|
|
867
|
+
const o = this.getValue("number"), [c, a = ""] = o.toFixed(6).split("."), l = c.replace(/\B(?=(\d{3})+(?!\d))/g, i), h = c || a ? c === "0" ? `${Number.parseFloat(`0.${a}`)}`.replace(".", s) : `${l}${Number.parseInt(a) ? `${s}${a.slice(0, r)}` : ""}` : "0.00";
|
|
856
868
|
return `${n === "start" ? t : ""}${h}${n === "end" ? t : ""}`;
|
|
857
869
|
}
|
|
858
870
|
formatBigIntToSafeValue(t, n) {
|
|
859
871
|
const r = n || this.decimal || B, s = Math.max(
|
|
860
872
|
r,
|
|
861
873
|
v(this.decimalMultiplier)
|
|
862
|
-
), i = t < 0n, o = t.toString().substring(i ? 1 : 0), c = s - (o.length - 1), a = c > 0 ? "0".repeat(c) + o : o,
|
|
874
|
+
), i = t < 0n, o = t.toString().substring(i ? 1 : 0), c = s - (o.length - 1), a = c > 0 ? "0".repeat(c) + o : o, l = a.length - s;
|
|
863
875
|
let h = a.slice(-s);
|
|
864
|
-
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(
|
|
876
|
+
return Number.parseInt(h[r]) >= 5 ? h = `${h.substring(0, r - 1)}${(Number.parseInt(h[r - 1]) + 1).toString()}` : h = h.substring(0, r), `${i ? "-" : ""}${a.slice(
|
|
865
877
|
0,
|
|
866
|
-
|
|
878
|
+
l
|
|
867
879
|
)}.${h}`.replace(/\.?0*$/, "");
|
|
868
880
|
}
|
|
869
881
|
};
|
|
870
|
-
w = new WeakSet(),
|
|
882
|
+
w = new WeakSet(), $ = function(t, ...n) {
|
|
871
883
|
const r = p(this, V, Z).call(this, this, ...n), s = Math.max(r, v(this.decimalMultiplier)), i = y(s), o = n.reduce(
|
|
872
|
-
(a,
|
|
873
|
-
const h = this.getBigIntValue(
|
|
884
|
+
(a, l) => {
|
|
885
|
+
const h = this.getBigIntValue(l, s);
|
|
874
886
|
switch (t) {
|
|
875
887
|
case "add":
|
|
876
888
|
return a + h;
|
|
@@ -915,10 +927,10 @@ w = new WeakSet(), I = function(t, ...n) {
|
|
|
915
927
|
return i === s;
|
|
916
928
|
}
|
|
917
929
|
}, j = new WeakSet(), be = function(t) {
|
|
918
|
-
const n =
|
|
930
|
+
const n = M(t) || "0";
|
|
919
931
|
this.bigIntValue = p(this, H, ee).call(this, n);
|
|
920
932
|
}, V = new WeakSet(), Z = function(...t) {
|
|
921
|
-
const n = t.map((r) => typeof r == "object" ? r.decimal || v(r.decimalMultiplier) : he(
|
|
933
|
+
const n = t.map((r) => typeof r == "object" ? r.decimal || v(r.decimalMultiplier) : he(M(r))).filter(Boolean);
|
|
922
934
|
return Math.max(...n, B);
|
|
923
935
|
}, H = new WeakSet(), ee = function(t, n) {
|
|
924
936
|
const r = n ? y(n) : this.decimalMultiplier, s = v(r), [i = "", o = ""] = t.split(".");
|
|
@@ -929,7 +941,7 @@ const pt = Intl.NumberFormat("fullwide", {
|
|
|
929
941
|
useGrouping: !1,
|
|
930
942
|
maximumFractionDigits: 20
|
|
931
943
|
});
|
|
932
|
-
function
|
|
944
|
+
function M(e) {
|
|
933
945
|
const n = `${typeof e == "number" ? pt.format(e) : te(e)}`.replaceAll(",", ".").split(".");
|
|
934
946
|
return n.length > 1 ? `${n.slice(0, -1).join("")}.${n.at(-1)}` : n[0];
|
|
935
947
|
}
|
|
@@ -971,7 +983,7 @@ class A extends D {
|
|
|
971
983
|
_(this, "tax");
|
|
972
984
|
_(this, "ticker");
|
|
973
985
|
_(this, "type");
|
|
974
|
-
const a =
|
|
986
|
+
const a = I(c || `${i}.${o}`);
|
|
975
987
|
this.type = ot(a), this.tax = s, this.chain = a.chain, this.ticker = a.ticker, this.symbol = a.symbol, this.address = a.address, this.isSynthetic = a.isSynthetic, this.isGasAsset = a.isGasAsset;
|
|
976
988
|
}
|
|
977
989
|
toString() {
|
|
@@ -993,27 +1005,27 @@ class A extends D {
|
|
|
993
1005
|
const [s, i, o] = n.split(".");
|
|
994
1006
|
if (!(s && i))
|
|
995
1007
|
throw new Error("Invalid asset url");
|
|
996
|
-
const c = s ===
|
|
997
|
-
return
|
|
1008
|
+
const c = s === u.THORChain && o ? `${s}.${i}/${o}` : n;
|
|
1009
|
+
return J(c, r);
|
|
998
1010
|
}
|
|
999
1011
|
static fromString(n, r = 0) {
|
|
1000
|
-
return
|
|
1012
|
+
return J(n, r);
|
|
1001
1013
|
}
|
|
1002
1014
|
static fromIdentifier(n, r = 0) {
|
|
1003
|
-
return
|
|
1015
|
+
return J(n, r);
|
|
1004
1016
|
}
|
|
1005
1017
|
static fromStringSync(n, r = 0) {
|
|
1006
|
-
const { chain: s, isSynthetic: i } =
|
|
1018
|
+
const { chain: s, isSynthetic: i } = I(n), o = P.get(n.toUpperCase());
|
|
1007
1019
|
if (i)
|
|
1008
1020
|
return Q(n, r);
|
|
1009
|
-
const { tax: c, decimal: a, identifier:
|
|
1021
|
+
const { tax: c, decimal: a, identifier: l } = o || {
|
|
1010
1022
|
decimal: d[s],
|
|
1011
1023
|
identifier: n
|
|
1012
1024
|
};
|
|
1013
1025
|
return new A({
|
|
1014
1026
|
tax: c,
|
|
1015
1027
|
value: O(r, a),
|
|
1016
|
-
identifier: i ? n :
|
|
1028
|
+
identifier: i ? n : l,
|
|
1017
1029
|
decimal: i ? 8 : a
|
|
1018
1030
|
});
|
|
1019
1031
|
}
|
|
@@ -1026,10 +1038,10 @@ class A extends D {
|
|
|
1026
1038
|
return (await A.fromString(n, r)).set(i);
|
|
1027
1039
|
}
|
|
1028
1040
|
static fromStringWithBaseSync(n, r = 0, s = d.THOR) {
|
|
1029
|
-
const { chain: i, isSynthetic: o } =
|
|
1041
|
+
const { chain: i, isSynthetic: o } = I(n), c = P.get(n.toUpperCase());
|
|
1030
1042
|
if (o)
|
|
1031
1043
|
return Q(n, r);
|
|
1032
|
-
const { tax: a, decimal:
|
|
1044
|
+
const { tax: a, decimal: l, identifier: h } = c || {
|
|
1033
1045
|
decimal: d[i],
|
|
1034
1046
|
identifier: n
|
|
1035
1047
|
};
|
|
@@ -1037,18 +1049,18 @@ class A extends D {
|
|
|
1037
1049
|
tax: a,
|
|
1038
1050
|
value: O(BigInt(r), s),
|
|
1039
1051
|
identifier: h,
|
|
1040
|
-
decimal:
|
|
1052
|
+
decimal: l
|
|
1041
1053
|
});
|
|
1042
1054
|
}
|
|
1043
1055
|
static fromIdentifierSync(n, r = 0) {
|
|
1044
|
-
const { chain: s, isSynthetic: i } =
|
|
1056
|
+
const { chain: s, isSynthetic: i } = I(n), o = P.get(n);
|
|
1045
1057
|
if (i)
|
|
1046
1058
|
return Q(n, r);
|
|
1047
|
-
const { tax: c, decimal: a, identifier:
|
|
1059
|
+
const { tax: c, decimal: a, identifier: l } = o || {
|
|
1048
1060
|
decimal: d[s],
|
|
1049
1061
|
identifier: n
|
|
1050
1062
|
};
|
|
1051
|
-
return new A({ tax: c, decimal: a, identifier:
|
|
1063
|
+
return new A({ tax: c, decimal: a, identifier: l, value: O(r, a) });
|
|
1052
1064
|
}
|
|
1053
1065
|
static fromChainOrSignature(n, r = 0) {
|
|
1054
1066
|
const { decimal: s, identifier: i } = it(n);
|
|
@@ -1078,56 +1090,56 @@ class A extends D {
|
|
|
1078
1090
|
);
|
|
1079
1091
|
}
|
|
1080
1092
|
}
|
|
1081
|
-
function
|
|
1093
|
+
function Bt(e) {
|
|
1082
1094
|
const t = A.fromChainOrSignature(e);
|
|
1083
1095
|
switch (e) {
|
|
1084
|
-
case
|
|
1085
|
-
case
|
|
1086
|
-
case
|
|
1096
|
+
case u.Bitcoin:
|
|
1097
|
+
case u.Litecoin:
|
|
1098
|
+
case u.BitcoinCash:
|
|
1087
1099
|
return t.set(10001e-8);
|
|
1088
|
-
case
|
|
1100
|
+
case u.Dogecoin:
|
|
1089
1101
|
return t.set(1.00000001);
|
|
1090
|
-
case
|
|
1091
|
-
case
|
|
1102
|
+
case u.Avalanche:
|
|
1103
|
+
case u.Ethereum:
|
|
1092
1104
|
return t.set(1e-8);
|
|
1093
|
-
case
|
|
1094
|
-
case
|
|
1105
|
+
case u.THORChain:
|
|
1106
|
+
case u.Maya:
|
|
1095
1107
|
return t.set(0);
|
|
1096
|
-
case
|
|
1108
|
+
case u.Cosmos:
|
|
1097
1109
|
return t.set(1e-6);
|
|
1098
1110
|
default:
|
|
1099
1111
|
return t.set(1e-8);
|
|
1100
1112
|
}
|
|
1101
1113
|
}
|
|
1102
|
-
async function
|
|
1114
|
+
async function J(e, t = 0) {
|
|
1103
1115
|
dt(e);
|
|
1104
|
-
const n = P.get(e.toUpperCase()), r = (n == null ? void 0 : n.decimal) || await st(
|
|
1116
|
+
const n = P.get(e.toUpperCase()), r = (n == null ? void 0 : n.decimal) || await st(I(e));
|
|
1105
1117
|
return n || P.set(e.toUpperCase(), { identifier: e, decimal: r }), new A({ decimal: r, value: O(t, r), identifier: e });
|
|
1106
1118
|
}
|
|
1107
1119
|
function Q(e, t = 0) {
|
|
1108
|
-
const [n, r] = e.split(".")[0].toUpperCase() ===
|
|
1120
|
+
const [n, r] = e.split(".")[0].toUpperCase() === u.THORChain ? e.split(".").slice(1).join().split("/") : e.split("/");
|
|
1109
1121
|
if (!(n && r))
|
|
1110
1122
|
throw new Error("Invalid asset identifier");
|
|
1111
1123
|
return new A({
|
|
1112
1124
|
decimal: 8,
|
|
1113
1125
|
value: O(t, 8),
|
|
1114
|
-
identifier: `${
|
|
1126
|
+
identifier: `${u.THORChain}.${n}/${r}`
|
|
1115
1127
|
});
|
|
1116
1128
|
}
|
|
1117
1129
|
function O(e, t) {
|
|
1118
1130
|
return typeof e == "bigint" ? U({ value: e, bigIntDecimal: t, decimal: t }) : e;
|
|
1119
1131
|
}
|
|
1120
|
-
function
|
|
1121
|
-
const t = e.slice(0, 14).includes("/"), [n, r] = e.split(".")[0].toUpperCase() ===
|
|
1132
|
+
function I(e) {
|
|
1133
|
+
const t = e.slice(0, 14).includes("/"), [n, r] = e.split(".")[0].toUpperCase() === u.THORChain ? e.split(".").slice(1).join().split("/") : e.split("/");
|
|
1122
1134
|
if (t && !(n && r))
|
|
1123
1135
|
throw new Error("Invalid asset identifier");
|
|
1124
|
-
const s = e.includes(".") && !t ? e : `${
|
|
1136
|
+
const s = e.includes(".") && !t ? e : `${u.THORChain}.${r}`, [i, ...o] = s.split("."), [c, a] = (t ? r : o.join(".")).split("-"), l = t ? r : o.join(".");
|
|
1125
1137
|
return {
|
|
1126
1138
|
address: a == null ? void 0 : a.toLowerCase(),
|
|
1127
1139
|
chain: i,
|
|
1128
|
-
isGasAsset: Se({ chain: i, symbol:
|
|
1140
|
+
isGasAsset: Se({ chain: i, symbol: l }),
|
|
1129
1141
|
isSynthetic: t,
|
|
1130
|
-
symbol: (t ? `${n}/` : "") + (a ? `${c}-${(a == null ? void 0 : a.toLowerCase()) ?? ""}` :
|
|
1142
|
+
symbol: (t ? `${n}/` : "") + (a ? `${c}-${(a == null ? void 0 : a.toLowerCase()) ?? ""}` : l),
|
|
1131
1143
|
ticker: c
|
|
1132
1144
|
};
|
|
1133
1145
|
}
|
|
@@ -1140,6 +1152,7 @@ const mt = {
|
|
|
1140
1152
|
core_extend_error: 10003,
|
|
1141
1153
|
core_inbound_data_not_found: 10004,
|
|
1142
1154
|
core_approve_asset_address_or_from_not_found: 10005,
|
|
1155
|
+
core_plugin_not_found: 10006,
|
|
1143
1156
|
core_chain_halted: 10099,
|
|
1144
1157
|
/**
|
|
1145
1158
|
* Core - Wallet Connection
|
|
@@ -1164,7 +1177,6 @@ const mt = {
|
|
|
1164
1177
|
core_swap_contract_not_supported: 10205,
|
|
1165
1178
|
core_swap_transaction_error: 10206,
|
|
1166
1179
|
core_swap_quote_mode_not_supported: 10207,
|
|
1167
|
-
core_swap_provider_not_found: 10208,
|
|
1168
1180
|
/**
|
|
1169
1181
|
* Core - Transaction
|
|
1170
1182
|
*/
|
|
@@ -1215,10 +1227,10 @@ class ye extends Error {
|
|
|
1215
1227
|
}
|
|
1216
1228
|
}
|
|
1217
1229
|
export {
|
|
1218
|
-
|
|
1230
|
+
T as ApiEndpoints,
|
|
1219
1231
|
A as AssetValue,
|
|
1220
1232
|
D as BigIntArithmetics,
|
|
1221
|
-
|
|
1233
|
+
f as RequestClient,
|
|
1222
1234
|
Ze as StreamingSwapProgressStatus,
|
|
1223
1235
|
gt as SwapKitApi,
|
|
1224
1236
|
ye as SwapKitError,
|
|
@@ -1227,26 +1239,28 @@ export {
|
|
|
1227
1239
|
ze as TxStatus,
|
|
1228
1240
|
Ct as assetFromString,
|
|
1229
1241
|
Ae as defaultRequestHeaders,
|
|
1230
|
-
|
|
1242
|
+
It as derivationPathToString,
|
|
1231
1243
|
St as filterAssets,
|
|
1232
1244
|
U as formatBigIntToSafeValue,
|
|
1233
1245
|
At as gasFeeMultiplier,
|
|
1234
1246
|
ot as getAssetType,
|
|
1235
|
-
|
|
1247
|
+
lt as getAsymmetricAssetShare,
|
|
1236
1248
|
yt as getAsymmetricAssetWithdrawAmount,
|
|
1237
|
-
|
|
1249
|
+
ut as getAsymmetricRuneShare,
|
|
1238
1250
|
bt as getAsymmetricRuneWithdrawAmount,
|
|
1239
1251
|
it as getCommonAssetInfo,
|
|
1240
1252
|
st as getDecimal,
|
|
1241
1253
|
Rt as getEstimatedPoolShare,
|
|
1242
1254
|
Et as getLiquiditySlippage,
|
|
1255
|
+
Nt as getMAYANameCost,
|
|
1243
1256
|
Pt as getMemoFor,
|
|
1244
|
-
|
|
1257
|
+
Bt as getMinAmountByChain,
|
|
1245
1258
|
ht as getSymmetricPoolShare,
|
|
1246
1259
|
wt as getSymmetricWithdraw,
|
|
1247
1260
|
Ot as getTHORNameCost,
|
|
1248
1261
|
Se as isGasAsset,
|
|
1249
|
-
|
|
1250
|
-
$t as
|
|
1262
|
+
Tt as setRequestClientConfig,
|
|
1263
|
+
$t as validateMAYAName,
|
|
1264
|
+
vt as validateTHORName
|
|
1251
1265
|
};
|
|
1252
1266
|
//# sourceMappingURL=index.es.js.map
|