@swapkit/helpers 1.0.0-rc.36 → 1.0.0-rc.38
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 +10 -3
- package/dist/index.es.js +392 -374
- package/package.json +6 -6
- package/src/modules/__tests__/swapKitNumber.test.ts +21 -0
- package/src/modules/assetValue.ts +26 -16
- package/src/modules/bigIntArithmetics.ts +24 -5
- package/src/modules/swapKitError.ts +1 -1
package/dist/index.es.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
if (!t.has(
|
|
1
|
+
var bt = Object.defineProperty;
|
|
2
|
+
var yt = (r, t, e) => t in r ? bt(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
3
|
+
var f = (r, t, e) => (yt(r, typeof t != "symbol" ? t + "" : t, e), e), wt = (r, t, e) => {
|
|
4
|
+
if (!t.has(r))
|
|
5
5
|
throw TypeError("Cannot " + e);
|
|
6
6
|
};
|
|
7
|
-
var
|
|
8
|
-
if (t.has(
|
|
7
|
+
var $ = (r, t, e) => {
|
|
8
|
+
if (t.has(r))
|
|
9
9
|
throw TypeError("Cannot add the same private member more than once");
|
|
10
|
-
t instanceof WeakSet ? t.add(
|
|
10
|
+
t instanceof WeakSet ? t.add(r) : t.set(r, e);
|
|
11
11
|
};
|
|
12
|
-
var
|
|
13
|
-
import { FeeOption as
|
|
14
|
-
const
|
|
12
|
+
var m = (r, t, e) => (wt(r, 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: r, to: t }) => {
|
|
15
15
|
try {
|
|
16
|
-
const { result: e } = await
|
|
16
|
+
const { result: e } = await Zt.post(vt[r], {
|
|
17
17
|
headers: {
|
|
18
18
|
accept: "*/*",
|
|
19
19
|
"content-type": "application/json",
|
|
@@ -23,38 +23,38 @@ 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
|
-
return console.error(e), h[
|
|
31
|
+
return console.error(e), h[r];
|
|
32
32
|
}
|
|
33
|
-
},
|
|
34
|
-
if (
|
|
33
|
+
}, $t = async (r) => {
|
|
34
|
+
if (r === o.Ethereum)
|
|
35
35
|
return h.ETH;
|
|
36
|
-
const [, t] =
|
|
37
|
-
return t != null && t.startsWith("0x") ?
|
|
38
|
-
},
|
|
39
|
-
const [, t] =
|
|
40
|
-
return t != null && t.startsWith("0x") ?
|
|
41
|
-
},
|
|
42
|
-
switch (
|
|
36
|
+
const [, t] = r.split("-");
|
|
37
|
+
return t != null && t.startsWith("0x") ? it({ chain: o.Ethereum, to: t }) : h.ETH;
|
|
38
|
+
}, Rt = async (r) => {
|
|
39
|
+
const [, t] = r.split("-");
|
|
40
|
+
return t != null && t.startsWith("0x") ? it({ chain: o.Avalanche, to: t.toLowerCase() }) : h.AVAX;
|
|
41
|
+
}, St = async (r) => r === o.BinanceSmartChain ? h.BSC : h.BSC, Ct = async ({ chain: r, symbol: t }) => {
|
|
42
|
+
switch (r) {
|
|
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
|
-
return h[
|
|
50
|
+
return h[r];
|
|
51
51
|
}
|
|
52
|
-
},
|
|
53
|
-
[
|
|
54
|
-
[
|
|
55
|
-
[
|
|
56
|
-
},
|
|
57
|
-
switch (
|
|
52
|
+
}, ie = {
|
|
53
|
+
[L.Average]: 1.2,
|
|
54
|
+
[L.Fast]: 1.5,
|
|
55
|
+
[L.Fastest]: 2
|
|
56
|
+
}, ot = ({ chain: r, symbol: t }) => {
|
|
57
|
+
switch (r) {
|
|
58
58
|
case o.Bitcoin:
|
|
59
59
|
case o.BitcoinCash:
|
|
60
60
|
case o.Litecoin:
|
|
@@ -62,7 +62,7 @@ const At = "0x313ce567", rt = async ({ chain: s, to: t }) => {
|
|
|
62
62
|
case o.Binance:
|
|
63
63
|
case o.Ethereum:
|
|
64
64
|
case o.Avalanche:
|
|
65
|
-
return t ===
|
|
65
|
+
return t === r;
|
|
66
66
|
case o.Arbitrum:
|
|
67
67
|
case o.Optimism:
|
|
68
68
|
return t === "ETH";
|
|
@@ -79,18 +79,18 @@ const At = "0x313ce567", rt = async ({ chain: s, to: t }) => {
|
|
|
79
79
|
case o.THORChain:
|
|
80
80
|
return t === "RUNE";
|
|
81
81
|
}
|
|
82
|
-
},
|
|
83
|
-
switch (
|
|
82
|
+
}, It = (r) => {
|
|
83
|
+
switch (r) {
|
|
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: h[
|
|
89
|
+
return { identifier: "GAIA.ATOM", decimal: h[r] };
|
|
90
90
|
case o.THORChain:
|
|
91
|
-
return { identifier: "THOR.RUNE", decimal: h[
|
|
91
|
+
return { identifier: "THOR.RUNE", decimal: h[r] };
|
|
92
92
|
case o.BinanceSmartChain:
|
|
93
|
-
return { identifier: "BSC.BNB", decimal: h[
|
|
93
|
+
return { identifier: "BSC.BNB", decimal: h[r] };
|
|
94
94
|
case o.Maya:
|
|
95
95
|
return { identifier: "MAYA.CACAO", decimal: h.MAYA };
|
|
96
96
|
case "MAYA.MAYA":
|
|
@@ -106,12 +106,12 @@ const At = "0x313ce567", rt = async ({ chain: s, to: t }) => {
|
|
|
106
106
|
case o.Polygon:
|
|
107
107
|
case o.Bitcoin:
|
|
108
108
|
case o.Ethereum:
|
|
109
|
-
return { identifier: `${
|
|
109
|
+
return { identifier: `${r}.${r}`, decimal: h[r] };
|
|
110
110
|
}
|
|
111
|
-
},
|
|
111
|
+
}, Ot = ({ chain: r, symbol: t }) => {
|
|
112
112
|
if (t.includes("/"))
|
|
113
113
|
return "Synth";
|
|
114
|
-
switch (
|
|
114
|
+
switch (r) {
|
|
115
115
|
case o.Bitcoin:
|
|
116
116
|
case o.BitcoinCash:
|
|
117
117
|
case o.Dogecoin:
|
|
@@ -138,134 +138,134 @@ 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
|
-
},
|
|
141
|
+
}, oe = (r) => {
|
|
142
142
|
var a;
|
|
143
|
-
const [t, ...e] =
|
|
144
|
-
return { chain: t, symbol: n, ticker: i, synth:
|
|
145
|
-
},
|
|
143
|
+
const [t, ...e] = r.split("."), s = r.includes("/"), n = e.join("."), i = (a = n == null ? void 0 : n.split("-")) == null ? void 0 : a[0];
|
|
144
|
+
return { chain: t, symbol: n, ticker: i, synth: s };
|
|
145
|
+
}, Et = new RegExp(
|
|
146
146
|
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
|
|
147
147
|
"gmi"
|
|
148
|
-
),
|
|
149
|
-
const [t, e] =
|
|
150
|
-
if (!
|
|
148
|
+
), Mt = (r) => {
|
|
149
|
+
const [t, e] = r.split(".");
|
|
150
|
+
if (!At.includes(t))
|
|
151
151
|
return !0;
|
|
152
|
-
const [,
|
|
153
|
-
return
|
|
154
|
-
},
|
|
152
|
+
const [, s] = e.split("-");
|
|
153
|
+
return ot({ chain: t, symbol: e }) || !!s;
|
|
154
|
+
}, ae = (r) => r.filter((t) => {
|
|
155
155
|
const e = `${t.chain}.${t.symbol}`;
|
|
156
|
-
return !
|
|
157
|
-
}),
|
|
158
|
-
liquidityUnits:
|
|
156
|
+
return !Et.test(e) && Mt(e) && t.value !== "0";
|
|
157
|
+
}), Bt = ({
|
|
158
|
+
liquidityUnits: r,
|
|
159
159
|
poolUnits: t,
|
|
160
160
|
runeDepth: e
|
|
161
161
|
}) => {
|
|
162
|
-
const
|
|
162
|
+
const s = p(r), n = p(t), i = p(e), a = s.mul(i), c = n.mul(n).mul(2), u = n.mul(s).mul(2), d = s.mul(s), l = n.mul(n).mul(n);
|
|
163
163
|
return a.mul(c.sub(u).add(d)).div(l);
|
|
164
|
-
},
|
|
165
|
-
liquidityUnits:
|
|
164
|
+
}, xt = ({
|
|
165
|
+
liquidityUnits: r,
|
|
166
166
|
poolUnits: t,
|
|
167
167
|
assetDepth: e
|
|
168
168
|
}) => {
|
|
169
|
-
const
|
|
169
|
+
const s = p(r), n = p(t), i = p(e), a = s.mul(i), c = n.mul(n).mul(2), u = n.mul(s).mul(2), d = s.mul(s), l = a.mul(c.sub(u).add(d)), _ = n.mul(n).mul(n);
|
|
170
170
|
return l.div(_);
|
|
171
|
-
},
|
|
172
|
-
percent:
|
|
171
|
+
}, ce = ({
|
|
172
|
+
percent: r,
|
|
173
173
|
runeDepth: t,
|
|
174
174
|
liquidityUnits: e,
|
|
175
|
-
poolUnits:
|
|
176
|
-
}) =>
|
|
177
|
-
percent:
|
|
175
|
+
poolUnits: s
|
|
176
|
+
}) => Bt({ runeDepth: t, liquidityUnits: e, poolUnits: s }).mul(r), ue = ({
|
|
177
|
+
percent: r,
|
|
178
178
|
assetDepth: t,
|
|
179
179
|
liquidityUnits: e,
|
|
180
|
-
poolUnits:
|
|
181
|
-
}) =>
|
|
182
|
-
liquidityUnits:
|
|
180
|
+
poolUnits: s
|
|
181
|
+
}) => xt({ assetDepth: t, liquidityUnits: e, poolUnits: s }).mul(r), p = (r) => b.fromBigInt(BigInt(r), h.THOR), qt = ({
|
|
182
|
+
liquidityUnits: r,
|
|
183
183
|
poolUnits: t,
|
|
184
184
|
runeDepth: e,
|
|
185
|
-
assetDepth:
|
|
185
|
+
assetDepth: s
|
|
186
186
|
}) => ({
|
|
187
|
-
assetAmount:
|
|
188
|
-
runeAmount:
|
|
189
|
-
}),
|
|
190
|
-
liquidityUnits:
|
|
187
|
+
assetAmount: p(s).mul(r).div(t),
|
|
188
|
+
runeAmount: p(e).mul(r).div(t)
|
|
189
|
+
}), le = ({
|
|
190
|
+
liquidityUnits: r,
|
|
191
191
|
poolUnits: t,
|
|
192
192
|
runeDepth: e,
|
|
193
|
-
assetDepth:
|
|
193
|
+
assetDepth: s,
|
|
194
194
|
percent: n
|
|
195
195
|
}) => Object.fromEntries(
|
|
196
|
-
Object.entries(
|
|
196
|
+
Object.entries(qt({ liquidityUnits: r, poolUnits: t, runeDepth: e, assetDepth: s })).map(
|
|
197
197
|
([i, a]) => [i, a.mul(n)]
|
|
198
198
|
)
|
|
199
|
-
),
|
|
200
|
-
runeDepth:
|
|
199
|
+
), de = ({
|
|
200
|
+
runeDepth: r,
|
|
201
201
|
poolUnits: t,
|
|
202
202
|
assetDepth: e,
|
|
203
|
-
liquidityUnits:
|
|
203
|
+
liquidityUnits: s,
|
|
204
204
|
runeAmount: n,
|
|
205
205
|
assetAmount: i
|
|
206
206
|
}) => {
|
|
207
|
-
const a = new b({ value:
|
|
208
|
-
if (
|
|
209
|
-
return
|
|
210
|
-
const
|
|
211
|
-
return
|
|
212
|
-
},
|
|
213
|
-
runeAmount:
|
|
207
|
+
const a = new b({ value: r, 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(s).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
|
+
runeAmount: r,
|
|
214
214
|
assetAmount: t,
|
|
215
215
|
runeDepth: e,
|
|
216
|
-
assetDepth:
|
|
216
|
+
assetDepth: s
|
|
217
217
|
}) => {
|
|
218
|
-
if (
|
|
218
|
+
if (r === "0" || t === "0" || e === "0" || s === "0")
|
|
219
219
|
return 0;
|
|
220
|
-
const n =
|
|
220
|
+
const n = p(e), i = p(s), a = p(t), c = p(r), u = a.mul(n).sub(i.mul(c)), d = i.mul(c).add(n.mul(i));
|
|
221
221
|
return Math.abs(u.div(d).getBaseValue("number"));
|
|
222
|
-
},
|
|
223
|
-
symbol:
|
|
222
|
+
}, kt = ({
|
|
223
|
+
symbol: r,
|
|
224
224
|
ticker: t,
|
|
225
225
|
chain: e
|
|
226
|
-
}) => e === "ETH" && t !== "ETH" ? `${t}-${
|
|
227
|
-
switch (
|
|
226
|
+
}) => e === "ETH" && t !== "ETH" ? `${t}-${r.slice(-3)}` : r, me = (r, t) => {
|
|
227
|
+
switch (r) {
|
|
228
228
|
case g.LEAVE:
|
|
229
229
|
case g.BOND: {
|
|
230
230
|
const { address: e } = t;
|
|
231
|
-
return `${
|
|
231
|
+
return `${r}:${e}`;
|
|
232
232
|
}
|
|
233
233
|
case g.UNBOND: {
|
|
234
|
-
const { address: e, unbondAmount:
|
|
235
|
-
return `${
|
|
234
|
+
const { address: e, unbondAmount: s } = t;
|
|
235
|
+
return `${r}:${e}:${s * 10 ** 8}`;
|
|
236
236
|
}
|
|
237
237
|
case g.THORNAME_REGISTER: {
|
|
238
|
-
const { name: e, chain:
|
|
239
|
-
return `${
|
|
238
|
+
const { name: e, chain: s, address: n, owner: i } = t;
|
|
239
|
+
return `${r}:${e}:${s}:${n}${i ? `:${i}` : ""}`;
|
|
240
240
|
}
|
|
241
241
|
case g.DEPOSIT: {
|
|
242
|
-
const { chain: e, symbol:
|
|
243
|
-
return i ? `${
|
|
242
|
+
const { chain: e, symbol: s, address: n, singleSide: i } = t;
|
|
243
|
+
return i ? `${r}:${e}/${s}::t:0` : `${r}:${e}.${s}:${n || ""}:t:0`;
|
|
244
244
|
}
|
|
245
245
|
case g.WITHDRAW: {
|
|
246
|
-
const { chain: e, ticker:
|
|
247
|
-
return `${
|
|
246
|
+
const { chain: e, ticker: s, symbol: n, basisPoints: i, targetAssetString: a, singleSide: c } = t, u = !c && a ? `:${a}` : "", d = kt({ chain: e, symbol: n, ticker: s });
|
|
247
|
+
return `${r}:${e}${c ? "/" : "."}${d}:${i}${u}`;
|
|
248
248
|
}
|
|
249
249
|
case g.OPEN_LOAN:
|
|
250
250
|
case g.CLOSE_LOAN: {
|
|
251
|
-
const { asset: e, address:
|
|
252
|
-
return `${
|
|
251
|
+
const { asset: e, address: s } = t;
|
|
252
|
+
return `${r}:${e}:${s}`;
|
|
253
253
|
}
|
|
254
254
|
default:
|
|
255
255
|
return "";
|
|
256
256
|
}
|
|
257
|
-
},
|
|
258
|
-
if (
|
|
257
|
+
}, pe = (r) => {
|
|
258
|
+
if (r < 0)
|
|
259
259
|
throw new Error("Invalid number of year");
|
|
260
|
-
return 10 +
|
|
261
|
-
},
|
|
262
|
-
if (
|
|
260
|
+
return 10 + r;
|
|
261
|
+
}, fe = (r) => {
|
|
262
|
+
if (r.length > 30)
|
|
263
263
|
return !1;
|
|
264
264
|
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
265
|
-
return !!
|
|
266
|
-
},
|
|
267
|
-
class
|
|
268
|
-
constructor(t, e,
|
|
265
|
+
return !!r.match(t);
|
|
266
|
+
}, _e = ([r, t, e, s, n]) => `${r}'/${t}'/${e}'/${s}${typeof n != "number" ? "" : `/${n}`}`;
|
|
267
|
+
class X extends Error {
|
|
268
|
+
constructor(t, e, s) {
|
|
269
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
270
|
super(`Request failed with ${c}`), Object.defineProperty(this, "response", {
|
|
271
271
|
enumerable: !0,
|
|
@@ -282,10 +282,10 @@ class J extends Error {
|
|
|
282
282
|
configurable: !0,
|
|
283
283
|
writable: !0,
|
|
284
284
|
value: void 0
|
|
285
|
-
}), this.name = "HTTPError", this.response = t, this.request = e, this.options =
|
|
285
|
+
}), this.name = "HTTPError", this.response = t, this.request = e, this.options = s;
|
|
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,45 +295,45 @@ class nt extends Error {
|
|
|
295
295
|
}), this.name = "TimeoutError", this.request = t;
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
|
-
const
|
|
299
|
-
for (const t of
|
|
300
|
-
if ((!
|
|
298
|
+
const q = (r) => r !== null && typeof r == "object", B = (...r) => {
|
|
299
|
+
for (const t of r)
|
|
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
|
-
},
|
|
304
|
-
const e = new globalThis.Headers(
|
|
302
|
+
return J({}, ...r);
|
|
303
|
+
}, ct = (r = {}, t = {}) => {
|
|
304
|
+
const e = new globalThis.Headers(r), s = t instanceof globalThis.Headers, n = new globalThis.Headers(t);
|
|
305
305
|
for (const [i, a] of n.entries())
|
|
306
|
-
|
|
306
|
+
s && a === "undefined" || a === void 0 ? e.delete(i) : e.set(i, a);
|
|
307
307
|
return e;
|
|
308
|
-
},
|
|
308
|
+
}, J = (...r) => {
|
|
309
309
|
let t = {}, e = {};
|
|
310
|
-
for (const
|
|
311
|
-
if (Array.isArray(
|
|
312
|
-
Array.isArray(t) || (t = []), t = [...t, ...
|
|
313
|
-
else if (
|
|
314
|
-
for (let [n, i] of Object.entries(
|
|
315
|
-
|
|
316
|
-
|
|
310
|
+
for (const s of r)
|
|
311
|
+
if (Array.isArray(s))
|
|
312
|
+
Array.isArray(t) || (t = []), t = [...t, ...s];
|
|
313
|
+
else if (q(s)) {
|
|
314
|
+
for (let [n, i] of Object.entries(s))
|
|
315
|
+
q(i) && n in t && (i = J(t[n], i)), t = { ...t, [n]: i };
|
|
316
|
+
q(s.headers) && (e = ct(e, s.headers), t.headers = e);
|
|
317
317
|
}
|
|
318
318
|
return t;
|
|
319
|
-
},
|
|
320
|
-
let
|
|
321
|
-
const e = typeof globalThis.ReadableStream == "function",
|
|
322
|
-
return e &&
|
|
319
|
+
}, Vt = (() => {
|
|
320
|
+
let r = !1, t = !1;
|
|
321
|
+
const e = typeof globalThis.ReadableStream == "function", s = typeof globalThis.Request == "function";
|
|
322
|
+
return e && s && (t = new globalThis.Request("https://empty.invalid", {
|
|
323
323
|
body: new globalThis.ReadableStream(),
|
|
324
324
|
method: "POST",
|
|
325
325
|
// @ts-expect-error - Types are outdated.
|
|
326
326
|
get duplex() {
|
|
327
|
-
return
|
|
327
|
+
return r = !0, "half";
|
|
328
328
|
}
|
|
329
|
-
}).headers.has("Content-Type")),
|
|
330
|
-
})(),
|
|
329
|
+
}).headers.has("Content-Type")), r && !t;
|
|
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,86 +360,86 @@ 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 = (r) => ut.includes(r) ? r.toUpperCase() : r, 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
|
-
delay: (
|
|
371
|
-
},
|
|
372
|
-
if (typeof
|
|
370
|
+
delay: (r) => 0.3 * 2 ** (r - 1) * 1e3
|
|
371
|
+
}, Gt = (r = {}) => {
|
|
372
|
+
if (typeof r == "number")
|
|
373
373
|
return {
|
|
374
|
-
...
|
|
375
|
-
limit:
|
|
374
|
+
...Z,
|
|
375
|
+
limit: r
|
|
376
376
|
};
|
|
377
|
-
if (
|
|
377
|
+
if (r.methods && !Array.isArray(r.methods))
|
|
378
378
|
throw new Error("retry.methods must be an array");
|
|
379
|
-
if (
|
|
379
|
+
if (r.statusCodes && !Array.isArray(r.statusCodes))
|
|
380
380
|
throw new Error("retry.statusCodes must be an array");
|
|
381
381
|
return {
|
|
382
|
-
...
|
|
383
|
-
...
|
|
384
|
-
afterStatusCodes:
|
|
382
|
+
...Z,
|
|
383
|
+
...r,
|
|
384
|
+
afterStatusCodes: dt
|
|
385
385
|
};
|
|
386
386
|
};
|
|
387
|
-
async function
|
|
387
|
+
async function Yt(r, t, e, s) {
|
|
388
388
|
return new Promise((n, i) => {
|
|
389
389
|
const a = setTimeout(() => {
|
|
390
|
-
e && e.abort(), i(new
|
|
391
|
-
},
|
|
392
|
-
|
|
390
|
+
e && e.abort(), i(new at(r));
|
|
391
|
+
}, s.timeout);
|
|
392
|
+
s.fetch(r, t).then(n).catch(i).then(() => {
|
|
393
393
|
clearTimeout(a);
|
|
394
394
|
});
|
|
395
395
|
});
|
|
396
396
|
}
|
|
397
|
-
async function
|
|
398
|
-
return new Promise((e,
|
|
397
|
+
async function zt(r, { signal: t }) {
|
|
398
|
+
return new Promise((e, s) => {
|
|
399
399
|
t && (t.throwIfAborted(), t.addEventListener("abort", n, { once: !0 }));
|
|
400
400
|
function n() {
|
|
401
|
-
clearTimeout(i),
|
|
401
|
+
clearTimeout(i), s(t.reason);
|
|
402
402
|
}
|
|
403
403
|
const i = setTimeout(() => {
|
|
404
404
|
t == null || t.removeEventListener("abort", n), e();
|
|
405
|
-
},
|
|
405
|
+
}, r);
|
|
406
406
|
});
|
|
407
407
|
}
|
|
408
|
-
const
|
|
408
|
+
const Jt = (r, t) => {
|
|
409
409
|
const e = {};
|
|
410
|
-
for (const
|
|
411
|
-
!(
|
|
410
|
+
for (const s in t)
|
|
411
|
+
!(s in Dt) && !(s in Lt) && !(s in r) && (e[s] = t[s]);
|
|
412
412
|
return e;
|
|
413
413
|
};
|
|
414
414
|
class V {
|
|
415
415
|
static create(t, e) {
|
|
416
|
-
const
|
|
417
|
-
if (typeof
|
|
418
|
-
throw new RangeError(`The \`timeout\` option cannot be greater than ${
|
|
416
|
+
const s = new V(t, e), n = async () => {
|
|
417
|
+
if (typeof s._options.timeout == "number" && s._options.timeout > D)
|
|
418
|
+
throw new RangeError(`The \`timeout\` option cannot be greater than ${D}`);
|
|
419
419
|
await Promise.resolve();
|
|
420
|
-
let c = await
|
|
421
|
-
for (const u of
|
|
422
|
-
const d = await u(
|
|
420
|
+
let c = await s._fetch();
|
|
421
|
+
for (const u of s._options.hooks.afterResponse) {
|
|
422
|
+
const d = await u(s.request, s._options, s._decorateResponse(c.clone()));
|
|
423
423
|
d instanceof globalThis.Response && (c = d);
|
|
424
424
|
}
|
|
425
|
-
if (
|
|
426
|
-
let u = new
|
|
427
|
-
for (const d of
|
|
425
|
+
if (s._decorateResponse(c), !c.ok && s._options.throwHttpErrors) {
|
|
426
|
+
let u = new X(c, s.request, s._options);
|
|
427
|
+
for (const d of s._options.hooks.beforeError)
|
|
428
428
|
u = await d(u);
|
|
429
429
|
throw u;
|
|
430
430
|
}
|
|
431
|
-
if (
|
|
432
|
-
if (typeof
|
|
431
|
+
if (s._options.onDownloadProgress) {
|
|
432
|
+
if (typeof s._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
|
|
436
|
+
return s._stream(c.clone(), s._options.onDownloadProgress);
|
|
437
437
|
}
|
|
438
438
|
return c;
|
|
439
|
-
}, a =
|
|
440
|
-
for (const [c, u] of Object.entries(
|
|
439
|
+
}, a = s._options.retry.methods.includes(s.request.method.toLowerCase()) ? s._retry(n) : n();
|
|
440
|
+
for (const [c, u] of Object.entries(Ht))
|
|
441
441
|
a[c] = async () => {
|
|
442
|
-
|
|
442
|
+
s.request.headers.set("accept", s.request.headers.get("accept") || u);
|
|
443
443
|
const l = (await a).clone();
|
|
444
444
|
if (c === "json") {
|
|
445
445
|
if (l.status === 204 || (await l.clone().arrayBuffer()).byteLength === 0)
|
|
@@ -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,30 +503,30 @@ 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
|
-
const
|
|
508
|
+
const s = this._options.signal;
|
|
509
509
|
this._options.signal.addEventListener("abort", () => {
|
|
510
|
-
this.abortController.abort(
|
|
510
|
+
this.abortController.abort(s.reason);
|
|
511
511
|
});
|
|
512
512
|
}
|
|
513
513
|
this._options.signal = this.abortController.signal;
|
|
514
514
|
}
|
|
515
|
-
if (
|
|
515
|
+
if (Vt && (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
|
-
const
|
|
527
|
-
if (
|
|
528
|
-
let n = Number(
|
|
529
|
-
return Number.isNaN(n) ? n = Date.parse(
|
|
526
|
+
const s = t.response.headers.get("Retry-After");
|
|
527
|
+
if (s && this._options.retry.afterStatusCodes.includes(t.response.status)) {
|
|
528
|
+
let n = Number(s);
|
|
529
|
+
return Number.isNaN(n) ? n = Date.parse(s) - Date.now() : n *= 1e3, this._options.retry.maxRetryAfter !== void 0 && n > this._options.retry.maxRetryAfter ? 0 : n;
|
|
530
530
|
}
|
|
531
531
|
if (t.response.status === 413)
|
|
532
532
|
return 0;
|
|
@@ -543,16 +543,16 @@ class V {
|
|
|
543
543
|
try {
|
|
544
544
|
return await t();
|
|
545
545
|
} catch (e) {
|
|
546
|
-
const
|
|
547
|
-
if (
|
|
548
|
-
await
|
|
546
|
+
const s = Math.min(this._calculateRetryDelay(e), D);
|
|
547
|
+
if (s !== 0 && this._retryCount > 0) {
|
|
548
|
+
await zt(s, { 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
|
}
|
|
@@ -561,29 +561,29 @@ class V {
|
|
|
561
561
|
}
|
|
562
562
|
async _fetch() {
|
|
563
563
|
for (const e of this._options.hooks.beforeRequest) {
|
|
564
|
-
const
|
|
565
|
-
if (
|
|
566
|
-
this.request =
|
|
564
|
+
const s = await e(this.request, this._options);
|
|
565
|
+
if (s instanceof Request) {
|
|
566
|
+
this.request = s;
|
|
567
567
|
break;
|
|
568
568
|
}
|
|
569
|
-
if (
|
|
570
|
-
return
|
|
569
|
+
if (s instanceof Response)
|
|
570
|
+
return s;
|
|
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) {
|
|
577
|
-
const
|
|
577
|
+
const s = Number(t.headers.get("content-length")) || 0;
|
|
578
578
|
let n = 0;
|
|
579
|
-
return t.status === 204 ? (e && e({ percent: 1, totalBytes:
|
|
579
|
+
return t.status === 204 ? (e && e({ percent: 1, totalBytes: s, transferredBytes: n }, new Uint8Array()), new globalThis.Response(null, {
|
|
580
580
|
status: t.status,
|
|
581
581
|
statusText: t.statusText,
|
|
582
582
|
headers: t.headers
|
|
583
583
|
})) : new globalThis.Response(new globalThis.ReadableStream({
|
|
584
584
|
async start(i) {
|
|
585
585
|
const a = t.body.getReader();
|
|
586
|
-
e && e({ percent: 0, transferredBytes: 0, totalBytes:
|
|
586
|
+
e && e({ percent: 0, transferredBytes: 0, totalBytes: s }, new Uint8Array());
|
|
587
587
|
async function c() {
|
|
588
588
|
const { done: u, value: d } = await a.read();
|
|
589
589
|
if (u) {
|
|
@@ -592,8 +592,8 @@ class V {
|
|
|
592
592
|
}
|
|
593
593
|
if (e) {
|
|
594
594
|
n += d.byteLength;
|
|
595
|
-
const l =
|
|
596
|
-
e({ percent: l, transferredBytes: n, totalBytes:
|
|
595
|
+
const l = s === 0 ? 0 : n / s;
|
|
596
|
+
e({ percent: l, transferredBytes: n, totalBytes: s }, d);
|
|
597
597
|
}
|
|
598
598
|
i.enqueue(d), await c();
|
|
599
599
|
}
|
|
@@ -607,105 +607,106 @@ class V {
|
|
|
607
607
|
}
|
|
608
608
|
}
|
|
609
609
|
/*! MIT License © Sindre Sorhus */
|
|
610
|
-
const
|
|
611
|
-
const t = (e,
|
|
612
|
-
for (const e of
|
|
613
|
-
t[e] = (
|
|
614
|
-
return t.create = (e) =>
|
|
615
|
-
},
|
|
616
|
-
get: (
|
|
617
|
-
post: (
|
|
618
|
-
},
|
|
619
|
-
const t =
|
|
620
|
-
if (
|
|
610
|
+
const U = (r) => {
|
|
611
|
+
const t = (e, s) => V.create(e, B(r, s));
|
|
612
|
+
for (const e of ut)
|
|
613
|
+
t[e] = (s, n) => V.create(s, B(r, n, { method: e }));
|
|
614
|
+
return t.create = (e) => U(B(e)), t.extend = (e) => U(B(r, 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: (r, t) => tt.get(r, t).json(),
|
|
617
|
+
post: (r, t) => tt.post(r, t).json()
|
|
618
|
+
}, et = Object.values(o), te = (r = "") => {
|
|
619
|
+
const t = r.toUpperCase(), [e] = t.split(".");
|
|
620
|
+
if (et.includes(e))
|
|
621
621
|
return !0;
|
|
622
|
-
const [
|
|
623
|
-
if (
|
|
622
|
+
const [s] = t.split("/");
|
|
623
|
+
if (et.includes(s))
|
|
624
624
|
return !0;
|
|
625
625
|
throw new Error(
|
|
626
|
-
`Invalid identifier: ${
|
|
626
|
+
`Invalid identifier: ${r}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
627
627
|
);
|
|
628
|
-
},
|
|
629
|
-
function
|
|
630
|
-
value:
|
|
631
|
-
bigIntDecimal: t =
|
|
632
|
-
decimal: e =
|
|
628
|
+
}, I = 8, w = (r) => 10n ** BigInt(r), S = (r) => Math.log10(parseFloat(r.toString()));
|
|
629
|
+
function P({
|
|
630
|
+
value: r,
|
|
631
|
+
bigIntDecimal: t = I,
|
|
632
|
+
decimal: e = I
|
|
633
633
|
}) {
|
|
634
|
-
const
|
|
635
|
-
let n =
|
|
634
|
+
const s = r < 0n;
|
|
635
|
+
let n = r.toString().substring(s ? 1 : 0);
|
|
636
636
|
const i = e - (n.length - 1);
|
|
637
637
|
i > 0 && (n = "0".repeat(i) + n);
|
|
638
638
|
const a = n.length - e;
|
|
639
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), `${
|
|
640
|
+
return parseInt(c[t]) >= 5 ? c = `${c.substring(0, t - 1)}${(parseInt(c[t - 1]) + 1).toString()}` : c = c.substring(0, t), `${s ? "-" : ""}${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, E, F, M, W;
|
|
646
|
+
const K = class K {
|
|
647
647
|
constructor(t) {
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
648
|
+
$(this, v);
|
|
649
|
+
$(this, y);
|
|
650
|
+
$(this, N);
|
|
651
|
+
$(this, E);
|
|
652
|
+
$(this, M);
|
|
653
|
+
f(this, "decimalMultiplier", 10n ** 8n);
|
|
654
|
+
f(this, "bigIntValue", 0n);
|
|
655
|
+
f(this, "decimal");
|
|
656
|
+
const e = G(t), s = typeof t == "object";
|
|
657
|
+
this.decimal = s ? t.decimal : void 0, this.decimalMultiplier = s && "decimalMultiplier" in t ? t.decimalMultiplier : w(Math.max(st(x(e)), this.decimal || 0)), m(this, N, ht).call(this, e);
|
|
657
658
|
}
|
|
658
659
|
static fromBigInt(t, e) {
|
|
659
|
-
return new
|
|
660
|
+
return new K({
|
|
660
661
|
decimal: e,
|
|
661
|
-
value:
|
|
662
|
+
value: P({ value: t, bigIntDecimal: e, decimal: e })
|
|
662
663
|
});
|
|
663
664
|
}
|
|
664
665
|
static shiftDecimals({
|
|
665
666
|
value: t,
|
|
666
667
|
from: e,
|
|
667
|
-
to:
|
|
668
|
+
to: s
|
|
668
669
|
}) {
|
|
669
670
|
return this.fromBigInt(
|
|
670
|
-
t.getBaseValue("bigint") *
|
|
671
|
-
|
|
671
|
+
t.getBaseValue("bigint") * w(s) / w(e),
|
|
672
|
+
s
|
|
672
673
|
);
|
|
673
674
|
}
|
|
674
675
|
set(t) {
|
|
675
676
|
return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
|
|
676
677
|
}
|
|
677
678
|
add(...t) {
|
|
678
|
-
return
|
|
679
|
+
return m(this, v, C).call(this, "add", ...t);
|
|
679
680
|
}
|
|
680
681
|
sub(...t) {
|
|
681
|
-
return
|
|
682
|
+
return m(this, v, C).call(this, "sub", ...t);
|
|
682
683
|
}
|
|
683
684
|
mul(...t) {
|
|
684
|
-
return
|
|
685
|
+
return m(this, v, C).call(this, "mul", ...t);
|
|
685
686
|
}
|
|
686
687
|
div(...t) {
|
|
687
|
-
return
|
|
688
|
+
return m(this, v, C).call(this, "div", ...t);
|
|
688
689
|
}
|
|
689
690
|
gt(t) {
|
|
690
|
-
return this
|
|
691
|
+
return m(this, y, R).call(this, "gt", t);
|
|
691
692
|
}
|
|
692
693
|
gte(t) {
|
|
693
|
-
return this
|
|
694
|
+
return m(this, y, R).call(this, "gte", t);
|
|
694
695
|
}
|
|
695
696
|
lt(t) {
|
|
696
|
-
return this
|
|
697
|
+
return m(this, y, R).call(this, "lt", t);
|
|
697
698
|
}
|
|
698
699
|
lte(t) {
|
|
699
|
-
return this
|
|
700
|
+
return m(this, y, R).call(this, "lte", t);
|
|
700
701
|
}
|
|
701
702
|
eqValue(t) {
|
|
702
|
-
return this
|
|
703
|
+
return m(this, y, R).call(this, "eqValue", t);
|
|
703
704
|
}
|
|
704
705
|
// @ts-expect-error False positive
|
|
705
706
|
getValue(t) {
|
|
706
707
|
const e = this.formatBigIntToSafeValue(
|
|
707
708
|
this.bigIntValue,
|
|
708
|
-
this.decimal ||
|
|
709
|
+
this.decimal || S(this.decimalMultiplier)
|
|
709
710
|
);
|
|
710
711
|
switch (t) {
|
|
711
712
|
case "number":
|
|
@@ -718,24 +719,24 @@ const Y = class Y {
|
|
|
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), s = this.bigIntValue / e;
|
|
722
723
|
switch (t) {
|
|
723
724
|
case "number":
|
|
724
|
-
return Number(
|
|
725
|
+
return Number(s);
|
|
725
726
|
case "string":
|
|
726
|
-
return
|
|
727
|
+
return s.toString();
|
|
727
728
|
case "bigint":
|
|
728
|
-
return
|
|
729
|
+
return s;
|
|
729
730
|
}
|
|
730
731
|
}
|
|
731
732
|
getBigIntValue(t, e) {
|
|
732
733
|
if (!e && typeof t == "object")
|
|
733
734
|
return t.bigIntValue;
|
|
734
|
-
const
|
|
735
|
-
return n === "0" || n === "undefined" ? 0n :
|
|
735
|
+
const s = G(t), n = x(s);
|
|
736
|
+
return n === "0" || n === "undefined" ? 0n : m(this, M, W).call(this, n, e);
|
|
736
737
|
}
|
|
737
738
|
toSignificant(t = 6) {
|
|
738
|
-
const [e,
|
|
739
|
+
const [e, s] = this.getValue("string").split("."), n = e || "", i = s || "";
|
|
739
740
|
if ((parseInt(n) ? n.length + i.length : i.length) <= t)
|
|
740
741
|
return this.getValue("string");
|
|
741
742
|
if (n.length >= t)
|
|
@@ -752,7 +753,7 @@ const Y = class Y {
|
|
|
752
753
|
)}`;
|
|
753
754
|
}
|
|
754
755
|
toFixed(t = 6) {
|
|
755
|
-
const [e,
|
|
756
|
+
const [e, s] = this.getValue("string").split("."), n = e || "", i = s || "";
|
|
756
757
|
if (parseInt(n))
|
|
757
758
|
return `${n}.${i.slice(0, t)}`.padEnd(t, "0");
|
|
758
759
|
const a = parseInt(i), c = `${a}`.slice(0, t);
|
|
@@ -762,7 +763,7 @@ const Y = class Y {
|
|
|
762
763
|
)}`;
|
|
763
764
|
}
|
|
764
765
|
toAbbreviation(t = 2) {
|
|
765
|
-
const e = this.getValue("number"),
|
|
766
|
+
const e = this.getValue("number"), s = ["", "K", "M", "B", "T", "Q", "Qi", "S"], n = Math.floor(Math.log10(Math.abs(e)) / 3), i = s[n];
|
|
766
767
|
if (!i)
|
|
767
768
|
return this.getValue("string");
|
|
768
769
|
const a = 10 ** (n * 3);
|
|
@@ -770,27 +771,27 @@ const Y = class Y {
|
|
|
770
771
|
}
|
|
771
772
|
toCurrency(t = "$", {
|
|
772
773
|
currencyPosition: e = "start",
|
|
773
|
-
decimal:
|
|
774
|
+
decimal: s = 2,
|
|
774
775
|
decimalSeparator: n = ".",
|
|
775
776
|
thousandSeparator: i = ","
|
|
776
777
|
} = {}) {
|
|
777
|
-
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,
|
|
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, s)}` : ""}`;
|
|
778
779
|
return `${e === "start" ? t : ""}${l}${e === "end" ? t : ""}`;
|
|
779
780
|
}
|
|
780
781
|
formatBigIntToSafeValue(t, e) {
|
|
781
|
-
const
|
|
782
|
-
|
|
783
|
-
|
|
782
|
+
const s = e || this.decimal || I, n = Math.max(
|
|
783
|
+
s,
|
|
784
|
+
S(this.decimalMultiplier)
|
|
784
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;
|
|
785
786
|
let l = u.slice(-n);
|
|
786
|
-
return parseInt(l[
|
|
787
|
+
return parseInt(l[s]) >= 5 ? l = `${l.substring(0, s - 1)}${(parseInt(l[s - 1]) + 1).toString()}` : l = l.substring(0, s), `${i ? "-" : ""}${u.slice(
|
|
787
788
|
0,
|
|
788
789
|
d
|
|
789
790
|
)}.${l}`.replace(/\.?0*$/, "");
|
|
790
791
|
}
|
|
791
792
|
};
|
|
792
|
-
|
|
793
|
-
const
|
|
793
|
+
v = new WeakSet(), C = function(t, ...e) {
|
|
794
|
+
const s = m(this, E, F).call(this, this, ...e), n = Math.max(s, S(this.decimalMultiplier)), i = w(n), a = e.reduce(
|
|
794
795
|
(u, d) => {
|
|
795
796
|
const l = this.getBigIntValue(d, n);
|
|
796
797
|
switch (t) {
|
|
@@ -811,104 +812,121 @@ A = new WeakSet(), R = function(t, ...e) {
|
|
|
811
812
|
},
|
|
812
813
|
//normalize is to precision multiplier base
|
|
813
814
|
this.bigIntValue * i / this.decimalMultiplier
|
|
814
|
-
), c =
|
|
815
|
+
), c = P({
|
|
815
816
|
bigIntDecimal: n,
|
|
816
817
|
decimal: n,
|
|
817
818
|
value: a
|
|
818
819
|
});
|
|
819
820
|
return new this.constructor({
|
|
820
|
-
decimalMultiplier:
|
|
821
|
+
decimalMultiplier: w(n),
|
|
821
822
|
decimal: this.decimal,
|
|
822
823
|
value: c,
|
|
823
824
|
identifier: this.toString()
|
|
824
825
|
});
|
|
825
|
-
},
|
|
826
|
-
const e =
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
826
|
+
}, y = new WeakSet(), R = function(t, ...e) {
|
|
827
|
+
const s = m(this, E, F).call(this, this, ...e), n = this.getBigIntValue(e[0], s), i = this.getBigIntValue(this, s);
|
|
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
|
+
}, E = new WeakSet(), F = function(...t) {
|
|
844
|
+
const e = t.map((s) => typeof s == "object" ? s.decimal || S(s.decimalMultiplier) : st(x(s))).filter(Boolean);
|
|
845
|
+
return Math.max(...e, I);
|
|
846
|
+
}, M = new WeakSet(), W = function(t, e) {
|
|
847
|
+
const s = e ? w(e) : this.decimalMultiplier, n = S(s), [i = "", a = ""] = t.split(".");
|
|
833
848
|
return BigInt(`${i}${a.padEnd(n, "0")}`);
|
|
834
849
|
};
|
|
835
|
-
let
|
|
836
|
-
const
|
|
850
|
+
let O = K;
|
|
851
|
+
const ee = Intl.NumberFormat("fullwide", {
|
|
837
852
|
useGrouping: !1,
|
|
838
853
|
maximumFractionDigits: 20
|
|
839
854
|
});
|
|
840
|
-
function
|
|
841
|
-
const e = `${typeof
|
|
855
|
+
function x(r) {
|
|
856
|
+
const e = `${typeof r == "number" ? ee.format(r) : G(r)}`.replaceAll(",", ".").split(".");
|
|
842
857
|
return e.length > 1 ? `${e.slice(0, -1).join("")}.${e.at(-1)}` : e[0];
|
|
843
858
|
}
|
|
844
|
-
function
|
|
859
|
+
function st(r) {
|
|
845
860
|
var e;
|
|
846
|
-
const t = ((e =
|
|
847
|
-
return Math.max(t,
|
|
861
|
+
const t = ((e = r.split(".")[1]) == null ? void 0 : e.length) || 0;
|
|
862
|
+
return Math.max(t, I);
|
|
848
863
|
}
|
|
849
|
-
function
|
|
850
|
-
return typeof
|
|
864
|
+
function G(r) {
|
|
865
|
+
return typeof r == "object" ? "getValue" in r ? r.getValue("string") : r.value : r;
|
|
851
866
|
}
|
|
852
|
-
const
|
|
853
|
-
let
|
|
854
|
-
const
|
|
855
|
-
if (!
|
|
867
|
+
const k = (r, t) => typeof r == "bigint" ? P({ value: r, bigIntDecimal: t, decimal: t }) : r;
|
|
868
|
+
let Y;
|
|
869
|
+
const rt = (r) => {
|
|
870
|
+
if (!Y)
|
|
856
871
|
throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");
|
|
857
|
-
return
|
|
858
|
-
},
|
|
859
|
-
|
|
860
|
-
const e = await
|
|
861
|
-
return new
|
|
872
|
+
return Y.get(r.toUpperCase()) || { decimal: h.THOR, identifier: "" };
|
|
873
|
+
}, nt = async (r, t = 0) => {
|
|
874
|
+
te(r);
|
|
875
|
+
const e = await Ct(z(r)), s = k(t, e);
|
|
876
|
+
return new A({ decimal: e, value: s, identifier: r });
|
|
862
877
|
};
|
|
863
|
-
class
|
|
878
|
+
class A extends O {
|
|
864
879
|
constructor(e) {
|
|
865
|
-
const
|
|
880
|
+
const s = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`;
|
|
866
881
|
super(
|
|
867
|
-
e.value instanceof
|
|
882
|
+
e.value instanceof O ? e.value : { decimal: e.decimal, value: e.value }
|
|
868
883
|
);
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
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(s);
|
|
893
|
+
this.type = Ot(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;
|
|
878
894
|
}
|
|
879
895
|
toString(e = !1) {
|
|
880
|
-
const
|
|
881
|
-
return e ?
|
|
896
|
+
const s = this.isSynthetic ? this.symbol.split("-")[0] : this.ticker;
|
|
897
|
+
return e ? s : (
|
|
882
898
|
// THOR.ETH/ETH | ETH.USDT-0x1234567890
|
|
883
899
|
`${this.chain}.${this.symbol}`
|
|
884
900
|
);
|
|
885
901
|
}
|
|
886
|
-
eq({ chain: e, symbol:
|
|
887
|
-
return this.chain === e && this.symbol ===
|
|
902
|
+
eq({ chain: e, symbol: s }) {
|
|
903
|
+
return this.chain === e && this.symbol === s;
|
|
888
904
|
}
|
|
889
|
-
static async fromString(e,
|
|
890
|
-
return
|
|
905
|
+
static async fromString(e, s = 0) {
|
|
906
|
+
return nt(e, s);
|
|
891
907
|
}
|
|
892
|
-
static fromStringSync(e,
|
|
893
|
-
const { isSynthetic: n } =
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
908
|
+
static fromStringSync(e, s = 0) {
|
|
909
|
+
const { isSynthetic: n } = z(e), {
|
|
910
|
+
tax: i,
|
|
911
|
+
decimal: a,
|
|
912
|
+
identifier: c
|
|
913
|
+
} = rt(e), u = k(s, 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;
|
|
897
915
|
}
|
|
898
|
-
static async fromIdentifier(e,
|
|
899
|
-
return
|
|
916
|
+
static async fromIdentifier(e, s = 0) {
|
|
917
|
+
return nt(e, s);
|
|
900
918
|
}
|
|
901
|
-
static fromIdentifierSync(e,
|
|
902
|
-
const { decimal: n, identifier: i } =
|
|
903
|
-
return new
|
|
919
|
+
static fromIdentifierSync(e, s = 0) {
|
|
920
|
+
const { decimal: n, identifier: i } = rt(e), a = k(s, n);
|
|
921
|
+
return new A({ decimal: n, identifier: i, value: a });
|
|
904
922
|
}
|
|
905
|
-
static fromChainOrSignature(e,
|
|
906
|
-
const { decimal: n, identifier: i } =
|
|
907
|
-
return new
|
|
923
|
+
static fromChainOrSignature(e, s = 0) {
|
|
924
|
+
const { decimal: n, identifier: i } = It(e), a = k(s, n);
|
|
925
|
+
return new A({ value: a, decimal: n, identifier: i });
|
|
908
926
|
}
|
|
909
927
|
static async loadStaticAssets() {
|
|
910
928
|
return new Promise(
|
|
911
|
-
async (e,
|
|
929
|
+
async (e, s) => {
|
|
912
930
|
try {
|
|
913
931
|
const {
|
|
914
932
|
// Omit ThorchainList from import to avoid decimals conflict (TC uses 8 for all)
|
|
@@ -917,15 +935,15 @@ class w extends C {
|
|
|
917
935
|
NativeList: i,
|
|
918
936
|
...a
|
|
919
937
|
} = await import("@swapkit/tokens");
|
|
920
|
-
|
|
921
|
-
(u, { tokens: d }) => (d.forEach(({ identifier: l, chain: _, ...
|
|
922
|
-
const
|
|
923
|
-
u.set(l, { identifier: l, decimal:
|
|
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 });
|
|
924
942
|
}), u),
|
|
925
943
|
/* @__PURE__ */ new Map()
|
|
926
944
|
), e({ ok: !0 });
|
|
927
945
|
} catch (n) {
|
|
928
|
-
console.error(n),
|
|
946
|
+
console.error(n), s({
|
|
929
947
|
ok: !1,
|
|
930
948
|
error: n,
|
|
931
949
|
message: "Couldn't load static assets. Ensure you have installed @swapkit/tokens package"
|
|
@@ -935,9 +953,9 @@ class w extends C {
|
|
|
935
953
|
);
|
|
936
954
|
}
|
|
937
955
|
}
|
|
938
|
-
const
|
|
939
|
-
const t =
|
|
940
|
-
switch (
|
|
956
|
+
const ge = (r) => {
|
|
957
|
+
const t = A.fromChainOrSignature(r);
|
|
958
|
+
switch (r) {
|
|
941
959
|
case o.Bitcoin:
|
|
942
960
|
case o.Litecoin:
|
|
943
961
|
case o.BitcoinCash:
|
|
@@ -953,17 +971,17 @@ const fe = (s) => {
|
|
|
953
971
|
default:
|
|
954
972
|
return t.set(1e-8);
|
|
955
973
|
}
|
|
956
|
-
},
|
|
957
|
-
const t =
|
|
974
|
+
}, z = (r) => {
|
|
975
|
+
const t = r.slice(0, 14).includes("/"), [e, s] = r.split(".").pop().split("/"), n = r.includes(".") && !t ? r : `${o.THORChain}.${s}`, [i, a] = n.split("."), [c, u] = (t ? s : a).split("-");
|
|
958
976
|
return {
|
|
959
977
|
address: u == null ? void 0 : u.toLowerCase(),
|
|
960
978
|
chain: i,
|
|
961
|
-
isGasAsset:
|
|
979
|
+
isGasAsset: ot({ chain: i, symbol: a }),
|
|
962
980
|
isSynthetic: t,
|
|
963
981
|
symbol: (t ? `${e}/` : "") + (u ? `${c}-${(u == null ? void 0 : u.toLowerCase()) ?? ""}` : a),
|
|
964
982
|
ticker: c
|
|
965
983
|
};
|
|
966
|
-
},
|
|
984
|
+
}, se = {
|
|
967
985
|
/**
|
|
968
986
|
* Core
|
|
969
987
|
*/
|
|
@@ -1020,47 +1038,47 @@ const fe = (s) => {
|
|
|
1020
1038
|
*/
|
|
1021
1039
|
helpers_number_different_decimals: 99101
|
|
1022
1040
|
};
|
|
1023
|
-
class
|
|
1041
|
+
class mt extends Error {
|
|
1024
1042
|
constructor(t, e) {
|
|
1025
|
-
console.error(e), super(t, { cause: { code:
|
|
1043
|
+
console.error(e, { stack: e == null ? void 0 : e.stack, message: e == null ? void 0 : e.message }), super(t, { cause: { code: se[t], message: t } }), Object.setPrototypeOf(this, mt.prototype);
|
|
1026
1044
|
}
|
|
1027
1045
|
}
|
|
1028
|
-
class b extends
|
|
1046
|
+
class b extends O {
|
|
1029
1047
|
eq(t) {
|
|
1030
1048
|
return this.eqValue(t);
|
|
1031
1049
|
}
|
|
1032
1050
|
static fromBigInt(t, e) {
|
|
1033
1051
|
return new b({
|
|
1034
1052
|
decimal: e,
|
|
1035
|
-
value:
|
|
1053
|
+
value: P({ value: t, bigIntDecimal: e, decimal: e })
|
|
1036
1054
|
});
|
|
1037
1055
|
}
|
|
1038
1056
|
}
|
|
1039
1057
|
export {
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1058
|
+
A as AssetValue,
|
|
1059
|
+
O as BigIntArithmetics,
|
|
1060
|
+
Zt as RequestClient,
|
|
1061
|
+
mt as SwapKitError,
|
|
1044
1062
|
b as SwapKitNumber,
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1063
|
+
oe as assetFromString,
|
|
1064
|
+
_e as derivationPathToString,
|
|
1065
|
+
ae as filterAssets,
|
|
1066
|
+
P as formatBigIntToSafeValue,
|
|
1067
|
+
ie as gasFeeMultiplier,
|
|
1068
|
+
Ot 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
|
|
1066
1084
|
};
|