@swapkit/helpers 1.0.0-rc.67 → 1.0.0-rc.69
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 +2 -1
- package/dist/index.es.js +202 -223
- package/dist/index.es.js.map +1 -1
- package/package.json +6 -6
- package/src/helpers/asset.ts +11 -37
- package/src/helpers/validators.ts +1 -1
- package/src/types.ts +3 -1
package/dist/index.es.js
CHANGED
|
@@ -10,13 +10,13 @@ var O = (e, t, n) => {
|
|
|
10
10
|
t instanceof WeakSet ? t.add(e) : t.set(e, n);
|
|
11
11
|
};
|
|
12
12
|
var T = (e, t, n) => (Ve(e, t, "access private method"), n);
|
|
13
|
-
import { FeeOption as Y, BaseDecimal as d, Chain as
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
var
|
|
17
|
-
const q = Object.values(
|
|
13
|
+
import { FeeOption as Y, BaseDecimal as d, Chain as l, EVMChainList as Be, ChainToRPC as Ue, MemoType as E, ChainToChainId as Le } from "@swapkit/types";
|
|
14
|
+
var u = /* @__PURE__ */ ((e) => (e.INVALID_INPUT_PARAMETERS = "1000", e.UNKNOWN_PROVIDERS = "1001", e.CANNOT_FIND_INBOUND_ADDRESS = "1002", e.NO_INBOUND_ADDRESSES = "1003", e.CHAIN_HALTED_OR_UNSUPPORTED = "1004", e.MISSING_INPUT_PARAMETER = "1005", e.INVALID_TYPE_GENERIC = "1100", e.INVALID_NUMBER_STRING = "1101", e.INVALID_NUMBER = "1102", e.INVALID_BOOLEAN = "1103", e.INVALID_OBJECT = "1104", e.INVALID_ARRAY = "1105", e.SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER = "2000", e.SELL_BUY_ASSETS_ARE_THE_SAME = "2001", e.MISSING_SOURCE_ADDRESS_FOR_SYNTH = "2002", e.AFF_ADDRESS_AND_BPS_OR_NEITHER = "2003", e.AFF_ADDRESS_TOO_LONG = "2004", e.AFF_BPS_INTEGER_MAX_500 = "2005", e.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN = "2006", e.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN = "2007", e.PREFERRED_PROVIDER_NOT_SUPPORTED = "2008", e.DESTINATION_ADDRESS_SMART_CONTRACT = "2009", e.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER = "2010", e.SOURCE_ADDRESS_SMART_CONTRACT = "2011", e.SWAP_AMOUNT_TOO_LOW = "2012", e.INVALID_PROVIDER = "2100", e.MISSING_CROSS_CHAIN_PROVIDER = "2101", e.MISSING_AVAX_PROVIDER = "2102", e.MISSING_BSC_PROVIDER = "2103", e.MISSING_ETH_PROVIDER = "2104", e.INVALID_PROVIDER_FOR_SWAP_OUT = "2105", e.MISSING_ARB_PROVIDER = "2106", e.INVALID_CHAIN = "2200", e.INVALID_ASSET = "2201", e.INVALID_ASSET_IDENTIFIER = "2202", e.UNSUPPORTED_CHAIN = "2204", e.UNSUPPORTED_ASSET = "2203", e.UNSUPPORTED_ASSET_FOR_SWAPOUT = "2205", e.INVALID_SOURCE_ADDRESS = "2300", e.INVALID_DESTINATION_ADDRESS = "2301", e.THORNODE_QUOTE_GENERIC_ERROR = "3000", e.NOT_ENOUGH_SYNTH_BALANCE = "3001", e.SYNTH_MINTING_CAP_REACHED = "3002", e.INVALID_QUOTE_MODE = "4000", e.NO_QUOTES = "4001", e.SERVICE_UNAVAILABLE_GENERIC = "5000", e.MISSING_GAS_DATA_GENERIC = "5100", e.MISSING_TOKEN_INFO_GENERIC = "5200", e.CANT_FIND_TOKEN_LIST = "5201", e.NO_PRICE = "5202", e.PRICE_IS_STALE = "5203", e.ADDRESS_NOT_WHITELISTED = "6000", e.ADDRESS_ALREADY_CLAIMED = "6001", e.TEMPORARY_ERROR = "9999", e))(u || {});
|
|
15
|
+
u.INVALID_INPUT_PARAMETERS + "", u.UNKNOWN_PROVIDERS + "", u.CANNOT_FIND_INBOUND_ADDRESS + "", u.NO_INBOUND_ADDRESSES + "", u.CHAIN_HALTED_OR_UNSUPPORTED + "", u.MISSING_INPUT_PARAMETER + "", u.INVALID_TYPE_GENERIC + "", u.INVALID_NUMBER_STRING + "", u.INVALID_NUMBER + "", u.INVALID_BOOLEAN + "", u.INVALID_OBJECT + "", u.INVALID_ARRAY + "", u.SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER + "", u.SELL_BUY_ASSETS_ARE_THE_SAME + "", u.MISSING_SOURCE_ADDRESS_FOR_SYNTH + "", u.AFF_ADDRESS_AND_BPS_OR_NEITHER + "", u.AFF_ADDRESS_TOO_LONG + "", u.AFF_BPS_INTEGER_MAX_500 + "", u.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN + "", u.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN + "", u.PREFERRED_PROVIDER_NOT_SUPPORTED + "", u.SOURCE_ADDRESS_SMART_CONTRACT + "", u.SWAP_AMOUNT_TOO_LOW + "", u.DESTINATION_ADDRESS_SMART_CONTRACT + "", u.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER + "", u.INVALID_PROVIDER + "", u.MISSING_CROSS_CHAIN_PROVIDER + "", u.MISSING_AVAX_PROVIDER + "", u.MISSING_BSC_PROVIDER + "", u.MISSING_ETH_PROVIDER + "", u.MISSING_ARB_PROVIDER + "", u.INVALID_PROVIDER_FOR_SWAP_OUT + "", u.INVALID_CHAIN + "", u.INVALID_ASSET + "", u.UNSUPPORTED_CHAIN + "", u.UNSUPPORTED_ASSET + "", u.UNSUPPORTED_ASSET_FOR_SWAPOUT + "", u.THORNODE_QUOTE_GENERIC_ERROR + "", u.INVALID_SOURCE_ADDRESS + "", u.INVALID_DESTINATION_ADDRESS + "", u.NOT_ENOUGH_SYNTH_BALANCE + "", u.SYNTH_MINTING_CAP_REACHED + "", u.INVALID_QUOTE_MODE + "", u.NO_QUOTES + "", u.SERVICE_UNAVAILABLE_GENERIC + "", u.MISSING_GAS_DATA_GENERIC + "", u.MISSING_TOKEN_INFO_GENERIC + "", u.CANT_FIND_TOKEN_LIST + "", u.NO_PRICE + "", u.PRICE_IS_STALE + "", u.ADDRESS_NOT_WHITELISTED + "", u.ADDRESS_ALREADY_CLAIMED + "";
|
|
16
|
+
var j = /* @__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))(j || {}), te = /* @__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))(te || {}), 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 || {}), R = /* @__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))(R || {});
|
|
17
|
+
const q = Object.values(j), $e = Object.keys(j), ne = q.reduce(
|
|
18
18
|
(e, t) => {
|
|
19
|
-
const n =
|
|
19
|
+
const n = $e.find((r) => j[r] === t);
|
|
20
20
|
return n && (e[t] = n), e;
|
|
21
21
|
},
|
|
22
22
|
{}
|
|
@@ -38,8 +38,8 @@ q.reduce(
|
|
|
38
38
|
);
|
|
39
39
|
class oe extends Error {
|
|
40
40
|
constructor(t, n, r) {
|
|
41
|
-
const s = t.status || t.status === 0 ? t.status : "", i = t.statusText || "",
|
|
42
|
-
super(`Request failed with ${
|
|
41
|
+
const s = t.status || t.status === 0 ? t.status : "", i = t.statusText || "", a = `${s} ${i}`.trim(), c = a ? `status code ${a}` : "an unknown error";
|
|
42
|
+
super(`Request failed with ${c}`), Object.defineProperty(this, "response", {
|
|
43
43
|
enumerable: !0,
|
|
44
44
|
configurable: !0,
|
|
45
45
|
writable: !0,
|
|
@@ -67,15 +67,15 @@ class Te extends Error {
|
|
|
67
67
|
}), this.name = "TimeoutError", this.request = t;
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
const M = (e) => e !== null && typeof e == "object",
|
|
70
|
+
const M = (e) => e !== null && typeof e == "object", $ = (...e) => {
|
|
71
71
|
for (const t of e)
|
|
72
72
|
if ((!M(t) || Array.isArray(t)) && t !== void 0)
|
|
73
73
|
throw new TypeError("The `options` argument must be an object");
|
|
74
74
|
return re({}, ...e);
|
|
75
75
|
}, Ae = (e = {}, t = {}) => {
|
|
76
76
|
const n = new globalThis.Headers(e), r = t instanceof globalThis.Headers, s = new globalThis.Headers(t);
|
|
77
|
-
for (const [i,
|
|
78
|
-
r &&
|
|
77
|
+
for (const [i, a] of s.entries())
|
|
78
|
+
r && a === "undefined" || a === void 0 ? n.delete(i) : n.set(i, a);
|
|
79
79
|
return n;
|
|
80
80
|
}, re = (...e) => {
|
|
81
81
|
let t = {}, n = {};
|
|
@@ -88,7 +88,7 @@ const M = (e) => e !== null && typeof e == "object", v = (...e) => {
|
|
|
88
88
|
M(r.headers) && (n = Ae(n, r.headers), t.headers = n);
|
|
89
89
|
}
|
|
90
90
|
return t;
|
|
91
|
-
},
|
|
91
|
+
}, ve = (() => {
|
|
92
92
|
let e = !1, t = !1;
|
|
93
93
|
const n = typeof globalThis.ReadableStream == "function", r = typeof globalThis.Request == "function";
|
|
94
94
|
return n && r && (t = new globalThis.Request("https://empty.invalid", {
|
|
@@ -99,7 +99,7 @@ const M = (e) => e !== null && typeof e == "object", v = (...e) => {
|
|
|
99
99
|
return e = !0, "half";
|
|
100
100
|
}
|
|
101
101
|
}).headers.has("Content-Type")), e && !t;
|
|
102
|
-
})(), Me = typeof globalThis.AbortController == "function", He = typeof globalThis.ReadableStream == "function",
|
|
102
|
+
})(), Me = typeof globalThis.AbortController == "function", He = typeof globalThis.ReadableStream == "function", Fe = typeof globalThis.FormData == "function", pe = ["get", "post", "put", "patch", "head", "delete"], xe = {
|
|
103
103
|
json: "application/json",
|
|
104
104
|
text: "text/*",
|
|
105
105
|
formData: "multipart/form-data",
|
|
@@ -132,9 +132,9 @@ const M = (e) => e !== null && typeof e == "object", v = (...e) => {
|
|
|
132
132
|
window: !0,
|
|
133
133
|
dispatcher: !0,
|
|
134
134
|
duplex: !0
|
|
135
|
-
},
|
|
135
|
+
}, ke = (e) => pe.includes(e) ? e.toUpperCase() : e, je = ["get", "put", "head", "delete", "options", "trace"], qe = [408, 413, 429, 500, 502, 503, 504], me = [413, 429, 503], ce = {
|
|
136
136
|
limit: 2,
|
|
137
|
-
methods:
|
|
137
|
+
methods: je,
|
|
138
138
|
statusCodes: qe,
|
|
139
139
|
afterStatusCodes: me,
|
|
140
140
|
maxRetryAfter: Number.POSITIVE_INFINITY,
|
|
@@ -158,11 +158,11 @@ const M = (e) => e !== null && typeof e == "object", v = (...e) => {
|
|
|
158
158
|
};
|
|
159
159
|
async function Ye(e, t, n, r) {
|
|
160
160
|
return new Promise((s, i) => {
|
|
161
|
-
const
|
|
161
|
+
const a = setTimeout(() => {
|
|
162
162
|
n && n.abort(), i(new Te(e));
|
|
163
163
|
}, r.timeout);
|
|
164
164
|
r.fetch(e, t).then(s).catch(i).then(() => {
|
|
165
|
-
clearTimeout(
|
|
165
|
+
clearTimeout(a);
|
|
166
166
|
});
|
|
167
167
|
});
|
|
168
168
|
}
|
|
@@ -183,43 +183,43 @@ const Je = (e, t) => {
|
|
|
183
183
|
!(r in We) && !(r in Ge) && !(r in e) && (n[r] = t[r]);
|
|
184
184
|
return n;
|
|
185
185
|
};
|
|
186
|
-
class
|
|
186
|
+
class x {
|
|
187
187
|
static create(t, n) {
|
|
188
|
-
const r = new
|
|
188
|
+
const r = new x(t, n), s = async () => {
|
|
189
189
|
if (typeof r._options.timeout == "number" && r._options.timeout > K)
|
|
190
190
|
throw new RangeError(`The \`timeout\` option cannot be greater than ${K}`);
|
|
191
191
|
await Promise.resolve();
|
|
192
|
-
let
|
|
193
|
-
for (const
|
|
194
|
-
const
|
|
195
|
-
|
|
192
|
+
let a = await r._fetch();
|
|
193
|
+
for (const c of r._options.hooks.afterResponse) {
|
|
194
|
+
const o = await c(r.request, r._options, r._decorateResponse(a.clone()));
|
|
195
|
+
o instanceof globalThis.Response && (a = o);
|
|
196
196
|
}
|
|
197
|
-
if (r._decorateResponse(
|
|
198
|
-
let
|
|
199
|
-
for (const
|
|
200
|
-
|
|
201
|
-
throw
|
|
197
|
+
if (r._decorateResponse(a), !a.ok && r._options.throwHttpErrors) {
|
|
198
|
+
let c = new oe(a, r.request, r._options);
|
|
199
|
+
for (const o of r._options.hooks.beforeError)
|
|
200
|
+
c = await o(c);
|
|
201
|
+
throw c;
|
|
202
202
|
}
|
|
203
203
|
if (r._options.onDownloadProgress) {
|
|
204
204
|
if (typeof r._options.onDownloadProgress != "function")
|
|
205
205
|
throw new TypeError("The `onDownloadProgress` option must be a function");
|
|
206
206
|
if (!He)
|
|
207
207
|
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
|
|
208
|
-
return r._stream(
|
|
208
|
+
return r._stream(a.clone(), r._options.onDownloadProgress);
|
|
209
209
|
}
|
|
210
|
-
return
|
|
210
|
+
return a;
|
|
211
211
|
}, i = r._options.retry.methods.includes(r.request.method.toLowerCase()) ? r._retry(s) : s();
|
|
212
|
-
for (const [
|
|
213
|
-
i[
|
|
214
|
-
r.request.headers.set("accept", r.request.headers.get("accept") ||
|
|
215
|
-
const
|
|
216
|
-
if (
|
|
217
|
-
if (
|
|
212
|
+
for (const [a, c] of Object.entries(xe))
|
|
213
|
+
i[a] = async () => {
|
|
214
|
+
r.request.headers.set("accept", r.request.headers.get("accept") || c);
|
|
215
|
+
const o = (await i).clone();
|
|
216
|
+
if (a === "json") {
|
|
217
|
+
if (o.status === 204 || (await o.clone().arrayBuffer()).byteLength === 0)
|
|
218
218
|
return "";
|
|
219
219
|
if (n.parseJson)
|
|
220
|
-
return n.parseJson(await
|
|
220
|
+
return n.parseJson(await o.text());
|
|
221
221
|
}
|
|
222
|
-
return
|
|
222
|
+
return o[a]();
|
|
223
223
|
};
|
|
224
224
|
return i;
|
|
225
225
|
}
|
|
@@ -261,7 +261,7 @@ class F {
|
|
|
261
261
|
beforeError: [],
|
|
262
262
|
afterResponse: []
|
|
263
263
|
}, n.hooks),
|
|
264
|
-
method:
|
|
264
|
+
method: ke(n.method ?? this._input.method),
|
|
265
265
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
266
266
|
prefixUrl: String(n.prefixUrl || ""),
|
|
267
267
|
retry: Xe(n.retry),
|
|
@@ -284,9 +284,9 @@ class F {
|
|
|
284
284
|
}
|
|
285
285
|
this._options.signal = this.abortController.signal;
|
|
286
286
|
}
|
|
287
|
-
if (
|
|
287
|
+
if (ve && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
|
|
288
288
|
const r = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), s = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, r);
|
|
289
|
-
(
|
|
289
|
+
(Fe && 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);
|
|
290
290
|
}
|
|
291
291
|
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 }));
|
|
292
292
|
}
|
|
@@ -354,11 +354,11 @@ class F {
|
|
|
354
354
|
headers: t.headers
|
|
355
355
|
})) : new globalThis.Response(new globalThis.ReadableStream({
|
|
356
356
|
async start(i) {
|
|
357
|
-
const
|
|
357
|
+
const a = t.body.getReader();
|
|
358
358
|
n && n({ percent: 0, transferredBytes: 0, totalBytes: r }, new Uint8Array());
|
|
359
|
-
async function
|
|
360
|
-
const { done:
|
|
361
|
-
if (
|
|
359
|
+
async function c() {
|
|
360
|
+
const { done: o, value: _ } = await a.read();
|
|
361
|
+
if (o) {
|
|
362
362
|
i.close();
|
|
363
363
|
return;
|
|
364
364
|
}
|
|
@@ -367,9 +367,9 @@ class F {
|
|
|
367
367
|
const h = r === 0 ? 0 : s / r;
|
|
368
368
|
n({ percent: h, transferredBytes: s, totalBytes: r }, _);
|
|
369
369
|
}
|
|
370
|
-
i.enqueue(_), await
|
|
370
|
+
i.enqueue(_), await c();
|
|
371
371
|
}
|
|
372
|
-
await
|
|
372
|
+
await c();
|
|
373
373
|
}
|
|
374
374
|
}), {
|
|
375
375
|
status: t.status,
|
|
@@ -380,10 +380,10 @@ class F {
|
|
|
380
380
|
}
|
|
381
381
|
/*! MIT License © Sindre Sorhus */
|
|
382
382
|
const Q = (e) => {
|
|
383
|
-
const t = (n, r) =>
|
|
383
|
+
const t = (n, r) => x.create(n, $(e, r));
|
|
384
384
|
for (const n of pe)
|
|
385
|
-
t[n] = (r, s) =>
|
|
386
|
-
return t.create = (n) => Q(
|
|
385
|
+
t[n] = (r, s) => x.create(r, $(e, s, { method: n }));
|
|
386
|
+
return t.create = (n) => Q($(n)), t.extend = (n) => Q($(e, n)), t.stop = Se, t;
|
|
387
387
|
}, Ee = Q();
|
|
388
388
|
let H;
|
|
389
389
|
const m = {
|
|
@@ -394,17 +394,17 @@ const m = {
|
|
|
394
394
|
TokenlistProviders: `${R.ThorswapApi}/tokenlist/providers`,
|
|
395
395
|
TokenList: `${R.ThorswapStatic}/token-list`,
|
|
396
396
|
Thorname: `${R.ThorswapApi}/thorname`
|
|
397
|
-
}, Re = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" },
|
|
397
|
+
}, Re = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, le = () => H || (H = Ee.create({ headers: Re }), H), mt = ({ apiKey: e, ...t }) => {
|
|
398
398
|
H = Ee.create({
|
|
399
399
|
...t,
|
|
400
400
|
headers: { ...Re, ...t.headers, "x-api-key": e }
|
|
401
401
|
});
|
|
402
402
|
}, S = {
|
|
403
|
-
get: (e, t) =>
|
|
404
|
-
post: (e, t) =>
|
|
403
|
+
get: (e, t) => le().get(e, t).json(),
|
|
404
|
+
post: (e, t) => le().post(e, t).json()
|
|
405
405
|
}, Qe = ({ tokens: e, ...t }) => {
|
|
406
406
|
const n = new URLSearchParams();
|
|
407
|
-
return e.filter((r, s, i) => i.findIndex((
|
|
407
|
+
return e.filter((r, s, i) => i.findIndex((a) => a === r) === s).forEach((r) => n.append("tokens", JSON.stringify(r))), t.metadata && n.append("metadata", "true"), t.lookup && n.append("lookup", "true"), t.sparkline && n.append("sparkline", "true"), S.post(m.CachedPrices, {
|
|
408
408
|
body: n.toString(),
|
|
409
409
|
headers: { "Content-Type": "application/x-www-form-urlencoded" }
|
|
410
410
|
});
|
|
@@ -440,20 +440,20 @@ const tt = "0x313ce567", Ie = async ({ chain: e, to: t }) => {
|
|
|
440
440
|
return console.error(n), d[e];
|
|
441
441
|
}
|
|
442
442
|
}, nt = async (e) => {
|
|
443
|
-
if (e ===
|
|
443
|
+
if (e === l.Ethereum)
|
|
444
444
|
return d.ETH;
|
|
445
445
|
const [, t] = e.split("-");
|
|
446
|
-
return t != null && t.startsWith("0x") ? Ie({ chain:
|
|
446
|
+
return t != null && t.startsWith("0x") ? Ie({ chain: l.Ethereum, to: t }) : d.ETH;
|
|
447
447
|
}, rt = async (e) => {
|
|
448
448
|
const [, t] = e.split("-");
|
|
449
|
-
return t != null && t.startsWith("0x") ? Ie({ chain:
|
|
450
|
-
}, st = async (e) => e ===
|
|
449
|
+
return t != null && t.startsWith("0x") ? Ie({ chain: l.Avalanche, to: t.toLowerCase() }) : d.AVAX;
|
|
450
|
+
}, st = async (e) => e === l.BinanceSmartChain ? d.BSC : d.BSC, it = async ({ chain: e, symbol: t }) => {
|
|
451
451
|
switch (e) {
|
|
452
|
-
case
|
|
452
|
+
case l.Ethereum:
|
|
453
453
|
return nt(t);
|
|
454
|
-
case
|
|
454
|
+
case l.Avalanche:
|
|
455
455
|
return rt(t);
|
|
456
|
-
case
|
|
456
|
+
case l.BinanceSmartChain:
|
|
457
457
|
return st(t);
|
|
458
458
|
default:
|
|
459
459
|
return d[e];
|
|
@@ -464,122 +464,101 @@ const tt = "0x313ce567", Ie = async ({ chain: e, to: t }) => {
|
|
|
464
464
|
[Y.Fastest]: 2
|
|
465
465
|
}, fe = ({ chain: e, symbol: t }) => {
|
|
466
466
|
switch (e) {
|
|
467
|
-
case
|
|
468
|
-
case
|
|
469
|
-
case a.Litecoin:
|
|
470
|
-
case a.Dogecoin:
|
|
471
|
-
case a.Binance:
|
|
472
|
-
case a.Ethereum:
|
|
473
|
-
case a.Avalanche:
|
|
474
|
-
return t === e;
|
|
475
|
-
case a.Arbitrum:
|
|
476
|
-
case a.Optimism:
|
|
467
|
+
case l.Arbitrum:
|
|
468
|
+
case l.Optimism:
|
|
477
469
|
return t === "ETH";
|
|
478
|
-
case
|
|
470
|
+
case l.Maya:
|
|
479
471
|
return t === "CACAO";
|
|
480
|
-
case
|
|
472
|
+
case l.Kujira:
|
|
481
473
|
return t === "KUJI";
|
|
482
|
-
case
|
|
474
|
+
case l.Cosmos:
|
|
483
475
|
return t === "ATOM";
|
|
484
|
-
case
|
|
476
|
+
case l.Polygon:
|
|
485
477
|
return t === "MATIC";
|
|
486
|
-
case
|
|
478
|
+
case l.BinanceSmartChain:
|
|
487
479
|
return t === "BNB";
|
|
488
|
-
case
|
|
480
|
+
case l.THORChain:
|
|
489
481
|
return t === "RUNE";
|
|
482
|
+
default:
|
|
483
|
+
return t === e;
|
|
490
484
|
}
|
|
491
485
|
}, at = (e) => {
|
|
492
486
|
switch (e) {
|
|
493
|
-
case `${
|
|
487
|
+
case `${l.Ethereum}.THOR`:
|
|
494
488
|
return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
|
|
495
|
-
case `${
|
|
489
|
+
case `${l.Ethereum}.vTHOR`:
|
|
496
490
|
return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
|
|
497
|
-
case
|
|
491
|
+
case l.Cosmos:
|
|
498
492
|
return { identifier: "GAIA.ATOM", decimal: d[e] };
|
|
499
|
-
case
|
|
493
|
+
case l.THORChain:
|
|
500
494
|
return { identifier: "THOR.RUNE", decimal: d[e] };
|
|
501
|
-
case
|
|
495
|
+
case l.BinanceSmartChain:
|
|
502
496
|
return { identifier: "BSC.BNB", decimal: d[e] };
|
|
503
|
-
case
|
|
497
|
+
case l.Maya:
|
|
504
498
|
return { identifier: "MAYA.CACAO", decimal: d.MAYA };
|
|
505
|
-
case `${
|
|
499
|
+
case `${l.Maya}.MAYA`:
|
|
506
500
|
return { identifier: "MAYA.MAYA", decimal: 4 };
|
|
507
|
-
case `${
|
|
508
|
-
return { identifier: `${
|
|
509
|
-
|
|
510
|
-
case a.Arbitrum:
|
|
511
|
-
case a.Optimism:
|
|
512
|
-
case a.BitcoinCash:
|
|
513
|
-
case a.Litecoin:
|
|
514
|
-
case a.Dogecoin:
|
|
515
|
-
case a.Binance:
|
|
516
|
-
case a.Avalanche:
|
|
517
|
-
case a.Polygon:
|
|
518
|
-
case a.Bitcoin:
|
|
519
|
-
case a.Ethereum:
|
|
501
|
+
case `${l.Kujira}.USK`:
|
|
502
|
+
return { identifier: `${l.Kujira}.USK`, decimal: 6 };
|
|
503
|
+
default:
|
|
520
504
|
return { identifier: `${e}.${e}`, decimal: d[e] };
|
|
521
505
|
}
|
|
522
506
|
}, ot = ({ chain: e, symbol: t }) => {
|
|
523
507
|
if (t.includes("/"))
|
|
524
508
|
return "Synth";
|
|
525
509
|
switch (e) {
|
|
526
|
-
case
|
|
527
|
-
|
|
528
|
-
case
|
|
529
|
-
|
|
530
|
-
case
|
|
531
|
-
|
|
510
|
+
case l.Cosmos:
|
|
511
|
+
return t === "ATOM" ? "Native" : l.Cosmos;
|
|
512
|
+
case l.Kujira:
|
|
513
|
+
return t === l.Kujira ? "Native" : l.Kujira;
|
|
514
|
+
case l.Binance:
|
|
515
|
+
return t === l.Binance ? "Native" : "BEP2";
|
|
516
|
+
case l.BinanceSmartChain:
|
|
517
|
+
return t === l.Binance ? "Native" : "BEP20";
|
|
518
|
+
case l.Ethereum:
|
|
519
|
+
return t === l.Ethereum ? "Native" : "ERC20";
|
|
520
|
+
case l.Avalanche:
|
|
521
|
+
return t === l.Avalanche ? "Native" : l.Avalanche;
|
|
522
|
+
case l.Polygon:
|
|
523
|
+
return t === l.Polygon ? "Native" : "POLYGON";
|
|
524
|
+
case l.Arbitrum:
|
|
525
|
+
return [l.Ethereum, l.Arbitrum].includes(t) ? "Native" : "ARBITRUM";
|
|
526
|
+
case l.Optimism:
|
|
527
|
+
return [l.Ethereum, l.Optimism].includes(t) ? "Native" : "OPTIMISM";
|
|
528
|
+
default:
|
|
532
529
|
return "Native";
|
|
533
|
-
case a.Cosmos:
|
|
534
|
-
return t === "ATOM" ? "Native" : a.Cosmos;
|
|
535
|
-
case a.Kujira:
|
|
536
|
-
return t === a.Kujira ? "Native" : a.Kujira;
|
|
537
|
-
case a.Binance:
|
|
538
|
-
return t === a.Binance ? "Native" : "BEP2";
|
|
539
|
-
case a.BinanceSmartChain:
|
|
540
|
-
return t === a.Binance ? "Native" : "BEP20";
|
|
541
|
-
case a.Ethereum:
|
|
542
|
-
return t === a.Ethereum ? "Native" : "ERC20";
|
|
543
|
-
case a.Avalanche:
|
|
544
|
-
return t === a.Avalanche ? "Native" : a.Avalanche;
|
|
545
|
-
case a.Polygon:
|
|
546
|
-
return t === a.Polygon ? "Native" : "POLYGON";
|
|
547
|
-
case a.Arbitrum:
|
|
548
|
-
return [a.Ethereum, a.Arbitrum].includes(t) ? "Native" : "ARBITRUM";
|
|
549
|
-
case a.Optimism:
|
|
550
|
-
return [a.Ethereum, a.Optimism].includes(t) ? "Native" : "OPTIMISM";
|
|
551
530
|
}
|
|
552
531
|
}, It = (e) => {
|
|
553
|
-
var
|
|
554
|
-
const [t, ...n] = e.split("."), r = e.includes("/"), s = n.join("."), i = (
|
|
532
|
+
var a;
|
|
533
|
+
const [t, ...n] = e.split("."), r = e.includes("/"), s = n.join("."), i = (a = s == null ? void 0 : s.split("-")) == null ? void 0 : a[0];
|
|
555
534
|
return { chain: t, symbol: s, ticker: i, synth: r };
|
|
556
535
|
}, ct = new RegExp(
|
|
557
536
|
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
|
|
558
537
|
"gmi"
|
|
559
|
-
),
|
|
538
|
+
), lt = (e) => {
|
|
560
539
|
const [t, n] = e.split(".");
|
|
561
540
|
if (!Be.includes(t))
|
|
562
541
|
return !0;
|
|
563
542
|
const [, r] = n.split("-");
|
|
564
543
|
return fe({ chain: t, symbol: n }) || !!r;
|
|
565
|
-
}, ft = (e) => e.filter((t) => {
|
|
566
|
-
const
|
|
567
|
-
return !ct.test(
|
|
544
|
+
}, ft = (e) => e.filter(({ chain: t, value: n, symbol: r }) => {
|
|
545
|
+
const s = `${t}.${r}`;
|
|
546
|
+
return !ct.test(s) && lt(s) && n !== "0";
|
|
568
547
|
});
|
|
569
|
-
function
|
|
548
|
+
function ut({
|
|
570
549
|
liquidityUnits: e,
|
|
571
550
|
poolUnits: t,
|
|
572
551
|
runeDepth: n
|
|
573
552
|
}) {
|
|
574
|
-
const r = A(e), s = A(t), i = A(n),
|
|
575
|
-
return
|
|
553
|
+
const r = A(e), s = A(t), i = A(n), a = r.mul(i), c = s.mul(s).mul(2), o = s.mul(r).mul(2), _ = r.mul(r), h = s.mul(s).mul(s);
|
|
554
|
+
return a.mul(c.sub(o).add(_)).div(h);
|
|
576
555
|
}
|
|
577
556
|
function _t({
|
|
578
557
|
liquidityUnits: e,
|
|
579
558
|
poolUnits: t,
|
|
580
559
|
assetDepth: n
|
|
581
560
|
}) {
|
|
582
|
-
const r = A(e), s = A(t), i = A(n),
|
|
561
|
+
const r = A(e), s = A(t), i = A(n), a = r.mul(i), c = s.mul(s).mul(2), o = s.mul(r).mul(2), _ = r.mul(r), h = a.mul(c.sub(o).add(_)), P = s.mul(s).mul(s);
|
|
583
562
|
return h.div(P);
|
|
584
563
|
}
|
|
585
564
|
function Nt({
|
|
@@ -588,7 +567,7 @@ function Nt({
|
|
|
588
567
|
liquidityUnits: n,
|
|
589
568
|
poolUnits: r
|
|
590
569
|
}) {
|
|
591
|
-
return
|
|
570
|
+
return ut({ runeDepth: t, liquidityUnits: n, poolUnits: r }).mul(e);
|
|
592
571
|
}
|
|
593
572
|
function Ct({
|
|
594
573
|
percent: e,
|
|
@@ -621,7 +600,7 @@ function gt({
|
|
|
621
600
|
}) {
|
|
622
601
|
return Object.fromEntries(
|
|
623
602
|
Object.entries(ht({ liquidityUnits: e, poolUnits: t, runeDepth: n, assetDepth: r })).map(
|
|
624
|
-
([i,
|
|
603
|
+
([i, a]) => [i, a.mul(s)]
|
|
625
604
|
)
|
|
626
605
|
);
|
|
627
606
|
}
|
|
@@ -633,10 +612,10 @@ function Ot({
|
|
|
633
612
|
runeAmount: s,
|
|
634
613
|
assetAmount: i
|
|
635
614
|
}) {
|
|
636
|
-
const
|
|
615
|
+
const a = new I({ value: e, decimal: 8 }), c = new I({ value: n, decimal: 8 }), o = new I({ value: t, decimal: 8 }), _ = new I({ value: s, decimal: 8 }), h = new I({ value: i, decimal: 8 }), P = _.mul(c), ie = h.mul(a), ge = _.mul(h), Oe = a.mul(c), De = o.mul(P.add(ie.add(ge.mul(2)))), Pe = P.add(ie.add(Oe.mul(2))), ae = De.div(Pe), X = A(r).add(ae);
|
|
637
616
|
if (ae.getBaseValue("number") === 0)
|
|
638
|
-
return X.div(
|
|
639
|
-
const be =
|
|
617
|
+
return X.div(o).getBaseValue("number");
|
|
618
|
+
const be = o.add(X);
|
|
640
619
|
return X.div(be).getBaseValue("number");
|
|
641
620
|
}
|
|
642
621
|
function Dt({
|
|
@@ -647,8 +626,8 @@ function Dt({
|
|
|
647
626
|
}) {
|
|
648
627
|
if (e === "0" || t === "0" || n === "0" || r === "0")
|
|
649
628
|
return 0;
|
|
650
|
-
const s = A(n), i = A(r),
|
|
651
|
-
return Math.abs(
|
|
629
|
+
const s = A(n), i = A(r), a = A(t), c = A(e), o = a.mul(s).sub(i.mul(c)), _ = i.mul(c).add(s.mul(i));
|
|
630
|
+
return Math.abs(o.div(_).getBaseValue("number"));
|
|
652
631
|
}
|
|
653
632
|
const Pt = (e, t) => {
|
|
654
633
|
switch (e) {
|
|
@@ -667,22 +646,22 @@ const Pt = (e, t) => {
|
|
|
667
646
|
}
|
|
668
647
|
case E.DEPOSIT: {
|
|
669
648
|
const { chain: n, symbol: r, address: s, singleSide: i } = t;
|
|
670
|
-
return i ? `${e}:${n}/${r}::t:0` : `${e}:${((
|
|
671
|
-
switch (
|
|
672
|
-
case
|
|
649
|
+
return i ? `${e}:${n}/${r}::t:0` : `${e}:${((c, o) => {
|
|
650
|
+
switch (c) {
|
|
651
|
+
case l.Litecoin:
|
|
673
652
|
return "l";
|
|
674
|
-
case
|
|
653
|
+
case l.Dogecoin:
|
|
675
654
|
return "d";
|
|
676
|
-
case
|
|
655
|
+
case l.BitcoinCash:
|
|
677
656
|
return "c";
|
|
678
657
|
default:
|
|
679
|
-
return `${
|
|
658
|
+
return `${c}.${o}`;
|
|
680
659
|
}
|
|
681
660
|
})(n, r)}:${s || ""}:t:0`;
|
|
682
661
|
}
|
|
683
662
|
case E.WITHDRAW: {
|
|
684
|
-
const { chain: n, ticker: r, symbol: s, basisPoints: i, targetAssetString:
|
|
685
|
-
return `${e}:${n}${
|
|
663
|
+
const { chain: n, ticker: r, symbol: s, basisPoints: i, targetAssetString: a, singleSide: c } = t, o = n === "ETH" && r !== "ETH" ? `${r}-${s.slice(-3)}` : s, _ = !c && a ? `:${a}` : "";
|
|
664
|
+
return `${e}:${n}${c ? "/" : "."}${o}:${i}${_}`;
|
|
686
665
|
}
|
|
687
666
|
case E.OPEN_LOAN:
|
|
688
667
|
case E.CLOSE_LOAN: {
|
|
@@ -707,13 +686,13 @@ function yt(e) {
|
|
|
707
686
|
function wt([e, t, n, r, s]) {
|
|
708
687
|
return `${e}'/${t}'/${n}'/${r}${typeof s != "number" ? "" : `/${s}`}`;
|
|
709
688
|
}
|
|
710
|
-
const
|
|
689
|
+
const ue = [...Object.values(l), "TERRA"];
|
|
711
690
|
function dt(e = "") {
|
|
712
691
|
const t = e.toUpperCase(), [n] = t.split(".");
|
|
713
|
-
if (
|
|
692
|
+
if (ue.includes(n))
|
|
714
693
|
return !0;
|
|
715
694
|
const [r] = t.split("/");
|
|
716
|
-
if (
|
|
695
|
+
if (ue.includes(r))
|
|
717
696
|
return !0;
|
|
718
697
|
throw new Error(
|
|
719
698
|
`Invalid identifier: ${e}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
@@ -731,26 +710,26 @@ function G({
|
|
|
731
710
|
let s = e.toString().substring(r ? 1 : 0);
|
|
732
711
|
const i = n - (s.length - 1);
|
|
733
712
|
i > 0 && (s = "0".repeat(i) + s);
|
|
734
|
-
const
|
|
735
|
-
let
|
|
736
|
-
return parseInt(
|
|
713
|
+
const a = s.length - n;
|
|
714
|
+
let c = s.slice(-n);
|
|
715
|
+
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, a)}.${c}`.replace(
|
|
737
716
|
/\.?0*$/,
|
|
738
717
|
""
|
|
739
718
|
);
|
|
740
719
|
}
|
|
741
|
-
var C, y, f, D,
|
|
720
|
+
var C, y, f, D, k, Ne, U, z, L, Z;
|
|
742
721
|
const se = class se {
|
|
743
722
|
constructor(t) {
|
|
744
723
|
O(this, C);
|
|
745
724
|
O(this, f);
|
|
746
|
-
O(this,
|
|
725
|
+
O(this, k);
|
|
747
726
|
O(this, U);
|
|
748
727
|
O(this, L);
|
|
749
728
|
p(this, "decimalMultiplier", 10n ** 8n);
|
|
750
729
|
p(this, "bigIntValue", 0n);
|
|
751
730
|
p(this, "decimal");
|
|
752
731
|
const n = ee(t), r = typeof t == "object";
|
|
753
|
-
this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier : N(Math.max(_e(
|
|
732
|
+
this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier : N(Math.max(_e(v(n)), this.decimal || 0)), T(this, k, Ne).call(this, n);
|
|
754
733
|
}
|
|
755
734
|
static fromBigInt(t, n) {
|
|
756
735
|
return new se({
|
|
@@ -828,7 +807,7 @@ const se = class se {
|
|
|
828
807
|
getBigIntValue(t, n) {
|
|
829
808
|
if (!n && typeof t == "object")
|
|
830
809
|
return t.bigIntValue;
|
|
831
|
-
const r = ee(t), s =
|
|
810
|
+
const r = ee(t), s = v(r);
|
|
832
811
|
return s === "0" || s === "undefined" ? 0n : T(this, L, Z).call(this, s, n);
|
|
833
812
|
}
|
|
834
813
|
toSignificant(t = 6) {
|
|
@@ -842,9 +821,9 @@ const se = class se {
|
|
|
842
821
|
t - s.length,
|
|
843
822
|
"0"
|
|
844
823
|
);
|
|
845
|
-
const
|
|
846
|
-
return `0.${
|
|
847
|
-
i.length - `${
|
|
824
|
+
const c = parseInt(i), o = `${c}`.slice(0, t);
|
|
825
|
+
return `0.${o.padStart(
|
|
826
|
+
i.length - `${c}`.length + o.length,
|
|
848
827
|
"0"
|
|
849
828
|
)}`;
|
|
850
829
|
}
|
|
@@ -852,9 +831,9 @@ const se = class se {
|
|
|
852
831
|
const [n, r] = this.getValue("string").split("."), s = n || "", i = r || "";
|
|
853
832
|
if (parseInt(s))
|
|
854
833
|
return `${s}.${i.slice(0, t)}`.padEnd(t, "0");
|
|
855
|
-
const
|
|
856
|
-
return `0.${
|
|
857
|
-
i.length - `${
|
|
834
|
+
const a = parseInt(i), c = `${a}`.slice(0, t);
|
|
835
|
+
return `0.${c.padStart(
|
|
836
|
+
i.length - `${a}`.length + c.length,
|
|
858
837
|
"0"
|
|
859
838
|
)}`;
|
|
860
839
|
}
|
|
@@ -862,8 +841,8 @@ const se = class se {
|
|
|
862
841
|
const n = this.getValue("number"), r = ["", "K", "M", "B", "T", "Q", "Qi", "S"], s = Math.floor(Math.log10(Math.abs(n)) / 3), i = r[s];
|
|
863
842
|
if (!i)
|
|
864
843
|
return this.getValue("string");
|
|
865
|
-
const
|
|
866
|
-
return `${(n /
|
|
844
|
+
const a = 10 ** (s * 3);
|
|
845
|
+
return `${(n / a).toFixed(t)}${i}`;
|
|
867
846
|
}
|
|
868
847
|
toCurrency(t = "$", {
|
|
869
848
|
currencyPosition: n = "start",
|
|
@@ -871,52 +850,52 @@ const se = class se {
|
|
|
871
850
|
decimalSeparator: s = ".",
|
|
872
851
|
thousandSeparator: i = ","
|
|
873
852
|
} = {}) {
|
|
874
|
-
const
|
|
853
|
+
const a = this.getValue("number"), [c, o = ""] = a.toFixed(6).split("."), _ = c.replace(/\B(?=(\d{3})+(?!\d))/g, i), h = !c && !o ? "0.00" : c === "0" ? `${parseFloat(`0.${o}`)}`.replace(".", s) : `${_}${parseInt(o) ? `${s}${o.slice(0, r)}` : ""}`;
|
|
875
854
|
return `${n === "start" ? t : ""}${h}${n === "end" ? t : ""}`;
|
|
876
855
|
}
|
|
877
856
|
formatBigIntToSafeValue(t, n) {
|
|
878
857
|
const r = n || this.decimal || B, s = Math.max(
|
|
879
858
|
r,
|
|
880
859
|
b(this.decimalMultiplier)
|
|
881
|
-
), i = t < 0n,
|
|
882
|
-
let h =
|
|
883
|
-
return parseInt(h[r]) >= 5 ? h = `${h.substring(0, r - 1)}${(parseInt(h[r - 1]) + 1).toString()}` : h = h.substring(0, r), `${i ? "-" : ""}${
|
|
860
|
+
), i = t < 0n, a = t.toString().substring(i ? 1 : 0), c = s - (a.length - 1), o = c > 0 ? "0".repeat(c) + a : a, _ = o.length - s;
|
|
861
|
+
let h = o.slice(-s);
|
|
862
|
+
return parseInt(h[r]) >= 5 ? h = `${h.substring(0, r - 1)}${(parseInt(h[r - 1]) + 1).toString()}` : h = h.substring(0, r), `${i ? "-" : ""}${o.slice(
|
|
884
863
|
0,
|
|
885
864
|
_
|
|
886
865
|
)}.${h}`.replace(/\.?0*$/, "");
|
|
887
866
|
}
|
|
888
867
|
};
|
|
889
868
|
C = new WeakSet(), y = function(t, ...n) {
|
|
890
|
-
const r = T(this, U, z).call(this, this, ...n), s = Math.max(r, b(this.decimalMultiplier)), i = N(s),
|
|
891
|
-
(
|
|
869
|
+
const r = T(this, U, z).call(this, this, ...n), s = Math.max(r, b(this.decimalMultiplier)), i = N(s), a = n.reduce(
|
|
870
|
+
(o, _) => {
|
|
892
871
|
const h = this.getBigIntValue(_, s);
|
|
893
872
|
switch (t) {
|
|
894
873
|
case "add":
|
|
895
|
-
return
|
|
874
|
+
return o + h;
|
|
896
875
|
case "sub":
|
|
897
|
-
return
|
|
876
|
+
return o - h;
|
|
898
877
|
case "mul":
|
|
899
|
-
return
|
|
878
|
+
return o * h / i;
|
|
900
879
|
case "div": {
|
|
901
880
|
if (h === 0n)
|
|
902
881
|
throw new RangeError("Division by zero");
|
|
903
|
-
return
|
|
882
|
+
return o * i / h;
|
|
904
883
|
}
|
|
905
884
|
default:
|
|
906
|
-
return
|
|
885
|
+
return o;
|
|
907
886
|
}
|
|
908
887
|
},
|
|
909
888
|
//normalize is to precision multiplier base
|
|
910
889
|
this.bigIntValue * i / this.decimalMultiplier
|
|
911
|
-
),
|
|
890
|
+
), c = G({
|
|
912
891
|
bigIntDecimal: s,
|
|
913
892
|
decimal: s,
|
|
914
|
-
value:
|
|
893
|
+
value: a
|
|
915
894
|
});
|
|
916
895
|
return new this.constructor({
|
|
917
896
|
decimalMultiplier: N(s),
|
|
918
897
|
decimal: this.decimal,
|
|
919
|
-
value:
|
|
898
|
+
value: c,
|
|
920
899
|
identifier: this.toString()
|
|
921
900
|
});
|
|
922
901
|
}, f = new WeakSet(), D = function(t, ...n) {
|
|
@@ -933,22 +912,22 @@ C = new WeakSet(), y = function(t, ...n) {
|
|
|
933
912
|
case "eqValue":
|
|
934
913
|
return i === s;
|
|
935
914
|
}
|
|
936
|
-
},
|
|
937
|
-
const n =
|
|
915
|
+
}, k = new WeakSet(), Ne = function(t) {
|
|
916
|
+
const n = v(t) || "0";
|
|
938
917
|
this.bigIntValue = T(this, L, Z).call(this, n);
|
|
939
918
|
}, U = new WeakSet(), z = function(...t) {
|
|
940
|
-
const n = t.map((r) => typeof r == "object" ? r.decimal || b(r.decimalMultiplier) : _e(
|
|
919
|
+
const n = t.map((r) => typeof r == "object" ? r.decimal || b(r.decimalMultiplier) : _e(v(r))).filter(Boolean);
|
|
941
920
|
return Math.max(...n, B);
|
|
942
921
|
}, L = new WeakSet(), Z = function(t, n) {
|
|
943
|
-
const r = n ? N(n) : this.decimalMultiplier, s = b(r), [i = "",
|
|
944
|
-
return BigInt(`${i}${
|
|
922
|
+
const r = n ? N(n) : this.decimalMultiplier, s = b(r), [i = "", a = ""] = t.split(".");
|
|
923
|
+
return BigInt(`${i}${a.padEnd(s, "0")}`);
|
|
945
924
|
};
|
|
946
925
|
let W = se;
|
|
947
926
|
const Tt = Intl.NumberFormat("fullwide", {
|
|
948
927
|
useGrouping: !1,
|
|
949
928
|
maximumFractionDigits: 20
|
|
950
929
|
});
|
|
951
|
-
function
|
|
930
|
+
function v(e) {
|
|
952
931
|
const n = `${typeof e == "number" ? Tt.format(e) : ee(e)}`.replaceAll(",", ".").split(".");
|
|
953
932
|
return n.length > 1 ? `${n.slice(0, -1).join("")}.${n.at(-1)}` : n[0];
|
|
954
933
|
}
|
|
@@ -967,8 +946,8 @@ class g extends W {
|
|
|
967
946
|
decimal: r,
|
|
968
947
|
tax: s,
|
|
969
948
|
chain: i,
|
|
970
|
-
symbol:
|
|
971
|
-
identifier:
|
|
949
|
+
symbol: a,
|
|
950
|
+
identifier: c
|
|
972
951
|
}) {
|
|
973
952
|
super(typeof n == "object" ? n : { decimal: r, value: n });
|
|
974
953
|
p(this, "address");
|
|
@@ -979,8 +958,8 @@ class g extends W {
|
|
|
979
958
|
p(this, "tax");
|
|
980
959
|
p(this, "ticker");
|
|
981
960
|
p(this, "type");
|
|
982
|
-
const
|
|
983
|
-
this.type = ot(
|
|
961
|
+
const o = F(c || `${i}.${a}`);
|
|
962
|
+
this.type = ot(o), this.tax = s, this.chain = o.chain, this.ticker = o.ticker, this.symbol = o.symbol, this.address = o.address, this.isSynthetic = o.isSynthetic, this.isGasAsset = o.isGasAsset;
|
|
984
963
|
}
|
|
985
964
|
toString() {
|
|
986
965
|
return this.isSynthetic ? this.symbol : `${this.chain}.${this.symbol}`;
|
|
@@ -998,11 +977,11 @@ class g extends W {
|
|
|
998
977
|
// THOR.ETH.ETH
|
|
999
978
|
// ETH.THOR-0x1234567890
|
|
1000
979
|
static fromUrl(n, r = 0) {
|
|
1001
|
-
const [s, i,
|
|
980
|
+
const [s, i, a] = n.split(".");
|
|
1002
981
|
if (!s || !i)
|
|
1003
982
|
throw new Error("Invalid asset url");
|
|
1004
|
-
const
|
|
1005
|
-
return J(
|
|
983
|
+
const c = s === l.THORChain && a ? `${s}.${i}/${a}` : n;
|
|
984
|
+
return J(c, r);
|
|
1006
985
|
}
|
|
1007
986
|
static fromString(n, r = 0) {
|
|
1008
987
|
return J(n, r);
|
|
@@ -1011,29 +990,29 @@ class g extends W {
|
|
|
1011
990
|
return J(n, r);
|
|
1012
991
|
}
|
|
1013
992
|
static fromStringSync(n, r = 0) {
|
|
1014
|
-
const { chain: s, isSynthetic: i } =
|
|
993
|
+
const { chain: s, isSynthetic: i } = F(n), a = w.get(n.toUpperCase());
|
|
1015
994
|
if (i)
|
|
1016
995
|
return he(n, r);
|
|
1017
|
-
const { tax:
|
|
996
|
+
const { tax: c, decimal: o, identifier: _ } = a || {
|
|
1018
997
|
decimal: d[s],
|
|
1019
998
|
identifier: n
|
|
1020
999
|
};
|
|
1021
1000
|
return new g({
|
|
1022
|
-
tax:
|
|
1023
|
-
value: V(r,
|
|
1001
|
+
tax: c,
|
|
1002
|
+
value: V(r, o),
|
|
1024
1003
|
identifier: i ? n : _,
|
|
1025
|
-
decimal: i ? 8 :
|
|
1004
|
+
decimal: i ? 8 : o
|
|
1026
1005
|
});
|
|
1027
1006
|
}
|
|
1028
1007
|
static fromIdentifierSync(n, r = 0) {
|
|
1029
|
-
const { chain: s, isSynthetic: i } =
|
|
1008
|
+
const { chain: s, isSynthetic: i } = F(n), a = w.get(n);
|
|
1030
1009
|
if (i)
|
|
1031
1010
|
return he(n, r);
|
|
1032
|
-
const { tax:
|
|
1011
|
+
const { tax: c, decimal: o, identifier: _ } = a || {
|
|
1033
1012
|
decimal: d[s],
|
|
1034
1013
|
identifier: n
|
|
1035
1014
|
};
|
|
1036
|
-
return new g({ tax:
|
|
1015
|
+
return new g({ tax: c, decimal: o, identifier: _, value: V(r, o) });
|
|
1037
1016
|
}
|
|
1038
1017
|
static fromChainOrSignature(n, r = 0) {
|
|
1039
1018
|
const { decimal: s, identifier: i } = at(n);
|
|
@@ -1045,11 +1024,11 @@ class g extends W {
|
|
|
1045
1024
|
try {
|
|
1046
1025
|
const s = await import("@swapkit/tokens");
|
|
1047
1026
|
Object.values(s).forEach((i) => {
|
|
1048
|
-
var
|
|
1049
|
-
(
|
|
1050
|
-
w.set(
|
|
1051
|
-
identifier:
|
|
1052
|
-
decimal: "decimals" in _ ? _.decimals : d[
|
|
1027
|
+
var a;
|
|
1028
|
+
(a = i == null ? void 0 : i.tokens) == null || a.forEach(({ identifier: c, chain: o, ..._ }) => {
|
|
1029
|
+
w.set(c.toUpperCase(), {
|
|
1030
|
+
identifier: c,
|
|
1031
|
+
decimal: "decimals" in _ ? _.decimals : d[o]
|
|
1053
1032
|
});
|
|
1054
1033
|
});
|
|
1055
1034
|
}), n({ ok: !0 });
|
|
@@ -1067,19 +1046,19 @@ class g extends W {
|
|
|
1067
1046
|
function Vt(e) {
|
|
1068
1047
|
const t = g.fromChainOrSignature(e);
|
|
1069
1048
|
switch (e) {
|
|
1070
|
-
case
|
|
1071
|
-
case
|
|
1072
|
-
case
|
|
1049
|
+
case l.Bitcoin:
|
|
1050
|
+
case l.Litecoin:
|
|
1051
|
+
case l.BitcoinCash:
|
|
1073
1052
|
return t.set(10001e-8);
|
|
1074
|
-
case
|
|
1053
|
+
case l.Dogecoin:
|
|
1075
1054
|
return t.set(1.00000001);
|
|
1076
|
-
case
|
|
1077
|
-
case
|
|
1055
|
+
case l.Avalanche:
|
|
1056
|
+
case l.Ethereum:
|
|
1078
1057
|
return t.set(1e-8);
|
|
1079
|
-
case
|
|
1080
|
-
case
|
|
1058
|
+
case l.THORChain:
|
|
1059
|
+
case l.Maya:
|
|
1081
1060
|
return t.set(0);
|
|
1082
|
-
case
|
|
1061
|
+
case l.Cosmos:
|
|
1083
1062
|
return t.set(1e-6);
|
|
1084
1063
|
default:
|
|
1085
1064
|
return t.set(1e-8);
|
|
@@ -1087,34 +1066,34 @@ function Vt(e) {
|
|
|
1087
1066
|
}
|
|
1088
1067
|
async function J(e, t = 0) {
|
|
1089
1068
|
dt(e);
|
|
1090
|
-
const n = w.get(e.toUpperCase()), r = (n == null ? void 0 : n.decimal) || await it(
|
|
1069
|
+
const n = w.get(e.toUpperCase()), r = (n == null ? void 0 : n.decimal) || await it(F(e));
|
|
1091
1070
|
return n || w.set(e.toUpperCase(), { identifier: e, decimal: r }), new g({ decimal: r, value: V(t, r), identifier: e });
|
|
1092
1071
|
}
|
|
1093
1072
|
function he(e, t = 0) {
|
|
1094
|
-
const [n, r] = e.split(".")[0].toUpperCase() ===
|
|
1073
|
+
const [n, r] = e.split(".")[0].toUpperCase() === l.THORChain ? e.split(".").slice(1).join().split("/") : e.split("/");
|
|
1095
1074
|
if (!n || !r)
|
|
1096
1075
|
throw new Error("Invalid asset identifier");
|
|
1097
1076
|
return new g({
|
|
1098
1077
|
decimal: 8,
|
|
1099
1078
|
value: V(t, 8),
|
|
1100
|
-
identifier: `${
|
|
1079
|
+
identifier: `${l.THORChain}.${n}/${r}`
|
|
1101
1080
|
});
|
|
1102
1081
|
}
|
|
1103
1082
|
function V(e, t) {
|
|
1104
1083
|
return typeof e == "bigint" ? G({ value: e, bigIntDecimal: t, decimal: t }) : e;
|
|
1105
1084
|
}
|
|
1106
|
-
function
|
|
1107
|
-
const t = e.slice(0, 14).includes("/"), [n, r] = e.split(".")[0].toUpperCase() ===
|
|
1085
|
+
function F(e) {
|
|
1086
|
+
const t = e.slice(0, 14).includes("/"), [n, r] = e.split(".")[0].toUpperCase() === l.THORChain ? e.split(".").slice(1).join().split("/") : e.split("/");
|
|
1108
1087
|
if (t && (!n || !r))
|
|
1109
1088
|
throw new Error("Invalid asset identifier");
|
|
1110
|
-
const s = e.includes(".") && !t ? e : `${
|
|
1089
|
+
const s = e.includes(".") && !t ? e : `${l.THORChain}.${r}`, [i, ...a] = s.split("."), [c, o] = (t ? r : a.join(".")).split("-"), _ = t ? r : a.join(".");
|
|
1111
1090
|
return {
|
|
1112
|
-
address:
|
|
1091
|
+
address: o == null ? void 0 : o.toLowerCase(),
|
|
1113
1092
|
chain: i,
|
|
1114
1093
|
isGasAsset: fe({ chain: i, symbol: _ }),
|
|
1115
1094
|
isSynthetic: t,
|
|
1116
|
-
symbol: (t ? `${n}/` : "") + (
|
|
1117
|
-
ticker:
|
|
1095
|
+
symbol: (t ? `${n}/` : "") + (o ? `${c}-${(o == null ? void 0 : o.toLowerCase()) ?? ""}` : _),
|
|
1096
|
+
ticker: c
|
|
1118
1097
|
};
|
|
1119
1098
|
}
|
|
1120
1099
|
const At = {
|
|
@@ -1217,7 +1196,7 @@ export {
|
|
|
1217
1196
|
ot as getAssetType,
|
|
1218
1197
|
_t as getAsymmetricAssetShare,
|
|
1219
1198
|
Ct as getAsymmetricAssetWithdrawAmount,
|
|
1220
|
-
|
|
1199
|
+
ut as getAsymmetricRuneShare,
|
|
1221
1200
|
Nt as getAsymmetricRuneWithdrawAmount,
|
|
1222
1201
|
at as getCommonAssetInfo,
|
|
1223
1202
|
it as getDecimal,
|