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