@swapkit/helpers 1.0.0-rc.26 → 1.0.0-rc.28
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.es.js +302 -308
- package/package.json +5 -5
- package/src/modules/assetValue.ts +0 -11
package/dist/index.es.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var p = (
|
|
4
|
-
if (!t.has(
|
|
1
|
+
var _t = Object.defineProperty;
|
|
2
|
+
var gt = (s, t, e) => t in s ? _t(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
|
|
3
|
+
var p = (s, t, e) => (gt(s, typeof t != "symbol" ? t + "" : t, e), e), bt = (s, t, e) => {
|
|
4
|
+
if (!t.has(s))
|
|
5
5
|
throw TypeError("Cannot " + e);
|
|
6
6
|
};
|
|
7
|
-
var T = (
|
|
8
|
-
if (t.has(
|
|
7
|
+
var T = (s, t, e) => {
|
|
8
|
+
if (t.has(s))
|
|
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(s) : t.set(s, e);
|
|
11
11
|
};
|
|
12
|
-
var f = (
|
|
13
|
-
import { FeeOption as H, BaseDecimal as d, Chain as o, EVMChainList as
|
|
14
|
-
const
|
|
12
|
+
var f = (s, t, e) => (bt(s, t, "access private method"), e);
|
|
13
|
+
import { FeeOption as H, BaseDecimal as d, Chain as o, EVMChainList as yt, ChainToRPC as wt, MemoType as g } from "@swapkit/types";
|
|
14
|
+
const At = "0x313ce567", st = async ({ chain: s, to: t }) => {
|
|
15
15
|
try {
|
|
16
|
-
const { result: e } = await
|
|
16
|
+
const { result: e } = await Qt.post(wt[s], {
|
|
17
17
|
headers: {
|
|
18
18
|
accept: "*/*",
|
|
19
19
|
"content-type": "application/json",
|
|
@@ -23,38 +23,38 @@ const vt = "0x313ce567", nt = async ({ chain: r, 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: At }, "latest"]
|
|
27
27
|
})
|
|
28
28
|
});
|
|
29
29
|
return parseInt(BigInt(e).toString());
|
|
30
30
|
} catch (e) {
|
|
31
|
-
return console.error(e), d[
|
|
31
|
+
return console.error(e), d[s];
|
|
32
32
|
}
|
|
33
|
-
},
|
|
34
|
-
if (
|
|
33
|
+
}, vt = async (s) => {
|
|
34
|
+
if (s === o.Ethereum)
|
|
35
35
|
return d.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] = s.split("-");
|
|
37
|
+
return t != null && t.startsWith("0x") ? st({ chain: o.Ethereum, to: t }) : d.ETH;
|
|
38
|
+
}, Tt = async (s) => {
|
|
39
|
+
const [, t] = s.split("-");
|
|
40
|
+
return t != null && t.startsWith("0x") ? st({ chain: o.Avalanche, to: t.toLowerCase() }) : d.AVAX;
|
|
41
|
+
}, $t = async (s) => s === o.BinanceSmartChain ? d.BSC : d.BSC, Rt = async ({ chain: s, symbol: t }) => {
|
|
42
|
+
switch (s) {
|
|
43
43
|
case o.Ethereum:
|
|
44
|
-
return
|
|
44
|
+
return vt(t);
|
|
45
45
|
case o.Avalanche:
|
|
46
|
-
return
|
|
46
|
+
return Tt(t);
|
|
47
47
|
case o.BinanceSmartChain:
|
|
48
|
-
return
|
|
48
|
+
return $t(t);
|
|
49
49
|
default:
|
|
50
|
-
return d[
|
|
50
|
+
return d[s];
|
|
51
51
|
}
|
|
52
|
-
},
|
|
52
|
+
}, se = {
|
|
53
53
|
[H.Average]: 1.2,
|
|
54
54
|
[H.Fast]: 1.5,
|
|
55
55
|
[H.Fastest]: 2
|
|
56
|
-
},
|
|
57
|
-
switch (
|
|
56
|
+
}, nt = ({ chain: s, symbol: t }) => {
|
|
57
|
+
switch (s) {
|
|
58
58
|
case o.Bitcoin:
|
|
59
59
|
case o.BitcoinCash:
|
|
60
60
|
case o.Litecoin:
|
|
@@ -62,7 +62,7 @@ const vt = "0x313ce567", nt = async ({ chain: r, to: t }) => {
|
|
|
62
62
|
case o.Binance:
|
|
63
63
|
case o.Ethereum:
|
|
64
64
|
case o.Avalanche:
|
|
65
|
-
return t ===
|
|
65
|
+
return t === s;
|
|
66
66
|
case o.Arbitrum:
|
|
67
67
|
case o.Optimism:
|
|
68
68
|
return t === "ETH";
|
|
@@ -79,18 +79,18 @@ const vt = "0x313ce567", nt = async ({ chain: r, to: t }) => {
|
|
|
79
79
|
case o.THORChain:
|
|
80
80
|
return t === "RUNE";
|
|
81
81
|
}
|
|
82
|
-
},
|
|
83
|
-
switch (
|
|
82
|
+
}, St = (s) => {
|
|
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: d[
|
|
89
|
+
return { identifier: "GAIA.ATOM", decimal: d[s] };
|
|
90
90
|
case o.THORChain:
|
|
91
|
-
return { identifier: "THOR.RUNE", decimal: d[
|
|
91
|
+
return { identifier: "THOR.RUNE", decimal: d[s] };
|
|
92
92
|
case o.BinanceSmartChain:
|
|
93
|
-
return { identifier: "BSC.BNB", decimal: d[
|
|
93
|
+
return { identifier: "BSC.BNB", decimal: d[s] };
|
|
94
94
|
case o.Maya:
|
|
95
95
|
return { identifier: "MAYA.CACAO", decimal: d.MAYA };
|
|
96
96
|
case "MAYA.MAYA":
|
|
@@ -106,12 +106,12 @@ const vt = "0x313ce567", nt = async ({ chain: r, to: t }) => {
|
|
|
106
106
|
case o.Polygon:
|
|
107
107
|
case o.Bitcoin:
|
|
108
108
|
case o.Ethereum:
|
|
109
|
-
return { identifier: `${
|
|
109
|
+
return { identifier: `${s}.${s}`, decimal: d[s] };
|
|
110
110
|
}
|
|
111
|
-
},
|
|
111
|
+
}, Ct = ({ chain: s, symbol: t }) => {
|
|
112
112
|
if (t.includes("/"))
|
|
113
113
|
return "Synth";
|
|
114
|
-
switch (
|
|
114
|
+
switch (s) {
|
|
115
115
|
case o.Bitcoin:
|
|
116
116
|
case o.BitcoinCash:
|
|
117
117
|
case o.Dogecoin:
|
|
@@ -138,134 +138,134 @@ const vt = "0x313ce567", nt = async ({ chain: r, to: t }) => {
|
|
|
138
138
|
case o.Optimism:
|
|
139
139
|
return [o.Ethereum, o.Optimism].includes(t) ? "Native" : "OPTIMISM";
|
|
140
140
|
}
|
|
141
|
-
},
|
|
141
|
+
}, ne = (s) => {
|
|
142
142
|
var c;
|
|
143
|
-
const [t, ...e] =
|
|
144
|
-
return { chain: t, symbol: n, ticker: i, synth:
|
|
145
|
-
},
|
|
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
|
+
return { chain: t, symbol: n, ticker: i, synth: r };
|
|
145
|
+
}, It = new RegExp(
|
|
146
146
|
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
|
|
147
147
|
"gmi"
|
|
148
|
-
),
|
|
149
|
-
const [t, e] =
|
|
150
|
-
if (!
|
|
148
|
+
), Et = (s) => {
|
|
149
|
+
const [t, e] = s.split(".");
|
|
150
|
+
if (!yt.includes(t))
|
|
151
151
|
return !0;
|
|
152
|
-
const [,
|
|
153
|
-
return
|
|
154
|
-
},
|
|
152
|
+
const [, r] = e.split("-");
|
|
153
|
+
return nt({ chain: t, symbol: e }) || !!r;
|
|
154
|
+
}, ie = (s) => s.filter((t) => {
|
|
155
155
|
const e = `${t.chain}.${t.symbol}`;
|
|
156
|
-
return !
|
|
157
|
-
}),
|
|
158
|
-
liquidityUnits:
|
|
156
|
+
return !It.test(e) && Et(e) && t.value !== "0";
|
|
157
|
+
}), Ot = ({
|
|
158
|
+
liquidityUnits: s,
|
|
159
159
|
poolUnits: t,
|
|
160
160
|
runeDepth: e
|
|
161
161
|
}) => {
|
|
162
|
-
const
|
|
162
|
+
const r = m(s), n = m(t), i = m(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);
|
|
163
163
|
return c.mul(a.sub(u).add(l)).div(h);
|
|
164
|
-
},
|
|
165
|
-
liquidityUnits:
|
|
164
|
+
}, Bt = ({
|
|
165
|
+
liquidityUnits: s,
|
|
166
166
|
poolUnits: t,
|
|
167
167
|
assetDepth: e
|
|
168
168
|
}) => {
|
|
169
|
-
const
|
|
169
|
+
const r = m(s), n = m(t), i = m(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);
|
|
170
170
|
return h.div(_);
|
|
171
|
-
},
|
|
172
|
-
percent:
|
|
171
|
+
}, oe = ({
|
|
172
|
+
percent: s,
|
|
173
173
|
runeDepth: t,
|
|
174
174
|
liquidityUnits: e,
|
|
175
|
-
poolUnits:
|
|
176
|
-
}) =>
|
|
177
|
-
percent:
|
|
175
|
+
poolUnits: r
|
|
176
|
+
}) => Ot({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), ae = ({
|
|
177
|
+
percent: s,
|
|
178
178
|
assetDepth: t,
|
|
179
179
|
liquidityUnits: e,
|
|
180
|
-
poolUnits:
|
|
181
|
-
}) =>
|
|
182
|
-
liquidityUnits:
|
|
180
|
+
poolUnits: r
|
|
181
|
+
}) => Bt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), m = (s) => b.fromBigInt(BigInt(s), d.THOR), Mt = ({
|
|
182
|
+
liquidityUnits: s,
|
|
183
183
|
poolUnits: t,
|
|
184
184
|
runeDepth: e,
|
|
185
|
-
assetDepth:
|
|
185
|
+
assetDepth: r
|
|
186
186
|
}) => ({
|
|
187
|
-
assetAmount: m(
|
|
188
|
-
runeAmount: m(e).mul(
|
|
189
|
-
}),
|
|
190
|
-
liquidityUnits:
|
|
187
|
+
assetAmount: m(r).mul(s).div(t),
|
|
188
|
+
runeAmount: m(e).mul(s).div(t)
|
|
189
|
+
}), ce = ({
|
|
190
|
+
liquidityUnits: s,
|
|
191
191
|
poolUnits: t,
|
|
192
192
|
runeDepth: e,
|
|
193
|
-
assetDepth:
|
|
193
|
+
assetDepth: r,
|
|
194
194
|
percent: n
|
|
195
195
|
}) => Object.fromEntries(
|
|
196
|
-
Object.entries(
|
|
196
|
+
Object.entries(Mt({ liquidityUnits: s, poolUnits: t, runeDepth: e, assetDepth: r })).map(
|
|
197
197
|
([i, c]) => [i, c.mul(n)]
|
|
198
198
|
)
|
|
199
|
-
),
|
|
200
|
-
runeDepth:
|
|
199
|
+
), ue = ({
|
|
200
|
+
runeDepth: s,
|
|
201
201
|
poolUnits: t,
|
|
202
202
|
assetDepth: e,
|
|
203
|
-
liquidityUnits:
|
|
203
|
+
liquidityUnits: r,
|
|
204
204
|
runeAmount: n,
|
|
205
205
|
assetAmount: i
|
|
206
206
|
}) => {
|
|
207
|
-
const c = new b({ value:
|
|
207
|
+
const c = new b({ value: s, decimal: 8 }), a = new b({ value: e, decimal: 8 }), u = new b({ value: t, decimal: 8 }), l = new b({ value: n, decimal: 8 }), h = new b({ value: i, decimal: 8 }), _ = l.mul(a), A = h.mul(c), N = l.mul(h), dt = c.mul(a), mt = u.mul(_.add(A.add(N.mul(2)))), pt = _.add(A.add(dt.mul(2))), J = mt.div(pt), j = m(r).add(J);
|
|
208
208
|
if (J.getBaseValue("number") === 0)
|
|
209
209
|
return j.div(u).getBaseValue("number");
|
|
210
|
-
const
|
|
211
|
-
return j.div(
|
|
212
|
-
},
|
|
213
|
-
runeAmount:
|
|
210
|
+
const ft = u.add(j);
|
|
211
|
+
return j.div(ft).getBaseValue("number");
|
|
212
|
+
}, le = ({
|
|
213
|
+
runeAmount: s,
|
|
214
214
|
assetAmount: t,
|
|
215
215
|
runeDepth: e,
|
|
216
|
-
assetDepth:
|
|
216
|
+
assetDepth: r
|
|
217
217
|
}) => {
|
|
218
|
-
if (
|
|
218
|
+
if (s === "0" || t === "0" || e === "0" || r === "0")
|
|
219
219
|
return 0;
|
|
220
|
-
const n = m(e), i = m(
|
|
220
|
+
const n = m(e), i = m(r), c = m(t), a = m(s), u = c.mul(n).sub(i.mul(a)), l = i.mul(a).add(n.mul(i));
|
|
221
221
|
return Math.abs(u.div(l).getBaseValue("number"));
|
|
222
|
-
},
|
|
223
|
-
symbol:
|
|
222
|
+
}, Vt = ({
|
|
223
|
+
symbol: s,
|
|
224
224
|
ticker: t,
|
|
225
225
|
chain: e
|
|
226
|
-
}) => e === "ETH" && t !== "ETH" ? `${t}-${
|
|
227
|
-
switch (
|
|
226
|
+
}) => e === "ETH" && t !== "ETH" ? `${t}-${s.slice(-3)}` : s, he = (s, t) => {
|
|
227
|
+
switch (s) {
|
|
228
228
|
case g.LEAVE:
|
|
229
229
|
case g.BOND: {
|
|
230
230
|
const { address: e } = t;
|
|
231
|
-
return `${
|
|
231
|
+
return `${s}:${e}`;
|
|
232
232
|
}
|
|
233
233
|
case g.UNBOND: {
|
|
234
|
-
const { address: e, unbondAmount:
|
|
235
|
-
return `${
|
|
234
|
+
const { address: e, unbondAmount: r } = t;
|
|
235
|
+
return `${s}:${e}:${r * 10 ** 8}`;
|
|
236
236
|
}
|
|
237
237
|
case g.THORNAME_REGISTER: {
|
|
238
|
-
const { name: e, chain:
|
|
239
|
-
return `${
|
|
238
|
+
const { name: e, chain: r, address: n, owner: i } = t;
|
|
239
|
+
return `${s}:${e}:${r}:${n}${i ? `:${i}` : ""}`;
|
|
240
240
|
}
|
|
241
241
|
case g.DEPOSIT: {
|
|
242
|
-
const { chain: e, symbol:
|
|
243
|
-
return i ? `${
|
|
242
|
+
const { chain: e, symbol: r, address: n, singleSide: i } = t;
|
|
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:
|
|
247
|
-
return `${
|
|
246
|
+
const { chain: e, ticker: r, symbol: n, basisPoints: i, targetAssetString: c, singleSide: a } = t, u = !a && c ? `:${c}` : "", l = Vt({ chain: e, symbol: n, ticker: r });
|
|
247
|
+
return `${s}:${e}${a ? "/" : "."}${l}:${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: r } = t;
|
|
252
|
+
return `${s}:${e}:${r}`;
|
|
253
253
|
}
|
|
254
254
|
default:
|
|
255
255
|
return "";
|
|
256
256
|
}
|
|
257
|
-
},
|
|
258
|
-
if (
|
|
257
|
+
}, de = (s) => {
|
|
258
|
+
if (s < 0)
|
|
259
259
|
throw new Error("Invalid number of year");
|
|
260
|
-
return 10 +
|
|
261
|
-
},
|
|
262
|
-
if (
|
|
260
|
+
return 10 + s;
|
|
261
|
+
}, me = (s) => {
|
|
262
|
+
if (s.length > 30)
|
|
263
263
|
return !1;
|
|
264
264
|
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
265
|
-
return !!
|
|
266
|
-
},
|
|
265
|
+
return !!s.match(t);
|
|
266
|
+
}, pe = ([s, t, e, r, n]) => `${s}'/${t}'/${e}'/${r}${typeof n != "number" ? "" : `/${n}`}`;
|
|
267
267
|
class K extends Error {
|
|
268
|
-
constructor(t, e,
|
|
268
|
+
constructor(t, e, r) {
|
|
269
269
|
const n = t.status || t.status === 0 ? t.status : "", i = t.statusText || "", c = `${n} ${i}`.trim(), a = c ? `status code ${c}` : "an unknown error";
|
|
270
270
|
super(`Request failed with ${a}`), Object.defineProperty(this, "response", {
|
|
271
271
|
enumerable: !0,
|
|
@@ -282,10 +282,10 @@ class K 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 = r;
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
|
-
class
|
|
288
|
+
class it 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 ot extends Error {
|
|
|
295
295
|
}), this.name = "TimeoutError", this.request = t;
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
|
-
const M = (
|
|
299
|
-
for (const t of
|
|
298
|
+
const M = (s) => s !== null && typeof s == "object", O = (...s) => {
|
|
299
|
+
for (const t of s)
|
|
300
300
|
if ((!M(t) || Array.isArray(t)) && t !== void 0)
|
|
301
301
|
throw new TypeError("The `options` argument must be an object");
|
|
302
|
-
return Y({}, ...
|
|
303
|
-
},
|
|
304
|
-
const e = new globalThis.Headers(
|
|
302
|
+
return Y({}, ...s);
|
|
303
|
+
}, ot = (s = {}, t = {}) => {
|
|
304
|
+
const e = new globalThis.Headers(s), r = t instanceof globalThis.Headers, n = new globalThis.Headers(t);
|
|
305
305
|
for (const [i, c] of n.entries())
|
|
306
|
-
|
|
306
|
+
r && c === "undefined" || c === void 0 ? e.delete(i) : e.set(i, c);
|
|
307
307
|
return e;
|
|
308
|
-
}, Y = (...
|
|
308
|
+
}, Y = (...s) => {
|
|
309
309
|
let t = {}, e = {};
|
|
310
|
-
for (const
|
|
311
|
-
if (Array.isArray(
|
|
312
|
-
Array.isArray(t) || (t = []), t = [...t, ...
|
|
313
|
-
else if (M(
|
|
314
|
-
for (let [n, i] of Object.entries(
|
|
310
|
+
for (const r of s)
|
|
311
|
+
if (Array.isArray(r))
|
|
312
|
+
Array.isArray(t) || (t = []), t = [...t, ...r];
|
|
313
|
+
else if (M(r)) {
|
|
314
|
+
for (let [n, i] of Object.entries(r))
|
|
315
315
|
M(i) && n in t && (i = Y(t[n], i)), t = { ...t, [n]: i };
|
|
316
|
-
M(
|
|
316
|
+
M(r.headers) && (e = ot(e, r.headers), t.headers = e);
|
|
317
317
|
}
|
|
318
318
|
return t;
|
|
319
|
-
},
|
|
320
|
-
let
|
|
321
|
-
const e = typeof globalThis.ReadableStream == "function",
|
|
322
|
-
return e &&
|
|
319
|
+
}, qt = (() => {
|
|
320
|
+
let s = !1, t = !1;
|
|
321
|
+
const e = typeof globalThis.ReadableStream == "function", r = typeof globalThis.Request == "function";
|
|
322
|
+
return e && r && (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 s = !0, "half";
|
|
328
328
|
}
|
|
329
|
-
}).headers.has("Content-Type")),
|
|
330
|
-
})(),
|
|
329
|
+
}).headers.has("Content-Type")), s && !t;
|
|
330
|
+
})(), xt = typeof globalThis.AbortController == "function", kt = typeof globalThis.ReadableStream == "function", Pt = typeof globalThis.FormData == "function", at = ["get", "post", "put", "patch", "head", "delete"], Nt = {
|
|
331
331
|
json: "application/json",
|
|
332
332
|
text: "text/*",
|
|
333
333
|
formData: "multipart/form-data",
|
|
334
334
|
arrayBuffer: "*/*",
|
|
335
335
|
blob: "*/*"
|
|
336
|
-
}, L = 2147483647,
|
|
336
|
+
}, L = 2147483647, ct = Symbol("stop"), jt = {
|
|
337
337
|
json: !0,
|
|
338
338
|
parseJson: !0,
|
|
339
339
|
searchParams: !0,
|
|
@@ -344,7 +344,7 @@ const M = (r) => r !== null && typeof r == "object", O = (...r) => {
|
|
|
344
344
|
throwHttpErrors: !0,
|
|
345
345
|
onDownloadProgress: !0,
|
|
346
346
|
fetch: !0
|
|
347
|
-
},
|
|
347
|
+
}, Ht = {
|
|
348
348
|
method: !0,
|
|
349
349
|
headers: !0,
|
|
350
350
|
body: !0,
|
|
@@ -360,86 +360,86 @@ const M = (r) => r !== null && typeof r == "object", O = (...r) => {
|
|
|
360
360
|
window: !0,
|
|
361
361
|
dispatcher: !0,
|
|
362
362
|
duplex: !0
|
|
363
|
-
},
|
|
363
|
+
}, Lt = (s) => at.includes(s) ? s.toUpperCase() : s, Dt = ["get", "put", "head", "delete", "options", "trace"], Ut = [408, 413, 429, 500, 502, 503, 504], ut = [413, 429, 503], Q = {
|
|
364
364
|
limit: 2,
|
|
365
|
-
methods:
|
|
366
|
-
statusCodes:
|
|
367
|
-
afterStatusCodes:
|
|
365
|
+
methods: Dt,
|
|
366
|
+
statusCodes: Ut,
|
|
367
|
+
afterStatusCodes: ut,
|
|
368
368
|
maxRetryAfter: Number.POSITIVE_INFINITY,
|
|
369
369
|
backoffLimit: Number.POSITIVE_INFINITY,
|
|
370
|
-
delay: (
|
|
371
|
-
},
|
|
372
|
-
if (typeof
|
|
370
|
+
delay: (s) => 0.3 * 2 ** (s - 1) * 1e3
|
|
371
|
+
}, Ft = (s = {}) => {
|
|
372
|
+
if (typeof s == "number")
|
|
373
373
|
return {
|
|
374
374
|
...Q,
|
|
375
|
-
limit:
|
|
375
|
+
limit: s
|
|
376
376
|
};
|
|
377
|
-
if (
|
|
377
|
+
if (s.methods && !Array.isArray(s.methods))
|
|
378
378
|
throw new Error("retry.methods must be an array");
|
|
379
|
-
if (
|
|
379
|
+
if (s.statusCodes && !Array.isArray(s.statusCodes))
|
|
380
380
|
throw new Error("retry.statusCodes must be an array");
|
|
381
381
|
return {
|
|
382
382
|
...Q,
|
|
383
|
-
...
|
|
384
|
-
afterStatusCodes:
|
|
383
|
+
...s,
|
|
384
|
+
afterStatusCodes: ut
|
|
385
385
|
};
|
|
386
386
|
};
|
|
387
|
-
async function
|
|
387
|
+
async function Wt(s, t, e, r) {
|
|
388
388
|
return new Promise((n, i) => {
|
|
389
389
|
const c = setTimeout(() => {
|
|
390
|
-
e && e.abort(), i(new
|
|
391
|
-
},
|
|
392
|
-
|
|
390
|
+
e && e.abort(), i(new it(s));
|
|
391
|
+
}, r.timeout);
|
|
392
|
+
r.fetch(s, t).then(n).catch(i).then(() => {
|
|
393
393
|
clearTimeout(c);
|
|
394
394
|
});
|
|
395
395
|
});
|
|
396
396
|
}
|
|
397
|
-
async function
|
|
398
|
-
return new Promise((e,
|
|
397
|
+
async function Gt(s, { signal: t }) {
|
|
398
|
+
return new Promise((e, r) => {
|
|
399
399
|
t && (t.throwIfAborted(), t.addEventListener("abort", n, { once: !0 }));
|
|
400
400
|
function n() {
|
|
401
|
-
clearTimeout(i),
|
|
401
|
+
clearTimeout(i), r(t.reason);
|
|
402
402
|
}
|
|
403
403
|
const i = setTimeout(() => {
|
|
404
404
|
t == null || t.removeEventListener("abort", n), e();
|
|
405
|
-
},
|
|
405
|
+
}, s);
|
|
406
406
|
});
|
|
407
407
|
}
|
|
408
|
-
const
|
|
408
|
+
const Yt = (s, t) => {
|
|
409
409
|
const e = {};
|
|
410
|
-
for (const
|
|
411
|
-
!(
|
|
410
|
+
for (const r in t)
|
|
411
|
+
!(r in Ht) && !(r in jt) && !(r in s) && (e[r] = t[r]);
|
|
412
412
|
return e;
|
|
413
413
|
};
|
|
414
414
|
class x {
|
|
415
415
|
static create(t, e) {
|
|
416
|
-
const
|
|
417
|
-
if (typeof
|
|
416
|
+
const r = new x(t, e), n = async () => {
|
|
417
|
+
if (typeof r._options.timeout == "number" && r._options.timeout > L)
|
|
418
418
|
throw new RangeError(`The \`timeout\` option cannot be greater than ${L}`);
|
|
419
419
|
await Promise.resolve();
|
|
420
|
-
let a = await
|
|
421
|
-
for (const u of
|
|
422
|
-
const l = await u(
|
|
420
|
+
let a = await r._fetch();
|
|
421
|
+
for (const u of r._options.hooks.afterResponse) {
|
|
422
|
+
const l = await u(r.request, r._options, r._decorateResponse(a.clone()));
|
|
423
423
|
l instanceof globalThis.Response && (a = l);
|
|
424
424
|
}
|
|
425
|
-
if (
|
|
426
|
-
let u = new K(a,
|
|
427
|
-
for (const l of
|
|
425
|
+
if (r._decorateResponse(a), !a.ok && r._options.throwHttpErrors) {
|
|
426
|
+
let u = new K(a, r.request, r._options);
|
|
427
|
+
for (const l of r._options.hooks.beforeError)
|
|
428
428
|
u = await l(u);
|
|
429
429
|
throw u;
|
|
430
430
|
}
|
|
431
|
-
if (
|
|
432
|
-
if (typeof
|
|
431
|
+
if (r._options.onDownloadProgress) {
|
|
432
|
+
if (typeof r._options.onDownloadProgress != "function")
|
|
433
433
|
throw new TypeError("The `onDownloadProgress` option must be a function");
|
|
434
|
-
if (!
|
|
434
|
+
if (!kt)
|
|
435
435
|
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
|
|
436
|
-
return
|
|
436
|
+
return r._stream(a.clone(), r._options.onDownloadProgress);
|
|
437
437
|
}
|
|
438
438
|
return a;
|
|
439
|
-
}, c =
|
|
440
|
-
for (const [a, u] of Object.entries(
|
|
439
|
+
}, c = r._options.retry.methods.includes(r.request.method.toLowerCase()) ? r._retry(n) : n();
|
|
440
|
+
for (const [a, u] of Object.entries(Nt))
|
|
441
441
|
c[a] = async () => {
|
|
442
|
-
|
|
442
|
+
r.request.headers.set("accept", r.request.headers.get("accept") || u);
|
|
443
443
|
const h = (await c).clone();
|
|
444
444
|
if (a === "json") {
|
|
445
445
|
if (h.status === 204 || (await h.clone().arrayBuffer()).byteLength === 0)
|
|
@@ -482,17 +482,17 @@ class x {
|
|
|
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:
|
|
485
|
+
headers: ot(this._input.headers, e.headers),
|
|
486
486
|
hooks: Y({
|
|
487
487
|
beforeRequest: [],
|
|
488
488
|
beforeRetry: [],
|
|
489
489
|
beforeError: [],
|
|
490
490
|
afterResponse: []
|
|
491
491
|
}, e.hooks),
|
|
492
|
-
method:
|
|
492
|
+
method: Lt(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: Ft(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 x {
|
|
|
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 (xt) {
|
|
507
507
|
if (this.abortController = new globalThis.AbortController(), this._options.signal) {
|
|
508
|
-
const
|
|
508
|
+
const r = this._options.signal;
|
|
509
509
|
this._options.signal.addEventListener("abort", () => {
|
|
510
|
-
this.abortController.abort(
|
|
510
|
+
this.abortController.abort(r.reason);
|
|
511
511
|
});
|
|
512
512
|
}
|
|
513
513
|
this._options.signal = this.abortController.signal;
|
|
514
514
|
}
|
|
515
|
-
if (
|
|
515
|
+
if (qt && (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
|
+
(Pt && 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
|
|
522
|
+
if (this._retryCount++, this._retryCount < this._options.retry.limit && !(t instanceof it)) {
|
|
523
523
|
if (t instanceof K) {
|
|
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 r = t.response.headers.get("Retry-After");
|
|
527
|
+
if (r && this._options.retry.afterStatusCodes.includes(t.response.status)) {
|
|
528
|
+
let n = Number(r);
|
|
529
|
+
return Number.isNaN(n) ? n = Date.parse(r) - 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 x {
|
|
|
543
543
|
try {
|
|
544
544
|
return await t();
|
|
545
545
|
} catch (e) {
|
|
546
|
-
const
|
|
547
|
-
if (
|
|
548
|
-
await
|
|
546
|
+
const r = Math.min(this._calculateRetryDelay(e), L);
|
|
547
|
+
if (r !== 0 && this._retryCount > 0) {
|
|
548
|
+
await Gt(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
|
+
}) === ct)
|
|
556
556
|
return;
|
|
557
557
|
return this._retry(t);
|
|
558
558
|
}
|
|
@@ -561,29 +561,29 @@ class x {
|
|
|
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 r = await e(this.request, this._options);
|
|
565
|
+
if (r instanceof Request) {
|
|
566
|
+
this.request = r;
|
|
567
567
|
break;
|
|
568
568
|
}
|
|
569
|
-
if (
|
|
570
|
-
return
|
|
569
|
+
if (r instanceof Response)
|
|
570
|
+
return r;
|
|
571
571
|
}
|
|
572
|
-
const t =
|
|
573
|
-
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) :
|
|
572
|
+
const t = Yt(this.request, this._options);
|
|
573
|
+
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Wt(this.request.clone(), t, this.abortController, this._options);
|
|
574
574
|
}
|
|
575
575
|
/* istanbul ignore next */
|
|
576
576
|
_stream(t, e) {
|
|
577
|
-
const
|
|
577
|
+
const r = 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: r, 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 c = t.body.getReader();
|
|
586
|
-
e && e({ percent: 0, transferredBytes: 0, totalBytes:
|
|
586
|
+
e && e({ percent: 0, transferredBytes: 0, totalBytes: r }, new Uint8Array());
|
|
587
587
|
async function a() {
|
|
588
588
|
const { done: u, value: l } = await c.read();
|
|
589
589
|
if (u) {
|
|
@@ -592,8 +592,8 @@ class x {
|
|
|
592
592
|
}
|
|
593
593
|
if (e) {
|
|
594
594
|
n += l.byteLength;
|
|
595
|
-
const h =
|
|
596
|
-
e({ percent: h, transferredBytes: n, totalBytes:
|
|
595
|
+
const h = r === 0 ? 0 : n / r;
|
|
596
|
+
e({ percent: h, transferredBytes: n, totalBytes: r }, l);
|
|
597
597
|
}
|
|
598
598
|
i.enqueue(l), await a();
|
|
599
599
|
}
|
|
@@ -607,42 +607,42 @@ class x {
|
|
|
607
607
|
}
|
|
608
608
|
}
|
|
609
609
|
/*! MIT License © Sindre Sorhus */
|
|
610
|
-
const D = (
|
|
611
|
-
const t = (e,
|
|
612
|
-
for (const e of
|
|
613
|
-
t[e] = (
|
|
614
|
-
return t.create = (e) => D(O(e)), t.extend = (e) => D(O(
|
|
615
|
-
},
|
|
616
|
-
get: (
|
|
617
|
-
post: (
|
|
618
|
-
}, Z = Object.values(o),
|
|
619
|
-
const t =
|
|
610
|
+
const D = (s) => {
|
|
611
|
+
const t = (e, r) => x.create(e, O(s, r));
|
|
612
|
+
for (const e of at)
|
|
613
|
+
t[e] = (r, n) => x.create(r, O(s, n, { method: e }));
|
|
614
|
+
return t.create = (e) => D(O(e)), t.extend = (e) => D(O(s, e)), t.stop = ct, t;
|
|
615
|
+
}, zt = D(), Jt = zt, Kt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, X = Jt.create({ headers: Kt }), Qt = {
|
|
616
|
+
get: (s, t) => X.get(s, t).json(),
|
|
617
|
+
post: (s, t) => X.post(s, t).json()
|
|
618
|
+
}, Z = Object.values(o), Xt = (s = "") => {
|
|
619
|
+
const t = s.toUpperCase(), [e] = t.split(".");
|
|
620
620
|
if (Z.includes(e))
|
|
621
621
|
return !0;
|
|
622
|
-
const [
|
|
623
|
-
if (Z.includes(
|
|
622
|
+
const [r] = t.split("/");
|
|
623
|
+
if (Z.includes(r))
|
|
624
624
|
return !0;
|
|
625
625
|
throw new Error(
|
|
626
|
-
`Invalid identifier: ${
|
|
626
|
+
`Invalid identifier: ${s}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
627
627
|
);
|
|
628
|
-
}, S = 8, v = (
|
|
628
|
+
}, S = 8, v = (s) => 10n ** BigInt(s), $ = (s) => Math.log10(parseFloat(s.toString()));
|
|
629
629
|
function k({
|
|
630
|
-
value:
|
|
630
|
+
value: s,
|
|
631
631
|
bigIntDecimal: t = S,
|
|
632
632
|
decimal: e = S
|
|
633
633
|
}) {
|
|
634
|
-
const
|
|
635
|
-
let n =
|
|
634
|
+
const r = s < 0n;
|
|
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
638
|
const c = n.length - e;
|
|
639
639
|
let a = n.slice(-e);
|
|
640
|
-
return parseInt(a[t]) >= 5 ? a = `${a.substring(0, t - 1)}${(parseInt(a[t - 1]) + 1).toString()}` : a = a.substring(0, t), `${
|
|
640
|
+
return parseInt(a[t]) >= 5 ? a = `${a.substring(0, t - 1)}${(parseInt(a[t - 1]) + 1).toString()}` : a = a.substring(0, t), `${r ? "-" : ""}${n.slice(0, c)}.${a}`.replace(
|
|
641
641
|
/\.?0*$/,
|
|
642
642
|
""
|
|
643
643
|
);
|
|
644
644
|
}
|
|
645
|
-
var w, R, I, U, P,
|
|
645
|
+
var w, R, I, U, P, lt, E, F;
|
|
646
646
|
const z = class z {
|
|
647
647
|
constructor(t) {
|
|
648
648
|
T(this, w);
|
|
@@ -666,11 +666,11 @@ const z = class z {
|
|
|
666
666
|
static shiftDecimals({
|
|
667
667
|
value: t,
|
|
668
668
|
from: e,
|
|
669
|
-
to:
|
|
669
|
+
to: r
|
|
670
670
|
}) {
|
|
671
671
|
return this.fromBigInt(
|
|
672
|
-
t.getBaseValue("bigint") * v(
|
|
673
|
-
|
|
672
|
+
t.getBaseValue("bigint") * v(r) / v(e),
|
|
673
|
+
r
|
|
674
674
|
);
|
|
675
675
|
}
|
|
676
676
|
set(t) {
|
|
@@ -718,35 +718,35 @@ const z = class z {
|
|
|
718
718
|
}
|
|
719
719
|
}
|
|
720
720
|
getBaseValue(t) {
|
|
721
|
-
const e = this.decimalMultiplier / v(this.decimal || d.THOR),
|
|
721
|
+
const e = this.decimalMultiplier / v(this.decimal || d.THOR), r = this.bigIntValue / e;
|
|
722
722
|
switch (t) {
|
|
723
723
|
case "number":
|
|
724
|
-
return Number(
|
|
724
|
+
return Number(r);
|
|
725
725
|
case "string":
|
|
726
|
-
return
|
|
726
|
+
return r.toString();
|
|
727
727
|
default:
|
|
728
|
-
return
|
|
728
|
+
return r;
|
|
729
729
|
}
|
|
730
730
|
}
|
|
731
731
|
getBigIntValue(t, e) {
|
|
732
732
|
if (!e && typeof t == "object")
|
|
733
733
|
return t.bigIntValue;
|
|
734
|
-
const
|
|
734
|
+
const r = V(t), n = B(r);
|
|
735
735
|
return n === "0" || n === "undefined" ? 0n : f(this, E, F).call(this, n, e);
|
|
736
736
|
}
|
|
737
737
|
formatBigIntToSafeValue(t, e) {
|
|
738
|
-
const
|
|
739
|
-
|
|
738
|
+
const r = e || this.decimal || S, n = Math.max(
|
|
739
|
+
r,
|
|
740
740
|
$(this.decimalMultiplier)
|
|
741
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
742
|
let h = u.slice(-n);
|
|
743
|
-
return parseInt(h[
|
|
743
|
+
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(
|
|
744
744
|
0,
|
|
745
745
|
l
|
|
746
746
|
)}.${h}`.replace(/\.?0*$/, "");
|
|
747
747
|
}
|
|
748
748
|
toSignificant(t = 6) {
|
|
749
|
-
const [e,
|
|
749
|
+
const [e, r] = this.getValue("string").split("."), n = e || "", i = r || "";
|
|
750
750
|
if ((parseInt(n) ? n.length + i.length : i.length) <= t)
|
|
751
751
|
return this.getValue("string");
|
|
752
752
|
if (n.length >= t)
|
|
@@ -763,7 +763,7 @@ const z = class z {
|
|
|
763
763
|
)}`;
|
|
764
764
|
}
|
|
765
765
|
toFixed(t = 6) {
|
|
766
|
-
const [e,
|
|
766
|
+
const [e, r] = this.getValue("string").split("."), n = e || "", i = r || "";
|
|
767
767
|
if (parseInt(n))
|
|
768
768
|
return `${n}.${i.slice(0, t)}`.padEnd(t, "0");
|
|
769
769
|
const c = parseInt(i), a = `${c}`.slice(0, t);
|
|
@@ -773,7 +773,7 @@ const z = class z {
|
|
|
773
773
|
)}`;
|
|
774
774
|
}
|
|
775
775
|
toAbbreviation(t = 2) {
|
|
776
|
-
const e = this.getValue("number"),
|
|
776
|
+
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
777
|
if (!i)
|
|
778
778
|
return this.getValue("string");
|
|
779
779
|
const c = 10 ** (n * 3);
|
|
@@ -781,18 +781,18 @@ const z = class z {
|
|
|
781
781
|
}
|
|
782
782
|
toCurrency(t = "$", {
|
|
783
783
|
currencyPosition: e = "start",
|
|
784
|
-
decimal:
|
|
784
|
+
decimal: r = 2,
|
|
785
785
|
decimalSeparator: n = ".",
|
|
786
786
|
thousandSeparator: i = ","
|
|
787
787
|
} = {}) {
|
|
788
|
-
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}${u ? `${n}${u.slice(0,
|
|
788
|
+
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}${u ? `${n}${u.slice(0, r)}` : ""}`;
|
|
789
789
|
return `${e === "start" ? t : ""}${h}${e === "end" ? t : ""}`;
|
|
790
790
|
}
|
|
791
791
|
};
|
|
792
792
|
w = new WeakSet(), R = function(t, ...e) {
|
|
793
|
-
const
|
|
793
|
+
const r = f(this, P, lt).call(this, this, ...e), n = v(r), i = e.reduce(
|
|
794
794
|
(a, u) => {
|
|
795
|
-
const l = this.getBigIntValue(u,
|
|
795
|
+
const l = this.getBigIntValue(u, r);
|
|
796
796
|
switch (t) {
|
|
797
797
|
case "add":
|
|
798
798
|
return a + l;
|
|
@@ -812,106 +812,100 @@ w = new WeakSet(), R = function(t, ...e) {
|
|
|
812
812
|
//normalize is to precision multiplier base
|
|
813
813
|
this.bigIntValue * n / this.decimalMultiplier
|
|
814
814
|
), c = k({
|
|
815
|
-
bigIntDecimal:
|
|
816
|
-
decimal: Math.max(
|
|
815
|
+
bigIntDecimal: r,
|
|
816
|
+
decimal: Math.max(r, $(this.decimalMultiplier)),
|
|
817
817
|
value: i
|
|
818
818
|
});
|
|
819
819
|
return new this.constructor({ decimal: this.decimal, value: c, identifier: this.toString() });
|
|
820
820
|
}, I = new WeakSet(), U = function(t) {
|
|
821
821
|
const e = B(t) || "0";
|
|
822
822
|
this.bigIntValue = f(this, E, F).call(this, e);
|
|
823
|
-
}, P = new WeakSet(),
|
|
823
|
+
}, P = new WeakSet(), lt = function(...t) {
|
|
824
824
|
const e = t.map(
|
|
825
|
-
(
|
|
825
|
+
(r) => typeof r == "object" ? r.decimal || $(r.decimalMultiplier) : tt(B(r))
|
|
826
826
|
).filter(Boolean);
|
|
827
827
|
return Math.max(...e, S);
|
|
828
828
|
}, E = new WeakSet(), F = function(t, e) {
|
|
829
|
-
const
|
|
829
|
+
const r = e ? v(e) : this.decimalMultiplier, n = $(r), [i = "", c = ""] = t.split(".");
|
|
830
830
|
return BigInt(`${i}${c.padEnd(n, "0")}`);
|
|
831
831
|
};
|
|
832
832
|
let C = z;
|
|
833
|
-
const
|
|
833
|
+
const Zt = Intl.NumberFormat("fullwide", {
|
|
834
834
|
useGrouping: !1,
|
|
835
835
|
maximumFractionDigits: 20
|
|
836
836
|
});
|
|
837
|
-
function B(
|
|
838
|
-
const e = `${typeof
|
|
837
|
+
function B(s) {
|
|
838
|
+
const e = `${typeof s == "number" ? Zt.format(s) : V(s)}`.replaceAll(",", ".").split(".");
|
|
839
839
|
return e.length > 1 ? `${e.slice(0, -1).join("")}.${e.at(-1)}` : e[0];
|
|
840
840
|
}
|
|
841
|
-
function tt(
|
|
841
|
+
function tt(s) {
|
|
842
842
|
var e;
|
|
843
|
-
const t = ((e =
|
|
843
|
+
const t = ((e = s.split(".")[1]) == null ? void 0 : e.length) || 0;
|
|
844
844
|
return Math.max(t, S);
|
|
845
845
|
}
|
|
846
|
-
function V(
|
|
847
|
-
return typeof
|
|
846
|
+
function V(s) {
|
|
847
|
+
return typeof s == "object" ? "getValue" in s ? s.getValue("string") : s.value : s;
|
|
848
848
|
}
|
|
849
|
-
const q = (
|
|
849
|
+
const q = (s, t) => typeof s == "bigint" ? k({ value: s, bigIntDecimal: t, decimal: t }) : s;
|
|
850
850
|
let W;
|
|
851
|
-
const et = (
|
|
851
|
+
const et = (s) => {
|
|
852
852
|
if (!W)
|
|
853
853
|
throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");
|
|
854
|
-
return W.get(
|
|
855
|
-
},
|
|
856
|
-
|
|
857
|
-
const e = await
|
|
858
|
-
return new y({ decimal: e, value:
|
|
859
|
-
}
|
|
854
|
+
return W.get(s.toUpperCase()) || { decimal: d.THOR, identifier: "" };
|
|
855
|
+
}, rt = async (s, t = 0) => {
|
|
856
|
+
Xt(s);
|
|
857
|
+
const e = await Rt(G(s)), r = q(t, e);
|
|
858
|
+
return new y({ decimal: e, value: r, identifier: s });
|
|
859
|
+
};
|
|
860
860
|
class y extends C {
|
|
861
861
|
constructor(e) {
|
|
862
|
-
const
|
|
863
|
-
if (n)
|
|
864
|
-
return n.set(e.value);
|
|
862
|
+
const r = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`;
|
|
865
863
|
super(
|
|
866
864
|
e.value instanceof C ? e.value : { decimal: e.decimal, value: e.value }
|
|
867
865
|
);
|
|
868
866
|
p(this, "address");
|
|
869
867
|
p(this, "isSynthetic", !1);
|
|
870
868
|
p(this, "isGasAsset", !1);
|
|
871
|
-
// @ts-expect-error cache is false positive on that case
|
|
872
869
|
p(this, "chain");
|
|
873
|
-
// @ts-expect-error cache is false positive on that case
|
|
874
870
|
p(this, "symbol");
|
|
875
|
-
// @ts-expect-error cache is false positive on that case
|
|
876
871
|
p(this, "ticker");
|
|
877
|
-
// @ts-expect-error cache is false positive on that case
|
|
878
872
|
p(this, "type");
|
|
879
|
-
const
|
|
880
|
-
this.type =
|
|
873
|
+
const n = G(r);
|
|
874
|
+
this.type = Ct(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;
|
|
881
875
|
}
|
|
882
876
|
toString(e = !1) {
|
|
883
|
-
const
|
|
884
|
-
return e ?
|
|
877
|
+
const r = this.isSynthetic ? this.symbol.split("-")[0] : this.ticker;
|
|
878
|
+
return e ? r : (
|
|
885
879
|
// THOR.ETH/ETH | ETH.USDT-0x1234567890
|
|
886
880
|
`${this.chain}.${this.symbol}`
|
|
887
881
|
);
|
|
888
882
|
}
|
|
889
|
-
eq({ chain: e, symbol:
|
|
890
|
-
return this.chain === e && this.symbol ===
|
|
883
|
+
eq({ chain: e, symbol: r }) {
|
|
884
|
+
return this.chain === e && this.symbol === r;
|
|
891
885
|
}
|
|
892
|
-
static async fromString(e,
|
|
893
|
-
return
|
|
886
|
+
static async fromString(e, r = 0) {
|
|
887
|
+
return rt(e, r);
|
|
894
888
|
}
|
|
895
|
-
static fromStringSync(e,
|
|
889
|
+
static fromStringSync(e, r = 0) {
|
|
896
890
|
const { isSynthetic: n } = G(e), { decimal: i, identifier: c } = et(
|
|
897
891
|
e
|
|
898
|
-
), a = q(
|
|
892
|
+
), a = q(r, i);
|
|
899
893
|
return c ? new y({ decimal: i, identifier: c, value: a }) : n ? new y({ decimal: 8, identifier: e, value: a }) : void 0;
|
|
900
894
|
}
|
|
901
|
-
static async fromIdentifier(e,
|
|
902
|
-
return
|
|
895
|
+
static async fromIdentifier(e, r = 0) {
|
|
896
|
+
return rt(e, r);
|
|
903
897
|
}
|
|
904
|
-
static fromIdentifierSync(e,
|
|
905
|
-
const { decimal: n, identifier: i } = et(e), c = q(
|
|
898
|
+
static fromIdentifierSync(e, r = 0) {
|
|
899
|
+
const { decimal: n, identifier: i } = et(e), c = q(r, n);
|
|
906
900
|
return new y({ decimal: n, identifier: i, value: c });
|
|
907
901
|
}
|
|
908
|
-
static fromChainOrSignature(e,
|
|
909
|
-
const { decimal: n, identifier: i } =
|
|
902
|
+
static fromChainOrSignature(e, r = 0) {
|
|
903
|
+
const { decimal: n, identifier: i } = St(e), c = q(r, n);
|
|
910
904
|
return new y({ value: c, decimal: n, identifier: i });
|
|
911
905
|
}
|
|
912
906
|
static async loadStaticAssets() {
|
|
913
907
|
return new Promise(
|
|
914
|
-
async (e,
|
|
908
|
+
async (e, r) => {
|
|
915
909
|
try {
|
|
916
910
|
const {
|
|
917
911
|
// Omit ThorchainList from import to avoid decimals conflict (TC uses 8 for all)
|
|
@@ -928,7 +922,7 @@ class y extends C {
|
|
|
928
922
|
/* @__PURE__ */ new Map()
|
|
929
923
|
), e({ ok: !0 });
|
|
930
924
|
} catch (n) {
|
|
931
|
-
console.error(n),
|
|
925
|
+
console.error(n), r({
|
|
932
926
|
ok: !1,
|
|
933
927
|
error: n,
|
|
934
928
|
message: "Couldn't load static assets. Ensure you have installed @swapkit/tokens package"
|
|
@@ -938,9 +932,9 @@ class y extends C {
|
|
|
938
932
|
);
|
|
939
933
|
}
|
|
940
934
|
}
|
|
941
|
-
const
|
|
942
|
-
const t = y.fromChainOrSignature(
|
|
943
|
-
switch (
|
|
935
|
+
const fe = (s) => {
|
|
936
|
+
const t = y.fromChainOrSignature(s);
|
|
937
|
+
switch (s) {
|
|
944
938
|
case o.Bitcoin:
|
|
945
939
|
case o.Litecoin:
|
|
946
940
|
case o.BitcoinCash:
|
|
@@ -956,17 +950,17 @@ const _e = (r) => {
|
|
|
956
950
|
default:
|
|
957
951
|
return t.set(1e-8);
|
|
958
952
|
}
|
|
959
|
-
}, G = (
|
|
960
|
-
const t =
|
|
953
|
+
}, G = (s) => {
|
|
954
|
+
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("-");
|
|
961
955
|
return {
|
|
962
956
|
address: u == null ? void 0 : u.toLowerCase(),
|
|
963
957
|
chain: i,
|
|
964
|
-
isGasAsset:
|
|
958
|
+
isGasAsset: nt({ chain: i, symbol: c }),
|
|
965
959
|
isSynthetic: t,
|
|
966
960
|
symbol: (t ? `${e}/` : "") + (u ? `${a}-${(u == null ? void 0 : u.toLowerCase()) ?? ""}` : c),
|
|
967
961
|
ticker: a
|
|
968
962
|
};
|
|
969
|
-
},
|
|
963
|
+
}, te = {
|
|
970
964
|
/**
|
|
971
965
|
* Core
|
|
972
966
|
*/
|
|
@@ -1023,9 +1017,9 @@ const _e = (r) => {
|
|
|
1023
1017
|
*/
|
|
1024
1018
|
helpers_number_different_decimals: 99101
|
|
1025
1019
|
};
|
|
1026
|
-
class
|
|
1020
|
+
class ht extends Error {
|
|
1027
1021
|
constructor(t, e) {
|
|
1028
|
-
console.error(e), super(t, { cause: { code:
|
|
1022
|
+
console.error(e), super(t, { cause: { code: te[t], message: t } }), Object.setPrototypeOf(this, ht.prototype);
|
|
1029
1023
|
}
|
|
1030
1024
|
}
|
|
1031
1025
|
class b extends C {
|
|
@@ -1042,28 +1036,28 @@ class b extends C {
|
|
|
1042
1036
|
export {
|
|
1043
1037
|
y as AssetValue,
|
|
1044
1038
|
C as BigIntArithmetics,
|
|
1045
|
-
|
|
1046
|
-
|
|
1039
|
+
Qt as RequestClient,
|
|
1040
|
+
ht as SwapKitError,
|
|
1047
1041
|
b as SwapKitNumber,
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1042
|
+
ne as assetFromString,
|
|
1043
|
+
pe as derivationPathToString,
|
|
1044
|
+
ie as filterAssets,
|
|
1051
1045
|
k as formatBigIntToSafeValue,
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1046
|
+
se as gasFeeMultiplier,
|
|
1047
|
+
Ct as getAssetType,
|
|
1048
|
+
Bt as getAsymmetricAssetShare,
|
|
1049
|
+
ae as getAsymmetricAssetWithdrawAmount,
|
|
1050
|
+
Ot as getAsymmetricRuneShare,
|
|
1051
|
+
oe as getAsymmetricRuneWithdrawAmount,
|
|
1052
|
+
St as getCommonAssetInfo,
|
|
1053
|
+
Rt as getDecimal,
|
|
1054
|
+
ue as getEstimatedPoolShare,
|
|
1055
|
+
le as getLiquiditySlippage,
|
|
1056
|
+
he as getMemoFor,
|
|
1057
|
+
fe as getMinAmountByChain,
|
|
1058
|
+
Mt as getSymmetricPoolShare,
|
|
1059
|
+
ce as getSymmetricWithdraw,
|
|
1060
|
+
de as getTHORNameCost,
|
|
1061
|
+
nt as isGasAsset,
|
|
1062
|
+
me as validateTHORName
|
|
1069
1063
|
};
|