@swapkit/helpers 1.0.0-rc.52 → 1.0.0-rc.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +35 -36
- package/dist/index.es.js +439 -397
- package/dist/index.es.js.map +1 -1
- package/package.json +1 -1
- package/src/helpers/liquidity.ts +35 -29
- package/src/helpers/memo.ts +2 -11
- package/src/helpers/others.ts +6 -6
- package/src/helpers/validators.ts +4 -3
- package/src/modules/assetValue.ts +80 -110
- package/src/types.ts +28 -0
package/dist/index.es.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var f = (
|
|
4
|
-
if (!t.has(
|
|
1
|
+
var gt = Object.defineProperty;
|
|
2
|
+
var bt = (s, t, e) => t in s ? gt(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
|
|
3
|
+
var f = (s, t, e) => (bt(s, typeof t != "symbol" ? t + "" : t, e), e), yt = (s, t, e) => {
|
|
4
|
+
if (!t.has(s))
|
|
5
5
|
throw TypeError("Cannot " + e);
|
|
6
6
|
};
|
|
7
|
-
var
|
|
8
|
-
if (t.has(
|
|
7
|
+
var v = (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
|
|
13
|
-
import { FeeOption as
|
|
14
|
-
const
|
|
12
|
+
var d = (s, t, e) => (yt(s, t, "access private method"), e);
|
|
13
|
+
import { FeeOption as D, BaseDecimal as m, Chain as o, EVMChainList as wt, ChainToRPC as At, MemoType as _ } from "@swapkit/types";
|
|
14
|
+
const vt = "0x313ce567", st = async ({ chain: s, to: t }) => {
|
|
15
15
|
try {
|
|
16
|
-
const { result: e } = await
|
|
16
|
+
const { result: e } = await Qt.post(At[s], {
|
|
17
17
|
headers: {
|
|
18
18
|
accept: "*/*",
|
|
19
19
|
"content-type": "application/json",
|
|
@@ -23,38 +23,38 @@ const Tt = "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: vt }, "latest"]
|
|
27
27
|
})
|
|
28
28
|
});
|
|
29
29
|
return parseInt(BigInt(e).toString());
|
|
30
30
|
} catch (e) {
|
|
31
|
-
return console.error(e),
|
|
31
|
+
return console.error(e), m[s];
|
|
32
32
|
}
|
|
33
|
-
}, $t = async (
|
|
34
|
-
if (
|
|
35
|
-
return
|
|
36
|
-
const [, t] =
|
|
37
|
-
return t != null && t.startsWith("0x") ?
|
|
38
|
-
},
|
|
39
|
-
const [, t] =
|
|
40
|
-
return t != null && t.startsWith("0x") ?
|
|
41
|
-
}, Rt = async (
|
|
42
|
-
switch (
|
|
33
|
+
}, $t = async (s) => {
|
|
34
|
+
if (s === o.Ethereum)
|
|
35
|
+
return m.ETH;
|
|
36
|
+
const [, t] = s.split("-");
|
|
37
|
+
return t != null && t.startsWith("0x") ? st({ chain: o.Ethereum, to: t }) : m.ETH;
|
|
38
|
+
}, Tt = async (s) => {
|
|
39
|
+
const [, t] = s.split("-");
|
|
40
|
+
return t != null && t.startsWith("0x") ? st({ chain: o.Avalanche, to: t.toLowerCase() }) : m.AVAX;
|
|
41
|
+
}, Rt = async (s) => s === o.BinanceSmartChain ? m.BSC : m.BSC, Ct = async ({ chain: s, symbol: t }) => {
|
|
42
|
+
switch (s) {
|
|
43
43
|
case o.Ethereum:
|
|
44
44
|
return $t(t);
|
|
45
45
|
case o.Avalanche:
|
|
46
|
-
return
|
|
46
|
+
return Tt(t);
|
|
47
47
|
case o.BinanceSmartChain:
|
|
48
48
|
return Rt(t);
|
|
49
49
|
default:
|
|
50
|
-
return
|
|
50
|
+
return m[s];
|
|
51
51
|
}
|
|
52
|
-
},
|
|
53
|
-
[
|
|
54
|
-
[
|
|
55
|
-
[
|
|
56
|
-
},
|
|
57
|
-
switch (
|
|
52
|
+
}, se = {
|
|
53
|
+
[D.Average]: 1.2,
|
|
54
|
+
[D.Fast]: 1.5,
|
|
55
|
+
[D.Fastest]: 2
|
|
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 Tt = "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,20 +79,20 @@ const Tt = "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:
|
|
89
|
+
return { identifier: "GAIA.ATOM", decimal: m[s] };
|
|
90
90
|
case o.THORChain:
|
|
91
|
-
return { identifier: "THOR.RUNE", decimal:
|
|
91
|
+
return { identifier: "THOR.RUNE", decimal: m[s] };
|
|
92
92
|
case o.BinanceSmartChain:
|
|
93
|
-
return { identifier: "BSC.BNB", decimal:
|
|
93
|
+
return { identifier: "BSC.BNB", decimal: m[s] };
|
|
94
94
|
case o.Maya:
|
|
95
|
-
return { identifier: "MAYA.CACAO", decimal:
|
|
95
|
+
return { identifier: "MAYA.CACAO", decimal: m.MAYA };
|
|
96
96
|
case "MAYA.MAYA":
|
|
97
97
|
return { identifier: "MAYA.MAYA", decimal: 4 };
|
|
98
98
|
case o.Kujira:
|
|
@@ -106,12 +106,12 @@ const Tt = "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: m[s] };
|
|
110
110
|
}
|
|
111
|
-
},
|
|
111
|
+
}, It = ({ 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,109 +138,125 @@ const Tt = "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
|
+
}, Ot = 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 (!wt.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
|
-
|
|
156
|
+
return !Ot.test(e) && Et(e) && t.value !== "0";
|
|
157
|
+
});
|
|
158
|
+
function Bt({
|
|
159
|
+
liquidityUnits: s,
|
|
159
160
|
poolUnits: t,
|
|
160
161
|
runeDepth: e
|
|
161
|
-
})
|
|
162
|
-
const
|
|
163
|
-
return c.mul(a.sub(u).add(
|
|
164
|
-
}
|
|
165
|
-
|
|
162
|
+
}) {
|
|
163
|
+
const r = p(s), n = p(t), i = p(e), c = r.mul(i), a = n.mul(n).mul(2), u = n.mul(r).mul(2), h = r.mul(r), l = n.mul(n).mul(n);
|
|
164
|
+
return c.mul(a.sub(u).add(h)).div(l);
|
|
165
|
+
}
|
|
166
|
+
function Mt({
|
|
167
|
+
liquidityUnits: s,
|
|
166
168
|
poolUnits: t,
|
|
167
169
|
assetDepth: e
|
|
168
|
-
})
|
|
169
|
-
const
|
|
170
|
-
return l.div(
|
|
171
|
-
}
|
|
172
|
-
|
|
170
|
+
}) {
|
|
171
|
+
const r = p(s), n = p(t), i = p(e), c = r.mul(i), a = n.mul(n).mul(2), u = n.mul(r).mul(2), h = r.mul(r), l = c.mul(a.sub(u).add(h)), A = n.mul(n).mul(n);
|
|
172
|
+
return l.div(A);
|
|
173
|
+
}
|
|
174
|
+
function oe({
|
|
175
|
+
percent: s,
|
|
173
176
|
runeDepth: t,
|
|
174
177
|
liquidityUnits: e,
|
|
175
|
-
poolUnits:
|
|
176
|
-
})
|
|
177
|
-
|
|
178
|
+
poolUnits: r
|
|
179
|
+
}) {
|
|
180
|
+
return Bt({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(s);
|
|
181
|
+
}
|
|
182
|
+
function ae({
|
|
183
|
+
percent: s,
|
|
178
184
|
assetDepth: t,
|
|
179
185
|
liquidityUnits: e,
|
|
180
|
-
poolUnits:
|
|
181
|
-
})
|
|
182
|
-
liquidityUnits: r
|
|
186
|
+
poolUnits: r
|
|
187
|
+
}) {
|
|
188
|
+
return Mt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(s);
|
|
189
|
+
}
|
|
190
|
+
function p(s) {
|
|
191
|
+
return g.fromBigInt(BigInt(s), m.THOR);
|
|
192
|
+
}
|
|
193
|
+
function xt({
|
|
194
|
+
liquidityUnits: s,
|
|
183
195
|
poolUnits: t,
|
|
184
196
|
runeDepth: e,
|
|
185
|
-
assetDepth:
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
197
|
+
assetDepth: r
|
|
198
|
+
}) {
|
|
199
|
+
return {
|
|
200
|
+
assetAmount: p(r).mul(s).div(t),
|
|
201
|
+
runeAmount: p(e).mul(s).div(t)
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function ce({
|
|
205
|
+
liquidityUnits: s,
|
|
191
206
|
poolUnits: t,
|
|
192
207
|
runeDepth: e,
|
|
193
|
-
assetDepth:
|
|
208
|
+
assetDepth: r,
|
|
194
209
|
percent: n
|
|
195
|
-
})
|
|
196
|
-
Object.
|
|
197
|
-
(
|
|
198
|
-
|
|
199
|
-
)
|
|
200
|
-
|
|
210
|
+
}) {
|
|
211
|
+
return Object.fromEntries(
|
|
212
|
+
Object.entries(xt({ liquidityUnits: s, poolUnits: t, runeDepth: e, assetDepth: r })).map(
|
|
213
|
+
([i, c]) => [i, c.mul(n)]
|
|
214
|
+
)
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
function ue({
|
|
218
|
+
runeDepth: s,
|
|
201
219
|
poolUnits: t,
|
|
202
220
|
assetDepth: e,
|
|
203
|
-
liquidityUnits:
|
|
221
|
+
liquidityUnits: r,
|
|
204
222
|
runeAmount: n,
|
|
205
223
|
assetAmount: i
|
|
206
|
-
})
|
|
207
|
-
const c = new
|
|
224
|
+
}) {
|
|
225
|
+
const c = new g({ value: s, decimal: 8 }), a = new g({ value: e, decimal: 8 }), u = new g({ value: t, decimal: 8 }), h = new g({ value: n, decimal: 8 }), l = new g({ value: i, decimal: 8 }), A = h.mul(a), j = l.mul(c), dt = h.mul(l), mt = c.mul(a), pt = u.mul(A.add(j.add(dt.mul(2)))), ft = A.add(j.add(mt.mul(2))), Q = pt.div(ft), H = p(r).add(Q);
|
|
208
226
|
if (Q.getBaseValue("number") === 0)
|
|
209
|
-
return
|
|
210
|
-
const
|
|
211
|
-
return
|
|
212
|
-
}
|
|
213
|
-
|
|
227
|
+
return H.div(u).getBaseValue("number");
|
|
228
|
+
const _t = u.add(H);
|
|
229
|
+
return H.div(_t).getBaseValue("number");
|
|
230
|
+
}
|
|
231
|
+
function le({
|
|
232
|
+
runeAmount: s,
|
|
214
233
|
assetAmount: t,
|
|
215
234
|
runeDepth: e,
|
|
216
|
-
assetDepth:
|
|
217
|
-
})
|
|
218
|
-
if (
|
|
235
|
+
assetDepth: r
|
|
236
|
+
}) {
|
|
237
|
+
if (s === "0" || t === "0" || e === "0" || r === "0")
|
|
219
238
|
return 0;
|
|
220
|
-
const n = p(e), i = p(
|
|
221
|
-
return Math.abs(u.div(
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
switch (r) {
|
|
228
|
-
case g.LEAVE:
|
|
229
|
-
case g.BOND: {
|
|
239
|
+
const n = p(e), i = p(r), c = p(t), a = p(s), u = c.mul(n).sub(i.mul(a)), h = i.mul(a).add(n.mul(i));
|
|
240
|
+
return Math.abs(u.div(h).getBaseValue("number"));
|
|
241
|
+
}
|
|
242
|
+
const he = (s, t) => {
|
|
243
|
+
switch (s) {
|
|
244
|
+
case _.LEAVE:
|
|
245
|
+
case _.BOND: {
|
|
230
246
|
const { address: e } = t;
|
|
231
|
-
return `${
|
|
247
|
+
return `${s}:${e}`;
|
|
232
248
|
}
|
|
233
|
-
case
|
|
234
|
-
const { address: e, unbondAmount:
|
|
235
|
-
return `${
|
|
249
|
+
case _.UNBOND: {
|
|
250
|
+
const { address: e, unbondAmount: r } = t;
|
|
251
|
+
return `${s}:${e}:${r * 10 ** 8}`;
|
|
236
252
|
}
|
|
237
|
-
case
|
|
238
|
-
const { name: e, chain:
|
|
239
|
-
return `${
|
|
253
|
+
case _.THORNAME_REGISTER: {
|
|
254
|
+
const { name: e, chain: r, address: n, owner: i } = t;
|
|
255
|
+
return `${s}:${e}:${r}:${n}${i ? `:${i}` : ""}`;
|
|
240
256
|
}
|
|
241
|
-
case
|
|
242
|
-
const { chain: e, symbol:
|
|
243
|
-
return i ? `${
|
|
257
|
+
case _.DEPOSIT: {
|
|
258
|
+
const { chain: e, symbol: r, address: n, singleSide: i } = t;
|
|
259
|
+
return i ? `${s}:${e}/${r}::t:0` : `${s}:${((a, u) => {
|
|
244
260
|
switch (a) {
|
|
245
261
|
case o.Litecoin:
|
|
246
262
|
return "l";
|
|
@@ -251,32 +267,37 @@ const Tt = "0x313ce567", nt = async ({ chain: r, to: t }) => {
|
|
|
251
267
|
default:
|
|
252
268
|
return `${a}.${u}`;
|
|
253
269
|
}
|
|
254
|
-
})(e,
|
|
270
|
+
})(e, r)}:${n || ""}:t:0`;
|
|
255
271
|
}
|
|
256
|
-
case
|
|
257
|
-
const { chain: e, ticker:
|
|
258
|
-
return `${
|
|
272
|
+
case _.WITHDRAW: {
|
|
273
|
+
const { chain: e, ticker: r, symbol: n, basisPoints: i, targetAssetString: c, singleSide: a } = t, u = e === "ETH" && r !== "ETH" ? `${r}-${n.slice(-3)}` : n, h = !a && c ? `:${c}` : "";
|
|
274
|
+
return `${s}:${e}${a ? "/" : "."}${u}:${i}${h}`;
|
|
259
275
|
}
|
|
260
|
-
case
|
|
261
|
-
case
|
|
262
|
-
const { asset: e, address:
|
|
263
|
-
return `${
|
|
276
|
+
case _.OPEN_LOAN:
|
|
277
|
+
case _.CLOSE_LOAN: {
|
|
278
|
+
const { asset: e, address: r } = t;
|
|
279
|
+
return `${s}:${e}:${r}`;
|
|
264
280
|
}
|
|
265
281
|
default:
|
|
266
282
|
return "";
|
|
267
283
|
}
|
|
268
|
-
}
|
|
269
|
-
|
|
284
|
+
};
|
|
285
|
+
function de(s) {
|
|
286
|
+
if (s < 0)
|
|
270
287
|
throw new Error("Invalid number of year");
|
|
271
|
-
return 10 +
|
|
272
|
-
}
|
|
273
|
-
|
|
288
|
+
return 10 + s;
|
|
289
|
+
}
|
|
290
|
+
function me(s) {
|
|
291
|
+
if (s.length > 30)
|
|
274
292
|
return !1;
|
|
275
293
|
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
276
|
-
return !!
|
|
277
|
-
}
|
|
294
|
+
return !!s.match(t);
|
|
295
|
+
}
|
|
296
|
+
function pe([s, t, e, r, n]) {
|
|
297
|
+
return `${s}'/${t}'/${e}'/${r}${typeof n != "number" ? "" : `/${n}`}`;
|
|
298
|
+
}
|
|
278
299
|
class X extends Error {
|
|
279
|
-
constructor(t, e,
|
|
300
|
+
constructor(t, e, r) {
|
|
280
301
|
const n = t.status || t.status === 0 ? t.status : "", i = t.statusText || "", c = `${n} ${i}`.trim(), a = c ? `status code ${c}` : "an unknown error";
|
|
281
302
|
super(`Request failed with ${a}`), Object.defineProperty(this, "response", {
|
|
282
303
|
enumerable: !0,
|
|
@@ -293,10 +314,10 @@ class X extends Error {
|
|
|
293
314
|
configurable: !0,
|
|
294
315
|
writable: !0,
|
|
295
316
|
value: void 0
|
|
296
|
-
}), this.name = "HTTPError", this.response = t, this.request = e, this.options =
|
|
317
|
+
}), this.name = "HTTPError", this.response = t, this.request = e, this.options = r;
|
|
297
318
|
}
|
|
298
319
|
}
|
|
299
|
-
class
|
|
320
|
+
class it extends Error {
|
|
300
321
|
constructor(t) {
|
|
301
322
|
super("Request timed out"), Object.defineProperty(this, "request", {
|
|
302
323
|
enumerable: !0,
|
|
@@ -306,45 +327,45 @@ class ot extends Error {
|
|
|
306
327
|
}), this.name = "TimeoutError", this.request = t;
|
|
307
328
|
}
|
|
308
329
|
}
|
|
309
|
-
const x = (
|
|
310
|
-
for (const t of
|
|
330
|
+
const x = (s) => s !== null && typeof s == "object", B = (...s) => {
|
|
331
|
+
for (const t of s)
|
|
311
332
|
if ((!x(t) || Array.isArray(t)) && t !== void 0)
|
|
312
333
|
throw new TypeError("The `options` argument must be an object");
|
|
313
|
-
return J({}, ...
|
|
314
|
-
},
|
|
315
|
-
const e = new globalThis.Headers(
|
|
334
|
+
return J({}, ...s);
|
|
335
|
+
}, ot = (s = {}, t = {}) => {
|
|
336
|
+
const e = new globalThis.Headers(s), r = t instanceof globalThis.Headers, n = new globalThis.Headers(t);
|
|
316
337
|
for (const [i, c] of n.entries())
|
|
317
|
-
|
|
338
|
+
r && c === "undefined" || c === void 0 ? e.delete(i) : e.set(i, c);
|
|
318
339
|
return e;
|
|
319
|
-
}, J = (...
|
|
340
|
+
}, J = (...s) => {
|
|
320
341
|
let t = {}, e = {};
|
|
321
|
-
for (const
|
|
322
|
-
if (Array.isArray(
|
|
323
|
-
Array.isArray(t) || (t = []), t = [...t, ...
|
|
324
|
-
else if (x(
|
|
325
|
-
for (let [n, i] of Object.entries(
|
|
342
|
+
for (const r of s)
|
|
343
|
+
if (Array.isArray(r))
|
|
344
|
+
Array.isArray(t) || (t = []), t = [...t, ...r];
|
|
345
|
+
else if (x(r)) {
|
|
346
|
+
for (let [n, i] of Object.entries(r))
|
|
326
347
|
x(i) && n in t && (i = J(t[n], i)), t = { ...t, [n]: i };
|
|
327
|
-
x(
|
|
348
|
+
x(r.headers) && (e = ot(e, r.headers), t.headers = e);
|
|
328
349
|
}
|
|
329
350
|
return t;
|
|
330
|
-
},
|
|
331
|
-
let
|
|
332
|
-
const e = typeof globalThis.ReadableStream == "function",
|
|
333
|
-
return e &&
|
|
351
|
+
}, qt = (() => {
|
|
352
|
+
let s = !1, t = !1;
|
|
353
|
+
const e = typeof globalThis.ReadableStream == "function", r = typeof globalThis.Request == "function";
|
|
354
|
+
return e && r && (t = new globalThis.Request("https://empty.invalid", {
|
|
334
355
|
body: new globalThis.ReadableStream(),
|
|
335
356
|
method: "POST",
|
|
336
357
|
// @ts-expect-error - Types are outdated.
|
|
337
358
|
get duplex() {
|
|
338
|
-
return
|
|
359
|
+
return s = !0, "half";
|
|
339
360
|
}
|
|
340
|
-
}).headers.has("Content-Type")),
|
|
341
|
-
})(), Pt = typeof globalThis.AbortController == "function",
|
|
361
|
+
}).headers.has("Content-Type")), s && !t;
|
|
362
|
+
})(), Pt = typeof globalThis.AbortController == "function", Vt = typeof globalThis.ReadableStream == "function", kt = typeof globalThis.FormData == "function", at = ["get", "post", "put", "patch", "head", "delete"], Nt = {
|
|
342
363
|
json: "application/json",
|
|
343
364
|
text: "text/*",
|
|
344
365
|
formData: "multipart/form-data",
|
|
345
366
|
arrayBuffer: "*/*",
|
|
346
367
|
blob: "*/*"
|
|
347
|
-
},
|
|
368
|
+
}, U = 2147483647, ct = Symbol("stop"), jt = {
|
|
348
369
|
json: !0,
|
|
349
370
|
parseJson: !0,
|
|
350
371
|
searchParams: !0,
|
|
@@ -355,7 +376,7 @@ const x = (r) => r !== null && typeof r == "object", M = (...r) => {
|
|
|
355
376
|
throwHttpErrors: !0,
|
|
356
377
|
onDownloadProgress: !0,
|
|
357
378
|
fetch: !0
|
|
358
|
-
},
|
|
379
|
+
}, Ht = {
|
|
359
380
|
method: !0,
|
|
360
381
|
headers: !0,
|
|
361
382
|
body: !0,
|
|
@@ -371,86 +392,86 @@ const x = (r) => r !== null && typeof r == "object", M = (...r) => {
|
|
|
371
392
|
window: !0,
|
|
372
393
|
dispatcher: !0,
|
|
373
394
|
duplex: !0
|
|
374
|
-
},
|
|
395
|
+
}, Dt = (s) => at.includes(s) ? s.toUpperCase() : s, Ut = ["get", "put", "head", "delete", "options", "trace"], Lt = [408, 413, 429, 500, 502, 503, 504], ut = [413, 429, 503], Z = {
|
|
375
396
|
limit: 2,
|
|
376
|
-
methods:
|
|
377
|
-
statusCodes:
|
|
378
|
-
afterStatusCodes:
|
|
397
|
+
methods: Ut,
|
|
398
|
+
statusCodes: Lt,
|
|
399
|
+
afterStatusCodes: ut,
|
|
379
400
|
maxRetryAfter: Number.POSITIVE_INFINITY,
|
|
380
401
|
backoffLimit: Number.POSITIVE_INFINITY,
|
|
381
|
-
delay: (
|
|
382
|
-
},
|
|
383
|
-
if (typeof
|
|
402
|
+
delay: (s) => 0.3 * 2 ** (s - 1) * 1e3
|
|
403
|
+
}, Ft = (s = {}) => {
|
|
404
|
+
if (typeof s == "number")
|
|
384
405
|
return {
|
|
385
406
|
...Z,
|
|
386
|
-
limit:
|
|
407
|
+
limit: s
|
|
387
408
|
};
|
|
388
|
-
if (
|
|
409
|
+
if (s.methods && !Array.isArray(s.methods))
|
|
389
410
|
throw new Error("retry.methods must be an array");
|
|
390
|
-
if (
|
|
411
|
+
if (s.statusCodes && !Array.isArray(s.statusCodes))
|
|
391
412
|
throw new Error("retry.statusCodes must be an array");
|
|
392
413
|
return {
|
|
393
414
|
...Z,
|
|
394
|
-
...
|
|
395
|
-
afterStatusCodes:
|
|
415
|
+
...s,
|
|
416
|
+
afterStatusCodes: ut
|
|
396
417
|
};
|
|
397
418
|
};
|
|
398
|
-
async function
|
|
419
|
+
async function Wt(s, t, e, r) {
|
|
399
420
|
return new Promise((n, i) => {
|
|
400
421
|
const c = setTimeout(() => {
|
|
401
|
-
e && e.abort(), i(new
|
|
402
|
-
},
|
|
403
|
-
|
|
422
|
+
e && e.abort(), i(new it(s));
|
|
423
|
+
}, r.timeout);
|
|
424
|
+
r.fetch(s, t).then(n).catch(i).then(() => {
|
|
404
425
|
clearTimeout(c);
|
|
405
426
|
});
|
|
406
427
|
});
|
|
407
428
|
}
|
|
408
|
-
async function
|
|
409
|
-
return new Promise((e,
|
|
429
|
+
async function Gt(s, { signal: t }) {
|
|
430
|
+
return new Promise((e, r) => {
|
|
410
431
|
t && (t.throwIfAborted(), t.addEventListener("abort", n, { once: !0 }));
|
|
411
432
|
function n() {
|
|
412
|
-
clearTimeout(i),
|
|
433
|
+
clearTimeout(i), r(t.reason);
|
|
413
434
|
}
|
|
414
435
|
const i = setTimeout(() => {
|
|
415
436
|
t == null || t.removeEventListener("abort", n), e();
|
|
416
|
-
},
|
|
437
|
+
}, s);
|
|
417
438
|
});
|
|
418
439
|
}
|
|
419
|
-
const
|
|
440
|
+
const Yt = (s, t) => {
|
|
420
441
|
const e = {};
|
|
421
|
-
for (const
|
|
422
|
-
!(
|
|
442
|
+
for (const r in t)
|
|
443
|
+
!(r in Ht) && !(r in jt) && !(r in s) && (e[r] = t[r]);
|
|
423
444
|
return e;
|
|
424
445
|
};
|
|
425
|
-
class
|
|
446
|
+
class P {
|
|
426
447
|
static create(t, e) {
|
|
427
|
-
const
|
|
428
|
-
if (typeof
|
|
429
|
-
throw new RangeError(`The \`timeout\` option cannot be greater than ${
|
|
448
|
+
const r = new P(t, e), n = async () => {
|
|
449
|
+
if (typeof r._options.timeout == "number" && r._options.timeout > U)
|
|
450
|
+
throw new RangeError(`The \`timeout\` option cannot be greater than ${U}`);
|
|
430
451
|
await Promise.resolve();
|
|
431
|
-
let a = await
|
|
432
|
-
for (const u of
|
|
433
|
-
const
|
|
434
|
-
|
|
452
|
+
let a = await r._fetch();
|
|
453
|
+
for (const u of r._options.hooks.afterResponse) {
|
|
454
|
+
const h = await u(r.request, r._options, r._decorateResponse(a.clone()));
|
|
455
|
+
h instanceof globalThis.Response && (a = h);
|
|
435
456
|
}
|
|
436
|
-
if (
|
|
437
|
-
let u = new X(a,
|
|
438
|
-
for (const
|
|
439
|
-
u = await
|
|
457
|
+
if (r._decorateResponse(a), !a.ok && r._options.throwHttpErrors) {
|
|
458
|
+
let u = new X(a, r.request, r._options);
|
|
459
|
+
for (const h of r._options.hooks.beforeError)
|
|
460
|
+
u = await h(u);
|
|
440
461
|
throw u;
|
|
441
462
|
}
|
|
442
|
-
if (
|
|
443
|
-
if (typeof
|
|
463
|
+
if (r._options.onDownloadProgress) {
|
|
464
|
+
if (typeof r._options.onDownloadProgress != "function")
|
|
444
465
|
throw new TypeError("The `onDownloadProgress` option must be a function");
|
|
445
|
-
if (!
|
|
466
|
+
if (!Vt)
|
|
446
467
|
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
|
|
447
|
-
return
|
|
468
|
+
return r._stream(a.clone(), r._options.onDownloadProgress);
|
|
448
469
|
}
|
|
449
470
|
return a;
|
|
450
|
-
}, c =
|
|
451
|
-
for (const [a, u] of Object.entries(
|
|
471
|
+
}, c = r._options.retry.methods.includes(r.request.method.toLowerCase()) ? r._retry(n) : n();
|
|
472
|
+
for (const [a, u] of Object.entries(Nt))
|
|
452
473
|
c[a] = async () => {
|
|
453
|
-
|
|
474
|
+
r.request.headers.set("accept", r.request.headers.get("accept") || u);
|
|
454
475
|
const l = (await c).clone();
|
|
455
476
|
if (a === "json") {
|
|
456
477
|
if (l.status === 204 || (await l.clone().arrayBuffer()).byteLength === 0)
|
|
@@ -493,17 +514,17 @@ class V {
|
|
|
493
514
|
// TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208
|
|
494
515
|
credentials: this._input.credentials || "same-origin",
|
|
495
516
|
...e,
|
|
496
|
-
headers:
|
|
517
|
+
headers: ot(this._input.headers, e.headers),
|
|
497
518
|
hooks: J({
|
|
498
519
|
beforeRequest: [],
|
|
499
520
|
beforeRetry: [],
|
|
500
521
|
beforeError: [],
|
|
501
522
|
afterResponse: []
|
|
502
523
|
}, e.hooks),
|
|
503
|
-
method:
|
|
524
|
+
method: Dt(e.method ?? this._input.method),
|
|
504
525
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
505
526
|
prefixUrl: String(e.prefixUrl || ""),
|
|
506
|
-
retry:
|
|
527
|
+
retry: Ft(e.retry),
|
|
507
528
|
throwHttpErrors: e.throwHttpErrors !== !1,
|
|
508
529
|
timeout: e.timeout ?? 1e4,
|
|
509
530
|
fetch: e.fetch ?? globalThis.fetch.bind(globalThis)
|
|
@@ -516,28 +537,28 @@ class V {
|
|
|
516
537
|
}
|
|
517
538
|
if (Pt) {
|
|
518
539
|
if (this.abortController = new globalThis.AbortController(), this._options.signal) {
|
|
519
|
-
const
|
|
540
|
+
const r = this._options.signal;
|
|
520
541
|
this._options.signal.addEventListener("abort", () => {
|
|
521
|
-
this.abortController.abort(
|
|
542
|
+
this.abortController.abort(r.reason);
|
|
522
543
|
});
|
|
523
544
|
}
|
|
524
545
|
this._options.signal = this.abortController.signal;
|
|
525
546
|
}
|
|
526
|
-
if (
|
|
547
|
+
if (qt && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
|
|
527
548
|
const n = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), i = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, n);
|
|
528
|
-
(
|
|
549
|
+
(kt && 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);
|
|
529
550
|
}
|
|
530
551
|
this._options.json !== void 0 && (this._options.body = JSON.stringify(this._options.json), this.request.headers.set("content-type", this._options.headers.get("content-type") ?? "application/json"), this.request = new globalThis.Request(this.request, { body: this._options.body }));
|
|
531
552
|
}
|
|
532
553
|
_calculateRetryDelay(t) {
|
|
533
|
-
if (this._retryCount++, this._retryCount < this._options.retry.limit && !(t instanceof
|
|
554
|
+
if (this._retryCount++, this._retryCount < this._options.retry.limit && !(t instanceof it)) {
|
|
534
555
|
if (t instanceof X) {
|
|
535
556
|
if (!this._options.retry.statusCodes.includes(t.response.status))
|
|
536
557
|
return 0;
|
|
537
|
-
const
|
|
538
|
-
if (
|
|
539
|
-
let n = Number(
|
|
540
|
-
return Number.isNaN(n) ? n = Date.parse(
|
|
558
|
+
const r = t.response.headers.get("Retry-After");
|
|
559
|
+
if (r && this._options.retry.afterStatusCodes.includes(t.response.status)) {
|
|
560
|
+
let n = Number(r);
|
|
561
|
+
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;
|
|
541
562
|
}
|
|
542
563
|
if (t.response.status === 413)
|
|
543
564
|
return 0;
|
|
@@ -554,16 +575,16 @@ class V {
|
|
|
554
575
|
try {
|
|
555
576
|
return await t();
|
|
556
577
|
} catch (e) {
|
|
557
|
-
const
|
|
558
|
-
if (
|
|
559
|
-
await
|
|
578
|
+
const r = Math.min(this._calculateRetryDelay(e), U);
|
|
579
|
+
if (r !== 0 && this._retryCount > 0) {
|
|
580
|
+
await Gt(r, { signal: this._options.signal });
|
|
560
581
|
for (const n of this._options.hooks.beforeRetry)
|
|
561
582
|
if (await n({
|
|
562
583
|
request: this.request,
|
|
563
584
|
options: this._options,
|
|
564
585
|
error: e,
|
|
565
586
|
retryCount: this._retryCount
|
|
566
|
-
}) ===
|
|
587
|
+
}) === ct)
|
|
567
588
|
return;
|
|
568
589
|
return this._retry(t);
|
|
569
590
|
}
|
|
@@ -572,41 +593,41 @@ class V {
|
|
|
572
593
|
}
|
|
573
594
|
async _fetch() {
|
|
574
595
|
for (const e of this._options.hooks.beforeRequest) {
|
|
575
|
-
const
|
|
576
|
-
if (
|
|
577
|
-
this.request =
|
|
596
|
+
const r = await e(this.request, this._options);
|
|
597
|
+
if (r instanceof Request) {
|
|
598
|
+
this.request = r;
|
|
578
599
|
break;
|
|
579
600
|
}
|
|
580
|
-
if (
|
|
581
|
-
return
|
|
601
|
+
if (r instanceof Response)
|
|
602
|
+
return r;
|
|
582
603
|
}
|
|
583
|
-
const t =
|
|
584
|
-
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) :
|
|
604
|
+
const t = Yt(this.request, this._options);
|
|
605
|
+
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Wt(this.request.clone(), t, this.abortController, this._options);
|
|
585
606
|
}
|
|
586
607
|
/* istanbul ignore next */
|
|
587
608
|
_stream(t, e) {
|
|
588
|
-
const
|
|
609
|
+
const r = Number(t.headers.get("content-length")) || 0;
|
|
589
610
|
let n = 0;
|
|
590
|
-
return t.status === 204 ? (e && e({ percent: 1, totalBytes:
|
|
611
|
+
return t.status === 204 ? (e && e({ percent: 1, totalBytes: r, transferredBytes: n }, new Uint8Array()), new globalThis.Response(null, {
|
|
591
612
|
status: t.status,
|
|
592
613
|
statusText: t.statusText,
|
|
593
614
|
headers: t.headers
|
|
594
615
|
})) : new globalThis.Response(new globalThis.ReadableStream({
|
|
595
616
|
async start(i) {
|
|
596
617
|
const c = t.body.getReader();
|
|
597
|
-
e && e({ percent: 0, transferredBytes: 0, totalBytes:
|
|
618
|
+
e && e({ percent: 0, transferredBytes: 0, totalBytes: r }, new Uint8Array());
|
|
598
619
|
async function a() {
|
|
599
|
-
const { done: u, value:
|
|
620
|
+
const { done: u, value: h } = await c.read();
|
|
600
621
|
if (u) {
|
|
601
622
|
i.close();
|
|
602
623
|
return;
|
|
603
624
|
}
|
|
604
625
|
if (e) {
|
|
605
|
-
n +=
|
|
606
|
-
const l =
|
|
607
|
-
e({ percent: l, transferredBytes: n, totalBytes:
|
|
626
|
+
n += h.byteLength;
|
|
627
|
+
const l = r === 0 ? 0 : n / r;
|
|
628
|
+
e({ percent: l, transferredBytes: n, totalBytes: r }, h);
|
|
608
629
|
}
|
|
609
|
-
i.enqueue(
|
|
630
|
+
i.enqueue(h), await a();
|
|
610
631
|
}
|
|
611
632
|
await a();
|
|
612
633
|
}
|
|
@@ -618,108 +639,110 @@ class V {
|
|
|
618
639
|
}
|
|
619
640
|
}
|
|
620
641
|
/*! MIT License © Sindre Sorhus */
|
|
621
|
-
const
|
|
622
|
-
const t = (e,
|
|
623
|
-
for (const e of
|
|
624
|
-
t[e] = (
|
|
625
|
-
return t.create = (e) =>
|
|
626
|
-
},
|
|
627
|
-
get: (
|
|
628
|
-
post: (
|
|
629
|
-
}, et = Object.values(o),
|
|
630
|
-
|
|
642
|
+
const F = (s) => {
|
|
643
|
+
const t = (e, r) => P.create(e, B(s, r));
|
|
644
|
+
for (const e of at)
|
|
645
|
+
t[e] = (r, n) => P.create(r, B(s, n, { method: e }));
|
|
646
|
+
return t.create = (e) => F(B(e)), t.extend = (e) => F(B(s, e)), t.stop = ct, t;
|
|
647
|
+
}, zt = F(), Jt = zt, Kt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, tt = Jt.create({ headers: Kt }), Qt = {
|
|
648
|
+
get: (s, t) => tt.get(s, t).json(),
|
|
649
|
+
post: (s, t) => tt.post(s, t).json()
|
|
650
|
+
}, et = [...Object.values(o), "TERRA"];
|
|
651
|
+
function Xt(s = "") {
|
|
652
|
+
const t = s.toUpperCase(), [e] = t.split(".");
|
|
631
653
|
if (et.includes(e))
|
|
632
654
|
return !0;
|
|
633
|
-
const [
|
|
634
|
-
if (et.includes(
|
|
655
|
+
const [r] = t.split("/");
|
|
656
|
+
if (et.includes(r))
|
|
635
657
|
return !0;
|
|
636
658
|
throw new Error(
|
|
637
|
-
`Invalid identifier: ${
|
|
659
|
+
`Invalid identifier: ${s}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
638
660
|
);
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
661
|
+
}
|
|
662
|
+
const I = 8, y = (s) => 10n ** BigInt(s), R = (s) => Math.log10(parseFloat(s.toString()));
|
|
663
|
+
function V({
|
|
664
|
+
value: s,
|
|
665
|
+
bigIntDecimal: t = I,
|
|
666
|
+
decimal: e = I
|
|
644
667
|
}) {
|
|
645
668
|
if (e === 0)
|
|
646
|
-
return
|
|
647
|
-
const
|
|
648
|
-
let n =
|
|
669
|
+
return s.toString();
|
|
670
|
+
const r = s < 0n;
|
|
671
|
+
let n = s.toString().substring(r ? 1 : 0);
|
|
649
672
|
const i = e - (n.length - 1);
|
|
650
673
|
i > 0 && (n = "0".repeat(i) + n);
|
|
651
674
|
const c = n.length - e;
|
|
652
675
|
let a = n.slice(-e);
|
|
653
|
-
return parseInt(a[t]) >= 5 ? a = `${a.substring(0, t - 1)}${(parseInt(a[t - 1]) + 1).toString()}` : a = a.substring(0, t), `${
|
|
676
|
+
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(
|
|
654
677
|
/\.?0*$/,
|
|
655
678
|
""
|
|
656
679
|
);
|
|
657
680
|
}
|
|
658
|
-
var
|
|
681
|
+
var w, C, b, $, N, lt, O, W, E, G;
|
|
659
682
|
const K = class K {
|
|
660
683
|
constructor(t) {
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
684
|
+
v(this, w);
|
|
685
|
+
v(this, b);
|
|
686
|
+
v(this, N);
|
|
687
|
+
v(this, O);
|
|
688
|
+
v(this, E);
|
|
666
689
|
f(this, "decimalMultiplier", 10n ** 8n);
|
|
667
690
|
f(this, "bigIntValue", 0n);
|
|
668
691
|
f(this, "decimal");
|
|
669
|
-
const e =
|
|
670
|
-
this.decimal =
|
|
692
|
+
const e = Y(t), r = typeof t == "object";
|
|
693
|
+
this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier : y(Math.max(rt(M(e)), this.decimal || 0)), d(this, N, lt).call(this, e);
|
|
671
694
|
}
|
|
672
695
|
static fromBigInt(t, e) {
|
|
673
696
|
return new K({
|
|
674
697
|
decimal: e,
|
|
675
|
-
value:
|
|
698
|
+
value: V({ value: t, bigIntDecimal: e, decimal: e })
|
|
676
699
|
});
|
|
677
700
|
}
|
|
678
701
|
static shiftDecimals({
|
|
679
702
|
value: t,
|
|
680
703
|
from: e,
|
|
681
|
-
to:
|
|
704
|
+
to: r
|
|
682
705
|
}) {
|
|
683
706
|
return this.fromBigInt(
|
|
684
|
-
t.getBaseValue("bigint") *
|
|
685
|
-
|
|
707
|
+
t.getBaseValue("bigint") * y(r) / y(e),
|
|
708
|
+
r
|
|
686
709
|
);
|
|
687
710
|
}
|
|
688
711
|
set(t) {
|
|
689
712
|
return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
|
|
690
713
|
}
|
|
691
714
|
add(...t) {
|
|
692
|
-
return
|
|
715
|
+
return d(this, w, C).call(this, "add", ...t);
|
|
693
716
|
}
|
|
694
717
|
sub(...t) {
|
|
695
|
-
return
|
|
718
|
+
return d(this, w, C).call(this, "sub", ...t);
|
|
696
719
|
}
|
|
697
720
|
mul(...t) {
|
|
698
|
-
return
|
|
721
|
+
return d(this, w, C).call(this, "mul", ...t);
|
|
699
722
|
}
|
|
700
723
|
div(...t) {
|
|
701
|
-
return
|
|
724
|
+
return d(this, w, C).call(this, "div", ...t);
|
|
702
725
|
}
|
|
703
726
|
gt(t) {
|
|
704
|
-
return
|
|
727
|
+
return d(this, b, $).call(this, "gt", t);
|
|
705
728
|
}
|
|
706
729
|
gte(t) {
|
|
707
|
-
return
|
|
730
|
+
return d(this, b, $).call(this, "gte", t);
|
|
708
731
|
}
|
|
709
732
|
lt(t) {
|
|
710
|
-
return
|
|
733
|
+
return d(this, b, $).call(this, "lt", t);
|
|
711
734
|
}
|
|
712
735
|
lte(t) {
|
|
713
|
-
return
|
|
736
|
+
return d(this, b, $).call(this, "lte", t);
|
|
714
737
|
}
|
|
715
738
|
eqValue(t) {
|
|
716
|
-
return
|
|
739
|
+
return d(this, b, $).call(this, "eqValue", t);
|
|
717
740
|
}
|
|
718
741
|
// @ts-expect-error False positive
|
|
719
742
|
getValue(t) {
|
|
720
743
|
const e = this.formatBigIntToSafeValue(
|
|
721
744
|
this.bigIntValue,
|
|
722
|
-
this.decimal ||
|
|
745
|
+
this.decimal || R(this.decimalMultiplier)
|
|
723
746
|
);
|
|
724
747
|
switch (t) {
|
|
725
748
|
case "number":
|
|
@@ -732,24 +755,24 @@ const K = class K {
|
|
|
732
755
|
}
|
|
733
756
|
// @ts-expect-error
|
|
734
757
|
getBaseValue(t) {
|
|
735
|
-
const e = this.decimalMultiplier /
|
|
758
|
+
const e = this.decimalMultiplier / y(this.decimal || m.THOR), r = this.bigIntValue / e;
|
|
736
759
|
switch (t) {
|
|
737
760
|
case "number":
|
|
738
|
-
return Number(
|
|
761
|
+
return Number(r);
|
|
739
762
|
case "string":
|
|
740
|
-
return
|
|
763
|
+
return r.toString();
|
|
741
764
|
case "bigint":
|
|
742
|
-
return
|
|
765
|
+
return r;
|
|
743
766
|
}
|
|
744
767
|
}
|
|
745
768
|
getBigIntValue(t, e) {
|
|
746
769
|
if (!e && typeof t == "object")
|
|
747
770
|
return t.bigIntValue;
|
|
748
|
-
const
|
|
749
|
-
return n === "0" || n === "undefined" ? 0n :
|
|
771
|
+
const r = Y(t), n = M(r);
|
|
772
|
+
return n === "0" || n === "undefined" ? 0n : d(this, E, G).call(this, n, e);
|
|
750
773
|
}
|
|
751
774
|
toSignificant(t = 6) {
|
|
752
|
-
const [e,
|
|
775
|
+
const [e, r] = this.getValue("string").split("."), n = e || "", i = r || "";
|
|
753
776
|
if ((parseInt(n) ? n.length + i.length : i.length) <= t)
|
|
754
777
|
return this.getValue("string");
|
|
755
778
|
if (n.length >= t)
|
|
@@ -766,7 +789,7 @@ const K = class K {
|
|
|
766
789
|
)}`;
|
|
767
790
|
}
|
|
768
791
|
toFixed(t = 6) {
|
|
769
|
-
const [e,
|
|
792
|
+
const [e, r] = this.getValue("string").split("."), n = e || "", i = r || "";
|
|
770
793
|
if (parseInt(n))
|
|
771
794
|
return `${n}.${i.slice(0, t)}`.padEnd(t, "0");
|
|
772
795
|
const c = parseInt(i), a = `${c}`.slice(0, t);
|
|
@@ -776,7 +799,7 @@ const K = class K {
|
|
|
776
799
|
)}`;
|
|
777
800
|
}
|
|
778
801
|
toAbbreviation(t = 2) {
|
|
779
|
-
const e = this.getValue("number"),
|
|
802
|
+
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];
|
|
780
803
|
if (!i)
|
|
781
804
|
return this.getValue("string");
|
|
782
805
|
const c = 10 ** (n * 3);
|
|
@@ -784,29 +807,29 @@ const K = class K {
|
|
|
784
807
|
}
|
|
785
808
|
toCurrency(t = "$", {
|
|
786
809
|
currencyPosition: e = "start",
|
|
787
|
-
decimal:
|
|
810
|
+
decimal: r = 2,
|
|
788
811
|
decimalSeparator: n = ".",
|
|
789
812
|
thousandSeparator: i = ","
|
|
790
813
|
} = {}) {
|
|
791
|
-
const c = this.getValue("number"), [a, u = ""] = c.toFixed(6).split("."),
|
|
814
|
+
const c = this.getValue("number"), [a, u = ""] = c.toFixed(6).split("."), h = a.replace(/\B(?=(\d{3})+(?!\d))/g, i), l = !a && !u ? "0.00" : a === "0" ? `${parseFloat(`0.${u}`)}`.replace(".", n) : `${h}${parseInt(u) ? `${n}${u.slice(0, r)}` : ""}`;
|
|
792
815
|
return `${e === "start" ? t : ""}${l}${e === "end" ? t : ""}`;
|
|
793
816
|
}
|
|
794
817
|
formatBigIntToSafeValue(t, e) {
|
|
795
|
-
const
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
), i = t < 0n, c = t.toString().substring(i ? 1 : 0), a = n - (c.length - 1), u = a > 0 ? "0".repeat(a) + c : c,
|
|
818
|
+
const r = e || this.decimal || I, n = Math.max(
|
|
819
|
+
r,
|
|
820
|
+
R(this.decimalMultiplier)
|
|
821
|
+
), i = t < 0n, c = t.toString().substring(i ? 1 : 0), a = n - (c.length - 1), u = a > 0 ? "0".repeat(a) + c : c, h = u.length - n;
|
|
799
822
|
let l = u.slice(-n);
|
|
800
|
-
return parseInt(l[
|
|
823
|
+
return parseInt(l[r]) >= 5 ? l = `${l.substring(0, r - 1)}${(parseInt(l[r - 1]) + 1).toString()}` : l = l.substring(0, r), `${i ? "-" : ""}${u.slice(
|
|
801
824
|
0,
|
|
802
|
-
|
|
825
|
+
h
|
|
803
826
|
)}.${l}`.replace(/\.?0*$/, "");
|
|
804
827
|
}
|
|
805
828
|
};
|
|
806
|
-
|
|
807
|
-
const
|
|
808
|
-
(u,
|
|
809
|
-
const l = this.getBigIntValue(
|
|
829
|
+
w = new WeakSet(), C = function(t, ...e) {
|
|
830
|
+
const r = d(this, O, W).call(this, this, ...e), n = Math.max(r, R(this.decimalMultiplier)), i = y(n), c = e.reduce(
|
|
831
|
+
(u, h) => {
|
|
832
|
+
const l = this.getBigIntValue(h, n);
|
|
810
833
|
switch (t) {
|
|
811
834
|
case "add":
|
|
812
835
|
return u + l;
|
|
@@ -825,19 +848,19 @@ v = new WeakSet(), R = function(t, ...e) {
|
|
|
825
848
|
},
|
|
826
849
|
//normalize is to precision multiplier base
|
|
827
850
|
this.bigIntValue * i / this.decimalMultiplier
|
|
828
|
-
), a =
|
|
851
|
+
), a = V({
|
|
829
852
|
bigIntDecimal: n,
|
|
830
853
|
decimal: n,
|
|
831
854
|
value: c
|
|
832
855
|
});
|
|
833
856
|
return new this.constructor({
|
|
834
|
-
decimalMultiplier:
|
|
857
|
+
decimalMultiplier: y(n),
|
|
835
858
|
decimal: this.decimal,
|
|
836
859
|
value: a,
|
|
837
860
|
identifier: this.toString()
|
|
838
861
|
});
|
|
839
|
-
},
|
|
840
|
-
const
|
|
862
|
+
}, b = new WeakSet(), $ = function(t, ...e) {
|
|
863
|
+
const r = d(this, O, W).call(this, this, ...e), n = this.getBigIntValue(e[0], r), i = this.getBigIntValue(this, r);
|
|
841
864
|
switch (t) {
|
|
842
865
|
case "gt":
|
|
843
866
|
return i > n;
|
|
@@ -850,50 +873,44 @@ v = new WeakSet(), R = function(t, ...e) {
|
|
|
850
873
|
case "eqValue":
|
|
851
874
|
return i === n;
|
|
852
875
|
}
|
|
853
|
-
},
|
|
854
|
-
const e =
|
|
855
|
-
this.bigIntValue =
|
|
856
|
-
}, O = new WeakSet(),
|
|
857
|
-
const e = t.map((
|
|
858
|
-
return Math.max(...e,
|
|
859
|
-
}, E = new WeakSet(),
|
|
860
|
-
const
|
|
876
|
+
}, N = new WeakSet(), lt = function(t) {
|
|
877
|
+
const e = M(t) || "0";
|
|
878
|
+
this.bigIntValue = d(this, E, G).call(this, e);
|
|
879
|
+
}, O = new WeakSet(), W = function(...t) {
|
|
880
|
+
const e = t.map((r) => typeof r == "object" ? r.decimal || R(r.decimalMultiplier) : rt(M(r))).filter(Boolean);
|
|
881
|
+
return Math.max(...e, I);
|
|
882
|
+
}, E = new WeakSet(), G = function(t, e) {
|
|
883
|
+
const r = e ? y(e) : this.decimalMultiplier, n = R(r), [i = "", c = ""] = t.split(".");
|
|
861
884
|
return BigInt(`${i}${c.padEnd(n, "0")}`);
|
|
862
885
|
};
|
|
863
|
-
let
|
|
864
|
-
const
|
|
886
|
+
let k = K;
|
|
887
|
+
const Zt = Intl.NumberFormat("fullwide", {
|
|
865
888
|
useGrouping: !1,
|
|
866
889
|
maximumFractionDigits: 20
|
|
867
890
|
});
|
|
868
|
-
function
|
|
869
|
-
const e = `${typeof
|
|
891
|
+
function M(s) {
|
|
892
|
+
const e = `${typeof s == "number" ? Zt.format(s) : Y(s)}`.replaceAll(",", ".").split(".");
|
|
870
893
|
return e.length > 1 ? `${e.slice(0, -1).join("")}.${e.at(-1)}` : e[0];
|
|
871
894
|
}
|
|
872
|
-
function
|
|
895
|
+
function rt(s) {
|
|
873
896
|
var e;
|
|
874
|
-
const t = ((e =
|
|
875
|
-
return Math.max(t,
|
|
897
|
+
const t = ((e = s.split(".")[1]) == null ? void 0 : e.length) || 0;
|
|
898
|
+
return Math.max(t, I);
|
|
876
899
|
}
|
|
877
|
-
function
|
|
878
|
-
return typeof
|
|
900
|
+
function Y(s) {
|
|
901
|
+
return typeof s == "object" ? "getValue" in s ? s.getValue("string") : s.value : s;
|
|
879
902
|
}
|
|
880
|
-
const
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
};
|
|
891
|
-
class A extends I {
|
|
892
|
-
constructor(e) {
|
|
893
|
-
const s = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`;
|
|
894
|
-
super(
|
|
895
|
-
e.value instanceof I ? e.value : { decimal: e.decimal, value: e.value }
|
|
896
|
-
);
|
|
903
|
+
const S = /* @__PURE__ */ new Map();
|
|
904
|
+
class T extends k {
|
|
905
|
+
constructor({
|
|
906
|
+
value: e,
|
|
907
|
+
decimal: r,
|
|
908
|
+
tax: n,
|
|
909
|
+
chain: i,
|
|
910
|
+
symbol: c,
|
|
911
|
+
identifier: a
|
|
912
|
+
}) {
|
|
913
|
+
super(typeof e == "object" ? e : { decimal: r, value: e });
|
|
897
914
|
f(this, "address");
|
|
898
915
|
f(this, "chain");
|
|
899
916
|
f(this, "isGasAsset", !1);
|
|
@@ -902,8 +919,8 @@ class A extends I {
|
|
|
902
919
|
f(this, "tax");
|
|
903
920
|
f(this, "ticker");
|
|
904
921
|
f(this, "type");
|
|
905
|
-
const
|
|
906
|
-
this.type =
|
|
922
|
+
const u = z(a || `${i}.${c}`);
|
|
923
|
+
this.type = It(u), this.tax = n, this.chain = u.chain, this.ticker = u.ticker, this.symbol = u.symbol, this.address = u.address, this.isSynthetic = u.isSynthetic, this.isGasAsset = u.isGasAsset;
|
|
907
924
|
}
|
|
908
925
|
toString() {
|
|
909
926
|
return this.isSynthetic ? this.symbol : `${this.chain}.${this.symbol}`;
|
|
@@ -911,57 +928,72 @@ class A extends I {
|
|
|
911
928
|
toUrl() {
|
|
912
929
|
return this.isSynthetic ? `${this.chain}.${this.symbol.replace("/", ".")}` : this.toString();
|
|
913
930
|
}
|
|
914
|
-
eq({ chain: e, symbol:
|
|
915
|
-
return this.chain === e && this.symbol ===
|
|
931
|
+
eq({ chain: e, symbol: r }) {
|
|
932
|
+
return this.chain === e && this.symbol === r;
|
|
916
933
|
}
|
|
917
934
|
// THOR.RUNE
|
|
918
935
|
// THOR.ETH.ETH
|
|
919
936
|
// ETH.THOR-0x1234567890
|
|
920
|
-
static fromUrl(e,
|
|
937
|
+
static fromUrl(e, r = 0) {
|
|
921
938
|
const [n, i, c] = e.split(".");
|
|
922
939
|
if (!n || !i)
|
|
923
940
|
throw new Error("Invalid asset url");
|
|
924
941
|
const a = n === o.THORChain && c ? `${n}.${i}/${c}` : e;
|
|
925
|
-
return L(a,
|
|
942
|
+
return L(a, r);
|
|
926
943
|
}
|
|
927
|
-
static fromString(e,
|
|
928
|
-
return L(e,
|
|
944
|
+
static fromString(e, r = 0) {
|
|
945
|
+
return L(e, r);
|
|
929
946
|
}
|
|
930
|
-
static
|
|
931
|
-
|
|
932
|
-
tax: i,
|
|
933
|
-
decimal: c,
|
|
934
|
-
identifier: a
|
|
935
|
-
} = rt(e), u = q(s, c);
|
|
936
|
-
return a ? new A({ tax: i, decimal: c, identifier: a, value: u }) : n ? new A({ tax: i, decimal: 8, identifier: e, value: u }) : void 0;
|
|
947
|
+
static fromIdentifier(e, r = 0) {
|
|
948
|
+
return L(e, r);
|
|
937
949
|
}
|
|
938
|
-
static
|
|
939
|
-
|
|
950
|
+
static fromStringSync(e, r = 0) {
|
|
951
|
+
const { isSynthetic: n } = z(e), i = S.get(e.toUpperCase());
|
|
952
|
+
if (!i) {
|
|
953
|
+
console.error(
|
|
954
|
+
`Asset ${e} is not loaded. Use AssetValue.loadStaticAssets() to load it`
|
|
955
|
+
);
|
|
956
|
+
return;
|
|
957
|
+
}
|
|
958
|
+
const { tax: c, decimal: a, identifier: u } = i;
|
|
959
|
+
return new T({
|
|
960
|
+
tax: c,
|
|
961
|
+
value: q(r, a),
|
|
962
|
+
identifier: n ? e : u,
|
|
963
|
+
decimal: n ? 8 : a
|
|
964
|
+
});
|
|
940
965
|
}
|
|
941
|
-
static fromIdentifierSync(e,
|
|
942
|
-
const
|
|
943
|
-
|
|
966
|
+
static fromIdentifierSync(e, r = 0) {
|
|
967
|
+
const n = S.get(e);
|
|
968
|
+
if (!n) {
|
|
969
|
+
console.error(
|
|
970
|
+
`Asset ${e} is not loaded. Use AssetValue.loadStaticAssets() to load it`
|
|
971
|
+
);
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
974
|
+
const { tax: i, decimal: c, identifier: a } = n;
|
|
975
|
+
return new T({ tax: i, decimal: c, identifier: a, value: q(r, c) });
|
|
944
976
|
}
|
|
945
|
-
static fromChainOrSignature(e,
|
|
946
|
-
const { decimal: n, identifier: i } =
|
|
947
|
-
return new
|
|
977
|
+
static fromChainOrSignature(e, r = 0) {
|
|
978
|
+
const { decimal: n, identifier: i } = St(e);
|
|
979
|
+
return new T({ value: q(r, n), decimal: n, identifier: i });
|
|
948
980
|
}
|
|
949
981
|
static loadStaticAssets() {
|
|
950
982
|
return new Promise(
|
|
951
|
-
async (e,
|
|
983
|
+
async (e, r) => {
|
|
952
984
|
try {
|
|
953
985
|
const n = await import("@swapkit/tokens");
|
|
954
|
-
|
|
955
|
-
var
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
identifier:
|
|
959
|
-
decimal: "decimals" in
|
|
986
|
+
Object.values(n).forEach((i) => {
|
|
987
|
+
var c;
|
|
988
|
+
(c = i == null ? void 0 : i.tokens) == null || c.forEach(({ identifier: a, chain: u, ...h }) => {
|
|
989
|
+
S.set(a.toUpperCase(), {
|
|
990
|
+
identifier: a,
|
|
991
|
+
decimal: "decimals" in h ? h.decimals : m[u]
|
|
960
992
|
});
|
|
961
|
-
})
|
|
962
|
-
}
|
|
993
|
+
});
|
|
994
|
+
}), e({ ok: !0 });
|
|
963
995
|
} catch (n) {
|
|
964
|
-
console.error(n),
|
|
996
|
+
console.error(n), r({
|
|
965
997
|
ok: !1,
|
|
966
998
|
error: n,
|
|
967
999
|
message: "Couldn't load static assets. Ensure you have installed @swapkit/tokens package"
|
|
@@ -971,9 +1003,9 @@ class A extends I {
|
|
|
971
1003
|
);
|
|
972
1004
|
}
|
|
973
1005
|
}
|
|
974
|
-
|
|
975
|
-
const t =
|
|
976
|
-
switch (
|
|
1006
|
+
function fe(s) {
|
|
1007
|
+
const t = T.fromChainOrSignature(s);
|
|
1008
|
+
switch (s) {
|
|
977
1009
|
case o.Bitcoin:
|
|
978
1010
|
case o.Litecoin:
|
|
979
1011
|
case o.BitcoinCash:
|
|
@@ -989,17 +1021,27 @@ const ge = (r) => {
|
|
|
989
1021
|
default:
|
|
990
1022
|
return t.set(1e-8);
|
|
991
1023
|
}
|
|
992
|
-
}
|
|
993
|
-
|
|
1024
|
+
}
|
|
1025
|
+
async function L(s, t = 0) {
|
|
1026
|
+
Xt(s);
|
|
1027
|
+
const e = S.get(s.toUpperCase()), r = (e == null ? void 0 : e.decimal) || await Ct(z(s));
|
|
1028
|
+
return e || S.set(s.toUpperCase(), { identifier: s, decimal: r }), new T({ decimal: r, value: q(t, r), identifier: s });
|
|
1029
|
+
}
|
|
1030
|
+
function q(s, t) {
|
|
1031
|
+
return typeof s == "bigint" ? V({ value: s, bigIntDecimal: t, decimal: t }) : s;
|
|
1032
|
+
}
|
|
1033
|
+
function z(s) {
|
|
1034
|
+
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("-");
|
|
994
1035
|
return {
|
|
995
1036
|
address: u == null ? void 0 : u.toLowerCase(),
|
|
996
1037
|
chain: i,
|
|
997
|
-
isGasAsset:
|
|
1038
|
+
isGasAsset: nt({ chain: i, symbol: c }),
|
|
998
1039
|
isSynthetic: t,
|
|
999
1040
|
symbol: (t ? `${e}/` : "") + (u ? `${a}-${(u == null ? void 0 : u.toLowerCase()) ?? ""}` : c),
|
|
1000
1041
|
ticker: a
|
|
1001
1042
|
};
|
|
1002
|
-
}
|
|
1043
|
+
}
|
|
1044
|
+
const te = {
|
|
1003
1045
|
/**
|
|
1004
1046
|
* Core
|
|
1005
1047
|
*/
|
|
@@ -1059,46 +1101,46 @@ const ge = (r) => {
|
|
|
1059
1101
|
};
|
|
1060
1102
|
class ht extends Error {
|
|
1061
1103
|
constructor(t, e) {
|
|
1062
|
-
console.error(e, { stack: e == null ? void 0 : e.stack, message: e == null ? void 0 : e.message }), super(t, { cause: { code:
|
|
1104
|
+
console.error(e, { stack: e == null ? void 0 : e.stack, message: e == null ? void 0 : e.message }), super(t, { cause: { code: te[t], message: t } }), Object.setPrototypeOf(this, ht.prototype);
|
|
1063
1105
|
}
|
|
1064
1106
|
}
|
|
1065
|
-
class
|
|
1107
|
+
class g extends k {
|
|
1066
1108
|
eq(t) {
|
|
1067
1109
|
return this.eqValue(t);
|
|
1068
1110
|
}
|
|
1069
1111
|
static fromBigInt(t, e) {
|
|
1070
|
-
return new
|
|
1112
|
+
return new g({
|
|
1071
1113
|
decimal: e,
|
|
1072
|
-
value:
|
|
1114
|
+
value: V({ value: t, bigIntDecimal: e, decimal: e })
|
|
1073
1115
|
});
|
|
1074
1116
|
}
|
|
1075
1117
|
}
|
|
1076
1118
|
export {
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1119
|
+
T as AssetValue,
|
|
1120
|
+
k as BigIntArithmetics,
|
|
1121
|
+
Qt as RequestClient,
|
|
1080
1122
|
ht as SwapKitError,
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1123
|
+
g as SwapKitNumber,
|
|
1124
|
+
ne as assetFromString,
|
|
1125
|
+
pe as derivationPathToString,
|
|
1126
|
+
ie as filterAssets,
|
|
1127
|
+
V as formatBigIntToSafeValue,
|
|
1128
|
+
se as gasFeeMultiplier,
|
|
1129
|
+
It as getAssetType,
|
|
1130
|
+
Mt as getAsymmetricAssetShare,
|
|
1131
|
+
ae as getAsymmetricAssetWithdrawAmount,
|
|
1090
1132
|
Bt as getAsymmetricRuneShare,
|
|
1091
|
-
|
|
1092
|
-
|
|
1133
|
+
oe as getAsymmetricRuneWithdrawAmount,
|
|
1134
|
+
St as getCommonAssetInfo,
|
|
1093
1135
|
Ct as getDecimal,
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1136
|
+
ue as getEstimatedPoolShare,
|
|
1137
|
+
le as getLiquiditySlippage,
|
|
1138
|
+
he as getMemoFor,
|
|
1139
|
+
fe as getMinAmountByChain,
|
|
1140
|
+
xt as getSymmetricPoolShare,
|
|
1141
|
+
ce as getSymmetricWithdraw,
|
|
1142
|
+
de as getTHORNameCost,
|
|
1143
|
+
nt as isGasAsset,
|
|
1144
|
+
me as validateTHORName
|
|
1103
1145
|
};
|
|
1104
1146
|
//# sourceMappingURL=index.es.js.map
|