@swapkit/helpers 1.0.0-rc.63 → 1.0.0-rc.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -6
- package/dist/index.es.js +788 -723
- package/dist/index.es.js.map +1 -1
- package/package.json +10 -10
- package/src/helpers/asset.ts +1 -2
- package/src/index.ts +2 -1
- package/src/helpers/request.ts +0 -15
package/dist/index.es.js
CHANGED
|
@@ -1,307 +1,45 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
if (!t.has(
|
|
5
|
-
throw TypeError("Cannot " +
|
|
1
|
+
var ye = Object.defineProperty;
|
|
2
|
+
var we = (e, t, n) => t in e ? ye(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var p = (e, t, n) => (we(e, typeof t != "symbol" ? t + "" : t, n), n), Ve = (e, t, n) => {
|
|
4
|
+
if (!t.has(e))
|
|
5
|
+
throw TypeError("Cannot " + n);
|
|
6
6
|
};
|
|
7
|
-
var
|
|
8
|
-
if (t.has(
|
|
7
|
+
var O = (e, t, n) => {
|
|
8
|
+
if (t.has(e))
|
|
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(e) : t.set(e, n);
|
|
11
11
|
};
|
|
12
|
-
var
|
|
13
|
-
import { FeeOption as
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
case o.Ethereum:
|
|
44
|
-
return Ct(t);
|
|
45
|
-
case o.Avalanche:
|
|
46
|
-
return Rt(t);
|
|
47
|
-
case o.BinanceSmartChain:
|
|
48
|
-
return St(t);
|
|
49
|
-
default:
|
|
50
|
-
return d[s];
|
|
51
|
-
}
|
|
52
|
-
}, ie = {
|
|
53
|
-
[D.Average]: 1.2,
|
|
54
|
-
[D.Fast]: 1.5,
|
|
55
|
-
[D.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:
|
|
68
|
-
return t === "ETH";
|
|
69
|
-
case o.Maya:
|
|
70
|
-
return t === "CACAO";
|
|
71
|
-
case o.Kujira:
|
|
72
|
-
return t === "KUJI";
|
|
73
|
-
case o.Cosmos:
|
|
74
|
-
return t === "ATOM";
|
|
75
|
-
case o.Polygon:
|
|
76
|
-
return t === "MATIC";
|
|
77
|
-
case o.BinanceSmartChain:
|
|
78
|
-
return t === "BNB";
|
|
79
|
-
case o.THORChain:
|
|
80
|
-
return t === "RUNE";
|
|
81
|
-
}
|
|
82
|
-
}, Ot = (s) => {
|
|
83
|
-
switch (s) {
|
|
84
|
-
case `${o.Ethereum}.THOR`:
|
|
85
|
-
return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
|
|
86
|
-
case `${o.Ethereum}.vTHOR`:
|
|
87
|
-
return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
|
|
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 };
|
|
96
|
-
case `${o.Maya}.MAYA`:
|
|
97
|
-
return { identifier: "MAYA.MAYA", decimal: 4 };
|
|
98
|
-
case `${o.Kujira}.USK`:
|
|
99
|
-
return { identifier: `${o.Kujira}.USK`, decimal: 6 };
|
|
100
|
-
case o.Kujira:
|
|
101
|
-
case o.Arbitrum:
|
|
102
|
-
case o.Optimism:
|
|
103
|
-
case o.BitcoinCash:
|
|
104
|
-
case o.Litecoin:
|
|
105
|
-
case o.Dogecoin:
|
|
106
|
-
case o.Binance:
|
|
107
|
-
case o.Avalanche:
|
|
108
|
-
case o.Polygon:
|
|
109
|
-
case o.Bitcoin:
|
|
110
|
-
case o.Ethereum:
|
|
111
|
-
return { identifier: `${s}.${s}`, decimal: d[s] };
|
|
112
|
-
}
|
|
113
|
-
}, Et = ({ chain: s, symbol: t }) => {
|
|
114
|
-
if (t.includes("/"))
|
|
115
|
-
return "Synth";
|
|
116
|
-
switch (s) {
|
|
117
|
-
case o.Bitcoin:
|
|
118
|
-
case o.BitcoinCash:
|
|
119
|
-
case o.Dogecoin:
|
|
120
|
-
case o.Litecoin:
|
|
121
|
-
case o.Maya:
|
|
122
|
-
case o.THORChain:
|
|
123
|
-
return "Native";
|
|
124
|
-
case o.Cosmos:
|
|
125
|
-
return t === "ATOM" ? "Native" : o.Cosmos;
|
|
126
|
-
case o.Kujira:
|
|
127
|
-
return t === o.Kujira ? "Native" : o.Kujira;
|
|
128
|
-
case o.Binance:
|
|
129
|
-
return t === o.Binance ? "Native" : "BEP2";
|
|
130
|
-
case o.BinanceSmartChain:
|
|
131
|
-
return t === o.Binance ? "Native" : "BEP20";
|
|
132
|
-
case o.Ethereum:
|
|
133
|
-
return t === o.Ethereum ? "Native" : "ERC20";
|
|
134
|
-
case o.Avalanche:
|
|
135
|
-
return t === o.Avalanche ? "Native" : o.Avalanche;
|
|
136
|
-
case o.Polygon:
|
|
137
|
-
return t === o.Polygon ? "Native" : "POLYGON";
|
|
138
|
-
case o.Arbitrum:
|
|
139
|
-
return [o.Ethereum, o.Arbitrum].includes(t) ? "Native" : "ARBITRUM";
|
|
140
|
-
case o.Optimism:
|
|
141
|
-
return [o.Ethereum, o.Optimism].includes(t) ? "Native" : "OPTIMISM";
|
|
142
|
-
}
|
|
143
|
-
}, oe = (s) => {
|
|
144
|
-
var c;
|
|
145
|
-
const [t, ...e] = s.split("."), r = s.includes("/"), n = e.join("."), i = (c = n == null ? void 0 : n.split("-")) == null ? void 0 : c[0];
|
|
146
|
-
return { chain: t, symbol: n, ticker: i, synth: r };
|
|
147
|
-
}, Bt = new RegExp(
|
|
148
|
-
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
|
|
149
|
-
"gmi"
|
|
150
|
-
), Mt = (s) => {
|
|
151
|
-
const [t, e] = s.split(".");
|
|
152
|
-
if (!At.includes(t))
|
|
153
|
-
return !0;
|
|
154
|
-
const [, r] = e.split("-");
|
|
155
|
-
return it({ chain: t, symbol: e }) || !!r;
|
|
156
|
-
}, ae = (s) => s.filter((t) => {
|
|
157
|
-
const e = `${t.chain}.${t.symbol}`;
|
|
158
|
-
return !Bt.test(e) && Mt(e) && t.value !== "0";
|
|
159
|
-
});
|
|
160
|
-
function xt({
|
|
161
|
-
liquidityUnits: s,
|
|
162
|
-
poolUnits: t,
|
|
163
|
-
runeDepth: e
|
|
164
|
-
}) {
|
|
165
|
-
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);
|
|
166
|
-
return c.mul(a.sub(u).add(l)).div(h);
|
|
167
|
-
}
|
|
168
|
-
function qt({
|
|
169
|
-
liquidityUnits: s,
|
|
170
|
-
poolUnits: t,
|
|
171
|
-
assetDepth: e
|
|
172
|
-
}) {
|
|
173
|
-
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)), $ = n.mul(n).mul(n);
|
|
174
|
-
return h.div($);
|
|
175
|
-
}
|
|
176
|
-
function ce({
|
|
177
|
-
percent: s,
|
|
178
|
-
runeDepth: t,
|
|
179
|
-
liquidityUnits: e,
|
|
180
|
-
poolUnits: r
|
|
181
|
-
}) {
|
|
182
|
-
return xt({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(s);
|
|
183
|
-
}
|
|
184
|
-
function ue({
|
|
185
|
-
percent: s,
|
|
186
|
-
assetDepth: t,
|
|
187
|
-
liquidityUnits: e,
|
|
188
|
-
poolUnits: r
|
|
189
|
-
}) {
|
|
190
|
-
return qt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(s);
|
|
191
|
-
}
|
|
192
|
-
function p(s) {
|
|
193
|
-
return g.fromBigInt(BigInt(s), d.THOR);
|
|
194
|
-
}
|
|
195
|
-
function Pt({
|
|
196
|
-
liquidityUnits: s,
|
|
197
|
-
poolUnits: t,
|
|
198
|
-
runeDepth: e,
|
|
199
|
-
assetDepth: r
|
|
200
|
-
}) {
|
|
201
|
-
return {
|
|
202
|
-
assetAmount: p(r).mul(s).div(t),
|
|
203
|
-
runeAmount: p(e).mul(s).div(t)
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
function le({
|
|
207
|
-
liquidityUnits: s,
|
|
208
|
-
poolUnits: t,
|
|
209
|
-
runeDepth: e,
|
|
210
|
-
assetDepth: r,
|
|
211
|
-
percent: n
|
|
212
|
-
}) {
|
|
213
|
-
return Object.fromEntries(
|
|
214
|
-
Object.entries(Pt({ liquidityUnits: s, poolUnits: t, runeDepth: e, assetDepth: r })).map(
|
|
215
|
-
([i, c]) => [i, c.mul(n)]
|
|
216
|
-
)
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
function he({
|
|
220
|
-
runeDepth: s,
|
|
221
|
-
poolUnits: t,
|
|
222
|
-
assetDepth: e,
|
|
223
|
-
liquidityUnits: r,
|
|
224
|
-
runeAmount: n,
|
|
225
|
-
assetAmount: i
|
|
226
|
-
}) {
|
|
227
|
-
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 }), $ = l.mul(a), H = h.mul(c), mt = l.mul(h), pt = c.mul(a), ft = u.mul($.add(H.add(mt.mul(2)))), _t = $.add(H.add(pt.mul(2))), Q = ft.div(_t), U = p(r).add(Q);
|
|
228
|
-
if (Q.getBaseValue("number") === 0)
|
|
229
|
-
return U.div(u).getBaseValue("number");
|
|
230
|
-
const gt = u.add(U);
|
|
231
|
-
return U.div(gt).getBaseValue("number");
|
|
232
|
-
}
|
|
233
|
-
function de({
|
|
234
|
-
runeAmount: s,
|
|
235
|
-
assetAmount: t,
|
|
236
|
-
runeDepth: e,
|
|
237
|
-
assetDepth: r
|
|
238
|
-
}) {
|
|
239
|
-
if (s === "0" || t === "0" || e === "0" || r === "0")
|
|
240
|
-
return 0;
|
|
241
|
-
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));
|
|
242
|
-
return Math.abs(u.div(l).getBaseValue("number"));
|
|
243
|
-
}
|
|
244
|
-
const me = (s, t) => {
|
|
245
|
-
switch (s) {
|
|
246
|
-
case _.LEAVE:
|
|
247
|
-
case _.BOND: {
|
|
248
|
-
const { address: e } = t;
|
|
249
|
-
return `${s}:${e}`;
|
|
250
|
-
}
|
|
251
|
-
case _.UNBOND: {
|
|
252
|
-
const { address: e, unbondAmount: r } = t;
|
|
253
|
-
return `${s}:${e}:${r}`;
|
|
254
|
-
}
|
|
255
|
-
case _.THORNAME_REGISTER: {
|
|
256
|
-
const { name: e, chain: r, address: n, owner: i } = t;
|
|
257
|
-
return `${s}:${e}:${r}:${n}${i ? `:${i}` : ""}`;
|
|
258
|
-
}
|
|
259
|
-
case _.DEPOSIT: {
|
|
260
|
-
const { chain: e, symbol: r, address: n, singleSide: i } = t;
|
|
261
|
-
return i ? `${s}:${e}/${r}::t:0` : `${s}:${((a, u) => {
|
|
262
|
-
switch (a) {
|
|
263
|
-
case o.Litecoin:
|
|
264
|
-
return "l";
|
|
265
|
-
case o.Dogecoin:
|
|
266
|
-
return "d";
|
|
267
|
-
case o.BitcoinCash:
|
|
268
|
-
return "c";
|
|
269
|
-
default:
|
|
270
|
-
return `${a}.${u}`;
|
|
271
|
-
}
|
|
272
|
-
})(e, r)}:${n || ""}:t:0`;
|
|
273
|
-
}
|
|
274
|
-
case _.WITHDRAW: {
|
|
275
|
-
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}` : "";
|
|
276
|
-
return `${s}:${e}${a ? "/" : "."}${u}:${i}${l}`;
|
|
277
|
-
}
|
|
278
|
-
case _.OPEN_LOAN:
|
|
279
|
-
case _.CLOSE_LOAN: {
|
|
280
|
-
const { asset: e, address: r } = t;
|
|
281
|
-
return `${s}:${e}:${r}`;
|
|
282
|
-
}
|
|
283
|
-
default:
|
|
284
|
-
return "";
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
function pe(s) {
|
|
288
|
-
if (s < 0)
|
|
289
|
-
throw new Error("Invalid number of year");
|
|
290
|
-
return 10 + s;
|
|
291
|
-
}
|
|
292
|
-
function fe(s) {
|
|
293
|
-
if (s.length > 30)
|
|
294
|
-
return !1;
|
|
295
|
-
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
296
|
-
return !!s.match(t);
|
|
297
|
-
}
|
|
298
|
-
function _e([s, t, e, r, n]) {
|
|
299
|
-
return `${s}'/${t}'/${e}'/${r}${typeof n != "number" ? "" : `/${n}`}`;
|
|
300
|
-
}
|
|
301
|
-
class X extends Error {
|
|
302
|
-
constructor(t, e, r) {
|
|
303
|
-
const n = t.status || t.status === 0 ? t.status : "", i = t.statusText || "", c = `${n} ${i}`.trim(), a = c ? `status code ${c}` : "an unknown error";
|
|
304
|
-
super(`Request failed with ${a}`), Object.defineProperty(this, "response", {
|
|
12
|
+
var T = (e, t, n) => (Ve(e, t, "access private method"), n);
|
|
13
|
+
import { FeeOption as Y, BaseDecimal as d, Chain as a, EVMChainList as Be, ChainToRPC as Ue, MemoType as E, ChainToChainId as Le } from "@swapkit/types";
|
|
14
|
+
var l = /* @__PURE__ */ ((e) => (e.INVALID_INPUT_PARAMETERS = "1000", e.UNKNOWN_PROVIDERS = "1001", e.CANNOT_FIND_INBOUND_ADDRESS = "1002", e.NO_INBOUND_ADDRESSES = "1003", e.CHAIN_HALTED_OR_UNSUPPORTED = "1004", e.MISSING_INPUT_PARAMETER = "1005", e.INVALID_TYPE_GENERIC = "1100", e.INVALID_NUMBER_STRING = "1101", e.INVALID_NUMBER = "1102", e.INVALID_BOOLEAN = "1103", e.INVALID_OBJECT = "1104", e.INVALID_ARRAY = "1105", e.SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER = "2000", e.SELL_BUY_ASSETS_ARE_THE_SAME = "2001", e.MISSING_SOURCE_ADDRESS_FOR_SYNTH = "2002", e.AFF_ADDRESS_AND_BPS_OR_NEITHER = "2003", e.AFF_ADDRESS_TOO_LONG = "2004", e.AFF_BPS_INTEGER_MAX_500 = "2005", e.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN = "2006", e.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN = "2007", e.PREFERRED_PROVIDER_NOT_SUPPORTED = "2008", e.DESTINATION_ADDRESS_SMART_CONTRACT = "2009", e.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER = "2010", e.SOURCE_ADDRESS_SMART_CONTRACT = "2011", e.INVALID_PROVIDER = "2100", e.MISSING_CROSS_CHAIN_PROVIDER = "2101", e.MISSING_AVAX_PROVIDER = "2102", e.MISSING_BSC_PROVIDER = "2103", e.MISSING_ETH_PROVIDER = "2104", e.INVALID_PROVIDER_FOR_SWAP_OUT = "2105", e.MISSING_ARB_PROVIDER = "2106", e.INVALID_CHAIN = "2200", e.INVALID_ASSET = "2201", e.INVALID_ASSET_IDENTIFIER = "2202", e.UNSUPPORTED_CHAIN = "2204", e.UNSUPPORTED_ASSET = "2203", e.UNSUPPORTED_ASSET_FOR_SWAPOUT = "2205", e.INVALID_SOURCE_ADDRESS = "2300", e.INVALID_DESTINATION_ADDRESS = "2301", e.THORNODE_QUOTE_GENERIC_ERROR = "3000", e.NOT_ENOUGH_SYNTH_BALANCE = "3001", e.SYNTH_MINTING_CAP_REACHED = "3002", e.INVALID_QUOTE_MODE = "4000", e.NO_QUOTES = "4001", e.SERVICE_UNAVAILABLE_GENERIC = "5000", e.MISSING_GAS_DATA_GENERIC = "5100", e.MISSING_TOKEN_INFO_GENERIC = "5200", e.CANT_FIND_TOKEN_LIST = "5201", e.NO_PRICE = "5202", e.PRICE_IS_STALE = "5203", e.ADDRESS_NOT_WHITELISTED = "6000", e.ADDRESS_ALREADY_CLAIMED = "6001", e.TEMPORARY_ERROR = "9999", e))(l || {});
|
|
15
|
+
l.INVALID_INPUT_PARAMETERS + "", l.UNKNOWN_PROVIDERS + "", l.CANNOT_FIND_INBOUND_ADDRESS + "", l.NO_INBOUND_ADDRESSES + "", l.CHAIN_HALTED_OR_UNSUPPORTED + "", l.MISSING_INPUT_PARAMETER + "", l.INVALID_TYPE_GENERIC + "", l.INVALID_NUMBER_STRING + "", l.INVALID_NUMBER + "", l.INVALID_BOOLEAN + "", l.INVALID_OBJECT + "", l.INVALID_ARRAY + "", l.SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER + "", l.SELL_BUY_ASSETS_ARE_THE_SAME + "", l.MISSING_SOURCE_ADDRESS_FOR_SYNTH + "", l.AFF_ADDRESS_AND_BPS_OR_NEITHER + "", l.AFF_ADDRESS_TOO_LONG + "", l.AFF_BPS_INTEGER_MAX_500 + "", l.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN + "", l.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN + "", l.PREFERRED_PROVIDER_NOT_SUPPORTED + "", l.SOURCE_ADDRESS_SMART_CONTRACT + "", l.DESTINATION_ADDRESS_SMART_CONTRACT + "", l.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER + "", l.INVALID_PROVIDER + "", l.MISSING_CROSS_CHAIN_PROVIDER + "", l.MISSING_AVAX_PROVIDER + "", l.MISSING_BSC_PROVIDER + "", l.MISSING_ETH_PROVIDER + "", l.MISSING_ARB_PROVIDER + "", l.INVALID_PROVIDER_FOR_SWAP_OUT + "", l.INVALID_CHAIN + "", l.INVALID_ASSET + "", l.UNSUPPORTED_CHAIN + "", l.UNSUPPORTED_ASSET + "", l.UNSUPPORTED_ASSET_FOR_SWAPOUT + "", l.THORNODE_QUOTE_GENERIC_ERROR + "", l.INVALID_SOURCE_ADDRESS + "", l.INVALID_DESTINATION_ADDRESS + "", l.NOT_ENOUGH_SYNTH_BALANCE + "", l.SYNTH_MINTING_CAP_REACHED + "", l.INVALID_QUOTE_MODE + "", l.NO_QUOTES + "", l.SERVICE_UNAVAILABLE_GENERIC + "", l.MISSING_GAS_DATA_GENERIC + "", l.MISSING_TOKEN_INFO_GENERIC + "", l.CANT_FIND_TOKEN_LIST + "", l.NO_PRICE + "", l.PRICE_IS_STALE + "", l.ADDRESS_NOT_WHITELISTED + "", l.ADDRESS_ALREADY_CLAIMED + "";
|
|
16
|
+
var q = /* @__PURE__ */ ((e) => (e.Arbitrum = "ARB", e.Avalanche = "AVAX", e.Binance = "BNB", e.BinanceSmartChain = "BSC", e.Bitcoin = "BTC", e.BitcoinCash = "BCH", e.Cosmos = "GAIA", e.Dogecoin = "DOGE", e.Ethereum = "ETH", e.Kujira = "KUJI", e.Litecoin = "LTC", e.Maya = "MAYA", e.Optimism = "OP", e.Polygon = "MATIC", e.THORChain = "THOR", e))(q || {}), te = /* @__PURE__ */ ((e) => (e.Arbitrum = "42161", e.ArbitrumHex = "0xa4b1", e.Avalanche = "43114", e.AvalancheHex = "0xa86a", e.Binance = "Binance-Chain-Tigris", e.BinanceSmartChain = "56", e.BinanceSmartChainHex = "0x38", e.Bitcoin = "bitcoin", e.BitcoinCash = "bitcoincash", e.Cosmos = "cosmoshub-4", e.Dogecoin = "dogecoin", e.Kujira = "kaiyo-1", e.Ethereum = "1", e.EthereumHex = "0x1", e.Litecoin = "litecoin", e.Maya = "mayachain-mainnet-v1", e.MayaStagenet = "mayachain-stagenet-v1", e.Optimism = "10", e.OptimismHex = "0xa", e.Polygon = "137", e.PolygonHex = "0x89", e.THORChain = "thorchain-mainnet-v1", e.THORChainStagenet = "thorchain-stagenet-v2", e))(te || {}), de = /* @__PURE__ */ ((e) => (e.Arbitrum = "https://arb1.arbitrum.io/rpc", e.Avalanche = "https://node-router.thorswap.net/avalanche-c", e.Binance = "", e.BinanceSmartChain = "https://bsc-dataseed.binance.org", e.Bitcoin = "https://node-router.thorswap.net/bitcoin", e.BitcoinCash = "https://node-router.thorswap.net/bitcoin-cash", e.Cosmos = "https://node-router.thorswap.net/cosmos/rpc", e.Kujira = "https://rpc-kujira.synergynodes.com/", e.Dogecoin = "https://node-router.thorswap.net/dogecoin", e.Ethereum = "https://node-router.thorswap.net/ethereum", e.Litecoin = "https://node-router.thorswap.net/litecoin", e.Maya = "https://tendermint.mayachain.info", e.MayaStagenet = "https://stagenet.tendermint.mayachain.info", e.Optimism = "https://mainnet.optimism.io", e.Polygon = "https://polygon-rpc.com", e.THORChain = "https://rpc.thorswap.net", e.THORChainStagenet = "https://stagenet-rpc.ninerealms.com", e))(de || {}), R = /* @__PURE__ */ ((e) => (e.Cosmos = "https://node-router.thorswap.net/cosmos/rest", e.Kujira = "https://lcd-kujira.synergynodes.com/", e.MayanodeMainnet = "https://mayanode.mayachain.info", e.MayanodeStagenet = "https://stagenet.mayanode.mayachain.info", e.ThornodeMainnet = "https://thornode.thorswap.net", e.ThornodeStagenet = "https://stagenet-thornode.ninerealms.com", e.ThorswapApi = "https://api.thorswap.net", e.ThorswapStatic = "https://static.thorswap.net", e))(R || {});
|
|
17
|
+
const j = Object.values(q), $e = Object.keys(q), ne = j.reduce(
|
|
18
|
+
(e, t) => {
|
|
19
|
+
const n = $e.find((s) => q[s] === t);
|
|
20
|
+
return n && (e[t] = n), e;
|
|
21
|
+
},
|
|
22
|
+
{}
|
|
23
|
+
);
|
|
24
|
+
j.reduce(
|
|
25
|
+
(e, t) => (e[t] = te[ne[t]], e),
|
|
26
|
+
{}
|
|
27
|
+
);
|
|
28
|
+
j.reduce(
|
|
29
|
+
(e, t) => (e[t] = de[ne[t]], e),
|
|
30
|
+
{}
|
|
31
|
+
);
|
|
32
|
+
j.reduce(
|
|
33
|
+
(e, t) => {
|
|
34
|
+
const n = `${ne[t]}Hex`;
|
|
35
|
+
return e[t] = te[n], e;
|
|
36
|
+
},
|
|
37
|
+
{}
|
|
38
|
+
);
|
|
39
|
+
class oe extends Error {
|
|
40
|
+
constructor(t, n, s) {
|
|
41
|
+
const r = t.status || t.status === 0 ? t.status : "", i = t.statusText || "", o = `${r} ${i}`.trim(), u = o ? `status code ${o}` : "an unknown error";
|
|
42
|
+
super(`Request failed with ${u}`), Object.defineProperty(this, "response", {
|
|
305
43
|
enumerable: !0,
|
|
306
44
|
configurable: !0,
|
|
307
45
|
writable: !0,
|
|
@@ -316,10 +54,10 @@ class X extends Error {
|
|
|
316
54
|
configurable: !0,
|
|
317
55
|
writable: !0,
|
|
318
56
|
value: void 0
|
|
319
|
-
}), this.name = "HTTPError", this.response = t, this.request =
|
|
57
|
+
}), this.name = "HTTPError", this.response = t, this.request = n, this.options = s;
|
|
320
58
|
}
|
|
321
59
|
}
|
|
322
|
-
class
|
|
60
|
+
class Te extends Error {
|
|
323
61
|
constructor(t) {
|
|
324
62
|
super("Request timed out"), Object.defineProperty(this, "request", {
|
|
325
63
|
enumerable: !0,
|
|
@@ -329,45 +67,45 @@ class ot extends Error {
|
|
|
329
67
|
}), this.name = "TimeoutError", this.request = t;
|
|
330
68
|
}
|
|
331
69
|
}
|
|
332
|
-
const
|
|
333
|
-
for (const t of
|
|
334
|
-
if ((!
|
|
70
|
+
const M = (e) => e !== null && typeof e == "object", $ = (...e) => {
|
|
71
|
+
for (const t of e)
|
|
72
|
+
if ((!M(t) || Array.isArray(t)) && t !== void 0)
|
|
335
73
|
throw new TypeError("The `options` argument must be an object");
|
|
336
|
-
return
|
|
337
|
-
},
|
|
338
|
-
const
|
|
339
|
-
for (const [i,
|
|
340
|
-
|
|
341
|
-
return
|
|
342
|
-
},
|
|
343
|
-
let t = {},
|
|
344
|
-
for (const
|
|
345
|
-
if (Array.isArray(
|
|
346
|
-
Array.isArray(t) || (t = []), t = [...t, ...
|
|
347
|
-
else if (
|
|
348
|
-
for (let [
|
|
349
|
-
|
|
350
|
-
|
|
74
|
+
return se({}, ...e);
|
|
75
|
+
}, Ae = (e = {}, t = {}) => {
|
|
76
|
+
const n = new globalThis.Headers(e), s = t instanceof globalThis.Headers, r = new globalThis.Headers(t);
|
|
77
|
+
for (const [i, o] of r.entries())
|
|
78
|
+
s && o === "undefined" || o === void 0 ? n.delete(i) : n.set(i, o);
|
|
79
|
+
return n;
|
|
80
|
+
}, se = (...e) => {
|
|
81
|
+
let t = {}, n = {};
|
|
82
|
+
for (const s of e)
|
|
83
|
+
if (Array.isArray(s))
|
|
84
|
+
Array.isArray(t) || (t = []), t = [...t, ...s];
|
|
85
|
+
else if (M(s)) {
|
|
86
|
+
for (let [r, i] of Object.entries(s))
|
|
87
|
+
M(i) && r in t && (i = se(t[r], i)), t = { ...t, [r]: i };
|
|
88
|
+
M(s.headers) && (n = Ae(n, s.headers), t.headers = n);
|
|
351
89
|
}
|
|
352
90
|
return t;
|
|
353
|
-
},
|
|
354
|
-
let
|
|
355
|
-
const
|
|
356
|
-
return
|
|
91
|
+
}, ve = (() => {
|
|
92
|
+
let e = !1, t = !1;
|
|
93
|
+
const n = typeof globalThis.ReadableStream == "function", s = typeof globalThis.Request == "function";
|
|
94
|
+
return n && s && (t = new globalThis.Request("https://empty.invalid", {
|
|
357
95
|
body: new globalThis.ReadableStream(),
|
|
358
96
|
method: "POST",
|
|
359
97
|
// @ts-expect-error - Types are outdated.
|
|
360
98
|
get duplex() {
|
|
361
|
-
return
|
|
99
|
+
return e = !0, "half";
|
|
362
100
|
}
|
|
363
|
-
}).headers.has("Content-Type")),
|
|
364
|
-
})(),
|
|
101
|
+
}).headers.has("Content-Type")), e && !t;
|
|
102
|
+
})(), Me = typeof globalThis.AbortController == "function", He = typeof globalThis.ReadableStream == "function", xe = typeof globalThis.FormData == "function", pe = ["get", "post", "put", "patch", "head", "delete"], Fe = {
|
|
365
103
|
json: "application/json",
|
|
366
104
|
text: "text/*",
|
|
367
105
|
formData: "multipart/form-data",
|
|
368
106
|
arrayBuffer: "*/*",
|
|
369
107
|
blob: "*/*"
|
|
370
|
-
},
|
|
108
|
+
}, K = 2147483647, Se = Symbol("stop"), Ge = {
|
|
371
109
|
json: !0,
|
|
372
110
|
parseJson: !0,
|
|
373
111
|
searchParams: !0,
|
|
@@ -378,7 +116,7 @@ const q = (s) => s !== null && typeof s == "object", M = (...s) => {
|
|
|
378
116
|
throwHttpErrors: !0,
|
|
379
117
|
onDownloadProgress: !0,
|
|
380
118
|
fetch: !0
|
|
381
|
-
},
|
|
119
|
+
}, We = {
|
|
382
120
|
method: !0,
|
|
383
121
|
headers: !0,
|
|
384
122
|
body: !0,
|
|
@@ -394,99 +132,99 @@ const q = (s) => s !== null && typeof s == "object", M = (...s) => {
|
|
|
394
132
|
window: !0,
|
|
395
133
|
dispatcher: !0,
|
|
396
134
|
duplex: !0
|
|
397
|
-
},
|
|
135
|
+
}, ke = (e) => pe.includes(e) ? e.toUpperCase() : e, qe = ["get", "put", "head", "delete", "options", "trace"], je = [408, 413, 429, 500, 502, 503, 504], me = [413, 429, 503], ce = {
|
|
398
136
|
limit: 2,
|
|
399
|
-
methods:
|
|
400
|
-
statusCodes:
|
|
401
|
-
afterStatusCodes:
|
|
137
|
+
methods: qe,
|
|
138
|
+
statusCodes: je,
|
|
139
|
+
afterStatusCodes: me,
|
|
402
140
|
maxRetryAfter: Number.POSITIVE_INFINITY,
|
|
403
141
|
backoffLimit: Number.POSITIVE_INFINITY,
|
|
404
|
-
delay: (
|
|
405
|
-
},
|
|
406
|
-
if (typeof
|
|
142
|
+
delay: (e) => 0.3 * 2 ** (e - 1) * 1e3
|
|
143
|
+
}, Xe = (e = {}) => {
|
|
144
|
+
if (typeof e == "number")
|
|
407
145
|
return {
|
|
408
|
-
...
|
|
409
|
-
limit:
|
|
146
|
+
...ce,
|
|
147
|
+
limit: e
|
|
410
148
|
};
|
|
411
|
-
if (
|
|
149
|
+
if (e.methods && !Array.isArray(e.methods))
|
|
412
150
|
throw new Error("retry.methods must be an array");
|
|
413
|
-
if (
|
|
151
|
+
if (e.statusCodes && !Array.isArray(e.statusCodes))
|
|
414
152
|
throw new Error("retry.statusCodes must be an array");
|
|
415
153
|
return {
|
|
416
|
-
...
|
|
417
|
-
...
|
|
418
|
-
afterStatusCodes:
|
|
154
|
+
...ce,
|
|
155
|
+
...e,
|
|
156
|
+
afterStatusCodes: me
|
|
419
157
|
};
|
|
420
158
|
};
|
|
421
|
-
async function
|
|
422
|
-
return new Promise((
|
|
423
|
-
const
|
|
424
|
-
|
|
425
|
-
},
|
|
426
|
-
|
|
427
|
-
clearTimeout(
|
|
159
|
+
async function Ye(e, t, n, s) {
|
|
160
|
+
return new Promise((r, i) => {
|
|
161
|
+
const o = setTimeout(() => {
|
|
162
|
+
n && n.abort(), i(new Te(e));
|
|
163
|
+
}, s.timeout);
|
|
164
|
+
s.fetch(e, t).then(r).catch(i).then(() => {
|
|
165
|
+
clearTimeout(o);
|
|
428
166
|
});
|
|
429
167
|
});
|
|
430
168
|
}
|
|
431
|
-
async function
|
|
432
|
-
return new Promise((
|
|
433
|
-
t && (t.throwIfAborted(), t.addEventListener("abort",
|
|
434
|
-
function
|
|
435
|
-
clearTimeout(i),
|
|
169
|
+
async function Ke(e, { signal: t }) {
|
|
170
|
+
return new Promise((n, s) => {
|
|
171
|
+
t && (t.throwIfAborted(), t.addEventListener("abort", r, { once: !0 }));
|
|
172
|
+
function r() {
|
|
173
|
+
clearTimeout(i), s(t.reason);
|
|
436
174
|
}
|
|
437
175
|
const i = setTimeout(() => {
|
|
438
|
-
t == null || t.removeEventListener("abort",
|
|
439
|
-
},
|
|
176
|
+
t == null || t.removeEventListener("abort", r), n();
|
|
177
|
+
}, e);
|
|
440
178
|
});
|
|
441
179
|
}
|
|
442
|
-
const
|
|
443
|
-
const
|
|
444
|
-
for (const
|
|
445
|
-
!(
|
|
446
|
-
return
|
|
180
|
+
const Je = (e, t) => {
|
|
181
|
+
const n = {};
|
|
182
|
+
for (const s in t)
|
|
183
|
+
!(s in We) && !(s in Ge) && !(s in e) && (n[s] = t[s]);
|
|
184
|
+
return n;
|
|
447
185
|
};
|
|
448
|
-
class
|
|
449
|
-
static create(t,
|
|
450
|
-
const
|
|
451
|
-
if (typeof
|
|
452
|
-
throw new RangeError(`The \`timeout\` option cannot be greater than ${
|
|
186
|
+
class F {
|
|
187
|
+
static create(t, n) {
|
|
188
|
+
const s = new F(t, n), r = async () => {
|
|
189
|
+
if (typeof s._options.timeout == "number" && s._options.timeout > K)
|
|
190
|
+
throw new RangeError(`The \`timeout\` option cannot be greater than ${K}`);
|
|
453
191
|
await Promise.resolve();
|
|
454
|
-
let
|
|
455
|
-
for (const u of
|
|
456
|
-
const
|
|
457
|
-
|
|
192
|
+
let o = await s._fetch();
|
|
193
|
+
for (const u of s._options.hooks.afterResponse) {
|
|
194
|
+
const c = await u(s.request, s._options, s._decorateResponse(o.clone()));
|
|
195
|
+
c instanceof globalThis.Response && (o = c);
|
|
458
196
|
}
|
|
459
|
-
if (
|
|
460
|
-
let u = new
|
|
461
|
-
for (const
|
|
462
|
-
u = await
|
|
197
|
+
if (s._decorateResponse(o), !o.ok && s._options.throwHttpErrors) {
|
|
198
|
+
let u = new oe(o, s.request, s._options);
|
|
199
|
+
for (const c of s._options.hooks.beforeError)
|
|
200
|
+
u = await c(u);
|
|
463
201
|
throw u;
|
|
464
202
|
}
|
|
465
|
-
if (
|
|
466
|
-
if (typeof
|
|
203
|
+
if (s._options.onDownloadProgress) {
|
|
204
|
+
if (typeof s._options.onDownloadProgress != "function")
|
|
467
205
|
throw new TypeError("The `onDownloadProgress` option must be a function");
|
|
468
|
-
if (!
|
|
206
|
+
if (!He)
|
|
469
207
|
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
|
|
470
|
-
return
|
|
208
|
+
return s._stream(o.clone(), s._options.onDownloadProgress);
|
|
471
209
|
}
|
|
472
|
-
return
|
|
473
|
-
},
|
|
474
|
-
for (const [
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
const
|
|
478
|
-
if (
|
|
479
|
-
if (
|
|
210
|
+
return o;
|
|
211
|
+
}, i = s._options.retry.methods.includes(s.request.method.toLowerCase()) ? s._retry(r) : r();
|
|
212
|
+
for (const [o, u] of Object.entries(Fe))
|
|
213
|
+
i[o] = async () => {
|
|
214
|
+
s.request.headers.set("accept", s.request.headers.get("accept") || u);
|
|
215
|
+
const c = (await i).clone();
|
|
216
|
+
if (o === "json") {
|
|
217
|
+
if (c.status === 204 || (await c.clone().arrayBuffer()).byteLength === 0)
|
|
480
218
|
return "";
|
|
481
|
-
if (
|
|
482
|
-
return
|
|
219
|
+
if (n.parseJson)
|
|
220
|
+
return n.parseJson(await c.text());
|
|
483
221
|
}
|
|
484
|
-
return
|
|
222
|
+
return c[o]();
|
|
485
223
|
};
|
|
486
|
-
return
|
|
224
|
+
return i;
|
|
487
225
|
}
|
|
488
226
|
// eslint-disable-next-line complexity
|
|
489
|
-
constructor(t,
|
|
227
|
+
constructor(t, n = {}) {
|
|
490
228
|
if (Object.defineProperty(this, "request", {
|
|
491
229
|
enumerable: !0,
|
|
492
230
|
configurable: !0,
|
|
@@ -515,21 +253,21 @@ class V {
|
|
|
515
253
|
}), this._input = t, this._options = {
|
|
516
254
|
// TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208
|
|
517
255
|
credentials: this._input.credentials || "same-origin",
|
|
518
|
-
...
|
|
519
|
-
headers:
|
|
520
|
-
hooks:
|
|
256
|
+
...n,
|
|
257
|
+
headers: Ae(this._input.headers, n.headers),
|
|
258
|
+
hooks: se({
|
|
521
259
|
beforeRequest: [],
|
|
522
260
|
beforeRetry: [],
|
|
523
261
|
beforeError: [],
|
|
524
262
|
afterResponse: []
|
|
525
|
-
},
|
|
526
|
-
method:
|
|
263
|
+
}, n.hooks),
|
|
264
|
+
method: ke(n.method ?? this._input.method),
|
|
527
265
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
528
|
-
prefixUrl: String(
|
|
529
|
-
retry:
|
|
530
|
-
throwHttpErrors:
|
|
531
|
-
timeout:
|
|
532
|
-
fetch:
|
|
266
|
+
prefixUrl: String(n.prefixUrl || ""),
|
|
267
|
+
retry: Xe(n.retry),
|
|
268
|
+
throwHttpErrors: n.throwHttpErrors !== !1,
|
|
269
|
+
timeout: n.timeout ?? 1e4,
|
|
270
|
+
fetch: n.fetch ?? globalThis.fetch.bind(globalThis)
|
|
533
271
|
}, typeof this._input != "string" && !(this._input instanceof URL || this._input instanceof globalThis.Request))
|
|
534
272
|
throw new TypeError("`input` must be a string, URL, or Request");
|
|
535
273
|
if (this._options.prefixUrl && typeof this._input == "string") {
|
|
@@ -537,36 +275,36 @@ class V {
|
|
|
537
275
|
throw new Error("`input` must not begin with a slash when using `prefixUrl`");
|
|
538
276
|
this._options.prefixUrl.endsWith("/") || (this._options.prefixUrl += "/"), this._input = this._options.prefixUrl + this._input;
|
|
539
277
|
}
|
|
540
|
-
if (
|
|
278
|
+
if (Me) {
|
|
541
279
|
if (this.abortController = new globalThis.AbortController(), this._options.signal) {
|
|
542
|
-
const
|
|
280
|
+
const s = this._options.signal;
|
|
543
281
|
this._options.signal.addEventListener("abort", () => {
|
|
544
|
-
this.abortController.abort(
|
|
282
|
+
this.abortController.abort(s.reason);
|
|
545
283
|
});
|
|
546
284
|
}
|
|
547
285
|
this._options.signal = this.abortController.signal;
|
|
548
286
|
}
|
|
549
|
-
if (
|
|
550
|
-
const
|
|
551
|
-
(
|
|
287
|
+
if (ve && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
|
|
288
|
+
const s = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), r = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, s);
|
|
289
|
+
(xe && 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(r, { ...this.request }), this._options);
|
|
552
290
|
}
|
|
553
291
|
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 }));
|
|
554
292
|
}
|
|
555
293
|
_calculateRetryDelay(t) {
|
|
556
|
-
if (this._retryCount++, this._retryCount
|
|
557
|
-
if (t instanceof
|
|
294
|
+
if (this._retryCount++, this._retryCount <= this._options.retry.limit && !(t instanceof Te)) {
|
|
295
|
+
if (t instanceof oe) {
|
|
558
296
|
if (!this._options.retry.statusCodes.includes(t.response.status))
|
|
559
297
|
return 0;
|
|
560
|
-
const
|
|
561
|
-
if (
|
|
562
|
-
let
|
|
563
|
-
return Number.isNaN(
|
|
298
|
+
const s = t.response.headers.get("Retry-After");
|
|
299
|
+
if (s && this._options.retry.afterStatusCodes.includes(t.response.status)) {
|
|
300
|
+
let r = Number(s);
|
|
301
|
+
return Number.isNaN(r) ? r = Date.parse(s) - Date.now() : r *= 1e3, this._options.retry.maxRetryAfter !== void 0 && r > this._options.retry.maxRetryAfter ? 0 : r;
|
|
564
302
|
}
|
|
565
303
|
if (t.response.status === 413)
|
|
566
304
|
return 0;
|
|
567
305
|
}
|
|
568
|
-
const
|
|
569
|
-
return Math.min(this._options.retry.backoffLimit,
|
|
306
|
+
const n = this._options.retry.delay(this._retryCount);
|
|
307
|
+
return Math.min(this._options.retry.backoffLimit, n);
|
|
570
308
|
}
|
|
571
309
|
return 0;
|
|
572
310
|
}
|
|
@@ -576,62 +314,62 @@ class V {
|
|
|
576
314
|
async _retry(t) {
|
|
577
315
|
try {
|
|
578
316
|
return await t();
|
|
579
|
-
} catch (
|
|
580
|
-
const
|
|
581
|
-
if (
|
|
582
|
-
await
|
|
583
|
-
for (const
|
|
584
|
-
if (await
|
|
317
|
+
} catch (n) {
|
|
318
|
+
const s = Math.min(this._calculateRetryDelay(n), K);
|
|
319
|
+
if (s !== 0 && this._retryCount > 0) {
|
|
320
|
+
await Ke(s, { signal: this._options.signal });
|
|
321
|
+
for (const r of this._options.hooks.beforeRetry)
|
|
322
|
+
if (await r({
|
|
585
323
|
request: this.request,
|
|
586
324
|
options: this._options,
|
|
587
|
-
error:
|
|
325
|
+
error: n,
|
|
588
326
|
retryCount: this._retryCount
|
|
589
|
-
}) ===
|
|
327
|
+
}) === Se)
|
|
590
328
|
return;
|
|
591
329
|
return this._retry(t);
|
|
592
330
|
}
|
|
593
|
-
throw
|
|
331
|
+
throw n;
|
|
594
332
|
}
|
|
595
333
|
}
|
|
596
334
|
async _fetch() {
|
|
597
|
-
for (const
|
|
598
|
-
const
|
|
599
|
-
if (
|
|
600
|
-
this.request =
|
|
335
|
+
for (const n of this._options.hooks.beforeRequest) {
|
|
336
|
+
const s = await n(this.request, this._options);
|
|
337
|
+
if (s instanceof Request) {
|
|
338
|
+
this.request = s;
|
|
601
339
|
break;
|
|
602
340
|
}
|
|
603
|
-
if (
|
|
604
|
-
return
|
|
341
|
+
if (s instanceof Response)
|
|
342
|
+
return s;
|
|
605
343
|
}
|
|
606
|
-
const t =
|
|
607
|
-
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) :
|
|
344
|
+
const t = Je(this.request, this._options);
|
|
345
|
+
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Ye(this.request.clone(), t, this.abortController, this._options);
|
|
608
346
|
}
|
|
609
347
|
/* istanbul ignore next */
|
|
610
|
-
_stream(t,
|
|
611
|
-
const
|
|
612
|
-
let
|
|
613
|
-
return t.status === 204 ? (
|
|
348
|
+
_stream(t, n) {
|
|
349
|
+
const s = Number(t.headers.get("content-length")) || 0;
|
|
350
|
+
let r = 0;
|
|
351
|
+
return t.status === 204 ? (n && n({ percent: 1, totalBytes: s, transferredBytes: r }, new Uint8Array()), new globalThis.Response(null, {
|
|
614
352
|
status: t.status,
|
|
615
353
|
statusText: t.statusText,
|
|
616
354
|
headers: t.headers
|
|
617
355
|
})) : new globalThis.Response(new globalThis.ReadableStream({
|
|
618
356
|
async start(i) {
|
|
619
|
-
const
|
|
620
|
-
|
|
621
|
-
async function
|
|
622
|
-
const { done:
|
|
623
|
-
if (
|
|
357
|
+
const o = t.body.getReader();
|
|
358
|
+
n && n({ percent: 0, transferredBytes: 0, totalBytes: s }, new Uint8Array());
|
|
359
|
+
async function u() {
|
|
360
|
+
const { done: c, value: _ } = await o.read();
|
|
361
|
+
if (c) {
|
|
624
362
|
i.close();
|
|
625
363
|
return;
|
|
626
364
|
}
|
|
627
|
-
if (
|
|
628
|
-
|
|
629
|
-
const h =
|
|
630
|
-
|
|
365
|
+
if (n) {
|
|
366
|
+
r += _.byteLength;
|
|
367
|
+
const h = s === 0 ? 0 : r / s;
|
|
368
|
+
n({ percent: h, transferredBytes: r, totalBytes: s }, _);
|
|
631
369
|
}
|
|
632
|
-
i.enqueue(
|
|
370
|
+
i.enqueue(_), await u();
|
|
633
371
|
}
|
|
634
|
-
await
|
|
372
|
+
await u();
|
|
635
373
|
}
|
|
636
374
|
}), {
|
|
637
375
|
status: t.status,
|
|
@@ -641,288 +379,608 @@ class V {
|
|
|
641
379
|
}
|
|
642
380
|
}
|
|
643
381
|
/*! MIT License © Sindre Sorhus */
|
|
644
|
-
const
|
|
645
|
-
const t = (
|
|
646
|
-
for (const
|
|
647
|
-
t[
|
|
648
|
-
return t.create = (
|
|
649
|
-
},
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
382
|
+
const Q = (e) => {
|
|
383
|
+
const t = (n, s) => F.create(n, $(e, s));
|
|
384
|
+
for (const n of pe)
|
|
385
|
+
t[n] = (s, r) => F.create(s, $(e, r, { method: n }));
|
|
386
|
+
return t.create = (n) => Q($(n)), t.extend = (n) => Q($(e, n)), t.stop = Se, t;
|
|
387
|
+
}, Ee = Q();
|
|
388
|
+
let H;
|
|
389
|
+
const m = {
|
|
390
|
+
CachedPrices: `${R.ThorswapApi}/tokenlist/cached-price`,
|
|
391
|
+
GasRates: `${R.ThorswapApi}/resource-worker/gasPrice/getAll`,
|
|
392
|
+
Quote: `${R.ThorswapApi}/aggregator/tokens/quote`,
|
|
393
|
+
Txn: `${R.ThorswapApi}/apiusage/v2/txn`,
|
|
394
|
+
TokenlistProviders: `${R.ThorswapApi}/tokenlist/providers`,
|
|
395
|
+
TokenList: `${R.ThorswapStatic}/token-list`,
|
|
396
|
+
Thorname: `${R.ThorswapApi}/thorname`
|
|
397
|
+
}, Re = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, ue = () => H || (H = Ee.create({ headers: Re }), H), mt = ({ apiKey: e, ...t }) => {
|
|
398
|
+
H = Ee.create({
|
|
399
|
+
...t,
|
|
400
|
+
headers: { ...Re, ...t.headers, "x-api-key": e }
|
|
401
|
+
});
|
|
402
|
+
}, S = {
|
|
403
|
+
get: (e, t) => ue().get(e, t).json(),
|
|
404
|
+
post: (e, t) => ue().post(e, t).json()
|
|
405
|
+
}, Qe = ({ tokens: e, ...t }) => {
|
|
406
|
+
const n = new URLSearchParams();
|
|
407
|
+
return e.filter((s, r, i) => i.findIndex((o) => o === s) === r).forEach((s) => n.append("tokens", JSON.stringify(s))), t.metadata && n.append("metadata", "true"), t.lookup && n.append("lookup", "true"), t.sparkline && n.append("sparkline", "true"), S.post(m.CachedPrices, {
|
|
408
|
+
body: n.toString(),
|
|
409
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" }
|
|
410
|
+
});
|
|
411
|
+
}, Et = {
|
|
412
|
+
getCachedPrices: Qe,
|
|
413
|
+
getQuote: (e) => S.get(m.Quote, { searchParams: e }),
|
|
414
|
+
getGasRates: () => S.get(m.GasRates),
|
|
415
|
+
getTxnDetails: (e) => S.get(m.Txn, { searchParams: e }),
|
|
416
|
+
getTokenlistProviders: () => S.get(m.TokenlistProviders),
|
|
417
|
+
getTokenList: (e) => S.get(`${m.TokenList}/${e}.json`),
|
|
418
|
+
getThornameAddresses: (e) => S.get(`${m.Thorname}/${e}`),
|
|
419
|
+
getThornameRegisteredChains: (e) => S.get(`${m.Thorname}/chains/${e}`),
|
|
420
|
+
getThornameRlookup: (e, t) => S.get(`${m.Thorname}/rlookup`, { searchParams: { address: e, chain: t } })
|
|
421
|
+
};
|
|
422
|
+
var ze = /* @__PURE__ */ ((e) => (e.SWAP_TC_TO_TC = "SWAP:TC-TC", e.SWAP_ETH_TO_TC = "SWAP:ERC20-TC", e.SWAP_TC_TO_ETH = "SWAP:TC-ERC20", e.SWAP_ETH_TO_ETH = "SWAP:ERC20-ERC20", e.SWAP_AVAX_TO_TC = "SWAP:AVAX-TC", e.SWAP_TC_TO_AVAX = "SWAP:TC-AVAX", e.SWAP_AVAX_TO_AVAX = "SWAP:AVAX-AVAX", e.SWAP_ETH_TO_AVAX = "SWAP:ETH-AVAX", e.SWAP_AVAX_TO_ETH = "SWAP:AVAX-ETH", e.SWAP_TC_TO_GAIA = "SWAP:TC-GAIA", e.SWAP_GAIA_TO_TC = "SWAP:GAIA-TC", e.SWAP_TC_TO_BNB = "SWAP:TC-BNB", e.SWAP_BNB_TO_TC = "SWAP:BNB-TC", e.SWAP_TC_TO_BTC = "SWAP:TC-BTC", e.SWAP_BTC_TO_TC = "SWAP:BTC-TC", e.SWAP_TC_TO_BCH = "SWAP:TC-BCH", e.SWAP_BCH_TO_TC = "SWAP:BCH-TC", e.SWAP_TC_TO_LTC = "SWAP:TC-LTC", e.SWAP_LTC_TO_TC = "SWAP:LTC-TC", e.SWAP_TC_TO_DOGE = "SWAP:TC-DOGE", e.SWAP_DOGE_TO_TC = "SWAP:DOGE-TC", e.TC_STATUS = "TC:STATUS", e.TC_TRANSFER = "TC:TRANSFER", e.TC_DEPOSIT = "TC:DEPOSIT", e.TC_SEND = "TC:SEND", e.TC_SWITCH = "TC:SWITCH", e.TC_LP_ADD = "TC:ADDLIQUIDITY", e.TC_LP_WITHDRAW = "TC:WITHDRAW", e.TC_TNS_CREATE = "TC:TNS-CREATE", e.TC_TNS_EXTEND = "TC:TNS-EXTEND", e.TC_TNS_UPDATE = "TC:TNS-UPDATE", e.TC_SAVINGS_ADD = "TC:ADDSAVINGS", e.TC_SAVINGS_WITHDRAW = "TC:WITHDRAWSAVINGS", e.TC_LENDING_OPEN = "TC:LENDINGOPEN", e.TC_LENDING_CLOSE = "TC:LENDINGCLOSE", e.ETH_APPROVAL = "ETH:APPROVAL", e.ETH_STATUS = "ETH:STATUS", e.ETH_TRANSFER_TO_TC = "ETH:TRANSFER:IN", e.ETH_TRANSFER_FROM_TC = "ETH:TRANSFER:OUT", e.AVAX_APPROVAL = "AVAX:APPROVAL", e.AVAX_STATUS = "AVAX:STATUS", e.AVAX_TRANSFER_TO_TC = "AVAX:TRANSFER:IN", e.AVAX_TRANSFER_FROM_TC = "AVAX:TRANSFER:OUT", e.BSC_APPROVAL = "BSC:APPROVAL", e.BSC_STATUS = "BSC:STATUS", e.BSC_TRANSFER_TO_TC = "BSC:TRANSFER:IN", e.BSC_TRANSFER_FROM_TC = "BSC:TRANSFER:OUT", e.APPROVAL = "APPROVAL", e.STATUS = "STATUS", e.TRANSFER_TO_TC = "TRANSFER:IN", e.TRANSFER_FROM_TC = "TRANSFER:OUT", e.UNSUPPORTED = "UNSUPPORTED", e.TC_LENDING = "TC:LENDING", e))(ze || {}), Ze = /* @__PURE__ */ ((e) => (e.PENDING = "pending", e.SUCCESS = "success", e.CANCELLED = "cancelled", e.REFUNDED = "refunded", e.REPLACED = "replaced", e.ERROR = "error", e.UNKNOWN = "unknown", e.NOT_STARTED = "not_started", e.NOT_FOUND = "not_found", e.RETRIES_EXCEEDED = "retries_exceeded", e.STREAMING = "streaming", e))(Ze || {}), et = /* @__PURE__ */ ((e) => (e[e.NOT_STARTED = 0] = "NOT_STARTED", e[e.SUCCESS = 1] = "SUCCESS", e[e.REFUNDED = 2] = "REFUNDED", e))(et || {});
|
|
423
|
+
const tt = "0x313ce567", Ie = async ({ chain: e, to: t }) => {
|
|
424
|
+
try {
|
|
425
|
+
const { result: n } = await S.post(Ue[e], {
|
|
426
|
+
headers: {
|
|
427
|
+
accept: "*/*",
|
|
428
|
+
"content-type": "application/json",
|
|
429
|
+
"cache-control": "no-cache"
|
|
430
|
+
},
|
|
431
|
+
body: JSON.stringify({
|
|
432
|
+
id: 44,
|
|
433
|
+
jsonrpc: "2.0",
|
|
434
|
+
method: "eth_call",
|
|
435
|
+
params: [{ to: t.toLowerCase(), data: tt }, "latest"]
|
|
436
|
+
})
|
|
437
|
+
});
|
|
438
|
+
return parseInt(BigInt(n).toString());
|
|
439
|
+
} catch (n) {
|
|
440
|
+
return console.error(n), d[e];
|
|
441
|
+
}
|
|
442
|
+
}, nt = async (e) => {
|
|
443
|
+
if (e === a.Ethereum)
|
|
444
|
+
return d.ETH;
|
|
445
|
+
const [, t] = e.split("-");
|
|
446
|
+
return t != null && t.startsWith("0x") ? Ie({ chain: a.Ethereum, to: t }) : d.ETH;
|
|
447
|
+
}, st = async (e) => {
|
|
448
|
+
const [, t] = e.split("-");
|
|
449
|
+
return t != null && t.startsWith("0x") ? Ie({ chain: a.Avalanche, to: t.toLowerCase() }) : d.AVAX;
|
|
450
|
+
}, rt = async (e) => e === a.BinanceSmartChain ? d.BSC : d.BSC, it = async ({ chain: e, symbol: t }) => {
|
|
451
|
+
switch (e) {
|
|
452
|
+
case a.Ethereum:
|
|
453
|
+
return nt(t);
|
|
454
|
+
case a.Avalanche:
|
|
455
|
+
return st(t);
|
|
456
|
+
case a.BinanceSmartChain:
|
|
457
|
+
return rt(t);
|
|
458
|
+
default:
|
|
459
|
+
return d[e];
|
|
460
|
+
}
|
|
461
|
+
}, Rt = {
|
|
462
|
+
[Y.Average]: 1.2,
|
|
463
|
+
[Y.Fast]: 1.5,
|
|
464
|
+
[Y.Fastest]: 2
|
|
465
|
+
}, fe = ({ chain: e, symbol: t }) => {
|
|
466
|
+
switch (e) {
|
|
467
|
+
case a.Bitcoin:
|
|
468
|
+
case a.BitcoinCash:
|
|
469
|
+
case a.Litecoin:
|
|
470
|
+
case a.Dogecoin:
|
|
471
|
+
case a.Binance:
|
|
472
|
+
case a.Ethereum:
|
|
473
|
+
case a.Avalanche:
|
|
474
|
+
return t === e;
|
|
475
|
+
case a.Arbitrum:
|
|
476
|
+
case a.Optimism:
|
|
477
|
+
return t === "ETH";
|
|
478
|
+
case a.Maya:
|
|
479
|
+
return t === "CACAO";
|
|
480
|
+
case a.Kujira:
|
|
481
|
+
return t === "KUJI";
|
|
482
|
+
case a.Cosmos:
|
|
483
|
+
return t === "ATOM";
|
|
484
|
+
case a.Polygon:
|
|
485
|
+
return t === "MATIC";
|
|
486
|
+
case a.BinanceSmartChain:
|
|
487
|
+
return t === "BNB";
|
|
488
|
+
case a.THORChain:
|
|
489
|
+
return t === "RUNE";
|
|
490
|
+
}
|
|
491
|
+
}, at = (e) => {
|
|
492
|
+
switch (e) {
|
|
493
|
+
case `${a.Ethereum}.THOR`:
|
|
494
|
+
return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
|
|
495
|
+
case `${a.Ethereum}.vTHOR`:
|
|
496
|
+
return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
|
|
497
|
+
case a.Cosmos:
|
|
498
|
+
return { identifier: "GAIA.ATOM", decimal: d[e] };
|
|
499
|
+
case a.THORChain:
|
|
500
|
+
return { identifier: "THOR.RUNE", decimal: d[e] };
|
|
501
|
+
case a.BinanceSmartChain:
|
|
502
|
+
return { identifier: "BSC.BNB", decimal: d[e] };
|
|
503
|
+
case a.Maya:
|
|
504
|
+
return { identifier: "MAYA.CACAO", decimal: d.MAYA };
|
|
505
|
+
case `${a.Maya}.MAYA`:
|
|
506
|
+
return { identifier: "MAYA.MAYA", decimal: 4 };
|
|
507
|
+
case `${a.Kujira}.USK`:
|
|
508
|
+
return { identifier: `${a.Kujira}.USK`, decimal: 6 };
|
|
509
|
+
case a.Kujira:
|
|
510
|
+
case a.Arbitrum:
|
|
511
|
+
case a.Optimism:
|
|
512
|
+
case a.BitcoinCash:
|
|
513
|
+
case a.Litecoin:
|
|
514
|
+
case a.Dogecoin:
|
|
515
|
+
case a.Binance:
|
|
516
|
+
case a.Avalanche:
|
|
517
|
+
case a.Polygon:
|
|
518
|
+
case a.Bitcoin:
|
|
519
|
+
case a.Ethereum:
|
|
520
|
+
return { identifier: `${e}.${e}`, decimal: d[e] };
|
|
521
|
+
}
|
|
522
|
+
}, ot = ({ chain: e, symbol: t }) => {
|
|
523
|
+
if (t.includes("/"))
|
|
524
|
+
return "Synth";
|
|
525
|
+
switch (e) {
|
|
526
|
+
case a.Bitcoin:
|
|
527
|
+
case a.BitcoinCash:
|
|
528
|
+
case a.Dogecoin:
|
|
529
|
+
case a.Litecoin:
|
|
530
|
+
case a.Maya:
|
|
531
|
+
case a.THORChain:
|
|
532
|
+
return "Native";
|
|
533
|
+
case a.Cosmos:
|
|
534
|
+
return t === "ATOM" ? "Native" : a.Cosmos;
|
|
535
|
+
case a.Kujira:
|
|
536
|
+
return t === a.Kujira ? "Native" : a.Kujira;
|
|
537
|
+
case a.Binance:
|
|
538
|
+
return t === a.Binance ? "Native" : "BEP2";
|
|
539
|
+
case a.BinanceSmartChain:
|
|
540
|
+
return t === a.Binance ? "Native" : "BEP20";
|
|
541
|
+
case a.Ethereum:
|
|
542
|
+
return t === a.Ethereum ? "Native" : "ERC20";
|
|
543
|
+
case a.Avalanche:
|
|
544
|
+
return t === a.Avalanche ? "Native" : a.Avalanche;
|
|
545
|
+
case a.Polygon:
|
|
546
|
+
return t === a.Polygon ? "Native" : "POLYGON";
|
|
547
|
+
case a.Arbitrum:
|
|
548
|
+
return [a.Ethereum, a.Arbitrum].includes(t) ? "Native" : "ARBITRUM";
|
|
549
|
+
case a.Optimism:
|
|
550
|
+
return [a.Ethereum, a.Optimism].includes(t) ? "Native" : "OPTIMISM";
|
|
551
|
+
}
|
|
552
|
+
}, It = (e) => {
|
|
553
|
+
var o;
|
|
554
|
+
const [t, ...n] = e.split("."), s = e.includes("/"), r = n.join("."), i = (o = r == null ? void 0 : r.split("-")) == null ? void 0 : o[0];
|
|
555
|
+
return { chain: t, symbol: r, ticker: i, synth: s };
|
|
556
|
+
}, ct = new RegExp(
|
|
557
|
+
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
|
|
558
|
+
"gmi"
|
|
559
|
+
), ut = (e) => {
|
|
560
|
+
const [t, n] = e.split(".");
|
|
561
|
+
if (!Be.includes(t))
|
|
656
562
|
return !0;
|
|
657
|
-
const [
|
|
658
|
-
|
|
563
|
+
const [, s] = n.split("-");
|
|
564
|
+
return fe({ chain: t, symbol: n }) || !!s;
|
|
565
|
+
}, ft = (e) => e.filter((t) => {
|
|
566
|
+
const n = `${t.chain}.${t.symbol}`;
|
|
567
|
+
return !ct.test(n) && ut(n) && t.value !== "0";
|
|
568
|
+
});
|
|
569
|
+
function lt({
|
|
570
|
+
liquidityUnits: e,
|
|
571
|
+
poolUnits: t,
|
|
572
|
+
runeDepth: n
|
|
573
|
+
}) {
|
|
574
|
+
const s = A(e), r = A(t), i = A(n), o = s.mul(i), u = r.mul(r).mul(2), c = r.mul(s).mul(2), _ = s.mul(s), h = r.mul(r).mul(r);
|
|
575
|
+
return o.mul(u.sub(c).add(_)).div(h);
|
|
576
|
+
}
|
|
577
|
+
function _t({
|
|
578
|
+
liquidityUnits: e,
|
|
579
|
+
poolUnits: t,
|
|
580
|
+
assetDepth: n
|
|
581
|
+
}) {
|
|
582
|
+
const s = A(e), r = A(t), i = A(n), o = s.mul(i), u = r.mul(r).mul(2), c = r.mul(s).mul(2), _ = s.mul(s), h = o.mul(u.sub(c).add(_)), P = r.mul(r).mul(r);
|
|
583
|
+
return h.div(P);
|
|
584
|
+
}
|
|
585
|
+
function Nt({
|
|
586
|
+
percent: e,
|
|
587
|
+
runeDepth: t,
|
|
588
|
+
liquidityUnits: n,
|
|
589
|
+
poolUnits: s
|
|
590
|
+
}) {
|
|
591
|
+
return lt({ runeDepth: t, liquidityUnits: n, poolUnits: s }).mul(e);
|
|
592
|
+
}
|
|
593
|
+
function Ct({
|
|
594
|
+
percent: e,
|
|
595
|
+
assetDepth: t,
|
|
596
|
+
liquidityUnits: n,
|
|
597
|
+
poolUnits: s
|
|
598
|
+
}) {
|
|
599
|
+
return _t({ assetDepth: t, liquidityUnits: n, poolUnits: s }).mul(e);
|
|
600
|
+
}
|
|
601
|
+
function A(e) {
|
|
602
|
+
return I.fromBigInt(BigInt(e), d.THOR);
|
|
603
|
+
}
|
|
604
|
+
function ht({
|
|
605
|
+
liquidityUnits: e,
|
|
606
|
+
poolUnits: t,
|
|
607
|
+
runeDepth: n,
|
|
608
|
+
assetDepth: s
|
|
609
|
+
}) {
|
|
610
|
+
return {
|
|
611
|
+
assetAmount: A(s).mul(e).div(t),
|
|
612
|
+
runeAmount: A(n).mul(e).div(t)
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
function gt({
|
|
616
|
+
liquidityUnits: e,
|
|
617
|
+
poolUnits: t,
|
|
618
|
+
runeDepth: n,
|
|
619
|
+
assetDepth: s,
|
|
620
|
+
percent: r
|
|
621
|
+
}) {
|
|
622
|
+
return Object.fromEntries(
|
|
623
|
+
Object.entries(ht({ liquidityUnits: e, poolUnits: t, runeDepth: n, assetDepth: s })).map(
|
|
624
|
+
([i, o]) => [i, o.mul(r)]
|
|
625
|
+
)
|
|
626
|
+
);
|
|
627
|
+
}
|
|
628
|
+
function Ot({
|
|
629
|
+
runeDepth: e,
|
|
630
|
+
poolUnits: t,
|
|
631
|
+
assetDepth: n,
|
|
632
|
+
liquidityUnits: s,
|
|
633
|
+
runeAmount: r,
|
|
634
|
+
assetAmount: i
|
|
635
|
+
}) {
|
|
636
|
+
const o = new I({ value: e, decimal: 8 }), u = new I({ value: n, decimal: 8 }), c = new I({ value: t, decimal: 8 }), _ = new I({ value: r, decimal: 8 }), h = new I({ value: i, decimal: 8 }), P = _.mul(u), ie = h.mul(o), ge = _.mul(h), Oe = o.mul(u), De = c.mul(P.add(ie.add(ge.mul(2)))), Pe = P.add(ie.add(Oe.mul(2))), ae = De.div(Pe), X = A(s).add(ae);
|
|
637
|
+
if (ae.getBaseValue("number") === 0)
|
|
638
|
+
return X.div(c).getBaseValue("number");
|
|
639
|
+
const be = c.add(X);
|
|
640
|
+
return X.div(be).getBaseValue("number");
|
|
641
|
+
}
|
|
642
|
+
function Dt({
|
|
643
|
+
runeAmount: e,
|
|
644
|
+
assetAmount: t,
|
|
645
|
+
runeDepth: n,
|
|
646
|
+
assetDepth: s
|
|
647
|
+
}) {
|
|
648
|
+
if (e === "0" || t === "0" || n === "0" || s === "0")
|
|
649
|
+
return 0;
|
|
650
|
+
const r = A(n), i = A(s), o = A(t), u = A(e), c = o.mul(r).sub(i.mul(u)), _ = i.mul(u).add(r.mul(i));
|
|
651
|
+
return Math.abs(c.div(_).getBaseValue("number"));
|
|
652
|
+
}
|
|
653
|
+
const Pt = (e, t) => {
|
|
654
|
+
switch (e) {
|
|
655
|
+
case E.LEAVE:
|
|
656
|
+
case E.BOND: {
|
|
657
|
+
const { address: n } = t;
|
|
658
|
+
return `${e}:${n}`;
|
|
659
|
+
}
|
|
660
|
+
case E.UNBOND: {
|
|
661
|
+
const { address: n, unbondAmount: s } = t;
|
|
662
|
+
return `${e}:${n}:${s}`;
|
|
663
|
+
}
|
|
664
|
+
case E.THORNAME_REGISTER: {
|
|
665
|
+
const { name: n, chain: s, address: r, owner: i } = t;
|
|
666
|
+
return `${e}:${n}:${s}:${r}${i ? `:${i}` : ""}`;
|
|
667
|
+
}
|
|
668
|
+
case E.DEPOSIT: {
|
|
669
|
+
const { chain: n, symbol: s, address: r, singleSide: i } = t;
|
|
670
|
+
return i ? `${e}:${n}/${s}::t:0` : `${e}:${((u, c) => {
|
|
671
|
+
switch (u) {
|
|
672
|
+
case a.Litecoin:
|
|
673
|
+
return "l";
|
|
674
|
+
case a.Dogecoin:
|
|
675
|
+
return "d";
|
|
676
|
+
case a.BitcoinCash:
|
|
677
|
+
return "c";
|
|
678
|
+
default:
|
|
679
|
+
return `${u}.${c}`;
|
|
680
|
+
}
|
|
681
|
+
})(n, s)}:${r || ""}:t:0`;
|
|
682
|
+
}
|
|
683
|
+
case E.WITHDRAW: {
|
|
684
|
+
const { chain: n, ticker: s, symbol: r, basisPoints: i, targetAssetString: o, singleSide: u } = t, c = n === "ETH" && s !== "ETH" ? `${s}-${r.slice(-3)}` : r, _ = !u && o ? `:${o}` : "";
|
|
685
|
+
return `${e}:${n}${u ? "/" : "."}${c}:${i}${_}`;
|
|
686
|
+
}
|
|
687
|
+
case E.OPEN_LOAN:
|
|
688
|
+
case E.CLOSE_LOAN: {
|
|
689
|
+
const { asset: n, address: s } = t;
|
|
690
|
+
return `${e}:${n}:${s}`;
|
|
691
|
+
}
|
|
692
|
+
default:
|
|
693
|
+
return "";
|
|
694
|
+
}
|
|
695
|
+
};
|
|
696
|
+
function bt(e) {
|
|
697
|
+
if (e < 0)
|
|
698
|
+
throw new Error("Invalid number of year");
|
|
699
|
+
return 10 + e;
|
|
700
|
+
}
|
|
701
|
+
function yt(e) {
|
|
702
|
+
if (e.length > 30)
|
|
703
|
+
return !1;
|
|
704
|
+
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
705
|
+
return !!e.match(t);
|
|
706
|
+
}
|
|
707
|
+
function wt([e, t, n, s, r]) {
|
|
708
|
+
return `${e}'/${t}'/${n}'/${s}${typeof r != "number" ? "" : `/${r}`}`;
|
|
709
|
+
}
|
|
710
|
+
const le = [...Object.values(a), "TERRA"];
|
|
711
|
+
function dt(e = "") {
|
|
712
|
+
const t = e.toUpperCase(), [n] = t.split(".");
|
|
713
|
+
if (le.includes(n))
|
|
714
|
+
return !0;
|
|
715
|
+
const [s] = t.split("/");
|
|
716
|
+
if (le.includes(s))
|
|
659
717
|
return !0;
|
|
660
718
|
throw new Error(
|
|
661
|
-
`Invalid identifier: ${
|
|
719
|
+
`Invalid identifier: ${e}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
662
720
|
);
|
|
663
721
|
}
|
|
664
|
-
const
|
|
665
|
-
function
|
|
666
|
-
value:
|
|
667
|
-
bigIntDecimal: t =
|
|
668
|
-
decimal:
|
|
722
|
+
const B = 8, N = (e) => 10n ** BigInt(e), b = (e) => Math.log10(parseFloat(e.toString()));
|
|
723
|
+
function G({
|
|
724
|
+
value: e,
|
|
725
|
+
bigIntDecimal: t = B,
|
|
726
|
+
decimal: n = B
|
|
669
727
|
}) {
|
|
670
|
-
if (
|
|
671
|
-
return
|
|
672
|
-
const
|
|
673
|
-
let
|
|
674
|
-
const i =
|
|
675
|
-
i > 0 && (
|
|
676
|
-
const
|
|
677
|
-
let
|
|
678
|
-
return parseInt(
|
|
728
|
+
if (n === 0)
|
|
729
|
+
return e.toString();
|
|
730
|
+
const s = e < 0n;
|
|
731
|
+
let r = e.toString().substring(s ? 1 : 0);
|
|
732
|
+
const i = n - (r.length - 1);
|
|
733
|
+
i > 0 && (r = "0".repeat(i) + r);
|
|
734
|
+
const o = r.length - n;
|
|
735
|
+
let u = r.slice(-n);
|
|
736
|
+
return parseInt(u[t]) >= 5 ? u = `${u.substring(0, t - 1)}${(parseInt(u[t - 1]) + 1).toString()}` : u = u.substring(0, t), `${s ? "-" : ""}${r.slice(0, o)}.${u}`.replace(
|
|
679
737
|
/\.?0*$/,
|
|
680
738
|
""
|
|
681
739
|
);
|
|
682
740
|
}
|
|
683
|
-
var
|
|
684
|
-
const
|
|
741
|
+
var C, y, f, D, k, Ne, U, z, L, Z;
|
|
742
|
+
const re = class re {
|
|
685
743
|
constructor(t) {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
const
|
|
695
|
-
this.decimal =
|
|
744
|
+
O(this, C);
|
|
745
|
+
O(this, f);
|
|
746
|
+
O(this, k);
|
|
747
|
+
O(this, U);
|
|
748
|
+
O(this, L);
|
|
749
|
+
p(this, "decimalMultiplier", 10n ** 8n);
|
|
750
|
+
p(this, "bigIntValue", 0n);
|
|
751
|
+
p(this, "decimal");
|
|
752
|
+
const n = ee(t), s = typeof t == "object";
|
|
753
|
+
this.decimal = s ? t.decimal : void 0, this.decimalMultiplier = s && "decimalMultiplier" in t ? t.decimalMultiplier : N(Math.max(_e(v(n)), this.decimal || 0)), T(this, k, Ne).call(this, n);
|
|
696
754
|
}
|
|
697
|
-
static fromBigInt(t,
|
|
698
|
-
return new
|
|
699
|
-
decimal:
|
|
700
|
-
value:
|
|
755
|
+
static fromBigInt(t, n) {
|
|
756
|
+
return new re({
|
|
757
|
+
decimal: n,
|
|
758
|
+
value: G({ value: t, bigIntDecimal: n, decimal: n })
|
|
701
759
|
});
|
|
702
760
|
}
|
|
703
761
|
static shiftDecimals({
|
|
704
762
|
value: t,
|
|
705
|
-
from:
|
|
706
|
-
to:
|
|
763
|
+
from: n,
|
|
764
|
+
to: s
|
|
707
765
|
}) {
|
|
708
766
|
return this.fromBigInt(
|
|
709
|
-
t.getBaseValue("bigint") *
|
|
710
|
-
|
|
767
|
+
t.getBaseValue("bigint") * N(s) / N(n),
|
|
768
|
+
s
|
|
711
769
|
);
|
|
712
770
|
}
|
|
713
771
|
set(t) {
|
|
714
772
|
return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
|
|
715
773
|
}
|
|
716
774
|
add(...t) {
|
|
717
|
-
return
|
|
775
|
+
return T(this, C, y).call(this, "add", ...t);
|
|
718
776
|
}
|
|
719
777
|
sub(...t) {
|
|
720
|
-
return
|
|
778
|
+
return T(this, C, y).call(this, "sub", ...t);
|
|
721
779
|
}
|
|
722
780
|
mul(...t) {
|
|
723
|
-
return
|
|
781
|
+
return T(this, C, y).call(this, "mul", ...t);
|
|
724
782
|
}
|
|
725
783
|
div(...t) {
|
|
726
|
-
return
|
|
784
|
+
return T(this, C, y).call(this, "div", ...t);
|
|
727
785
|
}
|
|
728
786
|
gt(t) {
|
|
729
|
-
return
|
|
787
|
+
return T(this, f, D).call(this, "gt", t);
|
|
730
788
|
}
|
|
731
789
|
gte(t) {
|
|
732
|
-
return
|
|
790
|
+
return T(this, f, D).call(this, "gte", t);
|
|
733
791
|
}
|
|
734
792
|
lt(t) {
|
|
735
|
-
return
|
|
793
|
+
return T(this, f, D).call(this, "lt", t);
|
|
736
794
|
}
|
|
737
795
|
lte(t) {
|
|
738
|
-
return
|
|
796
|
+
return T(this, f, D).call(this, "lte", t);
|
|
739
797
|
}
|
|
740
798
|
eqValue(t) {
|
|
741
|
-
return
|
|
799
|
+
return T(this, f, D).call(this, "eqValue", t);
|
|
742
800
|
}
|
|
743
801
|
// @ts-expect-error False positive
|
|
744
802
|
getValue(t) {
|
|
745
|
-
const
|
|
803
|
+
const n = this.formatBigIntToSafeValue(
|
|
746
804
|
this.bigIntValue,
|
|
747
|
-
this.decimal ||
|
|
805
|
+
this.decimal || b(this.decimalMultiplier)
|
|
748
806
|
);
|
|
749
807
|
switch (t) {
|
|
750
808
|
case "number":
|
|
751
|
-
return Number(
|
|
809
|
+
return Number(n);
|
|
752
810
|
case "string":
|
|
753
|
-
return
|
|
811
|
+
return n;
|
|
754
812
|
case "bigint":
|
|
755
813
|
return this.bigIntValue * 10n ** BigInt(this.decimal || 8n) / this.decimalMultiplier;
|
|
756
814
|
}
|
|
757
815
|
}
|
|
758
816
|
// @ts-expect-error
|
|
759
817
|
getBaseValue(t) {
|
|
760
|
-
const
|
|
818
|
+
const n = this.decimalMultiplier / N(this.decimal || d.THOR), s = this.bigIntValue / n;
|
|
761
819
|
switch (t) {
|
|
762
820
|
case "number":
|
|
763
|
-
return Number(
|
|
821
|
+
return Number(s);
|
|
764
822
|
case "string":
|
|
765
|
-
return
|
|
823
|
+
return s.toString();
|
|
766
824
|
case "bigint":
|
|
767
|
-
return
|
|
825
|
+
return s;
|
|
768
826
|
}
|
|
769
827
|
}
|
|
770
|
-
getBigIntValue(t,
|
|
771
|
-
if (!
|
|
828
|
+
getBigIntValue(t, n) {
|
|
829
|
+
if (!n && typeof t == "object")
|
|
772
830
|
return t.bigIntValue;
|
|
773
|
-
const
|
|
774
|
-
return
|
|
831
|
+
const s = ee(t), r = v(s);
|
|
832
|
+
return r === "0" || r === "undefined" ? 0n : T(this, L, Z).call(this, r, n);
|
|
775
833
|
}
|
|
776
834
|
toSignificant(t = 6) {
|
|
777
|
-
const [
|
|
778
|
-
if ((parseInt(
|
|
835
|
+
const [n, s] = this.getValue("string").split("."), r = n || "", i = s || "";
|
|
836
|
+
if ((parseInt(r) ? r.length + i.length : i.length) <= t)
|
|
779
837
|
return this.getValue("string");
|
|
780
|
-
if (
|
|
781
|
-
return
|
|
782
|
-
if (parseInt(
|
|
783
|
-
return `${
|
|
784
|
-
t -
|
|
838
|
+
if (r.length >= t)
|
|
839
|
+
return r.slice(0, t).padEnd(r.length, "0");
|
|
840
|
+
if (parseInt(r))
|
|
841
|
+
return `${r}.${i.slice(0, t - r.length)}`.padEnd(
|
|
842
|
+
t - r.length,
|
|
785
843
|
"0"
|
|
786
844
|
);
|
|
787
|
-
const
|
|
788
|
-
return `0.${
|
|
789
|
-
i.length - `${
|
|
845
|
+
const u = parseInt(i), c = `${u}`.slice(0, t);
|
|
846
|
+
return `0.${c.padStart(
|
|
847
|
+
i.length - `${u}`.length + c.length,
|
|
790
848
|
"0"
|
|
791
849
|
)}`;
|
|
792
850
|
}
|
|
793
851
|
toFixed(t = 6) {
|
|
794
|
-
const [
|
|
795
|
-
if (parseInt(
|
|
796
|
-
return `${
|
|
797
|
-
const
|
|
798
|
-
return `0.${
|
|
799
|
-
i.length - `${
|
|
852
|
+
const [n, s] = this.getValue("string").split("."), r = n || "", i = s || "";
|
|
853
|
+
if (parseInt(r))
|
|
854
|
+
return `${r}.${i.slice(0, t)}`.padEnd(t, "0");
|
|
855
|
+
const o = parseInt(i), u = `${o}`.slice(0, t);
|
|
856
|
+
return `0.${u.padStart(
|
|
857
|
+
i.length - `${o}`.length + u.length,
|
|
800
858
|
"0"
|
|
801
859
|
)}`;
|
|
802
860
|
}
|
|
803
861
|
toAbbreviation(t = 2) {
|
|
804
|
-
const
|
|
862
|
+
const n = this.getValue("number"), s = ["", "K", "M", "B", "T", "Q", "Qi", "S"], r = Math.floor(Math.log10(Math.abs(n)) / 3), i = s[r];
|
|
805
863
|
if (!i)
|
|
806
864
|
return this.getValue("string");
|
|
807
|
-
const
|
|
808
|
-
return `${(
|
|
865
|
+
const o = 10 ** (r * 3);
|
|
866
|
+
return `${(n / o).toFixed(t)}${i}`;
|
|
809
867
|
}
|
|
810
868
|
toCurrency(t = "$", {
|
|
811
|
-
currencyPosition:
|
|
812
|
-
decimal:
|
|
813
|
-
decimalSeparator:
|
|
869
|
+
currencyPosition: n = "start",
|
|
870
|
+
decimal: s = 2,
|
|
871
|
+
decimalSeparator: r = ".",
|
|
814
872
|
thousandSeparator: i = ","
|
|
815
873
|
} = {}) {
|
|
816
|
-
const
|
|
817
|
-
return `${
|
|
874
|
+
const o = this.getValue("number"), [u, c = ""] = o.toFixed(6).split("."), _ = u.replace(/\B(?=(\d{3})+(?!\d))/g, i), h = !u && !c ? "0.00" : u === "0" ? `${parseFloat(`0.${c}`)}`.replace(".", r) : `${_}${parseInt(c) ? `${r}${c.slice(0, s)}` : ""}`;
|
|
875
|
+
return `${n === "start" ? t : ""}${h}${n === "end" ? t : ""}`;
|
|
818
876
|
}
|
|
819
|
-
formatBigIntToSafeValue(t,
|
|
820
|
-
const
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
), i = t < 0n,
|
|
824
|
-
let h =
|
|
825
|
-
return parseInt(h[
|
|
877
|
+
formatBigIntToSafeValue(t, n) {
|
|
878
|
+
const s = n || this.decimal || B, r = Math.max(
|
|
879
|
+
s,
|
|
880
|
+
b(this.decimalMultiplier)
|
|
881
|
+
), i = t < 0n, o = t.toString().substring(i ? 1 : 0), u = r - (o.length - 1), c = u > 0 ? "0".repeat(u) + o : o, _ = c.length - r;
|
|
882
|
+
let h = c.slice(-r);
|
|
883
|
+
return parseInt(h[s]) >= 5 ? h = `${h.substring(0, s - 1)}${(parseInt(h[s - 1]) + 1).toString()}` : h = h.substring(0, s), `${i ? "-" : ""}${c.slice(
|
|
826
884
|
0,
|
|
827
|
-
|
|
885
|
+
_
|
|
828
886
|
)}.${h}`.replace(/\.?0*$/, "");
|
|
829
887
|
}
|
|
830
888
|
};
|
|
831
|
-
|
|
832
|
-
const
|
|
833
|
-
(
|
|
834
|
-
const h = this.getBigIntValue(
|
|
889
|
+
C = new WeakSet(), y = function(t, ...n) {
|
|
890
|
+
const s = T(this, U, z).call(this, this, ...n), r = Math.max(s, b(this.decimalMultiplier)), i = N(r), o = n.reduce(
|
|
891
|
+
(c, _) => {
|
|
892
|
+
const h = this.getBigIntValue(_, r);
|
|
835
893
|
switch (t) {
|
|
836
894
|
case "add":
|
|
837
|
-
return
|
|
895
|
+
return c + h;
|
|
838
896
|
case "sub":
|
|
839
|
-
return
|
|
897
|
+
return c - h;
|
|
840
898
|
case "mul":
|
|
841
|
-
return
|
|
899
|
+
return c * h / i;
|
|
842
900
|
case "div": {
|
|
843
901
|
if (h === 0n)
|
|
844
902
|
throw new RangeError("Division by zero");
|
|
845
|
-
return
|
|
903
|
+
return c * i / h;
|
|
846
904
|
}
|
|
847
905
|
default:
|
|
848
|
-
return
|
|
906
|
+
return c;
|
|
849
907
|
}
|
|
850
908
|
},
|
|
851
909
|
//normalize is to precision multiplier base
|
|
852
910
|
this.bigIntValue * i / this.decimalMultiplier
|
|
853
|
-
),
|
|
854
|
-
bigIntDecimal:
|
|
855
|
-
decimal:
|
|
856
|
-
value:
|
|
911
|
+
), u = G({
|
|
912
|
+
bigIntDecimal: r,
|
|
913
|
+
decimal: r,
|
|
914
|
+
value: o
|
|
857
915
|
});
|
|
858
916
|
return new this.constructor({
|
|
859
|
-
decimalMultiplier:
|
|
917
|
+
decimalMultiplier: N(r),
|
|
860
918
|
decimal: this.decimal,
|
|
861
|
-
value:
|
|
919
|
+
value: u,
|
|
862
920
|
identifier: this.toString()
|
|
863
921
|
});
|
|
864
|
-
},
|
|
865
|
-
const
|
|
922
|
+
}, f = new WeakSet(), D = function(t, ...n) {
|
|
923
|
+
const s = T(this, U, z).call(this, this, ...n), r = this.getBigIntValue(n[0], s), i = this.getBigIntValue(this, s);
|
|
866
924
|
switch (t) {
|
|
867
925
|
case "gt":
|
|
868
|
-
return i >
|
|
926
|
+
return i > r;
|
|
869
927
|
case "gte":
|
|
870
|
-
return i >=
|
|
928
|
+
return i >= r;
|
|
871
929
|
case "lt":
|
|
872
|
-
return i <
|
|
930
|
+
return i < r;
|
|
873
931
|
case "lte":
|
|
874
|
-
return i <=
|
|
932
|
+
return i <= r;
|
|
875
933
|
case "eqValue":
|
|
876
|
-
return i ===
|
|
934
|
+
return i === r;
|
|
877
935
|
}
|
|
878
|
-
},
|
|
879
|
-
const
|
|
880
|
-
this.bigIntValue =
|
|
881
|
-
},
|
|
882
|
-
const
|
|
883
|
-
return Math.max(...
|
|
884
|
-
},
|
|
885
|
-
const
|
|
886
|
-
return BigInt(`${i}${
|
|
936
|
+
}, k = new WeakSet(), Ne = function(t) {
|
|
937
|
+
const n = v(t) || "0";
|
|
938
|
+
this.bigIntValue = T(this, L, Z).call(this, n);
|
|
939
|
+
}, U = new WeakSet(), z = function(...t) {
|
|
940
|
+
const n = t.map((s) => typeof s == "object" ? s.decimal || b(s.decimalMultiplier) : _e(v(s))).filter(Boolean);
|
|
941
|
+
return Math.max(...n, B);
|
|
942
|
+
}, L = new WeakSet(), Z = function(t, n) {
|
|
943
|
+
const s = n ? N(n) : this.decimalMultiplier, r = b(s), [i = "", o = ""] = t.split(".");
|
|
944
|
+
return BigInt(`${i}${o.padEnd(r, "0")}`);
|
|
887
945
|
};
|
|
888
|
-
let
|
|
889
|
-
const
|
|
946
|
+
let W = re;
|
|
947
|
+
const Tt = Intl.NumberFormat("fullwide", {
|
|
890
948
|
useGrouping: !1,
|
|
891
949
|
maximumFractionDigits: 20
|
|
892
950
|
});
|
|
893
|
-
function
|
|
894
|
-
const
|
|
895
|
-
return
|
|
951
|
+
function v(e) {
|
|
952
|
+
const n = `${typeof e == "number" ? Tt.format(e) : ee(e)}`.replaceAll(",", ".").split(".");
|
|
953
|
+
return n.length > 1 ? `${n.slice(0, -1).join("")}.${n.at(-1)}` : n[0];
|
|
896
954
|
}
|
|
897
|
-
function
|
|
898
|
-
var
|
|
899
|
-
const t = ((
|
|
900
|
-
return Math.max(t,
|
|
955
|
+
function _e(e) {
|
|
956
|
+
var n;
|
|
957
|
+
const t = ((n = e.split(".")[1]) == null ? void 0 : n.length) || 0;
|
|
958
|
+
return Math.max(t, B);
|
|
901
959
|
}
|
|
902
|
-
function
|
|
903
|
-
return typeof
|
|
960
|
+
function ee(e) {
|
|
961
|
+
return typeof e == "object" ? "getValue" in e ? e.getValue("string") : e.value : e;
|
|
904
962
|
}
|
|
905
|
-
const
|
|
906
|
-
class
|
|
963
|
+
const w = /* @__PURE__ */ new Map();
|
|
964
|
+
class g extends W {
|
|
907
965
|
constructor({
|
|
908
|
-
value:
|
|
909
|
-
decimal:
|
|
910
|
-
tax:
|
|
966
|
+
value: n,
|
|
967
|
+
decimal: s,
|
|
968
|
+
tax: r,
|
|
911
969
|
chain: i,
|
|
912
|
-
symbol:
|
|
913
|
-
identifier:
|
|
970
|
+
symbol: o,
|
|
971
|
+
identifier: u
|
|
914
972
|
}) {
|
|
915
|
-
super(typeof
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
const
|
|
925
|
-
this.type =
|
|
973
|
+
super(typeof n == "object" ? n : { decimal: s, value: n });
|
|
974
|
+
p(this, "address");
|
|
975
|
+
p(this, "chain");
|
|
976
|
+
p(this, "isGasAsset", !1);
|
|
977
|
+
p(this, "isSynthetic", !1);
|
|
978
|
+
p(this, "symbol");
|
|
979
|
+
p(this, "tax");
|
|
980
|
+
p(this, "ticker");
|
|
981
|
+
p(this, "type");
|
|
982
|
+
const c = x(u || `${i}.${o}`);
|
|
983
|
+
this.type = ot(c), this.tax = r, this.chain = c.chain, this.ticker = c.ticker, this.symbol = c.symbol, this.address = c.address, this.isSynthetic = c.isSynthetic, this.isGasAsset = c.isGasAsset;
|
|
926
984
|
}
|
|
927
985
|
toString() {
|
|
928
986
|
return this.isSynthetic ? this.symbol : `${this.chain}.${this.symbol}`;
|
|
@@ -930,75 +988,75 @@ class A extends j {
|
|
|
930
988
|
toUrl() {
|
|
931
989
|
return this.isSynthetic ? `${this.chain}.${this.symbol.replace("/", ".")}` : this.toString();
|
|
932
990
|
}
|
|
933
|
-
eq({ chain:
|
|
934
|
-
return this.chain ===
|
|
991
|
+
eq({ chain: n, symbol: s }) {
|
|
992
|
+
return this.chain === n && this.symbol === s;
|
|
935
993
|
}
|
|
936
994
|
chainId() {
|
|
937
|
-
return
|
|
995
|
+
return Le[this.chain];
|
|
938
996
|
}
|
|
939
997
|
// THOR.RUNE
|
|
940
998
|
// THOR.ETH.ETH
|
|
941
999
|
// ETH.THOR-0x1234567890
|
|
942
|
-
static fromUrl(
|
|
943
|
-
const [
|
|
944
|
-
if (!
|
|
1000
|
+
static fromUrl(n, s = 0) {
|
|
1001
|
+
const [r, i, o] = n.split(".");
|
|
1002
|
+
if (!r || !i)
|
|
945
1003
|
throw new Error("Invalid asset url");
|
|
946
|
-
const
|
|
947
|
-
return
|
|
1004
|
+
const u = r === a.THORChain && o ? `${r}.${i}/${o}` : n;
|
|
1005
|
+
return J(u, s);
|
|
948
1006
|
}
|
|
949
|
-
static fromString(
|
|
950
|
-
return
|
|
1007
|
+
static fromString(n, s = 0) {
|
|
1008
|
+
return J(n, s);
|
|
951
1009
|
}
|
|
952
|
-
static fromIdentifier(
|
|
953
|
-
return
|
|
1010
|
+
static fromIdentifier(n, s = 0) {
|
|
1011
|
+
return J(n, s);
|
|
954
1012
|
}
|
|
955
|
-
static fromStringSync(
|
|
956
|
-
const { chain:
|
|
1013
|
+
static fromStringSync(n, s = 0) {
|
|
1014
|
+
const { chain: r, isSynthetic: i } = x(n), o = w.get(n.toUpperCase());
|
|
957
1015
|
if (i)
|
|
958
|
-
return
|
|
959
|
-
const { tax:
|
|
960
|
-
decimal: d[
|
|
961
|
-
identifier:
|
|
1016
|
+
return he(n, s);
|
|
1017
|
+
const { tax: u, decimal: c, identifier: _ } = o || {
|
|
1018
|
+
decimal: d[r],
|
|
1019
|
+
identifier: n
|
|
962
1020
|
};
|
|
963
|
-
return new
|
|
964
|
-
tax:
|
|
965
|
-
value:
|
|
966
|
-
identifier: i ?
|
|
967
|
-
decimal: i ? 8 :
|
|
1021
|
+
return new g({
|
|
1022
|
+
tax: u,
|
|
1023
|
+
value: V(s, c),
|
|
1024
|
+
identifier: i ? n : _,
|
|
1025
|
+
decimal: i ? 8 : c
|
|
968
1026
|
});
|
|
969
1027
|
}
|
|
970
|
-
static fromIdentifierSync(
|
|
971
|
-
const { chain:
|
|
1028
|
+
static fromIdentifierSync(n, s = 0) {
|
|
1029
|
+
const { chain: r, isSynthetic: i } = x(n), o = w.get(n);
|
|
972
1030
|
if (i)
|
|
973
|
-
return
|
|
974
|
-
const { tax:
|
|
975
|
-
decimal: d[
|
|
976
|
-
identifier:
|
|
1031
|
+
return he(n, s);
|
|
1032
|
+
const { tax: u, decimal: c, identifier: _ } = o || {
|
|
1033
|
+
decimal: d[r],
|
|
1034
|
+
identifier: n
|
|
977
1035
|
};
|
|
978
|
-
return new
|
|
1036
|
+
return new g({ tax: u, decimal: c, identifier: _, value: V(s, c) });
|
|
979
1037
|
}
|
|
980
|
-
static fromChainOrSignature(
|
|
981
|
-
const { decimal:
|
|
982
|
-
return new
|
|
1038
|
+
static fromChainOrSignature(n, s = 0) {
|
|
1039
|
+
const { decimal: r, identifier: i } = at(n);
|
|
1040
|
+
return new g({ value: V(s, r), decimal: r, identifier: i });
|
|
983
1041
|
}
|
|
984
1042
|
static loadStaticAssets() {
|
|
985
1043
|
return new Promise(
|
|
986
|
-
async (
|
|
1044
|
+
async (n, s) => {
|
|
987
1045
|
try {
|
|
988
|
-
const
|
|
989
|
-
Object.values(
|
|
990
|
-
var
|
|
991
|
-
(
|
|
992
|
-
|
|
993
|
-
identifier:
|
|
994
|
-
decimal: "decimals" in
|
|
1046
|
+
const r = await import("@swapkit/tokens");
|
|
1047
|
+
Object.values(r).forEach((i) => {
|
|
1048
|
+
var o;
|
|
1049
|
+
(o = i == null ? void 0 : i.tokens) == null || o.forEach(({ identifier: u, chain: c, ..._ }) => {
|
|
1050
|
+
w.set(u.toUpperCase(), {
|
|
1051
|
+
identifier: u,
|
|
1052
|
+
decimal: "decimals" in _ ? _.decimals : d[c]
|
|
995
1053
|
});
|
|
996
1054
|
});
|
|
997
|
-
}),
|
|
998
|
-
} catch (
|
|
999
|
-
console.error(
|
|
1055
|
+
}), n({ ok: !0 });
|
|
1056
|
+
} catch (r) {
|
|
1057
|
+
console.error(r), s({
|
|
1000
1058
|
ok: !1,
|
|
1001
|
-
error:
|
|
1059
|
+
error: r,
|
|
1002
1060
|
message: "Couldn't load static assets. Ensure you have installed @swapkit/tokens package"
|
|
1003
1061
|
});
|
|
1004
1062
|
}
|
|
@@ -1006,60 +1064,60 @@ class A extends j {
|
|
|
1006
1064
|
);
|
|
1007
1065
|
}
|
|
1008
1066
|
}
|
|
1009
|
-
function
|
|
1010
|
-
const t =
|
|
1011
|
-
switch (
|
|
1012
|
-
case
|
|
1013
|
-
case
|
|
1014
|
-
case
|
|
1067
|
+
function Vt(e) {
|
|
1068
|
+
const t = g.fromChainOrSignature(e);
|
|
1069
|
+
switch (e) {
|
|
1070
|
+
case a.Bitcoin:
|
|
1071
|
+
case a.Litecoin:
|
|
1072
|
+
case a.BitcoinCash:
|
|
1015
1073
|
return t.set(10001e-8);
|
|
1016
|
-
case
|
|
1074
|
+
case a.Dogecoin:
|
|
1017
1075
|
return t.set(1.00000001);
|
|
1018
|
-
case
|
|
1019
|
-
case
|
|
1076
|
+
case a.Avalanche:
|
|
1077
|
+
case a.Ethereum:
|
|
1020
1078
|
return t.set(1e-8);
|
|
1021
|
-
case
|
|
1022
|
-
case
|
|
1079
|
+
case a.THORChain:
|
|
1080
|
+
case a.Maya:
|
|
1023
1081
|
return t.set(0);
|
|
1024
|
-
case
|
|
1082
|
+
case a.Cosmos:
|
|
1025
1083
|
return t.set(1e-6);
|
|
1026
1084
|
default:
|
|
1027
1085
|
return t.set(1e-8);
|
|
1028
1086
|
}
|
|
1029
1087
|
}
|
|
1030
|
-
async function
|
|
1031
|
-
|
|
1032
|
-
const
|
|
1033
|
-
return
|
|
1088
|
+
async function J(e, t = 0) {
|
|
1089
|
+
dt(e);
|
|
1090
|
+
const n = w.get(e.toUpperCase()), s = (n == null ? void 0 : n.decimal) || await it(x(e));
|
|
1091
|
+
return n || w.set(e.toUpperCase(), { identifier: e, decimal: s }), new g({ decimal: s, value: V(t, s), identifier: e });
|
|
1034
1092
|
}
|
|
1035
|
-
function
|
|
1036
|
-
const [
|
|
1037
|
-
if (!
|
|
1093
|
+
function he(e, t = 0) {
|
|
1094
|
+
const [n, s] = e.split(".")[0].toUpperCase() === a.THORChain ? e.split(".").slice(1).join().split("/") : e.split("/");
|
|
1095
|
+
if (!n || !s)
|
|
1038
1096
|
throw new Error("Invalid asset identifier");
|
|
1039
|
-
return new
|
|
1097
|
+
return new g({
|
|
1040
1098
|
decimal: 8,
|
|
1041
|
-
value:
|
|
1042
|
-
identifier: `${
|
|
1099
|
+
value: V(t, 8),
|
|
1100
|
+
identifier: `${a.THORChain}.${n}/${s}`
|
|
1043
1101
|
});
|
|
1044
1102
|
}
|
|
1045
|
-
function
|
|
1046
|
-
return typeof
|
|
1103
|
+
function V(e, t) {
|
|
1104
|
+
return typeof e == "bigint" ? G({ value: e, bigIntDecimal: t, decimal: t }) : e;
|
|
1047
1105
|
}
|
|
1048
|
-
function
|
|
1049
|
-
const t =
|
|
1050
|
-
if (t && (!
|
|
1106
|
+
function x(e) {
|
|
1107
|
+
const t = e.slice(0, 14).includes("/"), [n, s] = e.split(".")[0].toUpperCase() === a.THORChain ? e.split(".").slice(1).join().split("/") : e.split("/");
|
|
1108
|
+
if (t && (!n || !s))
|
|
1051
1109
|
throw new Error("Invalid asset identifier");
|
|
1052
|
-
const
|
|
1110
|
+
const r = e.includes(".") && !t ? e : `${a.THORChain}.${s}`, [i, o] = r.split("."), [u, c] = (t ? s : o).split("-");
|
|
1053
1111
|
return {
|
|
1054
|
-
address:
|
|
1112
|
+
address: c == null ? void 0 : c.toLowerCase(),
|
|
1055
1113
|
chain: i,
|
|
1056
|
-
isGasAsset:
|
|
1114
|
+
isGasAsset: fe({ chain: i, symbol: o }),
|
|
1057
1115
|
isSynthetic: t,
|
|
1058
|
-
symbol: (t ? `${
|
|
1059
|
-
ticker:
|
|
1116
|
+
symbol: (t ? `${n}/` : "") + (c ? `${u}-${(c == null ? void 0 : c.toLowerCase()) ?? ""}` : o),
|
|
1117
|
+
ticker: u
|
|
1060
1118
|
};
|
|
1061
1119
|
}
|
|
1062
|
-
const
|
|
1120
|
+
const At = {
|
|
1063
1121
|
/**
|
|
1064
1122
|
* Core
|
|
1065
1123
|
*/
|
|
@@ -1118,48 +1176,55 @@ const re = {
|
|
|
1118
1176
|
*/
|
|
1119
1177
|
helpers_number_different_decimals: 99101
|
|
1120
1178
|
};
|
|
1121
|
-
class
|
|
1122
|
-
constructor(t,
|
|
1123
|
-
console.error(
|
|
1179
|
+
class Ce extends Error {
|
|
1180
|
+
constructor(t, n) {
|
|
1181
|
+
console.error(n, { stack: n == null ? void 0 : n.stack, message: n == null ? void 0 : n.message }), super(t, { cause: { code: At[t], message: t } }), Object.setPrototypeOf(this, Ce.prototype);
|
|
1124
1182
|
}
|
|
1125
1183
|
}
|
|
1126
|
-
class
|
|
1184
|
+
class I extends W {
|
|
1127
1185
|
eq(t) {
|
|
1128
1186
|
return this.eqValue(t);
|
|
1129
1187
|
}
|
|
1130
|
-
static fromBigInt(t,
|
|
1131
|
-
return new
|
|
1132
|
-
decimal:
|
|
1133
|
-
value:
|
|
1188
|
+
static fromBigInt(t, n) {
|
|
1189
|
+
return new I({
|
|
1190
|
+
decimal: n,
|
|
1191
|
+
value: G({ value: t, bigIntDecimal: n, decimal: n })
|
|
1134
1192
|
});
|
|
1135
1193
|
}
|
|
1136
1194
|
}
|
|
1137
1195
|
export {
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1196
|
+
m as ApiEndpoints,
|
|
1197
|
+
g as AssetValue,
|
|
1198
|
+
W as BigIntArithmetics,
|
|
1199
|
+
S as RequestClient,
|
|
1200
|
+
et as StreamingSwapProgressStatus,
|
|
1201
|
+
Et as SwapKitApi,
|
|
1202
|
+
Ce as SwapKitError,
|
|
1203
|
+
I as SwapKitNumber,
|
|
1204
|
+
ze as TransactionType,
|
|
1205
|
+
Ze as TxStatus,
|
|
1206
|
+
It as assetFromString,
|
|
1207
|
+
Re as defaultRequestHeaders,
|
|
1208
|
+
wt as derivationPathToString,
|
|
1209
|
+
ft as filterAssets,
|
|
1210
|
+
G as formatBigIntToSafeValue,
|
|
1211
|
+
Rt as gasFeeMultiplier,
|
|
1212
|
+
ot as getAssetType,
|
|
1213
|
+
_t as getAsymmetricAssetShare,
|
|
1214
|
+
Ct as getAsymmetricAssetWithdrawAmount,
|
|
1215
|
+
lt as getAsymmetricRuneShare,
|
|
1216
|
+
Nt as getAsymmetricRuneWithdrawAmount,
|
|
1217
|
+
at as getCommonAssetInfo,
|
|
1218
|
+
it as getDecimal,
|
|
1219
|
+
Ot as getEstimatedPoolShare,
|
|
1220
|
+
Dt as getLiquiditySlippage,
|
|
1221
|
+
Pt as getMemoFor,
|
|
1222
|
+
Vt as getMinAmountByChain,
|
|
1223
|
+
ht as getSymmetricPoolShare,
|
|
1224
|
+
gt as getSymmetricWithdraw,
|
|
1225
|
+
bt as getTHORNameCost,
|
|
1226
|
+
fe as isGasAsset,
|
|
1227
|
+
mt as setRequestClientConfig,
|
|
1228
|
+
yt as validateTHORName
|
|
1164
1229
|
};
|
|
1165
1230
|
//# sourceMappingURL=index.es.js.map
|