@swapkit/helpers 1.0.0-rc.67 → 1.0.0-rc.68
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 +285 -279
- package/dist/index.es.js.map +1 -1
- package/package.json +6 -6
- package/src/helpers/asset.ts +6 -0
- 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 a, EVMChainList as Be, ChainToRPC as
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
var
|
|
17
|
-
const q = Object.values(
|
|
13
|
+
import { FeeOption as Y, BaseDecimal as d, Chain as a, EVMChainList as Be, ChainToRPC as Le, MemoType as E, ChainToChainId as Ue } 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.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.Kujira = "https://rpc-kujira.synergynodes.com/", e.Dogecoin = "https://node-router.thorswap.net/dogecoin", e.Ethereum = "https://node-router.thorswap.net/ethereum", 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), ve = Object.keys(j), ne = q.reduce(
|
|
18
18
|
(e, t) => {
|
|
19
|
-
const n = ve.find((
|
|
19
|
+
const n = ve.find((s) => j[s] === 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, s) {
|
|
41
|
+
const r = t.status || t.status === 0 ? t.status : "", i = t.statusText || "", o = `${r} ${i}`.trim(), l = o ? `status code ${o}` : "an unknown error";
|
|
42
|
+
super(`Request failed with ${l}`), 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 = s;
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
class Te extends Error {
|
|
@@ -71,27 +71,27 @@ const M = (e) => e !== null && typeof e == "object", v = (...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 se({}, ...e);
|
|
75
75
|
}, Ae = (e = {}, t = {}) => {
|
|
76
|
-
const n = new globalThis.Headers(e),
|
|
77
|
-
for (const [i, o] of
|
|
78
|
-
|
|
76
|
+
const n = new globalThis.Headers(e), s = t instanceof globalThis.Headers, r = new globalThis.Headers(t);
|
|
77
|
+
for (const [i, o] of r.entries())
|
|
78
|
+
s && o === "undefined" || o === void 0 ? n.delete(i) : n.set(i, o);
|
|
79
79
|
return n;
|
|
80
|
-
},
|
|
80
|
+
}, se = (...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 s of e)
|
|
83
|
+
if (Array.isArray(s))
|
|
84
|
+
Array.isArray(t) || (t = []), t = [...t, ...s];
|
|
85
|
+
else if (M(s)) {
|
|
86
|
+
for (let [r, i] of Object.entries(s))
|
|
87
|
+
M(i) && r in t && (i = se(t[r], i)), t = { ...t, [r]: i };
|
|
88
|
+
M(s.headers) && (n = Ae(n, s.headers), t.headers = n);
|
|
89
89
|
}
|
|
90
90
|
return t;
|
|
91
91
|
}, $e = (() => {
|
|
92
92
|
let e = !1, t = !1;
|
|
93
|
-
const n = typeof globalThis.ReadableStream == "function",
|
|
94
|
-
return n &&
|
|
93
|
+
const n = typeof globalThis.ReadableStream == "function", s = typeof globalThis.Request == "function";
|
|
94
|
+
return n && s && (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.
|
|
@@ -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,
|
|
@@ -156,62 +156,62 @@ 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((
|
|
159
|
+
async function Ye(e, t, n, s) {
|
|
160
|
+
return new Promise((r, i) => {
|
|
161
161
|
const o = setTimeout(() => {
|
|
162
162
|
n && n.abort(), i(new Te(e));
|
|
163
|
-
},
|
|
164
|
-
|
|
163
|
+
}, s.timeout);
|
|
164
|
+
s.fetch(e, t).then(r).catch(i).then(() => {
|
|
165
165
|
clearTimeout(o);
|
|
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, s) => {
|
|
171
|
+
t && (t.throwIfAborted(), t.addEventListener("abort", r, { once: !0 }));
|
|
172
|
+
function r() {
|
|
173
|
+
clearTimeout(i), s(t.reason);
|
|
174
174
|
}
|
|
175
175
|
const i = setTimeout(() => {
|
|
176
|
-
t == null || t.removeEventListener("abort",
|
|
176
|
+
t == null || t.removeEventListener("abort", r), 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 s in t)
|
|
183
|
+
!(s in We) && !(s in Ge) && !(s in e) && (n[s] = t[s]);
|
|
184
184
|
return n;
|
|
185
185
|
};
|
|
186
|
-
class
|
|
186
|
+
class x {
|
|
187
187
|
static create(t, n) {
|
|
188
|
-
const
|
|
189
|
-
if (typeof
|
|
188
|
+
const s = new x(t, n), r = async () => {
|
|
189
|
+
if (typeof s._options.timeout == "number" && s._options.timeout > K)
|
|
190
190
|
throw new RangeError(`The \`timeout\` option cannot be greater than ${K}`);
|
|
191
191
|
await Promise.resolve();
|
|
192
|
-
let o = await
|
|
193
|
-
for (const
|
|
194
|
-
const c = await
|
|
192
|
+
let o = await s._fetch();
|
|
193
|
+
for (const l of s._options.hooks.afterResponse) {
|
|
194
|
+
const c = await l(s.request, s._options, s._decorateResponse(o.clone()));
|
|
195
195
|
c instanceof globalThis.Response && (o = c);
|
|
196
196
|
}
|
|
197
|
-
if (
|
|
198
|
-
let
|
|
199
|
-
for (const c of
|
|
200
|
-
|
|
201
|
-
throw
|
|
197
|
+
if (s._decorateResponse(o), !o.ok && s._options.throwHttpErrors) {
|
|
198
|
+
let l = new oe(o, s.request, s._options);
|
|
199
|
+
for (const c of s._options.hooks.beforeError)
|
|
200
|
+
l = await c(l);
|
|
201
|
+
throw l;
|
|
202
202
|
}
|
|
203
|
-
if (
|
|
204
|
-
if (typeof
|
|
203
|
+
if (s._options.onDownloadProgress) {
|
|
204
|
+
if (typeof s._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 s._stream(o.clone(), s._options.onDownloadProgress);
|
|
209
209
|
}
|
|
210
210
|
return o;
|
|
211
|
-
}, i =
|
|
212
|
-
for (const [o,
|
|
211
|
+
}, i = s._options.retry.methods.includes(s.request.method.toLowerCase()) ? s._retry(r) : r();
|
|
212
|
+
for (const [o, l] of Object.entries(xe))
|
|
213
213
|
i[o] = async () => {
|
|
214
|
-
|
|
214
|
+
s.request.headers.set("accept", s.request.headers.get("accept") || l);
|
|
215
215
|
const c = (await i).clone();
|
|
216
216
|
if (o === "json") {
|
|
217
217
|
if (c.status === 204 || (await c.clone().arrayBuffer()).byteLength === 0)
|
|
@@ -255,13 +255,13 @@ class F {
|
|
|
255
255
|
credentials: this._input.credentials || "same-origin",
|
|
256
256
|
...n,
|
|
257
257
|
headers: Ae(this._input.headers, n.headers),
|
|
258
|
-
hooks:
|
|
258
|
+
hooks: se({
|
|
259
259
|
beforeRequest: [],
|
|
260
260
|
beforeRetry: [],
|
|
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),
|
|
@@ -277,16 +277,16 @@ class F {
|
|
|
277
277
|
}
|
|
278
278
|
if (Me) {
|
|
279
279
|
if (this.abortController = new globalThis.AbortController(), this._options.signal) {
|
|
280
|
-
const
|
|
280
|
+
const s = this._options.signal;
|
|
281
281
|
this._options.signal.addEventListener("abort", () => {
|
|
282
|
-
this.abortController.abort(
|
|
282
|
+
this.abortController.abort(s.reason);
|
|
283
283
|
});
|
|
284
284
|
}
|
|
285
285
|
this._options.signal = this.abortController.signal;
|
|
286
286
|
}
|
|
287
287
|
if ($e && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
|
|
288
|
-
const
|
|
289
|
-
(
|
|
288
|
+
const s = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), r = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, s);
|
|
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(r, { ...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 F {
|
|
|
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 s = t.response.headers.get("Retry-After");
|
|
299
|
+
if (s && this._options.retry.afterStatusCodes.includes(t.response.status)) {
|
|
300
|
+
let r = Number(s);
|
|
301
|
+
return Number.isNaN(r) ? r = Date.parse(s) - Date.now() : r *= 1e3, this._options.retry.maxRetryAfter !== void 0 && r > this._options.retry.maxRetryAfter ? 0 : r;
|
|
302
302
|
}
|
|
303
303
|
if (t.response.status === 413)
|
|
304
304
|
return 0;
|
|
@@ -315,11 +315,11 @@ class F {
|
|
|
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 s = Math.min(this._calculateRetryDelay(n), K);
|
|
319
|
+
if (s !== 0 && this._retryCount > 0) {
|
|
320
|
+
await Ke(s, { signal: this._options.signal });
|
|
321
|
+
for (const r of this._options.hooks.beforeRetry)
|
|
322
|
+
if (await r({
|
|
323
323
|
request: this.request,
|
|
324
324
|
options: this._options,
|
|
325
325
|
error: n,
|
|
@@ -333,43 +333,43 @@ class F {
|
|
|
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 s = await n(this.request, this._options);
|
|
337
|
+
if (s instanceof Request) {
|
|
338
|
+
this.request = s;
|
|
339
339
|
break;
|
|
340
340
|
}
|
|
341
|
-
if (
|
|
342
|
-
return
|
|
341
|
+
if (s instanceof Response)
|
|
342
|
+
return s;
|
|
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 s = Number(t.headers.get("content-length")) || 0;
|
|
350
|
+
let r = 0;
|
|
351
|
+
return t.status === 204 ? (n && n({ percent: 1, totalBytes: s, transferredBytes: r }, 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
357
|
const o = t.body.getReader();
|
|
358
|
-
n && n({ percent: 0, transferredBytes: 0, totalBytes:
|
|
359
|
-
async function
|
|
358
|
+
n && n({ percent: 0, transferredBytes: 0, totalBytes: s }, new Uint8Array());
|
|
359
|
+
async function l() {
|
|
360
360
|
const { done: c, value: _ } = await o.read();
|
|
361
361
|
if (c) {
|
|
362
362
|
i.close();
|
|
363
363
|
return;
|
|
364
364
|
}
|
|
365
365
|
if (n) {
|
|
366
|
-
|
|
367
|
-
const h =
|
|
368
|
-
n({ percent: h, transferredBytes:
|
|
366
|
+
r += _.byteLength;
|
|
367
|
+
const h = s === 0 ? 0 : r / s;
|
|
368
|
+
n({ percent: h, transferredBytes: r, totalBytes: s }, _);
|
|
369
369
|
}
|
|
370
|
-
i.enqueue(_), await
|
|
370
|
+
i.enqueue(_), await l();
|
|
371
371
|
}
|
|
372
|
-
await
|
|
372
|
+
await l();
|
|
373
373
|
}
|
|
374
374
|
}), {
|
|
375
375
|
status: t.status,
|
|
@@ -380,9 +380,9 @@ class F {
|
|
|
380
380
|
}
|
|
381
381
|
/*! MIT License © Sindre Sorhus */
|
|
382
382
|
const Q = (e) => {
|
|
383
|
-
const t = (n,
|
|
383
|
+
const t = (n, s) => x.create(n, v(e, s));
|
|
384
384
|
for (const n of pe)
|
|
385
|
-
t[n] = (
|
|
385
|
+
t[n] = (s, r) => x.create(s, v(e, r, { method: n }));
|
|
386
386
|
return t.create = (n) => Q(v(n)), t.extend = (n) => Q(v(e, n)), t.stop = Se, t;
|
|
387
387
|
}, Ee = Q();
|
|
388
388
|
let H;
|
|
@@ -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((
|
|
407
|
+
return e.filter((s, r, i) => i.findIndex((o) => o === s) === r).forEach((s) => n.append("tokens", JSON.stringify(s))), 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(Le[e], {
|
|
426
426
|
headers: {
|
|
427
427
|
accept: "*/*",
|
|
428
428
|
"content-type": "application/json",
|
|
@@ -444,17 +444,17 @@ const tt = "0x313ce567", Ie = async ({ chain: e, to: t }) => {
|
|
|
444
444
|
return d.ETH;
|
|
445
445
|
const [, t] = e.split("-");
|
|
446
446
|
return t != null && t.startsWith("0x") ? Ie({ chain: a.Ethereum, to: t }) : d.ETH;
|
|
447
|
-
},
|
|
447
|
+
}, st = async (e) => {
|
|
448
448
|
const [, t] = e.split("-");
|
|
449
449
|
return t != null && t.startsWith("0x") ? Ie({ chain: a.Avalanche, to: t.toLowerCase() }) : d.AVAX;
|
|
450
|
-
},
|
|
450
|
+
}, rt = async (e) => e === a.BinanceSmartChain ? d.BSC : d.BSC, it = async ({ chain: e, symbol: t }) => {
|
|
451
451
|
switch (e) {
|
|
452
452
|
case a.Ethereum:
|
|
453
453
|
return nt(t);
|
|
454
454
|
case a.Avalanche:
|
|
455
|
-
return rt(t);
|
|
456
|
-
case a.BinanceSmartChain:
|
|
457
455
|
return st(t);
|
|
456
|
+
case a.BinanceSmartChain:
|
|
457
|
+
return rt(t);
|
|
458
458
|
default:
|
|
459
459
|
return d[e];
|
|
460
460
|
}
|
|
@@ -471,6 +471,8 @@ const tt = "0x313ce567", Ie = async ({ chain: e, to: t }) => {
|
|
|
471
471
|
case a.Binance:
|
|
472
472
|
case a.Ethereum:
|
|
473
473
|
case a.Avalanche:
|
|
474
|
+
case a.Polkadot:
|
|
475
|
+
case a.Chainflip:
|
|
474
476
|
return t === e;
|
|
475
477
|
case a.Arbitrum:
|
|
476
478
|
case a.Optimism:
|
|
@@ -514,7 +516,9 @@ const tt = "0x313ce567", Ie = async ({ chain: e, to: t }) => {
|
|
|
514
516
|
case a.Dogecoin:
|
|
515
517
|
case a.Binance:
|
|
516
518
|
case a.Avalanche:
|
|
519
|
+
case a.Chainflip:
|
|
517
520
|
case a.Polygon:
|
|
521
|
+
case a.Polkadot:
|
|
518
522
|
case a.Bitcoin:
|
|
519
523
|
case a.Ethereum:
|
|
520
524
|
return { identifier: `${e}.${e}`, decimal: d[e] };
|
|
@@ -529,6 +533,8 @@ const tt = "0x313ce567", Ie = async ({ chain: e, to: t }) => {
|
|
|
529
533
|
case a.Litecoin:
|
|
530
534
|
case a.Maya:
|
|
531
535
|
case a.THORChain:
|
|
536
|
+
case a.Polkadot:
|
|
537
|
+
case a.Chainflip:
|
|
532
538
|
return "Native";
|
|
533
539
|
case a.Cosmos:
|
|
534
540
|
return t === "ATOM" ? "Native" : a.Cosmos;
|
|
@@ -551,52 +557,52 @@ const tt = "0x313ce567", Ie = async ({ chain: e, to: t }) => {
|
|
|
551
557
|
}
|
|
552
558
|
}, It = (e) => {
|
|
553
559
|
var o;
|
|
554
|
-
const [t, ...n] = e.split("."),
|
|
555
|
-
return { chain: t, symbol:
|
|
560
|
+
const [t, ...n] = e.split("."), s = e.includes("/"), r = n.join("."), i = (o = r == null ? void 0 : r.split("-")) == null ? void 0 : o[0];
|
|
561
|
+
return { chain: t, symbol: r, ticker: i, synth: s };
|
|
556
562
|
}, ct = new RegExp(
|
|
557
563
|
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
|
|
558
564
|
"gmi"
|
|
559
|
-
),
|
|
565
|
+
), lt = (e) => {
|
|
560
566
|
const [t, n] = e.split(".");
|
|
561
567
|
if (!Be.includes(t))
|
|
562
568
|
return !0;
|
|
563
|
-
const [,
|
|
564
|
-
return fe({ chain: t, symbol: n }) || !!
|
|
569
|
+
const [, s] = n.split("-");
|
|
570
|
+
return fe({ chain: t, symbol: n }) || !!s;
|
|
565
571
|
}, ft = (e) => e.filter((t) => {
|
|
566
572
|
const n = `${t.chain}.${t.symbol}`;
|
|
567
|
-
return !ct.test(n) &&
|
|
573
|
+
return !ct.test(n) && lt(n) && t.value !== "0";
|
|
568
574
|
});
|
|
569
|
-
function
|
|
575
|
+
function ut({
|
|
570
576
|
liquidityUnits: e,
|
|
571
577
|
poolUnits: t,
|
|
572
578
|
runeDepth: n
|
|
573
579
|
}) {
|
|
574
|
-
const
|
|
575
|
-
return o.mul(
|
|
580
|
+
const s = A(e), r = A(t), i = A(n), o = s.mul(i), l = r.mul(r).mul(2), c = r.mul(s).mul(2), _ = s.mul(s), h = r.mul(r).mul(r);
|
|
581
|
+
return o.mul(l.sub(c).add(_)).div(h);
|
|
576
582
|
}
|
|
577
583
|
function _t({
|
|
578
584
|
liquidityUnits: e,
|
|
579
585
|
poolUnits: t,
|
|
580
586
|
assetDepth: n
|
|
581
587
|
}) {
|
|
582
|
-
const
|
|
588
|
+
const s = A(e), r = A(t), i = A(n), o = s.mul(i), l = r.mul(r).mul(2), c = r.mul(s).mul(2), _ = s.mul(s), h = o.mul(l.sub(c).add(_)), P = r.mul(r).mul(r);
|
|
583
589
|
return h.div(P);
|
|
584
590
|
}
|
|
585
|
-
function
|
|
591
|
+
function Ct({
|
|
586
592
|
percent: e,
|
|
587
593
|
runeDepth: t,
|
|
588
594
|
liquidityUnits: n,
|
|
589
|
-
poolUnits:
|
|
595
|
+
poolUnits: s
|
|
590
596
|
}) {
|
|
591
|
-
return
|
|
597
|
+
return ut({ runeDepth: t, liquidityUnits: n, poolUnits: s }).mul(e);
|
|
592
598
|
}
|
|
593
|
-
function
|
|
599
|
+
function Nt({
|
|
594
600
|
percent: e,
|
|
595
601
|
assetDepth: t,
|
|
596
602
|
liquidityUnits: n,
|
|
597
|
-
poolUnits:
|
|
603
|
+
poolUnits: s
|
|
598
604
|
}) {
|
|
599
|
-
return _t({ assetDepth: t, liquidityUnits: n, poolUnits:
|
|
605
|
+
return _t({ assetDepth: t, liquidityUnits: n, poolUnits: s }).mul(e);
|
|
600
606
|
}
|
|
601
607
|
function A(e) {
|
|
602
608
|
return I.fromBigInt(BigInt(e), d.THOR);
|
|
@@ -605,10 +611,10 @@ function ht({
|
|
|
605
611
|
liquidityUnits: e,
|
|
606
612
|
poolUnits: t,
|
|
607
613
|
runeDepth: n,
|
|
608
|
-
assetDepth:
|
|
614
|
+
assetDepth: s
|
|
609
615
|
}) {
|
|
610
616
|
return {
|
|
611
|
-
assetAmount: A(
|
|
617
|
+
assetAmount: A(s).mul(e).div(t),
|
|
612
618
|
runeAmount: A(n).mul(e).div(t)
|
|
613
619
|
};
|
|
614
620
|
}
|
|
@@ -616,12 +622,12 @@ function gt({
|
|
|
616
622
|
liquidityUnits: e,
|
|
617
623
|
poolUnits: t,
|
|
618
624
|
runeDepth: n,
|
|
619
|
-
assetDepth:
|
|
620
|
-
percent:
|
|
625
|
+
assetDepth: s,
|
|
626
|
+
percent: r
|
|
621
627
|
}) {
|
|
622
628
|
return Object.fromEntries(
|
|
623
|
-
Object.entries(ht({ liquidityUnits: e, poolUnits: t, runeDepth: n, assetDepth:
|
|
624
|
-
([i, o]) => [i, o.mul(
|
|
629
|
+
Object.entries(ht({ liquidityUnits: e, poolUnits: t, runeDepth: n, assetDepth: s })).map(
|
|
630
|
+
([i, o]) => [i, o.mul(r)]
|
|
625
631
|
)
|
|
626
632
|
);
|
|
627
633
|
}
|
|
@@ -629,11 +635,11 @@ function Ot({
|
|
|
629
635
|
runeDepth: e,
|
|
630
636
|
poolUnits: t,
|
|
631
637
|
assetDepth: n,
|
|
632
|
-
liquidityUnits:
|
|
633
|
-
runeAmount:
|
|
638
|
+
liquidityUnits: s,
|
|
639
|
+
runeAmount: r,
|
|
634
640
|
assetAmount: i
|
|
635
641
|
}) {
|
|
636
|
-
const o = new I({ value: e, decimal: 8 }),
|
|
642
|
+
const o = new I({ value: e, decimal: 8 }), l = new I({ value: n, decimal: 8 }), c = new I({ value: t, decimal: 8 }), _ = new I({ value: r, decimal: 8 }), h = new I({ value: i, decimal: 8 }), P = _.mul(l), ie = h.mul(o), ge = _.mul(h), Oe = o.mul(l), De = c.mul(P.add(ie.add(ge.mul(2)))), Pe = P.add(ie.add(Oe.mul(2))), ae = De.div(Pe), X = A(s).add(ae);
|
|
637
643
|
if (ae.getBaseValue("number") === 0)
|
|
638
644
|
return X.div(c).getBaseValue("number");
|
|
639
645
|
const be = c.add(X);
|
|
@@ -643,11 +649,11 @@ function Dt({
|
|
|
643
649
|
runeAmount: e,
|
|
644
650
|
assetAmount: t,
|
|
645
651
|
runeDepth: n,
|
|
646
|
-
assetDepth:
|
|
652
|
+
assetDepth: s
|
|
647
653
|
}) {
|
|
648
|
-
if (e === "0" || t === "0" || n === "0" ||
|
|
654
|
+
if (e === "0" || t === "0" || n === "0" || s === "0")
|
|
649
655
|
return 0;
|
|
650
|
-
const
|
|
656
|
+
const r = A(n), i = A(s), o = A(t), l = A(e), c = o.mul(r).sub(i.mul(l)), _ = i.mul(l).add(r.mul(i));
|
|
651
657
|
return Math.abs(c.div(_).getBaseValue("number"));
|
|
652
658
|
}
|
|
653
659
|
const Pt = (e, t) => {
|
|
@@ -658,17 +664,17 @@ const Pt = (e, t) => {
|
|
|
658
664
|
return `${e}:${n}`;
|
|
659
665
|
}
|
|
660
666
|
case E.UNBOND: {
|
|
661
|
-
const { address: n, unbondAmount:
|
|
662
|
-
return `${e}:${n}:${
|
|
667
|
+
const { address: n, unbondAmount: s } = t;
|
|
668
|
+
return `${e}:${n}:${s}`;
|
|
663
669
|
}
|
|
664
670
|
case E.THORNAME_REGISTER: {
|
|
665
|
-
const { name: n, chain:
|
|
666
|
-
return `${e}:${n}:${
|
|
671
|
+
const { name: n, chain: s, address: r, owner: i } = t;
|
|
672
|
+
return `${e}:${n}:${s}:${r}${i ? `:${i}` : ""}`;
|
|
667
673
|
}
|
|
668
674
|
case E.DEPOSIT: {
|
|
669
|
-
const { chain: n, symbol:
|
|
670
|
-
return i ? `${e}:${n}/${
|
|
671
|
-
switch (
|
|
675
|
+
const { chain: n, symbol: s, address: r, singleSide: i } = t;
|
|
676
|
+
return i ? `${e}:${n}/${s}::t:0` : `${e}:${((l, c) => {
|
|
677
|
+
switch (l) {
|
|
672
678
|
case a.Litecoin:
|
|
673
679
|
return "l";
|
|
674
680
|
case a.Dogecoin:
|
|
@@ -676,18 +682,18 @@ const Pt = (e, t) => {
|
|
|
676
682
|
case a.BitcoinCash:
|
|
677
683
|
return "c";
|
|
678
684
|
default:
|
|
679
|
-
return `${
|
|
685
|
+
return `${l}.${c}`;
|
|
680
686
|
}
|
|
681
|
-
})(n,
|
|
687
|
+
})(n, s)}:${r || ""}:t:0`;
|
|
682
688
|
}
|
|
683
689
|
case E.WITHDRAW: {
|
|
684
|
-
const { chain: n, ticker:
|
|
685
|
-
return `${e}:${n}${
|
|
690
|
+
const { chain: n, ticker: s, symbol: r, basisPoints: i, targetAssetString: o, singleSide: l } = t, c = n === "ETH" && s !== "ETH" ? `${s}-${r.slice(-3)}` : r, _ = !l && o ? `:${o}` : "";
|
|
691
|
+
return `${e}:${n}${l ? "/" : "."}${c}:${i}${_}`;
|
|
686
692
|
}
|
|
687
693
|
case E.OPEN_LOAN:
|
|
688
694
|
case E.CLOSE_LOAN: {
|
|
689
|
-
const { asset: n, address:
|
|
690
|
-
return `${e}:${n}:${
|
|
695
|
+
const { asset: n, address: s } = t;
|
|
696
|
+
return `${e}:${n}:${s}`;
|
|
691
697
|
}
|
|
692
698
|
default:
|
|
693
699
|
return "";
|
|
@@ -704,22 +710,22 @@ function yt(e) {
|
|
|
704
710
|
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
705
711
|
return !!e.match(t);
|
|
706
712
|
}
|
|
707
|
-
function wt([e, t, n,
|
|
708
|
-
return `${e}'/${t}'/${n}'/${
|
|
713
|
+
function wt([e, t, n, s, r]) {
|
|
714
|
+
return `${e}'/${t}'/${n}'/${s}${typeof r != "number" ? "" : `/${r}`}`;
|
|
709
715
|
}
|
|
710
|
-
const
|
|
716
|
+
const ue = [...Object.values(a), "TERRA"];
|
|
711
717
|
function dt(e = "") {
|
|
712
718
|
const t = e.toUpperCase(), [n] = t.split(".");
|
|
713
|
-
if (
|
|
719
|
+
if (ue.includes(n))
|
|
714
720
|
return !0;
|
|
715
|
-
const [
|
|
716
|
-
if (
|
|
721
|
+
const [s] = t.split("/");
|
|
722
|
+
if (ue.includes(s))
|
|
717
723
|
return !0;
|
|
718
724
|
throw new Error(
|
|
719
725
|
`Invalid identifier: ${e}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
720
726
|
);
|
|
721
727
|
}
|
|
722
|
-
const B = 8,
|
|
728
|
+
const B = 8, C = (e) => 10n ** BigInt(e), b = (e) => Math.log10(parseFloat(e.toString()));
|
|
723
729
|
function G({
|
|
724
730
|
value: e,
|
|
725
731
|
bigIntDecimal: t = B,
|
|
@@ -727,33 +733,33 @@ function G({
|
|
|
727
733
|
}) {
|
|
728
734
|
if (n === 0)
|
|
729
735
|
return e.toString();
|
|
730
|
-
const
|
|
731
|
-
let
|
|
732
|
-
const i = n - (
|
|
733
|
-
i > 0 && (
|
|
734
|
-
const o =
|
|
735
|
-
let
|
|
736
|
-
return parseInt(
|
|
736
|
+
const s = e < 0n;
|
|
737
|
+
let r = e.toString().substring(s ? 1 : 0);
|
|
738
|
+
const i = n - (r.length - 1);
|
|
739
|
+
i > 0 && (r = "0".repeat(i) + r);
|
|
740
|
+
const o = r.length - n;
|
|
741
|
+
let l = r.slice(-n);
|
|
742
|
+
return parseInt(l[t]) >= 5 ? l = `${l.substring(0, t - 1)}${(parseInt(l[t - 1]) + 1).toString()}` : l = l.substring(0, t), `${s ? "-" : ""}${r.slice(0, o)}.${l}`.replace(
|
|
737
743
|
/\.?0*$/,
|
|
738
744
|
""
|
|
739
745
|
);
|
|
740
746
|
}
|
|
741
|
-
var
|
|
742
|
-
const
|
|
747
|
+
var N, y, f, D, k, Ce, L, z, U, Z;
|
|
748
|
+
const re = class re {
|
|
743
749
|
constructor(t) {
|
|
744
|
-
O(this,
|
|
750
|
+
O(this, N);
|
|
745
751
|
O(this, f);
|
|
746
|
-
O(this,
|
|
747
|
-
O(this, U);
|
|
752
|
+
O(this, k);
|
|
748
753
|
O(this, L);
|
|
754
|
+
O(this, U);
|
|
749
755
|
p(this, "decimalMultiplier", 10n ** 8n);
|
|
750
756
|
p(this, "bigIntValue", 0n);
|
|
751
757
|
p(this, "decimal");
|
|
752
|
-
const n = ee(t),
|
|
753
|
-
this.decimal =
|
|
758
|
+
const n = ee(t), s = typeof t == "object";
|
|
759
|
+
this.decimal = s ? t.decimal : void 0, this.decimalMultiplier = s && "decimalMultiplier" in t ? t.decimalMultiplier : C(Math.max(_e($(n)), this.decimal || 0)), T(this, k, Ce).call(this, n);
|
|
754
760
|
}
|
|
755
761
|
static fromBigInt(t, n) {
|
|
756
|
-
return new
|
|
762
|
+
return new re({
|
|
757
763
|
decimal: n,
|
|
758
764
|
value: G({ value: t, bigIntDecimal: n, decimal: n })
|
|
759
765
|
});
|
|
@@ -761,27 +767,27 @@ const se = class se {
|
|
|
761
767
|
static shiftDecimals({
|
|
762
768
|
value: t,
|
|
763
769
|
from: n,
|
|
764
|
-
to:
|
|
770
|
+
to: s
|
|
765
771
|
}) {
|
|
766
772
|
return this.fromBigInt(
|
|
767
|
-
t.getBaseValue("bigint") *
|
|
768
|
-
|
|
773
|
+
t.getBaseValue("bigint") * C(s) / C(n),
|
|
774
|
+
s
|
|
769
775
|
);
|
|
770
776
|
}
|
|
771
777
|
set(t) {
|
|
772
778
|
return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
|
|
773
779
|
}
|
|
774
780
|
add(...t) {
|
|
775
|
-
return T(this,
|
|
781
|
+
return T(this, N, y).call(this, "add", ...t);
|
|
776
782
|
}
|
|
777
783
|
sub(...t) {
|
|
778
|
-
return T(this,
|
|
784
|
+
return T(this, N, y).call(this, "sub", ...t);
|
|
779
785
|
}
|
|
780
786
|
mul(...t) {
|
|
781
|
-
return T(this,
|
|
787
|
+
return T(this, N, y).call(this, "mul", ...t);
|
|
782
788
|
}
|
|
783
789
|
div(...t) {
|
|
784
|
-
return T(this,
|
|
790
|
+
return T(this, N, y).call(this, "div", ...t);
|
|
785
791
|
}
|
|
786
792
|
gt(t) {
|
|
787
793
|
return T(this, f, D).call(this, "gt", t);
|
|
@@ -815,81 +821,81 @@ const se = class se {
|
|
|
815
821
|
}
|
|
816
822
|
// @ts-expect-error
|
|
817
823
|
getBaseValue(t) {
|
|
818
|
-
const n = this.decimalMultiplier /
|
|
824
|
+
const n = this.decimalMultiplier / C(this.decimal || d.THOR), s = this.bigIntValue / n;
|
|
819
825
|
switch (t) {
|
|
820
826
|
case "number":
|
|
821
|
-
return Number(
|
|
827
|
+
return Number(s);
|
|
822
828
|
case "string":
|
|
823
|
-
return
|
|
829
|
+
return s.toString();
|
|
824
830
|
case "bigint":
|
|
825
|
-
return
|
|
831
|
+
return s;
|
|
826
832
|
}
|
|
827
833
|
}
|
|
828
834
|
getBigIntValue(t, n) {
|
|
829
835
|
if (!n && typeof t == "object")
|
|
830
836
|
return t.bigIntValue;
|
|
831
|
-
const
|
|
832
|
-
return
|
|
837
|
+
const s = ee(t), r = $(s);
|
|
838
|
+
return r === "0" || r === "undefined" ? 0n : T(this, U, Z).call(this, r, n);
|
|
833
839
|
}
|
|
834
840
|
toSignificant(t = 6) {
|
|
835
|
-
const [n,
|
|
836
|
-
if ((parseInt(
|
|
841
|
+
const [n, s] = this.getValue("string").split("."), r = n || "", i = s || "";
|
|
842
|
+
if ((parseInt(r) ? r.length + i.length : i.length) <= t)
|
|
837
843
|
return this.getValue("string");
|
|
838
|
-
if (
|
|
839
|
-
return
|
|
840
|
-
if (parseInt(
|
|
841
|
-
return `${
|
|
842
|
-
t -
|
|
844
|
+
if (r.length >= t)
|
|
845
|
+
return r.slice(0, t).padEnd(r.length, "0");
|
|
846
|
+
if (parseInt(r))
|
|
847
|
+
return `${r}.${i.slice(0, t - r.length)}`.padEnd(
|
|
848
|
+
t - r.length,
|
|
843
849
|
"0"
|
|
844
850
|
);
|
|
845
|
-
const
|
|
851
|
+
const l = parseInt(i), c = `${l}`.slice(0, t);
|
|
846
852
|
return `0.${c.padStart(
|
|
847
|
-
i.length - `${
|
|
853
|
+
i.length - `${l}`.length + c.length,
|
|
848
854
|
"0"
|
|
849
855
|
)}`;
|
|
850
856
|
}
|
|
851
857
|
toFixed(t = 6) {
|
|
852
|
-
const [n,
|
|
853
|
-
if (parseInt(
|
|
854
|
-
return `${
|
|
855
|
-
const o = parseInt(i),
|
|
856
|
-
return `0.${
|
|
857
|
-
i.length - `${o}`.length +
|
|
858
|
+
const [n, s] = this.getValue("string").split("."), r = n || "", i = s || "";
|
|
859
|
+
if (parseInt(r))
|
|
860
|
+
return `${r}.${i.slice(0, t)}`.padEnd(t, "0");
|
|
861
|
+
const o = parseInt(i), l = `${o}`.slice(0, t);
|
|
862
|
+
return `0.${l.padStart(
|
|
863
|
+
i.length - `${o}`.length + l.length,
|
|
858
864
|
"0"
|
|
859
865
|
)}`;
|
|
860
866
|
}
|
|
861
867
|
toAbbreviation(t = 2) {
|
|
862
|
-
const n = this.getValue("number"),
|
|
868
|
+
const n = this.getValue("number"), s = ["", "K", "M", "B", "T", "Q", "Qi", "S"], r = Math.floor(Math.log10(Math.abs(n)) / 3), i = s[r];
|
|
863
869
|
if (!i)
|
|
864
870
|
return this.getValue("string");
|
|
865
|
-
const o = 10 ** (
|
|
871
|
+
const o = 10 ** (r * 3);
|
|
866
872
|
return `${(n / o).toFixed(t)}${i}`;
|
|
867
873
|
}
|
|
868
874
|
toCurrency(t = "$", {
|
|
869
875
|
currencyPosition: n = "start",
|
|
870
|
-
decimal:
|
|
871
|
-
decimalSeparator:
|
|
876
|
+
decimal: s = 2,
|
|
877
|
+
decimalSeparator: r = ".",
|
|
872
878
|
thousandSeparator: i = ","
|
|
873
879
|
} = {}) {
|
|
874
|
-
const o = this.getValue("number"), [
|
|
880
|
+
const o = this.getValue("number"), [l, c = ""] = o.toFixed(6).split("."), _ = l.replace(/\B(?=(\d{3})+(?!\d))/g, i), h = !l && !c ? "0.00" : l === "0" ? `${parseFloat(`0.${c}`)}`.replace(".", r) : `${_}${parseInt(c) ? `${r}${c.slice(0, s)}` : ""}`;
|
|
875
881
|
return `${n === "start" ? t : ""}${h}${n === "end" ? t : ""}`;
|
|
876
882
|
}
|
|
877
883
|
formatBigIntToSafeValue(t, n) {
|
|
878
|
-
const
|
|
879
|
-
|
|
884
|
+
const s = n || this.decimal || B, r = Math.max(
|
|
885
|
+
s,
|
|
880
886
|
b(this.decimalMultiplier)
|
|
881
|
-
), i = t < 0n, o = t.toString().substring(i ? 1 : 0),
|
|
882
|
-
let h = c.slice(-
|
|
883
|
-
return parseInt(h[
|
|
887
|
+
), i = t < 0n, o = t.toString().substring(i ? 1 : 0), l = r - (o.length - 1), c = l > 0 ? "0".repeat(l) + o : o, _ = c.length - r;
|
|
888
|
+
let h = c.slice(-r);
|
|
889
|
+
return parseInt(h[s]) >= 5 ? h = `${h.substring(0, s - 1)}${(parseInt(h[s - 1]) + 1).toString()}` : h = h.substring(0, s), `${i ? "-" : ""}${c.slice(
|
|
884
890
|
0,
|
|
885
891
|
_
|
|
886
892
|
)}.${h}`.replace(/\.?0*$/, "");
|
|
887
893
|
}
|
|
888
894
|
};
|
|
889
|
-
|
|
890
|
-
const
|
|
895
|
+
N = new WeakSet(), y = function(t, ...n) {
|
|
896
|
+
const s = T(this, L, z).call(this, this, ...n), r = Math.max(s, b(this.decimalMultiplier)), i = C(r), o = n.reduce(
|
|
891
897
|
(c, _) => {
|
|
892
|
-
const h = this.getBigIntValue(_,
|
|
898
|
+
const h = this.getBigIntValue(_, r);
|
|
893
899
|
switch (t) {
|
|
894
900
|
case "add":
|
|
895
901
|
return c + h;
|
|
@@ -908,42 +914,42 @@ C = new WeakSet(), y = function(t, ...n) {
|
|
|
908
914
|
},
|
|
909
915
|
//normalize is to precision multiplier base
|
|
910
916
|
this.bigIntValue * i / this.decimalMultiplier
|
|
911
|
-
),
|
|
912
|
-
bigIntDecimal:
|
|
913
|
-
decimal:
|
|
917
|
+
), l = G({
|
|
918
|
+
bigIntDecimal: r,
|
|
919
|
+
decimal: r,
|
|
914
920
|
value: o
|
|
915
921
|
});
|
|
916
922
|
return new this.constructor({
|
|
917
|
-
decimalMultiplier:
|
|
923
|
+
decimalMultiplier: C(r),
|
|
918
924
|
decimal: this.decimal,
|
|
919
|
-
value:
|
|
925
|
+
value: l,
|
|
920
926
|
identifier: this.toString()
|
|
921
927
|
});
|
|
922
928
|
}, f = new WeakSet(), D = function(t, ...n) {
|
|
923
|
-
const
|
|
929
|
+
const s = T(this, L, z).call(this, this, ...n), r = this.getBigIntValue(n[0], s), i = this.getBigIntValue(this, s);
|
|
924
930
|
switch (t) {
|
|
925
931
|
case "gt":
|
|
926
|
-
return i >
|
|
932
|
+
return i > r;
|
|
927
933
|
case "gte":
|
|
928
|
-
return i >=
|
|
934
|
+
return i >= r;
|
|
929
935
|
case "lt":
|
|
930
|
-
return i <
|
|
936
|
+
return i < r;
|
|
931
937
|
case "lte":
|
|
932
|
-
return i <=
|
|
938
|
+
return i <= r;
|
|
933
939
|
case "eqValue":
|
|
934
|
-
return i ===
|
|
940
|
+
return i === r;
|
|
935
941
|
}
|
|
936
|
-
},
|
|
942
|
+
}, k = new WeakSet(), Ce = function(t) {
|
|
937
943
|
const n = $(t) || "0";
|
|
938
|
-
this.bigIntValue = T(this,
|
|
939
|
-
},
|
|
940
|
-
const n = t.map((
|
|
944
|
+
this.bigIntValue = T(this, U, Z).call(this, n);
|
|
945
|
+
}, L = new WeakSet(), z = function(...t) {
|
|
946
|
+
const n = t.map((s) => typeof s == "object" ? s.decimal || b(s.decimalMultiplier) : _e($(s))).filter(Boolean);
|
|
941
947
|
return Math.max(...n, B);
|
|
942
|
-
},
|
|
943
|
-
const
|
|
944
|
-
return BigInt(`${i}${o.padEnd(
|
|
948
|
+
}, U = new WeakSet(), Z = function(t, n) {
|
|
949
|
+
const s = n ? C(n) : this.decimalMultiplier, r = b(s), [i = "", o = ""] = t.split(".");
|
|
950
|
+
return BigInt(`${i}${o.padEnd(r, "0")}`);
|
|
945
951
|
};
|
|
946
|
-
let W =
|
|
952
|
+
let W = re;
|
|
947
953
|
const Tt = Intl.NumberFormat("fullwide", {
|
|
948
954
|
useGrouping: !1,
|
|
949
955
|
maximumFractionDigits: 20
|
|
@@ -964,13 +970,13 @@ const w = /* @__PURE__ */ new Map();
|
|
|
964
970
|
class g extends W {
|
|
965
971
|
constructor({
|
|
966
972
|
value: n,
|
|
967
|
-
decimal:
|
|
968
|
-
tax:
|
|
973
|
+
decimal: s,
|
|
974
|
+
tax: r,
|
|
969
975
|
chain: i,
|
|
970
976
|
symbol: o,
|
|
971
|
-
identifier:
|
|
977
|
+
identifier: l
|
|
972
978
|
}) {
|
|
973
|
-
super(typeof n == "object" ? n : { decimal:
|
|
979
|
+
super(typeof n == "object" ? n : { decimal: s, value: n });
|
|
974
980
|
p(this, "address");
|
|
975
981
|
p(this, "chain");
|
|
976
982
|
p(this, "isGasAsset", !1);
|
|
@@ -979,8 +985,8 @@ class g extends W {
|
|
|
979
985
|
p(this, "tax");
|
|
980
986
|
p(this, "ticker");
|
|
981
987
|
p(this, "type");
|
|
982
|
-
const c =
|
|
983
|
-
this.type = ot(c), this.tax =
|
|
988
|
+
const c = F(l || `${i}.${o}`);
|
|
989
|
+
this.type = ot(c), this.tax = r, this.chain = c.chain, this.ticker = c.ticker, this.symbol = c.symbol, this.address = c.address, this.isSynthetic = c.isSynthetic, this.isGasAsset = c.isGasAsset;
|
|
984
990
|
}
|
|
985
991
|
toString() {
|
|
986
992
|
return this.isSynthetic ? this.symbol : `${this.chain}.${this.symbol}`;
|
|
@@ -988,75 +994,75 @@ class g extends W {
|
|
|
988
994
|
toUrl() {
|
|
989
995
|
return this.isSynthetic ? `${this.chain}.${this.symbol.replace("/", ".")}` : this.toString();
|
|
990
996
|
}
|
|
991
|
-
eq({ chain: n, symbol:
|
|
992
|
-
return this.chain === n && this.symbol ===
|
|
997
|
+
eq({ chain: n, symbol: s }) {
|
|
998
|
+
return this.chain === n && this.symbol === s;
|
|
993
999
|
}
|
|
994
1000
|
chainId() {
|
|
995
|
-
return
|
|
1001
|
+
return Ue[this.chain];
|
|
996
1002
|
}
|
|
997
1003
|
// THOR.RUNE
|
|
998
1004
|
// THOR.ETH.ETH
|
|
999
1005
|
// ETH.THOR-0x1234567890
|
|
1000
|
-
static fromUrl(n,
|
|
1001
|
-
const [
|
|
1002
|
-
if (!
|
|
1006
|
+
static fromUrl(n, s = 0) {
|
|
1007
|
+
const [r, i, o] = n.split(".");
|
|
1008
|
+
if (!r || !i)
|
|
1003
1009
|
throw new Error("Invalid asset url");
|
|
1004
|
-
const
|
|
1005
|
-
return J(
|
|
1010
|
+
const l = r === a.THORChain && o ? `${r}.${i}/${o}` : n;
|
|
1011
|
+
return J(l, s);
|
|
1006
1012
|
}
|
|
1007
|
-
static fromString(n,
|
|
1008
|
-
return J(n,
|
|
1013
|
+
static fromString(n, s = 0) {
|
|
1014
|
+
return J(n, s);
|
|
1009
1015
|
}
|
|
1010
|
-
static fromIdentifier(n,
|
|
1011
|
-
return J(n,
|
|
1016
|
+
static fromIdentifier(n, s = 0) {
|
|
1017
|
+
return J(n, s);
|
|
1012
1018
|
}
|
|
1013
|
-
static fromStringSync(n,
|
|
1014
|
-
const { chain:
|
|
1019
|
+
static fromStringSync(n, s = 0) {
|
|
1020
|
+
const { chain: r, isSynthetic: i } = F(n), o = w.get(n.toUpperCase());
|
|
1015
1021
|
if (i)
|
|
1016
|
-
return he(n,
|
|
1017
|
-
const { tax:
|
|
1018
|
-
decimal: d[
|
|
1022
|
+
return he(n, s);
|
|
1023
|
+
const { tax: l, decimal: c, identifier: _ } = o || {
|
|
1024
|
+
decimal: d[r],
|
|
1019
1025
|
identifier: n
|
|
1020
1026
|
};
|
|
1021
1027
|
return new g({
|
|
1022
|
-
tax:
|
|
1023
|
-
value: V(
|
|
1028
|
+
tax: l,
|
|
1029
|
+
value: V(s, c),
|
|
1024
1030
|
identifier: i ? n : _,
|
|
1025
1031
|
decimal: i ? 8 : c
|
|
1026
1032
|
});
|
|
1027
1033
|
}
|
|
1028
|
-
static fromIdentifierSync(n,
|
|
1029
|
-
const { chain:
|
|
1034
|
+
static fromIdentifierSync(n, s = 0) {
|
|
1035
|
+
const { chain: r, isSynthetic: i } = F(n), o = w.get(n);
|
|
1030
1036
|
if (i)
|
|
1031
|
-
return he(n,
|
|
1032
|
-
const { tax:
|
|
1033
|
-
decimal: d[
|
|
1037
|
+
return he(n, s);
|
|
1038
|
+
const { tax: l, decimal: c, identifier: _ } = o || {
|
|
1039
|
+
decimal: d[r],
|
|
1034
1040
|
identifier: n
|
|
1035
1041
|
};
|
|
1036
|
-
return new g({ tax:
|
|
1042
|
+
return new g({ tax: l, decimal: c, identifier: _, value: V(s, c) });
|
|
1037
1043
|
}
|
|
1038
|
-
static fromChainOrSignature(n,
|
|
1039
|
-
const { decimal:
|
|
1040
|
-
return new g({ value: V(
|
|
1044
|
+
static fromChainOrSignature(n, s = 0) {
|
|
1045
|
+
const { decimal: r, identifier: i } = at(n);
|
|
1046
|
+
return new g({ value: V(s, r), decimal: r, identifier: i });
|
|
1041
1047
|
}
|
|
1042
1048
|
static loadStaticAssets() {
|
|
1043
1049
|
return new Promise(
|
|
1044
|
-
async (n,
|
|
1050
|
+
async (n, s) => {
|
|
1045
1051
|
try {
|
|
1046
|
-
const
|
|
1047
|
-
Object.values(
|
|
1052
|
+
const r = await import("@swapkit/tokens");
|
|
1053
|
+
Object.values(r).forEach((i) => {
|
|
1048
1054
|
var o;
|
|
1049
|
-
(o = i == null ? void 0 : i.tokens) == null || o.forEach(({ identifier:
|
|
1050
|
-
w.set(
|
|
1051
|
-
identifier:
|
|
1055
|
+
(o = i == null ? void 0 : i.tokens) == null || o.forEach(({ identifier: l, chain: c, ..._ }) => {
|
|
1056
|
+
w.set(l.toUpperCase(), {
|
|
1057
|
+
identifier: l,
|
|
1052
1058
|
decimal: "decimals" in _ ? _.decimals : d[c]
|
|
1053
1059
|
});
|
|
1054
1060
|
});
|
|
1055
1061
|
}), n({ ok: !0 });
|
|
1056
|
-
} catch (
|
|
1057
|
-
console.error(
|
|
1062
|
+
} catch (r) {
|
|
1063
|
+
console.error(r), s({
|
|
1058
1064
|
ok: !1,
|
|
1059
|
-
error:
|
|
1065
|
+
error: r,
|
|
1060
1066
|
message: "Couldn't load static assets. Ensure you have installed @swapkit/tokens package"
|
|
1061
1067
|
});
|
|
1062
1068
|
}
|
|
@@ -1087,34 +1093,34 @@ function Vt(e) {
|
|
|
1087
1093
|
}
|
|
1088
1094
|
async function J(e, t = 0) {
|
|
1089
1095
|
dt(e);
|
|
1090
|
-
const n = w.get(e.toUpperCase()),
|
|
1091
|
-
return n || w.set(e.toUpperCase(), { identifier: e, decimal:
|
|
1096
|
+
const n = w.get(e.toUpperCase()), s = (n == null ? void 0 : n.decimal) || await it(F(e));
|
|
1097
|
+
return n || w.set(e.toUpperCase(), { identifier: e, decimal: s }), new g({ decimal: s, value: V(t, s), identifier: e });
|
|
1092
1098
|
}
|
|
1093
1099
|
function he(e, t = 0) {
|
|
1094
|
-
const [n,
|
|
1095
|
-
if (!n || !
|
|
1100
|
+
const [n, s] = e.split(".")[0].toUpperCase() === a.THORChain ? e.split(".").slice(1).join().split("/") : e.split("/");
|
|
1101
|
+
if (!n || !s)
|
|
1096
1102
|
throw new Error("Invalid asset identifier");
|
|
1097
1103
|
return new g({
|
|
1098
1104
|
decimal: 8,
|
|
1099
1105
|
value: V(t, 8),
|
|
1100
|
-
identifier: `${a.THORChain}.${n}/${
|
|
1106
|
+
identifier: `${a.THORChain}.${n}/${s}`
|
|
1101
1107
|
});
|
|
1102
1108
|
}
|
|
1103
1109
|
function V(e, t) {
|
|
1104
1110
|
return typeof e == "bigint" ? G({ value: e, bigIntDecimal: t, decimal: t }) : e;
|
|
1105
1111
|
}
|
|
1106
|
-
function
|
|
1107
|
-
const t = e.slice(0, 14).includes("/"), [n,
|
|
1108
|
-
if (t && (!n || !
|
|
1112
|
+
function F(e) {
|
|
1113
|
+
const t = e.slice(0, 14).includes("/"), [n, s] = e.split(".")[0].toUpperCase() === a.THORChain ? e.split(".").slice(1).join().split("/") : e.split("/");
|
|
1114
|
+
if (t && (!n || !s))
|
|
1109
1115
|
throw new Error("Invalid asset identifier");
|
|
1110
|
-
const
|
|
1116
|
+
const r = e.includes(".") && !t ? e : `${a.THORChain}.${s}`, [i, ...o] = r.split("."), [l, c] = (t ? s : o.join(".")).split("-"), _ = t ? s : o.join(".");
|
|
1111
1117
|
return {
|
|
1112
1118
|
address: c == null ? void 0 : c.toLowerCase(),
|
|
1113
1119
|
chain: i,
|
|
1114
1120
|
isGasAsset: fe({ chain: i, symbol: _ }),
|
|
1115
1121
|
isSynthetic: t,
|
|
1116
|
-
symbol: (t ? `${n}/` : "") + (c ? `${
|
|
1117
|
-
ticker:
|
|
1122
|
+
symbol: (t ? `${n}/` : "") + (c ? `${l}-${(c == null ? void 0 : c.toLowerCase()) ?? ""}` : _),
|
|
1123
|
+
ticker: l
|
|
1118
1124
|
};
|
|
1119
1125
|
}
|
|
1120
1126
|
const At = {
|
|
@@ -1181,9 +1187,9 @@ const At = {
|
|
|
1181
1187
|
*/
|
|
1182
1188
|
helpers_number_different_decimals: 99101
|
|
1183
1189
|
};
|
|
1184
|
-
class
|
|
1190
|
+
class Ne extends Error {
|
|
1185
1191
|
constructor(t, n) {
|
|
1186
|
-
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,
|
|
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, Ne.prototype);
|
|
1187
1193
|
}
|
|
1188
1194
|
}
|
|
1189
1195
|
class I extends W {
|
|
@@ -1204,7 +1210,7 @@ export {
|
|
|
1204
1210
|
S as RequestClient,
|
|
1205
1211
|
et as StreamingSwapProgressStatus,
|
|
1206
1212
|
Et as SwapKitApi,
|
|
1207
|
-
|
|
1213
|
+
Ne as SwapKitError,
|
|
1208
1214
|
I as SwapKitNumber,
|
|
1209
1215
|
ze as TransactionType,
|
|
1210
1216
|
Ze as TxStatus,
|
|
@@ -1216,9 +1222,9 @@ export {
|
|
|
1216
1222
|
Rt as gasFeeMultiplier,
|
|
1217
1223
|
ot as getAssetType,
|
|
1218
1224
|
_t as getAsymmetricAssetShare,
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1225
|
+
Nt as getAsymmetricAssetWithdrawAmount,
|
|
1226
|
+
ut as getAsymmetricRuneShare,
|
|
1227
|
+
Ct as getAsymmetricRuneWithdrawAmount,
|
|
1222
1228
|
at as getCommonAssetInfo,
|
|
1223
1229
|
it as getDecimal,
|
|
1224
1230
|
Ot as getEstimatedPoolShare,
|