@swapkit/helpers 1.0.0-rc.70 → 1.0.0-rc.72
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 +33 -19
- package/dist/index.es.js +400 -363
- 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 +245 -144
- package/src/modules/__tests__/bigIntArithmetics.test.ts +8 -8
- package/src/modules/__tests__/swapKitNumber.test.ts +232 -232
- package/src/modules/assetValue.ts +78 -40
- package/src/modules/bigIntArithmetics.ts +86 -86
- package/src/modules/swapKitError.ts +17 -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 || {}), 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(
|
|
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
|
-
|
|
25
|
-
(e, t) => (e[t] =
|
|
22
|
+
G.reduce(
|
|
23
|
+
(e, t) => (e[t] = ne[re[t]], e),
|
|
26
24
|
{}
|
|
27
25
|
);
|
|
28
|
-
|
|
29
|
-
(e, t) => (e[t] = de[
|
|
26
|
+
G.reduce(
|
|
27
|
+
(e, t) => (e[t] = de[re[t]], e),
|
|
30
28
|
{}
|
|
31
29
|
);
|
|
32
|
-
|
|
30
|
+
G.reduce(
|
|
33
31
|
(e, t) => {
|
|
34
|
-
const n = `${
|
|
35
|
-
return e[t] =
|
|
32
|
+
const n = `${re[t]}Hex`;
|
|
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 oe 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 k = (e) => e !== null && typeof e == "object", x = (...e) => {
|
|
71
69
|
for (const t of e)
|
|
72
|
-
if ((!
|
|
70
|
+
if ((!k(t) || Array.isArray(t)) && t !== void 0)
|
|
73
71
|
throw new TypeError("The `options` argument must be an object");
|
|
74
|
-
return
|
|
75
|
-
},
|
|
72
|
+
return se({}, ...e);
|
|
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 (k(r)) {
|
|
86
84
|
for (let [s, i] of Object.entries(r))
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
k(i) && s in t && (i = se(t[s], i)), t = { ...t, [s]: i };
|
|
86
|
+
k(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 M = (e) => e !== null && typeof e == "object", $ = (...e) => {
|
|
|
99
97
|
return e = !0, "half";
|
|
100
98
|
}
|
|
101
99
|
}).headers.has("Content-Type")), e && !t;
|
|
102
|
-
})(),
|
|
100
|
+
})(), xe = typeof globalThis.AbortController == "function", Me = typeof globalThis.ReadableStream == "function", ke = 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 M = (e) => e !== null && typeof e == "object", $ = (...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,15 +130,15 @@ const M = (e) => e !== null && typeof e == "object", $ = (...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,
|
|
@@ -153,16 +151,16 @@ const M = (e) => e !== null && typeof e == "object", $ = (...e) => {
|
|
|
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 (!Me)
|
|
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 x {
|
|
|
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:
|
|
258
|
-
hooks:
|
|
255
|
+
headers: me(this._input.headers, n.headers),
|
|
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 x {
|
|
|
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 x {
|
|
|
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
|
+
(ke && 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 x {
|
|
|
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 x {
|
|
|
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 x {
|
|
|
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 x {
|
|
|
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
|
}
|
|
@@ -379,50 +377,54 @@ class x {
|
|
|
379
377
|
}
|
|
380
378
|
}
|
|
381
379
|
/*! MIT License © Sindre Sorhus */
|
|
382
|
-
const
|
|
383
|
-
const t = (n, r) =>
|
|
384
|
-
for (const n of
|
|
385
|
-
t[n] = (r, s) =>
|
|
386
|
-
return t.create = (n) =>
|
|
387
|
-
},
|
|
388
|
-
let
|
|
389
|
-
const
|
|
390
|
-
CachedPrices: `${
|
|
391
|
-
GasRates: `${
|
|
392
|
-
Quote: `${
|
|
393
|
-
Txn: `${
|
|
394
|
-
TokenlistProviders: `${
|
|
395
|
-
TokenList: `${
|
|
396
|
-
Thorname: `${
|
|
397
|
-
},
|
|
398
|
-
|
|
380
|
+
const z = (e) => {
|
|
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
|
-
},
|
|
400
|
+
}, T = {
|
|
403
401
|
get: (e, t) => le().get(e, t).json(),
|
|
404
402
|
post: (e, t) => le().post(e, t).json()
|
|
405
|
-
},
|
|
406
|
-
const n = new URLSearchParams()
|
|
407
|
-
|
|
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
|
|
616
|
-
if (
|
|
617
|
-
return X.div(
|
|
618
|
-
const
|
|
619
|
-
return X.div(
|
|
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);
|
|
618
|
+
if (oe.getBaseValue("number") === 0)
|
|
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,18 +674,18 @@ 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
691
|
const ue = [...Object.values(l), "TERRA"];
|
|
@@ -698,8 +700,8 @@ function dt(e = "") {
|
|
|
698
700
|
`Invalid identifier: ${e}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
699
701
|
);
|
|
700
702
|
}
|
|
701
|
-
const B = 8,
|
|
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
706
|
bigIntDecimal: t = B,
|
|
705
707
|
decimal: n = B
|
|
@@ -710,31 +712,31 @@ function G({
|
|
|
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
|
-
|
|
731
|
-
const n =
|
|
732
|
-
this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier :
|
|
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");
|
|
733
|
+
const n = te(t), r = typeof t == "object";
|
|
734
|
+
this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier : y(Math.max(he(M(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 se = class se {
|
|
|
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 se = class se {
|
|
|
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 se = class se {
|
|
|
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 se = class se {
|
|
|
807
809
|
getBigIntValue(t, n) {
|
|
808
810
|
if (!n && typeof t == "object")
|
|
809
811
|
return t.bigIntValue;
|
|
810
|
-
const r =
|
|
811
|
-
return s === "0" || s === "undefined" ? 0n :
|
|
812
|
+
const r = te(t), s = M(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 se = class se {
|
|
|
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 se = class se {
|
|
|
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 se = class se {
|
|
|
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 se = class se {
|
|
|
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
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,54 +914,65 @@ C = new WeakSet(), y = 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 ||
|
|
917
|
+
}, j = new WeakSet(), be = function(t) {
|
|
918
|
+
const n = M(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(M(r))).filter(Boolean);
|
|
920
922
|
return Math.max(...n, B);
|
|
921
|
-
},
|
|
922
|
-
const r = n ?
|
|
923
|
-
return BigInt(`${i}${
|
|
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 M(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
|
-
function
|
|
936
|
+
function he(e) {
|
|
935
937
|
var n;
|
|
936
938
|
const t = ((n = e.split(".")[1]) == null ? void 0 : n.length) || 0;
|
|
937
939
|
return Math.max(t, B);
|
|
938
940
|
}
|
|
939
|
-
function
|
|
941
|
+
function te(e) {
|
|
940
942
|
return typeof e == "object" ? "getValue" in e ? e.getValue("string") : e.value : e;
|
|
941
943
|
}
|
|
942
|
-
|
|
943
|
-
|
|
944
|
+
class g extends D {
|
|
945
|
+
eq(t) {
|
|
946
|
+
return this.eqValue(t);
|
|
947
|
+
}
|
|
948
|
+
static fromBigInt(t, n) {
|
|
949
|
+
return new g({
|
|
950
|
+
decimal: n,
|
|
951
|
+
value: U({ value: t, bigIntDecimal: n, decimal: n })
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
const P = /* @__PURE__ */ new Map();
|
|
956
|
+
class A extends D {
|
|
944
957
|
constructor({
|
|
945
958
|
value: n,
|
|
946
959
|
decimal: r,
|
|
947
960
|
tax: s,
|
|
948
961
|
chain: i,
|
|
949
|
-
symbol:
|
|
962
|
+
symbol: o,
|
|
950
963
|
identifier: c
|
|
951
964
|
}) {
|
|
952
965
|
super(typeof n == "object" ? n : { decimal: r, value: n });
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
const
|
|
962
|
-
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;
|
|
963
976
|
}
|
|
964
977
|
toString() {
|
|
965
978
|
return this.isSynthetic ? this.symbol : `${this.chain}.${this.symbol}`;
|
|
@@ -971,67 +984,89 @@ class g extends W {
|
|
|
971
984
|
return this.chain === n && this.symbol === r;
|
|
972
985
|
}
|
|
973
986
|
chainId() {
|
|
974
|
-
return
|
|
987
|
+
return De[this.chain];
|
|
975
988
|
}
|
|
976
989
|
// THOR.RUNE
|
|
977
990
|
// THOR.ETH.ETH
|
|
978
991
|
// ETH.THOR-0x1234567890
|
|
979
992
|
static fromUrl(n, r = 0) {
|
|
980
|
-
const [s, i,
|
|
981
|
-
if (!s
|
|
993
|
+
const [s, i, o] = n.split(".");
|
|
994
|
+
if (!(s && i))
|
|
982
995
|
throw new Error("Invalid asset url");
|
|
983
|
-
const c = s === l.THORChain &&
|
|
984
|
-
return
|
|
996
|
+
const c = s === l.THORChain && o ? `${s}.${i}/${o}` : n;
|
|
997
|
+
return Y(c, r);
|
|
985
998
|
}
|
|
986
999
|
static fromString(n, r = 0) {
|
|
987
|
-
return
|
|
1000
|
+
return Y(n, r);
|
|
988
1001
|
}
|
|
989
1002
|
static fromIdentifier(n, r = 0) {
|
|
990
|
-
return
|
|
1003
|
+
return Y(n, r);
|
|
991
1004
|
}
|
|
992
1005
|
static fromStringSync(n, r = 0) {
|
|
993
|
-
const { chain: s, isSynthetic: i } =
|
|
1006
|
+
const { chain: s, isSynthetic: i } = N(n), o = P.get(n.toUpperCase());
|
|
994
1007
|
if (i)
|
|
995
|
-
return
|
|
996
|
-
const { tax: c, decimal:
|
|
1008
|
+
return Q(n, r);
|
|
1009
|
+
const { tax: c, decimal: a, identifier: u } = o || {
|
|
997
1010
|
decimal: d[s],
|
|
998
1011
|
identifier: n
|
|
999
1012
|
};
|
|
1000
|
-
return new
|
|
1013
|
+
return new A({
|
|
1001
1014
|
tax: c,
|
|
1002
|
-
value:
|
|
1003
|
-
identifier: i ? n :
|
|
1004
|
-
decimal: i ? 8 :
|
|
1015
|
+
value: O(r, a),
|
|
1016
|
+
identifier: i ? n : u,
|
|
1017
|
+
decimal: i ? 8 : a
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
static async fromStringWithBase(n, r = 0, s = d.THOR) {
|
|
1021
|
+
const i = D.shiftDecimals({
|
|
1022
|
+
value: g.fromBigInt(BigInt(r)),
|
|
1023
|
+
from: 0,
|
|
1024
|
+
to: s
|
|
1025
|
+
}).getBaseValue("string");
|
|
1026
|
+
return (await A.fromString(n, r)).set(i);
|
|
1027
|
+
}
|
|
1028
|
+
static fromStringWithBaseSync(n, r = 0, s = d.THOR) {
|
|
1029
|
+
const { chain: i, isSynthetic: o } = N(n), c = P.get(n.toUpperCase());
|
|
1030
|
+
if (o)
|
|
1031
|
+
return Q(n, r);
|
|
1032
|
+
const { tax: a, decimal: u, identifier: h } = c || {
|
|
1033
|
+
decimal: d[i],
|
|
1034
|
+
identifier: n
|
|
1035
|
+
};
|
|
1036
|
+
return new A({
|
|
1037
|
+
tax: a,
|
|
1038
|
+
value: O(BigInt(r), s),
|
|
1039
|
+
identifier: h,
|
|
1040
|
+
decimal: u
|
|
1005
1041
|
});
|
|
1006
1042
|
}
|
|
1007
1043
|
static fromIdentifierSync(n, r = 0) {
|
|
1008
|
-
const { chain: s, isSynthetic: i } =
|
|
1044
|
+
const { chain: s, isSynthetic: i } = N(n), o = P.get(n);
|
|
1009
1045
|
if (i)
|
|
1010
|
-
return
|
|
1011
|
-
const { tax: c, decimal:
|
|
1046
|
+
return Q(n, r);
|
|
1047
|
+
const { tax: c, decimal: a, identifier: u } = o || {
|
|
1012
1048
|
decimal: d[s],
|
|
1013
1049
|
identifier: n
|
|
1014
1050
|
};
|
|
1015
|
-
return new
|
|
1051
|
+
return new A({ tax: c, decimal: a, identifier: u, value: O(r, a) });
|
|
1016
1052
|
}
|
|
1017
1053
|
static fromChainOrSignature(n, r = 0) {
|
|
1018
|
-
const { decimal: s, identifier: i } =
|
|
1019
|
-
return new
|
|
1054
|
+
const { decimal: s, identifier: i } = it(n);
|
|
1055
|
+
return new A({ value: O(r, s), decimal: s, identifier: i });
|
|
1020
1056
|
}
|
|
1021
1057
|
static loadStaticAssets() {
|
|
1022
1058
|
return new Promise(
|
|
1023
|
-
|
|
1059
|
+
(n, r) => {
|
|
1024
1060
|
try {
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
}), 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
|
+
});
|
|
1035
1070
|
} catch (s) {
|
|
1036
1071
|
console.error(s), r({
|
|
1037
1072
|
ok: !1,
|
|
@@ -1043,8 +1078,8 @@ class g extends W {
|
|
|
1043
1078
|
);
|
|
1044
1079
|
}
|
|
1045
1080
|
}
|
|
1046
|
-
function
|
|
1047
|
-
const t =
|
|
1081
|
+
function It(e) {
|
|
1082
|
+
const t = A.fromChainOrSignature(e);
|
|
1048
1083
|
switch (e) {
|
|
1049
1084
|
case l.Bitcoin:
|
|
1050
1085
|
case l.Litecoin:
|
|
@@ -1064,39 +1099,39 @@ function Vt(e) {
|
|
|
1064
1099
|
return t.set(1e-8);
|
|
1065
1100
|
}
|
|
1066
1101
|
}
|
|
1067
|
-
async function
|
|
1102
|
+
async function Y(e, t = 0) {
|
|
1068
1103
|
dt(e);
|
|
1069
|
-
const n =
|
|
1070
|
-
return n ||
|
|
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 });
|
|
1071
1106
|
}
|
|
1072
|
-
function
|
|
1107
|
+
function Q(e, t = 0) {
|
|
1073
1108
|
const [n, r] = e.split(".")[0].toUpperCase() === l.THORChain ? e.split(".").slice(1).join().split("/") : e.split("/");
|
|
1074
|
-
if (!n
|
|
1109
|
+
if (!(n && r))
|
|
1075
1110
|
throw new Error("Invalid asset identifier");
|
|
1076
|
-
return new
|
|
1111
|
+
return new A({
|
|
1077
1112
|
decimal: 8,
|
|
1078
|
-
value:
|
|
1113
|
+
value: O(t, 8),
|
|
1079
1114
|
identifier: `${l.THORChain}.${n}/${r}`
|
|
1080
1115
|
});
|
|
1081
1116
|
}
|
|
1082
|
-
function
|
|
1083
|
-
return typeof e == "bigint" ?
|
|
1117
|
+
function O(e, t) {
|
|
1118
|
+
return typeof e == "bigint" ? U({ value: e, bigIntDecimal: t, decimal: t }) : e;
|
|
1084
1119
|
}
|
|
1085
|
-
function
|
|
1120
|
+
function N(e) {
|
|
1086
1121
|
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 && (
|
|
1122
|
+
if (t && !(n && r))
|
|
1088
1123
|
throw new Error("Invalid asset identifier");
|
|
1089
|
-
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(".");
|
|
1090
1125
|
return {
|
|
1091
|
-
address:
|
|
1126
|
+
address: a == null ? void 0 : a.toLowerCase(),
|
|
1092
1127
|
chain: i,
|
|
1093
|
-
isGasAsset:
|
|
1128
|
+
isGasAsset: Se({ chain: i, symbol: u }),
|
|
1094
1129
|
isSynthetic: t,
|
|
1095
|
-
symbol: (t ? `${n}/` : "") + (
|
|
1130
|
+
symbol: (t ? `${n}/` : "") + (a ? `${c}-${(a == null ? void 0 : a.toLowerCase()) ?? ""}` : u),
|
|
1096
1131
|
ticker: c
|
|
1097
1132
|
};
|
|
1098
1133
|
}
|
|
1099
|
-
const
|
|
1134
|
+
const mt = {
|
|
1100
1135
|
/**
|
|
1101
1136
|
* Core
|
|
1102
1137
|
*/
|
|
@@ -1129,6 +1164,7 @@ const At = {
|
|
|
1129
1164
|
core_swap_contract_not_supported: 10205,
|
|
1130
1165
|
core_swap_transaction_error: 10206,
|
|
1131
1166
|
core_swap_quote_mode_not_supported: 10207,
|
|
1167
|
+
core_swap_provider_not_found: 10208,
|
|
1132
1168
|
/**
|
|
1133
1169
|
* Core - Transaction
|
|
1134
1170
|
*/
|
|
@@ -1155,60 +1191,61 @@ const At = {
|
|
|
1155
1191
|
wallet_ledger_get_address_error: 20003,
|
|
1156
1192
|
wallet_ledger_device_not_found: 20004,
|
|
1157
1193
|
wallet_ledger_device_locked: 20005,
|
|
1194
|
+
/**
|
|
1195
|
+
* Chainflip
|
|
1196
|
+
*/
|
|
1197
|
+
chainflip_channel_error: 30001,
|
|
1198
|
+
/**
|
|
1199
|
+
* THORChain
|
|
1200
|
+
*/
|
|
1158
1201
|
/**
|
|
1159
1202
|
* Helpers
|
|
1160
1203
|
*/
|
|
1161
1204
|
helpers_number_different_decimals: 99101
|
|
1162
1205
|
};
|
|
1163
|
-
class
|
|
1206
|
+
class ye extends Error {
|
|
1164
1207
|
constructor(t, n) {
|
|
1165
|
-
n && console.error(n, {
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
}
|
|
1172
|
-
static fromBigInt(t, n) {
|
|
1173
|
-
return new I({
|
|
1174
|
-
decimal: n,
|
|
1175
|
-
value: G({ value: t, bigIntDecimal: n, decimal: n })
|
|
1176
|
-
});
|
|
1208
|
+
n && console.error(n, {
|
|
1209
|
+
stack: n == null ? void 0 : n.stack,
|
|
1210
|
+
message: n == null ? void 0 : n.message
|
|
1211
|
+
}), super(t, {
|
|
1212
|
+
cause: { code: mt[t], message: t }
|
|
1213
|
+
}), Object.setPrototypeOf(this, ye.prototype);
|
|
1177
1214
|
}
|
|
1178
1215
|
}
|
|
1179
1216
|
export {
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1217
|
+
f as ApiEndpoints,
|
|
1218
|
+
A as AssetValue,
|
|
1219
|
+
D as BigIntArithmetics,
|
|
1220
|
+
T as RequestClient,
|
|
1221
|
+
Ze as StreamingSwapProgressStatus,
|
|
1222
|
+
gt as SwapKitApi,
|
|
1223
|
+
ye as SwapKitError,
|
|
1224
|
+
g as SwapKitNumber,
|
|
1225
|
+
Qe as TransactionType,
|
|
1226
|
+
ze as TxStatus,
|
|
1227
|
+
Ct as assetFromString,
|
|
1228
|
+
Ae as defaultRequestHeaders,
|
|
1229
|
+
vt as derivationPathToString,
|
|
1230
|
+
St as filterAssets,
|
|
1231
|
+
U as formatBigIntToSafeValue,
|
|
1232
|
+
At as gasFeeMultiplier,
|
|
1196
1233
|
ot as getAssetType,
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1234
|
+
ut as getAsymmetricAssetShare,
|
|
1235
|
+
yt as getAsymmetricAssetWithdrawAmount,
|
|
1236
|
+
lt as getAsymmetricRuneShare,
|
|
1237
|
+
bt as getAsymmetricRuneWithdrawAmount,
|
|
1238
|
+
it as getCommonAssetInfo,
|
|
1239
|
+
st as getDecimal,
|
|
1240
|
+
Rt as getEstimatedPoolShare,
|
|
1241
|
+
Et as getLiquiditySlippage,
|
|
1205
1242
|
Pt as getMemoFor,
|
|
1206
|
-
|
|
1243
|
+
It as getMinAmountByChain,
|
|
1207
1244
|
ht as getSymmetricPoolShare,
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1245
|
+
wt as getSymmetricWithdraw,
|
|
1246
|
+
Ot as getTHORNameCost,
|
|
1247
|
+
Se as isGasAsset,
|
|
1248
|
+
ft as setRequestClientConfig,
|
|
1249
|
+
$t as validateTHORName
|
|
1213
1250
|
};
|
|
1214
1251
|
//# sourceMappingURL=index.es.js.map
|