@swapkit/helpers 1.0.0-rc.7 → 1.0.0-rc.70

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.es.js CHANGED
@@ -1,592 +1,1037 @@
1
- var nt = Object.defineProperty;
2
- var rt = (n, t, e) => t in n ? nt(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
- var _ = (n, t, e) => (rt(n, typeof t != "symbol" ? t + "" : t, e), e), st = (n, t, e) => {
4
- if (!t.has(n))
5
- throw TypeError("Cannot " + e);
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
6
  };
7
- var $ = (n, t, e) => {
8
- if (t.has(n))
7
+ var O = (e, t, n) => {
8
+ if (t.has(e))
9
9
  throw TypeError("Cannot add the same private member more than once");
10
- t instanceof WeakSet ? t.add(n) : t.set(n, e);
10
+ t instanceof WeakSet ? t.add(e) : t.set(e, n);
11
11
  };
12
- var g = (n, t, e) => (st(n, t, "access private method"), e);
13
- import { FeeOption as H, BaseDecimal as m, Chain as i, ChainToRPC as it, MemoType as p } from "@swapkit/types";
14
- const vt = (n) => {
15
- if (n < 0)
16
- throw new Error("Invalid number of year");
17
- return 10 + n;
18
- }, Vt = (n) => {
19
- if (n.length > 30)
20
- return !1;
21
- const t = /^[a-zA-Z0-9+_-]+$/g;
22
- return !!n.match(t);
23
- }, Ct = ([n, t, e, r, s]) => `${n}'/${t}'/${e}'/${r}${typeof s != "number" ? "" : `/${s}`}`, Tt = async (n, t) => {
24
- try {
25
- const e = Object.entries(t || {}).reduce(
26
- (s, [a, c]) => (c && (s[a] = c), s),
27
- {}
28
- );
29
- return (await fetch(
30
- `${n}${t ? `?${new URLSearchParams(e).toString()}` : ""}`,
31
- { method: "GET", mode: "cors", credentials: "omit", referrer: "https://sk.thorswap.net" }
32
- )).json();
33
- } catch (e) {
34
- return console.error(e), {};
35
- }
36
- }, at = async (n, t, e, r = !1) => {
37
- try {
38
- const s = await fetch(`${n}`, {
39
- body: t,
40
- headers: e,
41
- method: "POST",
42
- referrer: "https://sk.thorswap.net"
12
+ var T = (e, t, n) => (Ve(e, t, "access private method"), n);
13
+ import { FeeOption as Y, BaseDecimal as d, Chain as l, EVMChainList as Be, ChainToRPC as Ue, MemoType as E, ChainToChainId as Le } from "@swapkit/types";
14
+ var u = /* @__PURE__ */ ((e) => (e.INVALID_INPUT_PARAMETERS = "1000", e.UNKNOWN_PROVIDERS = "1001", e.CANNOT_FIND_INBOUND_ADDRESS = "1002", e.NO_INBOUND_ADDRESSES = "1003", e.CHAIN_HALTED_OR_UNSUPPORTED = "1004", e.MISSING_INPUT_PARAMETER = "1005", e.INVALID_TYPE_GENERIC = "1100", e.INVALID_NUMBER_STRING = "1101", e.INVALID_NUMBER = "1102", e.INVALID_BOOLEAN = "1103", e.INVALID_OBJECT = "1104", e.INVALID_ARRAY = "1105", e.SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER = "2000", e.SELL_BUY_ASSETS_ARE_THE_SAME = "2001", e.MISSING_SOURCE_ADDRESS_FOR_SYNTH = "2002", e.AFF_ADDRESS_AND_BPS_OR_NEITHER = "2003", e.AFF_ADDRESS_TOO_LONG = "2004", e.AFF_BPS_INTEGER_MAX_500 = "2005", e.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN = "2006", e.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN = "2007", e.PREFERRED_PROVIDER_NOT_SUPPORTED = "2008", e.DESTINATION_ADDRESS_SMART_CONTRACT = "2009", e.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER = "2010", e.SOURCE_ADDRESS_SMART_CONTRACT = "2011", e.SWAP_AMOUNT_TOO_LOW = "2012", e.INVALID_PROVIDER = "2100", e.MISSING_CROSS_CHAIN_PROVIDER = "2101", e.MISSING_AVAX_PROVIDER = "2102", e.MISSING_BSC_PROVIDER = "2103", e.MISSING_ETH_PROVIDER = "2104", e.INVALID_PROVIDER_FOR_SWAP_OUT = "2105", e.MISSING_ARB_PROVIDER = "2106", e.INVALID_CHAIN = "2200", e.INVALID_ASSET = "2201", e.INVALID_ASSET_IDENTIFIER = "2202", e.UNSUPPORTED_CHAIN = "2204", e.UNSUPPORTED_ASSET = "2203", e.UNSUPPORTED_ASSET_FOR_SWAPOUT = "2205", e.INVALID_SOURCE_ADDRESS = "2300", e.INVALID_DESTINATION_ADDRESS = "2301", e.THORNODE_QUOTE_GENERIC_ERROR = "3000", e.NOT_ENOUGH_SYNTH_BALANCE = "3001", e.SYNTH_MINTING_CAP_REACHED = "3002", e.INVALID_QUOTE_MODE = "4000", e.NO_QUOTES = "4001", e.SERVICE_UNAVAILABLE_GENERIC = "5000", e.MISSING_GAS_DATA_GENERIC = "5100", e.MISSING_TOKEN_INFO_GENERIC = "5200", e.CANT_FIND_TOKEN_LIST = "5201", e.NO_PRICE = "5202", e.PRICE_IS_STALE = "5203", e.ADDRESS_NOT_WHITELISTED = "6000", e.ADDRESS_ALREADY_CLAIMED = "6001", e.TEMPORARY_ERROR = "9999", e))(u || {});
15
+ u.INVALID_INPUT_PARAMETERS + "", u.UNKNOWN_PROVIDERS + "", u.CANNOT_FIND_INBOUND_ADDRESS + "", u.NO_INBOUND_ADDRESSES + "", u.CHAIN_HALTED_OR_UNSUPPORTED + "", u.MISSING_INPUT_PARAMETER + "", u.INVALID_TYPE_GENERIC + "", u.INVALID_NUMBER_STRING + "", u.INVALID_NUMBER + "", u.INVALID_BOOLEAN + "", u.INVALID_OBJECT + "", u.INVALID_ARRAY + "", u.SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER + "", u.SELL_BUY_ASSETS_ARE_THE_SAME + "", u.MISSING_SOURCE_ADDRESS_FOR_SYNTH + "", u.AFF_ADDRESS_AND_BPS_OR_NEITHER + "", u.AFF_ADDRESS_TOO_LONG + "", u.AFF_BPS_INTEGER_MAX_500 + "", u.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN + "", u.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN + "", u.PREFERRED_PROVIDER_NOT_SUPPORTED + "", u.SOURCE_ADDRESS_SMART_CONTRACT + "", u.SWAP_AMOUNT_TOO_LOW + "", u.DESTINATION_ADDRESS_SMART_CONTRACT + "", u.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER + "", u.INVALID_PROVIDER + "", u.MISSING_CROSS_CHAIN_PROVIDER + "", u.MISSING_AVAX_PROVIDER + "", u.MISSING_BSC_PROVIDER + "", u.MISSING_ETH_PROVIDER + "", u.MISSING_ARB_PROVIDER + "", u.INVALID_PROVIDER_FOR_SWAP_OUT + "", u.INVALID_CHAIN + "", u.INVALID_ASSET + "", u.UNSUPPORTED_CHAIN + "", u.UNSUPPORTED_ASSET + "", u.UNSUPPORTED_ASSET_FOR_SWAPOUT + "", u.THORNODE_QUOTE_GENERIC_ERROR + "", u.INVALID_SOURCE_ADDRESS + "", u.INVALID_DESTINATION_ADDRESS + "", u.NOT_ENOUGH_SYNTH_BALANCE + "", u.SYNTH_MINTING_CAP_REACHED + "", u.INVALID_QUOTE_MODE + "", u.NO_QUOTES + "", u.SERVICE_UNAVAILABLE_GENERIC + "", u.MISSING_GAS_DATA_GENERIC + "", u.MISSING_TOKEN_INFO_GENERIC + "", u.CANT_FIND_TOKEN_LIST + "", u.NO_PRICE + "", u.PRICE_IS_STALE + "", u.ADDRESS_NOT_WHITELISTED + "", u.ADDRESS_ALREADY_CLAIMED + "";
16
+ var j = /* @__PURE__ */ ((e) => (e.Arbitrum = "ARB", e.Avalanche = "AVAX", e.Binance = "BNB", e.BinanceSmartChain = "BSC", e.Bitcoin = "BTC", e.BitcoinCash = "BCH", e.Cosmos = "GAIA", e.Dash = "DASH", e.Dogecoin = "DOGE", e.Ethereum = "ETH", e.Kujira = "KUJI", e.Litecoin = "LTC", e.Maya = "MAYA", e.Optimism = "OP", e.Polkadot = "DOT", e.Chainflip = "FLIP", e.Polygon = "MATIC", e.THORChain = "THOR", e))(j || {}), te = /* @__PURE__ */ ((e) => (e.Arbitrum = "42161", e.ArbitrumHex = "0xa4b1", e.Avalanche = "43114", e.AvalancheHex = "0xa86a", e.Binance = "Binance-Chain-Tigris", e.BinanceSmartChain = "56", e.BinanceSmartChainHex = "0x38", e.Bitcoin = "bitcoin", e.BitcoinCash = "bitcoincash", e.Chainflip = "chainflip", e.Cosmos = "cosmoshub-4", e.Dash = "dash", e.Dogecoin = "dogecoin", e.Kujira = "kaiyo-1", e.Ethereum = "1", e.EthereumHex = "0x1", e.Litecoin = "litecoin", e.Maya = "mayachain-mainnet-v1", e.MayaStagenet = "mayachain-stagenet-v1", e.Optimism = "10", e.OptimismHex = "0xa", e.Polkadot = "polkadot", e.Polygon = "137", e.PolygonHex = "0x89", e.THORChain = "thorchain-mainnet-v1", e.THORChainStagenet = "thorchain-stagenet-v2", e))(te || {}), de = /* @__PURE__ */ ((e) => (e.Arbitrum = "https://arb1.arbitrum.io/rpc", e.Avalanche = "https://node-router.thorswap.net/avalanche-c", e.Binance = "", e.BinanceSmartChain = "https://bsc-dataseed.binance.org", e.Bitcoin = "https://node-router.thorswap.net/bitcoin", e.BitcoinCash = "https://node-router.thorswap.net/bitcoin-cash", e.Chainflip = "wss://mainnet-archive.chainflip.io", e.Cosmos = "https://node-router.thorswap.net/cosmos/rpc", e.Dash = "https://node-router.thorswap.net/dash", e.Dogecoin = "https://node-router.thorswap.net/dogecoin", e.Ethereum = "https://node-router.thorswap.net/ethereum", e.Kujira = "https://rpc-kujira.synergynodes.com/", e.Litecoin = "https://node-router.thorswap.net/litecoin", e.Maya = "https://tendermint.mayachain.info", e.MayaStagenet = "https://stagenet.tendermint.mayachain.info", e.Optimism = "https://mainnet.optimism.io", e.Polkadot = "wss://rpc.polkadot.io", e.Polygon = "https://polygon-rpc.com", e.THORChain = "https://rpc.thorswap.net", e.THORChainStagenet = "https://stagenet-rpc.ninerealms.com", e))(de || {}), R = /* @__PURE__ */ ((e) => (e.Cosmos = "https://node-router.thorswap.net/cosmos/rest", e.Kujira = "https://lcd-kujira.synergynodes.com/", e.MayanodeMainnet = "https://mayanode.mayachain.info", e.MayanodeStagenet = "https://stagenet.mayanode.mayachain.info", e.ThornodeMainnet = "https://thornode.thorswap.net", e.ThornodeStagenet = "https://stagenet-thornode.ninerealms.com", e.ThorswapApi = "https://api.thorswap.net", e.ThorswapStatic = "https://static.thorswap.net", e))(R || {});
17
+ const q = Object.values(j), $e = Object.keys(j), ne = q.reduce(
18
+ (e, t) => {
19
+ const n = $e.find((r) => j[r] === 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, r) {
41
+ const s = t.status || t.status === 0 ? t.status : "", i = t.statusText || "", a = `${s} ${i}`.trim(), c = a ? `status code ${a}` : "an unknown error";
42
+ super(`Request failed with ${c}`), Object.defineProperty(this, "response", {
43
+ 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 = r;
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", $ = (...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 re({}, ...e);
75
+ }, Ae = (e = {}, t = {}) => {
76
+ const n = new globalThis.Headers(e), r = t instanceof globalThis.Headers, s = new globalThis.Headers(t);
77
+ for (const [i, a] of s.entries())
78
+ r && a === "undefined" || a === void 0 ? n.delete(i) : n.set(i, a);
79
+ return n;
80
+ }, re = (...e) => {
81
+ let t = {}, n = {};
82
+ for (const r of e)
83
+ if (Array.isArray(r))
84
+ Array.isArray(t) || (t = []), t = [...t, ...r];
85
+ else if (M(r)) {
86
+ for (let [s, i] of Object.entries(r))
87
+ M(i) && s in t && (i = re(t[s], i)), t = { ...t, [s]: i };
88
+ M(r.headers) && (n = Ae(n, r.headers), t.headers = n);
89
+ }
90
+ return t;
91
+ }, ve = (() => {
92
+ let e = !1, t = !1;
93
+ const n = typeof globalThis.ReadableStream == "function", r = typeof globalThis.Request == "function";
94
+ return n && r && (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, r) {
160
+ return new Promise((s, i) => {
161
+ const a = setTimeout(() => {
162
+ n && n.abort(), i(new Te(e));
163
+ }, r.timeout);
164
+ r.fetch(e, t).then(s).catch(i).then(() => {
165
+ clearTimeout(a);
166
+ });
167
+ });
168
+ }
169
+ async function Ke(e, { signal: t }) {
170
+ return new Promise((n, r) => {
171
+ t && (t.throwIfAborted(), t.addEventListener("abort", s, { once: !0 }));
172
+ function s() {
173
+ clearTimeout(i), r(t.reason);
174
+ }
175
+ const i = setTimeout(() => {
176
+ t == null || t.removeEventListener("abort", s), n();
177
+ }, e);
178
+ });
179
+ }
180
+ const Je = (e, t) => {
181
+ const n = {};
182
+ for (const r in t)
183
+ !(r in We) && !(r in Ge) && !(r in e) && (n[r] = t[r]);
184
+ return n;
185
+ };
186
+ class x {
187
+ static create(t, n) {
188
+ const r = new x(t, n), s = async () => {
189
+ if (typeof r._options.timeout == "number" && r._options.timeout > K)
190
+ throw new RangeError(`The \`timeout\` option cannot be greater than ${K}`);
191
+ await Promise.resolve();
192
+ let a = await r._fetch();
193
+ for (const c of r._options.hooks.afterResponse) {
194
+ const o = await c(r.request, r._options, r._decorateResponse(a.clone()));
195
+ o instanceof globalThis.Response && (a = o);
196
+ }
197
+ if (r._decorateResponse(a), !a.ok && r._options.throwHttpErrors) {
198
+ let c = new oe(a, r.request, r._options);
199
+ for (const o of r._options.hooks.beforeError)
200
+ c = await o(c);
201
+ throw c;
202
+ }
203
+ if (r._options.onDownloadProgress) {
204
+ if (typeof r._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 r._stream(a.clone(), r._options.onDownloadProgress);
209
+ }
210
+ return a;
211
+ }, i = r._options.retry.methods.includes(r.request.method.toLowerCase()) ? r._retry(s) : s();
212
+ for (const [a, c] of Object.entries(xe))
213
+ i[a] = async () => {
214
+ r.request.headers.set("accept", r.request.headers.get("accept") || c);
215
+ const o = (await i).clone();
216
+ if (a === "json") {
217
+ if (o.status === 204 || (await o.clone().arrayBuffer()).byteLength === 0)
218
+ return "";
219
+ if (n.parseJson)
220
+ return n.parseJson(await o.text());
221
+ }
222
+ return o[a]();
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: re({
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 r = this._options.signal;
281
+ this._options.signal.addEventListener("abort", () => {
282
+ this.abortController.abort(r.reason);
283
+ });
284
+ }
285
+ this._options.signal = this.abortController.signal;
286
+ }
287
+ if (ve && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
288
+ const r = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), s = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, r);
289
+ (Fe && this._options.body instanceof globalThis.FormData || this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers["content-type"]) && this.request.headers.delete("content-type"), this.request = new globalThis.Request(new globalThis.Request(s, { ...this.request }), this._options);
290
+ }
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 r = t.response.headers.get("Retry-After");
299
+ if (r && this._options.retry.afterStatusCodes.includes(t.response.status)) {
300
+ let s = Number(r);
301
+ return Number.isNaN(s) ? s = Date.parse(r) - Date.now() : s *= 1e3, this._options.retry.maxRetryAfter !== void 0 && s > this._options.retry.maxRetryAfter ? 0 : s;
302
+ }
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 r = Math.min(this._calculateRetryDelay(n), K);
319
+ if (r !== 0 && this._retryCount > 0) {
320
+ await Ke(r, { signal: this._options.signal });
321
+ for (const s of this._options.hooks.beforeRetry)
322
+ if (await s({
323
+ 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 r = await n(this.request, this._options);
337
+ if (r instanceof Request) {
338
+ this.request = r;
339
+ break;
340
+ }
341
+ if (r instanceof Response)
342
+ return r;
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 r = Number(t.headers.get("content-length")) || 0;
350
+ let s = 0;
351
+ return t.status === 204 ? (n && n({ percent: 1, totalBytes: r, transferredBytes: s }, new Uint8Array()), new globalThis.Response(null, {
352
+ status: t.status,
353
+ statusText: t.statusText,
354
+ headers: t.headers
355
+ })) : new globalThis.Response(new globalThis.ReadableStream({
356
+ async start(i) {
357
+ const a = t.body.getReader();
358
+ n && n({ percent: 0, transferredBytes: 0, totalBytes: r }, new Uint8Array());
359
+ async function c() {
360
+ const { done: o, value: _ } = await a.read();
361
+ if (o) {
362
+ i.close();
363
+ return;
364
+ }
365
+ if (n) {
366
+ s += _.byteLength;
367
+ const h = r === 0 ? 0 : s / r;
368
+ n({ percent: h, transferredBytes: s, totalBytes: r }, _);
369
+ }
370
+ i.enqueue(_), await c();
371
+ }
372
+ await c();
373
+ }
374
+ }), {
375
+ status: t.status,
376
+ statusText: t.statusText,
377
+ headers: t.headers
43
378
  });
44
- return r ? s.text() : s.json();
45
- } catch {
46
- return {};
47
379
  }
48
- }, ct = "0x313ce567", Y = async ({ chain: n, to: t }) => {
380
+ }
381
+ /*! MIT License © Sindre Sorhus */
382
+ const Q = (e) => {
383
+ const t = (n, r) => x.create(n, $(e, r));
384
+ for (const n of pe)
385
+ t[n] = (r, s) => x.create(r, $(e, s, { method: n }));
386
+ return t.create = (n) => Q($(n)), t.extend = (n) => Q($(e, n)), t.stop = Se, t;
387
+ }, 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((r, s, i) => i.findIndex((a) => a === r) === s).forEach((r) => n.append("tokens", JSON.stringify(r))), t.metadata && n.append("metadata", "true"), t.lookup && n.append("lookup", "true"), t.sparkline && n.append("sparkline", "true"), S.post(m.CachedPrices, {
408
+ 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 }) => {
49
424
  try {
50
- const e = await at(
51
- it[n],
52
- JSON.stringify({
53
- method: "eth_call",
54
- params: [{ to: t.toLowerCase(), data: ct }, "latest"],
425
+ const { result: n } = await S.post(Ue[e], {
426
+ headers: {
427
+ accept: "*/*",
428
+ "content-type": "application/json",
429
+ "cache-control": "no-cache"
430
+ },
431
+ body: JSON.stringify({
55
432
  id: 44,
56
- jsonrpc: "2.0"
57
- }),
58
- { accept: "*/*", "cache-control": "no-cache", "content-type": "application/json" },
59
- !0
60
- ), { result: r } = JSON.parse(e);
61
- return parseInt(BigInt(r).toString());
62
- } catch (e) {
63
- return console.error(e), m[n];
64
- }
65
- }, ot = async (n) => {
66
- if (n === i.Ethereum)
67
- return m.ETH;
68
- const [, t] = n.split("-");
69
- return t != null && t.startsWith("0x") ? Y({ chain: i.Ethereum, to: t }) : m.ETH;
70
- }, ut = async (n) => {
71
- const [, t] = n.split("-");
72
- return t != null && t.startsWith("0x") ? Y({ chain: i.Avalanche, to: t.toLowerCase() }) : m.AVAX;
73
- }, lt = async (n) => n === i.BinanceSmartChain ? m.BSC : m.BSC, K = async ({ chain: n, symbol: t }) => {
74
- switch (n) {
75
- case i.Ethereum:
76
- return ot(t);
77
- case i.Avalanche:
78
- return ut(t);
79
- case i.BinanceSmartChain:
80
- return lt(t);
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 === l.Ethereum)
444
+ return d.ETH;
445
+ const [, t] = e.split("-");
446
+ return t != null && t.startsWith("0x") ? Ie({ chain: l.Ethereum, to: t }) : d.ETH;
447
+ }, rt = async (e) => {
448
+ const [, t] = e.split("-");
449
+ return t != null && t.startsWith("0x") ? Ie({ chain: l.Avalanche, to: t.toLowerCase() }) : d.AVAX;
450
+ }, st = async (e) => e === l.BinanceSmartChain ? d.BSC : d.BSC, it = async ({ chain: e, symbol: t }) => {
451
+ switch (e) {
452
+ case l.Ethereum:
453
+ return nt(t);
454
+ case l.Avalanche:
455
+ return rt(t);
456
+ case l.BinanceSmartChain:
457
+ return st(t);
81
458
  default:
82
- return m[n];
83
- }
84
- }, Bt = {
85
- [H.Average]: 1.2,
86
- [H.Fast]: 1.5,
87
- [H.Fastest]: 2
88
- }, dt = ({ chain: n, symbol: t }) => {
89
- switch (n) {
90
- case i.Bitcoin:
91
- case i.BitcoinCash:
92
- case i.Litecoin:
93
- case i.Dogecoin:
94
- case i.Binance:
95
- case i.Ethereum:
96
- case i.Avalanche:
97
- return t === n;
98
- case i.Arbitrum:
99
- case i.Optimism:
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 l.Arbitrum:
468
+ case l.Optimism:
100
469
  return t === "ETH";
101
- case i.Maya:
470
+ case l.Maya:
102
471
  return t === "CACAO";
103
- case i.Kujira:
472
+ case l.Kujira:
104
473
  return t === "KUJI";
105
- case i.Cosmos:
474
+ case l.Cosmos:
106
475
  return t === "ATOM";
107
- case i.Polygon:
476
+ case l.Polygon:
108
477
  return t === "MATIC";
109
- case i.BinanceSmartChain:
478
+ case l.BinanceSmartChain:
110
479
  return t === "BNB";
111
- case i.THORChain:
480
+ case l.THORChain:
112
481
  return t === "RUNE";
482
+ default:
483
+ return t === e;
113
484
  }
114
- }, ht = (n) => {
115
- switch (n) {
116
- case "ETH.THOR":
485
+ }, at = (e) => {
486
+ switch (e) {
487
+ case `${l.Ethereum}.THOR`:
117
488
  return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
118
- case "ETH.vTHOR":
489
+ case `${l.Ethereum}.vTHOR`:
119
490
  return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
120
- case i.Cosmos:
121
- return { identifier: "GAIA.ATOM", decimal: m[n] };
122
- case i.THORChain:
123
- return { identifier: "THOR.RUNE", decimal: m[n] };
124
- case i.BinanceSmartChain:
125
- return { identifier: "BSC.BNB", decimal: m[n] };
126
- case i.Maya:
127
- return { identifier: "MAYA.CACAO", decimal: m.MAYA };
128
- case "MAYA.MAYA":
491
+ case l.Cosmos:
492
+ return { identifier: "GAIA.ATOM", decimal: d[e] };
493
+ case l.THORChain:
494
+ return { identifier: "THOR.RUNE", decimal: d[e] };
495
+ case l.BinanceSmartChain:
496
+ return { identifier: "BSC.BNB", decimal: d[e] };
497
+ case l.Maya:
498
+ return { identifier: "MAYA.CACAO", decimal: d.MAYA };
499
+ case `${l.Maya}.MAYA`:
129
500
  return { identifier: "MAYA.MAYA", decimal: 4 };
130
- case i.Kujira:
131
- case i.Arbitrum:
132
- case i.Optimism:
133
- case i.BitcoinCash:
134
- case i.Litecoin:
135
- case i.Dogecoin:
136
- case i.Binance:
137
- case i.Avalanche:
138
- case i.Polygon:
139
- case i.Bitcoin:
140
- case i.Ethereum:
141
- return { identifier: `${n}.${n}`, decimal: m[n] };
142
- }
143
- }, mt = ({ chain: n, symbol: t }) => {
501
+ case `${l.Kujira}.USK`:
502
+ return { identifier: `${l.Kujira}.USK`, decimal: 6 };
503
+ default:
504
+ return { identifier: `${e}.${e}`, decimal: d[e] };
505
+ }
506
+ }, ot = ({ chain: e, symbol: t }) => {
144
507
  if (t.includes("/"))
145
508
  return "Synth";
146
- switch (n) {
147
- case i.Bitcoin:
148
- case i.BitcoinCash:
149
- case i.Dogecoin:
150
- case i.Litecoin:
151
- case i.Maya:
152
- case i.THORChain:
509
+ switch (e) {
510
+ case l.Cosmos:
511
+ return t === "ATOM" ? "Native" : l.Cosmos;
512
+ case l.Kujira:
513
+ return t === l.Kujira ? "Native" : l.Kujira;
514
+ case l.Binance:
515
+ return t === l.Binance ? "Native" : "BEP2";
516
+ case l.BinanceSmartChain:
517
+ return t === l.Binance ? "Native" : "BEP20";
518
+ case l.Ethereum:
519
+ return t === l.Ethereum ? "Native" : "ERC20";
520
+ case l.Avalanche:
521
+ return t === l.Avalanche ? "Native" : l.Avalanche;
522
+ case l.Polygon:
523
+ return t === l.Polygon ? "Native" : "POLYGON";
524
+ case l.Arbitrum:
525
+ return [l.Ethereum, l.Arbitrum].includes(t) ? "Native" : "ARBITRUM";
526
+ case l.Optimism:
527
+ return [l.Ethereum, l.Optimism].includes(t) ? "Native" : "OPTIMISM";
528
+ default:
153
529
  return "Native";
154
- case i.Cosmos:
155
- return t === "ATOM" ? "Native" : i.Cosmos;
156
- case i.Kujira:
157
- return t === i.Kujira ? "Native" : i.Kujira;
158
- case i.Binance:
159
- return t === i.Binance ? "Native" : "BEP2";
160
- case i.BinanceSmartChain:
161
- return t === i.Binance ? "Native" : "BEP20";
162
- case i.Ethereum:
163
- return t === i.Ethereum ? "Native" : "ERC20";
164
- case i.Avalanche:
165
- return t === i.Avalanche ? "Native" : i.Avalanche;
166
- case i.Polygon:
167
- return t === i.Polygon ? "Native" : "POLYGON";
168
- case i.Arbitrum:
169
- return [i.Ethereum, i.Arbitrum].includes(t) ? "Native" : "ARBITRUM";
170
- case i.Optimism:
171
- return [i.Ethereum, i.Optimism].includes(t) ? "Native" : "OPTIMISM";
172
- }
173
- }, yt = (n) => {
174
- var c;
175
- const [t, ...e] = n.split("."), r = n.includes("/"), s = e.join("."), a = (c = s == null ? void 0 : s.split("-")) == null ? void 0 : c[0];
176
- return { chain: t, symbol: s, ticker: a, synth: r };
177
- }, gt = new RegExp(
530
+ }
531
+ }, It = (e) => {
532
+ var a;
533
+ const [t, ...n] = e.split("."), r = e.includes("/"), s = n.join("."), i = (a = s == null ? void 0 : s.split("-")) == null ? void 0 : a[0];
534
+ return { chain: t, symbol: s, ticker: i, synth: r };
535
+ }, ct = new RegExp(
178
536
  /(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
179
537
  "gmi"
180
- ), Et = (n) => n.filter(
181
- (t) => !gt.test(t.toString()) && !t.toString().includes("undefined")
182
- ), _t = ({
183
- liquidityUnits: n,
538
+ ), lt = (e) => {
539
+ const [t, n] = e.split(".");
540
+ if (!Be.includes(t))
541
+ return !0;
542
+ const [, r] = n.split("-");
543
+ return fe({ chain: t, symbol: n }) || !!r;
544
+ }, ft = (e) => e.filter(({ chain: t, value: n, symbol: r }) => {
545
+ const s = `${t}.${r}`;
546
+ return !ct.test(s) && lt(s) && n !== "0";
547
+ });
548
+ function ut({
549
+ liquidityUnits: e,
184
550
  poolUnits: t,
185
- runeDepth: e
186
- }) => {
187
- const r = h(n), s = h(t), a = h(e), c = r.mul(a), o = s.mul(s).mul(2), u = s.mul(r).mul(2), l = r.mul(r), d = s.mul(s).mul(s);
188
- return c.mul(o.sub(u).add(l)).div(d);
189
- }, pt = ({
190
- liquidityUnits: n,
551
+ runeDepth: n
552
+ }) {
553
+ const r = A(e), s = A(t), i = A(n), a = r.mul(i), c = s.mul(s).mul(2), o = s.mul(r).mul(2), _ = r.mul(r), h = s.mul(s).mul(s);
554
+ return a.mul(c.sub(o).add(_)).div(h);
555
+ }
556
+ function _t({
557
+ liquidityUnits: e,
191
558
  poolUnits: t,
192
- assetDepth: e
193
- }) => {
194
- const r = h(n), s = h(t), a = h(e), c = r.mul(a), o = s.mul(s).mul(2), u = s.mul(r).mul(2), l = r.mul(r), d = c.mul(o.sub(u).add(l)), A = s.mul(s).mul(s);
195
- return d.div(A);
196
- }, Ot = ({
197
- percent: n,
559
+ assetDepth: n
560
+ }) {
561
+ const r = A(e), s = A(t), i = A(n), a = r.mul(i), c = s.mul(s).mul(2), o = s.mul(r).mul(2), _ = r.mul(r), h = a.mul(c.sub(o).add(_)), P = s.mul(s).mul(s);
562
+ return h.div(P);
563
+ }
564
+ function Nt({
565
+ percent: e,
198
566
  runeDepth: t,
199
- liquidityUnits: e,
567
+ liquidityUnits: n,
200
568
  poolUnits: r
201
- }) => _t({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(n), Mt = ({
202
- percent: n,
569
+ }) {
570
+ return ut({ runeDepth: t, liquidityUnits: n, poolUnits: r }).mul(e);
571
+ }
572
+ function Ct({
573
+ percent: e,
203
574
  assetDepth: t,
204
- liquidityUnits: e,
205
- poolUnits: r
206
- }) => pt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(n), h = (n) => new bt({ value: n, decimal: m.THOR }), ft = ({
207
575
  liquidityUnits: n,
576
+ poolUnits: r
577
+ }) {
578
+ return _t({ assetDepth: t, liquidityUnits: n, poolUnits: r }).mul(e);
579
+ }
580
+ function A(e) {
581
+ return I.fromBigInt(BigInt(e), d.THOR);
582
+ }
583
+ function ht({
584
+ liquidityUnits: e,
208
585
  poolUnits: t,
209
- runeDepth: e,
586
+ runeDepth: n,
210
587
  assetDepth: r
211
- }) => ({
212
- assetAmount: h(r).mul(n).div(t),
213
- runeAmount: h(e).mul(n).div(t)
214
- }), Nt = ({
215
- liquidityUnits: n,
588
+ }) {
589
+ return {
590
+ assetAmount: A(r).mul(e).div(t),
591
+ runeAmount: A(n).mul(e).div(t)
592
+ };
593
+ }
594
+ function gt({
595
+ liquidityUnits: e,
216
596
  poolUnits: t,
217
- runeDepth: e,
597
+ runeDepth: n,
218
598
  assetDepth: r,
219
599
  percent: s
220
- }) => Object.fromEntries(
221
- Object.entries(ft({ liquidityUnits: n, poolUnits: t, runeDepth: e, assetDepth: r })).map(
222
- ([a, c]) => [a, c.mul(s)]
223
- )
224
- ), Rt = ({
225
- runeDepth: n,
600
+ }) {
601
+ return Object.fromEntries(
602
+ Object.entries(ht({ liquidityUnits: e, poolUnits: t, runeDepth: n, assetDepth: r })).map(
603
+ ([i, a]) => [i, a.mul(s)]
604
+ )
605
+ );
606
+ }
607
+ function Ot({
608
+ runeDepth: e,
226
609
  poolUnits: t,
227
- assetDepth: e,
610
+ assetDepth: n,
228
611
  liquidityUnits: r,
229
612
  runeAmount: s,
230
- assetAmount: a
231
- }) => {
232
- const c = h(n), o = h(e), u = h(t), l = h(s), d = h(a), A = l.mul(o), I = d.mul(c), R = l.mul(d), X = c.mul(o), Z = u.mul(A.add(I.add(R.mul(2)))), tt = A.add(I.add(X.mul(2))), F = Z.div(tt), k = h(r).add(F);
233
- if (F.baseValueNumber === 0)
234
- return k.div(u).baseValueNumber;
235
- const et = u.add(k);
236
- return k.div(et).baseValueNumber;
237
- }, kt = ({
238
- runeAmount: n,
613
+ assetAmount: i
614
+ }) {
615
+ const a = new I({ value: e, decimal: 8 }), c = new I({ value: n, decimal: 8 }), o = new I({ value: t, decimal: 8 }), _ = new I({ value: s, decimal: 8 }), h = new I({ value: i, decimal: 8 }), P = _.mul(c), ie = h.mul(a), ge = _.mul(h), Oe = a.mul(c), De = o.mul(P.add(ie.add(ge.mul(2)))), Pe = P.add(ie.add(Oe.mul(2))), ae = De.div(Pe), X = A(r).add(ae);
616
+ if (ae.getBaseValue("number") === 0)
617
+ return X.div(o).getBaseValue("number");
618
+ const be = o.add(X);
619
+ return X.div(be).getBaseValue("number");
620
+ }
621
+ function Dt({
622
+ runeAmount: e,
239
623
  assetAmount: t,
240
- runeDepth: e,
624
+ runeDepth: n,
241
625
  assetDepth: r
242
- }) => {
243
- const s = h(e), a = h(r), c = h(t), o = h(n), u = c.mul(s).sub(a.mul(o)), l = a.mul(o).add(s.mul(a));
244
- return Math.abs(u.div(l).baseValueNumber);
245
- }, At = ({
246
- symbol: n,
247
- ticker: t,
248
- chain: e
249
- }) => e === "ETH" && t !== "ETH" ? `${t}-${n.slice(-3)}` : n, Ht = (n, t) => {
250
- switch (n) {
251
- case p.LEAVE:
252
- case p.BOND: {
253
- const { address: e } = t;
254
- return `${n}:${e}`;
626
+ }) {
627
+ if (e === "0" || t === "0" || n === "0" || r === "0")
628
+ return 0;
629
+ const s = A(n), i = A(r), a = A(t), c = A(e), o = a.mul(s).sub(i.mul(c)), _ = i.mul(c).add(s.mul(i));
630
+ return Math.abs(o.div(_).getBaseValue("number"));
631
+ }
632
+ const Pt = (e, t) => {
633
+ switch (e) {
634
+ case E.LEAVE:
635
+ case E.BOND: {
636
+ const { address: n } = t;
637
+ return `${e}:${n}`;
255
638
  }
256
- case p.UNBOND: {
257
- const { address: e, unbondAmount: r } = t;
258
- return `${n}:${e}:${r * 10 ** 8}`;
639
+ case E.UNBOND: {
640
+ const { address: n, unbondAmount: r } = t;
641
+ return `${e}:${n}:${r}`;
259
642
  }
260
- case p.THORNAME_REGISTER: {
261
- const { name: e, chain: r, address: s, owner: a } = t;
262
- return `${n}:${e}:${r}:${s}${a ? `:${a}` : ""}`;
643
+ case E.THORNAME_REGISTER: {
644
+ const { name: n, chain: r, address: s, owner: i } = t;
645
+ return `${e}:${n}:${r}:${s}${i ? `:${i}` : ""}`;
263
646
  }
264
- case p.DEPOSIT: {
265
- const { chain: e, symbol: r, address: s, singleSide: a } = t;
266
- return a ? `${n}:${e}/${r}::t:0` : `${n}:${e}.${r}:${s || ""}:t:0`;
647
+ case E.DEPOSIT: {
648
+ const { chain: n, symbol: r, address: s, singleSide: i } = t;
649
+ return i ? `${e}:${n}/${r}` : `${e}:${((c, o) => {
650
+ switch (c) {
651
+ case l.Litecoin:
652
+ return "l";
653
+ case l.Dogecoin:
654
+ return "d";
655
+ case l.BitcoinCash:
656
+ return "c";
657
+ default:
658
+ return `${c}.${o}`;
659
+ }
660
+ })(n, r)}:${s || ""}`;
267
661
  }
268
- case p.WITHDRAW: {
269
- const { chain: e, ticker: r, symbol: s, basisPoints: a, targetAssetString: c, singleSide: o } = t, u = !o && c ? `:${c}` : "", l = At({ chain: e, symbol: s, ticker: r });
270
- return `${n}:${e}${o ? "/" : "."}${l}:${a}${u}`;
662
+ case E.WITHDRAW: {
663
+ const { chain: n, ticker: r, symbol: s, basisPoints: i, targetAssetString: a, singleSide: c } = t, o = n === "ETH" && r !== "ETH" ? `${r}-${s.slice(-3)}` : s, _ = !c && a ? `:${a}` : "";
664
+ return `${e}:${n}${c ? "/" : "."}${o}:${i}${_}`;
271
665
  }
272
- case p.OPEN_LOAN:
273
- case p.CLOSE_LOAN: {
274
- const { asset: e, address: r } = t;
275
- return `${n}:${e}:${r}`;
666
+ case E.OPEN_LOAN:
667
+ case E.CLOSE_LOAN: {
668
+ const { asset: n, address: r } = t;
669
+ return `${e}:${n}:${r}`;
276
670
  }
277
671
  default:
278
672
  return "";
279
673
  }
280
- }, G = Object.values(i), $t = (n = "") => {
281
- const t = n.toUpperCase(), [e] = t.split(".");
282
- if (G.includes(e))
674
+ };
675
+ function bt(e) {
676
+ if (e < 0)
677
+ throw new Error("Invalid number of year");
678
+ return 10 + e;
679
+ }
680
+ function yt(e) {
681
+ if (e.length > 30)
682
+ return !1;
683
+ const t = /^[a-zA-Z0-9+_-]+$/g;
684
+ return !!e.match(t);
685
+ }
686
+ function wt([e, t, n, r, s]) {
687
+ return `${e}'/${t}'/${n}'/${r}${typeof s != "number" ? "" : `/${s}`}`;
688
+ }
689
+ const ue = [...Object.values(l), "TERRA"];
690
+ function dt(e = "") {
691
+ const t = e.toUpperCase(), [n] = t.split(".");
692
+ if (ue.includes(n))
283
693
  return !0;
284
694
  const [r] = t.split("/");
285
- if (G.includes(r))
695
+ if (ue.includes(r))
286
696
  return !0;
287
697
  throw new Error(
288
- `Invalid identifier: ${n}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
698
+ `Invalid identifier: ${e}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
289
699
  );
290
- }, T = 8, S = (n) => 10n ** BigInt(n), v = (n) => Math.log10(parseFloat(n.toString()));
291
- function U({
292
- value: n,
293
- bigIntDecimal: t = T,
294
- decimal: e = T
700
+ }
701
+ const B = 8, N = (e) => 10n ** BigInt(e), b = (e) => Math.log10(parseFloat(e.toString()));
702
+ function G({
703
+ value: e,
704
+ bigIntDecimal: t = B,
705
+ decimal: n = B
295
706
  }) {
296
- const r = n < 0n;
297
- let s = n.toString().substring(r ? 1 : 0);
298
- const a = e - (s.length - 1);
299
- a > 0 && (s = "0".repeat(a) + s);
300
- const c = s.length - e;
301
- let o = s.slice(-e);
302
- return parseInt(o[t]) >= 5 ? o = `${o.substring(0, t - 1)}${(parseInt(o[t - 1]) + 1).toString()}` : o = o.substring(0, t), `${r ? "-" : ""}${s.slice(0, c)}.${o}`.replace(
707
+ if (n === 0)
708
+ return e.toString();
709
+ const r = e < 0n;
710
+ let s = e.toString().substring(r ? 1 : 0);
711
+ const i = n - (s.length - 1);
712
+ i > 0 && (s = "0".repeat(i) + s);
713
+ const a = s.length - n;
714
+ let c = s.slice(-n);
715
+ return parseInt(c[t]) >= 5 ? c = `${c.substring(0, t - 1)}${(parseInt(c[t - 1]) + 1).toString()}` : c = c.substring(0, t), `${r ? "-" : ""}${s.slice(0, a)}.${c}`.replace(
303
716
  /\.?0*$/,
304
717
  ""
305
718
  );
306
719
  }
307
- var w, V, M, z, N, J, E, D, b, C, O, L;
308
- const B = class B {
720
+ var C, y, f, D, k, Ne, U, z, L, Z;
721
+ const se = class se {
309
722
  constructor(t) {
310
- $(this, w);
311
- $(this, M);
312
- $(this, N);
313
- $(this, E);
314
- $(this, b);
315
- $(this, O);
316
- _(this, "decimalMultiplier", 10n ** 8n);
317
- _(this, "bigIntValue", 0n);
318
- _(this, "decimal");
319
- const e = P(t);
320
- this.decimal = typeof t == "object" ? t.decimal : void 0, this.decimalMultiplier = S(
321
- Math.max(g(this, O, L).call(this, g(this, b, C).call(this, e)), this.decimal || 0)
322
- ), g(this, M, z).call(this, e);
323
- }
324
- static fromBigInt(t, e) {
325
- return new B({
326
- decimal: e,
327
- value: U({ value: t, bigIntDecimal: e, decimal: e })
723
+ O(this, C);
724
+ O(this, f);
725
+ O(this, k);
726
+ O(this, U);
727
+ O(this, L);
728
+ p(this, "decimalMultiplier", 10n ** 8n);
729
+ p(this, "bigIntValue", 0n);
730
+ p(this, "decimal");
731
+ const n = ee(t), r = typeof t == "object";
732
+ this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier : N(Math.max(_e(v(n)), this.decimal || 0)), T(this, k, Ne).call(this, n);
733
+ }
734
+ static fromBigInt(t, n) {
735
+ return new se({
736
+ decimal: n,
737
+ value: G({ value: t, bigIntDecimal: n, decimal: n })
328
738
  });
329
739
  }
330
740
  static shiftDecimals({
331
741
  value: t,
332
- from: e,
742
+ from: n,
333
743
  to: r
334
744
  }) {
335
- return B.fromBigInt(
336
- new B(t).bigIntValue * S(r) / S(e),
745
+ return this.fromBigInt(
746
+ t.getBaseValue("bigint") * N(r) / N(n),
337
747
  r
338
748
  );
339
749
  }
340
- /**
341
- * @deprecated Use `getBaseValue('string')` instead
342
- */
343
- get baseValue() {
344
- return this.getBaseValue("string");
345
- }
346
- /**
347
- * @deprecated Use `getBaseValue('number')` instead
348
- */
349
- get baseValueNumber() {
350
- return this.getBaseValue("number");
351
- }
352
- /**
353
- * @deprecated Use `getBaseValue('bigint')` instead
354
- */
355
- get baseValueBigInt() {
356
- return this.getBaseValue("bigint");
357
- }
358
750
  set(t) {
359
751
  return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
360
752
  }
361
753
  add(...t) {
362
- return g(this, w, V).call(this, "add", ...t);
754
+ return T(this, C, y).call(this, "add", ...t);
363
755
  }
364
756
  sub(...t) {
365
- return g(this, w, V).call(this, "sub", ...t);
757
+ return T(this, C, y).call(this, "sub", ...t);
366
758
  }
367
759
  mul(...t) {
368
- return g(this, w, V).call(this, "mul", ...t);
760
+ return T(this, C, y).call(this, "mul", ...t);
369
761
  }
370
762
  div(...t) {
371
- return g(this, w, V).call(this, "div", ...t);
763
+ return T(this, C, y).call(this, "div", ...t);
372
764
  }
373
765
  gt(t) {
374
- return this.bigIntValue > this.getBigIntValue(t);
766
+ return T(this, f, D).call(this, "gt", t);
375
767
  }
376
768
  gte(t) {
377
- return this.bigIntValue >= this.getBigIntValue(t);
769
+ return T(this, f, D).call(this, "gte", t);
378
770
  }
379
771
  lt(t) {
380
- return this.bigIntValue < this.getBigIntValue(t);
772
+ return T(this, f, D).call(this, "lt", t);
381
773
  }
382
774
  lte(t) {
383
- return this.bigIntValue <= this.getBigIntValue(t);
775
+ return T(this, f, D).call(this, "lte", t);
384
776
  }
385
777
  eqValue(t) {
386
- return this.bigIntValue === this.getBigIntValue(t);
778
+ return T(this, f, D).call(this, "eqValue", t);
387
779
  }
780
+ // @ts-expect-error False positive
388
781
  getValue(t) {
389
- const e = this.formatBigIntToSafeValue(
782
+ const n = this.formatBigIntToSafeValue(
390
783
  this.bigIntValue,
391
- this.decimal || v(this.decimalMultiplier)
784
+ this.decimal || b(this.decimalMultiplier)
392
785
  );
393
786
  switch (t) {
394
787
  case "number":
395
- return Number(e);
788
+ return Number(n);
396
789
  case "string":
397
- return e;
398
- default:
399
- return this.bigIntValue;
790
+ return n;
791
+ case "bigint":
792
+ return this.bigIntValue * 10n ** BigInt(this.decimal || 8n) / this.decimalMultiplier;
400
793
  }
401
794
  }
795
+ // @ts-expect-error
402
796
  getBaseValue(t) {
403
- const e = this.decimalMultiplier / S(this.decimal || 0), r = this.bigIntValue / e;
797
+ const n = this.decimalMultiplier / N(this.decimal || d.THOR), r = this.bigIntValue / n;
404
798
  switch (t) {
405
799
  case "number":
406
800
  return Number(r);
407
801
  case "string":
408
802
  return r.toString();
409
- default:
410
- return this.bigIntValue;
803
+ case "bigint":
804
+ return r;
411
805
  }
412
806
  }
413
- getBigIntValue(t, e) {
414
- if (!e && typeof t == "object")
807
+ getBigIntValue(t, n) {
808
+ if (!n && typeof t == "object")
415
809
  return t.bigIntValue;
416
- const r = P(t), s = g(this, b, C).call(this, r);
417
- return s === "0" || s === "undefined" ? 0n : g(this, E, D).call(this, s, e);
418
- }
419
- formatBigIntToSafeValue(t, e) {
420
- const r = e || this.decimal || T, s = Math.max(
421
- r,
422
- v(this.decimalMultiplier)
423
- ), a = t < 0n, c = t.toString().substring(a ? 1 : 0), o = s - (c.length - 1), u = o > 0 ? "0".repeat(o) + c : c, l = u.length - s;
424
- let d = u.slice(-s);
425
- return parseInt(d[r]) >= 5 ? d = `${d.substring(0, r - 1)}${(parseInt(d[r - 1]) + 1).toString()}` : d = d.substring(0, r), `${a ? "-" : ""}${u.slice(
426
- 0,
427
- l
428
- )}.${d}`.replace(/\.?0*$/, "");
810
+ const r = ee(t), s = v(r);
811
+ return s === "0" || s === "undefined" ? 0n : T(this, L, Z).call(this, s, n);
429
812
  }
430
813
  toSignificant(t = 6) {
431
- const [e, r] = this.getValue("string").split("."), s = e || "", a = r || "", c = parseInt(s) ? s.length + a.length : a.length;
432
- if (c <= t)
814
+ const [n, r] = this.getValue("string").split("."), s = n || "", i = r || "";
815
+ if ((parseInt(s) ? s.length + i.length : i.length) <= t)
433
816
  return this.getValue("string");
434
817
  if (s.length >= t)
435
818
  return s.slice(0, t).padEnd(s.length, "0");
436
819
  if (parseInt(s))
437
- return `${s}.${a.slice(0, t - s.length)}`.padEnd(
438
- c - t,
820
+ return `${s}.${i.slice(0, t - s.length)}`.padEnd(
821
+ t - s.length,
439
822
  "0"
440
823
  );
441
- const o = parseInt(a), u = `${o}`.slice(0, t);
442
- return `0.${u.padStart(
443
- a.length - `${o}`.length + u.length,
824
+ const c = parseInt(i), o = `${c}`.slice(0, t);
825
+ return `0.${o.padStart(
826
+ i.length - `${c}`.length + o.length,
444
827
  "0"
445
828
  )}`;
446
829
  }
830
+ toFixed(t = 6) {
831
+ const [n, r] = this.getValue("string").split("."), s = n || "", i = r || "";
832
+ if (parseInt(s))
833
+ return `${s}.${i.slice(0, t)}`.padEnd(t, "0");
834
+ const a = parseInt(i), c = `${a}`.slice(0, t);
835
+ return `0.${c.padStart(
836
+ i.length - `${a}`.length + c.length,
837
+ "0"
838
+ )}`;
839
+ }
840
+ toAbbreviation(t = 2) {
841
+ const n = this.getValue("number"), r = ["", "K", "M", "B", "T", "Q", "Qi", "S"], s = Math.floor(Math.log10(Math.abs(n)) / 3), i = r[s];
842
+ if (!i)
843
+ return this.getValue("string");
844
+ const a = 10 ** (s * 3);
845
+ return `${(n / a).toFixed(t)}${i}`;
846
+ }
847
+ toCurrency(t = "$", {
848
+ currencyPosition: n = "start",
849
+ decimal: r = 2,
850
+ decimalSeparator: s = ".",
851
+ thousandSeparator: i = ","
852
+ } = {}) {
853
+ const a = this.getValue("number"), [c, o = ""] = a.toFixed(6).split("."), _ = c.replace(/\B(?=(\d{3})+(?!\d))/g, i), h = !c && !o ? "0.00" : c === "0" ? `${parseFloat(`0.${o}`)}`.replace(".", s) : `${_}${parseInt(o) ? `${s}${o.slice(0, r)}` : ""}`;
854
+ return `${n === "start" ? t : ""}${h}${n === "end" ? t : ""}`;
855
+ }
856
+ formatBigIntToSafeValue(t, n) {
857
+ const r = n || this.decimal || B, s = Math.max(
858
+ r,
859
+ b(this.decimalMultiplier)
860
+ ), i = t < 0n, a = t.toString().substring(i ? 1 : 0), c = s - (a.length - 1), o = c > 0 ? "0".repeat(c) + a : a, _ = o.length - s;
861
+ let h = o.slice(-s);
862
+ return parseInt(h[r]) >= 5 ? h = `${h.substring(0, r - 1)}${(parseInt(h[r - 1]) + 1).toString()}` : h = h.substring(0, r), `${i ? "-" : ""}${o.slice(
863
+ 0,
864
+ _
865
+ )}.${h}`.replace(/\.?0*$/, "");
866
+ }
447
867
  };
448
- w = new WeakSet(), V = function(t, ...e) {
449
- const r = g(this, N, J).call(this, this, ...e), s = S(r), a = e.reduce(
450
- (o, u) => {
451
- const l = this.getBigIntValue(u, r);
868
+ C = new WeakSet(), y = function(t, ...n) {
869
+ const r = T(this, U, z).call(this, this, ...n), s = Math.max(r, b(this.decimalMultiplier)), i = N(s), a = n.reduce(
870
+ (o, _) => {
871
+ const h = this.getBigIntValue(_, s);
452
872
  switch (t) {
453
873
  case "add":
454
- return o + l;
874
+ return o + h;
455
875
  case "sub":
456
- return o - l;
876
+ return o - h;
457
877
  case "mul":
458
- return o * l / s;
878
+ return o * h / i;
459
879
  case "div": {
460
- if (l === 0n)
880
+ if (h === 0n)
461
881
  throw new RangeError("Division by zero");
462
- return o * s / l;
882
+ return o * i / h;
463
883
  }
464
884
  default:
465
885
  return o;
466
886
  }
467
887
  },
468
888
  //normalize is to precision multiplier base
469
- this.bigIntValue * s / this.decimalMultiplier
470
- ), c = U({
471
- bigIntDecimal: r,
472
- decimal: Math.max(r, v(this.decimalMultiplier)),
889
+ this.bigIntValue * i / this.decimalMultiplier
890
+ ), c = G({
891
+ bigIntDecimal: s,
892
+ decimal: s,
473
893
  value: a
474
894
  });
475
- return new this.constructor({ decimal: this.decimal, value: c, identifier: this.toString() });
476
- }, M = new WeakSet(), z = function(t) {
477
- const e = g(this, b, C).call(this, t) || "0";
478
- this.bigIntValue = g(this, E, D).call(this, e);
479
- }, N = new WeakSet(), J = function(...t) {
480
- const e = t.map(
481
- (r) => typeof r == "object" ? r.decimal || v(r.decimalMultiplier) : g(this, O, L).call(this, g(this, b, C).call(this, r))
482
- ).filter(Boolean);
483
- return Math.max(...e, T);
484
- }, E = new WeakSet(), D = function(t, e) {
485
- const r = e ? S(e) : this.decimalMultiplier, s = v(r), [a = "", c = ""] = t.split(".");
486
- return BigInt(`${a}${c.padEnd(s, "0")}`);
487
- }, b = new WeakSet(), C = function(t) {
488
- const r = `${typeof t == "number" ? Number(t).toLocaleString("fullwide", {
489
- useGrouping: !1,
490
- maximumFractionDigits: 20
491
- }) : P(t)}`.replaceAll(",", ".").split(".");
492
- return r.length > 1 ? `${r.slice(0, -1).join("")}.${r.at(-1)}` : r[0];
493
- }, O = new WeakSet(), L = function(t) {
494
- var r;
495
- const e = ((r = t.split(".")[1]) == null ? void 0 : r.length) || 0;
496
- return Math.max(e, T);
895
+ return new this.constructor({
896
+ decimalMultiplier: N(s),
897
+ decimal: this.decimal,
898
+ value: c,
899
+ identifier: this.toString()
900
+ });
901
+ }, f = new WeakSet(), D = function(t, ...n) {
902
+ const r = T(this, U, z).call(this, this, ...n), s = this.getBigIntValue(n[0], r), i = this.getBigIntValue(this, r);
903
+ switch (t) {
904
+ case "gt":
905
+ return i > s;
906
+ case "gte":
907
+ return i >= s;
908
+ case "lt":
909
+ return i < s;
910
+ case "lte":
911
+ return i <= s;
912
+ case "eqValue":
913
+ return i === s;
914
+ }
915
+ }, k = new WeakSet(), Ne = function(t) {
916
+ const n = v(t) || "0";
917
+ this.bigIntValue = T(this, L, Z).call(this, n);
918
+ }, U = new WeakSet(), z = function(...t) {
919
+ const n = t.map((r) => typeof r == "object" ? r.decimal || b(r.decimalMultiplier) : _e(v(r))).filter(Boolean);
920
+ return Math.max(...n, B);
921
+ }, L = new WeakSet(), Z = function(t, n) {
922
+ const r = n ? N(n) : this.decimalMultiplier, s = b(r), [i = "", a = ""] = t.split(".");
923
+ return BigInt(`${i}${a.padEnd(s, "0")}`);
497
924
  };
498
- let y = B;
499
- function P(n) {
500
- return typeof n == "object" ? "getValue" in n ? n.getValue("string") : n.value : n;
925
+ let W = se;
926
+ const Tt = Intl.NumberFormat("fullwide", {
927
+ useGrouping: !1,
928
+ maximumFractionDigits: 20
929
+ });
930
+ function v(e) {
931
+ const n = `${typeof e == "number" ? Tt.format(e) : ee(e)}`.replaceAll(",", ".").split(".");
932
+ return n.length > 1 ? `${n.slice(0, -1).join("")}.${n.at(-1)}` : n[0];
501
933
  }
502
- let j;
503
- const x = (n) => {
504
- if (!j)
505
- throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");
506
- return j.get(n.toUpperCase()) || { decimal: m.THOR, identifier: "" };
507
- }, W = async (n, t = 0) => {
508
- $t(n);
509
- const e = await K(q(n));
510
- return new f({ decimal: e, value: t, identifier: n });
511
- };
512
- class f extends y {
513
- constructor(e) {
514
- super(
515
- e.value instanceof y ? e.value : { decimal: e.decimal, value: e.value }
516
- );
517
- _(this, "address");
518
- _(this, "chain");
519
- _(this, "isSynthetic", !1);
520
- _(this, "isGasAsset", !1);
521
- _(this, "symbol");
522
- _(this, "ticker");
523
- _(this, "type");
524
- const r = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`, s = q(r);
525
- this.type = mt(s), this.chain = s.chain, this.ticker = s.ticker, this.symbol = s.symbol, this.address = s.address, this.isSynthetic = s.isSynthetic, this.isGasAsset = s.isGasAsset;
526
- }
527
- get assetValue() {
528
- return `${this.getValue("string")} ${this.ticker}`;
529
- }
530
- toString(e = !1) {
531
- const r = this.isSynthetic ? this.ticker : `${this.chain}.${this.ticker}`;
532
- return e ? r : (
533
- // THOR.ETH/ETH | ETH.USDT-0x1234567890
534
- `${this.chain}.${this.symbol}`
535
- );
934
+ function _e(e) {
935
+ var n;
936
+ const t = ((n = e.split(".")[1]) == null ? void 0 : n.length) || 0;
937
+ return Math.max(t, B);
938
+ }
939
+ function ee(e) {
940
+ return typeof e == "object" ? "getValue" in e ? e.getValue("string") : e.value : e;
941
+ }
942
+ const w = /* @__PURE__ */ new Map();
943
+ class g extends W {
944
+ constructor({
945
+ value: n,
946
+ decimal: r,
947
+ tax: s,
948
+ chain: i,
949
+ symbol: a,
950
+ identifier: c
951
+ }) {
952
+ super(typeof n == "object" ? n : { decimal: r, value: n });
953
+ p(this, "address");
954
+ p(this, "chain");
955
+ p(this, "isGasAsset", !1);
956
+ p(this, "isSynthetic", !1);
957
+ p(this, "symbol");
958
+ p(this, "tax");
959
+ p(this, "ticker");
960
+ p(this, "type");
961
+ const o = F(c || `${i}.${a}`);
962
+ this.type = ot(o), this.tax = s, this.chain = o.chain, this.ticker = o.ticker, this.symbol = o.symbol, this.address = o.address, this.isSynthetic = o.isSynthetic, this.isGasAsset = o.isGasAsset;
536
963
  }
537
- eq({ chain: e, symbol: r }) {
538
- return this.chain === e && this.symbol === r;
964
+ toString() {
965
+ return this.isSynthetic ? this.symbol : `${this.chain}.${this.symbol}`;
539
966
  }
540
- static async fromString(e, r = 0) {
541
- return W(e, r);
967
+ toUrl() {
968
+ return this.isSynthetic ? `${this.chain}.${this.symbol.replace("/", ".")}` : this.toString();
542
969
  }
543
- static fromStringSync(e, r = 0) {
544
- const { decimal: s, identifier: a } = x(
545
- e
546
- );
547
- return a ? new f({ decimal: s, identifier: a, value: r }) : void 0;
970
+ eq({ chain: n, symbol: r }) {
971
+ return this.chain === n && this.symbol === r;
548
972
  }
549
- static async fromIdentifier(e, r = 0) {
550
- return W(e, r);
973
+ chainId() {
974
+ return Le[this.chain];
551
975
  }
552
- static fromIdentifierSync(e, r = 0) {
553
- const { decimal: s, identifier: a } = x(e);
554
- return new f({ decimal: s, identifier: a, value: r });
976
+ // THOR.RUNE
977
+ // THOR.ETH.ETH
978
+ // ETH.THOR-0x1234567890
979
+ static fromUrl(n, r = 0) {
980
+ const [s, i, a] = n.split(".");
981
+ if (!s || !i)
982
+ throw new Error("Invalid asset url");
983
+ const c = s === l.THORChain && a ? `${s}.${i}/${a}` : n;
984
+ return J(c, r);
555
985
  }
556
- static fromChainOrSignature(e, r = 0) {
557
- const { decimal: s, identifier: a } = ht(e);
558
- return new f({ value: r, decimal: s, identifier: a });
986
+ static fromString(n, r = 0) {
987
+ return J(n, r);
559
988
  }
560
- static async fromTCQuote(e, r = 0) {
561
- const s = await K(q(e)), a = this.shiftDecimals({ value: r, from: m.THOR, to: s });
562
- return new f({ value: a, identifier: e, decimal: s });
989
+ static fromIdentifier(n, r = 0) {
990
+ return J(n, r);
563
991
  }
564
- static fromTCQuoteStatic(e, r = 0) {
565
- const s = x(e), a = this.shiftDecimals({
566
- value: r,
567
- from: m.THOR,
568
- to: s.decimal
992
+ static fromStringSync(n, r = 0) {
993
+ const { chain: s, isSynthetic: i } = F(n), a = w.get(n.toUpperCase());
994
+ if (i)
995
+ return he(n, r);
996
+ const { tax: c, decimal: o, identifier: _ } = a || {
997
+ decimal: d[s],
998
+ identifier: n
999
+ };
1000
+ return new g({
1001
+ tax: c,
1002
+ value: V(r, o),
1003
+ identifier: i ? n : _,
1004
+ decimal: i ? 8 : o
569
1005
  });
570
- return new f({ ...s, value: a });
571
1006
  }
572
- static async loadStaticAssets() {
1007
+ static fromIdentifierSync(n, r = 0) {
1008
+ const { chain: s, isSynthetic: i } = F(n), a = w.get(n);
1009
+ if (i)
1010
+ return he(n, r);
1011
+ const { tax: c, decimal: o, identifier: _ } = a || {
1012
+ decimal: d[s],
1013
+ identifier: n
1014
+ };
1015
+ return new g({ tax: c, decimal: o, identifier: _, value: V(r, o) });
1016
+ }
1017
+ static fromChainOrSignature(n, r = 0) {
1018
+ const { decimal: s, identifier: i } = at(n);
1019
+ return new g({ value: V(r, s), decimal: s, identifier: i });
1020
+ }
1021
+ static loadStaticAssets() {
573
1022
  return new Promise(
574
- async (e, r) => {
1023
+ async (n, r) => {
575
1024
  try {
576
- const {
577
- // Omit ThorchainList from import to avoid decimals conflict (TC uses 8 for all)
578
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
579
- ThorchainList: s,
580
- NativeList: a,
581
- ...c
582
- } = await import("@swapkit/tokens");
583
- j = [a, ...Object.values(c)].reduce(
584
- (u, { tokens: l }) => (l.forEach(({ identifier: d, chain: A, ...I }) => {
585
- const R = "decimals" in I ? I.decimals : m[A];
586
- u.set(d, { identifier: d, decimal: R });
587
- }), u),
588
- /* @__PURE__ */ new Map()
589
- ), e({ ok: !0 });
1025
+ const s = await import("@swapkit/tokens");
1026
+ Object.values(s).forEach((i) => {
1027
+ var a;
1028
+ (a = i == null ? void 0 : i.tokens) == null || a.forEach(({ identifier: c, chain: o, ..._ }) => {
1029
+ w.set(c.toUpperCase(), {
1030
+ identifier: c,
1031
+ decimal: "decimals" in _ ? _.decimals : d[o]
1032
+ });
1033
+ });
1034
+ }), n({ ok: !0 });
590
1035
  } catch (s) {
591
1036
  console.error(s), r({
592
1037
  ok: !1,
@@ -598,35 +1043,60 @@ class f extends y {
598
1043
  );
599
1044
  }
600
1045
  }
601
- const Pt = (n) => {
602
- const t = f.fromChainOrSignature(n);
603
- switch (n) {
604
- case i.Bitcoin:
605
- case i.Litecoin:
606
- case i.BitcoinCash:
607
- return t.add(10001);
608
- case i.Dogecoin:
609
- return t.add(100000001);
610
- case i.Avalanche:
611
- case i.Ethereum:
612
- return t.add(10 * 10 ** 9);
613
- case i.THORChain:
614
- case i.Maya:
615
- return t.add(0);
1046
+ function Vt(e) {
1047
+ const t = g.fromChainOrSignature(e);
1048
+ switch (e) {
1049
+ case l.Bitcoin:
1050
+ case l.Litecoin:
1051
+ case l.BitcoinCash:
1052
+ return t.set(10001e-8);
1053
+ case l.Dogecoin:
1054
+ return t.set(1.00000001);
1055
+ case l.Avalanche:
1056
+ case l.Ethereum:
1057
+ return t.set(1e-8);
1058
+ case l.THORChain:
1059
+ case l.Maya:
1060
+ return t.set(0);
1061
+ case l.Cosmos:
1062
+ return t.set(1e-6);
616
1063
  default:
617
- return t.add(1);
1064
+ return t.set(1e-8);
618
1065
  }
619
- }, q = (n) => {
620
- const t = n.slice(0, 14).includes("/"), e = n.includes(".") ? n : `${i.THORChain}.${n}`, [r, s] = e.split("."), [a, c] = s.split("-");
1066
+ }
1067
+ async function J(e, t = 0) {
1068
+ dt(e);
1069
+ const n = w.get(e.toUpperCase()), r = (n == null ? void 0 : n.decimal) || await it(F(e));
1070
+ return n || w.set(e.toUpperCase(), { identifier: e, decimal: r }), new g({ decimal: r, value: V(t, r), identifier: e });
1071
+ }
1072
+ function he(e, t = 0) {
1073
+ const [n, r] = e.split(".")[0].toUpperCase() === l.THORChain ? e.split(".").slice(1).join().split("/") : e.split("/");
1074
+ if (!n || !r)
1075
+ throw new Error("Invalid asset identifier");
1076
+ return new g({
1077
+ decimal: 8,
1078
+ value: V(t, 8),
1079
+ identifier: `${l.THORChain}.${n}/${r}`
1080
+ });
1081
+ }
1082
+ function V(e, t) {
1083
+ return typeof e == "bigint" ? G({ value: e, bigIntDecimal: t, decimal: t }) : e;
1084
+ }
1085
+ function F(e) {
1086
+ const t = e.slice(0, 14).includes("/"), [n, r] = e.split(".")[0].toUpperCase() === l.THORChain ? e.split(".").slice(1).join().split("/") : e.split("/");
1087
+ if (t && (!n || !r))
1088
+ throw new Error("Invalid asset identifier");
1089
+ const s = e.includes(".") && !t ? e : `${l.THORChain}.${r}`, [i, ...a] = s.split("."), [c, o] = (t ? r : a.join(".")).split("-"), _ = t ? r : a.join(".");
621
1090
  return {
622
- address: c == null ? void 0 : c.toLowerCase(),
623
- chain: r,
624
- isGasAsset: dt({ chain: r, symbol: s }),
1091
+ address: o == null ? void 0 : o.toLowerCase(),
1092
+ chain: i,
1093
+ isGasAsset: fe({ chain: i, symbol: _ }),
625
1094
  isSynthetic: t,
626
- symbol: c ? `${a}-${(c == null ? void 0 : c.toLowerCase()) ?? ""}` : s,
627
- ticker: t ? s : a
1095
+ symbol: (t ? `${n}/` : "") + (o ? `${c}-${(o == null ? void 0 : o.toLowerCase()) ?? ""}` : _),
1096
+ ticker: c
628
1097
  };
629
- }, wt = {
1098
+ }
1099
+ const At = {
630
1100
  /**
631
1101
  * Core
632
1102
  */
@@ -647,6 +1117,7 @@ const Pt = (n) => {
647
1117
  core_wallet_trezor_not_installed: 10106,
648
1118
  core_wallet_keplr_not_installed: 10107,
649
1119
  core_wallet_okx_not_installed: 10108,
1120
+ core_wallet_keepkey_not_installed: 10109,
650
1121
  /**
651
1122
  * Core - Swap
652
1123
  */
@@ -673,52 +1144,71 @@ const Pt = (n) => {
673
1144
  core_transaction_deposit_to_pool_error: 10310,
674
1145
  core_transaction_deposit_insufficient_funds_error: 10311,
675
1146
  core_transaction_deposit_gas_error: 10312,
676
- core_transaction_deposit_server_error: 10313,
1147
+ core_transaction_invalid_sender_address: 10313,
1148
+ core_transaction_deposit_server_error: 10314,
1149
+ core_transaction_user_rejected: 10315,
677
1150
  /**
678
1151
  * Wallets
679
1152
  */
680
1153
  wallet_ledger_connection_error: 20001,
1154
+ wallet_ledger_connection_claimed: 20002,
1155
+ wallet_ledger_get_address_error: 20003,
1156
+ wallet_ledger_device_not_found: 20004,
1157
+ wallet_ledger_device_locked: 20005,
681
1158
  /**
682
1159
  * Helpers
683
1160
  */
684
1161
  helpers_number_different_decimals: 99101
685
1162
  };
686
- class Q extends Error {
687
- constructor(t, e) {
688
- console.error(e), super(t, { cause: { code: wt[t], message: t } }), Object.setPrototypeOf(this, Q.prototype);
1163
+ class Ce extends Error {
1164
+ constructor(t, n) {
1165
+ n && console.error(n, { stack: n == null ? void 0 : n.stack, message: n == null ? void 0 : n.message }), super(t, { cause: { code: At[t], message: t } }), Object.setPrototypeOf(this, Ce.prototype);
689
1166
  }
690
1167
  }
691
- class bt extends y {
1168
+ class I extends W {
692
1169
  eq(t) {
693
1170
  return this.eqValue(t);
694
1171
  }
1172
+ static fromBigInt(t, n) {
1173
+ return new I({
1174
+ decimal: n,
1175
+ value: G({ value: t, bigIntDecimal: n, decimal: n })
1176
+ });
1177
+ }
695
1178
  }
696
1179
  export {
697
- f as AssetValue,
698
- y as BigIntArithmetics,
699
- Q as SwapKitError,
700
- bt as SwapKitNumber,
701
- yt as assetFromString,
702
- Ct as derivationPathToString,
703
- Et as filterAssets,
704
- U as formatBigIntToSafeValue,
705
- Bt as gasFeeMultiplier,
706
- mt as getAssetType,
707
- pt as getAsymmetricAssetShare,
708
- Mt as getAsymmetricAssetWithdrawAmount,
709
- _t as getAsymmetricRuneShare,
710
- Ot as getAsymmetricRuneWithdrawAmount,
711
- ht as getCommonAssetInfo,
712
- K as getDecimal,
713
- Rt as getEstimatedPoolShare,
714
- kt as getLiquiditySlippage,
715
- Ht as getMemoFor,
716
- Pt as getMinAmountByChain,
717
- Tt as getRequest,
718
- ft as getSymmetricPoolShare,
719
- Nt as getSymmetricWithdraw,
720
- vt as getTHORNameCost,
721
- dt as isGasAsset,
722
- at as postRequest,
723
- Vt as validateTHORName
1180
+ m as ApiEndpoints,
1181
+ g as AssetValue,
1182
+ W as BigIntArithmetics,
1183
+ S as RequestClient,
1184
+ et as StreamingSwapProgressStatus,
1185
+ Et as SwapKitApi,
1186
+ Ce as SwapKitError,
1187
+ I as SwapKitNumber,
1188
+ ze as TransactionType,
1189
+ Ze as TxStatus,
1190
+ It as assetFromString,
1191
+ Re as defaultRequestHeaders,
1192
+ wt as derivationPathToString,
1193
+ ft as filterAssets,
1194
+ G as formatBigIntToSafeValue,
1195
+ Rt as gasFeeMultiplier,
1196
+ ot as getAssetType,
1197
+ _t as getAsymmetricAssetShare,
1198
+ Ct as getAsymmetricAssetWithdrawAmount,
1199
+ ut as getAsymmetricRuneShare,
1200
+ Nt as getAsymmetricRuneWithdrawAmount,
1201
+ at as getCommonAssetInfo,
1202
+ it as getDecimal,
1203
+ Ot as getEstimatedPoolShare,
1204
+ Dt as getLiquiditySlippage,
1205
+ Pt as getMemoFor,
1206
+ Vt as getMinAmountByChain,
1207
+ ht as getSymmetricPoolShare,
1208
+ gt as getSymmetricWithdraw,
1209
+ bt as getTHORNameCost,
1210
+ fe as isGasAsset,
1211
+ mt as setRequestClientConfig,
1212
+ yt as validateTHORName
724
1213
  };
1214
+ //# sourceMappingURL=index.es.js.map