@swapkit/helpers 0.0.0-nightly-20240208140027
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +490 -0
- package/dist/index.es.js +1241 -0
- package/dist/index.es.js.map +1 -0
- package/package.json +53 -0
- package/src/helpers/__tests__/asset.test.ts +157 -0
- package/src/helpers/__tests__/memo.test.ts +79 -0
- package/src/helpers/__tests__/others.test.ts +59 -0
- package/src/helpers/asset.ts +227 -0
- package/src/helpers/liquidity.ts +180 -0
- package/src/helpers/memo.ts +93 -0
- package/src/helpers/others.ts +20 -0
- package/src/helpers/validators.ts +18 -0
- package/src/index.ts +17 -0
- package/src/modules/__tests__/assetValue.test.ts +409 -0
- package/src/modules/__tests__/bigIntArithmetics.test.ts +30 -0
- package/src/modules/__tests__/swapKitNumber.test.ts +533 -0
- package/src/modules/assetValue.ts +266 -0
- package/src/modules/bigIntArithmetics.ts +419 -0
- package/src/modules/swapKitError.ts +79 -0
- package/src/modules/swapKitNumber.ts +16 -0
- package/src/types.ts +30 -0
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,1241 @@
|
|
|
1
|
+
var ye = Object.defineProperty;
|
|
2
|
+
var we = (e, t, n) => t in e ? ye(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var p = (e, t, n) => (we(e, typeof t != "symbol" ? t + "" : t, n), n), Ve = (e, t, n) => {
|
|
4
|
+
if (!t.has(e))
|
|
5
|
+
throw TypeError("Cannot " + n);
|
|
6
|
+
};
|
|
7
|
+
var O = (e, t, n) => {
|
|
8
|
+
if (t.has(e))
|
|
9
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
10
|
+
t instanceof WeakSet ? t.add(e) : t.set(e, n);
|
|
11
|
+
};
|
|
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 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.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.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
|
+
(e, t) => {
|
|
19
|
+
const n = ve.find((s) => j[s] === t);
|
|
20
|
+
return n && (e[t] = n), e;
|
|
21
|
+
},
|
|
22
|
+
{}
|
|
23
|
+
);
|
|
24
|
+
q.reduce(
|
|
25
|
+
(e, t) => (e[t] = te[ne[t]], e),
|
|
26
|
+
{}
|
|
27
|
+
);
|
|
28
|
+
q.reduce(
|
|
29
|
+
(e, t) => (e[t] = de[ne[t]], e),
|
|
30
|
+
{}
|
|
31
|
+
);
|
|
32
|
+
q.reduce(
|
|
33
|
+
(e, t) => {
|
|
34
|
+
const n = `${ne[t]}Hex`;
|
|
35
|
+
return e[t] = te[n], e;
|
|
36
|
+
},
|
|
37
|
+
{}
|
|
38
|
+
);
|
|
39
|
+
class oe extends Error {
|
|
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
|
+
enumerable: !0,
|
|
44
|
+
configurable: !0,
|
|
45
|
+
writable: !0,
|
|
46
|
+
value: void 0
|
|
47
|
+
}), Object.defineProperty(this, "request", {
|
|
48
|
+
enumerable: !0,
|
|
49
|
+
configurable: !0,
|
|
50
|
+
writable: !0,
|
|
51
|
+
value: void 0
|
|
52
|
+
}), Object.defineProperty(this, "options", {
|
|
53
|
+
enumerable: !0,
|
|
54
|
+
configurable: !0,
|
|
55
|
+
writable: !0,
|
|
56
|
+
value: void 0
|
|
57
|
+
}), this.name = "HTTPError", this.response = t, this.request = n, this.options = s;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
class Te extends Error {
|
|
61
|
+
constructor(t) {
|
|
62
|
+
super("Request timed out"), Object.defineProperty(this, "request", {
|
|
63
|
+
enumerable: !0,
|
|
64
|
+
configurable: !0,
|
|
65
|
+
writable: !0,
|
|
66
|
+
value: void 0
|
|
67
|
+
}), this.name = "TimeoutError", this.request = t;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const M = (e) => e !== null && typeof e == "object", v = (...e) => {
|
|
71
|
+
for (const t of e)
|
|
72
|
+
if ((!M(t) || Array.isArray(t)) && t !== void 0)
|
|
73
|
+
throw new TypeError("The `options` argument must be an object");
|
|
74
|
+
return se({}, ...e);
|
|
75
|
+
}, Ae = (e = {}, t = {}) => {
|
|
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
|
+
return n;
|
|
80
|
+
}, se = (...e) => {
|
|
81
|
+
let t = {}, n = {};
|
|
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
|
+
}
|
|
90
|
+
return t;
|
|
91
|
+
}, $e = (() => {
|
|
92
|
+
let e = !1, t = !1;
|
|
93
|
+
const n = typeof globalThis.ReadableStream == "function", s = typeof globalThis.Request == "function";
|
|
94
|
+
return n && s && (t = new globalThis.Request("https://empty.invalid", {
|
|
95
|
+
body: new globalThis.ReadableStream(),
|
|
96
|
+
method: "POST",
|
|
97
|
+
// @ts-expect-error - Types are outdated.
|
|
98
|
+
get duplex() {
|
|
99
|
+
return e = !0, "half";
|
|
100
|
+
}
|
|
101
|
+
}).headers.has("Content-Type")), e && !t;
|
|
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
|
+
json: "application/json",
|
|
104
|
+
text: "text/*",
|
|
105
|
+
formData: "multipart/form-data",
|
|
106
|
+
arrayBuffer: "*/*",
|
|
107
|
+
blob: "*/*"
|
|
108
|
+
}, K = 2147483647, Se = Symbol("stop"), Ge = {
|
|
109
|
+
json: !0,
|
|
110
|
+
parseJson: !0,
|
|
111
|
+
searchParams: !0,
|
|
112
|
+
prefixUrl: !0,
|
|
113
|
+
retry: !0,
|
|
114
|
+
timeout: !0,
|
|
115
|
+
hooks: !0,
|
|
116
|
+
throwHttpErrors: !0,
|
|
117
|
+
onDownloadProgress: !0,
|
|
118
|
+
fetch: !0
|
|
119
|
+
}, We = {
|
|
120
|
+
method: !0,
|
|
121
|
+
headers: !0,
|
|
122
|
+
body: !0,
|
|
123
|
+
mode: !0,
|
|
124
|
+
credentials: !0,
|
|
125
|
+
cache: !0,
|
|
126
|
+
redirect: !0,
|
|
127
|
+
referrer: !0,
|
|
128
|
+
referrerPolicy: !0,
|
|
129
|
+
integrity: !0,
|
|
130
|
+
keepalive: !0,
|
|
131
|
+
signal: !0,
|
|
132
|
+
window: !0,
|
|
133
|
+
dispatcher: !0,
|
|
134
|
+
duplex: !0
|
|
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
|
+
limit: 2,
|
|
137
|
+
methods: je,
|
|
138
|
+
statusCodes: qe,
|
|
139
|
+
afterStatusCodes: me,
|
|
140
|
+
maxRetryAfter: Number.POSITIVE_INFINITY,
|
|
141
|
+
backoffLimit: Number.POSITIVE_INFINITY,
|
|
142
|
+
delay: (e) => 0.3 * 2 ** (e - 1) * 1e3
|
|
143
|
+
}, Xe = (e = {}) => {
|
|
144
|
+
if (typeof e == "number")
|
|
145
|
+
return {
|
|
146
|
+
...ce,
|
|
147
|
+
limit: e
|
|
148
|
+
};
|
|
149
|
+
if (e.methods && !Array.isArray(e.methods))
|
|
150
|
+
throw new Error("retry.methods must be an array");
|
|
151
|
+
if (e.statusCodes && !Array.isArray(e.statusCodes))
|
|
152
|
+
throw new Error("retry.statusCodes must be an array");
|
|
153
|
+
return {
|
|
154
|
+
...ce,
|
|
155
|
+
...e,
|
|
156
|
+
afterStatusCodes: me
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
async function Ye(e, t, n, s) {
|
|
160
|
+
return new Promise((r, i) => {
|
|
161
|
+
const o = setTimeout(() => {
|
|
162
|
+
n && n.abort(), i(new Te(e));
|
|
163
|
+
}, s.timeout);
|
|
164
|
+
s.fetch(e, t).then(r).catch(i).then(() => {
|
|
165
|
+
clearTimeout(o);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
async function Ke(e, { signal: t }) {
|
|
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
|
+
}
|
|
175
|
+
const i = setTimeout(() => {
|
|
176
|
+
t == null || t.removeEventListener("abort", r), n();
|
|
177
|
+
}, e);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
const Je = (e, t) => {
|
|
181
|
+
const n = {};
|
|
182
|
+
for (const s in t)
|
|
183
|
+
!(s in We) && !(s in Ge) && !(s in e) && (n[s] = t[s]);
|
|
184
|
+
return n;
|
|
185
|
+
};
|
|
186
|
+
class x {
|
|
187
|
+
static create(t, n) {
|
|
188
|
+
const s = new x(t, n), r = async () => {
|
|
189
|
+
if (typeof s._options.timeout == "number" && s._options.timeout > K)
|
|
190
|
+
throw new RangeError(`The \`timeout\` option cannot be greater than ${K}`);
|
|
191
|
+
await Promise.resolve();
|
|
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
|
+
c instanceof globalThis.Response && (o = c);
|
|
196
|
+
}
|
|
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
|
+
}
|
|
203
|
+
if (s._options.onDownloadProgress) {
|
|
204
|
+
if (typeof s._options.onDownloadProgress != "function")
|
|
205
|
+
throw new TypeError("The `onDownloadProgress` option must be a function");
|
|
206
|
+
if (!He)
|
|
207
|
+
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
|
|
208
|
+
return s._stream(o.clone(), s._options.onDownloadProgress);
|
|
209
|
+
}
|
|
210
|
+
return 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
|
+
i[o] = async () => {
|
|
214
|
+
s.request.headers.set("accept", s.request.headers.get("accept") || l);
|
|
215
|
+
const c = (await i).clone();
|
|
216
|
+
if (o === "json") {
|
|
217
|
+
if (c.status === 204 || (await c.clone().arrayBuffer()).byteLength === 0)
|
|
218
|
+
return "";
|
|
219
|
+
if (n.parseJson)
|
|
220
|
+
return n.parseJson(await c.text());
|
|
221
|
+
}
|
|
222
|
+
return c[o]();
|
|
223
|
+
};
|
|
224
|
+
return i;
|
|
225
|
+
}
|
|
226
|
+
// eslint-disable-next-line complexity
|
|
227
|
+
constructor(t, n = {}) {
|
|
228
|
+
if (Object.defineProperty(this, "request", {
|
|
229
|
+
enumerable: !0,
|
|
230
|
+
configurable: !0,
|
|
231
|
+
writable: !0,
|
|
232
|
+
value: void 0
|
|
233
|
+
}), Object.defineProperty(this, "abortController", {
|
|
234
|
+
enumerable: !0,
|
|
235
|
+
configurable: !0,
|
|
236
|
+
writable: !0,
|
|
237
|
+
value: void 0
|
|
238
|
+
}), Object.defineProperty(this, "_retryCount", {
|
|
239
|
+
enumerable: !0,
|
|
240
|
+
configurable: !0,
|
|
241
|
+
writable: !0,
|
|
242
|
+
value: 0
|
|
243
|
+
}), Object.defineProperty(this, "_input", {
|
|
244
|
+
enumerable: !0,
|
|
245
|
+
configurable: !0,
|
|
246
|
+
writable: !0,
|
|
247
|
+
value: void 0
|
|
248
|
+
}), Object.defineProperty(this, "_options", {
|
|
249
|
+
enumerable: !0,
|
|
250
|
+
configurable: !0,
|
|
251
|
+
writable: !0,
|
|
252
|
+
value: void 0
|
|
253
|
+
}), this._input = t, this._options = {
|
|
254
|
+
// TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208
|
|
255
|
+
credentials: this._input.credentials || "same-origin",
|
|
256
|
+
...n,
|
|
257
|
+
headers: Ae(this._input.headers, n.headers),
|
|
258
|
+
hooks: se({
|
|
259
|
+
beforeRequest: [],
|
|
260
|
+
beforeRetry: [],
|
|
261
|
+
beforeError: [],
|
|
262
|
+
afterResponse: []
|
|
263
|
+
}, n.hooks),
|
|
264
|
+
method: ke(n.method ?? this._input.method),
|
|
265
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
266
|
+
prefixUrl: String(n.prefixUrl || ""),
|
|
267
|
+
retry: Xe(n.retry),
|
|
268
|
+
throwHttpErrors: n.throwHttpErrors !== !1,
|
|
269
|
+
timeout: n.timeout ?? 1e4,
|
|
270
|
+
fetch: n.fetch ?? globalThis.fetch.bind(globalThis)
|
|
271
|
+
}, typeof this._input != "string" && !(this._input instanceof URL || this._input instanceof globalThis.Request))
|
|
272
|
+
throw new TypeError("`input` must be a string, URL, or Request");
|
|
273
|
+
if (this._options.prefixUrl && typeof this._input == "string") {
|
|
274
|
+
if (this._input.startsWith("/"))
|
|
275
|
+
throw new Error("`input` must not begin with a slash when using `prefixUrl`");
|
|
276
|
+
this._options.prefixUrl.endsWith("/") || (this._options.prefixUrl += "/"), this._input = this._options.prefixUrl + this._input;
|
|
277
|
+
}
|
|
278
|
+
if (Me) {
|
|
279
|
+
if (this.abortController = new globalThis.AbortController(), this._options.signal) {
|
|
280
|
+
const s = this._options.signal;
|
|
281
|
+
this._options.signal.addEventListener("abort", () => {
|
|
282
|
+
this.abortController.abort(s.reason);
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
this._options.signal = this.abortController.signal;
|
|
286
|
+
}
|
|
287
|
+
if ($e && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
|
|
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
|
+
}
|
|
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
|
+
}
|
|
293
|
+
_calculateRetryDelay(t) {
|
|
294
|
+
if (this._retryCount++, this._retryCount <= this._options.retry.limit && !(t instanceof Te)) {
|
|
295
|
+
if (t instanceof oe) {
|
|
296
|
+
if (!this._options.retry.statusCodes.includes(t.response.status))
|
|
297
|
+
return 0;
|
|
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
|
+
}
|
|
303
|
+
if (t.response.status === 413)
|
|
304
|
+
return 0;
|
|
305
|
+
}
|
|
306
|
+
const n = this._options.retry.delay(this._retryCount);
|
|
307
|
+
return Math.min(this._options.retry.backoffLimit, n);
|
|
308
|
+
}
|
|
309
|
+
return 0;
|
|
310
|
+
}
|
|
311
|
+
_decorateResponse(t) {
|
|
312
|
+
return this._options.parseJson && (t.json = async () => this._options.parseJson(await t.text())), t;
|
|
313
|
+
}
|
|
314
|
+
async _retry(t) {
|
|
315
|
+
try {
|
|
316
|
+
return await t();
|
|
317
|
+
} catch (n) {
|
|
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
|
+
request: this.request,
|
|
324
|
+
options: this._options,
|
|
325
|
+
error: n,
|
|
326
|
+
retryCount: this._retryCount
|
|
327
|
+
}) === Se)
|
|
328
|
+
return;
|
|
329
|
+
return this._retry(t);
|
|
330
|
+
}
|
|
331
|
+
throw n;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
async _fetch() {
|
|
335
|
+
for (const n of this._options.hooks.beforeRequest) {
|
|
336
|
+
const s = await n(this.request, this._options);
|
|
337
|
+
if (s instanceof Request) {
|
|
338
|
+
this.request = s;
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
if (s instanceof Response)
|
|
342
|
+
return s;
|
|
343
|
+
}
|
|
344
|
+
const t = Je(this.request, this._options);
|
|
345
|
+
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Ye(this.request.clone(), t, this.abortController, this._options);
|
|
346
|
+
}
|
|
347
|
+
/* istanbul ignore next */
|
|
348
|
+
_stream(t, n) {
|
|
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
|
+
status: t.status,
|
|
353
|
+
statusText: t.statusText,
|
|
354
|
+
headers: t.headers
|
|
355
|
+
})) : new globalThis.Response(new globalThis.ReadableStream({
|
|
356
|
+
async start(i) {
|
|
357
|
+
const o = t.body.getReader();
|
|
358
|
+
n && n({ percent: 0, transferredBytes: 0, totalBytes: s }, new Uint8Array());
|
|
359
|
+
async function l() {
|
|
360
|
+
const { done: c, value: _ } = await o.read();
|
|
361
|
+
if (c) {
|
|
362
|
+
i.close();
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
if (n) {
|
|
366
|
+
r += _.byteLength;
|
|
367
|
+
const h = s === 0 ? 0 : r / s;
|
|
368
|
+
n({ percent: h, transferredBytes: r, totalBytes: s }, _);
|
|
369
|
+
}
|
|
370
|
+
i.enqueue(_), await l();
|
|
371
|
+
}
|
|
372
|
+
await l();
|
|
373
|
+
}
|
|
374
|
+
}), {
|
|
375
|
+
status: t.status,
|
|
376
|
+
statusText: t.statusText,
|
|
377
|
+
headers: t.headers
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
/*! MIT License © Sindre Sorhus */
|
|
382
|
+
const Q = (e) => {
|
|
383
|
+
const t = (n, s) => x.create(n, v(e, s));
|
|
384
|
+
for (const n of pe)
|
|
385
|
+
t[n] = (s, r) => x.create(s, v(e, r, { method: n }));
|
|
386
|
+
return t.create = (n) => Q(v(n)), t.extend = (n) => Q(v(e, n)), t.stop = Se, t;
|
|
387
|
+
}, Ee = Q();
|
|
388
|
+
let H;
|
|
389
|
+
const m = {
|
|
390
|
+
CachedPrices: `${R.ThorswapApi}/tokenlist/cached-price`,
|
|
391
|
+
GasRates: `${R.ThorswapApi}/resource-worker/gasPrice/getAll`,
|
|
392
|
+
Quote: `${R.ThorswapApi}/aggregator/tokens/quote`,
|
|
393
|
+
Txn: `${R.ThorswapApi}/apiusage/v2/txn`,
|
|
394
|
+
TokenlistProviders: `${R.ThorswapApi}/tokenlist/providers`,
|
|
395
|
+
TokenList: `${R.ThorswapStatic}/token-list`,
|
|
396
|
+
Thorname: `${R.ThorswapApi}/thorname`
|
|
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
|
+
H = Ee.create({
|
|
399
|
+
...t,
|
|
400
|
+
headers: { ...Re, ...t.headers, "x-api-key": e }
|
|
401
|
+
});
|
|
402
|
+
}, S = {
|
|
403
|
+
get: (e, t) => le().get(e, t).json(),
|
|
404
|
+
post: (e, t) => le().post(e, t).json()
|
|
405
|
+
}, Qe = ({ tokens: e, ...t }) => {
|
|
406
|
+
const n = new URLSearchParams();
|
|
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
|
+
body: n.toString(),
|
|
409
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" }
|
|
410
|
+
});
|
|
411
|
+
}, Et = {
|
|
412
|
+
getCachedPrices: Qe,
|
|
413
|
+
getQuote: (e) => S.get(m.Quote, { searchParams: e }),
|
|
414
|
+
getGasRates: () => S.get(m.GasRates),
|
|
415
|
+
getTxnDetails: (e) => S.get(m.Txn, { searchParams: e }),
|
|
416
|
+
getTokenlistProviders: () => S.get(m.TokenlistProviders),
|
|
417
|
+
getTokenList: (e) => S.get(`${m.TokenList}/${e}.json`),
|
|
418
|
+
getThornameAddresses: (e) => S.get(`${m.Thorname}/${e}`),
|
|
419
|
+
getThornameRegisteredChains: (e) => S.get(`${m.Thorname}/chains/${e}`),
|
|
420
|
+
getThornameRlookup: (e, t) => S.get(`${m.Thorname}/rlookup`, { searchParams: { address: e, chain: t } })
|
|
421
|
+
};
|
|
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
|
+
const tt = "0x313ce567", Ie = async ({ chain: e, to: t }) => {
|
|
424
|
+
try {
|
|
425
|
+
const { result: n } = await S.post(Le[e], {
|
|
426
|
+
headers: {
|
|
427
|
+
accept: "*/*",
|
|
428
|
+
"content-type": "application/json",
|
|
429
|
+
"cache-control": "no-cache"
|
|
430
|
+
},
|
|
431
|
+
body: JSON.stringify({
|
|
432
|
+
id: 44,
|
|
433
|
+
jsonrpc: "2.0",
|
|
434
|
+
method: "eth_call",
|
|
435
|
+
params: [{ to: t.toLowerCase(), data: tt }, "latest"]
|
|
436
|
+
})
|
|
437
|
+
});
|
|
438
|
+
return parseInt(BigInt(n).toString());
|
|
439
|
+
} catch (n) {
|
|
440
|
+
return console.error(n), d[e];
|
|
441
|
+
}
|
|
442
|
+
}, nt = async (e) => {
|
|
443
|
+
if (e === a.Ethereum)
|
|
444
|
+
return d.ETH;
|
|
445
|
+
const [, t] = e.split("-");
|
|
446
|
+
return t != null && t.startsWith("0x") ? Ie({ chain: a.Ethereum, to: t }) : d.ETH;
|
|
447
|
+
}, st = async (e) => {
|
|
448
|
+
const [, t] = e.split("-");
|
|
449
|
+
return t != null && t.startsWith("0x") ? Ie({ chain: a.Avalanche, to: t.toLowerCase() }) : d.AVAX;
|
|
450
|
+
}, rt = async (e) => e === a.BinanceSmartChain ? d.BSC : d.BSC, it = async ({ chain: e, symbol: t }) => {
|
|
451
|
+
switch (e) {
|
|
452
|
+
case a.Ethereum:
|
|
453
|
+
return nt(t);
|
|
454
|
+
case a.Avalanche:
|
|
455
|
+
return st(t);
|
|
456
|
+
case a.BinanceSmartChain:
|
|
457
|
+
return rt(t);
|
|
458
|
+
default:
|
|
459
|
+
return d[e];
|
|
460
|
+
}
|
|
461
|
+
}, Rt = {
|
|
462
|
+
[Y.Average]: 1.2,
|
|
463
|
+
[Y.Fast]: 1.5,
|
|
464
|
+
[Y.Fastest]: 2
|
|
465
|
+
}, fe = ({ chain: e, symbol: t }) => {
|
|
466
|
+
switch (e) {
|
|
467
|
+
case a.Bitcoin:
|
|
468
|
+
case a.BitcoinCash:
|
|
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:
|
|
479
|
+
return t === "ETH";
|
|
480
|
+
case a.Maya:
|
|
481
|
+
return t === "CACAO";
|
|
482
|
+
case a.Kujira:
|
|
483
|
+
return t === "KUJI";
|
|
484
|
+
case a.Cosmos:
|
|
485
|
+
return t === "ATOM";
|
|
486
|
+
case a.Polygon:
|
|
487
|
+
return t === "MATIC";
|
|
488
|
+
case a.BinanceSmartChain:
|
|
489
|
+
return t === "BNB";
|
|
490
|
+
case a.THORChain:
|
|
491
|
+
return t === "RUNE";
|
|
492
|
+
}
|
|
493
|
+
}, at = (e) => {
|
|
494
|
+
switch (e) {
|
|
495
|
+
case `${a.Ethereum}.THOR`:
|
|
496
|
+
return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
|
|
497
|
+
case `${a.Ethereum}.vTHOR`:
|
|
498
|
+
return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
|
|
499
|
+
case a.Cosmos:
|
|
500
|
+
return { identifier: "GAIA.ATOM", decimal: d[e] };
|
|
501
|
+
case a.THORChain:
|
|
502
|
+
return { identifier: "THOR.RUNE", decimal: d[e] };
|
|
503
|
+
case a.BinanceSmartChain:
|
|
504
|
+
return { identifier: "BSC.BNB", decimal: d[e] };
|
|
505
|
+
case a.Maya:
|
|
506
|
+
return { identifier: "MAYA.CACAO", decimal: d.MAYA };
|
|
507
|
+
case `${a.Maya}.MAYA`:
|
|
508
|
+
return { identifier: "MAYA.MAYA", decimal: 4 };
|
|
509
|
+
case `${a.Kujira}.USK`:
|
|
510
|
+
return { identifier: `${a.Kujira}.USK`, decimal: 6 };
|
|
511
|
+
case a.Kujira:
|
|
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:
|
|
524
|
+
return { identifier: `${e}.${e}`, decimal: d[e] };
|
|
525
|
+
}
|
|
526
|
+
}, ot = ({ chain: e, symbol: t }) => {
|
|
527
|
+
if (t.includes("/"))
|
|
528
|
+
return "Synth";
|
|
529
|
+
switch (e) {
|
|
530
|
+
case a.Bitcoin:
|
|
531
|
+
case a.BitcoinCash:
|
|
532
|
+
case a.Dogecoin:
|
|
533
|
+
case a.Litecoin:
|
|
534
|
+
case a.Maya:
|
|
535
|
+
case a.THORChain:
|
|
536
|
+
case a.Polkadot:
|
|
537
|
+
case a.Chainflip:
|
|
538
|
+
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
|
+
}
|
|
558
|
+
}, It = (e) => {
|
|
559
|
+
var o;
|
|
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 };
|
|
562
|
+
}, ct = new RegExp(
|
|
563
|
+
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
|
|
564
|
+
"gmi"
|
|
565
|
+
), lt = (e) => {
|
|
566
|
+
const [t, n] = e.split(".");
|
|
567
|
+
if (!Be.includes(t))
|
|
568
|
+
return !0;
|
|
569
|
+
const [, s] = n.split("-");
|
|
570
|
+
return fe({ chain: t, symbol: n }) || !!s;
|
|
571
|
+
}, ft = (e) => e.filter((t) => {
|
|
572
|
+
const n = `${t.chain}.${t.symbol}`;
|
|
573
|
+
return !ct.test(n) && lt(n) && t.value !== "0";
|
|
574
|
+
});
|
|
575
|
+
function ut({
|
|
576
|
+
liquidityUnits: e,
|
|
577
|
+
poolUnits: t,
|
|
578
|
+
runeDepth: n
|
|
579
|
+
}) {
|
|
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);
|
|
582
|
+
}
|
|
583
|
+
function _t({
|
|
584
|
+
liquidityUnits: e,
|
|
585
|
+
poolUnits: t,
|
|
586
|
+
assetDepth: n
|
|
587
|
+
}) {
|
|
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);
|
|
589
|
+
return h.div(P);
|
|
590
|
+
}
|
|
591
|
+
function Ct({
|
|
592
|
+
percent: e,
|
|
593
|
+
runeDepth: t,
|
|
594
|
+
liquidityUnits: n,
|
|
595
|
+
poolUnits: s
|
|
596
|
+
}) {
|
|
597
|
+
return ut({ runeDepth: t, liquidityUnits: n, poolUnits: s }).mul(e);
|
|
598
|
+
}
|
|
599
|
+
function Nt({
|
|
600
|
+
percent: e,
|
|
601
|
+
assetDepth: t,
|
|
602
|
+
liquidityUnits: n,
|
|
603
|
+
poolUnits: s
|
|
604
|
+
}) {
|
|
605
|
+
return _t({ assetDepth: t, liquidityUnits: n, poolUnits: s }).mul(e);
|
|
606
|
+
}
|
|
607
|
+
function A(e) {
|
|
608
|
+
return I.fromBigInt(BigInt(e), d.THOR);
|
|
609
|
+
}
|
|
610
|
+
function ht({
|
|
611
|
+
liquidityUnits: e,
|
|
612
|
+
poolUnits: t,
|
|
613
|
+
runeDepth: n,
|
|
614
|
+
assetDepth: s
|
|
615
|
+
}) {
|
|
616
|
+
return {
|
|
617
|
+
assetAmount: A(s).mul(e).div(t),
|
|
618
|
+
runeAmount: A(n).mul(e).div(t)
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
function gt({
|
|
622
|
+
liquidityUnits: e,
|
|
623
|
+
poolUnits: t,
|
|
624
|
+
runeDepth: n,
|
|
625
|
+
assetDepth: s,
|
|
626
|
+
percent: r
|
|
627
|
+
}) {
|
|
628
|
+
return Object.fromEntries(
|
|
629
|
+
Object.entries(ht({ liquidityUnits: e, poolUnits: t, runeDepth: n, assetDepth: s })).map(
|
|
630
|
+
([i, o]) => [i, o.mul(r)]
|
|
631
|
+
)
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
function Ot({
|
|
635
|
+
runeDepth: e,
|
|
636
|
+
poolUnits: t,
|
|
637
|
+
assetDepth: n,
|
|
638
|
+
liquidityUnits: s,
|
|
639
|
+
runeAmount: r,
|
|
640
|
+
assetAmount: i
|
|
641
|
+
}) {
|
|
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);
|
|
643
|
+
if (ae.getBaseValue("number") === 0)
|
|
644
|
+
return X.div(c).getBaseValue("number");
|
|
645
|
+
const be = c.add(X);
|
|
646
|
+
return X.div(be).getBaseValue("number");
|
|
647
|
+
}
|
|
648
|
+
function Dt({
|
|
649
|
+
runeAmount: e,
|
|
650
|
+
assetAmount: t,
|
|
651
|
+
runeDepth: n,
|
|
652
|
+
assetDepth: s
|
|
653
|
+
}) {
|
|
654
|
+
if (e === "0" || t === "0" || n === "0" || s === "0")
|
|
655
|
+
return 0;
|
|
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));
|
|
657
|
+
return Math.abs(c.div(_).getBaseValue("number"));
|
|
658
|
+
}
|
|
659
|
+
const Pt = (e, t) => {
|
|
660
|
+
switch (e) {
|
|
661
|
+
case E.LEAVE:
|
|
662
|
+
case E.BOND: {
|
|
663
|
+
const { address: n } = t;
|
|
664
|
+
return `${e}:${n}`;
|
|
665
|
+
}
|
|
666
|
+
case E.UNBOND: {
|
|
667
|
+
const { address: n, unbondAmount: s } = t;
|
|
668
|
+
return `${e}:${n}:${s}`;
|
|
669
|
+
}
|
|
670
|
+
case E.THORNAME_REGISTER: {
|
|
671
|
+
const { name: n, chain: s, address: r, owner: i } = t;
|
|
672
|
+
return `${e}:${n}:${s}:${r}${i ? `:${i}` : ""}`;
|
|
673
|
+
}
|
|
674
|
+
case E.DEPOSIT: {
|
|
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) {
|
|
678
|
+
case a.Litecoin:
|
|
679
|
+
return "l";
|
|
680
|
+
case a.Dogecoin:
|
|
681
|
+
return "d";
|
|
682
|
+
case a.BitcoinCash:
|
|
683
|
+
return "c";
|
|
684
|
+
default:
|
|
685
|
+
return `${l}.${c}`;
|
|
686
|
+
}
|
|
687
|
+
})(n, s)}:${r || ""}:t:0`;
|
|
688
|
+
}
|
|
689
|
+
case E.WITHDRAW: {
|
|
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}${_}`;
|
|
692
|
+
}
|
|
693
|
+
case E.OPEN_LOAN:
|
|
694
|
+
case E.CLOSE_LOAN: {
|
|
695
|
+
const { asset: n, address: s } = t;
|
|
696
|
+
return `${e}:${n}:${s}`;
|
|
697
|
+
}
|
|
698
|
+
default:
|
|
699
|
+
return "";
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
function bt(e) {
|
|
703
|
+
if (e < 0)
|
|
704
|
+
throw new Error("Invalid number of year");
|
|
705
|
+
return 10 + e;
|
|
706
|
+
}
|
|
707
|
+
function yt(e) {
|
|
708
|
+
if (e.length > 30)
|
|
709
|
+
return !1;
|
|
710
|
+
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
711
|
+
return !!e.match(t);
|
|
712
|
+
}
|
|
713
|
+
function wt([e, t, n, s, r]) {
|
|
714
|
+
return `${e}'/${t}'/${n}'/${s}${typeof r != "number" ? "" : `/${r}`}`;
|
|
715
|
+
}
|
|
716
|
+
const ue = [...Object.values(a), "TERRA"];
|
|
717
|
+
function dt(e = "") {
|
|
718
|
+
const t = e.toUpperCase(), [n] = t.split(".");
|
|
719
|
+
if (ue.includes(n))
|
|
720
|
+
return !0;
|
|
721
|
+
const [s] = t.split("/");
|
|
722
|
+
if (ue.includes(s))
|
|
723
|
+
return !0;
|
|
724
|
+
throw new Error(
|
|
725
|
+
`Invalid identifier: ${e}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
726
|
+
);
|
|
727
|
+
}
|
|
728
|
+
const B = 8, C = (e) => 10n ** BigInt(e), b = (e) => Math.log10(parseFloat(e.toString()));
|
|
729
|
+
function G({
|
|
730
|
+
value: e,
|
|
731
|
+
bigIntDecimal: t = B,
|
|
732
|
+
decimal: n = B
|
|
733
|
+
}) {
|
|
734
|
+
if (n === 0)
|
|
735
|
+
return e.toString();
|
|
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(
|
|
743
|
+
/\.?0*$/,
|
|
744
|
+
""
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
var N, y, f, D, k, Ce, L, z, U, Z;
|
|
748
|
+
const re = class re {
|
|
749
|
+
constructor(t) {
|
|
750
|
+
O(this, N);
|
|
751
|
+
O(this, f);
|
|
752
|
+
O(this, k);
|
|
753
|
+
O(this, L);
|
|
754
|
+
O(this, U);
|
|
755
|
+
p(this, "decimalMultiplier", 10n ** 8n);
|
|
756
|
+
p(this, "bigIntValue", 0n);
|
|
757
|
+
p(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);
|
|
760
|
+
}
|
|
761
|
+
static fromBigInt(t, n) {
|
|
762
|
+
return new re({
|
|
763
|
+
decimal: n,
|
|
764
|
+
value: G({ value: t, bigIntDecimal: n, decimal: n })
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
static shiftDecimals({
|
|
768
|
+
value: t,
|
|
769
|
+
from: n,
|
|
770
|
+
to: s
|
|
771
|
+
}) {
|
|
772
|
+
return this.fromBigInt(
|
|
773
|
+
t.getBaseValue("bigint") * C(s) / C(n),
|
|
774
|
+
s
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
set(t) {
|
|
778
|
+
return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
|
|
779
|
+
}
|
|
780
|
+
add(...t) {
|
|
781
|
+
return T(this, N, y).call(this, "add", ...t);
|
|
782
|
+
}
|
|
783
|
+
sub(...t) {
|
|
784
|
+
return T(this, N, y).call(this, "sub", ...t);
|
|
785
|
+
}
|
|
786
|
+
mul(...t) {
|
|
787
|
+
return T(this, N, y).call(this, "mul", ...t);
|
|
788
|
+
}
|
|
789
|
+
div(...t) {
|
|
790
|
+
return T(this, N, y).call(this, "div", ...t);
|
|
791
|
+
}
|
|
792
|
+
gt(t) {
|
|
793
|
+
return T(this, f, D).call(this, "gt", t);
|
|
794
|
+
}
|
|
795
|
+
gte(t) {
|
|
796
|
+
return T(this, f, D).call(this, "gte", t);
|
|
797
|
+
}
|
|
798
|
+
lt(t) {
|
|
799
|
+
return T(this, f, D).call(this, "lt", t);
|
|
800
|
+
}
|
|
801
|
+
lte(t) {
|
|
802
|
+
return T(this, f, D).call(this, "lte", t);
|
|
803
|
+
}
|
|
804
|
+
eqValue(t) {
|
|
805
|
+
return T(this, f, D).call(this, "eqValue", t);
|
|
806
|
+
}
|
|
807
|
+
// @ts-expect-error False positive
|
|
808
|
+
getValue(t) {
|
|
809
|
+
const n = this.formatBigIntToSafeValue(
|
|
810
|
+
this.bigIntValue,
|
|
811
|
+
this.decimal || b(this.decimalMultiplier)
|
|
812
|
+
);
|
|
813
|
+
switch (t) {
|
|
814
|
+
case "number":
|
|
815
|
+
return Number(n);
|
|
816
|
+
case "string":
|
|
817
|
+
return n;
|
|
818
|
+
case "bigint":
|
|
819
|
+
return this.bigIntValue * 10n ** BigInt(this.decimal || 8n) / this.decimalMultiplier;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
// @ts-expect-error
|
|
823
|
+
getBaseValue(t) {
|
|
824
|
+
const n = this.decimalMultiplier / C(this.decimal || d.THOR), s = this.bigIntValue / n;
|
|
825
|
+
switch (t) {
|
|
826
|
+
case "number":
|
|
827
|
+
return Number(s);
|
|
828
|
+
case "string":
|
|
829
|
+
return s.toString();
|
|
830
|
+
case "bigint":
|
|
831
|
+
return s;
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
getBigIntValue(t, n) {
|
|
835
|
+
if (!n && typeof t == "object")
|
|
836
|
+
return t.bigIntValue;
|
|
837
|
+
const s = ee(t), r = $(s);
|
|
838
|
+
return r === "0" || r === "undefined" ? 0n : T(this, U, Z).call(this, r, n);
|
|
839
|
+
}
|
|
840
|
+
toSignificant(t = 6) {
|
|
841
|
+
const [n, s] = this.getValue("string").split("."), r = n || "", i = s || "";
|
|
842
|
+
if ((parseInt(r) ? r.length + i.length : i.length) <= t)
|
|
843
|
+
return this.getValue("string");
|
|
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,
|
|
849
|
+
"0"
|
|
850
|
+
);
|
|
851
|
+
const l = parseInt(i), c = `${l}`.slice(0, t);
|
|
852
|
+
return `0.${c.padStart(
|
|
853
|
+
i.length - `${l}`.length + c.length,
|
|
854
|
+
"0"
|
|
855
|
+
)}`;
|
|
856
|
+
}
|
|
857
|
+
toFixed(t = 6) {
|
|
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,
|
|
864
|
+
"0"
|
|
865
|
+
)}`;
|
|
866
|
+
}
|
|
867
|
+
toAbbreviation(t = 2) {
|
|
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];
|
|
869
|
+
if (!i)
|
|
870
|
+
return this.getValue("string");
|
|
871
|
+
const o = 10 ** (r * 3);
|
|
872
|
+
return `${(n / o).toFixed(t)}${i}`;
|
|
873
|
+
}
|
|
874
|
+
toCurrency(t = "$", {
|
|
875
|
+
currencyPosition: n = "start",
|
|
876
|
+
decimal: s = 2,
|
|
877
|
+
decimalSeparator: r = ".",
|
|
878
|
+
thousandSeparator: i = ","
|
|
879
|
+
} = {}) {
|
|
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)}` : ""}`;
|
|
881
|
+
return `${n === "start" ? t : ""}${h}${n === "end" ? t : ""}`;
|
|
882
|
+
}
|
|
883
|
+
formatBigIntToSafeValue(t, n) {
|
|
884
|
+
const s = n || this.decimal || B, r = Math.max(
|
|
885
|
+
s,
|
|
886
|
+
b(this.decimalMultiplier)
|
|
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(
|
|
890
|
+
0,
|
|
891
|
+
_
|
|
892
|
+
)}.${h}`.replace(/\.?0*$/, "");
|
|
893
|
+
}
|
|
894
|
+
};
|
|
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(
|
|
897
|
+
(c, _) => {
|
|
898
|
+
const h = this.getBigIntValue(_, r);
|
|
899
|
+
switch (t) {
|
|
900
|
+
case "add":
|
|
901
|
+
return c + h;
|
|
902
|
+
case "sub":
|
|
903
|
+
return c - h;
|
|
904
|
+
case "mul":
|
|
905
|
+
return c * h / i;
|
|
906
|
+
case "div": {
|
|
907
|
+
if (h === 0n)
|
|
908
|
+
throw new RangeError("Division by zero");
|
|
909
|
+
return c * i / h;
|
|
910
|
+
}
|
|
911
|
+
default:
|
|
912
|
+
return c;
|
|
913
|
+
}
|
|
914
|
+
},
|
|
915
|
+
//normalize is to precision multiplier base
|
|
916
|
+
this.bigIntValue * i / this.decimalMultiplier
|
|
917
|
+
), l = G({
|
|
918
|
+
bigIntDecimal: r,
|
|
919
|
+
decimal: r,
|
|
920
|
+
value: o
|
|
921
|
+
});
|
|
922
|
+
return new this.constructor({
|
|
923
|
+
decimalMultiplier: C(r),
|
|
924
|
+
decimal: this.decimal,
|
|
925
|
+
value: l,
|
|
926
|
+
identifier: this.toString()
|
|
927
|
+
});
|
|
928
|
+
}, f = new WeakSet(), D = function(t, ...n) {
|
|
929
|
+
const s = T(this, L, z).call(this, this, ...n), r = this.getBigIntValue(n[0], s), i = this.getBigIntValue(this, s);
|
|
930
|
+
switch (t) {
|
|
931
|
+
case "gt":
|
|
932
|
+
return i > r;
|
|
933
|
+
case "gte":
|
|
934
|
+
return i >= r;
|
|
935
|
+
case "lt":
|
|
936
|
+
return i < r;
|
|
937
|
+
case "lte":
|
|
938
|
+
return i <= r;
|
|
939
|
+
case "eqValue":
|
|
940
|
+
return i === r;
|
|
941
|
+
}
|
|
942
|
+
}, k = new WeakSet(), Ce = function(t) {
|
|
943
|
+
const n = $(t) || "0";
|
|
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);
|
|
947
|
+
return Math.max(...n, B);
|
|
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")}`);
|
|
951
|
+
};
|
|
952
|
+
let W = re;
|
|
953
|
+
const Tt = Intl.NumberFormat("fullwide", {
|
|
954
|
+
useGrouping: !1,
|
|
955
|
+
maximumFractionDigits: 20
|
|
956
|
+
});
|
|
957
|
+
function $(e) {
|
|
958
|
+
const n = `${typeof e == "number" ? Tt.format(e) : ee(e)}`.replaceAll(",", ".").split(".");
|
|
959
|
+
return n.length > 1 ? `${n.slice(0, -1).join("")}.${n.at(-1)}` : n[0];
|
|
960
|
+
}
|
|
961
|
+
function _e(e) {
|
|
962
|
+
var n;
|
|
963
|
+
const t = ((n = e.split(".")[1]) == null ? void 0 : n.length) || 0;
|
|
964
|
+
return Math.max(t, B);
|
|
965
|
+
}
|
|
966
|
+
function ee(e) {
|
|
967
|
+
return typeof e == "object" ? "getValue" in e ? e.getValue("string") : e.value : e;
|
|
968
|
+
}
|
|
969
|
+
const w = /* @__PURE__ */ new Map();
|
|
970
|
+
class g extends W {
|
|
971
|
+
constructor({
|
|
972
|
+
value: n,
|
|
973
|
+
decimal: s,
|
|
974
|
+
tax: r,
|
|
975
|
+
chain: i,
|
|
976
|
+
symbol: o,
|
|
977
|
+
identifier: l
|
|
978
|
+
}) {
|
|
979
|
+
super(typeof n == "object" ? n : { decimal: s, value: n });
|
|
980
|
+
p(this, "address");
|
|
981
|
+
p(this, "chain");
|
|
982
|
+
p(this, "isGasAsset", !1);
|
|
983
|
+
p(this, "isSynthetic", !1);
|
|
984
|
+
p(this, "symbol");
|
|
985
|
+
p(this, "tax");
|
|
986
|
+
p(this, "ticker");
|
|
987
|
+
p(this, "type");
|
|
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;
|
|
990
|
+
}
|
|
991
|
+
toString() {
|
|
992
|
+
return this.isSynthetic ? this.symbol : `${this.chain}.${this.symbol}`;
|
|
993
|
+
}
|
|
994
|
+
toUrl() {
|
|
995
|
+
return this.isSynthetic ? `${this.chain}.${this.symbol.replace("/", ".")}` : this.toString();
|
|
996
|
+
}
|
|
997
|
+
eq({ chain: n, symbol: s }) {
|
|
998
|
+
return this.chain === n && this.symbol === s;
|
|
999
|
+
}
|
|
1000
|
+
chainId() {
|
|
1001
|
+
return Ue[this.chain];
|
|
1002
|
+
}
|
|
1003
|
+
// THOR.RUNE
|
|
1004
|
+
// THOR.ETH.ETH
|
|
1005
|
+
// ETH.THOR-0x1234567890
|
|
1006
|
+
static fromUrl(n, s = 0) {
|
|
1007
|
+
const [r, i, o] = n.split(".");
|
|
1008
|
+
if (!r || !i)
|
|
1009
|
+
throw new Error("Invalid asset url");
|
|
1010
|
+
const l = r === a.THORChain && o ? `${r}.${i}/${o}` : n;
|
|
1011
|
+
return J(l, s);
|
|
1012
|
+
}
|
|
1013
|
+
static fromString(n, s = 0) {
|
|
1014
|
+
return J(n, s);
|
|
1015
|
+
}
|
|
1016
|
+
static fromIdentifier(n, s = 0) {
|
|
1017
|
+
return J(n, s);
|
|
1018
|
+
}
|
|
1019
|
+
static fromStringSync(n, s = 0) {
|
|
1020
|
+
const { chain: r, isSynthetic: i } = F(n), o = w.get(n.toUpperCase());
|
|
1021
|
+
if (i)
|
|
1022
|
+
return he(n, s);
|
|
1023
|
+
const { tax: l, decimal: c, identifier: _ } = o || {
|
|
1024
|
+
decimal: d[r],
|
|
1025
|
+
identifier: n
|
|
1026
|
+
};
|
|
1027
|
+
return new g({
|
|
1028
|
+
tax: l,
|
|
1029
|
+
value: V(s, c),
|
|
1030
|
+
identifier: i ? n : _,
|
|
1031
|
+
decimal: i ? 8 : c
|
|
1032
|
+
});
|
|
1033
|
+
}
|
|
1034
|
+
static fromIdentifierSync(n, s = 0) {
|
|
1035
|
+
const { chain: r, isSynthetic: i } = F(n), o = w.get(n);
|
|
1036
|
+
if (i)
|
|
1037
|
+
return he(n, s);
|
|
1038
|
+
const { tax: l, decimal: c, identifier: _ } = o || {
|
|
1039
|
+
decimal: d[r],
|
|
1040
|
+
identifier: n
|
|
1041
|
+
};
|
|
1042
|
+
return new g({ tax: l, decimal: c, identifier: _, value: V(s, c) });
|
|
1043
|
+
}
|
|
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 });
|
|
1047
|
+
}
|
|
1048
|
+
static loadStaticAssets() {
|
|
1049
|
+
return new Promise(
|
|
1050
|
+
async (n, s) => {
|
|
1051
|
+
try {
|
|
1052
|
+
const r = await import("@swapkit/tokens");
|
|
1053
|
+
Object.values(r).forEach((i) => {
|
|
1054
|
+
var o;
|
|
1055
|
+
(o = i == null ? void 0 : i.tokens) == null || o.forEach(({ identifier: l, chain: c, ..._ }) => {
|
|
1056
|
+
w.set(l.toUpperCase(), {
|
|
1057
|
+
identifier: l,
|
|
1058
|
+
decimal: "decimals" in _ ? _.decimals : d[c]
|
|
1059
|
+
});
|
|
1060
|
+
});
|
|
1061
|
+
}), n({ ok: !0 });
|
|
1062
|
+
} catch (r) {
|
|
1063
|
+
console.error(r), s({
|
|
1064
|
+
ok: !1,
|
|
1065
|
+
error: r,
|
|
1066
|
+
message: "Couldn't load static assets. Ensure you have installed @swapkit/tokens package"
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
function Vt(e) {
|
|
1074
|
+
const t = g.fromChainOrSignature(e);
|
|
1075
|
+
switch (e) {
|
|
1076
|
+
case a.Bitcoin:
|
|
1077
|
+
case a.Litecoin:
|
|
1078
|
+
case a.BitcoinCash:
|
|
1079
|
+
return t.set(10001e-8);
|
|
1080
|
+
case a.Dogecoin:
|
|
1081
|
+
return t.set(1.00000001);
|
|
1082
|
+
case a.Avalanche:
|
|
1083
|
+
case a.Ethereum:
|
|
1084
|
+
return t.set(1e-8);
|
|
1085
|
+
case a.THORChain:
|
|
1086
|
+
case a.Maya:
|
|
1087
|
+
return t.set(0);
|
|
1088
|
+
case a.Cosmos:
|
|
1089
|
+
return t.set(1e-6);
|
|
1090
|
+
default:
|
|
1091
|
+
return t.set(1e-8);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
async function J(e, t = 0) {
|
|
1095
|
+
dt(e);
|
|
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 });
|
|
1098
|
+
}
|
|
1099
|
+
function he(e, t = 0) {
|
|
1100
|
+
const [n, s] = e.split(".")[0].toUpperCase() === a.THORChain ? e.split(".").slice(1).join().split("/") : e.split("/");
|
|
1101
|
+
if (!n || !s)
|
|
1102
|
+
throw new Error("Invalid asset identifier");
|
|
1103
|
+
return new g({
|
|
1104
|
+
decimal: 8,
|
|
1105
|
+
value: V(t, 8),
|
|
1106
|
+
identifier: `${a.THORChain}.${n}/${s}`
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
function V(e, t) {
|
|
1110
|
+
return typeof e == "bigint" ? G({ value: e, bigIntDecimal: t, decimal: t }) : e;
|
|
1111
|
+
}
|
|
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))
|
|
1115
|
+
throw new Error("Invalid asset identifier");
|
|
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(".");
|
|
1117
|
+
return {
|
|
1118
|
+
address: c == null ? void 0 : c.toLowerCase(),
|
|
1119
|
+
chain: i,
|
|
1120
|
+
isGasAsset: fe({ chain: i, symbol: _ }),
|
|
1121
|
+
isSynthetic: t,
|
|
1122
|
+
symbol: (t ? `${n}/` : "") + (c ? `${l}-${(c == null ? void 0 : c.toLowerCase()) ?? ""}` : _),
|
|
1123
|
+
ticker: l
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
const At = {
|
|
1127
|
+
/**
|
|
1128
|
+
* Core
|
|
1129
|
+
*/
|
|
1130
|
+
core_wallet_connection_not_found: 10001,
|
|
1131
|
+
core_estimated_max_spendable_chain_not_supported: 10002,
|
|
1132
|
+
core_extend_error: 10003,
|
|
1133
|
+
core_inbound_data_not_found: 10004,
|
|
1134
|
+
core_approve_asset_address_or_from_not_found: 10005,
|
|
1135
|
+
core_chain_halted: 10099,
|
|
1136
|
+
/**
|
|
1137
|
+
* Core - Wallet Connection
|
|
1138
|
+
*/
|
|
1139
|
+
core_wallet_xdefi_not_installed: 10101,
|
|
1140
|
+
core_wallet_evmwallet_not_installed: 10102,
|
|
1141
|
+
core_wallet_walletconnect_not_installed: 10103,
|
|
1142
|
+
core_wallet_keystore_not_installed: 10104,
|
|
1143
|
+
core_wallet_ledger_not_installed: 10105,
|
|
1144
|
+
core_wallet_trezor_not_installed: 10106,
|
|
1145
|
+
core_wallet_keplr_not_installed: 10107,
|
|
1146
|
+
core_wallet_okx_not_installed: 10108,
|
|
1147
|
+
core_wallet_keepkey_not_installed: 10109,
|
|
1148
|
+
/**
|
|
1149
|
+
* Core - Swap
|
|
1150
|
+
*/
|
|
1151
|
+
core_swap_invalid_params: 10200,
|
|
1152
|
+
core_swap_route_not_complete: 10201,
|
|
1153
|
+
core_swap_asset_not_recognized: 10202,
|
|
1154
|
+
core_swap_contract_not_found: 10203,
|
|
1155
|
+
core_swap_route_transaction_not_found: 10204,
|
|
1156
|
+
core_swap_contract_not_supported: 10205,
|
|
1157
|
+
core_swap_transaction_error: 10206,
|
|
1158
|
+
core_swap_quote_mode_not_supported: 10207,
|
|
1159
|
+
/**
|
|
1160
|
+
* Core - Transaction
|
|
1161
|
+
*/
|
|
1162
|
+
core_transaction_deposit_error: 10301,
|
|
1163
|
+
core_transaction_create_liquidity_rune_error: 10302,
|
|
1164
|
+
core_transaction_create_liquidity_asset_error: 10303,
|
|
1165
|
+
core_transaction_create_liquidity_invalid_params: 10304,
|
|
1166
|
+
core_transaction_add_liquidity_invalid_params: 10305,
|
|
1167
|
+
core_transaction_add_liquidity_no_rune_address: 10306,
|
|
1168
|
+
core_transaction_add_liquidity_rune_error: 10307,
|
|
1169
|
+
core_transaction_add_liquidity_asset_error: 10308,
|
|
1170
|
+
core_transaction_withdraw_error: 10309,
|
|
1171
|
+
core_transaction_deposit_to_pool_error: 10310,
|
|
1172
|
+
core_transaction_deposit_insufficient_funds_error: 10311,
|
|
1173
|
+
core_transaction_deposit_gas_error: 10312,
|
|
1174
|
+
core_transaction_invalid_sender_address: 10313,
|
|
1175
|
+
core_transaction_deposit_server_error: 10314,
|
|
1176
|
+
core_transaction_user_rejected: 10315,
|
|
1177
|
+
/**
|
|
1178
|
+
* Wallets
|
|
1179
|
+
*/
|
|
1180
|
+
wallet_ledger_connection_error: 20001,
|
|
1181
|
+
wallet_ledger_connection_claimed: 20002,
|
|
1182
|
+
wallet_ledger_get_address_error: 20003,
|
|
1183
|
+
wallet_ledger_device_not_found: 20004,
|
|
1184
|
+
wallet_ledger_device_locked: 20005,
|
|
1185
|
+
/**
|
|
1186
|
+
* Helpers
|
|
1187
|
+
*/
|
|
1188
|
+
helpers_number_different_decimals: 99101
|
|
1189
|
+
};
|
|
1190
|
+
class Ne extends Error {
|
|
1191
|
+
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, Ne.prototype);
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
class I extends W {
|
|
1196
|
+
eq(t) {
|
|
1197
|
+
return this.eqValue(t);
|
|
1198
|
+
}
|
|
1199
|
+
static fromBigInt(t, n) {
|
|
1200
|
+
return new I({
|
|
1201
|
+
decimal: n,
|
|
1202
|
+
value: G({ value: t, bigIntDecimal: n, decimal: n })
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
export {
|
|
1207
|
+
m as ApiEndpoints,
|
|
1208
|
+
g as AssetValue,
|
|
1209
|
+
W as BigIntArithmetics,
|
|
1210
|
+
S as RequestClient,
|
|
1211
|
+
et as StreamingSwapProgressStatus,
|
|
1212
|
+
Et as SwapKitApi,
|
|
1213
|
+
Ne as SwapKitError,
|
|
1214
|
+
I as SwapKitNumber,
|
|
1215
|
+
ze as TransactionType,
|
|
1216
|
+
Ze as TxStatus,
|
|
1217
|
+
It as assetFromString,
|
|
1218
|
+
Re as defaultRequestHeaders,
|
|
1219
|
+
wt as derivationPathToString,
|
|
1220
|
+
ft as filterAssets,
|
|
1221
|
+
G as formatBigIntToSafeValue,
|
|
1222
|
+
Rt as gasFeeMultiplier,
|
|
1223
|
+
ot as getAssetType,
|
|
1224
|
+
_t as getAsymmetricAssetShare,
|
|
1225
|
+
Nt as getAsymmetricAssetWithdrawAmount,
|
|
1226
|
+
ut as getAsymmetricRuneShare,
|
|
1227
|
+
Ct as getAsymmetricRuneWithdrawAmount,
|
|
1228
|
+
at as getCommonAssetInfo,
|
|
1229
|
+
it as getDecimal,
|
|
1230
|
+
Ot as getEstimatedPoolShare,
|
|
1231
|
+
Dt as getLiquiditySlippage,
|
|
1232
|
+
Pt as getMemoFor,
|
|
1233
|
+
Vt as getMinAmountByChain,
|
|
1234
|
+
ht as getSymmetricPoolShare,
|
|
1235
|
+
gt as getSymmetricWithdraw,
|
|
1236
|
+
bt as getTHORNameCost,
|
|
1237
|
+
fe as isGasAsset,
|
|
1238
|
+
mt as setRequestClientConfig,
|
|
1239
|
+
yt as validateTHORName
|
|
1240
|
+
};
|
|
1241
|
+
//# sourceMappingURL=index.es.js.map
|