@swapkit/helpers 1.0.0-rc.8 → 1.0.0-rc.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.es.js +709 -379
- package/package.json +8 -5
- package/src/helpers/asset.ts +7 -13
- package/src/helpers/others.ts +0 -48
- package/src/helpers/request.ts +16 -0
- package/src/index.ts +1 -0
- package/src/modules/__tests__/assetValue.test.ts +6 -7
package/dist/index.es.js
CHANGED
|
@@ -1,330 +1,661 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
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
|
|
8
|
-
if (t.has(
|
|
7
|
+
var y = (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 H, BaseDecimal as m, Chain as
|
|
14
|
-
const
|
|
15
|
-
if (n < 0)
|
|
16
|
-
throw new Error("Invalid number of year");
|
|
17
|
-
return 10 + n;
|
|
18
|
-
}, Ct = (n) => {
|
|
19
|
-
if (n.length > 30)
|
|
20
|
-
return !1;
|
|
21
|
-
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
22
|
-
return !!n.match(t);
|
|
23
|
-
}, Vt = ([n, t, e, r, s]) => `${n}'/${t}'/${e}'/${r}${typeof s != "number" ? "" : `/${s}`}`, Tt = async (n, t) => {
|
|
24
|
-
try {
|
|
25
|
-
const e = Object.entries(t || {}).reduce(
|
|
26
|
-
(s, [a, c]) => (c && (s[a] = c), s),
|
|
27
|
-
{}
|
|
28
|
-
);
|
|
29
|
-
return (await fetch(
|
|
30
|
-
`${n}${t ? `?${new URLSearchParams(e).toString()}` : ""}`,
|
|
31
|
-
{ method: "GET", mode: "cors", credentials: "omit", referrer: "https://sk.thorswap.net" }
|
|
32
|
-
)).json();
|
|
33
|
-
} catch (e) {
|
|
34
|
-
return console.error(e), {};
|
|
35
|
-
}
|
|
36
|
-
}, at = async (n, t, e, r = !1) => {
|
|
37
|
-
try {
|
|
38
|
-
const s = await fetch(`${n}`, {
|
|
39
|
-
body: t,
|
|
40
|
-
headers: e,
|
|
41
|
-
method: "POST",
|
|
42
|
-
referrer: "https://sk.thorswap.net"
|
|
43
|
-
});
|
|
44
|
-
return r ? s.text() : s.json();
|
|
45
|
-
} catch {
|
|
46
|
-
return {};
|
|
47
|
-
}
|
|
48
|
-
}, ct = "0x313ce567", Y = async ({ chain: n, to: t }) => {
|
|
12
|
+
var f = (s, t, e) => (bt(s, t, "access private method"), e);
|
|
13
|
+
import { FeeOption as H, BaseDecimal as m, Chain as o, ChainToRPC as yt, MemoType as g } from "@swapkit/types";
|
|
14
|
+
const wt = "0x313ce567", rt = async ({ chain: s, to: t }) => {
|
|
49
15
|
try {
|
|
50
|
-
const e = await
|
|
51
|
-
|
|
52
|
-
JSON.stringify({
|
|
53
|
-
method: "eth_call",
|
|
54
|
-
params: [{ to: t.toLowerCase(), data: ct }, "latest"],
|
|
16
|
+
const { result: e } = await zt.post(yt[s], {
|
|
17
|
+
headers: { accept: "*/*", "cache-control": "no-cache" },
|
|
18
|
+
body: JSON.stringify({
|
|
55
19
|
id: 44,
|
|
56
|
-
jsonrpc: "2.0"
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return parseInt(BigInt(
|
|
20
|
+
jsonrpc: "2.0",
|
|
21
|
+
method: "eth_call",
|
|
22
|
+
params: [{ to: t.toLowerCase(), data: wt }, "latest"]
|
|
23
|
+
})
|
|
24
|
+
});
|
|
25
|
+
return parseInt(BigInt(e).toString());
|
|
62
26
|
} catch (e) {
|
|
63
|
-
return console.error(e), m[
|
|
27
|
+
return console.error(e), m[s];
|
|
64
28
|
}
|
|
65
|
-
},
|
|
66
|
-
if (
|
|
29
|
+
}, At = async (s) => {
|
|
30
|
+
if (s === o.Ethereum)
|
|
67
31
|
return m.ETH;
|
|
68
|
-
const [, t] =
|
|
69
|
-
return t != null && t.startsWith("0x") ?
|
|
70
|
-
},
|
|
71
|
-
const [, t] =
|
|
72
|
-
return t != null && t.startsWith("0x") ?
|
|
73
|
-
},
|
|
74
|
-
switch (
|
|
75
|
-
case
|
|
76
|
-
return
|
|
77
|
-
case
|
|
78
|
-
return
|
|
79
|
-
case
|
|
80
|
-
return
|
|
32
|
+
const [, t] = s.split("-");
|
|
33
|
+
return t != null && t.startsWith("0x") ? rt({ chain: o.Ethereum, to: t }) : m.ETH;
|
|
34
|
+
}, Tt = async (s) => {
|
|
35
|
+
const [, t] = s.split("-");
|
|
36
|
+
return t != null && t.startsWith("0x") ? rt({ chain: o.Avalanche, to: t.toLowerCase() }) : m.AVAX;
|
|
37
|
+
}, Rt = async (s) => s === o.BinanceSmartChain ? m.BSC : m.BSC, st = async ({ chain: s, symbol: t }) => {
|
|
38
|
+
switch (s) {
|
|
39
|
+
case o.Ethereum:
|
|
40
|
+
return At(t);
|
|
41
|
+
case o.Avalanche:
|
|
42
|
+
return Tt(t);
|
|
43
|
+
case o.BinanceSmartChain:
|
|
44
|
+
return Rt(t);
|
|
81
45
|
default:
|
|
82
|
-
return m[
|
|
46
|
+
return m[s];
|
|
83
47
|
}
|
|
84
|
-
},
|
|
48
|
+
}, te = {
|
|
85
49
|
[H.Average]: 1.2,
|
|
86
50
|
[H.Fast]: 1.5,
|
|
87
51
|
[H.Fastest]: 2
|
|
88
|
-
},
|
|
89
|
-
switch (
|
|
90
|
-
case
|
|
91
|
-
case
|
|
92
|
-
case
|
|
93
|
-
case
|
|
94
|
-
case
|
|
95
|
-
case
|
|
96
|
-
case
|
|
97
|
-
return t ===
|
|
98
|
-
case
|
|
99
|
-
case
|
|
52
|
+
}, St = ({ chain: s, symbol: t }) => {
|
|
53
|
+
switch (s) {
|
|
54
|
+
case o.Bitcoin:
|
|
55
|
+
case o.BitcoinCash:
|
|
56
|
+
case o.Litecoin:
|
|
57
|
+
case o.Dogecoin:
|
|
58
|
+
case o.Binance:
|
|
59
|
+
case o.Ethereum:
|
|
60
|
+
case o.Avalanche:
|
|
61
|
+
return t === s;
|
|
62
|
+
case o.Arbitrum:
|
|
63
|
+
case o.Optimism:
|
|
100
64
|
return t === "ETH";
|
|
101
|
-
case
|
|
65
|
+
case o.Maya:
|
|
102
66
|
return t === "CACAO";
|
|
103
|
-
case
|
|
67
|
+
case o.Kujira:
|
|
104
68
|
return t === "KUJI";
|
|
105
|
-
case
|
|
69
|
+
case o.Cosmos:
|
|
106
70
|
return t === "ATOM";
|
|
107
|
-
case
|
|
71
|
+
case o.Polygon:
|
|
108
72
|
return t === "MATIC";
|
|
109
|
-
case
|
|
73
|
+
case o.BinanceSmartChain:
|
|
110
74
|
return t === "BNB";
|
|
111
|
-
case
|
|
75
|
+
case o.THORChain:
|
|
112
76
|
return t === "RUNE";
|
|
113
77
|
}
|
|
114
|
-
},
|
|
115
|
-
switch (
|
|
78
|
+
}, vt = (s) => {
|
|
79
|
+
switch (s) {
|
|
116
80
|
case "ETH.THOR":
|
|
117
81
|
return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
|
|
118
82
|
case "ETH.vTHOR":
|
|
119
83
|
return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
|
|
120
|
-
case
|
|
121
|
-
return { identifier: "GAIA.ATOM", decimal: m[
|
|
122
|
-
case
|
|
123
|
-
return { identifier: "THOR.RUNE", decimal: m[
|
|
124
|
-
case
|
|
125
|
-
return { identifier: "BSC.BNB", decimal: m[
|
|
126
|
-
case
|
|
84
|
+
case o.Cosmos:
|
|
85
|
+
return { identifier: "GAIA.ATOM", decimal: m[s] };
|
|
86
|
+
case o.THORChain:
|
|
87
|
+
return { identifier: "THOR.RUNE", decimal: m[s] };
|
|
88
|
+
case o.BinanceSmartChain:
|
|
89
|
+
return { identifier: "BSC.BNB", decimal: m[s] };
|
|
90
|
+
case o.Maya:
|
|
127
91
|
return { identifier: "MAYA.CACAO", decimal: m.MAYA };
|
|
128
92
|
case "MAYA.MAYA":
|
|
129
93
|
return { identifier: "MAYA.MAYA", decimal: 4 };
|
|
130
|
-
case
|
|
131
|
-
case
|
|
132
|
-
case
|
|
133
|
-
case
|
|
134
|
-
case
|
|
135
|
-
case
|
|
136
|
-
case
|
|
137
|
-
case
|
|
138
|
-
case
|
|
139
|
-
case
|
|
140
|
-
case
|
|
141
|
-
return { identifier: `${
|
|
142
|
-
}
|
|
143
|
-
},
|
|
94
|
+
case o.Kujira:
|
|
95
|
+
case o.Arbitrum:
|
|
96
|
+
case o.Optimism:
|
|
97
|
+
case o.BitcoinCash:
|
|
98
|
+
case o.Litecoin:
|
|
99
|
+
case o.Dogecoin:
|
|
100
|
+
case o.Binance:
|
|
101
|
+
case o.Avalanche:
|
|
102
|
+
case o.Polygon:
|
|
103
|
+
case o.Bitcoin:
|
|
104
|
+
case o.Ethereum:
|
|
105
|
+
return { identifier: `${s}.${s}`, decimal: m[s] };
|
|
106
|
+
}
|
|
107
|
+
}, Ct = ({ chain: s, symbol: t }) => {
|
|
144
108
|
if (t.includes("/"))
|
|
145
109
|
return "Synth";
|
|
146
|
-
switch (
|
|
147
|
-
case
|
|
148
|
-
case
|
|
149
|
-
case
|
|
150
|
-
case
|
|
151
|
-
case
|
|
152
|
-
case
|
|
110
|
+
switch (s) {
|
|
111
|
+
case o.Bitcoin:
|
|
112
|
+
case o.BitcoinCash:
|
|
113
|
+
case o.Dogecoin:
|
|
114
|
+
case o.Litecoin:
|
|
115
|
+
case o.Maya:
|
|
116
|
+
case o.THORChain:
|
|
153
117
|
return "Native";
|
|
154
|
-
case
|
|
155
|
-
return t === "ATOM" ? "Native" :
|
|
156
|
-
case
|
|
157
|
-
return t ===
|
|
158
|
-
case
|
|
159
|
-
return t ===
|
|
160
|
-
case
|
|
161
|
-
return t ===
|
|
162
|
-
case
|
|
163
|
-
return t ===
|
|
164
|
-
case
|
|
165
|
-
return t ===
|
|
166
|
-
case
|
|
167
|
-
return t ===
|
|
168
|
-
case
|
|
169
|
-
return [
|
|
170
|
-
case
|
|
171
|
-
return [
|
|
172
|
-
}
|
|
173
|
-
},
|
|
174
|
-
var
|
|
175
|
-
const [t, ...e] =
|
|
176
|
-
return { chain: t, symbol:
|
|
177
|
-
},
|
|
118
|
+
case o.Cosmos:
|
|
119
|
+
return t === "ATOM" ? "Native" : o.Cosmos;
|
|
120
|
+
case o.Kujira:
|
|
121
|
+
return t === o.Kujira ? "Native" : o.Kujira;
|
|
122
|
+
case o.Binance:
|
|
123
|
+
return t === o.Binance ? "Native" : "BEP2";
|
|
124
|
+
case o.BinanceSmartChain:
|
|
125
|
+
return t === o.Binance ? "Native" : "BEP20";
|
|
126
|
+
case o.Ethereum:
|
|
127
|
+
return t === o.Ethereum ? "Native" : "ERC20";
|
|
128
|
+
case o.Avalanche:
|
|
129
|
+
return t === o.Avalanche ? "Native" : o.Avalanche;
|
|
130
|
+
case o.Polygon:
|
|
131
|
+
return t === o.Polygon ? "Native" : "POLYGON";
|
|
132
|
+
case o.Arbitrum:
|
|
133
|
+
return [o.Ethereum, o.Arbitrum].includes(t) ? "Native" : "ARBITRUM";
|
|
134
|
+
case o.Optimism:
|
|
135
|
+
return [o.Ethereum, o.Optimism].includes(t) ? "Native" : "OPTIMISM";
|
|
136
|
+
}
|
|
137
|
+
}, ee = (s) => {
|
|
138
|
+
var a;
|
|
139
|
+
const [t, ...e] = s.split("."), r = s.includes("/"), n = e.join("."), i = (a = n == null ? void 0 : n.split("-")) == null ? void 0 : a[0];
|
|
140
|
+
return { chain: t, symbol: n, ticker: i, synth: r };
|
|
141
|
+
}, $t = new RegExp(
|
|
178
142
|
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
|
|
179
143
|
"gmi"
|
|
180
|
-
),
|
|
181
|
-
(t) =>
|
|
182
|
-
),
|
|
183
|
-
liquidityUnits:
|
|
144
|
+
), re = (s) => s.filter(
|
|
145
|
+
(t) => !$t.test(t.toString()) && !t.toString().includes("undefined")
|
|
146
|
+
), It = ({
|
|
147
|
+
liquidityUnits: s,
|
|
184
148
|
poolUnits: t,
|
|
185
149
|
runeDepth: e
|
|
186
150
|
}) => {
|
|
187
|
-
const r =
|
|
188
|
-
return
|
|
189
|
-
},
|
|
190
|
-
liquidityUnits:
|
|
151
|
+
const r = d(s), n = d(t), i = d(e), a = r.mul(i), c = n.mul(n).mul(2), u = n.mul(r).mul(2), l = r.mul(r), h = n.mul(n).mul(n);
|
|
152
|
+
return a.mul(c.sub(u).add(l)).div(h);
|
|
153
|
+
}, Et = ({
|
|
154
|
+
liquidityUnits: s,
|
|
191
155
|
poolUnits: t,
|
|
192
156
|
assetDepth: e
|
|
193
157
|
}) => {
|
|
194
|
-
const r =
|
|
195
|
-
return
|
|
196
|
-
},
|
|
197
|
-
percent:
|
|
158
|
+
const r = d(s), n = d(t), i = d(e), a = r.mul(i), c = n.mul(n).mul(2), u = n.mul(r).mul(2), l = r.mul(r), h = a.mul(c.sub(u).add(l)), _ = n.mul(n).mul(n);
|
|
159
|
+
return h.div(_);
|
|
160
|
+
}, se = ({
|
|
161
|
+
percent: s,
|
|
198
162
|
runeDepth: t,
|
|
199
163
|
liquidityUnits: e,
|
|
200
164
|
poolUnits: r
|
|
201
|
-
}) =>
|
|
202
|
-
percent:
|
|
165
|
+
}) => It({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), ne = ({
|
|
166
|
+
percent: s,
|
|
203
167
|
assetDepth: t,
|
|
204
168
|
liquidityUnits: e,
|
|
205
169
|
poolUnits: r
|
|
206
|
-
}) =>
|
|
207
|
-
liquidityUnits:
|
|
170
|
+
}) => Et({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), d = (s) => new Qt({ value: s, decimal: m.THOR }), Ot = ({
|
|
171
|
+
liquidityUnits: s,
|
|
208
172
|
poolUnits: t,
|
|
209
173
|
runeDepth: e,
|
|
210
174
|
assetDepth: r
|
|
211
175
|
}) => ({
|
|
212
|
-
assetAmount:
|
|
213
|
-
runeAmount:
|
|
214
|
-
}),
|
|
215
|
-
liquidityUnits:
|
|
176
|
+
assetAmount: d(r).mul(s).div(t),
|
|
177
|
+
runeAmount: d(e).mul(s).div(t)
|
|
178
|
+
}), ie = ({
|
|
179
|
+
liquidityUnits: s,
|
|
216
180
|
poolUnits: t,
|
|
217
181
|
runeDepth: e,
|
|
218
182
|
assetDepth: r,
|
|
219
|
-
percent:
|
|
183
|
+
percent: n
|
|
220
184
|
}) => Object.fromEntries(
|
|
221
|
-
Object.entries(
|
|
222
|
-
([
|
|
185
|
+
Object.entries(Ot({ liquidityUnits: s, poolUnits: t, runeDepth: e, assetDepth: r })).map(
|
|
186
|
+
([i, a]) => [i, a.mul(n)]
|
|
223
187
|
)
|
|
224
|
-
),
|
|
225
|
-
runeDepth:
|
|
188
|
+
), oe = ({
|
|
189
|
+
runeDepth: s,
|
|
226
190
|
poolUnits: t,
|
|
227
191
|
assetDepth: e,
|
|
228
192
|
liquidityUnits: r,
|
|
229
|
-
runeAmount: s,
|
|
230
|
-
assetAmount: a
|
|
231
|
-
}) => {
|
|
232
|
-
const c = h(n), o = h(e), u = h(t), l = h(s), d = h(a), A = l.mul(o), I = d.mul(c), R = l.mul(d), X = c.mul(o), Z = u.mul(A.add(I.add(R.mul(2)))), tt = A.add(I.add(X.mul(2))), F = Z.div(tt), k = h(r).add(F);
|
|
233
|
-
if (F.baseValueNumber === 0)
|
|
234
|
-
return k.div(u).baseValueNumber;
|
|
235
|
-
const et = u.add(k);
|
|
236
|
-
return k.div(et).baseValueNumber;
|
|
237
|
-
}, kt = ({
|
|
238
193
|
runeAmount: n,
|
|
194
|
+
assetAmount: i
|
|
195
|
+
}) => {
|
|
196
|
+
const a = d(s), c = d(e), u = d(t), l = d(n), h = d(i), _ = l.mul(c), T = h.mul(a), P = l.mul(h), dt = a.mul(c), mt = u.mul(_.add(T.add(P.mul(2)))), ft = _.add(T.add(dt.mul(2))), J = mt.div(ft), N = d(r).add(J);
|
|
197
|
+
if (J.baseValueNumber === 0)
|
|
198
|
+
return N.div(u).baseValueNumber;
|
|
199
|
+
const pt = u.add(N);
|
|
200
|
+
return N.div(pt).baseValueNumber;
|
|
201
|
+
}, ae = ({
|
|
202
|
+
runeAmount: s,
|
|
239
203
|
assetAmount: t,
|
|
240
204
|
runeDepth: e,
|
|
241
205
|
assetDepth: r
|
|
242
206
|
}) => {
|
|
243
|
-
const
|
|
207
|
+
const n = d(e), i = d(r), a = d(t), c = d(s), u = a.mul(n).sub(i.mul(c)), l = i.mul(c).add(n.mul(i));
|
|
244
208
|
return Math.abs(u.div(l).baseValueNumber);
|
|
245
|
-
},
|
|
246
|
-
symbol:
|
|
209
|
+
}, kt = ({
|
|
210
|
+
symbol: s,
|
|
247
211
|
ticker: t,
|
|
248
212
|
chain: e
|
|
249
|
-
}) => e === "ETH" && t !== "ETH" ? `${t}-${
|
|
250
|
-
switch (
|
|
251
|
-
case
|
|
252
|
-
case
|
|
213
|
+
}) => e === "ETH" && t !== "ETH" ? `${t}-${s.slice(-3)}` : s, ce = (s, t) => {
|
|
214
|
+
switch (s) {
|
|
215
|
+
case g.LEAVE:
|
|
216
|
+
case g.BOND: {
|
|
253
217
|
const { address: e } = t;
|
|
254
|
-
return `${
|
|
218
|
+
return `${s}:${e}`;
|
|
255
219
|
}
|
|
256
|
-
case
|
|
220
|
+
case g.UNBOND: {
|
|
257
221
|
const { address: e, unbondAmount: r } = t;
|
|
258
|
-
return `${
|
|
222
|
+
return `${s}:${e}:${r * 10 ** 8}`;
|
|
259
223
|
}
|
|
260
|
-
case
|
|
261
|
-
const { name: e, chain: r, address:
|
|
262
|
-
return `${
|
|
224
|
+
case g.THORNAME_REGISTER: {
|
|
225
|
+
const { name: e, chain: r, address: n, owner: i } = t;
|
|
226
|
+
return `${s}:${e}:${r}:${n}${i ? `:${i}` : ""}`;
|
|
263
227
|
}
|
|
264
|
-
case
|
|
265
|
-
const { chain: e, symbol: r, address:
|
|
266
|
-
return
|
|
228
|
+
case g.DEPOSIT: {
|
|
229
|
+
const { chain: e, symbol: r, address: n, singleSide: i } = t;
|
|
230
|
+
return i ? `${s}:${e}/${r}::t:0` : `${s}:${e}.${r}:${n || ""}:t:0`;
|
|
267
231
|
}
|
|
268
|
-
case
|
|
269
|
-
const { chain: e, ticker: r, symbol:
|
|
270
|
-
return `${
|
|
232
|
+
case g.WITHDRAW: {
|
|
233
|
+
const { chain: e, ticker: r, symbol: n, basisPoints: i, targetAssetString: a, singleSide: c } = t, u = !c && a ? `:${a}` : "", l = kt({ chain: e, symbol: n, ticker: r });
|
|
234
|
+
return `${s}:${e}${c ? "/" : "."}${l}:${i}${u}`;
|
|
271
235
|
}
|
|
272
|
-
case
|
|
273
|
-
case
|
|
236
|
+
case g.OPEN_LOAN:
|
|
237
|
+
case g.CLOSE_LOAN: {
|
|
274
238
|
const { asset: e, address: r } = t;
|
|
275
|
-
return `${
|
|
239
|
+
return `${s}:${e}:${r}`;
|
|
276
240
|
}
|
|
277
241
|
default:
|
|
278
242
|
return "";
|
|
279
243
|
}
|
|
280
|
-
},
|
|
281
|
-
|
|
282
|
-
|
|
244
|
+
}, ue = (s) => {
|
|
245
|
+
if (s < 0)
|
|
246
|
+
throw new Error("Invalid number of year");
|
|
247
|
+
return 10 + s;
|
|
248
|
+
}, le = (s) => {
|
|
249
|
+
if (s.length > 30)
|
|
250
|
+
return !1;
|
|
251
|
+
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
252
|
+
return !!s.match(t);
|
|
253
|
+
}, he = ([s, t, e, r, n]) => `${s}'/${t}'/${e}'/${r}${typeof n != "number" ? "" : `/${n}`}`;
|
|
254
|
+
class K extends Error {
|
|
255
|
+
constructor(t, e, r) {
|
|
256
|
+
const n = t.status || t.status === 0 ? t.status : "", i = t.statusText || "", a = `${n} ${i}`.trim(), c = a ? `status code ${a}` : "an unknown error";
|
|
257
|
+
super(`Request failed with ${c}`), Object.defineProperty(this, "response", {
|
|
258
|
+
enumerable: !0,
|
|
259
|
+
configurable: !0,
|
|
260
|
+
writable: !0,
|
|
261
|
+
value: void 0
|
|
262
|
+
}), Object.defineProperty(this, "request", {
|
|
263
|
+
enumerable: !0,
|
|
264
|
+
configurable: !0,
|
|
265
|
+
writable: !0,
|
|
266
|
+
value: void 0
|
|
267
|
+
}), Object.defineProperty(this, "options", {
|
|
268
|
+
enumerable: !0,
|
|
269
|
+
configurable: !0,
|
|
270
|
+
writable: !0,
|
|
271
|
+
value: void 0
|
|
272
|
+
}), this.name = "HTTPError", this.response = t, this.request = e, this.options = r;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
class nt extends Error {
|
|
276
|
+
constructor(t) {
|
|
277
|
+
super("Request timed out"), Object.defineProperty(this, "request", {
|
|
278
|
+
enumerable: !0,
|
|
279
|
+
configurable: !0,
|
|
280
|
+
writable: !0,
|
|
281
|
+
value: void 0
|
|
282
|
+
}), this.name = "TimeoutError", this.request = t;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
const V = (s) => s !== null && typeof s == "object", B = (...s) => {
|
|
286
|
+
for (const t of s)
|
|
287
|
+
if ((!V(t) || Array.isArray(t)) && t !== void 0)
|
|
288
|
+
throw new TypeError("The `options` argument must be an object");
|
|
289
|
+
return z({}, ...s);
|
|
290
|
+
}, it = (s = {}, t = {}) => {
|
|
291
|
+
const e = new globalThis.Headers(s), r = t instanceof globalThis.Headers, n = new globalThis.Headers(t);
|
|
292
|
+
for (const [i, a] of n.entries())
|
|
293
|
+
r && a === "undefined" || a === void 0 ? e.delete(i) : e.set(i, a);
|
|
294
|
+
return e;
|
|
295
|
+
}, z = (...s) => {
|
|
296
|
+
let t = {}, e = {};
|
|
297
|
+
for (const r of s)
|
|
298
|
+
if (Array.isArray(r))
|
|
299
|
+
Array.isArray(t) || (t = []), t = [...t, ...r];
|
|
300
|
+
else if (V(r)) {
|
|
301
|
+
for (let [n, i] of Object.entries(r))
|
|
302
|
+
V(i) && n in t && (i = z(t[n], i)), t = { ...t, [n]: i };
|
|
303
|
+
V(r.headers) && (e = it(e, r.headers), t.headers = e);
|
|
304
|
+
}
|
|
305
|
+
return t;
|
|
306
|
+
}, Bt = (() => {
|
|
307
|
+
let s = !1, t = !1;
|
|
308
|
+
const e = typeof globalThis.ReadableStream == "function", r = typeof globalThis.Request == "function";
|
|
309
|
+
return e && r && (t = new globalThis.Request("https://empty.invalid", {
|
|
310
|
+
body: new globalThis.ReadableStream(),
|
|
311
|
+
method: "POST",
|
|
312
|
+
// @ts-expect-error - Types are outdated.
|
|
313
|
+
get duplex() {
|
|
314
|
+
return s = !0, "half";
|
|
315
|
+
}
|
|
316
|
+
}).headers.has("Content-Type")), s && !t;
|
|
317
|
+
})(), Vt = typeof globalThis.AbortController == "function", qt = typeof globalThis.ReadableStream == "function", Mt = typeof globalThis.FormData == "function", ot = ["get", "post", "put", "patch", "head", "delete"], xt = {
|
|
318
|
+
json: "application/json",
|
|
319
|
+
text: "text/*",
|
|
320
|
+
formData: "multipart/form-data",
|
|
321
|
+
arrayBuffer: "*/*",
|
|
322
|
+
blob: "*/*"
|
|
323
|
+
}, j = 2147483647, at = Symbol("stop"), Pt = {
|
|
324
|
+
json: !0,
|
|
325
|
+
parseJson: !0,
|
|
326
|
+
searchParams: !0,
|
|
327
|
+
prefixUrl: !0,
|
|
328
|
+
retry: !0,
|
|
329
|
+
timeout: !0,
|
|
330
|
+
hooks: !0,
|
|
331
|
+
throwHttpErrors: !0,
|
|
332
|
+
onDownloadProgress: !0,
|
|
333
|
+
fetch: !0
|
|
334
|
+
}, Nt = {
|
|
335
|
+
method: !0,
|
|
336
|
+
headers: !0,
|
|
337
|
+
body: !0,
|
|
338
|
+
mode: !0,
|
|
339
|
+
credentials: !0,
|
|
340
|
+
cache: !0,
|
|
341
|
+
redirect: !0,
|
|
342
|
+
referrer: !0,
|
|
343
|
+
referrerPolicy: !0,
|
|
344
|
+
integrity: !0,
|
|
345
|
+
keepalive: !0,
|
|
346
|
+
signal: !0,
|
|
347
|
+
window: !0,
|
|
348
|
+
dispatcher: !0,
|
|
349
|
+
duplex: !0
|
|
350
|
+
}, Ht = (s) => ot.includes(s) ? s.toUpperCase() : s, jt = ["get", "put", "head", "delete", "options", "trace"], Lt = [408, 413, 429, 500, 502, 503, 504], ct = [413, 429, 503], Q = {
|
|
351
|
+
limit: 2,
|
|
352
|
+
methods: jt,
|
|
353
|
+
statusCodes: Lt,
|
|
354
|
+
afterStatusCodes: ct,
|
|
355
|
+
maxRetryAfter: Number.POSITIVE_INFINITY,
|
|
356
|
+
backoffLimit: Number.POSITIVE_INFINITY,
|
|
357
|
+
delay: (s) => 0.3 * 2 ** (s - 1) * 1e3
|
|
358
|
+
}, Dt = (s = {}) => {
|
|
359
|
+
if (typeof s == "number")
|
|
360
|
+
return {
|
|
361
|
+
...Q,
|
|
362
|
+
limit: s
|
|
363
|
+
};
|
|
364
|
+
if (s.methods && !Array.isArray(s.methods))
|
|
365
|
+
throw new Error("retry.methods must be an array");
|
|
366
|
+
if (s.statusCodes && !Array.isArray(s.statusCodes))
|
|
367
|
+
throw new Error("retry.statusCodes must be an array");
|
|
368
|
+
return {
|
|
369
|
+
...Q,
|
|
370
|
+
...s,
|
|
371
|
+
afterStatusCodes: ct
|
|
372
|
+
};
|
|
373
|
+
};
|
|
374
|
+
async function Ut(s, t, e, r) {
|
|
375
|
+
return new Promise((n, i) => {
|
|
376
|
+
const a = setTimeout(() => {
|
|
377
|
+
e && e.abort(), i(new nt(s));
|
|
378
|
+
}, r.timeout);
|
|
379
|
+
r.fetch(s, t).then(n).catch(i).then(() => {
|
|
380
|
+
clearTimeout(a);
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
async function Ft(s, { signal: t }) {
|
|
385
|
+
return new Promise((e, r) => {
|
|
386
|
+
t && (t.throwIfAborted(), t.addEventListener("abort", n, { once: !0 }));
|
|
387
|
+
function n() {
|
|
388
|
+
clearTimeout(i), r(t.reason);
|
|
389
|
+
}
|
|
390
|
+
const i = setTimeout(() => {
|
|
391
|
+
t == null || t.removeEventListener("abort", n), e();
|
|
392
|
+
}, s);
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
const Wt = (s, t) => {
|
|
396
|
+
const e = {};
|
|
397
|
+
for (const r in t)
|
|
398
|
+
!(r in Nt) && !(r in Pt) && !(r in s) && (e[r] = t[r]);
|
|
399
|
+
return e;
|
|
400
|
+
};
|
|
401
|
+
class q {
|
|
402
|
+
static create(t, e) {
|
|
403
|
+
const r = new q(t, e), n = async () => {
|
|
404
|
+
if (typeof r._options.timeout == "number" && r._options.timeout > j)
|
|
405
|
+
throw new RangeError(`The \`timeout\` option cannot be greater than ${j}`);
|
|
406
|
+
await Promise.resolve();
|
|
407
|
+
let c = await r._fetch();
|
|
408
|
+
for (const u of r._options.hooks.afterResponse) {
|
|
409
|
+
const l = await u(r.request, r._options, r._decorateResponse(c.clone()));
|
|
410
|
+
l instanceof globalThis.Response && (c = l);
|
|
411
|
+
}
|
|
412
|
+
if (r._decorateResponse(c), !c.ok && r._options.throwHttpErrors) {
|
|
413
|
+
let u = new K(c, r.request, r._options);
|
|
414
|
+
for (const l of r._options.hooks.beforeError)
|
|
415
|
+
u = await l(u);
|
|
416
|
+
throw u;
|
|
417
|
+
}
|
|
418
|
+
if (r._options.onDownloadProgress) {
|
|
419
|
+
if (typeof r._options.onDownloadProgress != "function")
|
|
420
|
+
throw new TypeError("The `onDownloadProgress` option must be a function");
|
|
421
|
+
if (!qt)
|
|
422
|
+
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
|
|
423
|
+
return r._stream(c.clone(), r._options.onDownloadProgress);
|
|
424
|
+
}
|
|
425
|
+
return c;
|
|
426
|
+
}, a = r._options.retry.methods.includes(r.request.method.toLowerCase()) ? r._retry(n) : n();
|
|
427
|
+
for (const [c, u] of Object.entries(xt))
|
|
428
|
+
a[c] = async () => {
|
|
429
|
+
r.request.headers.set("accept", r.request.headers.get("accept") || u);
|
|
430
|
+
const h = (await a).clone();
|
|
431
|
+
if (c === "json") {
|
|
432
|
+
if (h.status === 204 || (await h.clone().arrayBuffer()).byteLength === 0)
|
|
433
|
+
return "";
|
|
434
|
+
if (e.parseJson)
|
|
435
|
+
return e.parseJson(await h.text());
|
|
436
|
+
}
|
|
437
|
+
return h[c]();
|
|
438
|
+
};
|
|
439
|
+
return a;
|
|
440
|
+
}
|
|
441
|
+
// eslint-disable-next-line complexity
|
|
442
|
+
constructor(t, e = {}) {
|
|
443
|
+
if (Object.defineProperty(this, "request", {
|
|
444
|
+
enumerable: !0,
|
|
445
|
+
configurable: !0,
|
|
446
|
+
writable: !0,
|
|
447
|
+
value: void 0
|
|
448
|
+
}), Object.defineProperty(this, "abortController", {
|
|
449
|
+
enumerable: !0,
|
|
450
|
+
configurable: !0,
|
|
451
|
+
writable: !0,
|
|
452
|
+
value: void 0
|
|
453
|
+
}), Object.defineProperty(this, "_retryCount", {
|
|
454
|
+
enumerable: !0,
|
|
455
|
+
configurable: !0,
|
|
456
|
+
writable: !0,
|
|
457
|
+
value: 0
|
|
458
|
+
}), Object.defineProperty(this, "_input", {
|
|
459
|
+
enumerable: !0,
|
|
460
|
+
configurable: !0,
|
|
461
|
+
writable: !0,
|
|
462
|
+
value: void 0
|
|
463
|
+
}), Object.defineProperty(this, "_options", {
|
|
464
|
+
enumerable: !0,
|
|
465
|
+
configurable: !0,
|
|
466
|
+
writable: !0,
|
|
467
|
+
value: void 0
|
|
468
|
+
}), this._input = t, this._options = {
|
|
469
|
+
// TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208
|
|
470
|
+
credentials: this._input.credentials || "same-origin",
|
|
471
|
+
...e,
|
|
472
|
+
headers: it(this._input.headers, e.headers),
|
|
473
|
+
hooks: z({
|
|
474
|
+
beforeRequest: [],
|
|
475
|
+
beforeRetry: [],
|
|
476
|
+
beforeError: [],
|
|
477
|
+
afterResponse: []
|
|
478
|
+
}, e.hooks),
|
|
479
|
+
method: Ht(e.method ?? this._input.method),
|
|
480
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
481
|
+
prefixUrl: String(e.prefixUrl || ""),
|
|
482
|
+
retry: Dt(e.retry),
|
|
483
|
+
throwHttpErrors: e.throwHttpErrors !== !1,
|
|
484
|
+
timeout: e.timeout ?? 1e4,
|
|
485
|
+
fetch: e.fetch ?? globalThis.fetch.bind(globalThis)
|
|
486
|
+
}, typeof this._input != "string" && !(this._input instanceof URL || this._input instanceof globalThis.Request))
|
|
487
|
+
throw new TypeError("`input` must be a string, URL, or Request");
|
|
488
|
+
if (this._options.prefixUrl && typeof this._input == "string") {
|
|
489
|
+
if (this._input.startsWith("/"))
|
|
490
|
+
throw new Error("`input` must not begin with a slash when using `prefixUrl`");
|
|
491
|
+
this._options.prefixUrl.endsWith("/") || (this._options.prefixUrl += "/"), this._input = this._options.prefixUrl + this._input;
|
|
492
|
+
}
|
|
493
|
+
if (Vt) {
|
|
494
|
+
if (this.abortController = new globalThis.AbortController(), this._options.signal) {
|
|
495
|
+
const r = this._options.signal;
|
|
496
|
+
this._options.signal.addEventListener("abort", () => {
|
|
497
|
+
this.abortController.abort(r.reason);
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
this._options.signal = this.abortController.signal;
|
|
501
|
+
}
|
|
502
|
+
if (Bt && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
|
|
503
|
+
const n = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), i = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, n);
|
|
504
|
+
(Mt && 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);
|
|
505
|
+
}
|
|
506
|
+
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 }));
|
|
507
|
+
}
|
|
508
|
+
_calculateRetryDelay(t) {
|
|
509
|
+
if (this._retryCount++, this._retryCount < this._options.retry.limit && !(t instanceof nt)) {
|
|
510
|
+
if (t instanceof K) {
|
|
511
|
+
if (!this._options.retry.statusCodes.includes(t.response.status))
|
|
512
|
+
return 0;
|
|
513
|
+
const r = t.response.headers.get("Retry-After");
|
|
514
|
+
if (r && this._options.retry.afterStatusCodes.includes(t.response.status)) {
|
|
515
|
+
let n = Number(r);
|
|
516
|
+
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;
|
|
517
|
+
}
|
|
518
|
+
if (t.response.status === 413)
|
|
519
|
+
return 0;
|
|
520
|
+
}
|
|
521
|
+
const e = this._options.retry.delay(this._retryCount);
|
|
522
|
+
return Math.min(this._options.retry.backoffLimit, e);
|
|
523
|
+
}
|
|
524
|
+
return 0;
|
|
525
|
+
}
|
|
526
|
+
_decorateResponse(t) {
|
|
527
|
+
return this._options.parseJson && (t.json = async () => this._options.parseJson(await t.text())), t;
|
|
528
|
+
}
|
|
529
|
+
async _retry(t) {
|
|
530
|
+
try {
|
|
531
|
+
return await t();
|
|
532
|
+
} catch (e) {
|
|
533
|
+
const r = Math.min(this._calculateRetryDelay(e), j);
|
|
534
|
+
if (r !== 0 && this._retryCount > 0) {
|
|
535
|
+
await Ft(r, { signal: this._options.signal });
|
|
536
|
+
for (const n of this._options.hooks.beforeRetry)
|
|
537
|
+
if (await n({
|
|
538
|
+
request: this.request,
|
|
539
|
+
options: this._options,
|
|
540
|
+
error: e,
|
|
541
|
+
retryCount: this._retryCount
|
|
542
|
+
}) === at)
|
|
543
|
+
return;
|
|
544
|
+
return this._retry(t);
|
|
545
|
+
}
|
|
546
|
+
throw e;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
async _fetch() {
|
|
550
|
+
for (const e of this._options.hooks.beforeRequest) {
|
|
551
|
+
const r = await e(this.request, this._options);
|
|
552
|
+
if (r instanceof Request) {
|
|
553
|
+
this.request = r;
|
|
554
|
+
break;
|
|
555
|
+
}
|
|
556
|
+
if (r instanceof Response)
|
|
557
|
+
return r;
|
|
558
|
+
}
|
|
559
|
+
const t = Wt(this.request, this._options);
|
|
560
|
+
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Ut(this.request.clone(), t, this.abortController, this._options);
|
|
561
|
+
}
|
|
562
|
+
/* istanbul ignore next */
|
|
563
|
+
_stream(t, e) {
|
|
564
|
+
const r = Number(t.headers.get("content-length")) || 0;
|
|
565
|
+
let n = 0;
|
|
566
|
+
return t.status === 204 ? (e && e({ percent: 1, totalBytes: r, transferredBytes: n }, new Uint8Array()), new globalThis.Response(null, {
|
|
567
|
+
status: t.status,
|
|
568
|
+
statusText: t.statusText,
|
|
569
|
+
headers: t.headers
|
|
570
|
+
})) : new globalThis.Response(new globalThis.ReadableStream({
|
|
571
|
+
async start(i) {
|
|
572
|
+
const a = t.body.getReader();
|
|
573
|
+
e && e({ percent: 0, transferredBytes: 0, totalBytes: r }, new Uint8Array());
|
|
574
|
+
async function c() {
|
|
575
|
+
const { done: u, value: l } = await a.read();
|
|
576
|
+
if (u) {
|
|
577
|
+
i.close();
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
if (e) {
|
|
581
|
+
n += l.byteLength;
|
|
582
|
+
const h = r === 0 ? 0 : n / r;
|
|
583
|
+
e({ percent: h, transferredBytes: n, totalBytes: r }, l);
|
|
584
|
+
}
|
|
585
|
+
i.enqueue(l), await c();
|
|
586
|
+
}
|
|
587
|
+
await c();
|
|
588
|
+
}
|
|
589
|
+
}), {
|
|
590
|
+
status: t.status,
|
|
591
|
+
statusText: t.statusText,
|
|
592
|
+
headers: t.headers
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
/*! MIT License © Sindre Sorhus */
|
|
597
|
+
const U = (s) => {
|
|
598
|
+
const t = (e, r) => q.create(e, B(s, r));
|
|
599
|
+
for (const e of ot)
|
|
600
|
+
t[e] = (r, n) => q.create(r, B(s, n, { method: e }));
|
|
601
|
+
return t.create = (e) => U(B(e)), t.extend = (e) => U(B(s, e)), t.stop = at, t;
|
|
602
|
+
}, Gt = U(), Yt = Gt, X = Yt.create({
|
|
603
|
+
headers: {
|
|
604
|
+
referrer: "https://sk.thorswap.net",
|
|
605
|
+
referer: "https://sk.thorswap.net",
|
|
606
|
+
"Content-Type": "application/json"
|
|
607
|
+
}
|
|
608
|
+
}), zt = {
|
|
609
|
+
get: (s, t) => X.get(s, t).json(),
|
|
610
|
+
post: (s, t) => X.post(s, t).json()
|
|
611
|
+
}, Z = Object.values(o), Jt = (s = "") => {
|
|
612
|
+
const t = s.toUpperCase(), [e] = t.split(".");
|
|
613
|
+
if (Z.includes(e))
|
|
283
614
|
return !0;
|
|
284
615
|
const [r] = t.split("/");
|
|
285
|
-
if (
|
|
616
|
+
if (Z.includes(r))
|
|
286
617
|
return !0;
|
|
287
618
|
throw new Error(
|
|
288
|
-
`Invalid identifier: ${
|
|
619
|
+
`Invalid identifier: ${s}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
289
620
|
);
|
|
290
|
-
},
|
|
291
|
-
function
|
|
292
|
-
value:
|
|
293
|
-
bigIntDecimal: t =
|
|
294
|
-
decimal: e =
|
|
621
|
+
}, $ = 8, R = (s) => 10n ** BigInt(s), S = (s) => Math.log10(parseFloat(s.toString()));
|
|
622
|
+
function tt({
|
|
623
|
+
value: s,
|
|
624
|
+
bigIntDecimal: t = $,
|
|
625
|
+
decimal: e = $
|
|
295
626
|
}) {
|
|
296
|
-
const r =
|
|
297
|
-
let
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
const
|
|
301
|
-
let
|
|
302
|
-
return parseInt(
|
|
627
|
+
const r = s < 0n;
|
|
628
|
+
let n = s.toString().substring(r ? 1 : 0);
|
|
629
|
+
const i = e - (n.length - 1);
|
|
630
|
+
i > 0 && (n = "0".repeat(i) + n);
|
|
631
|
+
const a = n.length - e;
|
|
632
|
+
let c = n.slice(-e);
|
|
633
|
+
return parseInt(c[t]) >= 5 ? c = `${c.substring(0, t - 1)}${(parseInt(c[t - 1]) + 1).toString()}` : c = c.substring(0, t), `${r ? "-" : ""}${n.slice(0, a)}.${c}`.replace(
|
|
303
634
|
/\.?0*$/,
|
|
304
635
|
""
|
|
305
636
|
);
|
|
306
637
|
}
|
|
307
|
-
var w,
|
|
308
|
-
const
|
|
638
|
+
var w, v, M, ut, x, lt, O, F, A, C, k, W;
|
|
639
|
+
const I = class I {
|
|
309
640
|
constructor(t) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
const e =
|
|
320
|
-
this.decimal = typeof t == "object" ? t.decimal : void 0, this.decimalMultiplier =
|
|
321
|
-
Math.max(
|
|
322
|
-
),
|
|
641
|
+
y(this, w);
|
|
642
|
+
y(this, M);
|
|
643
|
+
y(this, x);
|
|
644
|
+
y(this, O);
|
|
645
|
+
y(this, A);
|
|
646
|
+
y(this, k);
|
|
647
|
+
p(this, "decimalMultiplier", 10n ** 8n);
|
|
648
|
+
p(this, "bigIntValue", 0n);
|
|
649
|
+
p(this, "decimal");
|
|
650
|
+
const e = L(t);
|
|
651
|
+
this.decimal = typeof t == "object" ? t.decimal : void 0, this.decimalMultiplier = R(
|
|
652
|
+
Math.max(f(this, k, W).call(this, f(this, A, C).call(this, e)), this.decimal || 0)
|
|
653
|
+
), f(this, M, ut).call(this, e);
|
|
323
654
|
}
|
|
324
655
|
static fromBigInt(t, e) {
|
|
325
|
-
return new
|
|
656
|
+
return new I({
|
|
326
657
|
decimal: e,
|
|
327
|
-
value:
|
|
658
|
+
value: tt({ value: t, bigIntDecimal: e, decimal: e })
|
|
328
659
|
});
|
|
329
660
|
}
|
|
330
661
|
static shiftDecimals({
|
|
@@ -332,8 +663,8 @@ const B = class B {
|
|
|
332
663
|
from: e,
|
|
333
664
|
to: r
|
|
334
665
|
}) {
|
|
335
|
-
return
|
|
336
|
-
new
|
|
666
|
+
return I.fromBigInt(
|
|
667
|
+
new I(t).bigIntValue * R(r) / R(e),
|
|
337
668
|
r
|
|
338
669
|
);
|
|
339
670
|
}
|
|
@@ -359,16 +690,16 @@ const B = class B {
|
|
|
359
690
|
return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
|
|
360
691
|
}
|
|
361
692
|
add(...t) {
|
|
362
|
-
return
|
|
693
|
+
return f(this, w, v).call(this, "add", ...t);
|
|
363
694
|
}
|
|
364
695
|
sub(...t) {
|
|
365
|
-
return
|
|
696
|
+
return f(this, w, v).call(this, "sub", ...t);
|
|
366
697
|
}
|
|
367
698
|
mul(...t) {
|
|
368
|
-
return
|
|
699
|
+
return f(this, w, v).call(this, "mul", ...t);
|
|
369
700
|
}
|
|
370
701
|
div(...t) {
|
|
371
|
-
return
|
|
702
|
+
return f(this, w, v).call(this, "div", ...t);
|
|
372
703
|
}
|
|
373
704
|
gt(t) {
|
|
374
705
|
return this.bigIntValue > this.getBigIntValue(t);
|
|
@@ -388,7 +719,7 @@ const B = class B {
|
|
|
388
719
|
getValue(t) {
|
|
389
720
|
const e = this.formatBigIntToSafeValue(
|
|
390
721
|
this.bigIntValue,
|
|
391
|
-
this.decimal ||
|
|
722
|
+
this.decimal || S(this.decimalMultiplier)
|
|
392
723
|
);
|
|
393
724
|
switch (t) {
|
|
394
725
|
case "number":
|
|
@@ -400,7 +731,7 @@ const B = class B {
|
|
|
400
731
|
}
|
|
401
732
|
}
|
|
402
733
|
getBaseValue(t) {
|
|
403
|
-
const e = this.decimalMultiplier /
|
|
734
|
+
const e = this.decimalMultiplier / R(this.decimal || m.THOR), r = this.bigIntValue / e;
|
|
404
735
|
switch (t) {
|
|
405
736
|
case "number":
|
|
406
737
|
return Number(r);
|
|
@@ -413,116 +744,116 @@ const B = class B {
|
|
|
413
744
|
getBigIntValue(t, e) {
|
|
414
745
|
if (!e && typeof t == "object")
|
|
415
746
|
return t.bigIntValue;
|
|
416
|
-
const r =
|
|
417
|
-
return
|
|
747
|
+
const r = L(t), n = f(this, A, C).call(this, r);
|
|
748
|
+
return n === "0" || n === "undefined" ? 0n : f(this, O, F).call(this, n, e);
|
|
418
749
|
}
|
|
419
750
|
formatBigIntToSafeValue(t, e) {
|
|
420
|
-
const r = e || this.decimal ||
|
|
751
|
+
const r = e || this.decimal || $, n = Math.max(
|
|
421
752
|
r,
|
|
422
|
-
|
|
423
|
-
),
|
|
424
|
-
let
|
|
425
|
-
return parseInt(
|
|
753
|
+
S(this.decimalMultiplier)
|
|
754
|
+
), i = t < 0n, a = t.toString().substring(i ? 1 : 0), c = n - (a.length - 1), u = c > 0 ? "0".repeat(c) + a : a, l = u.length - n;
|
|
755
|
+
let h = u.slice(-n);
|
|
756
|
+
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(
|
|
426
757
|
0,
|
|
427
758
|
l
|
|
428
|
-
)}.${
|
|
759
|
+
)}.${h}`.replace(/\.?0*$/, "");
|
|
429
760
|
}
|
|
430
761
|
toSignificant(t = 6) {
|
|
431
|
-
const [e, r] = this.getValue("string").split("."),
|
|
432
|
-
if (
|
|
762
|
+
const [e, r] = this.getValue("string").split("."), n = e || "", i = r || "", a = parseInt(n) ? n.length + i.length : i.length;
|
|
763
|
+
if (a <= t)
|
|
433
764
|
return this.getValue("string");
|
|
434
|
-
if (
|
|
435
|
-
return
|
|
436
|
-
if (parseInt(
|
|
437
|
-
return `${
|
|
438
|
-
|
|
765
|
+
if (n.length >= t)
|
|
766
|
+
return n.slice(0, t).padEnd(n.length, "0");
|
|
767
|
+
if (parseInt(n))
|
|
768
|
+
return `${n}.${i.slice(0, t - n.length)}`.padEnd(
|
|
769
|
+
a - t,
|
|
439
770
|
"0"
|
|
440
771
|
);
|
|
441
|
-
const
|
|
772
|
+
const c = parseInt(i), u = `${c}`.slice(0, t);
|
|
442
773
|
return `0.${u.padStart(
|
|
443
|
-
|
|
774
|
+
i.length - `${c}`.length + u.length,
|
|
444
775
|
"0"
|
|
445
776
|
)}`;
|
|
446
777
|
}
|
|
447
778
|
};
|
|
448
|
-
w = new WeakSet(),
|
|
449
|
-
const r =
|
|
450
|
-
(
|
|
779
|
+
w = new WeakSet(), v = function(t, ...e) {
|
|
780
|
+
const r = f(this, x, lt).call(this, this, ...e), n = R(r), i = e.reduce(
|
|
781
|
+
(c, u) => {
|
|
451
782
|
const l = this.getBigIntValue(u, r);
|
|
452
783
|
switch (t) {
|
|
453
784
|
case "add":
|
|
454
|
-
return
|
|
785
|
+
return c + l;
|
|
455
786
|
case "sub":
|
|
456
|
-
return
|
|
787
|
+
return c - l;
|
|
457
788
|
case "mul":
|
|
458
|
-
return
|
|
789
|
+
return c * l / n;
|
|
459
790
|
case "div": {
|
|
460
791
|
if (l === 0n)
|
|
461
792
|
throw new RangeError("Division by zero");
|
|
462
|
-
return
|
|
793
|
+
return c * n / l;
|
|
463
794
|
}
|
|
464
795
|
default:
|
|
465
|
-
return
|
|
796
|
+
return c;
|
|
466
797
|
}
|
|
467
798
|
},
|
|
468
799
|
//normalize is to precision multiplier base
|
|
469
|
-
this.bigIntValue *
|
|
470
|
-
),
|
|
800
|
+
this.bigIntValue * n / this.decimalMultiplier
|
|
801
|
+
), a = tt({
|
|
471
802
|
bigIntDecimal: r,
|
|
472
|
-
decimal: Math.max(r,
|
|
473
|
-
value:
|
|
803
|
+
decimal: Math.max(r, S(this.decimalMultiplier)),
|
|
804
|
+
value: i
|
|
474
805
|
});
|
|
475
|
-
return new this.constructor({ decimal: this.decimal, value:
|
|
476
|
-
}, M = new WeakSet(),
|
|
477
|
-
const e =
|
|
478
|
-
this.bigIntValue =
|
|
479
|
-
},
|
|
806
|
+
return new this.constructor({ decimal: this.decimal, value: a, identifier: this.toString() });
|
|
807
|
+
}, M = new WeakSet(), ut = function(t) {
|
|
808
|
+
const e = f(this, A, C).call(this, t) || "0";
|
|
809
|
+
this.bigIntValue = f(this, O, F).call(this, e);
|
|
810
|
+
}, x = new WeakSet(), lt = function(...t) {
|
|
480
811
|
const e = t.map(
|
|
481
|
-
(r) => typeof r == "object" ? r.decimal ||
|
|
812
|
+
(r) => typeof r == "object" ? r.decimal || S(r.decimalMultiplier) : f(this, k, W).call(this, f(this, A, C).call(this, r))
|
|
482
813
|
).filter(Boolean);
|
|
483
|
-
return Math.max(...e,
|
|
484
|
-
},
|
|
485
|
-
const r = e ?
|
|
486
|
-
return BigInt(`${
|
|
487
|
-
},
|
|
814
|
+
return Math.max(...e, $);
|
|
815
|
+
}, O = new WeakSet(), F = function(t, e) {
|
|
816
|
+
const r = e ? R(e) : this.decimalMultiplier, n = S(r), [i = "", a = ""] = t.split(".");
|
|
817
|
+
return BigInt(`${i}${a.padEnd(n, "0")}`);
|
|
818
|
+
}, A = new WeakSet(), C = function(t) {
|
|
488
819
|
const r = `${typeof t == "number" ? Number(t).toLocaleString("fullwide", {
|
|
489
820
|
useGrouping: !1,
|
|
490
821
|
maximumFractionDigits: 20
|
|
491
|
-
}) :
|
|
822
|
+
}) : L(t)}`.replaceAll(",", ".").split(".");
|
|
492
823
|
return r.length > 1 ? `${r.slice(0, -1).join("")}.${r.at(-1)}` : r[0];
|
|
493
|
-
},
|
|
824
|
+
}, k = new WeakSet(), W = function(t) {
|
|
494
825
|
var r;
|
|
495
826
|
const e = ((r = t.split(".")[1]) == null ? void 0 : r.length) || 0;
|
|
496
|
-
return Math.max(e,
|
|
827
|
+
return Math.max(e, $);
|
|
497
828
|
};
|
|
498
|
-
let
|
|
499
|
-
function
|
|
500
|
-
return typeof
|
|
829
|
+
let E = I;
|
|
830
|
+
function L(s) {
|
|
831
|
+
return typeof s == "object" ? "getValue" in s ? s.getValue("string") : s.value : s;
|
|
501
832
|
}
|
|
502
|
-
let
|
|
503
|
-
const
|
|
504
|
-
if (!
|
|
833
|
+
let G;
|
|
834
|
+
const D = (s) => {
|
|
835
|
+
if (!G)
|
|
505
836
|
throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");
|
|
506
|
-
return
|
|
507
|
-
},
|
|
508
|
-
|
|
509
|
-
const e = await
|
|
510
|
-
return new
|
|
837
|
+
return G.get(s.toUpperCase()) || { decimal: m.THOR, identifier: "" };
|
|
838
|
+
}, et = async (s, t = 0) => {
|
|
839
|
+
Jt(s);
|
|
840
|
+
const e = await st(Y(s));
|
|
841
|
+
return new b({ decimal: e, value: t, identifier: s });
|
|
511
842
|
};
|
|
512
|
-
class
|
|
843
|
+
class b extends E {
|
|
513
844
|
constructor(e) {
|
|
514
845
|
super(
|
|
515
|
-
e.value instanceof
|
|
846
|
+
e.value instanceof E ? e.value : { decimal: e.decimal, value: e.value }
|
|
516
847
|
);
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
const r = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`,
|
|
525
|
-
this.type =
|
|
848
|
+
p(this, "address");
|
|
849
|
+
p(this, "chain");
|
|
850
|
+
p(this, "isSynthetic", !1);
|
|
851
|
+
p(this, "isGasAsset", !1);
|
|
852
|
+
p(this, "symbol");
|
|
853
|
+
p(this, "ticker");
|
|
854
|
+
p(this, "type");
|
|
855
|
+
const r = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`, n = Y(r);
|
|
856
|
+
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;
|
|
526
857
|
}
|
|
527
858
|
get assetValue() {
|
|
528
859
|
return `${this.getValue("string")} ${this.ticker}`;
|
|
@@ -538,36 +869,36 @@ class f extends y {
|
|
|
538
869
|
return this.chain === e && this.symbol === r;
|
|
539
870
|
}
|
|
540
871
|
static async fromString(e, r = 0) {
|
|
541
|
-
return
|
|
872
|
+
return et(e, r);
|
|
542
873
|
}
|
|
543
874
|
static fromStringSync(e, r = 0) {
|
|
544
|
-
const { decimal:
|
|
875
|
+
const { decimal: n, identifier: i } = D(
|
|
545
876
|
e
|
|
546
877
|
);
|
|
547
|
-
return
|
|
878
|
+
return i ? new b({ decimal: n, identifier: i, value: r }) : void 0;
|
|
548
879
|
}
|
|
549
880
|
static async fromIdentifier(e, r = 0) {
|
|
550
|
-
return
|
|
881
|
+
return et(e, r);
|
|
551
882
|
}
|
|
552
883
|
static fromIdentifierSync(e, r = 0) {
|
|
553
|
-
const { decimal:
|
|
554
|
-
return new
|
|
884
|
+
const { decimal: n, identifier: i } = D(e);
|
|
885
|
+
return new b({ decimal: n, identifier: i, value: r });
|
|
555
886
|
}
|
|
556
887
|
static fromChainOrSignature(e, r = 0) {
|
|
557
|
-
const { decimal:
|
|
558
|
-
return new
|
|
888
|
+
const { decimal: n, identifier: i } = vt(e);
|
|
889
|
+
return new b({ value: r, decimal: n, identifier: i });
|
|
559
890
|
}
|
|
560
891
|
static async fromTCQuote(e, r = 0) {
|
|
561
|
-
const
|
|
562
|
-
return new
|
|
892
|
+
const n = await st(Y(e)), i = this.shiftDecimals({ value: r, from: m.THOR, to: n });
|
|
893
|
+
return new b({ value: i, identifier: e, decimal: n });
|
|
563
894
|
}
|
|
564
895
|
static fromTCQuoteStatic(e, r = 0) {
|
|
565
|
-
const
|
|
896
|
+
const n = D(e), i = this.shiftDecimals({
|
|
566
897
|
value: r,
|
|
567
898
|
from: m.THOR,
|
|
568
|
-
to:
|
|
899
|
+
to: n.decimal
|
|
569
900
|
});
|
|
570
|
-
return new
|
|
901
|
+
return new b({ ...n, value: i });
|
|
571
902
|
}
|
|
572
903
|
static async loadStaticAssets() {
|
|
573
904
|
return new Promise(
|
|
@@ -576,21 +907,21 @@ class f extends y {
|
|
|
576
907
|
const {
|
|
577
908
|
// Omit ThorchainList from import to avoid decimals conflict (TC uses 8 for all)
|
|
578
909
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
579
|
-
ThorchainList:
|
|
580
|
-
NativeList:
|
|
581
|
-
...
|
|
910
|
+
ThorchainList: n,
|
|
911
|
+
NativeList: i,
|
|
912
|
+
...a
|
|
582
913
|
} = await import("@swapkit/tokens");
|
|
583
|
-
|
|
584
|
-
(u, { tokens: l }) => (l.forEach(({ identifier:
|
|
585
|
-
const
|
|
586
|
-
u.set(
|
|
914
|
+
G = [i, ...Object.values(a)].reduce(
|
|
915
|
+
(u, { tokens: l }) => (l.forEach(({ identifier: h, chain: _, ...T }) => {
|
|
916
|
+
const P = "decimals" in T ? T.decimals : m[_];
|
|
917
|
+
u.set(h, { identifier: h, decimal: P });
|
|
587
918
|
}), u),
|
|
588
919
|
/* @__PURE__ */ new Map()
|
|
589
920
|
), e({ ok: !0 });
|
|
590
|
-
} catch (
|
|
591
|
-
console.error(
|
|
921
|
+
} catch (n) {
|
|
922
|
+
console.error(n), r({
|
|
592
923
|
ok: !1,
|
|
593
|
-
error:
|
|
924
|
+
error: n,
|
|
594
925
|
message: "Couldn't load static assets. Ensure you have installed @swapkit/tokens package"
|
|
595
926
|
});
|
|
596
927
|
}
|
|
@@ -598,35 +929,35 @@ class f extends y {
|
|
|
598
929
|
);
|
|
599
930
|
}
|
|
600
931
|
}
|
|
601
|
-
const
|
|
602
|
-
const t =
|
|
603
|
-
switch (
|
|
604
|
-
case
|
|
605
|
-
case
|
|
606
|
-
case
|
|
932
|
+
const de = (s) => {
|
|
933
|
+
const t = b.fromChainOrSignature(s);
|
|
934
|
+
switch (s) {
|
|
935
|
+
case o.Bitcoin:
|
|
936
|
+
case o.Litecoin:
|
|
937
|
+
case o.BitcoinCash:
|
|
607
938
|
return t.add(10001);
|
|
608
|
-
case
|
|
939
|
+
case o.Dogecoin:
|
|
609
940
|
return t.add(100000001);
|
|
610
|
-
case
|
|
611
|
-
case
|
|
941
|
+
case o.Avalanche:
|
|
942
|
+
case o.Ethereum:
|
|
612
943
|
return t.add(10 * 10 ** 9);
|
|
613
|
-
case
|
|
614
|
-
case
|
|
944
|
+
case o.THORChain:
|
|
945
|
+
case o.Maya:
|
|
615
946
|
return t.add(0);
|
|
616
947
|
default:
|
|
617
948
|
return t.add(1);
|
|
618
949
|
}
|
|
619
|
-
},
|
|
620
|
-
const t =
|
|
950
|
+
}, Y = (s) => {
|
|
951
|
+
const t = s.slice(0, 14).includes("/"), e = s.includes(".") ? s : `${o.THORChain}.${s}`, [r, n] = e.split("."), [i, a] = n.split("-");
|
|
621
952
|
return {
|
|
622
|
-
address:
|
|
953
|
+
address: a == null ? void 0 : a.toLowerCase(),
|
|
623
954
|
chain: r,
|
|
624
|
-
isGasAsset:
|
|
955
|
+
isGasAsset: St({ chain: r, symbol: n }),
|
|
625
956
|
isSynthetic: t,
|
|
626
|
-
symbol:
|
|
627
|
-
ticker: t ?
|
|
957
|
+
symbol: a ? `${i}-${(a == null ? void 0 : a.toLowerCase()) ?? ""}` : n,
|
|
958
|
+
ticker: t ? n : i
|
|
628
959
|
};
|
|
629
|
-
},
|
|
960
|
+
}, Kt = {
|
|
630
961
|
/**
|
|
631
962
|
* Core
|
|
632
963
|
*/
|
|
@@ -683,42 +1014,41 @@ const Pt = (n) => {
|
|
|
683
1014
|
*/
|
|
684
1015
|
helpers_number_different_decimals: 99101
|
|
685
1016
|
};
|
|
686
|
-
class
|
|
1017
|
+
class ht extends Error {
|
|
687
1018
|
constructor(t, e) {
|
|
688
|
-
console.error(e), super(t, { cause: { code:
|
|
1019
|
+
console.error(e), super(t, { cause: { code: Kt[t], message: t } }), Object.setPrototypeOf(this, ht.prototype);
|
|
689
1020
|
}
|
|
690
1021
|
}
|
|
691
|
-
class
|
|
1022
|
+
class Qt extends E {
|
|
692
1023
|
eq(t) {
|
|
693
1024
|
return this.eqValue(t);
|
|
694
1025
|
}
|
|
695
1026
|
}
|
|
696
1027
|
export {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
Ct as validateTHORName
|
|
1028
|
+
b as AssetValue,
|
|
1029
|
+
E as BigIntArithmetics,
|
|
1030
|
+
zt as RequestClient,
|
|
1031
|
+
ht as SwapKitError,
|
|
1032
|
+
Qt as SwapKitNumber,
|
|
1033
|
+
ee as assetFromString,
|
|
1034
|
+
he as derivationPathToString,
|
|
1035
|
+
re as filterAssets,
|
|
1036
|
+
tt as formatBigIntToSafeValue,
|
|
1037
|
+
te as gasFeeMultiplier,
|
|
1038
|
+
Ct as getAssetType,
|
|
1039
|
+
Et as getAsymmetricAssetShare,
|
|
1040
|
+
ne as getAsymmetricAssetWithdrawAmount,
|
|
1041
|
+
It as getAsymmetricRuneShare,
|
|
1042
|
+
se as getAsymmetricRuneWithdrawAmount,
|
|
1043
|
+
vt as getCommonAssetInfo,
|
|
1044
|
+
st as getDecimal,
|
|
1045
|
+
oe as getEstimatedPoolShare,
|
|
1046
|
+
ae as getLiquiditySlippage,
|
|
1047
|
+
ce as getMemoFor,
|
|
1048
|
+
de as getMinAmountByChain,
|
|
1049
|
+
Ot as getSymmetricPoolShare,
|
|
1050
|
+
ie as getSymmetricWithdraw,
|
|
1051
|
+
ue as getTHORNameCost,
|
|
1052
|
+
St as isGasAsset,
|
|
1053
|
+
le as validateTHORName
|
|
724
1054
|
};
|