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