@swapkit/helpers 1.0.0-rc.54 → 1.0.0-rc.55
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 +2 -2
- package/dist/index.es.js +263 -251
- package/dist/index.es.js.map +1 -1
- package/package.json +5 -5
- package/src/modules/__tests__/assetValue.test.ts +13 -2
- package/src/modules/assetValue.ts +23 -6
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var f = (s, t, e) => (
|
|
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
|
};
|
|
@@ -9,11 +9,11 @@ var v = (s, t, e) => {
|
|
|
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 vt = "0x313ce567",
|
|
12
|
+
var m = (s, t, e) => (wt(s, t, "access private method"), e);
|
|
13
|
+
import { FeeOption as U, BaseDecimal as d, Chain as o, EVMChainList as At, ChainToRPC as $t, MemoType as _ } from "@swapkit/types";
|
|
14
|
+
const vt = "0x313ce567", nt = async ({ chain: s, to: t }) => {
|
|
15
15
|
try {
|
|
16
|
-
const { result: e } = await
|
|
16
|
+
const { result: e } = await Xt.post($t[s], {
|
|
17
17
|
headers: {
|
|
18
18
|
accept: "*/*",
|
|
19
19
|
"content-type": "application/json",
|
|
@@ -28,32 +28,32 @@ const vt = "0x313ce567", st = async ({ chain: s, to: t }) => {
|
|
|
28
28
|
});
|
|
29
29
|
return parseInt(BigInt(e).toString());
|
|
30
30
|
} catch (e) {
|
|
31
|
-
return console.error(e),
|
|
31
|
+
return console.error(e), d[s];
|
|
32
32
|
}
|
|
33
|
-
},
|
|
33
|
+
}, Tt = async (s) => {
|
|
34
34
|
if (s === o.Ethereum)
|
|
35
|
-
return
|
|
35
|
+
return d.ETH;
|
|
36
36
|
const [, t] = s.split("-");
|
|
37
|
-
return t != null && t.startsWith("0x") ?
|
|
38
|
-
},
|
|
37
|
+
return t != null && t.startsWith("0x") ? nt({ chain: o.Ethereum, to: t }) : d.ETH;
|
|
38
|
+
}, Ct = async (s) => {
|
|
39
39
|
const [, t] = s.split("-");
|
|
40
|
-
return t != null && t.startsWith("0x") ?
|
|
41
|
-
}, Rt = async (s) => s === o.BinanceSmartChain ?
|
|
40
|
+
return t != null && t.startsWith("0x") ? nt({ chain: o.Avalanche, to: t.toLowerCase() }) : d.AVAX;
|
|
41
|
+
}, Rt = async (s) => s === o.BinanceSmartChain ? d.BSC : d.BSC, St = async ({ chain: s, symbol: t }) => {
|
|
42
42
|
switch (s) {
|
|
43
43
|
case o.Ethereum:
|
|
44
|
-
return $t(t);
|
|
45
|
-
case o.Avalanche:
|
|
46
44
|
return Tt(t);
|
|
45
|
+
case o.Avalanche:
|
|
46
|
+
return Ct(t);
|
|
47
47
|
case o.BinanceSmartChain:
|
|
48
48
|
return Rt(t);
|
|
49
49
|
default:
|
|
50
|
-
return
|
|
50
|
+
return d[s];
|
|
51
51
|
}
|
|
52
|
-
},
|
|
53
|
-
[
|
|
54
|
-
[
|
|
55
|
-
[
|
|
56
|
-
},
|
|
52
|
+
}, ne = {
|
|
53
|
+
[U.Average]: 1.2,
|
|
54
|
+
[U.Fast]: 1.5,
|
|
55
|
+
[U.Fastest]: 2
|
|
56
|
+
}, it = ({ chain: s, symbol: t }) => {
|
|
57
57
|
switch (s) {
|
|
58
58
|
case o.Bitcoin:
|
|
59
59
|
case o.BitcoinCash:
|
|
@@ -79,20 +79,20 @@ const vt = "0x313ce567", st = 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 };
|
|
86
86
|
case "ETH.vTHOR":
|
|
87
87
|
return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
|
|
88
88
|
case o.Cosmos:
|
|
89
|
-
return { identifier: "GAIA.ATOM", decimal:
|
|
89
|
+
return { identifier: "GAIA.ATOM", decimal: d[s] };
|
|
90
90
|
case o.THORChain:
|
|
91
|
-
return { identifier: "THOR.RUNE", decimal:
|
|
91
|
+
return { identifier: "THOR.RUNE", decimal: d[s] };
|
|
92
92
|
case o.BinanceSmartChain:
|
|
93
|
-
return { identifier: "BSC.BNB", decimal:
|
|
93
|
+
return { identifier: "BSC.BNB", decimal: d[s] };
|
|
94
94
|
case o.Maya:
|
|
95
|
-
return { identifier: "MAYA.CACAO", decimal:
|
|
95
|
+
return { identifier: "MAYA.CACAO", decimal: d.MAYA };
|
|
96
96
|
case "MAYA.MAYA":
|
|
97
97
|
return { identifier: "MAYA.MAYA", decimal: 4 };
|
|
98
98
|
case o.Kujira:
|
|
@@ -106,9 +106,9 @@ const vt = "0x313ce567", st = async ({ chain: s, to: t }) => {
|
|
|
106
106
|
case o.Polygon:
|
|
107
107
|
case o.Bitcoin:
|
|
108
108
|
case o.Ethereum:
|
|
109
|
-
return { identifier: `${s}.${s}`, decimal:
|
|
109
|
+
return { identifier: `${s}.${s}`, decimal: d[s] };
|
|
110
110
|
}
|
|
111
|
-
},
|
|
111
|
+
}, Ot = ({ chain: s, symbol: t }) => {
|
|
112
112
|
if (t.includes("/"))
|
|
113
113
|
return "Synth";
|
|
114
114
|
switch (s) {
|
|
@@ -138,59 +138,59 @@ const vt = "0x313ce567", st = async ({ chain: s, to: t }) => {
|
|
|
138
138
|
case o.Optimism:
|
|
139
139
|
return [o.Ethereum, o.Optimism].includes(t) ? "Native" : "OPTIMISM";
|
|
140
140
|
}
|
|
141
|
-
},
|
|
141
|
+
}, ie = (s) => {
|
|
142
142
|
var c;
|
|
143
143
|
const [t, ...e] = s.split("."), r = s.includes("/"), n = e.join("."), i = (c = n == null ? void 0 : n.split("-")) == null ? void 0 : c[0];
|
|
144
144
|
return { chain: t, symbol: n, ticker: i, synth: r };
|
|
145
|
-
},
|
|
145
|
+
}, Et = new RegExp(
|
|
146
146
|
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
|
|
147
147
|
"gmi"
|
|
148
|
-
),
|
|
148
|
+
), Bt = (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 it({ chain: t, symbol: e }) || !!r;
|
|
154
|
+
}, oe = (s) => s.filter((t) => {
|
|
155
155
|
const e = `${t.chain}.${t.symbol}`;
|
|
156
|
-
return !
|
|
156
|
+
return !Et.test(e) && Bt(e) && t.value !== "0";
|
|
157
157
|
});
|
|
158
|
-
function
|
|
158
|
+
function Mt({
|
|
159
159
|
liquidityUnits: s,
|
|
160
160
|
poolUnits: t,
|
|
161
161
|
runeDepth: e
|
|
162
162
|
}) {
|
|
163
|
-
const r = p(s), n = p(t), i = p(e), c = r.mul(i), a = n.mul(n).mul(2), u = n.mul(r).mul(2),
|
|
164
|
-
return c.mul(a.sub(u).add(
|
|
163
|
+
const r = p(s), n = p(t), i = p(e), c = r.mul(i), a = n.mul(n).mul(2), u = n.mul(r).mul(2), l = r.mul(r), h = n.mul(n).mul(n);
|
|
164
|
+
return c.mul(a.sub(u).add(l)).div(h);
|
|
165
165
|
}
|
|
166
|
-
function
|
|
166
|
+
function xt({
|
|
167
167
|
liquidityUnits: s,
|
|
168
168
|
poolUnits: t,
|
|
169
169
|
assetDepth: e
|
|
170
170
|
}) {
|
|
171
|
-
const r = p(s), n = p(t), i = p(e), c = r.mul(i), a = n.mul(n).mul(2), u = n.mul(r).mul(2),
|
|
172
|
-
return
|
|
171
|
+
const r = p(s), n = p(t), i = p(e), c = r.mul(i), a = n.mul(n).mul(2), u = n.mul(r).mul(2), l = r.mul(r), h = c.mul(a.sub(u).add(l)), $ = n.mul(n).mul(n);
|
|
172
|
+
return h.div($);
|
|
173
173
|
}
|
|
174
|
-
function
|
|
174
|
+
function ae({
|
|
175
175
|
percent: s,
|
|
176
176
|
runeDepth: t,
|
|
177
177
|
liquidityUnits: e,
|
|
178
178
|
poolUnits: r
|
|
179
179
|
}) {
|
|
180
|
-
return
|
|
180
|
+
return Mt({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(s);
|
|
181
181
|
}
|
|
182
|
-
function
|
|
182
|
+
function ce({
|
|
183
183
|
percent: s,
|
|
184
184
|
assetDepth: t,
|
|
185
185
|
liquidityUnits: e,
|
|
186
186
|
poolUnits: r
|
|
187
187
|
}) {
|
|
188
|
-
return
|
|
188
|
+
return xt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(s);
|
|
189
189
|
}
|
|
190
190
|
function p(s) {
|
|
191
|
-
return g.fromBigInt(BigInt(s),
|
|
191
|
+
return g.fromBigInt(BigInt(s), d.THOR);
|
|
192
192
|
}
|
|
193
|
-
function
|
|
193
|
+
function qt({
|
|
194
194
|
liquidityUnits: s,
|
|
195
195
|
poolUnits: t,
|
|
196
196
|
runeDepth: e,
|
|
@@ -201,7 +201,7 @@ function xt({
|
|
|
201
201
|
runeAmount: p(e).mul(s).div(t)
|
|
202
202
|
};
|
|
203
203
|
}
|
|
204
|
-
function
|
|
204
|
+
function ue({
|
|
205
205
|
liquidityUnits: s,
|
|
206
206
|
poolUnits: t,
|
|
207
207
|
runeDepth: e,
|
|
@@ -209,12 +209,12 @@ function ce({
|
|
|
209
209
|
percent: n
|
|
210
210
|
}) {
|
|
211
211
|
return Object.fromEntries(
|
|
212
|
-
Object.entries(
|
|
212
|
+
Object.entries(qt({ liquidityUnits: s, poolUnits: t, runeDepth: e, assetDepth: r })).map(
|
|
213
213
|
([i, c]) => [i, c.mul(n)]
|
|
214
214
|
)
|
|
215
215
|
);
|
|
216
216
|
}
|
|
217
|
-
function
|
|
217
|
+
function le({
|
|
218
218
|
runeDepth: s,
|
|
219
219
|
poolUnits: t,
|
|
220
220
|
assetDepth: e,
|
|
@@ -222,13 +222,13 @@ function ue({
|
|
|
222
222
|
runeAmount: n,
|
|
223
223
|
assetAmount: i
|
|
224
224
|
}) {
|
|
225
|
-
const c = new g({ value: s, decimal: 8 }), a = new g({ value: e, decimal: 8 }), u = new g({ value: t, decimal: 8 }),
|
|
225
|
+
const c = new g({ value: s, decimal: 8 }), a = new g({ value: e, decimal: 8 }), u = new g({ value: t, decimal: 8 }), l = new g({ value: n, decimal: 8 }), h = new g({ value: i, decimal: 8 }), $ = l.mul(a), H = h.mul(c), mt = l.mul(h), pt = c.mul(a), ft = u.mul($.add(H.add(mt.mul(2)))), _t = $.add(H.add(pt.mul(2))), Q = ft.div(_t), D = p(r).add(Q);
|
|
226
226
|
if (Q.getBaseValue("number") === 0)
|
|
227
|
-
return
|
|
228
|
-
const
|
|
229
|
-
return
|
|
227
|
+
return D.div(u).getBaseValue("number");
|
|
228
|
+
const gt = u.add(D);
|
|
229
|
+
return D.div(gt).getBaseValue("number");
|
|
230
230
|
}
|
|
231
|
-
function
|
|
231
|
+
function he({
|
|
232
232
|
runeAmount: s,
|
|
233
233
|
assetAmount: t,
|
|
234
234
|
runeDepth: e,
|
|
@@ -236,10 +236,10 @@ function le({
|
|
|
236
236
|
}) {
|
|
237
237
|
if (s === "0" || t === "0" || e === "0" || r === "0")
|
|
238
238
|
return 0;
|
|
239
|
-
const n = p(e), i = p(r), c = p(t), a = p(s), u = c.mul(n).sub(i.mul(a)),
|
|
240
|
-
return Math.abs(u.div(
|
|
239
|
+
const n = p(e), i = p(r), c = p(t), a = p(s), u = c.mul(n).sub(i.mul(a)), l = i.mul(a).add(n.mul(i));
|
|
240
|
+
return Math.abs(u.div(l).getBaseValue("number"));
|
|
241
241
|
}
|
|
242
|
-
const
|
|
242
|
+
const de = (s, t) => {
|
|
243
243
|
switch (s) {
|
|
244
244
|
case _.LEAVE:
|
|
245
245
|
case _.BOND: {
|
|
@@ -270,8 +270,8 @@ const he = (s, t) => {
|
|
|
270
270
|
})(e, r)}:${n || ""}:t:0`;
|
|
271
271
|
}
|
|
272
272
|
case _.WITHDRAW: {
|
|
273
|
-
const { chain: e, ticker: r, symbol: n, basisPoints: i, targetAssetString: c, singleSide: a } = t, u = e === "ETH" && r !== "ETH" ? `${r}-${n.slice(-3)}` : n,
|
|
274
|
-
return `${s}:${e}${a ? "/" : "."}${u}:${i}${
|
|
273
|
+
const { chain: e, ticker: r, symbol: n, basisPoints: i, targetAssetString: c, singleSide: a } = t, u = e === "ETH" && r !== "ETH" ? `${r}-${n.slice(-3)}` : n, l = !a && c ? `:${c}` : "";
|
|
274
|
+
return `${s}:${e}${a ? "/" : "."}${u}:${i}${l}`;
|
|
275
275
|
}
|
|
276
276
|
case _.OPEN_LOAN:
|
|
277
277
|
case _.CLOSE_LOAN: {
|
|
@@ -282,18 +282,18 @@ const he = (s, t) => {
|
|
|
282
282
|
return "";
|
|
283
283
|
}
|
|
284
284
|
};
|
|
285
|
-
function
|
|
285
|
+
function me(s) {
|
|
286
286
|
if (s < 0)
|
|
287
287
|
throw new Error("Invalid number of year");
|
|
288
288
|
return 10 + s;
|
|
289
289
|
}
|
|
290
|
-
function
|
|
290
|
+
function pe(s) {
|
|
291
291
|
if (s.length > 30)
|
|
292
292
|
return !1;
|
|
293
293
|
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
294
294
|
return !!s.match(t);
|
|
295
295
|
}
|
|
296
|
-
function
|
|
296
|
+
function fe([s, t, e, r, n]) {
|
|
297
297
|
return `${s}'/${t}'/${e}'/${r}${typeof n != "number" ? "" : `/${n}`}`;
|
|
298
298
|
}
|
|
299
299
|
class X extends Error {
|
|
@@ -317,7 +317,7 @@ class X extends Error {
|
|
|
317
317
|
}), this.name = "HTTPError", this.response = t, this.request = e, this.options = r;
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
|
-
class
|
|
320
|
+
class ot extends Error {
|
|
321
321
|
constructor(t) {
|
|
322
322
|
super("Request timed out"), Object.defineProperty(this, "request", {
|
|
323
323
|
enumerable: !0,
|
|
@@ -327,12 +327,12 @@ class it extends Error {
|
|
|
327
327
|
}), this.name = "TimeoutError", this.request = t;
|
|
328
328
|
}
|
|
329
329
|
}
|
|
330
|
-
const
|
|
330
|
+
const q = (s) => s !== null && typeof s == "object", M = (...s) => {
|
|
331
331
|
for (const t of s)
|
|
332
|
-
if ((!
|
|
332
|
+
if ((!q(t) || Array.isArray(t)) && t !== void 0)
|
|
333
333
|
throw new TypeError("The `options` argument must be an object");
|
|
334
334
|
return J({}, ...s);
|
|
335
|
-
},
|
|
335
|
+
}, at = (s = {}, t = {}) => {
|
|
336
336
|
const e = new globalThis.Headers(s), r = t instanceof globalThis.Headers, n = new globalThis.Headers(t);
|
|
337
337
|
for (const [i, c] of n.entries())
|
|
338
338
|
r && c === "undefined" || c === void 0 ? e.delete(i) : e.set(i, c);
|
|
@@ -342,13 +342,13 @@ const x = (s) => s !== null && typeof s == "object", B = (...s) => {
|
|
|
342
342
|
for (const r of s)
|
|
343
343
|
if (Array.isArray(r))
|
|
344
344
|
Array.isArray(t) || (t = []), t = [...t, ...r];
|
|
345
|
-
else if (
|
|
345
|
+
else if (q(r)) {
|
|
346
346
|
for (let [n, i] of Object.entries(r))
|
|
347
|
-
|
|
348
|
-
|
|
347
|
+
q(i) && n in t && (i = J(t[n], i)), t = { ...t, [n]: i };
|
|
348
|
+
q(r.headers) && (e = at(e, r.headers), t.headers = e);
|
|
349
349
|
}
|
|
350
350
|
return t;
|
|
351
|
-
},
|
|
351
|
+
}, Vt = (() => {
|
|
352
352
|
let s = !1, t = !1;
|
|
353
353
|
const e = typeof globalThis.ReadableStream == "function", r = typeof globalThis.Request == "function";
|
|
354
354
|
return e && r && (t = new globalThis.Request("https://empty.invalid", {
|
|
@@ -359,13 +359,13 @@ const x = (s) => s !== null && typeof s == "object", B = (...s) => {
|
|
|
359
359
|
return s = !0, "half";
|
|
360
360
|
}
|
|
361
361
|
}).headers.has("Content-Type")), s && !t;
|
|
362
|
-
})(), Pt = typeof globalThis.AbortController == "function",
|
|
362
|
+
})(), Pt = typeof globalThis.AbortController == "function", kt = typeof globalThis.ReadableStream == "function", Nt = typeof globalThis.FormData == "function", ct = ["get", "post", "put", "patch", "head", "delete"], jt = {
|
|
363
363
|
json: "application/json",
|
|
364
364
|
text: "text/*",
|
|
365
365
|
formData: "multipart/form-data",
|
|
366
366
|
arrayBuffer: "*/*",
|
|
367
367
|
blob: "*/*"
|
|
368
|
-
},
|
|
368
|
+
}, L = 2147483647, ut = Symbol("stop"), Ht = {
|
|
369
369
|
json: !0,
|
|
370
370
|
parseJson: !0,
|
|
371
371
|
searchParams: !0,
|
|
@@ -376,7 +376,7 @@ const x = (s) => s !== null && typeof s == "object", B = (...s) => {
|
|
|
376
376
|
throwHttpErrors: !0,
|
|
377
377
|
onDownloadProgress: !0,
|
|
378
378
|
fetch: !0
|
|
379
|
-
},
|
|
379
|
+
}, Dt = {
|
|
380
380
|
method: !0,
|
|
381
381
|
headers: !0,
|
|
382
382
|
body: !0,
|
|
@@ -392,15 +392,15 @@ const x = (s) => s !== null && typeof s == "object", B = (...s) => {
|
|
|
392
392
|
window: !0,
|
|
393
393
|
dispatcher: !0,
|
|
394
394
|
duplex: !0
|
|
395
|
-
},
|
|
395
|
+
}, Ut = (s) => ct.includes(s) ? s.toUpperCase() : s, Lt = ["get", "put", "head", "delete", "options", "trace"], Ft = [408, 413, 429, 500, 502, 503, 504], lt = [413, 429, 503], Z = {
|
|
396
396
|
limit: 2,
|
|
397
|
-
methods:
|
|
398
|
-
statusCodes:
|
|
399
|
-
afterStatusCodes:
|
|
397
|
+
methods: Lt,
|
|
398
|
+
statusCodes: Ft,
|
|
399
|
+
afterStatusCodes: lt,
|
|
400
400
|
maxRetryAfter: Number.POSITIVE_INFINITY,
|
|
401
401
|
backoffLimit: Number.POSITIVE_INFINITY,
|
|
402
402
|
delay: (s) => 0.3 * 2 ** (s - 1) * 1e3
|
|
403
|
-
},
|
|
403
|
+
}, Wt = (s = {}) => {
|
|
404
404
|
if (typeof s == "number")
|
|
405
405
|
return {
|
|
406
406
|
...Z,
|
|
@@ -413,20 +413,20 @@ const x = (s) => s !== null && typeof s == "object", B = (...s) => {
|
|
|
413
413
|
return {
|
|
414
414
|
...Z,
|
|
415
415
|
...s,
|
|
416
|
-
afterStatusCodes:
|
|
416
|
+
afterStatusCodes: lt
|
|
417
417
|
};
|
|
418
418
|
};
|
|
419
|
-
async function
|
|
419
|
+
async function Gt(s, t, e, r) {
|
|
420
420
|
return new Promise((n, i) => {
|
|
421
421
|
const c = setTimeout(() => {
|
|
422
|
-
e && e.abort(), i(new
|
|
422
|
+
e && e.abort(), i(new ot(s));
|
|
423
423
|
}, r.timeout);
|
|
424
424
|
r.fetch(s, t).then(n).catch(i).then(() => {
|
|
425
425
|
clearTimeout(c);
|
|
426
426
|
});
|
|
427
427
|
});
|
|
428
428
|
}
|
|
429
|
-
async function
|
|
429
|
+
async function Yt(s, { signal: t }) {
|
|
430
430
|
return new Promise((e, r) => {
|
|
431
431
|
t && (t.throwIfAborted(), t.addEventListener("abort", n, { once: !0 }));
|
|
432
432
|
function n() {
|
|
@@ -437,49 +437,49 @@ async function Gt(s, { signal: t }) {
|
|
|
437
437
|
}, s);
|
|
438
438
|
});
|
|
439
439
|
}
|
|
440
|
-
const
|
|
440
|
+
const zt = (s, t) => {
|
|
441
441
|
const e = {};
|
|
442
442
|
for (const r in t)
|
|
443
|
-
!(r in
|
|
443
|
+
!(r in Dt) && !(r in Ht) && !(r in s) && (e[r] = t[r]);
|
|
444
444
|
return e;
|
|
445
445
|
};
|
|
446
446
|
class P {
|
|
447
447
|
static create(t, e) {
|
|
448
448
|
const r = new P(t, e), n = async () => {
|
|
449
|
-
if (typeof r._options.timeout == "number" && r._options.timeout >
|
|
450
|
-
throw new RangeError(`The \`timeout\` option cannot be greater than ${
|
|
449
|
+
if (typeof r._options.timeout == "number" && r._options.timeout > L)
|
|
450
|
+
throw new RangeError(`The \`timeout\` option cannot be greater than ${L}`);
|
|
451
451
|
await Promise.resolve();
|
|
452
452
|
let a = await r._fetch();
|
|
453
453
|
for (const u of r._options.hooks.afterResponse) {
|
|
454
|
-
const
|
|
455
|
-
|
|
454
|
+
const l = await u(r.request, r._options, r._decorateResponse(a.clone()));
|
|
455
|
+
l instanceof globalThis.Response && (a = l);
|
|
456
456
|
}
|
|
457
457
|
if (r._decorateResponse(a), !a.ok && r._options.throwHttpErrors) {
|
|
458
458
|
let u = new X(a, r.request, r._options);
|
|
459
|
-
for (const
|
|
460
|
-
u = await
|
|
459
|
+
for (const l of r._options.hooks.beforeError)
|
|
460
|
+
u = await l(u);
|
|
461
461
|
throw u;
|
|
462
462
|
}
|
|
463
463
|
if (r._options.onDownloadProgress) {
|
|
464
464
|
if (typeof r._options.onDownloadProgress != "function")
|
|
465
465
|
throw new TypeError("The `onDownloadProgress` option must be a function");
|
|
466
|
-
if (!
|
|
466
|
+
if (!kt)
|
|
467
467
|
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
|
|
468
468
|
return r._stream(a.clone(), r._options.onDownloadProgress);
|
|
469
469
|
}
|
|
470
470
|
return a;
|
|
471
471
|
}, c = r._options.retry.methods.includes(r.request.method.toLowerCase()) ? r._retry(n) : n();
|
|
472
|
-
for (const [a, u] of Object.entries(
|
|
472
|
+
for (const [a, u] of Object.entries(jt))
|
|
473
473
|
c[a] = async () => {
|
|
474
474
|
r.request.headers.set("accept", r.request.headers.get("accept") || u);
|
|
475
|
-
const
|
|
475
|
+
const h = (await c).clone();
|
|
476
476
|
if (a === "json") {
|
|
477
|
-
if (
|
|
477
|
+
if (h.status === 204 || (await h.clone().arrayBuffer()).byteLength === 0)
|
|
478
478
|
return "";
|
|
479
479
|
if (e.parseJson)
|
|
480
|
-
return e.parseJson(await
|
|
480
|
+
return e.parseJson(await h.text());
|
|
481
481
|
}
|
|
482
|
-
return
|
|
482
|
+
return h[a]();
|
|
483
483
|
};
|
|
484
484
|
return c;
|
|
485
485
|
}
|
|
@@ -514,17 +514,17 @@ class P {
|
|
|
514
514
|
// TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208
|
|
515
515
|
credentials: this._input.credentials || "same-origin",
|
|
516
516
|
...e,
|
|
517
|
-
headers:
|
|
517
|
+
headers: at(this._input.headers, e.headers),
|
|
518
518
|
hooks: J({
|
|
519
519
|
beforeRequest: [],
|
|
520
520
|
beforeRetry: [],
|
|
521
521
|
beforeError: [],
|
|
522
522
|
afterResponse: []
|
|
523
523
|
}, e.hooks),
|
|
524
|
-
method:
|
|
524
|
+
method: Ut(e.method ?? this._input.method),
|
|
525
525
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
526
526
|
prefixUrl: String(e.prefixUrl || ""),
|
|
527
|
-
retry:
|
|
527
|
+
retry: Wt(e.retry),
|
|
528
528
|
throwHttpErrors: e.throwHttpErrors !== !1,
|
|
529
529
|
timeout: e.timeout ?? 1e4,
|
|
530
530
|
fetch: e.fetch ?? globalThis.fetch.bind(globalThis)
|
|
@@ -544,14 +544,14 @@ class P {
|
|
|
544
544
|
}
|
|
545
545
|
this._options.signal = this.abortController.signal;
|
|
546
546
|
}
|
|
547
|
-
if (
|
|
547
|
+
if (Vt && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
|
|
548
548
|
const n = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), i = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, n);
|
|
549
|
-
(
|
|
549
|
+
(Nt && 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);
|
|
550
550
|
}
|
|
551
551
|
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 }));
|
|
552
552
|
}
|
|
553
553
|
_calculateRetryDelay(t) {
|
|
554
|
-
if (this._retryCount++, this._retryCount < this._options.retry.limit && !(t instanceof
|
|
554
|
+
if (this._retryCount++, this._retryCount < this._options.retry.limit && !(t instanceof ot)) {
|
|
555
555
|
if (t instanceof X) {
|
|
556
556
|
if (!this._options.retry.statusCodes.includes(t.response.status))
|
|
557
557
|
return 0;
|
|
@@ -575,16 +575,16 @@ class P {
|
|
|
575
575
|
try {
|
|
576
576
|
return await t();
|
|
577
577
|
} catch (e) {
|
|
578
|
-
const r = Math.min(this._calculateRetryDelay(e),
|
|
578
|
+
const r = Math.min(this._calculateRetryDelay(e), L);
|
|
579
579
|
if (r !== 0 && this._retryCount > 0) {
|
|
580
|
-
await
|
|
580
|
+
await Yt(r, { signal: this._options.signal });
|
|
581
581
|
for (const n of this._options.hooks.beforeRetry)
|
|
582
582
|
if (await n({
|
|
583
583
|
request: this.request,
|
|
584
584
|
options: this._options,
|
|
585
585
|
error: e,
|
|
586
586
|
retryCount: this._retryCount
|
|
587
|
-
}) ===
|
|
587
|
+
}) === ut)
|
|
588
588
|
return;
|
|
589
589
|
return this._retry(t);
|
|
590
590
|
}
|
|
@@ -601,8 +601,8 @@ class P {
|
|
|
601
601
|
if (r instanceof Response)
|
|
602
602
|
return r;
|
|
603
603
|
}
|
|
604
|
-
const t =
|
|
605
|
-
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) :
|
|
604
|
+
const t = zt(this.request, this._options);
|
|
605
|
+
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Gt(this.request.clone(), t, this.abortController, this._options);
|
|
606
606
|
}
|
|
607
607
|
/* istanbul ignore next */
|
|
608
608
|
_stream(t, e) {
|
|
@@ -617,17 +617,17 @@ class P {
|
|
|
617
617
|
const c = t.body.getReader();
|
|
618
618
|
e && e({ percent: 0, transferredBytes: 0, totalBytes: r }, new Uint8Array());
|
|
619
619
|
async function a() {
|
|
620
|
-
const { done: u, value:
|
|
620
|
+
const { done: u, value: l } = await c.read();
|
|
621
621
|
if (u) {
|
|
622
622
|
i.close();
|
|
623
623
|
return;
|
|
624
624
|
}
|
|
625
625
|
if (e) {
|
|
626
|
-
n +=
|
|
627
|
-
const
|
|
628
|
-
e({ percent:
|
|
626
|
+
n += l.byteLength;
|
|
627
|
+
const h = r === 0 ? 0 : n / r;
|
|
628
|
+
e({ percent: h, transferredBytes: n, totalBytes: r }, l);
|
|
629
629
|
}
|
|
630
|
-
i.enqueue(
|
|
630
|
+
i.enqueue(l), await a();
|
|
631
631
|
}
|
|
632
632
|
await a();
|
|
633
633
|
}
|
|
@@ -639,16 +639,16 @@ class P {
|
|
|
639
639
|
}
|
|
640
640
|
}
|
|
641
641
|
/*! MIT License © Sindre Sorhus */
|
|
642
|
-
const
|
|
643
|
-
const t = (e, r) => P.create(e,
|
|
644
|
-
for (const e of
|
|
645
|
-
t[e] = (r, n) => P.create(r,
|
|
646
|
-
return t.create = (e) =>
|
|
647
|
-
},
|
|
642
|
+
const W = (s) => {
|
|
643
|
+
const t = (e, r) => P.create(e, M(s, r));
|
|
644
|
+
for (const e of ct)
|
|
645
|
+
t[e] = (r, n) => P.create(r, M(s, n, { method: e }));
|
|
646
|
+
return t.create = (e) => W(M(e)), t.extend = (e) => W(M(s, e)), t.stop = ut, t;
|
|
647
|
+
}, Jt = W(), Kt = Jt, Qt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, tt = Kt.create({ headers: Qt }), Xt = {
|
|
648
648
|
get: (s, t) => tt.get(s, t).json(),
|
|
649
649
|
post: (s, t) => tt.post(s, t).json()
|
|
650
650
|
}, et = [...Object.values(o), "TERRA"];
|
|
651
|
-
function
|
|
651
|
+
function Zt(s = "") {
|
|
652
652
|
const t = s.toUpperCase(), [e] = t.split(".");
|
|
653
653
|
if (et.includes(e))
|
|
654
654
|
return !0;
|
|
@@ -659,11 +659,11 @@ function Xt(s = "") {
|
|
|
659
659
|
`Invalid identifier: ${s}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
660
660
|
);
|
|
661
661
|
}
|
|
662
|
-
const
|
|
663
|
-
function
|
|
662
|
+
const O = 8, y = (s) => 10n ** BigInt(s), C = (s) => Math.log10(parseFloat(s.toString()));
|
|
663
|
+
function k({
|
|
664
664
|
value: s,
|
|
665
|
-
bigIntDecimal: t =
|
|
666
|
-
decimal: e =
|
|
665
|
+
bigIntDecimal: t = O,
|
|
666
|
+
decimal: e = O
|
|
667
667
|
}) {
|
|
668
668
|
if (e === 0)
|
|
669
669
|
return s.toString();
|
|
@@ -678,24 +678,24 @@ function V({
|
|
|
678
678
|
""
|
|
679
679
|
);
|
|
680
680
|
}
|
|
681
|
-
var w,
|
|
681
|
+
var w, R, b, T, j, ht, E, G, B, Y;
|
|
682
682
|
const K = class K {
|
|
683
683
|
constructor(t) {
|
|
684
684
|
v(this, w);
|
|
685
685
|
v(this, b);
|
|
686
|
-
v(this,
|
|
687
|
-
v(this, O);
|
|
686
|
+
v(this, j);
|
|
688
687
|
v(this, E);
|
|
688
|
+
v(this, B);
|
|
689
689
|
f(this, "decimalMultiplier", 10n ** 8n);
|
|
690
690
|
f(this, "bigIntValue", 0n);
|
|
691
691
|
f(this, "decimal");
|
|
692
|
-
const e =
|
|
693
|
-
this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier : y(Math.max(rt(
|
|
692
|
+
const e = z(t), r = typeof t == "object";
|
|
693
|
+
this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier : y(Math.max(rt(x(e)), this.decimal || 0)), m(this, j, ht).call(this, e);
|
|
694
694
|
}
|
|
695
695
|
static fromBigInt(t, e) {
|
|
696
696
|
return new K({
|
|
697
697
|
decimal: e,
|
|
698
|
-
value:
|
|
698
|
+
value: k({ value: t, bigIntDecimal: e, decimal: e })
|
|
699
699
|
});
|
|
700
700
|
}
|
|
701
701
|
static shiftDecimals({
|
|
@@ -712,37 +712,37 @@ const K = class K {
|
|
|
712
712
|
return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
|
|
713
713
|
}
|
|
714
714
|
add(...t) {
|
|
715
|
-
return
|
|
715
|
+
return m(this, w, R).call(this, "add", ...t);
|
|
716
716
|
}
|
|
717
717
|
sub(...t) {
|
|
718
|
-
return
|
|
718
|
+
return m(this, w, R).call(this, "sub", ...t);
|
|
719
719
|
}
|
|
720
720
|
mul(...t) {
|
|
721
|
-
return
|
|
721
|
+
return m(this, w, R).call(this, "mul", ...t);
|
|
722
722
|
}
|
|
723
723
|
div(...t) {
|
|
724
|
-
return
|
|
724
|
+
return m(this, w, R).call(this, "div", ...t);
|
|
725
725
|
}
|
|
726
726
|
gt(t) {
|
|
727
|
-
return
|
|
727
|
+
return m(this, b, T).call(this, "gt", t);
|
|
728
728
|
}
|
|
729
729
|
gte(t) {
|
|
730
|
-
return
|
|
730
|
+
return m(this, b, T).call(this, "gte", t);
|
|
731
731
|
}
|
|
732
732
|
lt(t) {
|
|
733
|
-
return
|
|
733
|
+
return m(this, b, T).call(this, "lt", t);
|
|
734
734
|
}
|
|
735
735
|
lte(t) {
|
|
736
|
-
return
|
|
736
|
+
return m(this, b, T).call(this, "lte", t);
|
|
737
737
|
}
|
|
738
738
|
eqValue(t) {
|
|
739
|
-
return
|
|
739
|
+
return m(this, b, T).call(this, "eqValue", t);
|
|
740
740
|
}
|
|
741
741
|
// @ts-expect-error False positive
|
|
742
742
|
getValue(t) {
|
|
743
743
|
const e = this.formatBigIntToSafeValue(
|
|
744
744
|
this.bigIntValue,
|
|
745
|
-
this.decimal ||
|
|
745
|
+
this.decimal || C(this.decimalMultiplier)
|
|
746
746
|
);
|
|
747
747
|
switch (t) {
|
|
748
748
|
case "number":
|
|
@@ -755,7 +755,7 @@ const K = class K {
|
|
|
755
755
|
}
|
|
756
756
|
// @ts-expect-error
|
|
757
757
|
getBaseValue(t) {
|
|
758
|
-
const e = this.decimalMultiplier / y(this.decimal ||
|
|
758
|
+
const e = this.decimalMultiplier / y(this.decimal || d.THOR), r = this.bigIntValue / e;
|
|
759
759
|
switch (t) {
|
|
760
760
|
case "number":
|
|
761
761
|
return Number(r);
|
|
@@ -768,8 +768,8 @@ const K = class K {
|
|
|
768
768
|
getBigIntValue(t, e) {
|
|
769
769
|
if (!e && typeof t == "object")
|
|
770
770
|
return t.bigIntValue;
|
|
771
|
-
const r =
|
|
772
|
-
return n === "0" || n === "undefined" ? 0n :
|
|
771
|
+
const r = z(t), n = x(r);
|
|
772
|
+
return n === "0" || n === "undefined" ? 0n : m(this, B, Y).call(this, n, e);
|
|
773
773
|
}
|
|
774
774
|
toSignificant(t = 6) {
|
|
775
775
|
const [e, r] = this.getValue("string").split("."), n = e || "", i = r || "";
|
|
@@ -811,36 +811,36 @@ const K = class K {
|
|
|
811
811
|
decimalSeparator: n = ".",
|
|
812
812
|
thousandSeparator: i = ","
|
|
813
813
|
} = {}) {
|
|
814
|
-
const c = this.getValue("number"), [a, u = ""] = c.toFixed(6).split("."),
|
|
815
|
-
return `${e === "start" ? t : ""}${
|
|
814
|
+
const c = this.getValue("number"), [a, u = ""] = c.toFixed(6).split("."), l = a.replace(/\B(?=(\d{3})+(?!\d))/g, i), h = !a && !u ? "0.00" : a === "0" ? `${parseFloat(`0.${u}`)}`.replace(".", n) : `${l}${parseInt(u) ? `${n}${u.slice(0, r)}` : ""}`;
|
|
815
|
+
return `${e === "start" ? t : ""}${h}${e === "end" ? t : ""}`;
|
|
816
816
|
}
|
|
817
817
|
formatBigIntToSafeValue(t, e) {
|
|
818
|
-
const r = e || this.decimal ||
|
|
818
|
+
const r = e || this.decimal || O, n = Math.max(
|
|
819
819
|
r,
|
|
820
|
-
|
|
821
|
-
), i = t < 0n, c = t.toString().substring(i ? 1 : 0), a = n - (c.length - 1), u = a > 0 ? "0".repeat(a) + c : c,
|
|
822
|
-
let
|
|
823
|
-
return parseInt(
|
|
820
|
+
C(this.decimalMultiplier)
|
|
821
|
+
), 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;
|
|
822
|
+
let h = u.slice(-n);
|
|
823
|
+
return parseInt(h[r]) >= 5 ? h = `${h.substring(0, r - 1)}${(parseInt(h[r - 1]) + 1).toString()}` : h = h.substring(0, r), `${i ? "-" : ""}${u.slice(
|
|
824
824
|
0,
|
|
825
|
-
|
|
826
|
-
)}.${
|
|
825
|
+
l
|
|
826
|
+
)}.${h}`.replace(/\.?0*$/, "");
|
|
827
827
|
}
|
|
828
828
|
};
|
|
829
|
-
w = new WeakSet(),
|
|
830
|
-
const r =
|
|
831
|
-
(u,
|
|
832
|
-
const
|
|
829
|
+
w = new WeakSet(), R = function(t, ...e) {
|
|
830
|
+
const r = m(this, E, G).call(this, this, ...e), n = Math.max(r, C(this.decimalMultiplier)), i = y(n), c = e.reduce(
|
|
831
|
+
(u, l) => {
|
|
832
|
+
const h = this.getBigIntValue(l, n);
|
|
833
833
|
switch (t) {
|
|
834
834
|
case "add":
|
|
835
|
-
return u +
|
|
835
|
+
return u + h;
|
|
836
836
|
case "sub":
|
|
837
|
-
return u -
|
|
837
|
+
return u - h;
|
|
838
838
|
case "mul":
|
|
839
|
-
return u *
|
|
839
|
+
return u * h / i;
|
|
840
840
|
case "div": {
|
|
841
|
-
if (
|
|
841
|
+
if (h === 0n)
|
|
842
842
|
throw new RangeError("Division by zero");
|
|
843
|
-
return u * i /
|
|
843
|
+
return u * i / h;
|
|
844
844
|
}
|
|
845
845
|
default:
|
|
846
846
|
return u;
|
|
@@ -848,7 +848,7 @@ w = new WeakSet(), C = function(t, ...e) {
|
|
|
848
848
|
},
|
|
849
849
|
//normalize is to precision multiplier base
|
|
850
850
|
this.bigIntValue * i / this.decimalMultiplier
|
|
851
|
-
), a =
|
|
851
|
+
), a = k({
|
|
852
852
|
bigIntDecimal: n,
|
|
853
853
|
decimal: n,
|
|
854
854
|
value: c
|
|
@@ -859,8 +859,8 @@ w = new WeakSet(), C = function(t, ...e) {
|
|
|
859
859
|
value: a,
|
|
860
860
|
identifier: this.toString()
|
|
861
861
|
});
|
|
862
|
-
}, b = new WeakSet(),
|
|
863
|
-
const r =
|
|
862
|
+
}, b = new WeakSet(), T = function(t, ...e) {
|
|
863
|
+
const r = m(this, E, G).call(this, this, ...e), n = this.getBigIntValue(e[0], r), i = this.getBigIntValue(this, r);
|
|
864
864
|
switch (t) {
|
|
865
865
|
case "gt":
|
|
866
866
|
return i > n;
|
|
@@ -873,35 +873,35 @@ w = new WeakSet(), C = function(t, ...e) {
|
|
|
873
873
|
case "eqValue":
|
|
874
874
|
return i === n;
|
|
875
875
|
}
|
|
876
|
-
},
|
|
877
|
-
const e =
|
|
878
|
-
this.bigIntValue =
|
|
879
|
-
},
|
|
880
|
-
const e = t.map((r) => typeof r == "object" ? r.decimal ||
|
|
881
|
-
return Math.max(...e,
|
|
882
|
-
},
|
|
883
|
-
const r = e ? y(e) : this.decimalMultiplier, n =
|
|
876
|
+
}, j = new WeakSet(), ht = function(t) {
|
|
877
|
+
const e = x(t) || "0";
|
|
878
|
+
this.bigIntValue = m(this, B, Y).call(this, e);
|
|
879
|
+
}, E = new WeakSet(), G = function(...t) {
|
|
880
|
+
const e = t.map((r) => typeof r == "object" ? r.decimal || C(r.decimalMultiplier) : rt(x(r))).filter(Boolean);
|
|
881
|
+
return Math.max(...e, O);
|
|
882
|
+
}, B = new WeakSet(), Y = function(t, e) {
|
|
883
|
+
const r = e ? y(e) : this.decimalMultiplier, n = C(r), [i = "", c = ""] = t.split(".");
|
|
884
884
|
return BigInt(`${i}${c.padEnd(n, "0")}`);
|
|
885
885
|
};
|
|
886
|
-
let
|
|
887
|
-
const
|
|
886
|
+
let N = K;
|
|
887
|
+
const te = Intl.NumberFormat("fullwide", {
|
|
888
888
|
useGrouping: !1,
|
|
889
889
|
maximumFractionDigits: 20
|
|
890
890
|
});
|
|
891
|
-
function
|
|
892
|
-
const e = `${typeof s == "number" ?
|
|
891
|
+
function x(s) {
|
|
892
|
+
const e = `${typeof s == "number" ? te.format(s) : z(s)}`.replaceAll(",", ".").split(".");
|
|
893
893
|
return e.length > 1 ? `${e.slice(0, -1).join("")}.${e.at(-1)}` : e[0];
|
|
894
894
|
}
|
|
895
895
|
function rt(s) {
|
|
896
896
|
var e;
|
|
897
897
|
const t = ((e = s.split(".")[1]) == null ? void 0 : e.length) || 0;
|
|
898
|
-
return Math.max(t,
|
|
898
|
+
return Math.max(t, O);
|
|
899
899
|
}
|
|
900
|
-
function
|
|
900
|
+
function z(s) {
|
|
901
901
|
return typeof s == "object" ? "getValue" in s ? s.getValue("string") : s.value : s;
|
|
902
902
|
}
|
|
903
903
|
const S = /* @__PURE__ */ new Map();
|
|
904
|
-
class
|
|
904
|
+
class A extends N {
|
|
905
905
|
constructor({
|
|
906
906
|
value: e,
|
|
907
907
|
decimal: r,
|
|
@@ -919,8 +919,8 @@ class T extends k {
|
|
|
919
919
|
f(this, "tax");
|
|
920
920
|
f(this, "ticker");
|
|
921
921
|
f(this, "type");
|
|
922
|
-
const u =
|
|
923
|
-
this.type =
|
|
922
|
+
const u = V(a || `${i}.${c}`);
|
|
923
|
+
this.type = Ot(u), this.tax = n, this.chain = u.chain, this.ticker = u.ticker, this.symbol = u.symbol, this.address = u.address, this.isSynthetic = u.isSynthetic, this.isGasAsset = u.isGasAsset;
|
|
924
924
|
}
|
|
925
925
|
toString() {
|
|
926
926
|
return this.isSynthetic ? this.symbol : `${this.chain}.${this.symbol}`;
|
|
@@ -939,44 +939,48 @@ class T extends k {
|
|
|
939
939
|
if (!n || !i)
|
|
940
940
|
throw new Error("Invalid asset url");
|
|
941
941
|
const a = n === o.THORChain && c ? `${n}.${i}/${c}` : e;
|
|
942
|
-
return
|
|
942
|
+
return F(a, r);
|
|
943
943
|
}
|
|
944
944
|
static fromString(e, r = 0) {
|
|
945
|
-
return
|
|
945
|
+
return F(e, r);
|
|
946
946
|
}
|
|
947
947
|
static fromIdentifier(e, r = 0) {
|
|
948
|
-
return
|
|
948
|
+
return F(e, r);
|
|
949
949
|
}
|
|
950
950
|
static fromStringSync(e, r = 0) {
|
|
951
|
-
const {
|
|
952
|
-
if (
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
)
|
|
956
|
-
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
951
|
+
const { chain: n, isSynthetic: i } = V(e), c = S.get(e.toUpperCase());
|
|
952
|
+
if (i)
|
|
953
|
+
return st(e, r);
|
|
954
|
+
c || console.error(
|
|
955
|
+
`Asset ${e} is not loaded. Use AssetValue.loadStaticAssets() to load it`
|
|
956
|
+
);
|
|
957
|
+
const { tax: a, decimal: u, identifier: l } = c || {
|
|
958
|
+
decimal: d[n],
|
|
959
|
+
identifier: e
|
|
960
|
+
};
|
|
961
|
+
return new A({
|
|
962
|
+
tax: a,
|
|
963
|
+
value: I(r, u),
|
|
964
|
+
identifier: i ? e : l,
|
|
965
|
+
decimal: i ? 8 : u
|
|
964
966
|
});
|
|
965
967
|
}
|
|
966
968
|
static fromIdentifierSync(e, r = 0) {
|
|
967
|
-
const n = S.get(e);
|
|
968
|
-
if (
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
)
|
|
972
|
-
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
|
|
969
|
+
const { chain: n, isSynthetic: i } = V(e), c = S.get(e);
|
|
970
|
+
if (i)
|
|
971
|
+
return st(e, r);
|
|
972
|
+
c || console.error(
|
|
973
|
+
`Asset ${e} is not loaded. - Loading with base Chain. Use AssetValue.loadStaticAssets() to load it`
|
|
974
|
+
);
|
|
975
|
+
const { tax: a, decimal: u, identifier: l } = c || {
|
|
976
|
+
decimal: d[n],
|
|
977
|
+
identifier: e
|
|
978
|
+
};
|
|
979
|
+
return new A({ tax: a, decimal: u, identifier: l, value: I(r, u) });
|
|
976
980
|
}
|
|
977
981
|
static fromChainOrSignature(e, r = 0) {
|
|
978
|
-
const { decimal: n, identifier: i } =
|
|
979
|
-
return new
|
|
982
|
+
const { decimal: n, identifier: i } = It(e);
|
|
983
|
+
return new A({ value: I(r, n), decimal: n, identifier: i });
|
|
980
984
|
}
|
|
981
985
|
static loadStaticAssets() {
|
|
982
986
|
return new Promise(
|
|
@@ -985,10 +989,10 @@ class T extends k {
|
|
|
985
989
|
const n = await import("@swapkit/tokens");
|
|
986
990
|
Object.values(n).forEach((i) => {
|
|
987
991
|
var c;
|
|
988
|
-
(c = i == null ? void 0 : i.tokens) == null || c.forEach(({ identifier: a, chain: u, ...
|
|
992
|
+
(c = i == null ? void 0 : i.tokens) == null || c.forEach(({ identifier: a, chain: u, ...l }) => {
|
|
989
993
|
S.set(a.toUpperCase(), {
|
|
990
994
|
identifier: a,
|
|
991
|
-
decimal: "decimals" in
|
|
995
|
+
decimal: "decimals" in l ? l.decimals : d[u]
|
|
992
996
|
});
|
|
993
997
|
});
|
|
994
998
|
}), e({ ok: !0 });
|
|
@@ -1003,8 +1007,8 @@ class T extends k {
|
|
|
1003
1007
|
);
|
|
1004
1008
|
}
|
|
1005
1009
|
}
|
|
1006
|
-
function
|
|
1007
|
-
const t =
|
|
1010
|
+
function _e(s) {
|
|
1011
|
+
const t = A.fromChainOrSignature(s);
|
|
1008
1012
|
switch (s) {
|
|
1009
1013
|
case o.Bitcoin:
|
|
1010
1014
|
case o.Litecoin:
|
|
@@ -1022,26 +1026,34 @@ function fe(s) {
|
|
|
1022
1026
|
return t.set(1e-8);
|
|
1023
1027
|
}
|
|
1024
1028
|
}
|
|
1025
|
-
async function
|
|
1026
|
-
|
|
1027
|
-
const e = S.get(s.toUpperCase()), r = (e == null ? void 0 : e.decimal) || await
|
|
1028
|
-
return e || S.set(s.toUpperCase(), { identifier: s, decimal: r }), new
|
|
1029
|
+
async function F(s, t = 0) {
|
|
1030
|
+
Zt(s);
|
|
1031
|
+
const e = S.get(s.toUpperCase()), r = (e == null ? void 0 : e.decimal) || await St(V(s));
|
|
1032
|
+
return e || S.set(s.toUpperCase(), { identifier: s, decimal: r }), new A({ decimal: r, value: I(t, r), identifier: s });
|
|
1029
1033
|
}
|
|
1030
|
-
function
|
|
1031
|
-
|
|
1034
|
+
function st(s, t = 0) {
|
|
1035
|
+
const [e, r] = s.split("/");
|
|
1036
|
+
return new A({
|
|
1037
|
+
decimal: 8,
|
|
1038
|
+
value: I(t, 8),
|
|
1039
|
+
identifier: `${o.THORChain}.${e}/${r}`
|
|
1040
|
+
});
|
|
1032
1041
|
}
|
|
1033
|
-
function
|
|
1042
|
+
function I(s, t) {
|
|
1043
|
+
return typeof s == "bigint" ? k({ value: s, bigIntDecimal: t, decimal: t }) : s;
|
|
1044
|
+
}
|
|
1045
|
+
function V(s) {
|
|
1034
1046
|
const t = s.slice(0, 14).includes("/"), [e, r] = s.split(".").pop().split("/"), n = s.includes(".") && !t ? s : `${o.THORChain}.${r}`, [i, c] = n.split("."), [a, u] = (t ? r : c).split("-");
|
|
1035
1047
|
return {
|
|
1036
1048
|
address: u == null ? void 0 : u.toLowerCase(),
|
|
1037
1049
|
chain: i,
|
|
1038
|
-
isGasAsset:
|
|
1050
|
+
isGasAsset: it({ chain: i, symbol: c }),
|
|
1039
1051
|
isSynthetic: t,
|
|
1040
1052
|
symbol: (t ? `${e}/` : "") + (u ? `${a}-${(u == null ? void 0 : u.toLowerCase()) ?? ""}` : c),
|
|
1041
1053
|
ticker: a
|
|
1042
1054
|
};
|
|
1043
1055
|
}
|
|
1044
|
-
const
|
|
1056
|
+
const ee = {
|
|
1045
1057
|
/**
|
|
1046
1058
|
* Core
|
|
1047
1059
|
*/
|
|
@@ -1099,48 +1111,48 @@ const te = {
|
|
|
1099
1111
|
*/
|
|
1100
1112
|
helpers_number_different_decimals: 99101
|
|
1101
1113
|
};
|
|
1102
|
-
class
|
|
1114
|
+
class dt extends Error {
|
|
1103
1115
|
constructor(t, e) {
|
|
1104
|
-
console.error(e, { stack: e == null ? void 0 : e.stack, message: e == null ? void 0 : e.message }), super(t, { cause: { code:
|
|
1116
|
+
console.error(e, { stack: e == null ? void 0 : e.stack, message: e == null ? void 0 : e.message }), super(t, { cause: { code: ee[t], message: t } }), Object.setPrototypeOf(this, dt.prototype);
|
|
1105
1117
|
}
|
|
1106
1118
|
}
|
|
1107
|
-
class g extends
|
|
1119
|
+
class g extends N {
|
|
1108
1120
|
eq(t) {
|
|
1109
1121
|
return this.eqValue(t);
|
|
1110
1122
|
}
|
|
1111
1123
|
static fromBigInt(t, e) {
|
|
1112
1124
|
return new g({
|
|
1113
1125
|
decimal: e,
|
|
1114
|
-
value:
|
|
1126
|
+
value: k({ value: t, bigIntDecimal: e, decimal: e })
|
|
1115
1127
|
});
|
|
1116
1128
|
}
|
|
1117
1129
|
}
|
|
1118
1130
|
export {
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1131
|
+
A as AssetValue,
|
|
1132
|
+
N as BigIntArithmetics,
|
|
1133
|
+
Xt as RequestClient,
|
|
1134
|
+
dt as SwapKitError,
|
|
1123
1135
|
g as SwapKitNumber,
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1136
|
+
ie as assetFromString,
|
|
1137
|
+
fe as derivationPathToString,
|
|
1138
|
+
oe as filterAssets,
|
|
1139
|
+
k as formatBigIntToSafeValue,
|
|
1140
|
+
ne as gasFeeMultiplier,
|
|
1141
|
+
Ot as getAssetType,
|
|
1142
|
+
xt as getAsymmetricAssetShare,
|
|
1143
|
+
ce as getAsymmetricAssetWithdrawAmount,
|
|
1144
|
+
Mt as getAsymmetricRuneShare,
|
|
1145
|
+
ae as getAsymmetricRuneWithdrawAmount,
|
|
1146
|
+
It as getCommonAssetInfo,
|
|
1147
|
+
St as getDecimal,
|
|
1148
|
+
le as getEstimatedPoolShare,
|
|
1149
|
+
he as getLiquiditySlippage,
|
|
1150
|
+
de as getMemoFor,
|
|
1151
|
+
_e as getMinAmountByChain,
|
|
1152
|
+
qt as getSymmetricPoolShare,
|
|
1153
|
+
ue as getSymmetricWithdraw,
|
|
1154
|
+
me as getTHORNameCost,
|
|
1155
|
+
it as isGasAsset,
|
|
1156
|
+
pe as validateTHORName
|
|
1145
1157
|
};
|
|
1146
1158
|
//# sourceMappingURL=index.es.js.map
|