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