@swapkit/helpers 1.0.0-rc.35 → 1.0.0-rc.37
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.d.ts +15 -6
- package/dist/index.es.js +336 -315
- package/package.json +6 -6
- package/src/modules/__tests__/swapKitNumber.test.ts +41 -1
- package/src/modules/assetValue.ts +26 -16
- package/src/modules/bigIntArithmetics.ts +96 -67
package/dist/index.es.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
var bt = Object.defineProperty;
|
|
2
|
+
var yt = (s, t, e) => t in s ? bt(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
|
|
3
|
+
var f = (s, t, e) => (yt(s, typeof t != "symbol" ? t + "" : t, e), e), wt = (s, t, e) => {
|
|
4
4
|
if (!t.has(s))
|
|
5
5
|
throw TypeError("Cannot " + e);
|
|
6
6
|
};
|
|
7
|
-
var
|
|
7
|
+
var $ = (s, t, e) => {
|
|
8
8
|
if (t.has(s))
|
|
9
9
|
throw TypeError("Cannot add the same private member more than once");
|
|
10
10
|
t instanceof WeakSet ? t.add(s) : t.set(s, e);
|
|
11
11
|
};
|
|
12
|
-
var
|
|
13
|
-
import { FeeOption as
|
|
14
|
-
const
|
|
12
|
+
var m = (s, t, e) => (wt(s, t, "access private method"), e);
|
|
13
|
+
import { FeeOption as L, BaseDecimal as h, Chain as o, EVMChainList as At, ChainToRPC as vt, MemoType as g } from "@swapkit/types";
|
|
14
|
+
const Tt = "0x313ce567", it = async ({ chain: s, to: t }) => {
|
|
15
15
|
try {
|
|
16
|
-
const { result: e } = await
|
|
16
|
+
const { result: e } = await Zt.post(vt[s], {
|
|
17
17
|
headers: {
|
|
18
18
|
accept: "*/*",
|
|
19
19
|
"content-type": "application/json",
|
|
@@ -23,37 +23,37 @@ const At = "0x313ce567", rt = async ({ chain: s, to: t }) => {
|
|
|
23
23
|
id: 44,
|
|
24
24
|
jsonrpc: "2.0",
|
|
25
25
|
method: "eth_call",
|
|
26
|
-
params: [{ to: t.toLowerCase(), data:
|
|
26
|
+
params: [{ to: t.toLowerCase(), data: Tt }, "latest"]
|
|
27
27
|
})
|
|
28
28
|
});
|
|
29
29
|
return parseInt(BigInt(e).toString());
|
|
30
30
|
} catch (e) {
|
|
31
31
|
return console.error(e), h[s];
|
|
32
32
|
}
|
|
33
|
-
},
|
|
33
|
+
}, $t = async (s) => {
|
|
34
34
|
if (s === o.Ethereum)
|
|
35
35
|
return h.ETH;
|
|
36
36
|
const [, t] = s.split("-");
|
|
37
|
-
return t != null && t.startsWith("0x") ?
|
|
38
|
-
},
|
|
37
|
+
return t != null && t.startsWith("0x") ? it({ chain: o.Ethereum, to: t }) : h.ETH;
|
|
38
|
+
}, Rt = async (s) => {
|
|
39
39
|
const [, t] = s.split("-");
|
|
40
|
-
return t != null && t.startsWith("0x") ?
|
|
41
|
-
},
|
|
40
|
+
return t != null && t.startsWith("0x") ? it({ chain: o.Avalanche, to: t.toLowerCase() }) : h.AVAX;
|
|
41
|
+
}, St = async (s) => s === o.BinanceSmartChain ? h.BSC : h.BSC, Ct = async ({ chain: s, symbol: t }) => {
|
|
42
42
|
switch (s) {
|
|
43
43
|
case o.Ethereum:
|
|
44
|
-
return
|
|
44
|
+
return $t(t);
|
|
45
45
|
case o.Avalanche:
|
|
46
|
-
return
|
|
46
|
+
return Rt(t);
|
|
47
47
|
case o.BinanceSmartChain:
|
|
48
|
-
return
|
|
48
|
+
return St(t);
|
|
49
49
|
default:
|
|
50
50
|
return h[s];
|
|
51
51
|
}
|
|
52
|
-
},
|
|
53
|
-
[
|
|
54
|
-
[
|
|
55
|
-
[
|
|
56
|
-
},
|
|
52
|
+
}, ie = {
|
|
53
|
+
[L.Average]: 1.2,
|
|
54
|
+
[L.Fast]: 1.5,
|
|
55
|
+
[L.Fastest]: 2
|
|
56
|
+
}, ot = ({ chain: s, symbol: t }) => {
|
|
57
57
|
switch (s) {
|
|
58
58
|
case o.Bitcoin:
|
|
59
59
|
case o.BitcoinCash:
|
|
@@ -79,7 +79,7 @@ const At = "0x313ce567", rt = async ({ chain: s, to: t }) => {
|
|
|
79
79
|
case o.THORChain:
|
|
80
80
|
return t === "RUNE";
|
|
81
81
|
}
|
|
82
|
-
},
|
|
82
|
+
}, It = (s) => {
|
|
83
83
|
switch (s) {
|
|
84
84
|
case "ETH.THOR":
|
|
85
85
|
return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
|
|
@@ -108,7 +108,7 @@ const At = "0x313ce567", rt = async ({ chain: s, to: t }) => {
|
|
|
108
108
|
case o.Ethereum:
|
|
109
109
|
return { identifier: `${s}.${s}`, decimal: h[s] };
|
|
110
110
|
}
|
|
111
|
-
},
|
|
111
|
+
}, Et = ({ chain: s, symbol: t }) => {
|
|
112
112
|
if (t.includes("/"))
|
|
113
113
|
return "Synth";
|
|
114
114
|
switch (s) {
|
|
@@ -138,65 +138,65 @@ const At = "0x313ce567", rt = async ({ chain: s, to: t }) => {
|
|
|
138
138
|
case o.Optimism:
|
|
139
139
|
return [o.Ethereum, o.Optimism].includes(t) ? "Native" : "OPTIMISM";
|
|
140
140
|
}
|
|
141
|
-
},
|
|
142
|
-
var
|
|
143
|
-
const [t, ...e] = s.split("."), r = s.includes("/"), n = e.join("."), i = (
|
|
141
|
+
}, oe = (s) => {
|
|
142
|
+
var a;
|
|
143
|
+
const [t, ...e] = s.split("."), r = s.includes("/"), n = e.join("."), i = (a = n == null ? void 0 : n.split("-")) == null ? void 0 : a[0];
|
|
144
144
|
return { chain: t, symbol: n, ticker: i, synth: r };
|
|
145
|
-
},
|
|
145
|
+
}, Ot = new RegExp(
|
|
146
146
|
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
|
|
147
147
|
"gmi"
|
|
148
|
-
),
|
|
148
|
+
), Mt = (s) => {
|
|
149
149
|
const [t, e] = s.split(".");
|
|
150
|
-
if (!
|
|
150
|
+
if (!At.includes(t))
|
|
151
151
|
return !0;
|
|
152
152
|
const [, r] = e.split("-");
|
|
153
|
-
return
|
|
154
|
-
},
|
|
153
|
+
return ot({ chain: t, symbol: e }) || !!r;
|
|
154
|
+
}, ae = (s) => s.filter((t) => {
|
|
155
155
|
const e = `${t.chain}.${t.symbol}`;
|
|
156
|
-
return !
|
|
157
|
-
}),
|
|
156
|
+
return !Ot.test(e) && Mt(e) && t.value !== "0";
|
|
157
|
+
}), Bt = ({
|
|
158
158
|
liquidityUnits: s,
|
|
159
159
|
poolUnits: t,
|
|
160
160
|
runeDepth: e
|
|
161
161
|
}) => {
|
|
162
|
-
const r =
|
|
163
|
-
return
|
|
164
|
-
},
|
|
162
|
+
const r = p(s), n = p(t), i = p(e), a = r.mul(i), c = n.mul(n).mul(2), u = n.mul(r).mul(2), d = r.mul(r), l = n.mul(n).mul(n);
|
|
163
|
+
return a.mul(c.sub(u).add(d)).div(l);
|
|
164
|
+
}, xt = ({
|
|
165
165
|
liquidityUnits: s,
|
|
166
166
|
poolUnits: t,
|
|
167
167
|
assetDepth: e
|
|
168
168
|
}) => {
|
|
169
|
-
const r =
|
|
170
|
-
return
|
|
171
|
-
},
|
|
169
|
+
const r = p(s), n = p(t), i = p(e), a = r.mul(i), c = n.mul(n).mul(2), u = n.mul(r).mul(2), d = r.mul(r), l = a.mul(c.sub(u).add(d)), _ = n.mul(n).mul(n);
|
|
170
|
+
return l.div(_);
|
|
171
|
+
}, ce = ({
|
|
172
172
|
percent: s,
|
|
173
173
|
runeDepth: t,
|
|
174
174
|
liquidityUnits: e,
|
|
175
175
|
poolUnits: r
|
|
176
|
-
}) =>
|
|
176
|
+
}) => Bt({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), ue = ({
|
|
177
177
|
percent: s,
|
|
178
178
|
assetDepth: t,
|
|
179
179
|
liquidityUnits: e,
|
|
180
180
|
poolUnits: r
|
|
181
|
-
}) =>
|
|
181
|
+
}) => xt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), p = (s) => b.fromBigInt(BigInt(s), h.THOR), qt = ({
|
|
182
182
|
liquidityUnits: s,
|
|
183
183
|
poolUnits: t,
|
|
184
184
|
runeDepth: e,
|
|
185
185
|
assetDepth: r
|
|
186
186
|
}) => ({
|
|
187
|
-
assetAmount:
|
|
188
|
-
runeAmount:
|
|
189
|
-
}),
|
|
187
|
+
assetAmount: p(r).mul(s).div(t),
|
|
188
|
+
runeAmount: p(e).mul(s).div(t)
|
|
189
|
+
}), le = ({
|
|
190
190
|
liquidityUnits: s,
|
|
191
191
|
poolUnits: t,
|
|
192
192
|
runeDepth: e,
|
|
193
193
|
assetDepth: r,
|
|
194
194
|
percent: n
|
|
195
195
|
}) => Object.fromEntries(
|
|
196
|
-
Object.entries(
|
|
197
|
-
([i,
|
|
196
|
+
Object.entries(qt({ liquidityUnits: s, poolUnits: t, runeDepth: e, assetDepth: r })).map(
|
|
197
|
+
([i, a]) => [i, a.mul(n)]
|
|
198
198
|
)
|
|
199
|
-
),
|
|
199
|
+
), de = ({
|
|
200
200
|
runeDepth: s,
|
|
201
201
|
poolUnits: t,
|
|
202
202
|
assetDepth: e,
|
|
@@ -204,12 +204,12 @@ const At = "0x313ce567", rt = async ({ chain: s, to: t }) => {
|
|
|
204
204
|
runeAmount: n,
|
|
205
205
|
assetAmount: i
|
|
206
206
|
}) => {
|
|
207
|
-
const
|
|
208
|
-
if (
|
|
209
|
-
return
|
|
210
|
-
const
|
|
211
|
-
return
|
|
212
|
-
},
|
|
207
|
+
const a = new b({ value: s, decimal: 8 }), c = new b({ value: e, decimal: 8 }), u = new b({ value: t, decimal: 8 }), d = new b({ value: n, decimal: 8 }), l = new b({ value: i, decimal: 8 }), _ = d.mul(c), T = l.mul(a), j = d.mul(l), pt = a.mul(c), ft = u.mul(_.add(T.add(j.mul(2)))), _t = _.add(T.add(pt.mul(2))), Q = ft.div(_t), H = p(r).add(Q);
|
|
208
|
+
if (Q.getBaseValue("number") === 0)
|
|
209
|
+
return H.div(u).getBaseValue("number");
|
|
210
|
+
const gt = u.add(H);
|
|
211
|
+
return H.div(gt).getBaseValue("number");
|
|
212
|
+
}, he = ({
|
|
213
213
|
runeAmount: s,
|
|
214
214
|
assetAmount: t,
|
|
215
215
|
runeDepth: e,
|
|
@@ -217,13 +217,13 @@ const At = "0x313ce567", rt = async ({ chain: s, to: t }) => {
|
|
|
217
217
|
}) => {
|
|
218
218
|
if (s === "0" || t === "0" || e === "0" || r === "0")
|
|
219
219
|
return 0;
|
|
220
|
-
const n =
|
|
221
|
-
return Math.abs(u.div(
|
|
220
|
+
const n = p(e), i = p(r), a = p(t), c = p(s), u = a.mul(n).sub(i.mul(c)), d = i.mul(c).add(n.mul(i));
|
|
221
|
+
return Math.abs(u.div(d).getBaseValue("number"));
|
|
222
222
|
}, Vt = ({
|
|
223
223
|
symbol: s,
|
|
224
224
|
ticker: t,
|
|
225
225
|
chain: e
|
|
226
|
-
}) => e === "ETH" && t !== "ETH" ? `${t}-${s.slice(-3)}` : s,
|
|
226
|
+
}) => e === "ETH" && t !== "ETH" ? `${t}-${s.slice(-3)}` : s, me = (s, t) => {
|
|
227
227
|
switch (s) {
|
|
228
228
|
case g.LEAVE:
|
|
229
229
|
case g.BOND: {
|
|
@@ -243,8 +243,8 @@ const At = "0x313ce567", rt = async ({ chain: s, to: t }) => {
|
|
|
243
243
|
return i ? `${s}:${e}/${r}::t:0` : `${s}:${e}.${r}:${n || ""}:t:0`;
|
|
244
244
|
}
|
|
245
245
|
case g.WITHDRAW: {
|
|
246
|
-
const { chain: e, ticker: r, symbol: n, basisPoints: i, targetAssetString:
|
|
247
|
-
return `${s}:${e}${
|
|
246
|
+
const { chain: e, ticker: r, symbol: n, basisPoints: i, targetAssetString: a, singleSide: c } = t, u = !c && a ? `:${a}` : "", d = Vt({ chain: e, symbol: n, ticker: r });
|
|
247
|
+
return `${s}:${e}${c ? "/" : "."}${d}:${i}${u}`;
|
|
248
248
|
}
|
|
249
249
|
case g.OPEN_LOAN:
|
|
250
250
|
case g.CLOSE_LOAN: {
|
|
@@ -254,20 +254,20 @@ const At = "0x313ce567", rt = async ({ chain: s, to: t }) => {
|
|
|
254
254
|
default:
|
|
255
255
|
return "";
|
|
256
256
|
}
|
|
257
|
-
},
|
|
257
|
+
}, pe = (s) => {
|
|
258
258
|
if (s < 0)
|
|
259
259
|
throw new Error("Invalid number of year");
|
|
260
260
|
return 10 + s;
|
|
261
|
-
},
|
|
261
|
+
}, fe = (s) => {
|
|
262
262
|
if (s.length > 30)
|
|
263
263
|
return !1;
|
|
264
264
|
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
265
265
|
return !!s.match(t);
|
|
266
|
-
},
|
|
267
|
-
class
|
|
266
|
+
}, _e = ([s, t, e, r, n]) => `${s}'/${t}'/${e}'/${r}${typeof n != "number" ? "" : `/${n}`}`;
|
|
267
|
+
class X extends Error {
|
|
268
268
|
constructor(t, e, r) {
|
|
269
|
-
const n = t.status || t.status === 0 ? t.status : "", i = t.statusText || "",
|
|
270
|
-
super(`Request failed with ${
|
|
269
|
+
const n = t.status || t.status === 0 ? t.status : "", i = t.statusText || "", a = `${n} ${i}`.trim(), c = a ? `status code ${a}` : "an unknown error";
|
|
270
|
+
super(`Request failed with ${c}`), Object.defineProperty(this, "response", {
|
|
271
271
|
enumerable: !0,
|
|
272
272
|
configurable: !0,
|
|
273
273
|
writable: !0,
|
|
@@ -285,7 +285,7 @@ class J extends Error {
|
|
|
285
285
|
}), this.name = "HTTPError", this.response = t, this.request = e, this.options = r;
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
|
-
class
|
|
288
|
+
class at extends Error {
|
|
289
289
|
constructor(t) {
|
|
290
290
|
super("Request timed out"), Object.defineProperty(this, "request", {
|
|
291
291
|
enumerable: !0,
|
|
@@ -295,28 +295,28 @@ class nt extends Error {
|
|
|
295
295
|
}), this.name = "TimeoutError", this.request = t;
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
|
-
const
|
|
298
|
+
const q = (s) => s !== null && typeof s == "object", B = (...s) => {
|
|
299
299
|
for (const t of s)
|
|
300
|
-
if ((!
|
|
300
|
+
if ((!q(t) || Array.isArray(t)) && t !== void 0)
|
|
301
301
|
throw new TypeError("The `options` argument must be an object");
|
|
302
|
-
return
|
|
303
|
-
},
|
|
302
|
+
return J({}, ...s);
|
|
303
|
+
}, ct = (s = {}, t = {}) => {
|
|
304
304
|
const e = new globalThis.Headers(s), r = t instanceof globalThis.Headers, n = new globalThis.Headers(t);
|
|
305
|
-
for (const [i,
|
|
306
|
-
r &&
|
|
305
|
+
for (const [i, a] of n.entries())
|
|
306
|
+
r && a === "undefined" || a === void 0 ? e.delete(i) : e.set(i, a);
|
|
307
307
|
return e;
|
|
308
|
-
},
|
|
308
|
+
}, J = (...s) => {
|
|
309
309
|
let t = {}, e = {};
|
|
310
310
|
for (const r of s)
|
|
311
311
|
if (Array.isArray(r))
|
|
312
312
|
Array.isArray(t) || (t = []), t = [...t, ...r];
|
|
313
|
-
else if (
|
|
313
|
+
else if (q(r)) {
|
|
314
314
|
for (let [n, i] of Object.entries(r))
|
|
315
|
-
|
|
316
|
-
|
|
315
|
+
q(i) && n in t && (i = J(t[n], i)), t = { ...t, [n]: i };
|
|
316
|
+
q(r.headers) && (e = ct(e, r.headers), t.headers = e);
|
|
317
317
|
}
|
|
318
318
|
return t;
|
|
319
|
-
},
|
|
319
|
+
}, kt = (() => {
|
|
320
320
|
let s = !1, t = !1;
|
|
321
321
|
const e = typeof globalThis.ReadableStream == "function", r = typeof globalThis.Request == "function";
|
|
322
322
|
return e && r && (t = new globalThis.Request("https://empty.invalid", {
|
|
@@ -327,13 +327,13 @@ const B = (s) => s !== null && typeof s == "object", E = (...s) => {
|
|
|
327
327
|
return s = !0, "half";
|
|
328
328
|
}
|
|
329
329
|
}).headers.has("Content-Type")), s && !t;
|
|
330
|
-
})(),
|
|
330
|
+
})(), Pt = typeof globalThis.AbortController == "function", Nt = typeof globalThis.ReadableStream == "function", jt = typeof globalThis.FormData == "function", ut = ["get", "post", "put", "patch", "head", "delete"], Ht = {
|
|
331
331
|
json: "application/json",
|
|
332
332
|
text: "text/*",
|
|
333
333
|
formData: "multipart/form-data",
|
|
334
334
|
arrayBuffer: "*/*",
|
|
335
335
|
blob: "*/*"
|
|
336
|
-
},
|
|
336
|
+
}, D = 2147483647, lt = Symbol("stop"), Lt = {
|
|
337
337
|
json: !0,
|
|
338
338
|
parseJson: !0,
|
|
339
339
|
searchParams: !0,
|
|
@@ -344,7 +344,7 @@ const B = (s) => s !== null && typeof s == "object", E = (...s) => {
|
|
|
344
344
|
throwHttpErrors: !0,
|
|
345
345
|
onDownloadProgress: !0,
|
|
346
346
|
fetch: !0
|
|
347
|
-
},
|
|
347
|
+
}, Dt = {
|
|
348
348
|
method: !0,
|
|
349
349
|
headers: !0,
|
|
350
350
|
body: !0,
|
|
@@ -360,18 +360,18 @@ const B = (s) => s !== null && typeof s == "object", E = (...s) => {
|
|
|
360
360
|
window: !0,
|
|
361
361
|
dispatcher: !0,
|
|
362
362
|
duplex: !0
|
|
363
|
-
},
|
|
363
|
+
}, Ut = (s) => ut.includes(s) ? s.toUpperCase() : s, Ft = ["get", "put", "head", "delete", "options", "trace"], Wt = [408, 413, 429, 500, 502, 503, 504], dt = [413, 429, 503], Z = {
|
|
364
364
|
limit: 2,
|
|
365
|
-
methods:
|
|
366
|
-
statusCodes:
|
|
367
|
-
afterStatusCodes:
|
|
365
|
+
methods: Ft,
|
|
366
|
+
statusCodes: Wt,
|
|
367
|
+
afterStatusCodes: dt,
|
|
368
368
|
maxRetryAfter: Number.POSITIVE_INFINITY,
|
|
369
369
|
backoffLimit: Number.POSITIVE_INFINITY,
|
|
370
370
|
delay: (s) => 0.3 * 2 ** (s - 1) * 1e3
|
|
371
|
-
},
|
|
371
|
+
}, Gt = (s = {}) => {
|
|
372
372
|
if (typeof s == "number")
|
|
373
373
|
return {
|
|
374
|
-
...
|
|
374
|
+
...Z,
|
|
375
375
|
limit: s
|
|
376
376
|
};
|
|
377
377
|
if (s.methods && !Array.isArray(s.methods))
|
|
@@ -379,22 +379,22 @@ const B = (s) => s !== null && typeof s == "object", E = (...s) => {
|
|
|
379
379
|
if (s.statusCodes && !Array.isArray(s.statusCodes))
|
|
380
380
|
throw new Error("retry.statusCodes must be an array");
|
|
381
381
|
return {
|
|
382
|
-
...
|
|
382
|
+
...Z,
|
|
383
383
|
...s,
|
|
384
|
-
afterStatusCodes:
|
|
384
|
+
afterStatusCodes: dt
|
|
385
385
|
};
|
|
386
386
|
};
|
|
387
|
-
async function
|
|
387
|
+
async function Yt(s, t, e, r) {
|
|
388
388
|
return new Promise((n, i) => {
|
|
389
|
-
const
|
|
390
|
-
e && e.abort(), i(new
|
|
389
|
+
const a = setTimeout(() => {
|
|
390
|
+
e && e.abort(), i(new at(s));
|
|
391
391
|
}, r.timeout);
|
|
392
392
|
r.fetch(s, t).then(n).catch(i).then(() => {
|
|
393
|
-
clearTimeout(
|
|
393
|
+
clearTimeout(a);
|
|
394
394
|
});
|
|
395
395
|
});
|
|
396
396
|
}
|
|
397
|
-
async function
|
|
397
|
+
async function zt(s, { signal: t }) {
|
|
398
398
|
return new Promise((e, r) => {
|
|
399
399
|
t && (t.throwIfAborted(), t.addEventListener("abort", n, { once: !0 }));
|
|
400
400
|
function n() {
|
|
@@ -405,51 +405,51 @@ async function Gt(s, { signal: t }) {
|
|
|
405
405
|
}, s);
|
|
406
406
|
});
|
|
407
407
|
}
|
|
408
|
-
const
|
|
408
|
+
const Jt = (s, t) => {
|
|
409
409
|
const e = {};
|
|
410
410
|
for (const r in t)
|
|
411
|
-
!(r in
|
|
411
|
+
!(r in Dt) && !(r in Lt) && !(r in s) && (e[r] = t[r]);
|
|
412
412
|
return e;
|
|
413
413
|
};
|
|
414
|
-
class
|
|
414
|
+
class k {
|
|
415
415
|
static create(t, e) {
|
|
416
|
-
const r = new
|
|
417
|
-
if (typeof r._options.timeout == "number" && r._options.timeout >
|
|
418
|
-
throw new RangeError(`The \`timeout\` option cannot be greater than ${
|
|
416
|
+
const r = new k(t, e), n = async () => {
|
|
417
|
+
if (typeof r._options.timeout == "number" && r._options.timeout > D)
|
|
418
|
+
throw new RangeError(`The \`timeout\` option cannot be greater than ${D}`);
|
|
419
419
|
await Promise.resolve();
|
|
420
|
-
let
|
|
420
|
+
let c = await r._fetch();
|
|
421
421
|
for (const u of r._options.hooks.afterResponse) {
|
|
422
|
-
const
|
|
423
|
-
|
|
422
|
+
const d = await u(r.request, r._options, r._decorateResponse(c.clone()));
|
|
423
|
+
d instanceof globalThis.Response && (c = d);
|
|
424
424
|
}
|
|
425
|
-
if (r._decorateResponse(
|
|
426
|
-
let u = new
|
|
427
|
-
for (const
|
|
428
|
-
u = await
|
|
425
|
+
if (r._decorateResponse(c), !c.ok && r._options.throwHttpErrors) {
|
|
426
|
+
let u = new X(c, r.request, r._options);
|
|
427
|
+
for (const d of r._options.hooks.beforeError)
|
|
428
|
+
u = await d(u);
|
|
429
429
|
throw u;
|
|
430
430
|
}
|
|
431
431
|
if (r._options.onDownloadProgress) {
|
|
432
432
|
if (typeof r._options.onDownloadProgress != "function")
|
|
433
433
|
throw new TypeError("The `onDownloadProgress` option must be a function");
|
|
434
|
-
if (!
|
|
434
|
+
if (!Nt)
|
|
435
435
|
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
|
|
436
|
-
return r._stream(
|
|
436
|
+
return r._stream(c.clone(), r._options.onDownloadProgress);
|
|
437
437
|
}
|
|
438
|
-
return
|
|
439
|
-
},
|
|
440
|
-
for (const [
|
|
441
|
-
c
|
|
438
|
+
return c;
|
|
439
|
+
}, a = r._options.retry.methods.includes(r.request.method.toLowerCase()) ? r._retry(n) : n();
|
|
440
|
+
for (const [c, u] of Object.entries(Ht))
|
|
441
|
+
a[c] = async () => {
|
|
442
442
|
r.request.headers.set("accept", r.request.headers.get("accept") || u);
|
|
443
|
-
const
|
|
444
|
-
if (
|
|
445
|
-
if (
|
|
443
|
+
const l = (await a).clone();
|
|
444
|
+
if (c === "json") {
|
|
445
|
+
if (l.status === 204 || (await l.clone().arrayBuffer()).byteLength === 0)
|
|
446
446
|
return "";
|
|
447
447
|
if (e.parseJson)
|
|
448
|
-
return e.parseJson(await
|
|
448
|
+
return e.parseJson(await l.text());
|
|
449
449
|
}
|
|
450
|
-
return
|
|
450
|
+
return l[c]();
|
|
451
451
|
};
|
|
452
|
-
return
|
|
452
|
+
return a;
|
|
453
453
|
}
|
|
454
454
|
// eslint-disable-next-line complexity
|
|
455
455
|
constructor(t, e = {}) {
|
|
@@ -482,17 +482,17 @@ class V {
|
|
|
482
482
|
// TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208
|
|
483
483
|
credentials: this._input.credentials || "same-origin",
|
|
484
484
|
...e,
|
|
485
|
-
headers:
|
|
486
|
-
hooks:
|
|
485
|
+
headers: ct(this._input.headers, e.headers),
|
|
486
|
+
hooks: J({
|
|
487
487
|
beforeRequest: [],
|
|
488
488
|
beforeRetry: [],
|
|
489
489
|
beforeError: [],
|
|
490
490
|
afterResponse: []
|
|
491
491
|
}, e.hooks),
|
|
492
|
-
method:
|
|
492
|
+
method: Ut(e.method ?? this._input.method),
|
|
493
493
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
494
494
|
prefixUrl: String(e.prefixUrl || ""),
|
|
495
|
-
retry:
|
|
495
|
+
retry: Gt(e.retry),
|
|
496
496
|
throwHttpErrors: e.throwHttpErrors !== !1,
|
|
497
497
|
timeout: e.timeout ?? 1e4,
|
|
498
498
|
fetch: e.fetch ?? globalThis.fetch.bind(globalThis)
|
|
@@ -503,7 +503,7 @@ class V {
|
|
|
503
503
|
throw new Error("`input` must not begin with a slash when using `prefixUrl`");
|
|
504
504
|
this._options.prefixUrl.endsWith("/") || (this._options.prefixUrl += "/"), this._input = this._options.prefixUrl + this._input;
|
|
505
505
|
}
|
|
506
|
-
if (
|
|
506
|
+
if (Pt) {
|
|
507
507
|
if (this.abortController = new globalThis.AbortController(), this._options.signal) {
|
|
508
508
|
const r = this._options.signal;
|
|
509
509
|
this._options.signal.addEventListener("abort", () => {
|
|
@@ -512,15 +512,15 @@ class V {
|
|
|
512
512
|
}
|
|
513
513
|
this._options.signal = this.abortController.signal;
|
|
514
514
|
}
|
|
515
|
-
if (
|
|
515
|
+
if (kt && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
|
|
516
516
|
const n = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), i = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, n);
|
|
517
|
-
(
|
|
517
|
+
(jt && 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(i, { ...this.request }), this._options);
|
|
518
518
|
}
|
|
519
519
|
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 }));
|
|
520
520
|
}
|
|
521
521
|
_calculateRetryDelay(t) {
|
|
522
|
-
if (this._retryCount++, this._retryCount < this._options.retry.limit && !(t instanceof
|
|
523
|
-
if (t instanceof
|
|
522
|
+
if (this._retryCount++, this._retryCount < this._options.retry.limit && !(t instanceof at)) {
|
|
523
|
+
if (t instanceof X) {
|
|
524
524
|
if (!this._options.retry.statusCodes.includes(t.response.status))
|
|
525
525
|
return 0;
|
|
526
526
|
const r = t.response.headers.get("Retry-After");
|
|
@@ -543,16 +543,16 @@ class V {
|
|
|
543
543
|
try {
|
|
544
544
|
return await t();
|
|
545
545
|
} catch (e) {
|
|
546
|
-
const r = Math.min(this._calculateRetryDelay(e),
|
|
546
|
+
const r = Math.min(this._calculateRetryDelay(e), D);
|
|
547
547
|
if (r !== 0 && this._retryCount > 0) {
|
|
548
|
-
await
|
|
548
|
+
await zt(r, { signal: this._options.signal });
|
|
549
549
|
for (const n of this._options.hooks.beforeRetry)
|
|
550
550
|
if (await n({
|
|
551
551
|
request: this.request,
|
|
552
552
|
options: this._options,
|
|
553
553
|
error: e,
|
|
554
554
|
retryCount: this._retryCount
|
|
555
|
-
}) ===
|
|
555
|
+
}) === lt)
|
|
556
556
|
return;
|
|
557
557
|
return this._retry(t);
|
|
558
558
|
}
|
|
@@ -569,8 +569,8 @@ class V {
|
|
|
569
569
|
if (r instanceof Response)
|
|
570
570
|
return r;
|
|
571
571
|
}
|
|
572
|
-
const t =
|
|
573
|
-
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) :
|
|
572
|
+
const t = Jt(this.request, this._options);
|
|
573
|
+
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Yt(this.request.clone(), t, this.abortController, this._options);
|
|
574
574
|
}
|
|
575
575
|
/* istanbul ignore next */
|
|
576
576
|
_stream(t, e) {
|
|
@@ -582,22 +582,22 @@ class V {
|
|
|
582
582
|
headers: t.headers
|
|
583
583
|
})) : new globalThis.Response(new globalThis.ReadableStream({
|
|
584
584
|
async start(i) {
|
|
585
|
-
const
|
|
585
|
+
const a = t.body.getReader();
|
|
586
586
|
e && e({ percent: 0, transferredBytes: 0, totalBytes: r }, new Uint8Array());
|
|
587
|
-
async function
|
|
588
|
-
const { done: u, value:
|
|
587
|
+
async function c() {
|
|
588
|
+
const { done: u, value: d } = await a.read();
|
|
589
589
|
if (u) {
|
|
590
590
|
i.close();
|
|
591
591
|
return;
|
|
592
592
|
}
|
|
593
593
|
if (e) {
|
|
594
|
-
n +=
|
|
595
|
-
const
|
|
596
|
-
e({ percent:
|
|
594
|
+
n += d.byteLength;
|
|
595
|
+
const l = r === 0 ? 0 : n / r;
|
|
596
|
+
e({ percent: l, transferredBytes: n, totalBytes: r }, d);
|
|
597
597
|
}
|
|
598
|
-
i.enqueue(
|
|
598
|
+
i.enqueue(d), await c();
|
|
599
599
|
}
|
|
600
|
-
await
|
|
600
|
+
await c();
|
|
601
601
|
}
|
|
602
602
|
}), {
|
|
603
603
|
status: t.status,
|
|
@@ -607,60 +607,59 @@ class V {
|
|
|
607
607
|
}
|
|
608
608
|
}
|
|
609
609
|
/*! MIT License © Sindre Sorhus */
|
|
610
|
-
const
|
|
611
|
-
const t = (e, r) =>
|
|
612
|
-
for (const e of
|
|
613
|
-
t[e] = (r, n) =>
|
|
614
|
-
return t.create = (e) =>
|
|
615
|
-
},
|
|
616
|
-
get: (s, t) =>
|
|
617
|
-
post: (s, t) =>
|
|
618
|
-
},
|
|
610
|
+
const U = (s) => {
|
|
611
|
+
const t = (e, r) => k.create(e, B(s, r));
|
|
612
|
+
for (const e of ut)
|
|
613
|
+
t[e] = (r, n) => k.create(r, B(s, n, { method: e }));
|
|
614
|
+
return t.create = (e) => U(B(e)), t.extend = (e) => U(B(s, e)), t.stop = lt, t;
|
|
615
|
+
}, Kt = U(), Qt = Kt, Xt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, tt = Qt.create({ headers: Xt }), Zt = {
|
|
616
|
+
get: (s, t) => tt.get(s, t).json(),
|
|
617
|
+
post: (s, t) => tt.post(s, t).json()
|
|
618
|
+
}, et = Object.values(o), te = (s = "") => {
|
|
619
619
|
const t = s.toUpperCase(), [e] = t.split(".");
|
|
620
|
-
if (
|
|
620
|
+
if (et.includes(e))
|
|
621
621
|
return !0;
|
|
622
622
|
const [r] = t.split("/");
|
|
623
|
-
if (
|
|
623
|
+
if (et.includes(r))
|
|
624
624
|
return !0;
|
|
625
625
|
throw new Error(
|
|
626
626
|
`Invalid identifier: ${s}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
627
627
|
);
|
|
628
|
-
},
|
|
629
|
-
function
|
|
628
|
+
}, I = 8, w = (s) => 10n ** BigInt(s), S = (s) => Math.log10(parseFloat(s.toString()));
|
|
629
|
+
function P({
|
|
630
630
|
value: s,
|
|
631
|
-
bigIntDecimal: t =
|
|
632
|
-
decimal: e =
|
|
631
|
+
bigIntDecimal: t = I,
|
|
632
|
+
decimal: e = I
|
|
633
633
|
}) {
|
|
634
634
|
const r = s < 0n;
|
|
635
635
|
let n = s.toString().substring(r ? 1 : 0);
|
|
636
636
|
const i = e - (n.length - 1);
|
|
637
637
|
i > 0 && (n = "0".repeat(i) + n);
|
|
638
|
-
const
|
|
639
|
-
let
|
|
640
|
-
return parseInt(
|
|
638
|
+
const a = n.length - e;
|
|
639
|
+
let c = n.slice(-e);
|
|
640
|
+
return parseInt(c[t]) >= 5 ? c = `${c.substring(0, t - 1)}${(parseInt(c[t - 1]) + 1).toString()}` : c = c.substring(0, t), `${r ? "-" : ""}${n.slice(0, a)}.${c}`.replace(
|
|
641
641
|
/\.?0*$/,
|
|
642
642
|
""
|
|
643
643
|
);
|
|
644
644
|
}
|
|
645
|
-
var
|
|
646
|
-
const
|
|
645
|
+
var v, C, y, R, N, ht, O, F, M, W;
|
|
646
|
+
const K = class K {
|
|
647
647
|
constructor(t) {
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
), f(this, x, ut).call(this, e);
|
|
648
|
+
$(this, v);
|
|
649
|
+
$(this, y);
|
|
650
|
+
$(this, N);
|
|
651
|
+
$(this, O);
|
|
652
|
+
$(this, M);
|
|
653
|
+
f(this, "decimalMultiplier", 10n ** 8n);
|
|
654
|
+
f(this, "bigIntValue", 0n);
|
|
655
|
+
f(this, "decimal");
|
|
656
|
+
const e = G(t), r = typeof t == "object";
|
|
657
|
+
this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier : w(Math.max(rt(x(e)), this.decimal || 0)), m(this, N, ht).call(this, e);
|
|
659
658
|
}
|
|
660
659
|
static fromBigInt(t, e) {
|
|
661
|
-
return new
|
|
660
|
+
return new K({
|
|
662
661
|
decimal: e,
|
|
663
|
-
value:
|
|
662
|
+
value: P({ value: t, bigIntDecimal: e, decimal: e })
|
|
664
663
|
});
|
|
665
664
|
}
|
|
666
665
|
static shiftDecimals({
|
|
@@ -669,7 +668,7 @@ const Y = class Y {
|
|
|
669
668
|
to: r
|
|
670
669
|
}) {
|
|
671
670
|
return this.fromBigInt(
|
|
672
|
-
t.getBaseValue("bigint") *
|
|
671
|
+
t.getBaseValue("bigint") * w(r) / w(e),
|
|
673
672
|
r
|
|
674
673
|
);
|
|
675
674
|
}
|
|
@@ -677,73 +676,64 @@ const Y = class Y {
|
|
|
677
676
|
return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
|
|
678
677
|
}
|
|
679
678
|
add(...t) {
|
|
680
|
-
return
|
|
679
|
+
return m(this, v, C).call(this, "add", ...t);
|
|
681
680
|
}
|
|
682
681
|
sub(...t) {
|
|
683
|
-
return
|
|
682
|
+
return m(this, v, C).call(this, "sub", ...t);
|
|
684
683
|
}
|
|
685
684
|
mul(...t) {
|
|
686
|
-
return
|
|
685
|
+
return m(this, v, C).call(this, "mul", ...t);
|
|
687
686
|
}
|
|
688
687
|
div(...t) {
|
|
689
|
-
return
|
|
688
|
+
return m(this, v, C).call(this, "div", ...t);
|
|
690
689
|
}
|
|
691
690
|
gt(t) {
|
|
692
|
-
return this
|
|
691
|
+
return m(this, y, R).call(this, "gt", t);
|
|
693
692
|
}
|
|
694
693
|
gte(t) {
|
|
695
|
-
return this
|
|
694
|
+
return m(this, y, R).call(this, "gte", t);
|
|
696
695
|
}
|
|
697
696
|
lt(t) {
|
|
698
|
-
return this
|
|
697
|
+
return m(this, y, R).call(this, "lt", t);
|
|
699
698
|
}
|
|
700
699
|
lte(t) {
|
|
701
|
-
return this
|
|
700
|
+
return m(this, y, R).call(this, "lte", t);
|
|
702
701
|
}
|
|
703
702
|
eqValue(t) {
|
|
704
|
-
return this
|
|
703
|
+
return m(this, y, R).call(this, "eqValue", t);
|
|
705
704
|
}
|
|
705
|
+
// @ts-expect-error False positive
|
|
706
706
|
getValue(t) {
|
|
707
707
|
const e = this.formatBigIntToSafeValue(
|
|
708
708
|
this.bigIntValue,
|
|
709
|
-
this.decimal ||
|
|
709
|
+
this.decimal || S(this.decimalMultiplier)
|
|
710
710
|
);
|
|
711
711
|
switch (t) {
|
|
712
712
|
case "number":
|
|
713
713
|
return Number(e);
|
|
714
714
|
case "string":
|
|
715
715
|
return e;
|
|
716
|
-
|
|
717
|
-
return this.bigIntValue * BigInt(this.decimal || 8n) / this.decimalMultiplier;
|
|
716
|
+
case "bigint":
|
|
717
|
+
return this.bigIntValue * 10n ** BigInt(this.decimal || 8n) / this.decimalMultiplier;
|
|
718
718
|
}
|
|
719
719
|
}
|
|
720
|
+
// @ts-expect-error
|
|
720
721
|
getBaseValue(t) {
|
|
721
|
-
const e = this.decimalMultiplier /
|
|
722
|
+
const e = this.decimalMultiplier / w(this.decimal || h.THOR), r = this.bigIntValue / e;
|
|
722
723
|
switch (t) {
|
|
723
724
|
case "number":
|
|
724
725
|
return Number(r);
|
|
725
726
|
case "string":
|
|
726
727
|
return r.toString();
|
|
727
|
-
|
|
728
|
+
case "bigint":
|
|
728
729
|
return r;
|
|
729
730
|
}
|
|
730
731
|
}
|
|
731
732
|
getBigIntValue(t, e) {
|
|
732
733
|
if (!e && typeof t == "object")
|
|
733
734
|
return t.bigIntValue;
|
|
734
|
-
const r =
|
|
735
|
-
return n === "0" || n === "undefined" ? 0n :
|
|
736
|
-
}
|
|
737
|
-
formatBigIntToSafeValue(t, e) {
|
|
738
|
-
const r = e || this.decimal || S, n = Math.max(
|
|
739
|
-
r,
|
|
740
|
-
$(this.decimalMultiplier)
|
|
741
|
-
), i = t < 0n, c = t.toString().substring(i ? 1 : 0), a = n - (c.length - 1), u = a > 0 ? "0".repeat(a) + c : c, l = u.length - n;
|
|
742
|
-
let d = u.slice(-n);
|
|
743
|
-
return parseInt(d[r]) >= 5 ? d = `${d.substring(0, r - 1)}${(parseInt(d[r - 1]) + 1).toString()}` : d = d.substring(0, r), `${i ? "-" : ""}${u.slice(
|
|
744
|
-
0,
|
|
745
|
-
l
|
|
746
|
-
)}.${d}`.replace(/\.?0*$/, "");
|
|
735
|
+
const r = G(t), n = x(r);
|
|
736
|
+
return n === "0" || n === "undefined" ? 0n : m(this, M, W).call(this, n, e);
|
|
747
737
|
}
|
|
748
738
|
toSignificant(t = 6) {
|
|
749
739
|
const [e, r] = this.getValue("string").split("."), n = e || "", i = r || "";
|
|
@@ -756,9 +746,9 @@ const Y = class Y {
|
|
|
756
746
|
t - n.length,
|
|
757
747
|
"0"
|
|
758
748
|
);
|
|
759
|
-
const
|
|
749
|
+
const c = parseInt(i), u = `${c}`.slice(0, t);
|
|
760
750
|
return `0.${u.padStart(
|
|
761
|
-
i.length - `${
|
|
751
|
+
i.length - `${c}`.length + u.length,
|
|
762
752
|
"0"
|
|
763
753
|
)}`;
|
|
764
754
|
}
|
|
@@ -766,9 +756,9 @@ const Y = class Y {
|
|
|
766
756
|
const [e, r] = this.getValue("string").split("."), n = e || "", i = r || "";
|
|
767
757
|
if (parseInt(n))
|
|
768
758
|
return `${n}.${i.slice(0, t)}`.padEnd(t, "0");
|
|
769
|
-
const
|
|
770
|
-
return `0.${
|
|
771
|
-
i.length - `${
|
|
759
|
+
const a = parseInt(i), c = `${a}`.slice(0, t);
|
|
760
|
+
return `0.${c.padStart(
|
|
761
|
+
i.length - `${a}`.length + c.length,
|
|
772
762
|
"0"
|
|
773
763
|
)}`;
|
|
774
764
|
}
|
|
@@ -776,8 +766,8 @@ const Y = class Y {
|
|
|
776
766
|
const e = this.getValue("number"), r = ["", "K", "M", "B", "T", "Q", "Qi", "S"], n = Math.floor(Math.log10(Math.abs(e)) / 3), i = r[n];
|
|
777
767
|
if (!i)
|
|
778
768
|
return this.getValue("string");
|
|
779
|
-
const
|
|
780
|
-
return `${(e /
|
|
769
|
+
const a = 10 ** (n * 3);
|
|
770
|
+
return `${(e / a).toFixed(t)}${i}`;
|
|
781
771
|
}
|
|
782
772
|
toCurrency(t = "$", {
|
|
783
773
|
currencyPosition: e = "start",
|
|
@@ -785,93 +775,122 @@ const Y = class Y {
|
|
|
785
775
|
decimalSeparator: n = ".",
|
|
786
776
|
thousandSeparator: i = ","
|
|
787
777
|
} = {}) {
|
|
788
|
-
const
|
|
789
|
-
return `${e === "start" ? t : ""}${
|
|
778
|
+
const a = this.getValue("number"), [c, u = ""] = a.toFixed(6).split("."), d = c.replace(/\B(?=(\d{3})+(?!\d))/g, i), l = !c && !u ? "0.00" : c === "0" ? `${parseFloat(`0.${u}`)}`.replace(".", n) : `${d}${parseInt(u) ? `${n}${u.slice(0, r)}` : ""}`;
|
|
779
|
+
return `${e === "start" ? t : ""}${l}${e === "end" ? t : ""}`;
|
|
780
|
+
}
|
|
781
|
+
formatBigIntToSafeValue(t, e) {
|
|
782
|
+
const r = e || this.decimal || I, n = Math.max(
|
|
783
|
+
r,
|
|
784
|
+
S(this.decimalMultiplier)
|
|
785
|
+
), i = t < 0n, a = t.toString().substring(i ? 1 : 0), c = n - (a.length - 1), u = c > 0 ? "0".repeat(c) + a : a, d = u.length - n;
|
|
786
|
+
let l = u.slice(-n);
|
|
787
|
+
return parseInt(l[r]) >= 5 ? l = `${l.substring(0, r - 1)}${(parseInt(l[r - 1]) + 1).toString()}` : l = l.substring(0, r), `${i ? "-" : ""}${u.slice(
|
|
788
|
+
0,
|
|
789
|
+
d
|
|
790
|
+
)}.${l}`.replace(/\.?0*$/, "");
|
|
790
791
|
}
|
|
791
792
|
};
|
|
792
|
-
|
|
793
|
-
const r =
|
|
794
|
-
(
|
|
795
|
-
const l = this.getBigIntValue(
|
|
793
|
+
v = new WeakSet(), C = function(t, ...e) {
|
|
794
|
+
const r = m(this, O, F).call(this, this, ...e), n = Math.max(r, S(this.decimalMultiplier)), i = w(n), a = e.reduce(
|
|
795
|
+
(u, d) => {
|
|
796
|
+
const l = this.getBigIntValue(d, n);
|
|
796
797
|
switch (t) {
|
|
797
798
|
case "add":
|
|
798
|
-
return
|
|
799
|
+
return u + l;
|
|
799
800
|
case "sub":
|
|
800
|
-
return
|
|
801
|
+
return u - l;
|
|
801
802
|
case "mul":
|
|
802
|
-
return
|
|
803
|
+
return u * l / i;
|
|
803
804
|
case "div": {
|
|
804
805
|
if (l === 0n)
|
|
805
806
|
throw new RangeError("Division by zero");
|
|
806
|
-
return
|
|
807
|
+
return u * i / l;
|
|
807
808
|
}
|
|
808
809
|
default:
|
|
809
|
-
return
|
|
810
|
+
return u;
|
|
810
811
|
}
|
|
811
812
|
},
|
|
812
813
|
//normalize is to precision multiplier base
|
|
813
|
-
this.bigIntValue *
|
|
814
|
-
), c =
|
|
815
|
-
bigIntDecimal:
|
|
816
|
-
decimal:
|
|
817
|
-
value:
|
|
814
|
+
this.bigIntValue * i / this.decimalMultiplier
|
|
815
|
+
), c = P({
|
|
816
|
+
bigIntDecimal: n,
|
|
817
|
+
decimal: n,
|
|
818
|
+
value: a
|
|
819
|
+
});
|
|
820
|
+
return new this.constructor({
|
|
821
|
+
decimalMultiplier: w(n),
|
|
822
|
+
decimal: this.decimal,
|
|
823
|
+
value: c,
|
|
824
|
+
identifier: this.toString()
|
|
818
825
|
});
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
826
|
+
}, y = new WeakSet(), R = function(t, ...e) {
|
|
827
|
+
const r = m(this, O, F).call(this, this, ...e), n = this.getBigIntValue(e[0], r), i = this.getBigIntValue(this, r);
|
|
828
|
+
switch (t) {
|
|
829
|
+
case "gt":
|
|
830
|
+
return i > n;
|
|
831
|
+
case "gte":
|
|
832
|
+
return i >= n;
|
|
833
|
+
case "lt":
|
|
834
|
+
return i < n;
|
|
835
|
+
case "lte":
|
|
836
|
+
return i <= n;
|
|
837
|
+
case "eqValue":
|
|
838
|
+
return i === n;
|
|
839
|
+
}
|
|
840
|
+
}, N = new WeakSet(), ht = function(t) {
|
|
841
|
+
const e = x(t) || "0";
|
|
842
|
+
this.bigIntValue = m(this, M, W).call(this, e);
|
|
843
|
+
}, O = new WeakSet(), F = function(...t) {
|
|
844
|
+
const e = t.map((r) => typeof r == "object" ? r.decimal || S(r.decimalMultiplier) : rt(x(r))).filter(Boolean);
|
|
845
|
+
return Math.max(...e, I);
|
|
846
|
+
}, M = new WeakSet(), W = function(t, e) {
|
|
847
|
+
const r = e ? w(e) : this.decimalMultiplier, n = S(r), [i = "", a = ""] = t.split(".");
|
|
848
|
+
return BigInt(`${i}${a.padEnd(n, "0")}`);
|
|
831
849
|
};
|
|
832
|
-
let
|
|
833
|
-
const
|
|
850
|
+
let E = K;
|
|
851
|
+
const ee = Intl.NumberFormat("fullwide", {
|
|
834
852
|
useGrouping: !1,
|
|
835
853
|
maximumFractionDigits: 20
|
|
836
854
|
});
|
|
837
|
-
function
|
|
838
|
-
const e = `${typeof s == "number" ?
|
|
855
|
+
function x(s) {
|
|
856
|
+
const e = `${typeof s == "number" ? ee.format(s) : G(s)}`.replaceAll(",", ".").split(".");
|
|
839
857
|
return e.length > 1 ? `${e.slice(0, -1).join("")}.${e.at(-1)}` : e[0];
|
|
840
858
|
}
|
|
841
|
-
function
|
|
859
|
+
function rt(s) {
|
|
842
860
|
var e;
|
|
843
861
|
const t = ((e = s.split(".")[1]) == null ? void 0 : e.length) || 0;
|
|
844
|
-
return Math.max(t,
|
|
862
|
+
return Math.max(t, I);
|
|
845
863
|
}
|
|
846
|
-
function
|
|
864
|
+
function G(s) {
|
|
847
865
|
return typeof s == "object" ? "getValue" in s ? s.getValue("string") : s.value : s;
|
|
848
866
|
}
|
|
849
|
-
const
|
|
850
|
-
let
|
|
851
|
-
const
|
|
852
|
-
if (!
|
|
867
|
+
const V = (s, t) => typeof s == "bigint" ? P({ value: s, bigIntDecimal: t, decimal: t }) : s;
|
|
868
|
+
let Y;
|
|
869
|
+
const st = (s) => {
|
|
870
|
+
if (!Y)
|
|
853
871
|
throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");
|
|
854
|
-
return
|
|
855
|
-
},
|
|
856
|
-
|
|
857
|
-
const e = await
|
|
858
|
-
return new
|
|
872
|
+
return Y.get(s.toUpperCase()) || { decimal: h.THOR, identifier: "" };
|
|
873
|
+
}, nt = async (s, t = 0) => {
|
|
874
|
+
te(s);
|
|
875
|
+
const e = await Ct(z(s)), r = V(t, e);
|
|
876
|
+
return new A({ decimal: e, value: r, identifier: s });
|
|
859
877
|
};
|
|
860
|
-
class
|
|
878
|
+
class A extends E {
|
|
861
879
|
constructor(e) {
|
|
862
880
|
const r = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`;
|
|
863
881
|
super(
|
|
864
|
-
e.value instanceof
|
|
882
|
+
e.value instanceof E ? e.value : { decimal: e.decimal, value: e.value }
|
|
865
883
|
);
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
884
|
+
f(this, "address");
|
|
885
|
+
f(this, "chain");
|
|
886
|
+
f(this, "isGasAsset", !1);
|
|
887
|
+
f(this, "isSynthetic", !1);
|
|
888
|
+
f(this, "symbol");
|
|
889
|
+
f(this, "tax");
|
|
890
|
+
f(this, "ticker");
|
|
891
|
+
f(this, "type");
|
|
892
|
+
const n = z(r);
|
|
893
|
+
this.type = Et(n), this.chain = n.chain, this.ticker = n.ticker, this.symbol = n.symbol, this.address = n.address, this.isSynthetic = n.isSynthetic, this.isGasAsset = n.isGasAsset, this.tax = e.tax;
|
|
875
894
|
}
|
|
876
895
|
toString(e = !1) {
|
|
877
896
|
const r = this.isSynthetic ? this.symbol.split("-")[0] : this.ticker;
|
|
@@ -884,24 +903,26 @@ class y extends C {
|
|
|
884
903
|
return this.chain === e && this.symbol === r;
|
|
885
904
|
}
|
|
886
905
|
static async fromString(e, r = 0) {
|
|
887
|
-
return
|
|
906
|
+
return nt(e, r);
|
|
888
907
|
}
|
|
889
908
|
static fromStringSync(e, r = 0) {
|
|
890
|
-
const { isSynthetic: n } =
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
909
|
+
const { isSynthetic: n } = z(e), {
|
|
910
|
+
tax: i,
|
|
911
|
+
decimal: a,
|
|
912
|
+
identifier: c
|
|
913
|
+
} = st(e), u = V(r, a);
|
|
914
|
+
return c ? new A({ tax: i, decimal: a, identifier: c, value: u }) : n ? new A({ tax: i, decimal: 8, identifier: e, value: u }) : void 0;
|
|
894
915
|
}
|
|
895
916
|
static async fromIdentifier(e, r = 0) {
|
|
896
|
-
return
|
|
917
|
+
return nt(e, r);
|
|
897
918
|
}
|
|
898
919
|
static fromIdentifierSync(e, r = 0) {
|
|
899
|
-
const { decimal: n, identifier: i } =
|
|
900
|
-
return new
|
|
920
|
+
const { decimal: n, identifier: i } = st(e), a = V(r, n);
|
|
921
|
+
return new A({ decimal: n, identifier: i, value: a });
|
|
901
922
|
}
|
|
902
923
|
static fromChainOrSignature(e, r = 0) {
|
|
903
|
-
const { decimal: n, identifier: i } =
|
|
904
|
-
return new
|
|
924
|
+
const { decimal: n, identifier: i } = It(e), a = V(r, n);
|
|
925
|
+
return new A({ value: a, decimal: n, identifier: i });
|
|
905
926
|
}
|
|
906
927
|
static async loadStaticAssets() {
|
|
907
928
|
return new Promise(
|
|
@@ -912,12 +933,12 @@ class y extends C {
|
|
|
912
933
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
913
934
|
ThorchainList: n,
|
|
914
935
|
NativeList: i,
|
|
915
|
-
...
|
|
936
|
+
...a
|
|
916
937
|
} = await import("@swapkit/tokens");
|
|
917
|
-
|
|
918
|
-
(u, { tokens:
|
|
919
|
-
const
|
|
920
|
-
u.set(
|
|
938
|
+
Y = [i, ...Object.values(a)].reduce(
|
|
939
|
+
(u, { tokens: d }) => (d.forEach(({ identifier: l, chain: _, ...T }) => {
|
|
940
|
+
const j = "decimals" in T ? T.decimals : h[_];
|
|
941
|
+
u.set(l, { identifier: l, decimal: j });
|
|
921
942
|
}), u),
|
|
922
943
|
/* @__PURE__ */ new Map()
|
|
923
944
|
), e({ ok: !0 });
|
|
@@ -932,8 +953,8 @@ class y extends C {
|
|
|
932
953
|
);
|
|
933
954
|
}
|
|
934
955
|
}
|
|
935
|
-
const
|
|
936
|
-
const t =
|
|
956
|
+
const ge = (s) => {
|
|
957
|
+
const t = A.fromChainOrSignature(s);
|
|
937
958
|
switch (s) {
|
|
938
959
|
case o.Bitcoin:
|
|
939
960
|
case o.Litecoin:
|
|
@@ -950,17 +971,17 @@ const fe = (s) => {
|
|
|
950
971
|
default:
|
|
951
972
|
return t.set(1e-8);
|
|
952
973
|
}
|
|
953
|
-
},
|
|
954
|
-
const t = s.slice(0, 14).includes("/"), [e, r] = s.split(".").pop().split("/"), n = s.includes(".") && !t ? s : `${o.THORChain}.${r}`, [i,
|
|
974
|
+
}, z = (s) => {
|
|
975
|
+
const t = s.slice(0, 14).includes("/"), [e, r] = s.split(".").pop().split("/"), n = s.includes(".") && !t ? s : `${o.THORChain}.${r}`, [i, a] = n.split("."), [c, u] = (t ? r : a).split("-");
|
|
955
976
|
return {
|
|
956
977
|
address: u == null ? void 0 : u.toLowerCase(),
|
|
957
978
|
chain: i,
|
|
958
|
-
isGasAsset:
|
|
979
|
+
isGasAsset: ot({ chain: i, symbol: a }),
|
|
959
980
|
isSynthetic: t,
|
|
960
|
-
symbol: (t ? `${e}/` : "") + (u ? `${
|
|
961
|
-
ticker:
|
|
981
|
+
symbol: (t ? `${e}/` : "") + (u ? `${c}-${(u == null ? void 0 : u.toLowerCase()) ?? ""}` : a),
|
|
982
|
+
ticker: c
|
|
962
983
|
};
|
|
963
|
-
},
|
|
984
|
+
}, re = {
|
|
964
985
|
/**
|
|
965
986
|
* Core
|
|
966
987
|
*/
|
|
@@ -1017,47 +1038,47 @@ const fe = (s) => {
|
|
|
1017
1038
|
*/
|
|
1018
1039
|
helpers_number_different_decimals: 99101
|
|
1019
1040
|
};
|
|
1020
|
-
class
|
|
1041
|
+
class mt extends Error {
|
|
1021
1042
|
constructor(t, e) {
|
|
1022
|
-
console.error(e), super(t, { cause: { code:
|
|
1043
|
+
console.error(e), super(t, { cause: { code: re[t], message: t } }), Object.setPrototypeOf(this, mt.prototype);
|
|
1023
1044
|
}
|
|
1024
1045
|
}
|
|
1025
|
-
class b extends
|
|
1046
|
+
class b extends E {
|
|
1026
1047
|
eq(t) {
|
|
1027
1048
|
return this.eqValue(t);
|
|
1028
1049
|
}
|
|
1029
1050
|
static fromBigInt(t, e) {
|
|
1030
1051
|
return new b({
|
|
1031
1052
|
decimal: e,
|
|
1032
|
-
value:
|
|
1053
|
+
value: P({ value: t, bigIntDecimal: e, decimal: e })
|
|
1033
1054
|
});
|
|
1034
1055
|
}
|
|
1035
1056
|
}
|
|
1036
1057
|
export {
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1058
|
+
A as AssetValue,
|
|
1059
|
+
E as BigIntArithmetics,
|
|
1060
|
+
Zt as RequestClient,
|
|
1061
|
+
mt as SwapKitError,
|
|
1041
1062
|
b as SwapKitNumber,
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
+
oe as assetFromString,
|
|
1064
|
+
_e as derivationPathToString,
|
|
1065
|
+
ae as filterAssets,
|
|
1066
|
+
P as formatBigIntToSafeValue,
|
|
1067
|
+
ie as gasFeeMultiplier,
|
|
1068
|
+
Et as getAssetType,
|
|
1069
|
+
xt as getAsymmetricAssetShare,
|
|
1070
|
+
ue as getAsymmetricAssetWithdrawAmount,
|
|
1071
|
+
Bt as getAsymmetricRuneShare,
|
|
1072
|
+
ce as getAsymmetricRuneWithdrawAmount,
|
|
1073
|
+
It as getCommonAssetInfo,
|
|
1074
|
+
Ct as getDecimal,
|
|
1075
|
+
de as getEstimatedPoolShare,
|
|
1076
|
+
he as getLiquiditySlippage,
|
|
1077
|
+
me as getMemoFor,
|
|
1078
|
+
ge as getMinAmountByChain,
|
|
1079
|
+
qt as getSymmetricPoolShare,
|
|
1080
|
+
le as getSymmetricWithdraw,
|
|
1081
|
+
pe as getTHORNameCost,
|
|
1082
|
+
ot as isGasAsset,
|
|
1083
|
+
fe as validateTHORName
|
|
1063
1084
|
};
|