@swapkit/helpers 1.0.0-rc.71 → 1.0.0-rc.73
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +32 -19
- package/dist/index.es.js +376 -361
- package/dist/index.es.js.map +1 -1
- package/package.json +12 -16
- package/src/helpers/__tests__/asset.test.ts +64 -62
- package/src/helpers/__tests__/memo.test.ts +42 -40
- package/src/helpers/__tests__/others.test.ts +31 -31
- package/src/helpers/asset.ts +53 -52
- package/src/helpers/liquidity.ts +9 -9
- package/src/helpers/memo.ts +17 -18
- package/src/helpers/others.ts +3 -3
- package/src/helpers/validators.ts +5 -5
- package/src/index.ts +9 -9
- package/src/modules/__tests__/assetValue.test.ts +187 -173
- package/src/modules/__tests__/bigIntArithmetics.test.ts +8 -8
- package/src/modules/__tests__/swapKitNumber.test.ts +232 -232
- package/src/modules/assetValue.ts +41 -41
- package/src/modules/bigIntArithmetics.ts +86 -86
- package/src/modules/swapKitError.ts +18 -2
- package/src/modules/swapKitNumber.ts +1 -1
- package/src/types.ts +13 -13
package/dist/index.es.js
CHANGED
|
@@ -1,44 +1,42 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
var $e = Object.defineProperty;
|
|
2
|
+
var ve = (e, t, n) => t in e ? $e(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var _ = (e, t, n) => (ve(e, typeof t != "symbol" ? t + "" : t, n), n), Ie = (e, t, n) => {
|
|
4
4
|
if (!t.has(e))
|
|
5
5
|
throw TypeError("Cannot " + n);
|
|
6
6
|
};
|
|
7
|
-
var
|
|
7
|
+
var R = (e, t, n) => {
|
|
8
8
|
if (t.has(e))
|
|
9
9
|
throw TypeError("Cannot add the same private member more than once");
|
|
10
10
|
t instanceof WeakSet ? t.add(e) : t.set(e, n);
|
|
11
11
|
};
|
|
12
|
-
var
|
|
13
|
-
import { FeeOption as
|
|
14
|
-
var
|
|
15
|
-
|
|
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 || {}), ne = /* @__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))(ne || {}), 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 || {}), f = /* @__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))(f || {});
|
|
17
|
-
const q = Object.values(j), $e = Object.keys(j), re = q.reduce(
|
|
12
|
+
var p = (e, t, n) => (Ie(e, t, "access private method"), n);
|
|
13
|
+
import { FeeOption as K, BaseDecimal as d, Chain as l, EVMChains as Ne, ChainToRPC as Be, MemoType as C, ChainToChainId as De } from "@swapkit/types";
|
|
14
|
+
var F = /* @__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))(F || {}), ne = /* @__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))(ne || {}), 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 || {}), S = /* @__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))(S || {});
|
|
15
|
+
const G = Object.values(F), Ve = Object.keys(F), re = G.reduce(
|
|
18
16
|
(e, t) => {
|
|
19
|
-
const n =
|
|
17
|
+
const n = Ve.find((r) => F[r] === t);
|
|
20
18
|
return n && (e[t] = n), e;
|
|
21
19
|
},
|
|
22
20
|
{}
|
|
23
21
|
);
|
|
24
|
-
|
|
22
|
+
G.reduce(
|
|
25
23
|
(e, t) => (e[t] = ne[re[t]], e),
|
|
26
24
|
{}
|
|
27
25
|
);
|
|
28
|
-
|
|
26
|
+
G.reduce(
|
|
29
27
|
(e, t) => (e[t] = de[re[t]], e),
|
|
30
28
|
{}
|
|
31
29
|
);
|
|
32
|
-
|
|
30
|
+
G.reduce(
|
|
33
31
|
(e, t) => {
|
|
34
32
|
const n = `${re[t]}Hex`;
|
|
35
33
|
return e[t] = ne[n], e;
|
|
36
34
|
},
|
|
37
35
|
{}
|
|
38
36
|
);
|
|
39
|
-
class
|
|
37
|
+
class ae extends Error {
|
|
40
38
|
constructor(t, n, r) {
|
|
41
|
-
const s = t.status || t.status === 0 ? t.status : "", i = t.statusText || "",
|
|
39
|
+
const s = t.status || t.status === 0 ? t.status : "", i = t.statusText || "", o = `${s} ${i}`.trim(), c = o ? `status code ${o}` : "an unknown error";
|
|
42
40
|
super(`Request failed with ${c}`), Object.defineProperty(this, "response", {
|
|
43
41
|
enumerable: !0,
|
|
44
42
|
configurable: !0,
|
|
@@ -57,7 +55,7 @@ class ce extends Error {
|
|
|
57
55
|
}), this.name = "HTTPError", this.response = t, this.request = n, this.options = r;
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
|
-
class
|
|
58
|
+
class pe extends Error {
|
|
61
59
|
constructor(t) {
|
|
62
60
|
super("Request timed out"), Object.defineProperty(this, "request", {
|
|
63
61
|
enumerable: !0,
|
|
@@ -67,28 +65,28 @@ class Te extends Error {
|
|
|
67
65
|
}), this.name = "TimeoutError", this.request = t;
|
|
68
66
|
}
|
|
69
67
|
}
|
|
70
|
-
const
|
|
68
|
+
const M = (e) => e !== null && typeof e == "object", x = (...e) => {
|
|
71
69
|
for (const t of e)
|
|
72
|
-
if ((!
|
|
70
|
+
if ((!M(t) || Array.isArray(t)) && t !== void 0)
|
|
73
71
|
throw new TypeError("The `options` argument must be an object");
|
|
74
72
|
return se({}, ...e);
|
|
75
|
-
},
|
|
73
|
+
}, me = (e = {}, t = {}) => {
|
|
76
74
|
const n = new globalThis.Headers(e), r = t instanceof globalThis.Headers, s = new globalThis.Headers(t);
|
|
77
|
-
for (const [i,
|
|
78
|
-
r &&
|
|
75
|
+
for (const [i, o] of s.entries())
|
|
76
|
+
r && o === "undefined" || o === void 0 ? n.delete(i) : n.set(i, o);
|
|
79
77
|
return n;
|
|
80
78
|
}, se = (...e) => {
|
|
81
79
|
let t = {}, n = {};
|
|
82
80
|
for (const r of e)
|
|
83
81
|
if (Array.isArray(r))
|
|
84
82
|
Array.isArray(t) || (t = []), t = [...t, ...r];
|
|
85
|
-
else if (
|
|
83
|
+
else if (M(r)) {
|
|
86
84
|
for (let [s, i] of Object.entries(r))
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
M(i) && s in t && (i = se(t[s], i)), t = { ...t, [s]: i };
|
|
86
|
+
M(r.headers) && (n = me(n, r.headers), t.headers = n);
|
|
89
87
|
}
|
|
90
88
|
return t;
|
|
91
|
-
},
|
|
89
|
+
}, He = (() => {
|
|
92
90
|
let e = !1, t = !1;
|
|
93
91
|
const n = typeof globalThis.ReadableStream == "function", r = typeof globalThis.Request == "function";
|
|
94
92
|
return n && r && (t = new globalThis.Request("https://empty.invalid", {
|
|
@@ -99,13 +97,13 @@ const x = (e) => e !== null && typeof e == "object", M = (...e) => {
|
|
|
99
97
|
return e = !0, "half";
|
|
100
98
|
}
|
|
101
99
|
}).headers.has("Content-Type")), e && !t;
|
|
102
|
-
})(),
|
|
100
|
+
})(), xe = typeof globalThis.AbortController == "function", ke = typeof globalThis.ReadableStream == "function", Me = typeof globalThis.FormData == "function", _e = ["get", "post", "put", "patch", "head", "delete"], Le = {
|
|
103
101
|
json: "application/json",
|
|
104
102
|
text: "text/*",
|
|
105
103
|
formData: "multipart/form-data",
|
|
106
104
|
arrayBuffer: "*/*",
|
|
107
105
|
blob: "*/*"
|
|
108
|
-
},
|
|
106
|
+
}, J = 2147483647, Te = Symbol("stop"), We = {
|
|
109
107
|
json: !0,
|
|
110
108
|
parseJson: !0,
|
|
111
109
|
searchParams: !0,
|
|
@@ -116,7 +114,7 @@ const x = (e) => e !== null && typeof e == "object", M = (...e) => {
|
|
|
116
114
|
throwHttpErrors: !0,
|
|
117
115
|
onDownloadProgress: !0,
|
|
118
116
|
fetch: !0
|
|
119
|
-
},
|
|
117
|
+
}, Ue = {
|
|
120
118
|
method: !0,
|
|
121
119
|
headers: !0,
|
|
122
120
|
body: !0,
|
|
@@ -132,18 +130,18 @@ const x = (e) => e !== null && typeof e == "object", M = (...e) => {
|
|
|
132
130
|
window: !0,
|
|
133
131
|
dispatcher: !0,
|
|
134
132
|
duplex: !0
|
|
135
|
-
},
|
|
133
|
+
}, je = (e) => _e.includes(e) ? e.toUpperCase() : e, qe = ["get", "put", "head", "delete", "options", "trace"], Fe = [408, 413, 429, 500, 502, 503, 504], fe = [413, 429, 503], ce = {
|
|
136
134
|
limit: 2,
|
|
137
|
-
methods:
|
|
138
|
-
statusCodes:
|
|
139
|
-
afterStatusCodes:
|
|
135
|
+
methods: qe,
|
|
136
|
+
statusCodes: Fe,
|
|
137
|
+
afterStatusCodes: fe,
|
|
140
138
|
maxRetryAfter: Number.POSITIVE_INFINITY,
|
|
141
139
|
backoffLimit: Number.POSITIVE_INFINITY,
|
|
142
140
|
delay: (e) => 0.3 * 2 ** (e - 1) * 1e3
|
|
143
|
-
},
|
|
141
|
+
}, Ge = (e = {}) => {
|
|
144
142
|
if (typeof e == "number")
|
|
145
143
|
return {
|
|
146
|
-
...
|
|
144
|
+
...ce,
|
|
147
145
|
limit: e
|
|
148
146
|
};
|
|
149
147
|
if (e.methods && !Array.isArray(e.methods))
|
|
@@ -151,18 +149,18 @@ const x = (e) => e !== null && typeof e == "object", M = (...e) => {
|
|
|
151
149
|
if (e.statusCodes && !Array.isArray(e.statusCodes))
|
|
152
150
|
throw new Error("retry.statusCodes must be an array");
|
|
153
151
|
return {
|
|
154
|
-
...
|
|
152
|
+
...ce,
|
|
155
153
|
...e,
|
|
156
|
-
afterStatusCodes:
|
|
154
|
+
afterStatusCodes: fe
|
|
157
155
|
};
|
|
158
156
|
};
|
|
159
|
-
async function
|
|
157
|
+
async function Xe(e, t, n, r) {
|
|
160
158
|
return new Promise((s, i) => {
|
|
161
|
-
const
|
|
162
|
-
n && n.abort(), i(new
|
|
159
|
+
const o = setTimeout(() => {
|
|
160
|
+
n && n.abort(), i(new pe(e));
|
|
163
161
|
}, r.timeout);
|
|
164
162
|
r.fetch(e, t).then(s).catch(i).then(() => {
|
|
165
|
-
clearTimeout(
|
|
163
|
+
clearTimeout(o);
|
|
166
164
|
});
|
|
167
165
|
});
|
|
168
166
|
}
|
|
@@ -180,46 +178,46 @@ async function Ke(e, { signal: t }) {
|
|
|
180
178
|
const Je = (e, t) => {
|
|
181
179
|
const n = {};
|
|
182
180
|
for (const r in t)
|
|
183
|
-
!(r in
|
|
181
|
+
!(r in Ue) && !(r in We) && !(r in e) && (n[r] = t[r]);
|
|
184
182
|
return n;
|
|
185
183
|
};
|
|
186
|
-
class
|
|
184
|
+
class W {
|
|
187
185
|
static create(t, n) {
|
|
188
|
-
const r = new
|
|
189
|
-
if (typeof r._options.timeout == "number" && r._options.timeout >
|
|
190
|
-
throw new RangeError(`The \`timeout\` option cannot be greater than ${
|
|
186
|
+
const r = new W(t, n), s = async () => {
|
|
187
|
+
if (typeof r._options.timeout == "number" && r._options.timeout > J)
|
|
188
|
+
throw new RangeError(`The \`timeout\` option cannot be greater than ${J}`);
|
|
191
189
|
await Promise.resolve();
|
|
192
|
-
let
|
|
190
|
+
let o = await r._fetch();
|
|
193
191
|
for (const c of r._options.hooks.afterResponse) {
|
|
194
|
-
const
|
|
195
|
-
|
|
192
|
+
const a = await c(r.request, r._options, r._decorateResponse(o.clone()));
|
|
193
|
+
a instanceof globalThis.Response && (o = a);
|
|
196
194
|
}
|
|
197
|
-
if (r._decorateResponse(
|
|
198
|
-
let c = new
|
|
199
|
-
for (const
|
|
200
|
-
c = await
|
|
195
|
+
if (r._decorateResponse(o), !o.ok && r._options.throwHttpErrors) {
|
|
196
|
+
let c = new ae(o, r.request, r._options);
|
|
197
|
+
for (const a of r._options.hooks.beforeError)
|
|
198
|
+
c = await a(c);
|
|
201
199
|
throw c;
|
|
202
200
|
}
|
|
203
201
|
if (r._options.onDownloadProgress) {
|
|
204
202
|
if (typeof r._options.onDownloadProgress != "function")
|
|
205
203
|
throw new TypeError("The `onDownloadProgress` option must be a function");
|
|
206
|
-
if (!
|
|
204
|
+
if (!ke)
|
|
207
205
|
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
|
|
208
|
-
return r._stream(
|
|
206
|
+
return r._stream(o.clone(), r._options.onDownloadProgress);
|
|
209
207
|
}
|
|
210
|
-
return
|
|
208
|
+
return o;
|
|
211
209
|
}, i = r._options.retry.methods.includes(r.request.method.toLowerCase()) ? r._retry(s) : s();
|
|
212
|
-
for (const [
|
|
213
|
-
i[
|
|
210
|
+
for (const [o, c] of Object.entries(Le))
|
|
211
|
+
i[o] = async () => {
|
|
214
212
|
r.request.headers.set("accept", r.request.headers.get("accept") || c);
|
|
215
|
-
const
|
|
216
|
-
if (
|
|
217
|
-
if (
|
|
213
|
+
const a = (await i).clone();
|
|
214
|
+
if (o === "json") {
|
|
215
|
+
if (a.status === 204 || (await a.clone().arrayBuffer()).byteLength === 0)
|
|
218
216
|
return "";
|
|
219
217
|
if (n.parseJson)
|
|
220
|
-
return n.parseJson(await
|
|
218
|
+
return n.parseJson(await a.text());
|
|
221
219
|
}
|
|
222
|
-
return o
|
|
220
|
+
return a[o]();
|
|
223
221
|
};
|
|
224
222
|
return i;
|
|
225
223
|
}
|
|
@@ -254,17 +252,17 @@ class G {
|
|
|
254
252
|
// TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208
|
|
255
253
|
credentials: this._input.credentials || "same-origin",
|
|
256
254
|
...n,
|
|
257
|
-
headers:
|
|
255
|
+
headers: me(this._input.headers, n.headers),
|
|
258
256
|
hooks: se({
|
|
259
257
|
beforeRequest: [],
|
|
260
258
|
beforeRetry: [],
|
|
261
259
|
beforeError: [],
|
|
262
260
|
afterResponse: []
|
|
263
261
|
}, n.hooks),
|
|
264
|
-
method:
|
|
262
|
+
method: je(n.method ?? this._input.method),
|
|
265
263
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
266
264
|
prefixUrl: String(n.prefixUrl || ""),
|
|
267
|
-
retry:
|
|
265
|
+
retry: Ge(n.retry),
|
|
268
266
|
throwHttpErrors: n.throwHttpErrors !== !1,
|
|
269
267
|
timeout: n.timeout ?? 1e4,
|
|
270
268
|
fetch: n.fetch ?? globalThis.fetch.bind(globalThis)
|
|
@@ -275,7 +273,7 @@ class G {
|
|
|
275
273
|
throw new Error("`input` must not begin with a slash when using `prefixUrl`");
|
|
276
274
|
this._options.prefixUrl.endsWith("/") || (this._options.prefixUrl += "/"), this._input = this._options.prefixUrl + this._input;
|
|
277
275
|
}
|
|
278
|
-
if (
|
|
276
|
+
if (xe) {
|
|
279
277
|
if (this.abortController = new globalThis.AbortController(), this._options.signal) {
|
|
280
278
|
const r = this._options.signal;
|
|
281
279
|
this._options.signal.addEventListener("abort", () => {
|
|
@@ -284,15 +282,15 @@ class G {
|
|
|
284
282
|
}
|
|
285
283
|
this._options.signal = this.abortController.signal;
|
|
286
284
|
}
|
|
287
|
-
if (
|
|
285
|
+
if (He && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
|
|
288
286
|
const r = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), s = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, r);
|
|
289
|
-
(
|
|
287
|
+
(Me && 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
288
|
}
|
|
291
289
|
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
290
|
}
|
|
293
291
|
_calculateRetryDelay(t) {
|
|
294
|
-
if (this._retryCount++, this._retryCount <= this._options.retry.limit && !(t instanceof
|
|
295
|
-
if (t instanceof
|
|
292
|
+
if (this._retryCount++, this._retryCount <= this._options.retry.limit && !(t instanceof pe)) {
|
|
293
|
+
if (t instanceof ae) {
|
|
296
294
|
if (!this._options.retry.statusCodes.includes(t.response.status))
|
|
297
295
|
return 0;
|
|
298
296
|
const r = t.response.headers.get("Retry-After");
|
|
@@ -315,7 +313,7 @@ class G {
|
|
|
315
313
|
try {
|
|
316
314
|
return await t();
|
|
317
315
|
} catch (n) {
|
|
318
|
-
const r = Math.min(this._calculateRetryDelay(n),
|
|
316
|
+
const r = Math.min(this._calculateRetryDelay(n), J);
|
|
319
317
|
if (r !== 0 && this._retryCount > 0) {
|
|
320
318
|
await Ke(r, { signal: this._options.signal });
|
|
321
319
|
for (const s of this._options.hooks.beforeRetry)
|
|
@@ -324,7 +322,7 @@ class G {
|
|
|
324
322
|
options: this._options,
|
|
325
323
|
error: n,
|
|
326
324
|
retryCount: this._retryCount
|
|
327
|
-
}) ===
|
|
325
|
+
}) === Te)
|
|
328
326
|
return;
|
|
329
327
|
return this._retry(t);
|
|
330
328
|
}
|
|
@@ -342,7 +340,7 @@ class G {
|
|
|
342
340
|
return r;
|
|
343
341
|
}
|
|
344
342
|
const t = Je(this.request, this._options);
|
|
345
|
-
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) :
|
|
343
|
+
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Xe(this.request.clone(), t, this.abortController, this._options);
|
|
346
344
|
}
|
|
347
345
|
/* istanbul ignore next */
|
|
348
346
|
_stream(t, n) {
|
|
@@ -354,20 +352,20 @@ class G {
|
|
|
354
352
|
headers: t.headers
|
|
355
353
|
})) : new globalThis.Response(new globalThis.ReadableStream({
|
|
356
354
|
async start(i) {
|
|
357
|
-
const
|
|
355
|
+
const o = t.body.getReader();
|
|
358
356
|
n && n({ percent: 0, transferredBytes: 0, totalBytes: r }, new Uint8Array());
|
|
359
357
|
async function c() {
|
|
360
|
-
const { done:
|
|
361
|
-
if (
|
|
358
|
+
const { done: a, value: u } = await o.read();
|
|
359
|
+
if (a) {
|
|
362
360
|
i.close();
|
|
363
361
|
return;
|
|
364
362
|
}
|
|
365
363
|
if (n) {
|
|
366
|
-
s +=
|
|
364
|
+
s += u.byteLength;
|
|
367
365
|
const h = r === 0 ? 0 : s / r;
|
|
368
|
-
n({ percent: h, transferredBytes: s, totalBytes: r },
|
|
366
|
+
n({ percent: h, transferredBytes: s, totalBytes: r }, u);
|
|
369
367
|
}
|
|
370
|
-
i.enqueue(
|
|
368
|
+
i.enqueue(u), await c();
|
|
371
369
|
}
|
|
372
370
|
await c();
|
|
373
371
|
}
|
|
@@ -380,49 +378,53 @@ class G {
|
|
|
380
378
|
}
|
|
381
379
|
/*! MIT License © Sindre Sorhus */
|
|
382
380
|
const z = (e) => {
|
|
383
|
-
const t = (n, r) =>
|
|
384
|
-
for (const n of
|
|
385
|
-
t[n] = (r, s) =>
|
|
386
|
-
return t.create = (n) => z(
|
|
387
|
-
},
|
|
388
|
-
let
|
|
389
|
-
const
|
|
390
|
-
CachedPrices: `${
|
|
391
|
-
GasRates: `${
|
|
392
|
-
Quote: `${
|
|
393
|
-
Txn: `${
|
|
394
|
-
TokenlistProviders: `${
|
|
395
|
-
TokenList: `${
|
|
396
|
-
Thorname: `${
|
|
397
|
-
},
|
|
398
|
-
|
|
381
|
+
const t = (n, r) => W.create(n, x(e, r));
|
|
382
|
+
for (const n of _e)
|
|
383
|
+
t[n] = (r, s) => W.create(r, x(e, s, { method: n }));
|
|
384
|
+
return t.create = (n) => z(x(n)), t.extend = (n) => z(x(e, n)), t.stop = Te, t;
|
|
385
|
+
}, ge = z();
|
|
386
|
+
let L;
|
|
387
|
+
const f = {
|
|
388
|
+
CachedPrices: `${S.ThorswapApi}/tokenlist/cached-price`,
|
|
389
|
+
GasRates: `${S.ThorswapApi}/resource-worker/gasPrice/getAll`,
|
|
390
|
+
Quote: `${S.ThorswapApi}/aggregator/tokens/quote`,
|
|
391
|
+
Txn: `${S.ThorswapApi}/apiusage/v2/txn`,
|
|
392
|
+
TokenlistProviders: `${S.ThorswapApi}/tokenlist/providers`,
|
|
393
|
+
TokenList: `${S.ThorswapStatic}/token-list`,
|
|
394
|
+
Thorname: `${S.ThorswapApi}/thorname`
|
|
395
|
+
}, Ae = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, le = () => L || (L = ge.create({ headers: Ae }), L), ft = ({ apiKey: e, ...t }) => {
|
|
396
|
+
L = ge.create({
|
|
399
397
|
...t,
|
|
400
|
-
headers: { ...
|
|
398
|
+
headers: { ...Ae, ...t.headers, "x-api-key": e }
|
|
401
399
|
});
|
|
402
|
-
},
|
|
403
|
-
get: (e, t) =>
|
|
404
|
-
post: (e, t) =>
|
|
405
|
-
},
|
|
406
|
-
const n = new URLSearchParams()
|
|
407
|
-
|
|
400
|
+
}, T = {
|
|
401
|
+
get: (e, t) => le().get(e, t).json(),
|
|
402
|
+
post: (e, t) => le().post(e, t).json()
|
|
403
|
+
}, Ye = ({ tokens: e, ...t }) => {
|
|
404
|
+
const n = new URLSearchParams(), r = e.filter(
|
|
405
|
+
(s, i, o) => o.findIndex((c) => c === s) === i
|
|
406
|
+
);
|
|
407
|
+
for (const s of r)
|
|
408
|
+
n.append("tokens", JSON.stringify(s));
|
|
409
|
+
return t.metadata && n.append("metadata", "true"), t.lookup && n.append("lookup", "true"), t.sparkline && n.append("sparkline", "true"), T.post(f.CachedPrices, {
|
|
408
410
|
body: n.toString(),
|
|
409
411
|
headers: { "Content-Type": "application/x-www-form-urlencoded" }
|
|
410
412
|
});
|
|
411
|
-
},
|
|
412
|
-
getCachedPrices:
|
|
413
|
-
getQuote: (e) =>
|
|
414
|
-
getGasRates: () =>
|
|
415
|
-
getTxnDetails: (e) =>
|
|
416
|
-
getTokenlistProviders: () =>
|
|
417
|
-
getTokenList: (e) =>
|
|
418
|
-
getThornameAddresses: (e) =>
|
|
419
|
-
getThornameRegisteredChains: (e) =>
|
|
420
|
-
getThornameRlookup: (e, t) =>
|
|
413
|
+
}, gt = {
|
|
414
|
+
getCachedPrices: Ye,
|
|
415
|
+
getQuote: (e) => T.get(f.Quote, { searchParams: e }),
|
|
416
|
+
getGasRates: () => T.get(f.GasRates),
|
|
417
|
+
getTxnDetails: (e) => T.get(f.Txn, { searchParams: e }),
|
|
418
|
+
getTokenlistProviders: () => T.get(f.TokenlistProviders),
|
|
419
|
+
getTokenList: (e) => T.get(`${f.TokenList}/${e}.json`),
|
|
420
|
+
getThornameAddresses: (e) => T.get(`${f.Thorname}/${e}`),
|
|
421
|
+
getThornameRegisteredChains: (e) => T.get(`${f.Thorname}/chains/${e}`),
|
|
422
|
+
getThornameRlookup: (e, t) => T.get(`${f.Thorname}/rlookup`, { searchParams: { address: e, chain: t } })
|
|
421
423
|
};
|
|
422
|
-
var
|
|
423
|
-
const
|
|
424
|
+
var Qe = /* @__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))(Qe || {}), 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 || {}), Ze = /* @__PURE__ */ ((e) => (e[e.NOT_STARTED = 0] = "NOT_STARTED", e[e.SUCCESS = 1] = "SUCCESS", e[e.REFUNDED = 2] = "REFUNDED", e))(Ze || {});
|
|
425
|
+
const et = "0x313ce567", Ce = async ({ chain: e, to: t }) => {
|
|
424
426
|
try {
|
|
425
|
-
const { result: n } = await
|
|
427
|
+
const { result: n } = await T.post(Be[e], {
|
|
426
428
|
headers: {
|
|
427
429
|
accept: "*/*",
|
|
428
430
|
"content-type": "application/json",
|
|
@@ -432,37 +434,37 @@ const tt = "0x313ce567", Ie = async ({ chain: e, to: t }) => {
|
|
|
432
434
|
id: 44,
|
|
433
435
|
jsonrpc: "2.0",
|
|
434
436
|
method: "eth_call",
|
|
435
|
-
params: [{ to: t.toLowerCase(), data:
|
|
437
|
+
params: [{ to: t.toLowerCase(), data: et }, "latest"]
|
|
436
438
|
})
|
|
437
439
|
});
|
|
438
440
|
return parseInt(BigInt(n).toString());
|
|
439
441
|
} catch (n) {
|
|
440
442
|
return console.error(n), d[e];
|
|
441
443
|
}
|
|
442
|
-
},
|
|
444
|
+
}, tt = (e) => {
|
|
443
445
|
if (e === l.Ethereum)
|
|
444
446
|
return d.ETH;
|
|
445
447
|
const [, t] = e.split("-");
|
|
446
|
-
return t != null && t.startsWith("0x") ?
|
|
447
|
-
},
|
|
448
|
+
return t != null && t.startsWith("0x") ? Ce({ chain: l.Ethereum, to: t }) : d.ETH;
|
|
449
|
+
}, nt = (e) => {
|
|
448
450
|
const [, t] = e.split("-");
|
|
449
|
-
return t != null && t.startsWith("0x") ?
|
|
450
|
-
},
|
|
451
|
+
return t != null && t.startsWith("0x") ? Ce({ chain: l.Avalanche, to: t.toLowerCase() }) : d.AVAX;
|
|
452
|
+
}, rt = (e) => e === l.BinanceSmartChain ? d.BSC : d.BSC, st = ({ chain: e, symbol: t }) => {
|
|
451
453
|
switch (e) {
|
|
452
454
|
case l.Ethereum:
|
|
453
|
-
return
|
|
455
|
+
return tt(t);
|
|
454
456
|
case l.Avalanche:
|
|
455
|
-
return
|
|
457
|
+
return nt(t);
|
|
456
458
|
case l.BinanceSmartChain:
|
|
457
|
-
return
|
|
459
|
+
return rt(t);
|
|
458
460
|
default:
|
|
459
461
|
return d[e];
|
|
460
462
|
}
|
|
461
|
-
},
|
|
462
|
-
[
|
|
463
|
-
[
|
|
464
|
-
[
|
|
465
|
-
},
|
|
463
|
+
}, At = {
|
|
464
|
+
[K.Average]: 1.2,
|
|
465
|
+
[K.Fast]: 1.5,
|
|
466
|
+
[K.Fastest]: 2
|
|
467
|
+
}, Se = ({ chain: e, symbol: t }) => {
|
|
466
468
|
switch (e) {
|
|
467
469
|
case l.Arbitrum:
|
|
468
470
|
case l.Optimism:
|
|
@@ -482,7 +484,7 @@ const tt = "0x313ce567", Ie = async ({ chain: e, to: t }) => {
|
|
|
482
484
|
default:
|
|
483
485
|
return t === e;
|
|
484
486
|
}
|
|
485
|
-
},
|
|
487
|
+
}, it = (e) => {
|
|
486
488
|
switch (e) {
|
|
487
489
|
case `${l.Ethereum}.THOR`:
|
|
488
490
|
return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
|
|
@@ -528,57 +530,57 @@ const tt = "0x313ce567", Ie = async ({ chain: e, to: t }) => {
|
|
|
528
530
|
default:
|
|
529
531
|
return "Native";
|
|
530
532
|
}
|
|
531
|
-
},
|
|
532
|
-
var
|
|
533
|
-
const [t, ...n] = e.split("."), r = e.includes("/"), s = n.join("."), i = (
|
|
533
|
+
}, Ct = (e) => {
|
|
534
|
+
var o;
|
|
535
|
+
const [t, ...n] = e.split("."), r = e.includes("/"), s = n.join("."), i = (o = s == null ? void 0 : s.split("-")) == null ? void 0 : o[0];
|
|
534
536
|
return { chain: t, symbol: s, ticker: i, synth: r };
|
|
535
|
-
},
|
|
537
|
+
}, at = new RegExp(
|
|
536
538
|
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
|
|
537
539
|
"gmi"
|
|
538
|
-
),
|
|
540
|
+
), ct = (e) => {
|
|
539
541
|
const [t, n] = e.split(".");
|
|
540
|
-
if (!
|
|
542
|
+
if (!Ne.includes(t))
|
|
541
543
|
return !0;
|
|
542
544
|
const [, r] = n.split("-");
|
|
543
|
-
return
|
|
544
|
-
},
|
|
545
|
+
return Se({ chain: t, symbol: n }) || !!r;
|
|
546
|
+
}, St = (e) => e.filter(({ chain: t, value: n, symbol: r }) => {
|
|
545
547
|
const s = `${t}.${r}`;
|
|
546
|
-
return !
|
|
548
|
+
return !at.test(s) && ct(s) && n !== "0";
|
|
547
549
|
});
|
|
548
|
-
function
|
|
550
|
+
function lt({
|
|
549
551
|
liquidityUnits: e,
|
|
550
552
|
poolUnits: t,
|
|
551
553
|
runeDepth: n
|
|
552
554
|
}) {
|
|
553
|
-
const r =
|
|
554
|
-
return
|
|
555
|
+
const r = m(e), s = m(t), i = m(n), o = r.mul(i), c = s.mul(s).mul(2), a = s.mul(r).mul(2), u = r.mul(r), h = s.mul(s).mul(s);
|
|
556
|
+
return o.mul(c.sub(a).add(u)).div(h);
|
|
555
557
|
}
|
|
556
|
-
function
|
|
558
|
+
function ut({
|
|
557
559
|
liquidityUnits: e,
|
|
558
560
|
poolUnits: t,
|
|
559
561
|
assetDepth: n
|
|
560
562
|
}) {
|
|
561
|
-
const r =
|
|
562
|
-
return h.div(
|
|
563
|
+
const r = m(e), s = m(t), i = m(n), o = r.mul(i), c = s.mul(s).mul(2), a = s.mul(r).mul(2), u = r.mul(r), h = o.mul(c.sub(a).add(u)), $ = s.mul(s).mul(s);
|
|
564
|
+
return h.div($);
|
|
563
565
|
}
|
|
564
|
-
function
|
|
566
|
+
function bt({
|
|
565
567
|
percent: e,
|
|
566
568
|
runeDepth: t,
|
|
567
569
|
liquidityUnits: n,
|
|
568
570
|
poolUnits: r
|
|
569
571
|
}) {
|
|
570
|
-
return
|
|
572
|
+
return lt({ runeDepth: t, liquidityUnits: n, poolUnits: r }).mul(e);
|
|
571
573
|
}
|
|
572
|
-
function
|
|
574
|
+
function yt({
|
|
573
575
|
percent: e,
|
|
574
576
|
assetDepth: t,
|
|
575
577
|
liquidityUnits: n,
|
|
576
578
|
poolUnits: r
|
|
577
579
|
}) {
|
|
578
|
-
return
|
|
580
|
+
return ut({ assetDepth: t, liquidityUnits: n, poolUnits: r }).mul(e);
|
|
579
581
|
}
|
|
580
|
-
function
|
|
581
|
-
return
|
|
582
|
+
function m(e) {
|
|
583
|
+
return g.fromBigInt(BigInt(e), d.THOR);
|
|
582
584
|
}
|
|
583
585
|
function ht({
|
|
584
586
|
liquidityUnits: e,
|
|
@@ -587,11 +589,11 @@ function ht({
|
|
|
587
589
|
assetDepth: r
|
|
588
590
|
}) {
|
|
589
591
|
return {
|
|
590
|
-
assetAmount:
|
|
591
|
-
runeAmount:
|
|
592
|
+
assetAmount: m(r).mul(e).div(t),
|
|
593
|
+
runeAmount: m(n).mul(e).div(t)
|
|
592
594
|
};
|
|
593
595
|
}
|
|
594
|
-
function
|
|
596
|
+
function wt({
|
|
595
597
|
liquidityUnits: e,
|
|
596
598
|
poolUnits: t,
|
|
597
599
|
runeDepth: n,
|
|
@@ -600,11 +602,11 @@ function gt({
|
|
|
600
602
|
}) {
|
|
601
603
|
return Object.fromEntries(
|
|
602
604
|
Object.entries(ht({ liquidityUnits: e, poolUnits: t, runeDepth: n, assetDepth: r })).map(
|
|
603
|
-
([i,
|
|
605
|
+
([i, o]) => [i, o.mul(s)]
|
|
604
606
|
)
|
|
605
607
|
);
|
|
606
608
|
}
|
|
607
|
-
function
|
|
609
|
+
function Rt({
|
|
608
610
|
runeDepth: e,
|
|
609
611
|
poolUnits: t,
|
|
610
612
|
assetDepth: n,
|
|
@@ -612,13 +614,13 @@ function Ot({
|
|
|
612
614
|
runeAmount: s,
|
|
613
615
|
assetAmount: i
|
|
614
616
|
}) {
|
|
615
|
-
const
|
|
617
|
+
const o = new g({ value: e, decimal: 8 }), c = new g({ value: n, decimal: 8 }), a = new g({ value: t, decimal: 8 }), u = new g({ value: s, decimal: 8 }), h = new g({ value: i, decimal: 8 }), $ = u.mul(c), ie = h.mul(o), we = u.mul(h), Re = o.mul(c), Ee = a.mul($.add(ie.add(we.mul(2)))), Pe = $.add(ie.add(Re.mul(2))), oe = Ee.div(Pe), X = m(r).add(oe);
|
|
616
618
|
if (oe.getBaseValue("number") === 0)
|
|
617
|
-
return X.div(
|
|
618
|
-
const
|
|
619
|
-
return X.div(
|
|
619
|
+
return X.div(a).getBaseValue("number");
|
|
620
|
+
const Oe = a.add(X);
|
|
621
|
+
return X.div(Oe).getBaseValue("number");
|
|
620
622
|
}
|
|
621
|
-
function
|
|
623
|
+
function Et({
|
|
622
624
|
runeAmount: e,
|
|
623
625
|
assetAmount: t,
|
|
624
626
|
runeDepth: n,
|
|
@@ -626,27 +628,27 @@ function Dt({
|
|
|
626
628
|
}) {
|
|
627
629
|
if (e === "0" || t === "0" || n === "0" || r === "0")
|
|
628
630
|
return 0;
|
|
629
|
-
const s =
|
|
630
|
-
return Math.abs(
|
|
631
|
+
const s = m(n), i = m(r), o = m(t), c = m(e), a = o.mul(s).sub(i.mul(c)), u = i.mul(c).add(s.mul(i));
|
|
632
|
+
return Math.abs(a.div(u).getBaseValue("number"));
|
|
631
633
|
}
|
|
632
634
|
const Pt = (e, t) => {
|
|
633
635
|
switch (e) {
|
|
634
|
-
case
|
|
635
|
-
case
|
|
636
|
+
case C.LEAVE:
|
|
637
|
+
case C.BOND: {
|
|
636
638
|
const { address: n } = t;
|
|
637
639
|
return `${e}:${n}`;
|
|
638
640
|
}
|
|
639
|
-
case
|
|
641
|
+
case C.UNBOND: {
|
|
640
642
|
const { address: n, unbondAmount: r } = t;
|
|
641
643
|
return `${e}:${n}:${r}`;
|
|
642
644
|
}
|
|
643
|
-
case
|
|
645
|
+
case C.THORNAME_REGISTER: {
|
|
644
646
|
const { name: n, chain: r, address: s, owner: i } = t;
|
|
645
647
|
return `${e}:${n}:${r}:${s}${i ? `:${i}` : ""}`;
|
|
646
648
|
}
|
|
647
|
-
case
|
|
649
|
+
case C.DEPOSIT: {
|
|
648
650
|
const { chain: n, symbol: r, address: s, singleSide: i } = t;
|
|
649
|
-
return i ? `${e}:${n}/${r}` : `${e}:${((c,
|
|
651
|
+
return i ? `${e}:${n}/${r}` : `${e}:${((c, a) => {
|
|
650
652
|
switch (c) {
|
|
651
653
|
case l.Litecoin:
|
|
652
654
|
return "l";
|
|
@@ -655,16 +657,16 @@ const Pt = (e, t) => {
|
|
|
655
657
|
case l.BitcoinCash:
|
|
656
658
|
return "c";
|
|
657
659
|
default:
|
|
658
|
-
return `${c}.${
|
|
660
|
+
return `${c}.${a}`;
|
|
659
661
|
}
|
|
660
662
|
})(n, r)}:${s || ""}`;
|
|
661
663
|
}
|
|
662
|
-
case
|
|
663
|
-
const { chain: n, ticker: r, symbol: s, basisPoints: i, targetAssetString:
|
|
664
|
-
return `${e}:${n}${c ? "/" : "."}${
|
|
664
|
+
case C.WITHDRAW: {
|
|
665
|
+
const { chain: n, ticker: r, symbol: s, basisPoints: i, targetAssetString: o, singleSide: c } = t, a = n === "ETH" && r !== "ETH" ? `${r}-${s.slice(-3)}` : s, u = !c && o ? `:${o}` : "";
|
|
666
|
+
return `${e}:${n}${c ? "/" : "."}${a}:${i}${u}`;
|
|
665
667
|
}
|
|
666
|
-
case
|
|
667
|
-
case
|
|
668
|
+
case C.OPEN_LOAN:
|
|
669
|
+
case C.CLOSE_LOAN: {
|
|
668
670
|
const { asset: n, address: r } = t;
|
|
669
671
|
return `${e}:${n}:${r}`;
|
|
670
672
|
}
|
|
@@ -672,37 +674,37 @@ const Pt = (e, t) => {
|
|
|
672
674
|
return "";
|
|
673
675
|
}
|
|
674
676
|
};
|
|
675
|
-
function
|
|
677
|
+
function Ot(e) {
|
|
676
678
|
if (e < 0)
|
|
677
679
|
throw new Error("Invalid number of year");
|
|
678
680
|
return 10 + e;
|
|
679
681
|
}
|
|
680
|
-
function
|
|
682
|
+
function $t(e) {
|
|
681
683
|
if (e.length > 30)
|
|
682
684
|
return !1;
|
|
683
685
|
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
684
686
|
return !!e.match(t);
|
|
685
687
|
}
|
|
686
|
-
function
|
|
688
|
+
function vt([e, t, n, r, s]) {
|
|
687
689
|
return `${e}'/${t}'/${n}'/${r}${typeof s != "number" ? "" : `/${s}`}`;
|
|
688
690
|
}
|
|
689
|
-
const
|
|
691
|
+
const ue = [...Object.values(l), "TERRA"];
|
|
690
692
|
function dt(e = "") {
|
|
691
693
|
const t = e.toUpperCase(), [n] = t.split(".");
|
|
692
|
-
if (
|
|
694
|
+
if (ue.includes(n))
|
|
693
695
|
return !0;
|
|
694
696
|
const [r] = t.split("/");
|
|
695
|
-
if (
|
|
697
|
+
if (ue.includes(r))
|
|
696
698
|
return !0;
|
|
697
699
|
throw new Error(
|
|
698
700
|
`Invalid identifier: ${e}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
699
701
|
);
|
|
700
702
|
}
|
|
701
|
-
const
|
|
702
|
-
function
|
|
703
|
+
const B = 8, y = (e) => 10n ** BigInt(e), v = (e) => Math.log10(parseFloat(e.toString()));
|
|
704
|
+
function U({
|
|
703
705
|
value: e,
|
|
704
|
-
bigIntDecimal: t =
|
|
705
|
-
decimal: n =
|
|
706
|
+
bigIntDecimal: t = B,
|
|
707
|
+
decimal: n = B
|
|
706
708
|
}) {
|
|
707
709
|
if (n === 0)
|
|
708
710
|
return e.toString();
|
|
@@ -710,31 +712,31 @@ function W({
|
|
|
710
712
|
let s = e.toString().substring(r ? 1 : 0);
|
|
711
713
|
const i = n - (s.length - 1);
|
|
712
714
|
i > 0 && (s = "0".repeat(i) + s);
|
|
713
|
-
const
|
|
715
|
+
const o = s.length - n;
|
|
714
716
|
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,
|
|
717
|
+
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, o)}.${c}`.replace(
|
|
716
718
|
/\.?0*$/,
|
|
717
719
|
""
|
|
718
720
|
);
|
|
719
721
|
}
|
|
720
|
-
var
|
|
721
|
-
const
|
|
722
|
+
var w, I, b, E, j, be, V, Z, H, ee;
|
|
723
|
+
const q = class q {
|
|
722
724
|
constructor(t) {
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
725
|
+
R(this, w);
|
|
726
|
+
R(this, b);
|
|
727
|
+
R(this, j);
|
|
728
|
+
R(this, V);
|
|
729
|
+
R(this, H);
|
|
730
|
+
_(this, "decimalMultiplier", 10n ** 8n);
|
|
731
|
+
_(this, "bigIntValue", 0n);
|
|
732
|
+
_(this, "decimal");
|
|
731
733
|
const n = te(t), r = typeof t == "object";
|
|
732
|
-
this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier :
|
|
734
|
+
this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier : y(Math.max(he(k(n)), this.decimal || 0)), p(this, j, be).call(this, n);
|
|
733
735
|
}
|
|
734
736
|
static fromBigInt(t, n) {
|
|
735
|
-
return new
|
|
737
|
+
return new q({
|
|
736
738
|
decimal: n,
|
|
737
|
-
value:
|
|
739
|
+
value: U({ value: t, bigIntDecimal: n, decimal: n })
|
|
738
740
|
});
|
|
739
741
|
}
|
|
740
742
|
static shiftDecimals({
|
|
@@ -742,8 +744,8 @@ const ie = class ie {
|
|
|
742
744
|
from: n,
|
|
743
745
|
to: r
|
|
744
746
|
}) {
|
|
745
|
-
return
|
|
746
|
-
t.getBaseValue("bigint") *
|
|
747
|
+
return q.fromBigInt(
|
|
748
|
+
t.getBaseValue("bigint") * y(r) / y(n),
|
|
747
749
|
r
|
|
748
750
|
);
|
|
749
751
|
}
|
|
@@ -751,37 +753,37 @@ const ie = class ie {
|
|
|
751
753
|
return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
|
|
752
754
|
}
|
|
753
755
|
add(...t) {
|
|
754
|
-
return
|
|
756
|
+
return p(this, w, I).call(this, "add", ...t);
|
|
755
757
|
}
|
|
756
758
|
sub(...t) {
|
|
757
|
-
return
|
|
759
|
+
return p(this, w, I).call(this, "sub", ...t);
|
|
758
760
|
}
|
|
759
761
|
mul(...t) {
|
|
760
|
-
return
|
|
762
|
+
return p(this, w, I).call(this, "mul", ...t);
|
|
761
763
|
}
|
|
762
764
|
div(...t) {
|
|
763
|
-
return
|
|
765
|
+
return p(this, w, I).call(this, "div", ...t);
|
|
764
766
|
}
|
|
765
767
|
gt(t) {
|
|
766
|
-
return
|
|
768
|
+
return p(this, b, E).call(this, "gt", t);
|
|
767
769
|
}
|
|
768
770
|
gte(t) {
|
|
769
|
-
return
|
|
771
|
+
return p(this, b, E).call(this, "gte", t);
|
|
770
772
|
}
|
|
771
773
|
lt(t) {
|
|
772
|
-
return
|
|
774
|
+
return p(this, b, E).call(this, "lt", t);
|
|
773
775
|
}
|
|
774
776
|
lte(t) {
|
|
775
|
-
return
|
|
777
|
+
return p(this, b, E).call(this, "lte", t);
|
|
776
778
|
}
|
|
777
779
|
eqValue(t) {
|
|
778
|
-
return
|
|
780
|
+
return p(this, b, E).call(this, "eqValue", t);
|
|
779
781
|
}
|
|
780
782
|
// @ts-expect-error False positive
|
|
781
783
|
getValue(t) {
|
|
782
784
|
const n = this.formatBigIntToSafeValue(
|
|
783
785
|
this.bigIntValue,
|
|
784
|
-
this.decimal ||
|
|
786
|
+
this.decimal || v(this.decimalMultiplier)
|
|
785
787
|
);
|
|
786
788
|
switch (t) {
|
|
787
789
|
case "number":
|
|
@@ -794,7 +796,7 @@ const ie = class ie {
|
|
|
794
796
|
}
|
|
795
797
|
// @ts-expect-error
|
|
796
798
|
getBaseValue(t) {
|
|
797
|
-
const n = this.decimalMultiplier /
|
|
799
|
+
const n = this.decimalMultiplier / y(this.decimal || d.THOR), r = this.bigIntValue / n;
|
|
798
800
|
switch (t) {
|
|
799
801
|
case "number":
|
|
800
802
|
return Number(r);
|
|
@@ -807,8 +809,8 @@ const ie = class ie {
|
|
|
807
809
|
getBigIntValue(t, n) {
|
|
808
810
|
if (!n && typeof t == "object")
|
|
809
811
|
return t.bigIntValue;
|
|
810
|
-
const r = te(t), s =
|
|
811
|
-
return s === "0" || s === "undefined" ? 0n :
|
|
812
|
+
const r = te(t), s = k(r);
|
|
813
|
+
return s === "0" || s === "undefined" ? 0n : p(this, H, ee).call(this, s, n);
|
|
812
814
|
}
|
|
813
815
|
toSignificant(t = 6) {
|
|
814
816
|
const [n, r] = this.getValue("string").split("."), s = n || "", i = r || "";
|
|
@@ -821,9 +823,9 @@ const ie = class ie {
|
|
|
821
823
|
t - s.length,
|
|
822
824
|
"0"
|
|
823
825
|
);
|
|
824
|
-
const c = parseInt(i),
|
|
825
|
-
return `0.${
|
|
826
|
-
i.length - `${c}`.length +
|
|
826
|
+
const c = parseInt(i), a = `${c}`.slice(0, t);
|
|
827
|
+
return `0.${a.padStart(
|
|
828
|
+
i.length - `${c}`.length + a.length,
|
|
827
829
|
"0"
|
|
828
830
|
)}`;
|
|
829
831
|
}
|
|
@@ -831,9 +833,9 @@ const ie = class ie {
|
|
|
831
833
|
const [n, r] = this.getValue("string").split("."), s = n || "", i = r || "";
|
|
832
834
|
if (parseInt(s))
|
|
833
835
|
return `${s}.${i.slice(0, t)}`.padEnd(t, "0");
|
|
834
|
-
const
|
|
836
|
+
const o = parseInt(i), c = `${o}`.slice(0, t);
|
|
835
837
|
return `0.${c.padStart(
|
|
836
|
-
i.length - `${
|
|
838
|
+
i.length - `${o}`.length + c.length,
|
|
837
839
|
"0"
|
|
838
840
|
)}`;
|
|
839
841
|
}
|
|
@@ -841,8 +843,8 @@ const ie = class ie {
|
|
|
841
843
|
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
844
|
if (!i)
|
|
843
845
|
return this.getValue("string");
|
|
844
|
-
const
|
|
845
|
-
return `${(n /
|
|
846
|
+
const o = 10 ** (s * 3);
|
|
847
|
+
return `${(n / o).toFixed(t)}${i}`;
|
|
846
848
|
}
|
|
847
849
|
toCurrency(t = "$", {
|
|
848
850
|
currencyPosition: n = "start",
|
|
@@ -850,56 +852,56 @@ const ie = class ie {
|
|
|
850
852
|
decimalSeparator: s = ".",
|
|
851
853
|
thousandSeparator: i = ","
|
|
852
854
|
} = {}) {
|
|
853
|
-
const
|
|
855
|
+
const o = this.getValue("number"), [c, a = ""] = o.toFixed(6).split("."), u = c.replace(/\B(?=(\d{3})+(?!\d))/g, i), h = c || a ? c === "0" ? `${parseFloat(`0.${a}`)}`.replace(".", s) : `${u}${parseInt(a) ? `${s}${a.slice(0, r)}` : ""}` : "0.00";
|
|
854
856
|
return `${n === "start" ? t : ""}${h}${n === "end" ? t : ""}`;
|
|
855
857
|
}
|
|
856
858
|
formatBigIntToSafeValue(t, n) {
|
|
857
|
-
const r = n || this.decimal ||
|
|
859
|
+
const r = n || this.decimal || B, s = Math.max(
|
|
858
860
|
r,
|
|
859
|
-
|
|
860
|
-
), i = t < 0n,
|
|
861
|
-
let h =
|
|
862
|
-
return parseInt(h[r]) >= 5 ? h = `${h.substring(0, r - 1)}${(parseInt(h[r - 1]) + 1).toString()}` : h = h.substring(0, r), `${i ? "-" : ""}${
|
|
861
|
+
v(this.decimalMultiplier)
|
|
862
|
+
), i = t < 0n, o = t.toString().substring(i ? 1 : 0), c = s - (o.length - 1), a = c > 0 ? "0".repeat(c) + o : o, u = a.length - s;
|
|
863
|
+
let h = a.slice(-s);
|
|
864
|
+
return parseInt(h[r]) >= 5 ? h = `${h.substring(0, r - 1)}${(parseInt(h[r - 1]) + 1).toString()}` : h = h.substring(0, r), `${i ? "-" : ""}${a.slice(
|
|
863
865
|
0,
|
|
864
|
-
|
|
866
|
+
u
|
|
865
867
|
)}.${h}`.replace(/\.?0*$/, "");
|
|
866
868
|
}
|
|
867
869
|
};
|
|
868
|
-
|
|
869
|
-
const r =
|
|
870
|
-
(
|
|
871
|
-
const h = this.getBigIntValue(
|
|
870
|
+
w = new WeakSet(), I = function(t, ...n) {
|
|
871
|
+
const r = p(this, V, Z).call(this, this, ...n), s = Math.max(r, v(this.decimalMultiplier)), i = y(s), o = n.reduce(
|
|
872
|
+
(a, u) => {
|
|
873
|
+
const h = this.getBigIntValue(u, s);
|
|
872
874
|
switch (t) {
|
|
873
875
|
case "add":
|
|
874
|
-
return
|
|
876
|
+
return a + h;
|
|
875
877
|
case "sub":
|
|
876
|
-
return
|
|
878
|
+
return a - h;
|
|
877
879
|
case "mul":
|
|
878
|
-
return
|
|
880
|
+
return a * h / i;
|
|
879
881
|
case "div": {
|
|
880
882
|
if (h === 0n)
|
|
881
883
|
throw new RangeError("Division by zero");
|
|
882
|
-
return
|
|
884
|
+
return a * i / h;
|
|
883
885
|
}
|
|
884
886
|
default:
|
|
885
|
-
return
|
|
887
|
+
return a;
|
|
886
888
|
}
|
|
887
889
|
},
|
|
888
890
|
//normalize is to precision multiplier base
|
|
889
891
|
this.bigIntValue * i / this.decimalMultiplier
|
|
890
|
-
), c =
|
|
892
|
+
), c = U({
|
|
891
893
|
bigIntDecimal: s,
|
|
892
894
|
decimal: s,
|
|
893
|
-
value:
|
|
895
|
+
value: o
|
|
894
896
|
});
|
|
895
897
|
return new this.constructor({
|
|
896
|
-
decimalMultiplier:
|
|
898
|
+
decimalMultiplier: y(s),
|
|
897
899
|
decimal: this.decimal,
|
|
898
900
|
value: c,
|
|
899
901
|
identifier: this.toString()
|
|
900
902
|
});
|
|
901
|
-
},
|
|
902
|
-
const r =
|
|
903
|
+
}, b = new WeakSet(), E = function(t, ...n) {
|
|
904
|
+
const r = p(this, V, Z).call(this, this, ...n), s = this.getBigIntValue(n[0], r), i = this.getBigIntValue(this, r);
|
|
903
905
|
switch (t) {
|
|
904
906
|
case "gt":
|
|
905
907
|
return i > s;
|
|
@@ -912,65 +914,65 @@ g = new WeakSet(), V = function(t, ...n) {
|
|
|
912
914
|
case "eqValue":
|
|
913
915
|
return i === s;
|
|
914
916
|
}
|
|
915
|
-
},
|
|
916
|
-
const n =
|
|
917
|
-
this.bigIntValue =
|
|
918
|
-
},
|
|
919
|
-
const n = t.map((r) => typeof r == "object" ? r.decimal ||
|
|
920
|
-
return Math.max(...n,
|
|
921
|
-
},
|
|
922
|
-
const r = n ?
|
|
923
|
-
return BigInt(`${i}${
|
|
917
|
+
}, j = new WeakSet(), be = function(t) {
|
|
918
|
+
const n = k(t) || "0";
|
|
919
|
+
this.bigIntValue = p(this, H, ee).call(this, n);
|
|
920
|
+
}, V = new WeakSet(), Z = function(...t) {
|
|
921
|
+
const n = t.map((r) => typeof r == "object" ? r.decimal || v(r.decimalMultiplier) : he(k(r))).filter(Boolean);
|
|
922
|
+
return Math.max(...n, B);
|
|
923
|
+
}, H = new WeakSet(), ee = function(t, n) {
|
|
924
|
+
const r = n ? y(n) : this.decimalMultiplier, s = v(r), [i = "", o = ""] = t.split(".");
|
|
925
|
+
return BigInt(`${i}${o.padEnd(s, "0")}`);
|
|
924
926
|
};
|
|
925
|
-
let
|
|
926
|
-
const
|
|
927
|
+
let D = q;
|
|
928
|
+
const pt = Intl.NumberFormat("fullwide", {
|
|
927
929
|
useGrouping: !1,
|
|
928
930
|
maximumFractionDigits: 20
|
|
929
931
|
});
|
|
930
|
-
function
|
|
931
|
-
const n = `${typeof e == "number" ?
|
|
932
|
+
function k(e) {
|
|
933
|
+
const n = `${typeof e == "number" ? pt.format(e) : te(e)}`.replaceAll(",", ".").split(".");
|
|
932
934
|
return n.length > 1 ? `${n.slice(0, -1).join("")}.${n.at(-1)}` : n[0];
|
|
933
935
|
}
|
|
934
936
|
function he(e) {
|
|
935
937
|
var n;
|
|
936
938
|
const t = ((n = e.split(".")[1]) == null ? void 0 : n.length) || 0;
|
|
937
|
-
return Math.max(t,
|
|
939
|
+
return Math.max(t, B);
|
|
938
940
|
}
|
|
939
941
|
function te(e) {
|
|
940
942
|
return typeof e == "object" ? "getValue" in e ? e.getValue("string") : e.value : e;
|
|
941
943
|
}
|
|
942
|
-
class
|
|
944
|
+
class g extends D {
|
|
943
945
|
eq(t) {
|
|
944
946
|
return this.eqValue(t);
|
|
945
947
|
}
|
|
946
948
|
static fromBigInt(t, n) {
|
|
947
|
-
return new
|
|
949
|
+
return new g({
|
|
948
950
|
decimal: n,
|
|
949
|
-
value:
|
|
951
|
+
value: U({ value: t, bigIntDecimal: n, decimal: n })
|
|
950
952
|
});
|
|
951
953
|
}
|
|
952
954
|
}
|
|
953
955
|
const P = /* @__PURE__ */ new Map();
|
|
954
|
-
class
|
|
956
|
+
class A extends D {
|
|
955
957
|
constructor({
|
|
956
958
|
value: n,
|
|
957
959
|
decimal: r,
|
|
958
960
|
tax: s,
|
|
959
961
|
chain: i,
|
|
960
|
-
symbol:
|
|
962
|
+
symbol: o,
|
|
961
963
|
identifier: c
|
|
962
964
|
}) {
|
|
963
965
|
super(typeof n == "object" ? n : { decimal: r, value: n });
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
const
|
|
973
|
-
this.type = ot(
|
|
966
|
+
_(this, "address");
|
|
967
|
+
_(this, "chain");
|
|
968
|
+
_(this, "isGasAsset", !1);
|
|
969
|
+
_(this, "isSynthetic", !1);
|
|
970
|
+
_(this, "symbol");
|
|
971
|
+
_(this, "tax");
|
|
972
|
+
_(this, "ticker");
|
|
973
|
+
_(this, "type");
|
|
974
|
+
const a = N(c || `${i}.${o}`);
|
|
975
|
+
this.type = ot(a), this.tax = s, this.chain = a.chain, this.ticker = a.ticker, this.symbol = a.symbol, this.address = a.address, this.isSynthetic = a.isSynthetic, this.isGasAsset = a.isGasAsset;
|
|
974
976
|
}
|
|
975
977
|
toString() {
|
|
976
978
|
return this.isSynthetic ? this.symbol : `${this.chain}.${this.symbol}`;
|
|
@@ -982,90 +984,89 @@ class R extends L {
|
|
|
982
984
|
return this.chain === n && this.symbol === r;
|
|
983
985
|
}
|
|
984
986
|
chainId() {
|
|
985
|
-
return
|
|
987
|
+
return De[this.chain];
|
|
986
988
|
}
|
|
987
989
|
// THOR.RUNE
|
|
988
990
|
// THOR.ETH.ETH
|
|
989
991
|
// ETH.THOR-0x1234567890
|
|
990
992
|
static fromUrl(n, r = 0) {
|
|
991
|
-
const [s, i,
|
|
992
|
-
if (!s
|
|
993
|
+
const [s, i, o] = n.split(".");
|
|
994
|
+
if (!(s && i))
|
|
993
995
|
throw new Error("Invalid asset url");
|
|
994
|
-
const c = s === l.THORChain &&
|
|
995
|
-
return
|
|
996
|
+
const c = s === l.THORChain && o ? `${s}.${i}/${o}` : n;
|
|
997
|
+
return Y(c, r);
|
|
996
998
|
}
|
|
997
999
|
static fromString(n, r = 0) {
|
|
998
|
-
return
|
|
1000
|
+
return Y(n, r);
|
|
999
1001
|
}
|
|
1000
1002
|
static fromIdentifier(n, r = 0) {
|
|
1001
|
-
return
|
|
1003
|
+
return Y(n, r);
|
|
1002
1004
|
}
|
|
1003
1005
|
static fromStringSync(n, r = 0) {
|
|
1004
|
-
const { chain: s, isSynthetic: i } =
|
|
1006
|
+
const { chain: s, isSynthetic: i } = N(n), o = P.get(n.toUpperCase());
|
|
1005
1007
|
if (i)
|
|
1006
1008
|
return Q(n, r);
|
|
1007
|
-
const { tax: c, decimal:
|
|
1009
|
+
const { tax: c, decimal: a, identifier: u } = o || {
|
|
1008
1010
|
decimal: d[s],
|
|
1009
1011
|
identifier: n
|
|
1010
1012
|
};
|
|
1011
|
-
return new
|
|
1013
|
+
return new A({
|
|
1012
1014
|
tax: c,
|
|
1013
|
-
value:
|
|
1014
|
-
identifier: i ? n :
|
|
1015
|
-
decimal: i ? 8 :
|
|
1015
|
+
value: O(r, a),
|
|
1016
|
+
identifier: i ? n : u,
|
|
1017
|
+
decimal: i ? 8 : a
|
|
1016
1018
|
});
|
|
1017
1019
|
}
|
|
1018
1020
|
static async fromStringWithBase(n, r = 0, s = d.THOR) {
|
|
1019
|
-
const i =
|
|
1020
|
-
value:
|
|
1021
|
+
const i = D.shiftDecimals({
|
|
1022
|
+
value: g.fromBigInt(BigInt(r)),
|
|
1021
1023
|
from: 0,
|
|
1022
1024
|
to: s
|
|
1023
1025
|
}).getBaseValue("string");
|
|
1024
|
-
return (await
|
|
1026
|
+
return (await A.fromString(n, r)).set(i);
|
|
1025
1027
|
}
|
|
1026
1028
|
static fromStringWithBaseSync(n, r = 0, s = d.THOR) {
|
|
1027
|
-
const { chain: i, isSynthetic:
|
|
1028
|
-
if (
|
|
1029
|
+
const { chain: i, isSynthetic: o } = N(n), c = P.get(n.toUpperCase());
|
|
1030
|
+
if (o)
|
|
1029
1031
|
return Q(n, r);
|
|
1030
|
-
const { tax:
|
|
1032
|
+
const { tax: a, decimal: u, identifier: h } = c || {
|
|
1031
1033
|
decimal: d[i],
|
|
1032
1034
|
identifier: n
|
|
1033
1035
|
};
|
|
1034
|
-
return new
|
|
1035
|
-
tax:
|
|
1036
|
-
value:
|
|
1036
|
+
return new A({
|
|
1037
|
+
tax: a,
|
|
1038
|
+
value: O(BigInt(r), s),
|
|
1037
1039
|
identifier: h,
|
|
1038
|
-
decimal:
|
|
1040
|
+
decimal: u
|
|
1039
1041
|
});
|
|
1040
1042
|
}
|
|
1041
1043
|
static fromIdentifierSync(n, r = 0) {
|
|
1042
|
-
const { chain: s, isSynthetic: i } =
|
|
1044
|
+
const { chain: s, isSynthetic: i } = N(n), o = P.get(n);
|
|
1043
1045
|
if (i)
|
|
1044
1046
|
return Q(n, r);
|
|
1045
|
-
const { tax: c, decimal:
|
|
1047
|
+
const { tax: c, decimal: a, identifier: u } = o || {
|
|
1046
1048
|
decimal: d[s],
|
|
1047
1049
|
identifier: n
|
|
1048
1050
|
};
|
|
1049
|
-
return new
|
|
1051
|
+
return new A({ tax: c, decimal: a, identifier: u, value: O(r, a) });
|
|
1050
1052
|
}
|
|
1051
1053
|
static fromChainOrSignature(n, r = 0) {
|
|
1052
|
-
const { decimal: s, identifier: i } =
|
|
1053
|
-
return new
|
|
1054
|
+
const { decimal: s, identifier: i } = it(n);
|
|
1055
|
+
return new A({ value: O(r, s), decimal: s, identifier: i });
|
|
1054
1056
|
}
|
|
1055
1057
|
static loadStaticAssets() {
|
|
1056
1058
|
return new Promise(
|
|
1057
|
-
|
|
1059
|
+
(n, r) => {
|
|
1058
1060
|
try {
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
}), n({ ok: !0 });
|
|
1061
|
+
import("@swapkit/tokens").then((s) => {
|
|
1062
|
+
for (const i of Object.values(s))
|
|
1063
|
+
for (const { identifier: o, chain: c, ...a } of i.tokens)
|
|
1064
|
+
P.set(o.toUpperCase(), {
|
|
1065
|
+
identifier: o,
|
|
1066
|
+
decimal: "decimals" in a ? a.decimals : d[c]
|
|
1067
|
+
});
|
|
1068
|
+
n({ ok: !0 });
|
|
1069
|
+
});
|
|
1069
1070
|
} catch (s) {
|
|
1070
1071
|
console.error(s), r({
|
|
1071
1072
|
ok: !1,
|
|
@@ -1077,8 +1078,8 @@ class R extends L {
|
|
|
1077
1078
|
);
|
|
1078
1079
|
}
|
|
1079
1080
|
}
|
|
1080
|
-
function
|
|
1081
|
-
const t =
|
|
1081
|
+
function It(e) {
|
|
1082
|
+
const t = A.fromChainOrSignature(e);
|
|
1082
1083
|
switch (e) {
|
|
1083
1084
|
case l.Bitcoin:
|
|
1084
1085
|
case l.Litecoin:
|
|
@@ -1098,39 +1099,39 @@ function Vt(e) {
|
|
|
1098
1099
|
return t.set(1e-8);
|
|
1099
1100
|
}
|
|
1100
1101
|
}
|
|
1101
|
-
async function
|
|
1102
|
+
async function Y(e, t = 0) {
|
|
1102
1103
|
dt(e);
|
|
1103
|
-
const n = P.get(e.toUpperCase()), r = (n == null ? void 0 : n.decimal) || await
|
|
1104
|
-
return n || P.set(e.toUpperCase(), { identifier: e, decimal: r }), new
|
|
1104
|
+
const n = P.get(e.toUpperCase()), r = (n == null ? void 0 : n.decimal) || await st(N(e));
|
|
1105
|
+
return n || P.set(e.toUpperCase(), { identifier: e, decimal: r }), new A({ decimal: r, value: O(t, r), identifier: e });
|
|
1105
1106
|
}
|
|
1106
1107
|
function Q(e, t = 0) {
|
|
1107
1108
|
const [n, r] = e.split(".")[0].toUpperCase() === l.THORChain ? e.split(".").slice(1).join().split("/") : e.split("/");
|
|
1108
|
-
if (!n
|
|
1109
|
+
if (!(n && r))
|
|
1109
1110
|
throw new Error("Invalid asset identifier");
|
|
1110
|
-
return new
|
|
1111
|
+
return new A({
|
|
1111
1112
|
decimal: 8,
|
|
1112
|
-
value:
|
|
1113
|
+
value: O(t, 8),
|
|
1113
1114
|
identifier: `${l.THORChain}.${n}/${r}`
|
|
1114
1115
|
});
|
|
1115
1116
|
}
|
|
1116
|
-
function
|
|
1117
|
-
return typeof e == "bigint" ?
|
|
1117
|
+
function O(e, t) {
|
|
1118
|
+
return typeof e == "bigint" ? U({ value: e, bigIntDecimal: t, decimal: t }) : e;
|
|
1118
1119
|
}
|
|
1119
|
-
function
|
|
1120
|
+
function N(e) {
|
|
1120
1121
|
const t = e.slice(0, 14).includes("/"), [n, r] = e.split(".")[0].toUpperCase() === l.THORChain ? e.split(".").slice(1).join().split("/") : e.split("/");
|
|
1121
|
-
if (t && (
|
|
1122
|
+
if (t && !(n && r))
|
|
1122
1123
|
throw new Error("Invalid asset identifier");
|
|
1123
|
-
const s = e.includes(".") && !t ? e : `${l.THORChain}.${r}`, [i, ...
|
|
1124
|
+
const s = e.includes(".") && !t ? e : `${l.THORChain}.${r}`, [i, ...o] = s.split("."), [c, a] = (t ? r : o.join(".")).split("-"), u = t ? r : o.join(".");
|
|
1124
1125
|
return {
|
|
1125
|
-
address:
|
|
1126
|
+
address: a == null ? void 0 : a.toLowerCase(),
|
|
1126
1127
|
chain: i,
|
|
1127
|
-
isGasAsset:
|
|
1128
|
+
isGasAsset: Se({ chain: i, symbol: u }),
|
|
1128
1129
|
isSynthetic: t,
|
|
1129
|
-
symbol: (t ? `${n}/` : "") + (
|
|
1130
|
+
symbol: (t ? `${n}/` : "") + (a ? `${c}-${(a == null ? void 0 : a.toLowerCase()) ?? ""}` : u),
|
|
1130
1131
|
ticker: c
|
|
1131
1132
|
};
|
|
1132
1133
|
}
|
|
1133
|
-
const
|
|
1134
|
+
const mt = {
|
|
1134
1135
|
/**
|
|
1135
1136
|
* Core
|
|
1136
1137
|
*/
|
|
@@ -1163,6 +1164,7 @@ const At = {
|
|
|
1163
1164
|
core_swap_contract_not_supported: 10205,
|
|
1164
1165
|
core_swap_transaction_error: 10206,
|
|
1165
1166
|
core_swap_quote_mode_not_supported: 10207,
|
|
1167
|
+
core_swap_provider_not_found: 10208,
|
|
1166
1168
|
/**
|
|
1167
1169
|
* Core - Transaction
|
|
1168
1170
|
*/
|
|
@@ -1189,49 +1191,62 @@ const At = {
|
|
|
1189
1191
|
wallet_ledger_get_address_error: 20003,
|
|
1190
1192
|
wallet_ledger_device_not_found: 20004,
|
|
1191
1193
|
wallet_ledger_device_locked: 20005,
|
|
1194
|
+
/**
|
|
1195
|
+
* Chainflip
|
|
1196
|
+
*/
|
|
1197
|
+
chainflip_channel_error: 30001,
|
|
1198
|
+
chainflip_broker_recipient_error: 30002,
|
|
1199
|
+
/**
|
|
1200
|
+
* THORChain
|
|
1201
|
+
*/
|
|
1192
1202
|
/**
|
|
1193
1203
|
* Helpers
|
|
1194
1204
|
*/
|
|
1195
1205
|
helpers_number_different_decimals: 99101
|
|
1196
1206
|
};
|
|
1197
|
-
class
|
|
1207
|
+
class ye extends Error {
|
|
1198
1208
|
constructor(t, n) {
|
|
1199
|
-
n && console.error(n, {
|
|
1209
|
+
n && console.error(n, {
|
|
1210
|
+
stack: n == null ? void 0 : n.stack,
|
|
1211
|
+
message: n == null ? void 0 : n.message
|
|
1212
|
+
}), super(t, {
|
|
1213
|
+
cause: { code: mt[t], message: t }
|
|
1214
|
+
}), Object.setPrototypeOf(this, ye.prototype);
|
|
1200
1215
|
}
|
|
1201
1216
|
}
|
|
1202
1217
|
export {
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1218
|
+
f as ApiEndpoints,
|
|
1219
|
+
A as AssetValue,
|
|
1220
|
+
D as BigIntArithmetics,
|
|
1221
|
+
T as RequestClient,
|
|
1222
|
+
Ze as StreamingSwapProgressStatus,
|
|
1223
|
+
gt as SwapKitApi,
|
|
1224
|
+
ye as SwapKitError,
|
|
1225
|
+
g as SwapKitNumber,
|
|
1226
|
+
Qe as TransactionType,
|
|
1227
|
+
ze as TxStatus,
|
|
1228
|
+
Ct as assetFromString,
|
|
1229
|
+
Ae as defaultRequestHeaders,
|
|
1230
|
+
vt as derivationPathToString,
|
|
1231
|
+
St as filterAssets,
|
|
1232
|
+
U as formatBigIntToSafeValue,
|
|
1233
|
+
At as gasFeeMultiplier,
|
|
1219
1234
|
ot as getAssetType,
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1235
|
+
ut as getAsymmetricAssetShare,
|
|
1236
|
+
yt as getAsymmetricAssetWithdrawAmount,
|
|
1237
|
+
lt as getAsymmetricRuneShare,
|
|
1238
|
+
bt as getAsymmetricRuneWithdrawAmount,
|
|
1239
|
+
it as getCommonAssetInfo,
|
|
1240
|
+
st as getDecimal,
|
|
1241
|
+
Rt as getEstimatedPoolShare,
|
|
1242
|
+
Et as getLiquiditySlippage,
|
|
1228
1243
|
Pt as getMemoFor,
|
|
1229
|
-
|
|
1244
|
+
It as getMinAmountByChain,
|
|
1230
1245
|
ht as getSymmetricPoolShare,
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1246
|
+
wt as getSymmetricWithdraw,
|
|
1247
|
+
Ot as getTHORNameCost,
|
|
1248
|
+
Se as isGasAsset,
|
|
1249
|
+
ft as setRequestClientConfig,
|
|
1250
|
+
$t as validateTHORName
|
|
1236
1251
|
};
|
|
1237
1252
|
//# sourceMappingURL=index.es.js.map
|