@swapkit/helpers 1.0.0-rc.68 → 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.es.js +358 -385
- package/dist/index.es.js.map +1 -1
- package/package.json +4 -4
- package/src/helpers/asset.ts +11 -43
- package/src/helpers/validators.ts +1 -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
|
|
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
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
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.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.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.
|
|
17
|
-
const q = Object.values(j),
|
|
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
|
{}
|
|
@@ -37,9 +37,9 @@ q.reduce(
|
|
|
37
37
|
{}
|
|
38
38
|
);
|
|
39
39
|
class oe extends Error {
|
|
40
|
-
constructor(t, n,
|
|
41
|
-
const
|
|
42
|
-
super(`Request failed with ${
|
|
40
|
+
constructor(t, n, r) {
|
|
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,
|
|
@@ -54,7 +54,7 @@ class oe extends Error {
|
|
|
54
54
|
configurable: !0,
|
|
55
55
|
writable: !0,
|
|
56
56
|
value: void 0
|
|
57
|
-
}), this.name = "HTTPError", this.response = t, this.request = n, this.options =
|
|
57
|
+
}), this.name = "HTTPError", this.response = t, this.request = n, this.options = r;
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
class Te extends Error {
|
|
@@ -67,31 +67,31 @@ 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
|
-
return
|
|
74
|
+
return re({}, ...e);
|
|
75
75
|
}, Ae = (e = {}, t = {}) => {
|
|
76
|
-
const n = new globalThis.Headers(e),
|
|
77
|
-
for (const [i,
|
|
78
|
-
|
|
76
|
+
const n = new globalThis.Headers(e), r = t instanceof globalThis.Headers, s = new globalThis.Headers(t);
|
|
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 = {};
|
|
82
|
-
for (const
|
|
83
|
-
if (Array.isArray(
|
|
84
|
-
Array.isArray(t) || (t = []), t = [...t, ...
|
|
85
|
-
else if (M(
|
|
86
|
-
for (let [
|
|
87
|
-
M(i) &&
|
|
88
|
-
M(
|
|
82
|
+
for (const r of e)
|
|
83
|
+
if (Array.isArray(r))
|
|
84
|
+
Array.isArray(t) || (t = []), t = [...t, ...r];
|
|
85
|
+
else if (M(r)) {
|
|
86
|
+
for (let [s, i] of Object.entries(r))
|
|
87
|
+
M(i) && s in t && (i = re(t[s], i)), t = { ...t, [s]: i };
|
|
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
|
-
const n = typeof globalThis.ReadableStream == "function",
|
|
94
|
-
return n &&
|
|
93
|
+
const n = typeof globalThis.ReadableStream == "function", r = typeof globalThis.Request == "function";
|
|
94
|
+
return n && r && (t = new globalThis.Request("https://empty.invalid", {
|
|
95
95
|
body: new globalThis.ReadableStream(),
|
|
96
96
|
method: "POST",
|
|
97
97
|
// @ts-expect-error - Types are outdated.
|
|
@@ -156,70 +156,70 @@ const M = (e) => e !== null && typeof e == "object", v = (...e) => {
|
|
|
156
156
|
afterStatusCodes: me
|
|
157
157
|
};
|
|
158
158
|
};
|
|
159
|
-
async function Ye(e, t, n,
|
|
160
|
-
return new Promise((
|
|
161
|
-
const
|
|
159
|
+
async function Ye(e, t, n, r) {
|
|
160
|
+
return new Promise((s, i) => {
|
|
161
|
+
const a = setTimeout(() => {
|
|
162
162
|
n && n.abort(), i(new Te(e));
|
|
163
|
-
},
|
|
164
|
-
|
|
165
|
-
clearTimeout(
|
|
163
|
+
}, r.timeout);
|
|
164
|
+
r.fetch(e, t).then(s).catch(i).then(() => {
|
|
165
|
+
clearTimeout(a);
|
|
166
166
|
});
|
|
167
167
|
});
|
|
168
168
|
}
|
|
169
169
|
async function Ke(e, { signal: t }) {
|
|
170
|
-
return new Promise((n,
|
|
171
|
-
t && (t.throwIfAborted(), t.addEventListener("abort",
|
|
172
|
-
function
|
|
173
|
-
clearTimeout(i),
|
|
170
|
+
return new Promise((n, r) => {
|
|
171
|
+
t && (t.throwIfAborted(), t.addEventListener("abort", s, { once: !0 }));
|
|
172
|
+
function s() {
|
|
173
|
+
clearTimeout(i), r(t.reason);
|
|
174
174
|
}
|
|
175
175
|
const i = setTimeout(() => {
|
|
176
|
-
t == null || t.removeEventListener("abort",
|
|
176
|
+
t == null || t.removeEventListener("abort", s), n();
|
|
177
177
|
}, e);
|
|
178
178
|
});
|
|
179
179
|
}
|
|
180
180
|
const Je = (e, t) => {
|
|
181
181
|
const n = {};
|
|
182
|
-
for (const
|
|
183
|
-
!(
|
|
182
|
+
for (const r in t)
|
|
183
|
+
!(r in We) && !(r in Ge) && !(r in e) && (n[r] = t[r]);
|
|
184
184
|
return n;
|
|
185
185
|
};
|
|
186
186
|
class x {
|
|
187
187
|
static create(t, n) {
|
|
188
|
-
const
|
|
189
|
-
if (typeof
|
|
188
|
+
const r = new x(t, n), s = async () => {
|
|
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 (
|
|
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
|
-
if (
|
|
204
|
-
if (typeof
|
|
203
|
+
if (r._options.onDownloadProgress) {
|
|
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
|
|
208
|
+
return r._stream(a.clone(), r._options.onDownloadProgress);
|
|
209
209
|
}
|
|
210
|
-
return
|
|
211
|
-
}, i =
|
|
212
|
-
for (const [
|
|
213
|
-
i[
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
if (
|
|
217
|
-
if (
|
|
210
|
+
return a;
|
|
211
|
+
}, i = r._options.retry.methods.includes(r.request.method.toLowerCase()) ? r._retry(s) : s();
|
|
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
|
}
|
|
@@ -255,7 +255,7 @@ class x {
|
|
|
255
255
|
credentials: this._input.credentials || "same-origin",
|
|
256
256
|
...n,
|
|
257
257
|
headers: Ae(this._input.headers, n.headers),
|
|
258
|
-
hooks:
|
|
258
|
+
hooks: re({
|
|
259
259
|
beforeRequest: [],
|
|
260
260
|
beforeRetry: [],
|
|
261
261
|
beforeError: [],
|
|
@@ -277,16 +277,16 @@ class x {
|
|
|
277
277
|
}
|
|
278
278
|
if (Me) {
|
|
279
279
|
if (this.abortController = new globalThis.AbortController(), this._options.signal) {
|
|
280
|
-
const
|
|
280
|
+
const r = this._options.signal;
|
|
281
281
|
this._options.signal.addEventListener("abort", () => {
|
|
282
|
-
this.abortController.abort(
|
|
282
|
+
this.abortController.abort(r.reason);
|
|
283
283
|
});
|
|
284
284
|
}
|
|
285
285
|
this._options.signal = this.abortController.signal;
|
|
286
286
|
}
|
|
287
|
-
if (
|
|
288
|
-
const
|
|
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(
|
|
287
|
+
if (ve && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
|
|
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
|
+
(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
|
}
|
|
@@ -295,10 +295,10 @@ class x {
|
|
|
295
295
|
if (t instanceof oe) {
|
|
296
296
|
if (!this._options.retry.statusCodes.includes(t.response.status))
|
|
297
297
|
return 0;
|
|
298
|
-
const
|
|
299
|
-
if (
|
|
300
|
-
let
|
|
301
|
-
return Number.isNaN(
|
|
298
|
+
const r = t.response.headers.get("Retry-After");
|
|
299
|
+
if (r && this._options.retry.afterStatusCodes.includes(t.response.status)) {
|
|
300
|
+
let s = Number(r);
|
|
301
|
+
return Number.isNaN(s) ? s = Date.parse(r) - Date.now() : s *= 1e3, this._options.retry.maxRetryAfter !== void 0 && s > this._options.retry.maxRetryAfter ? 0 : s;
|
|
302
302
|
}
|
|
303
303
|
if (t.response.status === 413)
|
|
304
304
|
return 0;
|
|
@@ -315,11 +315,11 @@ class x {
|
|
|
315
315
|
try {
|
|
316
316
|
return await t();
|
|
317
317
|
} catch (n) {
|
|
318
|
-
const
|
|
319
|
-
if (
|
|
320
|
-
await Ke(
|
|
321
|
-
for (const
|
|
322
|
-
if (await
|
|
318
|
+
const r = Math.min(this._calculateRetryDelay(n), K);
|
|
319
|
+
if (r !== 0 && this._retryCount > 0) {
|
|
320
|
+
await Ke(r, { signal: this._options.signal });
|
|
321
|
+
for (const s of this._options.hooks.beforeRetry)
|
|
322
|
+
if (await s({
|
|
323
323
|
request: this.request,
|
|
324
324
|
options: this._options,
|
|
325
325
|
error: n,
|
|
@@ -333,43 +333,43 @@ class x {
|
|
|
333
333
|
}
|
|
334
334
|
async _fetch() {
|
|
335
335
|
for (const n of this._options.hooks.beforeRequest) {
|
|
336
|
-
const
|
|
337
|
-
if (
|
|
338
|
-
this.request =
|
|
336
|
+
const r = await n(this.request, this._options);
|
|
337
|
+
if (r instanceof Request) {
|
|
338
|
+
this.request = r;
|
|
339
339
|
break;
|
|
340
340
|
}
|
|
341
|
-
if (
|
|
342
|
-
return
|
|
341
|
+
if (r instanceof Response)
|
|
342
|
+
return r;
|
|
343
343
|
}
|
|
344
344
|
const t = Je(this.request, this._options);
|
|
345
345
|
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Ye(this.request.clone(), t, this.abortController, this._options);
|
|
346
346
|
}
|
|
347
347
|
/* istanbul ignore next */
|
|
348
348
|
_stream(t, n) {
|
|
349
|
-
const
|
|
350
|
-
let
|
|
351
|
-
return t.status === 204 ? (n && n({ percent: 1, totalBytes:
|
|
349
|
+
const r = Number(t.headers.get("content-length")) || 0;
|
|
350
|
+
let s = 0;
|
|
351
|
+
return t.status === 204 ? (n && n({ percent: 1, totalBytes: r, transferredBytes: s }, new Uint8Array()), new globalThis.Response(null, {
|
|
352
352
|
status: t.status,
|
|
353
353
|
statusText: t.statusText,
|
|
354
354
|
headers: t.headers
|
|
355
355
|
})) : new globalThis.Response(new globalThis.ReadableStream({
|
|
356
356
|
async start(i) {
|
|
357
|
-
const
|
|
358
|
-
n && n({ percent: 0, transferredBytes: 0, totalBytes:
|
|
359
|
-
async function
|
|
360
|
-
const { done:
|
|
361
|
-
if (
|
|
357
|
+
const a = t.body.getReader();
|
|
358
|
+
n && n({ percent: 0, transferredBytes: 0, totalBytes: r }, new Uint8Array());
|
|
359
|
+
async function c() {
|
|
360
|
+
const { done: o, value: _ } = await a.read();
|
|
361
|
+
if (o) {
|
|
362
362
|
i.close();
|
|
363
363
|
return;
|
|
364
364
|
}
|
|
365
365
|
if (n) {
|
|
366
|
-
|
|
367
|
-
const h =
|
|
368
|
-
n({ percent: h, transferredBytes:
|
|
366
|
+
s += _.byteLength;
|
|
367
|
+
const h = r === 0 ? 0 : s / r;
|
|
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 x {
|
|
|
380
380
|
}
|
|
381
381
|
/*! MIT License © Sindre Sorhus */
|
|
382
382
|
const Q = (e) => {
|
|
383
|
-
const t = (n,
|
|
383
|
+
const t = (n, r) => x.create(n, $(e, r));
|
|
384
384
|
for (const n of pe)
|
|
385
|
-
t[n] = (
|
|
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 = {
|
|
@@ -404,7 +404,7 @@ const m = {
|
|
|
404
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((
|
|
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
|
});
|
|
@@ -422,7 +422,7 @@ const m = {
|
|
|
422
422
|
var ze = /* @__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))(ze || {}), 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 || {}), et = /* @__PURE__ */ ((e) => (e[e.NOT_STARTED = 0] = "NOT_STARTED", e[e.SUCCESS = 1] = "SUCCESS", e[e.REFUNDED = 2] = "REFUNDED", e))(et || {});
|
|
423
423
|
const tt = "0x313ce567", Ie = async ({ chain: e, to: t }) => {
|
|
424
424
|
try {
|
|
425
|
-
const { result: n } = await S.post(
|
|
425
|
+
const { result: n } = await S.post(Ue[e], {
|
|
426
426
|
headers: {
|
|
427
427
|
accept: "*/*",
|
|
428
428
|
"content-type": "application/json",
|
|
@@ -440,21 +440,21 @@ 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:
|
|
447
|
-
},
|
|
446
|
+
return t != null && t.startsWith("0x") ? Ie({ chain: l.Ethereum, to: t }) : d.ETH;
|
|
447
|
+
}, rt = async (e) => {
|
|
448
448
|
const [, t] = e.split("-");
|
|
449
|
-
return t != null && t.startsWith("0x") ? Ie({ chain:
|
|
450
|
-
},
|
|
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
|
|
455
|
-
return st(t);
|
|
456
|
-
case a.BinanceSmartChain:
|
|
454
|
+
case l.Avalanche:
|
|
457
455
|
return rt(t);
|
|
456
|
+
case l.BinanceSmartChain:
|
|
457
|
+
return st(t);
|
|
458
458
|
default:
|
|
459
459
|
return d[e];
|
|
460
460
|
}
|
|
@@ -464,101 +464,74 @@ 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
|
-
case a.Polkadot:
|
|
475
|
-
case a.Chainflip:
|
|
476
|
-
return t === e;
|
|
477
|
-
case a.Arbitrum:
|
|
478
|
-
case a.Optimism:
|
|
467
|
+
case l.Arbitrum:
|
|
468
|
+
case l.Optimism:
|
|
479
469
|
return t === "ETH";
|
|
480
|
-
case
|
|
470
|
+
case l.Maya:
|
|
481
471
|
return t === "CACAO";
|
|
482
|
-
case
|
|
472
|
+
case l.Kujira:
|
|
483
473
|
return t === "KUJI";
|
|
484
|
-
case
|
|
474
|
+
case l.Cosmos:
|
|
485
475
|
return t === "ATOM";
|
|
486
|
-
case
|
|
476
|
+
case l.Polygon:
|
|
487
477
|
return t === "MATIC";
|
|
488
|
-
case
|
|
478
|
+
case l.BinanceSmartChain:
|
|
489
479
|
return t === "BNB";
|
|
490
|
-
case
|
|
480
|
+
case l.THORChain:
|
|
491
481
|
return t === "RUNE";
|
|
482
|
+
default:
|
|
483
|
+
return t === e;
|
|
492
484
|
}
|
|
493
485
|
}, at = (e) => {
|
|
494
486
|
switch (e) {
|
|
495
|
-
case `${
|
|
487
|
+
case `${l.Ethereum}.THOR`:
|
|
496
488
|
return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
|
|
497
|
-
case `${
|
|
489
|
+
case `${l.Ethereum}.vTHOR`:
|
|
498
490
|
return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
|
|
499
|
-
case
|
|
491
|
+
case l.Cosmos:
|
|
500
492
|
return { identifier: "GAIA.ATOM", decimal: d[e] };
|
|
501
|
-
case
|
|
493
|
+
case l.THORChain:
|
|
502
494
|
return { identifier: "THOR.RUNE", decimal: d[e] };
|
|
503
|
-
case
|
|
495
|
+
case l.BinanceSmartChain:
|
|
504
496
|
return { identifier: "BSC.BNB", decimal: d[e] };
|
|
505
|
-
case
|
|
497
|
+
case l.Maya:
|
|
506
498
|
return { identifier: "MAYA.CACAO", decimal: d.MAYA };
|
|
507
|
-
case `${
|
|
499
|
+
case `${l.Maya}.MAYA`:
|
|
508
500
|
return { identifier: "MAYA.MAYA", decimal: 4 };
|
|
509
|
-
case `${
|
|
510
|
-
return { identifier: `${
|
|
511
|
-
|
|
512
|
-
case a.Arbitrum:
|
|
513
|
-
case a.Optimism:
|
|
514
|
-
case a.BitcoinCash:
|
|
515
|
-
case a.Litecoin:
|
|
516
|
-
case a.Dogecoin:
|
|
517
|
-
case a.Binance:
|
|
518
|
-
case a.Avalanche:
|
|
519
|
-
case a.Chainflip:
|
|
520
|
-
case a.Polygon:
|
|
521
|
-
case a.Polkadot:
|
|
522
|
-
case a.Bitcoin:
|
|
523
|
-
case a.Ethereum:
|
|
501
|
+
case `${l.Kujira}.USK`:
|
|
502
|
+
return { identifier: `${l.Kujira}.USK`, decimal: 6 };
|
|
503
|
+
default:
|
|
524
504
|
return { identifier: `${e}.${e}`, decimal: d[e] };
|
|
525
505
|
}
|
|
526
506
|
}, ot = ({ chain: e, symbol: t }) => {
|
|
527
507
|
if (t.includes("/"))
|
|
528
508
|
return "Synth";
|
|
529
509
|
switch (e) {
|
|
530
|
-
case
|
|
531
|
-
|
|
532
|
-
case
|
|
533
|
-
|
|
534
|
-
case
|
|
535
|
-
|
|
536
|
-
case
|
|
537
|
-
|
|
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:
|
|
538
529
|
return "Native";
|
|
539
|
-
case a.Cosmos:
|
|
540
|
-
return t === "ATOM" ? "Native" : a.Cosmos;
|
|
541
|
-
case a.Kujira:
|
|
542
|
-
return t === a.Kujira ? "Native" : a.Kujira;
|
|
543
|
-
case a.Binance:
|
|
544
|
-
return t === a.Binance ? "Native" : "BEP2";
|
|
545
|
-
case a.BinanceSmartChain:
|
|
546
|
-
return t === a.Binance ? "Native" : "BEP20";
|
|
547
|
-
case a.Ethereum:
|
|
548
|
-
return t === a.Ethereum ? "Native" : "ERC20";
|
|
549
|
-
case a.Avalanche:
|
|
550
|
-
return t === a.Avalanche ? "Native" : a.Avalanche;
|
|
551
|
-
case a.Polygon:
|
|
552
|
-
return t === a.Polygon ? "Native" : "POLYGON";
|
|
553
|
-
case a.Arbitrum:
|
|
554
|
-
return [a.Ethereum, a.Arbitrum].includes(t) ? "Native" : "ARBITRUM";
|
|
555
|
-
case a.Optimism:
|
|
556
|
-
return [a.Ethereum, a.Optimism].includes(t) ? "Native" : "OPTIMISM";
|
|
557
530
|
}
|
|
558
531
|
}, It = (e) => {
|
|
559
|
-
var
|
|
560
|
-
const [t, ...n] = e.split("."),
|
|
561
|
-
return { chain: t, symbol:
|
|
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];
|
|
534
|
+
return { chain: t, symbol: s, ticker: i, synth: r };
|
|
562
535
|
}, ct = new RegExp(
|
|
563
536
|
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
|
|
564
537
|
"gmi"
|
|
@@ -566,43 +539,43 @@ const tt = "0x313ce567", Ie = async ({ chain: e, to: t }) => {
|
|
|
566
539
|
const [t, n] = e.split(".");
|
|
567
540
|
if (!Be.includes(t))
|
|
568
541
|
return !0;
|
|
569
|
-
const [,
|
|
570
|
-
return fe({ chain: t, symbol: n }) || !!
|
|
571
|
-
}, ft = (e) => e.filter((t) => {
|
|
572
|
-
const
|
|
573
|
-
return !ct.test(
|
|
542
|
+
const [, r] = n.split("-");
|
|
543
|
+
return fe({ chain: t, symbol: n }) || !!r;
|
|
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";
|
|
574
547
|
});
|
|
575
548
|
function ut({
|
|
576
549
|
liquidityUnits: e,
|
|
577
550
|
poolUnits: t,
|
|
578
551
|
runeDepth: n
|
|
579
552
|
}) {
|
|
580
|
-
const
|
|
581
|
-
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);
|
|
582
555
|
}
|
|
583
556
|
function _t({
|
|
584
557
|
liquidityUnits: e,
|
|
585
558
|
poolUnits: t,
|
|
586
559
|
assetDepth: n
|
|
587
560
|
}) {
|
|
588
|
-
const
|
|
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);
|
|
589
562
|
return h.div(P);
|
|
590
563
|
}
|
|
591
|
-
function
|
|
564
|
+
function Nt({
|
|
592
565
|
percent: e,
|
|
593
566
|
runeDepth: t,
|
|
594
567
|
liquidityUnits: n,
|
|
595
|
-
poolUnits:
|
|
568
|
+
poolUnits: r
|
|
596
569
|
}) {
|
|
597
|
-
return ut({ runeDepth: t, liquidityUnits: n, poolUnits:
|
|
570
|
+
return ut({ runeDepth: t, liquidityUnits: n, poolUnits: r }).mul(e);
|
|
598
571
|
}
|
|
599
|
-
function
|
|
572
|
+
function Ct({
|
|
600
573
|
percent: e,
|
|
601
574
|
assetDepth: t,
|
|
602
575
|
liquidityUnits: n,
|
|
603
|
-
poolUnits:
|
|
576
|
+
poolUnits: r
|
|
604
577
|
}) {
|
|
605
|
-
return _t({ assetDepth: t, liquidityUnits: n, poolUnits:
|
|
578
|
+
return _t({ assetDepth: t, liquidityUnits: n, poolUnits: r }).mul(e);
|
|
606
579
|
}
|
|
607
580
|
function A(e) {
|
|
608
581
|
return I.fromBigInt(BigInt(e), d.THOR);
|
|
@@ -611,10 +584,10 @@ function ht({
|
|
|
611
584
|
liquidityUnits: e,
|
|
612
585
|
poolUnits: t,
|
|
613
586
|
runeDepth: n,
|
|
614
|
-
assetDepth:
|
|
587
|
+
assetDepth: r
|
|
615
588
|
}) {
|
|
616
589
|
return {
|
|
617
|
-
assetAmount: A(
|
|
590
|
+
assetAmount: A(r).mul(e).div(t),
|
|
618
591
|
runeAmount: A(n).mul(e).div(t)
|
|
619
592
|
};
|
|
620
593
|
}
|
|
@@ -622,12 +595,12 @@ function gt({
|
|
|
622
595
|
liquidityUnits: e,
|
|
623
596
|
poolUnits: t,
|
|
624
597
|
runeDepth: n,
|
|
625
|
-
assetDepth:
|
|
626
|
-
percent:
|
|
598
|
+
assetDepth: r,
|
|
599
|
+
percent: s
|
|
627
600
|
}) {
|
|
628
601
|
return Object.fromEntries(
|
|
629
|
-
Object.entries(ht({ liquidityUnits: e, poolUnits: t, runeDepth: n, assetDepth:
|
|
630
|
-
([i,
|
|
602
|
+
Object.entries(ht({ liquidityUnits: e, poolUnits: t, runeDepth: n, assetDepth: r })).map(
|
|
603
|
+
([i, a]) => [i, a.mul(s)]
|
|
631
604
|
)
|
|
632
605
|
);
|
|
633
606
|
}
|
|
@@ -635,26 +608,26 @@ function Ot({
|
|
|
635
608
|
runeDepth: e,
|
|
636
609
|
poolUnits: t,
|
|
637
610
|
assetDepth: n,
|
|
638
|
-
liquidityUnits:
|
|
639
|
-
runeAmount:
|
|
611
|
+
liquidityUnits: r,
|
|
612
|
+
runeAmount: s,
|
|
640
613
|
assetAmount: i
|
|
641
614
|
}) {
|
|
642
|
-
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);
|
|
643
616
|
if (ae.getBaseValue("number") === 0)
|
|
644
|
-
return X.div(
|
|
645
|
-
const be =
|
|
617
|
+
return X.div(o).getBaseValue("number");
|
|
618
|
+
const be = o.add(X);
|
|
646
619
|
return X.div(be).getBaseValue("number");
|
|
647
620
|
}
|
|
648
621
|
function Dt({
|
|
649
622
|
runeAmount: e,
|
|
650
623
|
assetAmount: t,
|
|
651
624
|
runeDepth: n,
|
|
652
|
-
assetDepth:
|
|
625
|
+
assetDepth: r
|
|
653
626
|
}) {
|
|
654
|
-
if (e === "0" || t === "0" || n === "0" ||
|
|
627
|
+
if (e === "0" || t === "0" || n === "0" || r === "0")
|
|
655
628
|
return 0;
|
|
656
|
-
const
|
|
657
|
-
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"));
|
|
658
631
|
}
|
|
659
632
|
const Pt = (e, t) => {
|
|
660
633
|
switch (e) {
|
|
@@ -664,36 +637,36 @@ const Pt = (e, t) => {
|
|
|
664
637
|
return `${e}:${n}`;
|
|
665
638
|
}
|
|
666
639
|
case E.UNBOND: {
|
|
667
|
-
const { address: n, unbondAmount:
|
|
668
|
-
return `${e}:${n}:${
|
|
640
|
+
const { address: n, unbondAmount: r } = t;
|
|
641
|
+
return `${e}:${n}:${r}`;
|
|
669
642
|
}
|
|
670
643
|
case E.THORNAME_REGISTER: {
|
|
671
|
-
const { name: n, chain:
|
|
672
|
-
return `${e}:${n}:${
|
|
644
|
+
const { name: n, chain: r, address: s, owner: i } = t;
|
|
645
|
+
return `${e}:${n}:${r}:${s}${i ? `:${i}` : ""}`;
|
|
673
646
|
}
|
|
674
647
|
case E.DEPOSIT: {
|
|
675
|
-
const { chain: n, symbol:
|
|
676
|
-
return i ? `${e}:${n}/${
|
|
677
|
-
switch (
|
|
678
|
-
case
|
|
648
|
+
const { chain: n, symbol: r, address: s, singleSide: i } = t;
|
|
649
|
+
return i ? `${e}:${n}/${r}::t:0` : `${e}:${((c, o) => {
|
|
650
|
+
switch (c) {
|
|
651
|
+
case l.Litecoin:
|
|
679
652
|
return "l";
|
|
680
|
-
case
|
|
653
|
+
case l.Dogecoin:
|
|
681
654
|
return "d";
|
|
682
|
-
case
|
|
655
|
+
case l.BitcoinCash:
|
|
683
656
|
return "c";
|
|
684
657
|
default:
|
|
685
|
-
return `${
|
|
658
|
+
return `${c}.${o}`;
|
|
686
659
|
}
|
|
687
|
-
})(n,
|
|
660
|
+
})(n, r)}:${s || ""}:t:0`;
|
|
688
661
|
}
|
|
689
662
|
case E.WITHDRAW: {
|
|
690
|
-
const { chain: n, ticker:
|
|
691
|
-
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}${_}`;
|
|
692
665
|
}
|
|
693
666
|
case E.OPEN_LOAN:
|
|
694
667
|
case E.CLOSE_LOAN: {
|
|
695
|
-
const { asset: n, address:
|
|
696
|
-
return `${e}:${n}:${
|
|
668
|
+
const { asset: n, address: r } = t;
|
|
669
|
+
return `${e}:${n}:${r}`;
|
|
697
670
|
}
|
|
698
671
|
default:
|
|
699
672
|
return "";
|
|
@@ -710,22 +683,22 @@ function yt(e) {
|
|
|
710
683
|
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
711
684
|
return !!e.match(t);
|
|
712
685
|
}
|
|
713
|
-
function wt([e, t, n,
|
|
714
|
-
return `${e}'/${t}'/${n}'/${
|
|
686
|
+
function wt([e, t, n, r, s]) {
|
|
687
|
+
return `${e}'/${t}'/${n}'/${r}${typeof s != "number" ? "" : `/${s}`}`;
|
|
715
688
|
}
|
|
716
|
-
const ue = [...Object.values(
|
|
689
|
+
const ue = [...Object.values(l), "TERRA"];
|
|
717
690
|
function dt(e = "") {
|
|
718
691
|
const t = e.toUpperCase(), [n] = t.split(".");
|
|
719
692
|
if (ue.includes(n))
|
|
720
693
|
return !0;
|
|
721
|
-
const [
|
|
722
|
-
if (ue.includes(
|
|
694
|
+
const [r] = t.split("/");
|
|
695
|
+
if (ue.includes(r))
|
|
723
696
|
return !0;
|
|
724
697
|
throw new Error(
|
|
725
698
|
`Invalid identifier: ${e}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
726
699
|
);
|
|
727
700
|
}
|
|
728
|
-
const B = 8,
|
|
701
|
+
const B = 8, N = (e) => 10n ** BigInt(e), b = (e) => Math.log10(parseFloat(e.toString()));
|
|
729
702
|
function G({
|
|
730
703
|
value: e,
|
|
731
704
|
bigIntDecimal: t = B,
|
|
@@ -733,33 +706,33 @@ function G({
|
|
|
733
706
|
}) {
|
|
734
707
|
if (n === 0)
|
|
735
708
|
return e.toString();
|
|
736
|
-
const
|
|
737
|
-
let
|
|
738
|
-
const i = n - (
|
|
739
|
-
i > 0 && (
|
|
740
|
-
const
|
|
741
|
-
let
|
|
742
|
-
return parseInt(
|
|
709
|
+
const r = e < 0n;
|
|
710
|
+
let s = e.toString().substring(r ? 1 : 0);
|
|
711
|
+
const i = n - (s.length - 1);
|
|
712
|
+
i > 0 && (s = "0".repeat(i) + s);
|
|
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(
|
|
743
716
|
/\.?0*$/,
|
|
744
717
|
""
|
|
745
718
|
);
|
|
746
719
|
}
|
|
747
|
-
var
|
|
748
|
-
const
|
|
720
|
+
var C, y, f, D, k, Ne, U, z, L, Z;
|
|
721
|
+
const se = class se {
|
|
749
722
|
constructor(t) {
|
|
750
|
-
O(this,
|
|
723
|
+
O(this, C);
|
|
751
724
|
O(this, f);
|
|
752
725
|
O(this, k);
|
|
753
|
-
O(this, L);
|
|
754
726
|
O(this, U);
|
|
727
|
+
O(this, L);
|
|
755
728
|
p(this, "decimalMultiplier", 10n ** 8n);
|
|
756
729
|
p(this, "bigIntValue", 0n);
|
|
757
730
|
p(this, "decimal");
|
|
758
|
-
const n = ee(t),
|
|
759
|
-
this.decimal =
|
|
731
|
+
const n = ee(t), r = typeof t == "object";
|
|
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);
|
|
760
733
|
}
|
|
761
734
|
static fromBigInt(t, n) {
|
|
762
|
-
return new
|
|
735
|
+
return new se({
|
|
763
736
|
decimal: n,
|
|
764
737
|
value: G({ value: t, bigIntDecimal: n, decimal: n })
|
|
765
738
|
});
|
|
@@ -767,27 +740,27 @@ const re = class re {
|
|
|
767
740
|
static shiftDecimals({
|
|
768
741
|
value: t,
|
|
769
742
|
from: n,
|
|
770
|
-
to:
|
|
743
|
+
to: r
|
|
771
744
|
}) {
|
|
772
745
|
return this.fromBigInt(
|
|
773
|
-
t.getBaseValue("bigint") *
|
|
774
|
-
|
|
746
|
+
t.getBaseValue("bigint") * N(r) / N(n),
|
|
747
|
+
r
|
|
775
748
|
);
|
|
776
749
|
}
|
|
777
750
|
set(t) {
|
|
778
751
|
return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
|
|
779
752
|
}
|
|
780
753
|
add(...t) {
|
|
781
|
-
return T(this,
|
|
754
|
+
return T(this, C, y).call(this, "add", ...t);
|
|
782
755
|
}
|
|
783
756
|
sub(...t) {
|
|
784
|
-
return T(this,
|
|
757
|
+
return T(this, C, y).call(this, "sub", ...t);
|
|
785
758
|
}
|
|
786
759
|
mul(...t) {
|
|
787
|
-
return T(this,
|
|
760
|
+
return T(this, C, y).call(this, "mul", ...t);
|
|
788
761
|
}
|
|
789
762
|
div(...t) {
|
|
790
|
-
return T(this,
|
|
763
|
+
return T(this, C, y).call(this, "div", ...t);
|
|
791
764
|
}
|
|
792
765
|
gt(t) {
|
|
793
766
|
return T(this, f, D).call(this, "gt", t);
|
|
@@ -821,140 +794,140 @@ const re = class re {
|
|
|
821
794
|
}
|
|
822
795
|
// @ts-expect-error
|
|
823
796
|
getBaseValue(t) {
|
|
824
|
-
const n = this.decimalMultiplier /
|
|
797
|
+
const n = this.decimalMultiplier / N(this.decimal || d.THOR), r = this.bigIntValue / n;
|
|
825
798
|
switch (t) {
|
|
826
799
|
case "number":
|
|
827
|
-
return Number(
|
|
800
|
+
return Number(r);
|
|
828
801
|
case "string":
|
|
829
|
-
return
|
|
802
|
+
return r.toString();
|
|
830
803
|
case "bigint":
|
|
831
|
-
return
|
|
804
|
+
return r;
|
|
832
805
|
}
|
|
833
806
|
}
|
|
834
807
|
getBigIntValue(t, n) {
|
|
835
808
|
if (!n && typeof t == "object")
|
|
836
809
|
return t.bigIntValue;
|
|
837
|
-
const
|
|
838
|
-
return
|
|
810
|
+
const r = ee(t), s = v(r);
|
|
811
|
+
return s === "0" || s === "undefined" ? 0n : T(this, L, Z).call(this, s, n);
|
|
839
812
|
}
|
|
840
813
|
toSignificant(t = 6) {
|
|
841
|
-
const [n,
|
|
842
|
-
if ((parseInt(
|
|
814
|
+
const [n, r] = this.getValue("string").split("."), s = n || "", i = r || "";
|
|
815
|
+
if ((parseInt(s) ? s.length + i.length : i.length) <= t)
|
|
843
816
|
return this.getValue("string");
|
|
844
|
-
if (
|
|
845
|
-
return
|
|
846
|
-
if (parseInt(
|
|
847
|
-
return `${
|
|
848
|
-
t -
|
|
817
|
+
if (s.length >= t)
|
|
818
|
+
return s.slice(0, t).padEnd(s.length, "0");
|
|
819
|
+
if (parseInt(s))
|
|
820
|
+
return `${s}.${i.slice(0, t - s.length)}`.padEnd(
|
|
821
|
+
t - s.length,
|
|
849
822
|
"0"
|
|
850
823
|
);
|
|
851
|
-
const
|
|
852
|
-
return `0.${
|
|
853
|
-
i.length - `${
|
|
824
|
+
const c = parseInt(i), o = `${c}`.slice(0, t);
|
|
825
|
+
return `0.${o.padStart(
|
|
826
|
+
i.length - `${c}`.length + o.length,
|
|
854
827
|
"0"
|
|
855
828
|
)}`;
|
|
856
829
|
}
|
|
857
830
|
toFixed(t = 6) {
|
|
858
|
-
const [n,
|
|
859
|
-
if (parseInt(
|
|
860
|
-
return `${
|
|
861
|
-
const
|
|
862
|
-
return `0.${
|
|
863
|
-
i.length - `${
|
|
831
|
+
const [n, r] = this.getValue("string").split("."), s = n || "", i = r || "";
|
|
832
|
+
if (parseInt(s))
|
|
833
|
+
return `${s}.${i.slice(0, t)}`.padEnd(t, "0");
|
|
834
|
+
const a = parseInt(i), c = `${a}`.slice(0, t);
|
|
835
|
+
return `0.${c.padStart(
|
|
836
|
+
i.length - `${a}`.length + c.length,
|
|
864
837
|
"0"
|
|
865
838
|
)}`;
|
|
866
839
|
}
|
|
867
840
|
toAbbreviation(t = 2) {
|
|
868
|
-
const n = this.getValue("number"),
|
|
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];
|
|
869
842
|
if (!i)
|
|
870
843
|
return this.getValue("string");
|
|
871
|
-
const
|
|
872
|
-
return `${(n /
|
|
844
|
+
const a = 10 ** (s * 3);
|
|
845
|
+
return `${(n / a).toFixed(t)}${i}`;
|
|
873
846
|
}
|
|
874
847
|
toCurrency(t = "$", {
|
|
875
848
|
currencyPosition: n = "start",
|
|
876
|
-
decimal:
|
|
877
|
-
decimalSeparator:
|
|
849
|
+
decimal: r = 2,
|
|
850
|
+
decimalSeparator: s = ".",
|
|
878
851
|
thousandSeparator: i = ","
|
|
879
852
|
} = {}) {
|
|
880
|
-
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)}` : ""}`;
|
|
881
854
|
return `${n === "start" ? t : ""}${h}${n === "end" ? t : ""}`;
|
|
882
855
|
}
|
|
883
856
|
formatBigIntToSafeValue(t, n) {
|
|
884
|
-
const
|
|
885
|
-
|
|
857
|
+
const r = n || this.decimal || B, s = Math.max(
|
|
858
|
+
r,
|
|
886
859
|
b(this.decimalMultiplier)
|
|
887
|
-
), i = t < 0n,
|
|
888
|
-
let h =
|
|
889
|
-
return parseInt(h[
|
|
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(
|
|
890
863
|
0,
|
|
891
864
|
_
|
|
892
865
|
)}.${h}`.replace(/\.?0*$/, "");
|
|
893
866
|
}
|
|
894
867
|
};
|
|
895
|
-
|
|
896
|
-
const
|
|
897
|
-
(
|
|
898
|
-
const h = this.getBigIntValue(_,
|
|
868
|
+
C = new WeakSet(), y = function(t, ...n) {
|
|
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, _) => {
|
|
871
|
+
const h = this.getBigIntValue(_, s);
|
|
899
872
|
switch (t) {
|
|
900
873
|
case "add":
|
|
901
|
-
return
|
|
874
|
+
return o + h;
|
|
902
875
|
case "sub":
|
|
903
|
-
return
|
|
876
|
+
return o - h;
|
|
904
877
|
case "mul":
|
|
905
|
-
return
|
|
878
|
+
return o * h / i;
|
|
906
879
|
case "div": {
|
|
907
880
|
if (h === 0n)
|
|
908
881
|
throw new RangeError("Division by zero");
|
|
909
|
-
return
|
|
882
|
+
return o * i / h;
|
|
910
883
|
}
|
|
911
884
|
default:
|
|
912
|
-
return
|
|
885
|
+
return o;
|
|
913
886
|
}
|
|
914
887
|
},
|
|
915
888
|
//normalize is to precision multiplier base
|
|
916
889
|
this.bigIntValue * i / this.decimalMultiplier
|
|
917
|
-
),
|
|
918
|
-
bigIntDecimal:
|
|
919
|
-
decimal:
|
|
920
|
-
value:
|
|
890
|
+
), c = G({
|
|
891
|
+
bigIntDecimal: s,
|
|
892
|
+
decimal: s,
|
|
893
|
+
value: a
|
|
921
894
|
});
|
|
922
895
|
return new this.constructor({
|
|
923
|
-
decimalMultiplier:
|
|
896
|
+
decimalMultiplier: N(s),
|
|
924
897
|
decimal: this.decimal,
|
|
925
|
-
value:
|
|
898
|
+
value: c,
|
|
926
899
|
identifier: this.toString()
|
|
927
900
|
});
|
|
928
901
|
}, f = new WeakSet(), D = function(t, ...n) {
|
|
929
|
-
const
|
|
902
|
+
const r = T(this, U, z).call(this, this, ...n), s = this.getBigIntValue(n[0], r), i = this.getBigIntValue(this, r);
|
|
930
903
|
switch (t) {
|
|
931
904
|
case "gt":
|
|
932
|
-
return i >
|
|
905
|
+
return i > s;
|
|
933
906
|
case "gte":
|
|
934
|
-
return i >=
|
|
907
|
+
return i >= s;
|
|
935
908
|
case "lt":
|
|
936
|
-
return i <
|
|
909
|
+
return i < s;
|
|
937
910
|
case "lte":
|
|
938
|
-
return i <=
|
|
911
|
+
return i <= s;
|
|
939
912
|
case "eqValue":
|
|
940
|
-
return i ===
|
|
913
|
+
return i === s;
|
|
941
914
|
}
|
|
942
|
-
}, k = new WeakSet(),
|
|
943
|
-
const n =
|
|
944
|
-
this.bigIntValue = T(this,
|
|
945
|
-
},
|
|
946
|
-
const n = t.map((
|
|
915
|
+
}, k = new WeakSet(), Ne = function(t) {
|
|
916
|
+
const n = v(t) || "0";
|
|
917
|
+
this.bigIntValue = T(this, L, Z).call(this, n);
|
|
918
|
+
}, U = new WeakSet(), z = function(...t) {
|
|
919
|
+
const n = t.map((r) => typeof r == "object" ? r.decimal || b(r.decimalMultiplier) : _e(v(r))).filter(Boolean);
|
|
947
920
|
return Math.max(...n, B);
|
|
948
|
-
},
|
|
949
|
-
const
|
|
950
|
-
return BigInt(`${i}${
|
|
921
|
+
}, L = new WeakSet(), Z = function(t, n) {
|
|
922
|
+
const r = n ? N(n) : this.decimalMultiplier, s = b(r), [i = "", a = ""] = t.split(".");
|
|
923
|
+
return BigInt(`${i}${a.padEnd(s, "0")}`);
|
|
951
924
|
};
|
|
952
|
-
let W =
|
|
925
|
+
let W = se;
|
|
953
926
|
const Tt = Intl.NumberFormat("fullwide", {
|
|
954
927
|
useGrouping: !1,
|
|
955
928
|
maximumFractionDigits: 20
|
|
956
929
|
});
|
|
957
|
-
function
|
|
930
|
+
function v(e) {
|
|
958
931
|
const n = `${typeof e == "number" ? Tt.format(e) : ee(e)}`.replaceAll(",", ".").split(".");
|
|
959
932
|
return n.length > 1 ? `${n.slice(0, -1).join("")}.${n.at(-1)}` : n[0];
|
|
960
933
|
}
|
|
@@ -970,13 +943,13 @@ const w = /* @__PURE__ */ new Map();
|
|
|
970
943
|
class g extends W {
|
|
971
944
|
constructor({
|
|
972
945
|
value: n,
|
|
973
|
-
decimal:
|
|
974
|
-
tax:
|
|
946
|
+
decimal: r,
|
|
947
|
+
tax: s,
|
|
975
948
|
chain: i,
|
|
976
|
-
symbol:
|
|
977
|
-
identifier:
|
|
949
|
+
symbol: a,
|
|
950
|
+
identifier: c
|
|
978
951
|
}) {
|
|
979
|
-
super(typeof n == "object" ? n : { decimal:
|
|
952
|
+
super(typeof n == "object" ? n : { decimal: r, value: n });
|
|
980
953
|
p(this, "address");
|
|
981
954
|
p(this, "chain");
|
|
982
955
|
p(this, "isGasAsset", !1);
|
|
@@ -985,8 +958,8 @@ class g extends W {
|
|
|
985
958
|
p(this, "tax");
|
|
986
959
|
p(this, "ticker");
|
|
987
960
|
p(this, "type");
|
|
988
|
-
const
|
|
989
|
-
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;
|
|
990
963
|
}
|
|
991
964
|
toString() {
|
|
992
965
|
return this.isSynthetic ? this.symbol : `${this.chain}.${this.symbol}`;
|
|
@@ -994,75 +967,75 @@ class g extends W {
|
|
|
994
967
|
toUrl() {
|
|
995
968
|
return this.isSynthetic ? `${this.chain}.${this.symbol.replace("/", ".")}` : this.toString();
|
|
996
969
|
}
|
|
997
|
-
eq({ chain: n, symbol:
|
|
998
|
-
return this.chain === n && this.symbol ===
|
|
970
|
+
eq({ chain: n, symbol: r }) {
|
|
971
|
+
return this.chain === n && this.symbol === r;
|
|
999
972
|
}
|
|
1000
973
|
chainId() {
|
|
1001
|
-
return
|
|
974
|
+
return Le[this.chain];
|
|
1002
975
|
}
|
|
1003
976
|
// THOR.RUNE
|
|
1004
977
|
// THOR.ETH.ETH
|
|
1005
978
|
// ETH.THOR-0x1234567890
|
|
1006
|
-
static fromUrl(n,
|
|
1007
|
-
const [
|
|
1008
|
-
if (!
|
|
979
|
+
static fromUrl(n, r = 0) {
|
|
980
|
+
const [s, i, a] = n.split(".");
|
|
981
|
+
if (!s || !i)
|
|
1009
982
|
throw new Error("Invalid asset url");
|
|
1010
|
-
const
|
|
1011
|
-
return J(
|
|
983
|
+
const c = s === l.THORChain && a ? `${s}.${i}/${a}` : n;
|
|
984
|
+
return J(c, r);
|
|
1012
985
|
}
|
|
1013
|
-
static fromString(n,
|
|
1014
|
-
return J(n,
|
|
986
|
+
static fromString(n, r = 0) {
|
|
987
|
+
return J(n, r);
|
|
1015
988
|
}
|
|
1016
|
-
static fromIdentifier(n,
|
|
1017
|
-
return J(n,
|
|
989
|
+
static fromIdentifier(n, r = 0) {
|
|
990
|
+
return J(n, r);
|
|
1018
991
|
}
|
|
1019
|
-
static fromStringSync(n,
|
|
1020
|
-
const { chain:
|
|
992
|
+
static fromStringSync(n, r = 0) {
|
|
993
|
+
const { chain: s, isSynthetic: i } = F(n), a = w.get(n.toUpperCase());
|
|
1021
994
|
if (i)
|
|
1022
|
-
return he(n,
|
|
1023
|
-
const { tax:
|
|
1024
|
-
decimal: d[
|
|
995
|
+
return he(n, r);
|
|
996
|
+
const { tax: c, decimal: o, identifier: _ } = a || {
|
|
997
|
+
decimal: d[s],
|
|
1025
998
|
identifier: n
|
|
1026
999
|
};
|
|
1027
1000
|
return new g({
|
|
1028
|
-
tax:
|
|
1029
|
-
value: V(
|
|
1001
|
+
tax: c,
|
|
1002
|
+
value: V(r, o),
|
|
1030
1003
|
identifier: i ? n : _,
|
|
1031
|
-
decimal: i ? 8 :
|
|
1004
|
+
decimal: i ? 8 : o
|
|
1032
1005
|
});
|
|
1033
1006
|
}
|
|
1034
|
-
static fromIdentifierSync(n,
|
|
1035
|
-
const { chain:
|
|
1007
|
+
static fromIdentifierSync(n, r = 0) {
|
|
1008
|
+
const { chain: s, isSynthetic: i } = F(n), a = w.get(n);
|
|
1036
1009
|
if (i)
|
|
1037
|
-
return he(n,
|
|
1038
|
-
const { tax:
|
|
1039
|
-
decimal: d[
|
|
1010
|
+
return he(n, r);
|
|
1011
|
+
const { tax: c, decimal: o, identifier: _ } = a || {
|
|
1012
|
+
decimal: d[s],
|
|
1040
1013
|
identifier: n
|
|
1041
1014
|
};
|
|
1042
|
-
return new g({ tax:
|
|
1015
|
+
return new g({ tax: c, decimal: o, identifier: _, value: V(r, o) });
|
|
1043
1016
|
}
|
|
1044
|
-
static fromChainOrSignature(n,
|
|
1045
|
-
const { decimal:
|
|
1046
|
-
return new g({ value: V(
|
|
1017
|
+
static fromChainOrSignature(n, r = 0) {
|
|
1018
|
+
const { decimal: s, identifier: i } = at(n);
|
|
1019
|
+
return new g({ value: V(r, s), decimal: s, identifier: i });
|
|
1047
1020
|
}
|
|
1048
1021
|
static loadStaticAssets() {
|
|
1049
1022
|
return new Promise(
|
|
1050
|
-
async (n,
|
|
1023
|
+
async (n, r) => {
|
|
1051
1024
|
try {
|
|
1052
|
-
const
|
|
1053
|
-
Object.values(
|
|
1054
|
-
var
|
|
1055
|
-
(
|
|
1056
|
-
w.set(
|
|
1057
|
-
identifier:
|
|
1058
|
-
decimal: "decimals" in _ ? _.decimals : d[
|
|
1025
|
+
const s = await import("@swapkit/tokens");
|
|
1026
|
+
Object.values(s).forEach((i) => {
|
|
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]
|
|
1059
1032
|
});
|
|
1060
1033
|
});
|
|
1061
1034
|
}), n({ ok: !0 });
|
|
1062
|
-
} catch (
|
|
1063
|
-
console.error(
|
|
1035
|
+
} catch (s) {
|
|
1036
|
+
console.error(s), r({
|
|
1064
1037
|
ok: !1,
|
|
1065
|
-
error:
|
|
1038
|
+
error: s,
|
|
1066
1039
|
message: "Couldn't load static assets. Ensure you have installed @swapkit/tokens package"
|
|
1067
1040
|
});
|
|
1068
1041
|
}
|
|
@@ -1073,19 +1046,19 @@ class g extends W {
|
|
|
1073
1046
|
function Vt(e) {
|
|
1074
1047
|
const t = g.fromChainOrSignature(e);
|
|
1075
1048
|
switch (e) {
|
|
1076
|
-
case
|
|
1077
|
-
case
|
|
1078
|
-
case
|
|
1049
|
+
case l.Bitcoin:
|
|
1050
|
+
case l.Litecoin:
|
|
1051
|
+
case l.BitcoinCash:
|
|
1079
1052
|
return t.set(10001e-8);
|
|
1080
|
-
case
|
|
1053
|
+
case l.Dogecoin:
|
|
1081
1054
|
return t.set(1.00000001);
|
|
1082
|
-
case
|
|
1083
|
-
case
|
|
1055
|
+
case l.Avalanche:
|
|
1056
|
+
case l.Ethereum:
|
|
1084
1057
|
return t.set(1e-8);
|
|
1085
|
-
case
|
|
1086
|
-
case
|
|
1058
|
+
case l.THORChain:
|
|
1059
|
+
case l.Maya:
|
|
1087
1060
|
return t.set(0);
|
|
1088
|
-
case
|
|
1061
|
+
case l.Cosmos:
|
|
1089
1062
|
return t.set(1e-6);
|
|
1090
1063
|
default:
|
|
1091
1064
|
return t.set(1e-8);
|
|
@@ -1093,34 +1066,34 @@ function Vt(e) {
|
|
|
1093
1066
|
}
|
|
1094
1067
|
async function J(e, t = 0) {
|
|
1095
1068
|
dt(e);
|
|
1096
|
-
const n = w.get(e.toUpperCase()),
|
|
1097
|
-
return n || w.set(e.toUpperCase(), { identifier: e, decimal:
|
|
1069
|
+
const n = w.get(e.toUpperCase()), r = (n == null ? void 0 : n.decimal) || await it(F(e));
|
|
1070
|
+
return n || w.set(e.toUpperCase(), { identifier: e, decimal: r }), new g({ decimal: r, value: V(t, r), identifier: e });
|
|
1098
1071
|
}
|
|
1099
1072
|
function he(e, t = 0) {
|
|
1100
|
-
const [n,
|
|
1101
|
-
if (!n || !
|
|
1073
|
+
const [n, r] = e.split(".")[0].toUpperCase() === l.THORChain ? e.split(".").slice(1).join().split("/") : e.split("/");
|
|
1074
|
+
if (!n || !r)
|
|
1102
1075
|
throw new Error("Invalid asset identifier");
|
|
1103
1076
|
return new g({
|
|
1104
1077
|
decimal: 8,
|
|
1105
1078
|
value: V(t, 8),
|
|
1106
|
-
identifier: `${
|
|
1079
|
+
identifier: `${l.THORChain}.${n}/${r}`
|
|
1107
1080
|
});
|
|
1108
1081
|
}
|
|
1109
1082
|
function V(e, t) {
|
|
1110
1083
|
return typeof e == "bigint" ? G({ value: e, bigIntDecimal: t, decimal: t }) : e;
|
|
1111
1084
|
}
|
|
1112
1085
|
function F(e) {
|
|
1113
|
-
const t = e.slice(0, 14).includes("/"), [n,
|
|
1114
|
-
if (t && (!n || !
|
|
1086
|
+
const t = e.slice(0, 14).includes("/"), [n, r] = e.split(".")[0].toUpperCase() === l.THORChain ? e.split(".").slice(1).join().split("/") : e.split("/");
|
|
1087
|
+
if (t && (!n || !r))
|
|
1115
1088
|
throw new Error("Invalid asset identifier");
|
|
1116
|
-
const
|
|
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(".");
|
|
1117
1090
|
return {
|
|
1118
|
-
address:
|
|
1091
|
+
address: o == null ? void 0 : o.toLowerCase(),
|
|
1119
1092
|
chain: i,
|
|
1120
1093
|
isGasAsset: fe({ chain: i, symbol: _ }),
|
|
1121
1094
|
isSynthetic: t,
|
|
1122
|
-
symbol: (t ? `${n}/` : "") + (
|
|
1123
|
-
ticker:
|
|
1095
|
+
symbol: (t ? `${n}/` : "") + (o ? `${c}-${(o == null ? void 0 : o.toLowerCase()) ?? ""}` : _),
|
|
1096
|
+
ticker: c
|
|
1124
1097
|
};
|
|
1125
1098
|
}
|
|
1126
1099
|
const At = {
|
|
@@ -1187,9 +1160,9 @@ const At = {
|
|
|
1187
1160
|
*/
|
|
1188
1161
|
helpers_number_different_decimals: 99101
|
|
1189
1162
|
};
|
|
1190
|
-
class
|
|
1163
|
+
class Ce extends Error {
|
|
1191
1164
|
constructor(t, n) {
|
|
1192
|
-
n && console.error(n, { stack: n == null ? void 0 : n.stack, message: n == null ? void 0 : n.message }), super(t, { cause: { code: At[t], message: t } }), Object.setPrototypeOf(this,
|
|
1165
|
+
n && console.error(n, { stack: n == null ? void 0 : n.stack, message: n == null ? void 0 : n.message }), super(t, { cause: { code: At[t], message: t } }), Object.setPrototypeOf(this, Ce.prototype);
|
|
1193
1166
|
}
|
|
1194
1167
|
}
|
|
1195
1168
|
class I extends W {
|
|
@@ -1210,7 +1183,7 @@ export {
|
|
|
1210
1183
|
S as RequestClient,
|
|
1211
1184
|
et as StreamingSwapProgressStatus,
|
|
1212
1185
|
Et as SwapKitApi,
|
|
1213
|
-
|
|
1186
|
+
Ce as SwapKitError,
|
|
1214
1187
|
I as SwapKitNumber,
|
|
1215
1188
|
ze as TransactionType,
|
|
1216
1189
|
Ze as TxStatus,
|
|
@@ -1222,9 +1195,9 @@ export {
|
|
|
1222
1195
|
Rt as gasFeeMultiplier,
|
|
1223
1196
|
ot as getAssetType,
|
|
1224
1197
|
_t as getAsymmetricAssetShare,
|
|
1225
|
-
|
|
1198
|
+
Ct as getAsymmetricAssetWithdrawAmount,
|
|
1226
1199
|
ut as getAsymmetricRuneShare,
|
|
1227
|
-
|
|
1200
|
+
Nt as getAsymmetricRuneWithdrawAmount,
|
|
1228
1201
|
at as getCommonAssetInfo,
|
|
1229
1202
|
it as getDecimal,
|
|
1230
1203
|
Ot as getEstimatedPoolShare,
|