@swapkit/helpers 1.0.0-rc.8 → 1.0.0-rc.81
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/LICENSE +1 -1
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +143 -89
- package/dist/index.es.js +578 -446
- package/dist/index.es.js.map +1 -0
- package/package.json +19 -19
- package/src/helpers/__tests__/asset.test.ts +64 -62
- package/src/helpers/__tests__/memo.test.ts +52 -40
- package/src/helpers/__tests__/others.test.ts +57 -30
- package/src/helpers/asset.ts +122 -96
- package/src/helpers/liquidity.ts +50 -42
- package/src/helpers/memo.ts +30 -28
- package/src/helpers/others.ts +30 -56
- package/src/helpers/validators.ts +7 -6
- package/src/index.ts +10 -8
- package/src/modules/__tests__/assetValue.test.ts +329 -121
- package/src/modules/__tests__/bigIntArithmetics.test.ts +30 -0
- package/src/modules/__tests__/swapKitNumber.test.ts +306 -183
- package/src/modules/assetValue.ts +214 -152
- package/src/modules/bigIntArithmetics.ts +214 -146
- package/src/modules/swapKitError.ts +30 -5
- package/src/modules/swapKitNumber.ts +8 -1
- package/src/types.ts +30 -0
package/dist/index.es.js
CHANGED
|
@@ -1,330 +1,351 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
var it = Object.defineProperty;
|
|
2
|
+
var st = (n, t, e) => t in n ? it(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
|
|
3
|
+
var f = (n, t, e) => (st(n, typeof t != "symbol" ? t + "" : t, e), e), at = (n, t, e) => {
|
|
4
4
|
if (!t.has(n))
|
|
5
5
|
throw TypeError("Cannot " + e);
|
|
6
6
|
};
|
|
7
|
-
var
|
|
7
|
+
var v = (n, t, e) => {
|
|
8
8
|
if (t.has(n))
|
|
9
9
|
throw TypeError("Cannot add the same private member more than once");
|
|
10
10
|
t instanceof WeakSet ? t.add(n) : t.set(n, e);
|
|
11
11
|
};
|
|
12
|
-
var
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return 10 + n;
|
|
18
|
-
}, Ct = (n) => {
|
|
19
|
-
if (n.length > 30)
|
|
20
|
-
return !1;
|
|
21
|
-
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
22
|
-
return !!n.match(t);
|
|
23
|
-
}, Vt = ([n, t, e, r, s]) => `${n}'/${t}'/${e}'/${r}${typeof s != "number" ? "" : `/${s}`}`, Tt = async (n, t) => {
|
|
12
|
+
var h = (n, t, e) => (at(n, t, "access private method"), e);
|
|
13
|
+
import { RequestClient as ct } from "@swapkit/api";
|
|
14
|
+
export * from "@swapkit/api";
|
|
15
|
+
import { FeeOption as P, BaseDecimal as m, Chain as a, EVMChains as ot, ChainToRPC as lt, MemoType as $, ChainToChainId as ut } from "@swapkit/types";
|
|
16
|
+
const dt = "0x313ce567", z = async ({ chain: n, to: t }) => {
|
|
24
17
|
try {
|
|
25
|
-
const e =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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 }) => {
|
|
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"],
|
|
18
|
+
const { result: e } = await ct.post(lt[n], {
|
|
19
|
+
headers: {
|
|
20
|
+
accept: "*/*",
|
|
21
|
+
"content-type": "application/json",
|
|
22
|
+
"cache-control": "no-cache"
|
|
23
|
+
},
|
|
24
|
+
body: JSON.stringify({
|
|
55
25
|
id: 44,
|
|
56
|
-
jsonrpc: "2.0"
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return parseInt(BigInt(
|
|
26
|
+
jsonrpc: "2.0",
|
|
27
|
+
method: "eth_call",
|
|
28
|
+
params: [{ to: t.toLowerCase(), data: dt }, "latest"]
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
return Number.parseInt(BigInt(e).toString());
|
|
62
32
|
} catch (e) {
|
|
63
33
|
return console.error(e), m[n];
|
|
64
34
|
}
|
|
65
|
-
},
|
|
66
|
-
if (n ===
|
|
35
|
+
}, mt = (n) => {
|
|
36
|
+
if (n === a.Ethereum)
|
|
67
37
|
return m.ETH;
|
|
68
38
|
const [, t] = n.split("-");
|
|
69
|
-
return t != null && t.startsWith("0x") ?
|
|
70
|
-
},
|
|
39
|
+
return t != null && t.startsWith("0x") ? z({ chain: a.Ethereum, to: t }) : m.ETH;
|
|
40
|
+
}, ht = (n) => {
|
|
71
41
|
const [, t] = n.split("-");
|
|
72
|
-
return t != null && t.startsWith("0x") ?
|
|
73
|
-
},
|
|
42
|
+
return t != null && t.startsWith("0x") ? z({ chain: a.Avalanche, to: t.toLowerCase() }) : m.AVAX;
|
|
43
|
+
}, _t = (n) => n === a.BinanceSmartChain ? m.BSC : m.BSC, ft = ({ chain: n, symbol: t }) => {
|
|
74
44
|
switch (n) {
|
|
75
|
-
case
|
|
76
|
-
return
|
|
77
|
-
case
|
|
78
|
-
return
|
|
79
|
-
case
|
|
80
|
-
return
|
|
45
|
+
case a.Ethereum:
|
|
46
|
+
return mt(t);
|
|
47
|
+
case a.Avalanche:
|
|
48
|
+
return ht(t);
|
|
49
|
+
case a.BinanceSmartChain:
|
|
50
|
+
return _t(t);
|
|
81
51
|
default:
|
|
82
52
|
return m[n];
|
|
83
53
|
}
|
|
84
|
-
},
|
|
85
|
-
[
|
|
86
|
-
[
|
|
87
|
-
[
|
|
88
|
-
},
|
|
54
|
+
}, Ot = {
|
|
55
|
+
[P.Average]: 1.2,
|
|
56
|
+
[P.Fast]: 1.5,
|
|
57
|
+
[P.Fastest]: 2
|
|
58
|
+
}, J = ({ chain: n, symbol: t }) => {
|
|
89
59
|
switch (n) {
|
|
90
|
-
case
|
|
91
|
-
case
|
|
92
|
-
case i.Litecoin:
|
|
93
|
-
case i.Dogecoin:
|
|
94
|
-
case i.Binance:
|
|
95
|
-
case i.Ethereum:
|
|
96
|
-
case i.Avalanche:
|
|
97
|
-
return t === n;
|
|
98
|
-
case i.Arbitrum:
|
|
99
|
-
case i.Optimism:
|
|
60
|
+
case a.Arbitrum:
|
|
61
|
+
case a.Optimism:
|
|
100
62
|
return t === "ETH";
|
|
101
|
-
case
|
|
63
|
+
case a.Maya:
|
|
102
64
|
return t === "CACAO";
|
|
103
|
-
case
|
|
65
|
+
case a.Kujira:
|
|
104
66
|
return t === "KUJI";
|
|
105
|
-
case
|
|
67
|
+
case a.Cosmos:
|
|
106
68
|
return t === "ATOM";
|
|
107
|
-
case
|
|
69
|
+
case a.Polygon:
|
|
108
70
|
return t === "MATIC";
|
|
109
|
-
case
|
|
71
|
+
case a.BinanceSmartChain:
|
|
110
72
|
return t === "BNB";
|
|
111
|
-
case
|
|
73
|
+
case a.THORChain:
|
|
112
74
|
return t === "RUNE";
|
|
75
|
+
default:
|
|
76
|
+
return t === n;
|
|
113
77
|
}
|
|
114
|
-
},
|
|
78
|
+
}, gt = (n) => {
|
|
115
79
|
switch (n) {
|
|
116
|
-
case
|
|
80
|
+
case `${a.Ethereum}.THOR`:
|
|
117
81
|
return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
|
|
118
|
-
case
|
|
82
|
+
case `${a.Ethereum}.vTHOR`:
|
|
119
83
|
return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
|
|
120
|
-
case
|
|
84
|
+
case a.Cosmos:
|
|
121
85
|
return { identifier: "GAIA.ATOM", decimal: m[n] };
|
|
122
|
-
case
|
|
86
|
+
case a.THORChain:
|
|
123
87
|
return { identifier: "THOR.RUNE", decimal: m[n] };
|
|
124
|
-
case
|
|
88
|
+
case a.BinanceSmartChain:
|
|
125
89
|
return { identifier: "BSC.BNB", decimal: m[n] };
|
|
126
|
-
case
|
|
90
|
+
case a.Maya:
|
|
127
91
|
return { identifier: "MAYA.CACAO", decimal: m.MAYA };
|
|
128
|
-
case
|
|
92
|
+
case `${a.Maya}.MAYA`:
|
|
129
93
|
return { identifier: "MAYA.MAYA", decimal: 4 };
|
|
130
|
-
case
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
case i.BitcoinCash:
|
|
134
|
-
case i.Litecoin:
|
|
135
|
-
case i.Dogecoin:
|
|
136
|
-
case i.Binance:
|
|
137
|
-
case i.Avalanche:
|
|
138
|
-
case i.Polygon:
|
|
139
|
-
case i.Bitcoin:
|
|
140
|
-
case i.Ethereum:
|
|
94
|
+
case `${a.Kujira}.USK`:
|
|
95
|
+
return { identifier: `${a.Kujira}.USK`, decimal: 6 };
|
|
96
|
+
default:
|
|
141
97
|
return { identifier: `${n}.${n}`, decimal: m[n] };
|
|
142
98
|
}
|
|
143
|
-
},
|
|
99
|
+
}, pt = ({ chain: n, symbol: t }) => {
|
|
144
100
|
if (t.includes("/"))
|
|
145
101
|
return "Synth";
|
|
146
102
|
switch (n) {
|
|
147
|
-
case
|
|
148
|
-
|
|
149
|
-
case
|
|
150
|
-
|
|
151
|
-
case
|
|
152
|
-
|
|
103
|
+
case a.Cosmos:
|
|
104
|
+
return t === "ATOM" ? "Native" : a.Cosmos;
|
|
105
|
+
case a.Kujira:
|
|
106
|
+
return t === a.Kujira ? "Native" : a.Kujira;
|
|
107
|
+
case a.Binance:
|
|
108
|
+
return t === a.Binance ? "Native" : "BEP2";
|
|
109
|
+
case a.BinanceSmartChain:
|
|
110
|
+
return t === a.Binance ? "Native" : "BEP20";
|
|
111
|
+
case a.Ethereum:
|
|
112
|
+
return t === a.Ethereum ? "Native" : "ERC20";
|
|
113
|
+
case a.Avalanche:
|
|
114
|
+
return t === a.Avalanche ? "Native" : a.Avalanche;
|
|
115
|
+
case a.Polygon:
|
|
116
|
+
return t === a.Polygon ? "Native" : "POLYGON";
|
|
117
|
+
case a.Arbitrum:
|
|
118
|
+
return [a.Ethereum, a.Arbitrum].includes(t) ? "Native" : "ARBITRUM";
|
|
119
|
+
case a.Optimism:
|
|
120
|
+
return [a.Ethereum, a.Optimism].includes(t) ? "Native" : "OPTIMISM";
|
|
121
|
+
default:
|
|
153
122
|
return "Native";
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
case i.BinanceSmartChain:
|
|
161
|
-
return t === i.Binance ? "Native" : "BEP20";
|
|
162
|
-
case i.Ethereum:
|
|
163
|
-
return t === i.Ethereum ? "Native" : "ERC20";
|
|
164
|
-
case i.Avalanche:
|
|
165
|
-
return t === i.Avalanche ? "Native" : i.Avalanche;
|
|
166
|
-
case i.Polygon:
|
|
167
|
-
return t === i.Polygon ? "Native" : "POLYGON";
|
|
168
|
-
case i.Arbitrum:
|
|
169
|
-
return [i.Ethereum, i.Arbitrum].includes(t) ? "Native" : "ARBITRUM";
|
|
170
|
-
case i.Optimism:
|
|
171
|
-
return [i.Ethereum, i.Optimism].includes(t) ? "Native" : "OPTIMISM";
|
|
172
|
-
}
|
|
173
|
-
}, yt = (n) => {
|
|
174
|
-
var c;
|
|
175
|
-
const [t, ...e] = n.split("."), r = n.includes("/"), s = e.join("."), a = (c = s == null ? void 0 : s.split("-")) == null ? void 0 : c[0];
|
|
176
|
-
return { chain: t, symbol: s, ticker: a, synth: r };
|
|
177
|
-
}, gt = new RegExp(
|
|
123
|
+
}
|
|
124
|
+
}, Tt = (n) => {
|
|
125
|
+
var l;
|
|
126
|
+
const [t, ...e] = n.split("."), r = n.includes("/"), i = e.join("."), s = (l = i == null ? void 0 : i.split("-")) == null ? void 0 : l[0];
|
|
127
|
+
return { chain: t, symbol: i, ticker: s, synth: r };
|
|
128
|
+
}, $t = new RegExp(
|
|
178
129
|
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
|
|
179
130
|
"gmi"
|
|
180
|
-
),
|
|
181
|
-
|
|
182
|
-
|
|
131
|
+
), At = (n) => {
|
|
132
|
+
const [t, e] = n.split(".");
|
|
133
|
+
if (!ot.includes(t))
|
|
134
|
+
return !0;
|
|
135
|
+
const [, r] = e.split("-");
|
|
136
|
+
return J({ chain: t, symbol: e }) || !!r;
|
|
137
|
+
}, Vt = (n) => n.filter(({ chain: t, value: e, symbol: r }) => {
|
|
138
|
+
const i = `${t}.${r}`;
|
|
139
|
+
return !$t.test(i) && At(i) && e !== "0";
|
|
140
|
+
});
|
|
141
|
+
async function Nt(n) {
|
|
142
|
+
const t = await import("@swapkit/tokens");
|
|
143
|
+
for (const e of Object.values(t))
|
|
144
|
+
for (const { identifier: r, chain: i, ...s } of e.tokens)
|
|
145
|
+
if ("identifier" in n && r === n.identifier || "address" in s && "chain" in n && i === n.chain && s.address.toLowerCase() === n.contract.toLowerCase())
|
|
146
|
+
return r;
|
|
147
|
+
}
|
|
148
|
+
function bt({
|
|
183
149
|
liquidityUnits: n,
|
|
184
150
|
poolUnits: t,
|
|
185
151
|
runeDepth: e
|
|
186
|
-
})
|
|
187
|
-
const r =
|
|
188
|
-
return
|
|
189
|
-
}
|
|
152
|
+
}) {
|
|
153
|
+
const r = _(n), i = _(t), s = _(e), l = r.mul(s), o = i.mul(i).mul(2), c = i.mul(r).mul(2), u = r.mul(r), d = i.mul(i).mul(i);
|
|
154
|
+
return l.mul(o.sub(c).add(u)).div(d);
|
|
155
|
+
}
|
|
156
|
+
function wt({
|
|
190
157
|
liquidityUnits: n,
|
|
191
158
|
poolUnits: t,
|
|
192
159
|
assetDepth: e
|
|
193
|
-
})
|
|
194
|
-
const r =
|
|
195
|
-
return d.div(
|
|
196
|
-
}
|
|
160
|
+
}) {
|
|
161
|
+
const r = _(n), i = _(t), s = _(e), l = r.mul(s), o = i.mul(i).mul(2), c = i.mul(r).mul(2), u = r.mul(r), d = l.mul(o.sub(c).add(u)), y = i.mul(i).mul(i);
|
|
162
|
+
return d.div(y);
|
|
163
|
+
}
|
|
164
|
+
function Et({
|
|
197
165
|
percent: n,
|
|
198
166
|
runeDepth: t,
|
|
199
167
|
liquidityUnits: e,
|
|
200
168
|
poolUnits: r
|
|
201
|
-
})
|
|
169
|
+
}) {
|
|
170
|
+
return bt({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(n);
|
|
171
|
+
}
|
|
172
|
+
function Rt({
|
|
202
173
|
percent: n,
|
|
203
174
|
assetDepth: t,
|
|
204
175
|
liquidityUnits: e,
|
|
205
176
|
poolUnits: r
|
|
206
|
-
})
|
|
177
|
+
}) {
|
|
178
|
+
return wt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(n);
|
|
179
|
+
}
|
|
180
|
+
function _(n) {
|
|
181
|
+
return g.fromBigInt(BigInt(n), m.THOR);
|
|
182
|
+
}
|
|
183
|
+
function vt({
|
|
207
184
|
liquidityUnits: n,
|
|
208
185
|
poolUnits: t,
|
|
209
186
|
runeDepth: e,
|
|
210
187
|
assetDepth: r
|
|
211
|
-
})
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
188
|
+
}) {
|
|
189
|
+
return {
|
|
190
|
+
assetAmount: _(r).mul(n).div(t),
|
|
191
|
+
runeAmount: _(e).mul(n).div(t)
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function xt({
|
|
215
195
|
liquidityUnits: n,
|
|
216
196
|
poolUnits: t,
|
|
217
197
|
runeDepth: e,
|
|
218
198
|
assetDepth: r,
|
|
219
|
-
percent:
|
|
220
|
-
})
|
|
221
|
-
Object.
|
|
222
|
-
(
|
|
223
|
-
|
|
224
|
-
)
|
|
199
|
+
percent: i
|
|
200
|
+
}) {
|
|
201
|
+
return Object.fromEntries(
|
|
202
|
+
Object.entries(vt({ liquidityUnits: n, poolUnits: t, runeDepth: e, assetDepth: r })).map(
|
|
203
|
+
([s, l]) => [s, l.mul(i)]
|
|
204
|
+
)
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
function kt({
|
|
225
208
|
runeDepth: n,
|
|
226
209
|
poolUnits: t,
|
|
227
210
|
assetDepth: e,
|
|
228
211
|
liquidityUnits: r,
|
|
229
|
-
runeAmount:
|
|
230
|
-
assetAmount:
|
|
231
|
-
})
|
|
232
|
-
const
|
|
233
|
-
if (
|
|
234
|
-
return
|
|
235
|
-
const
|
|
236
|
-
return
|
|
237
|
-
}
|
|
212
|
+
runeAmount: i,
|
|
213
|
+
assetAmount: s
|
|
214
|
+
}) {
|
|
215
|
+
const l = new g({ value: n, decimal: 8 }), o = new g({ value: e, decimal: 8 }), c = new g({ value: t, decimal: 8 }), u = new g({ value: i, decimal: 8 }), d = new g({ value: s, decimal: 8 }), y = u.mul(o), W = d.mul(l), Z = u.mul(d), tt = l.mul(o), et = c.mul(y.add(W.add(Z.mul(2)))), nt = y.add(W.add(tt.mul(2))), G = et.div(nt), j = _(r).add(G);
|
|
216
|
+
if (G.getBaseValue("number") === 0)
|
|
217
|
+
return j.div(c).getBaseValue("number");
|
|
218
|
+
const rt = c.add(j);
|
|
219
|
+
return j.div(rt).getBaseValue("number");
|
|
220
|
+
}
|
|
221
|
+
function Ht({
|
|
238
222
|
runeAmount: n,
|
|
239
223
|
assetAmount: t,
|
|
240
224
|
runeDepth: e,
|
|
241
225
|
assetDepth: r
|
|
242
|
-
})
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}) => e === "ETH" && t !== "ETH" ? `${t}-${n.slice(-3)}` : n, Ht = (n, t) => {
|
|
226
|
+
}) {
|
|
227
|
+
if (n === "0" || t === "0" || e === "0" || r === "0")
|
|
228
|
+
return 0;
|
|
229
|
+
const i = _(e), s = _(r), l = _(t), o = _(n), c = l.mul(i).sub(s.mul(o)), u = s.mul(o).add(i.mul(s));
|
|
230
|
+
return Math.abs(c.div(u).getBaseValue("number"));
|
|
231
|
+
}
|
|
232
|
+
const jt = (n, t) => {
|
|
250
233
|
switch (n) {
|
|
251
|
-
case
|
|
252
|
-
case
|
|
234
|
+
case $.LEAVE:
|
|
235
|
+
case $.BOND: {
|
|
253
236
|
const { address: e } = t;
|
|
254
237
|
return `${n}:${e}`;
|
|
255
238
|
}
|
|
256
|
-
case
|
|
239
|
+
case $.UNBOND: {
|
|
257
240
|
const { address: e, unbondAmount: r } = t;
|
|
258
|
-
return `${n}:${e}:${r
|
|
241
|
+
return `${n}:${e}:${r}`;
|
|
259
242
|
}
|
|
260
|
-
case
|
|
261
|
-
const { name: e, chain: r, address:
|
|
262
|
-
return `${n}:${e}:${r}:${
|
|
243
|
+
case $.THORNAME_REGISTER: {
|
|
244
|
+
const { name: e, chain: r, address: i, owner: s } = t;
|
|
245
|
+
return `${n}:${e}:${r}:${i}${s ? `:${s}` : ""}`;
|
|
263
246
|
}
|
|
264
|
-
case
|
|
265
|
-
const { chain: e, symbol: r, address:
|
|
266
|
-
return
|
|
247
|
+
case $.DEPOSIT: {
|
|
248
|
+
const { chain: e, symbol: r, address: i, singleSide: s } = t;
|
|
249
|
+
return s ? `${n}:${e}/${r}` : `${n}:${((o, c) => {
|
|
250
|
+
switch (o) {
|
|
251
|
+
case a.Litecoin:
|
|
252
|
+
return "l";
|
|
253
|
+
case a.Dogecoin:
|
|
254
|
+
return "d";
|
|
255
|
+
case a.BitcoinCash:
|
|
256
|
+
return "c";
|
|
257
|
+
default:
|
|
258
|
+
return `${o}.${c}`;
|
|
259
|
+
}
|
|
260
|
+
})(e, r)}:${i || ""}`;
|
|
267
261
|
}
|
|
268
|
-
case
|
|
269
|
-
const { chain: e, ticker: r, symbol:
|
|
270
|
-
return `${n}:${e}${o ? "/" : "."}${
|
|
262
|
+
case $.WITHDRAW: {
|
|
263
|
+
const { chain: e, ticker: r, symbol: i, basisPoints: s, targetAssetString: l, singleSide: o } = t, c = e === "ETH" && r !== "ETH" ? `${r}-${i.slice(-3)}` : i, u = !o && l ? `:${l}` : "";
|
|
264
|
+
return `${n}:${e}${o ? "/" : "."}${c}:${s}${u}`;
|
|
271
265
|
}
|
|
272
|
-
case
|
|
273
|
-
case
|
|
266
|
+
case $.OPEN_LOAN:
|
|
267
|
+
case $.CLOSE_LOAN: {
|
|
274
268
|
const { asset: e, address: r } = t;
|
|
275
269
|
return `${n}:${e}:${r}`;
|
|
276
270
|
}
|
|
277
271
|
default:
|
|
278
272
|
return "";
|
|
279
273
|
}
|
|
280
|
-
}
|
|
274
|
+
};
|
|
275
|
+
function Pt(n) {
|
|
276
|
+
if (n < 0)
|
|
277
|
+
throw new Error("Invalid number of year");
|
|
278
|
+
return 10 + n;
|
|
279
|
+
}
|
|
280
|
+
function Dt(n) {
|
|
281
|
+
if (n < 0)
|
|
282
|
+
throw new Error("Invalid number of year");
|
|
283
|
+
return Math.round((10 + n * 1.0512) * 1e10) / 1e10;
|
|
284
|
+
}
|
|
285
|
+
function Lt(n) {
|
|
286
|
+
if (n.length > 30)
|
|
287
|
+
return !1;
|
|
288
|
+
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
289
|
+
return !!n.match(t);
|
|
290
|
+
}
|
|
291
|
+
function Ut(n) {
|
|
292
|
+
if (n.length > 30)
|
|
293
|
+
return !1;
|
|
294
|
+
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
295
|
+
return !!n.match(t);
|
|
296
|
+
}
|
|
297
|
+
function Ft([n, t, e, r, i]) {
|
|
298
|
+
return `${n}'/${t}'/${e}'/${r}${typeof i != "number" ? "" : `/${i}`}`;
|
|
299
|
+
}
|
|
300
|
+
const K = [...Object.values(a), "TERRA"];
|
|
301
|
+
function Ct(n = "") {
|
|
281
302
|
const t = n.toUpperCase(), [e] = t.split(".");
|
|
282
|
-
if (
|
|
303
|
+
if (K.includes(e))
|
|
283
304
|
return !0;
|
|
284
305
|
const [r] = t.split("/");
|
|
285
|
-
if (
|
|
306
|
+
if (K.includes(r))
|
|
286
307
|
return !0;
|
|
287
308
|
throw new Error(
|
|
288
309
|
`Invalid identifier: ${n}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
289
310
|
);
|
|
290
|
-
}
|
|
291
|
-
|
|
311
|
+
}
|
|
312
|
+
const T = 8, b = (n) => 10n ** BigInt(n), B = (n) => Math.log10(Number.parseFloat(n.toString()));
|
|
313
|
+
function x({
|
|
292
314
|
value: n,
|
|
293
315
|
bigIntDecimal: t = T,
|
|
294
316
|
decimal: e = T
|
|
295
317
|
}) {
|
|
318
|
+
if (e === 0)
|
|
319
|
+
return n.toString();
|
|
296
320
|
const r = n < 0n;
|
|
297
|
-
let
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
const
|
|
301
|
-
let o =
|
|
302
|
-
return parseInt(o[t]) >= 5 ? o = `${o.substring(0, t - 1)}${(parseInt(o[t - 1]) + 1).toString()}` : o = o.substring(0, t), `${r ? "-" : ""}${
|
|
321
|
+
let i = n.toString().substring(r ? 1 : 0);
|
|
322
|
+
const s = e - (i.length - 1);
|
|
323
|
+
s > 0 && (i = "0".repeat(s) + i);
|
|
324
|
+
const l = i.length - e;
|
|
325
|
+
let o = i.slice(-e);
|
|
326
|
+
return Number.parseInt(o[t]) >= 5 ? o = `${o.substring(0, t - 1)}${(Number.parseInt(o[t - 1]) + 1).toString()}` : o = o.substring(0, t), `${r ? "-" : ""}${i.slice(0, l)}.${o}`.replace(
|
|
303
327
|
/\.?0*$/,
|
|
304
328
|
""
|
|
305
329
|
);
|
|
306
330
|
}
|
|
307
|
-
var w,
|
|
308
|
-
const
|
|
331
|
+
var w, M, A, C, k, Q, N, U, E, F;
|
|
332
|
+
const H = class H {
|
|
309
333
|
constructor(t) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
this.decimal = typeof t == "object" ? t.decimal : void 0, this.decimalMultiplier = S(
|
|
321
|
-
Math.max(g(this, O, L).call(this, g(this, b, V).call(this, e)), this.decimal || 0)
|
|
322
|
-
), g(this, M, z).call(this, e);
|
|
334
|
+
v(this, w);
|
|
335
|
+
v(this, A);
|
|
336
|
+
v(this, k);
|
|
337
|
+
v(this, N);
|
|
338
|
+
v(this, E);
|
|
339
|
+
f(this, "decimalMultiplier", 10n ** 8n);
|
|
340
|
+
f(this, "bigIntValue", 0n);
|
|
341
|
+
f(this, "decimal");
|
|
342
|
+
const e = q(t), r = typeof t == "object";
|
|
343
|
+
this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier : b(Math.max(Y(R(e)), this.decimal || 0)), h(this, k, Q).call(this, e);
|
|
323
344
|
}
|
|
324
345
|
static fromBigInt(t, e) {
|
|
325
|
-
return new
|
|
346
|
+
return new H({
|
|
326
347
|
decimal: e,
|
|
327
|
-
value:
|
|
348
|
+
value: x({ value: t, bigIntDecimal: e, decimal: e })
|
|
328
349
|
});
|
|
329
350
|
}
|
|
330
351
|
static shiftDecimals({
|
|
@@ -332,265 +353,333 @@ const B = class B {
|
|
|
332
353
|
from: e,
|
|
333
354
|
to: r
|
|
334
355
|
}) {
|
|
335
|
-
return
|
|
336
|
-
|
|
356
|
+
return H.fromBigInt(
|
|
357
|
+
t.getBaseValue("bigint") * b(r) / b(e),
|
|
337
358
|
r
|
|
338
359
|
);
|
|
339
360
|
}
|
|
340
|
-
/**
|
|
341
|
-
* @deprecated Use `getBaseValue('string')` instead
|
|
342
|
-
*/
|
|
343
|
-
get baseValue() {
|
|
344
|
-
return this.getBaseValue("string");
|
|
345
|
-
}
|
|
346
|
-
/**
|
|
347
|
-
* @deprecated Use `getBaseValue('number')` instead
|
|
348
|
-
*/
|
|
349
|
-
get baseValueNumber() {
|
|
350
|
-
return this.getBaseValue("number");
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* @deprecated Use `getBaseValue('bigint')` instead
|
|
354
|
-
*/
|
|
355
|
-
get baseValueBigInt() {
|
|
356
|
-
return this.getBaseValue("bigint");
|
|
357
|
-
}
|
|
358
361
|
set(t) {
|
|
359
362
|
return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
|
|
360
363
|
}
|
|
361
364
|
add(...t) {
|
|
362
|
-
return
|
|
365
|
+
return h(this, w, M).call(this, "add", ...t);
|
|
363
366
|
}
|
|
364
367
|
sub(...t) {
|
|
365
|
-
return
|
|
368
|
+
return h(this, w, M).call(this, "sub", ...t);
|
|
366
369
|
}
|
|
367
370
|
mul(...t) {
|
|
368
|
-
return
|
|
371
|
+
return h(this, w, M).call(this, "mul", ...t);
|
|
369
372
|
}
|
|
370
373
|
div(...t) {
|
|
371
|
-
return
|
|
374
|
+
return h(this, w, M).call(this, "div", ...t);
|
|
372
375
|
}
|
|
373
376
|
gt(t) {
|
|
374
|
-
return this
|
|
377
|
+
return h(this, A, C).call(this, "gt", t);
|
|
375
378
|
}
|
|
376
379
|
gte(t) {
|
|
377
|
-
return this
|
|
380
|
+
return h(this, A, C).call(this, "gte", t);
|
|
378
381
|
}
|
|
379
382
|
lt(t) {
|
|
380
|
-
return this
|
|
383
|
+
return h(this, A, C).call(this, "lt", t);
|
|
381
384
|
}
|
|
382
385
|
lte(t) {
|
|
383
|
-
return this
|
|
386
|
+
return h(this, A, C).call(this, "lte", t);
|
|
384
387
|
}
|
|
385
388
|
eqValue(t) {
|
|
386
|
-
return this
|
|
389
|
+
return h(this, A, C).call(this, "eqValue", t);
|
|
387
390
|
}
|
|
391
|
+
// @ts-expect-error False positive
|
|
388
392
|
getValue(t) {
|
|
389
393
|
const e = this.formatBigIntToSafeValue(
|
|
390
394
|
this.bigIntValue,
|
|
391
|
-
this.decimal ||
|
|
395
|
+
this.decimal || B(this.decimalMultiplier)
|
|
392
396
|
);
|
|
393
397
|
switch (t) {
|
|
394
398
|
case "number":
|
|
395
399
|
return Number(e);
|
|
396
400
|
case "string":
|
|
397
401
|
return e;
|
|
398
|
-
|
|
399
|
-
return this.bigIntValue * BigInt(this.decimal || 8n) / this.decimalMultiplier;
|
|
402
|
+
case "bigint":
|
|
403
|
+
return this.bigIntValue * 10n ** BigInt(this.decimal || 8n) / this.decimalMultiplier;
|
|
400
404
|
}
|
|
401
405
|
}
|
|
406
|
+
// @ts-expect-error
|
|
402
407
|
getBaseValue(t) {
|
|
403
|
-
const e = this.decimalMultiplier /
|
|
408
|
+
const e = this.decimalMultiplier / b(this.decimal || m.THOR), r = this.bigIntValue / e;
|
|
404
409
|
switch (t) {
|
|
405
410
|
case "number":
|
|
406
411
|
return Number(r);
|
|
407
412
|
case "string":
|
|
408
413
|
return r.toString();
|
|
409
|
-
|
|
414
|
+
case "bigint":
|
|
410
415
|
return r;
|
|
411
416
|
}
|
|
412
417
|
}
|
|
413
418
|
getBigIntValue(t, e) {
|
|
414
419
|
if (!e && typeof t == "object")
|
|
415
420
|
return t.bigIntValue;
|
|
416
|
-
const r =
|
|
417
|
-
return
|
|
418
|
-
}
|
|
419
|
-
formatBigIntToSafeValue(t, e) {
|
|
420
|
-
const r = e || this.decimal || T, s = Math.max(
|
|
421
|
-
r,
|
|
422
|
-
v(this.decimalMultiplier)
|
|
423
|
-
), 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;
|
|
424
|
-
let d = u.slice(-s);
|
|
425
|
-
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(
|
|
426
|
-
0,
|
|
427
|
-
l
|
|
428
|
-
)}.${d}`.replace(/\.?0*$/, "");
|
|
421
|
+
const r = q(t), i = R(r);
|
|
422
|
+
return i === "0" || i === "undefined" ? 0n : h(this, E, F).call(this, i, e);
|
|
429
423
|
}
|
|
430
424
|
toSignificant(t = 6) {
|
|
431
|
-
const [e, r] = this.getValue("string").split("."),
|
|
432
|
-
if (
|
|
425
|
+
const [e, r] = this.getValue("string").split("."), i = e || "", s = r || "";
|
|
426
|
+
if ((Number.parseInt(i) ? i.length + s.length : s.length) <= t)
|
|
433
427
|
return this.getValue("string");
|
|
434
|
-
if (
|
|
435
|
-
return
|
|
436
|
-
if (parseInt(
|
|
437
|
-
return `${
|
|
438
|
-
|
|
428
|
+
if (i.length >= t)
|
|
429
|
+
return i.slice(0, t).padEnd(i.length, "0");
|
|
430
|
+
if (Number.parseInt(i))
|
|
431
|
+
return `${i}.${s.slice(0, t - i.length)}`.padEnd(
|
|
432
|
+
t - i.length,
|
|
439
433
|
"0"
|
|
440
434
|
);
|
|
441
|
-
const o = parseInt(
|
|
442
|
-
return `0.${
|
|
443
|
-
|
|
435
|
+
const o = Number.parseInt(s), c = `${o}`.slice(0, t);
|
|
436
|
+
return `0.${c.padStart(
|
|
437
|
+
s.length - `${o}`.length + c.length,
|
|
438
|
+
"0"
|
|
439
|
+
)}`;
|
|
440
|
+
}
|
|
441
|
+
toFixed(t = 6) {
|
|
442
|
+
const [e, r] = this.getValue("string").split("."), i = e || "", s = r || "";
|
|
443
|
+
if (Number.parseInt(i))
|
|
444
|
+
return `${i}.${s.slice(0, t)}`.padEnd(t, "0");
|
|
445
|
+
const l = Number.parseInt(s), o = `${l}`.slice(0, t);
|
|
446
|
+
return `0.${o.padStart(
|
|
447
|
+
s.length - `${l}`.length + o.length,
|
|
444
448
|
"0"
|
|
445
449
|
)}`;
|
|
446
450
|
}
|
|
451
|
+
toAbbreviation(t = 2) {
|
|
452
|
+
const e = this.getValue("number"), r = ["", "K", "M", "B", "T", "Q", "Qi", "S"], i = Math.floor(Math.log10(Math.abs(e)) / 3), s = r[i];
|
|
453
|
+
if (!s)
|
|
454
|
+
return this.getValue("string");
|
|
455
|
+
const l = 10 ** (i * 3);
|
|
456
|
+
return `${(e / l).toFixed(t)}${s}`;
|
|
457
|
+
}
|
|
458
|
+
toCurrency(t = "$", {
|
|
459
|
+
currencyPosition: e = "start",
|
|
460
|
+
decimal: r = 2,
|
|
461
|
+
decimalSeparator: i = ".",
|
|
462
|
+
thousandSeparator: s = ","
|
|
463
|
+
} = {}) {
|
|
464
|
+
const l = this.getValue("number"), [o, c = ""] = l.toFixed(6).split("."), u = o.replace(/\B(?=(\d{3})+(?!\d))/g, s), d = o || c ? o === "0" ? `${Number.parseFloat(`0.${c}`)}`.replace(".", i) : `${u}${Number.parseInt(c) ? `${i}${c.slice(0, r)}` : ""}` : "0.00";
|
|
465
|
+
return `${e === "start" ? t : ""}${d}${e === "end" ? t : ""}`;
|
|
466
|
+
}
|
|
467
|
+
formatBigIntToSafeValue(t, e) {
|
|
468
|
+
const r = e || this.decimal || T, i = Math.max(
|
|
469
|
+
r,
|
|
470
|
+
B(this.decimalMultiplier)
|
|
471
|
+
), s = t < 0n, l = t.toString().substring(s ? 1 : 0), o = i - (l.length - 1), c = o > 0 ? "0".repeat(o) + l : l, u = c.length - i;
|
|
472
|
+
let d = c.slice(-i);
|
|
473
|
+
return Number.parseInt(d[r]) >= 5 ? d = `${d.substring(0, r - 1)}${(Number.parseInt(d[r - 1]) + 1).toString()}` : d = d.substring(0, r), `${s ? "-" : ""}${c.slice(
|
|
474
|
+
0,
|
|
475
|
+
u
|
|
476
|
+
)}.${d}`.replace(/\.?0*$/, "");
|
|
477
|
+
}
|
|
447
478
|
};
|
|
448
|
-
w = new WeakSet(),
|
|
449
|
-
const r =
|
|
450
|
-
(
|
|
451
|
-
const
|
|
479
|
+
w = new WeakSet(), M = function(t, ...e) {
|
|
480
|
+
const r = h(this, N, U).call(this, this, ...e), i = Math.max(r, B(this.decimalMultiplier)), s = b(i), l = e.reduce(
|
|
481
|
+
(c, u) => {
|
|
482
|
+
const d = this.getBigIntValue(u, i);
|
|
452
483
|
switch (t) {
|
|
453
484
|
case "add":
|
|
454
|
-
return
|
|
485
|
+
return c + d;
|
|
455
486
|
case "sub":
|
|
456
|
-
return
|
|
487
|
+
return c - d;
|
|
457
488
|
case "mul":
|
|
458
|
-
return
|
|
489
|
+
return c * d / s;
|
|
459
490
|
case "div": {
|
|
460
|
-
if (
|
|
491
|
+
if (d === 0n)
|
|
461
492
|
throw new RangeError("Division by zero");
|
|
462
|
-
return
|
|
493
|
+
return c * s / d;
|
|
463
494
|
}
|
|
464
495
|
default:
|
|
465
|
-
return
|
|
496
|
+
return c;
|
|
466
497
|
}
|
|
467
498
|
},
|
|
468
499
|
//normalize is to precision multiplier base
|
|
469
500
|
this.bigIntValue * s / this.decimalMultiplier
|
|
470
|
-
),
|
|
471
|
-
bigIntDecimal:
|
|
472
|
-
decimal:
|
|
473
|
-
value:
|
|
501
|
+
), o = x({
|
|
502
|
+
bigIntDecimal: i,
|
|
503
|
+
decimal: i,
|
|
504
|
+
value: l
|
|
505
|
+
});
|
|
506
|
+
return new this.constructor({
|
|
507
|
+
decimalMultiplier: b(i),
|
|
508
|
+
decimal: this.decimal,
|
|
509
|
+
value: o,
|
|
510
|
+
identifier: this.toString()
|
|
474
511
|
});
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
512
|
+
}, A = new WeakSet(), C = function(t, ...e) {
|
|
513
|
+
const r = h(this, N, U).call(this, this, ...e), i = this.getBigIntValue(e[0], r), s = this.getBigIntValue(this, r);
|
|
514
|
+
switch (t) {
|
|
515
|
+
case "gt":
|
|
516
|
+
return s > i;
|
|
517
|
+
case "gte":
|
|
518
|
+
return s >= i;
|
|
519
|
+
case "lt":
|
|
520
|
+
return s < i;
|
|
521
|
+
case "lte":
|
|
522
|
+
return s <= i;
|
|
523
|
+
case "eqValue":
|
|
524
|
+
return s === i;
|
|
525
|
+
}
|
|
526
|
+
}, k = new WeakSet(), Q = function(t) {
|
|
527
|
+
const e = R(t) || "0";
|
|
528
|
+
this.bigIntValue = h(this, E, F).call(this, e);
|
|
529
|
+
}, N = new WeakSet(), U = function(...t) {
|
|
530
|
+
const e = t.map((r) => typeof r == "object" ? r.decimal || B(r.decimalMultiplier) : Y(R(r))).filter(Boolean);
|
|
483
531
|
return Math.max(...e, T);
|
|
484
|
-
}, E = new WeakSet(),
|
|
485
|
-
const r = e ?
|
|
486
|
-
return BigInt(`${
|
|
487
|
-
}, b = new WeakSet(), V = function(t) {
|
|
488
|
-
const r = `${typeof t == "number" ? Number(t).toLocaleString("fullwide", {
|
|
489
|
-
useGrouping: !1,
|
|
490
|
-
maximumFractionDigits: 20
|
|
491
|
-
}) : P(t)}`.replaceAll(",", ".").split(".");
|
|
492
|
-
return r.length > 1 ? `${r.slice(0, -1).join("")}.${r.at(-1)}` : r[0];
|
|
493
|
-
}, O = new WeakSet(), L = function(t) {
|
|
494
|
-
var r;
|
|
495
|
-
const e = ((r = t.split(".")[1]) == null ? void 0 : r.length) || 0;
|
|
496
|
-
return Math.max(e, T);
|
|
532
|
+
}, E = new WeakSet(), F = function(t, e) {
|
|
533
|
+
const r = e ? b(e) : this.decimalMultiplier, i = B(r), [s = "", l = ""] = t.split(".");
|
|
534
|
+
return BigInt(`${s}${l.padEnd(i, "0")}`);
|
|
497
535
|
};
|
|
498
|
-
let
|
|
499
|
-
|
|
536
|
+
let V = H;
|
|
537
|
+
const It = Intl.NumberFormat("fullwide", {
|
|
538
|
+
useGrouping: !1,
|
|
539
|
+
maximumFractionDigits: 20
|
|
540
|
+
});
|
|
541
|
+
function R(n) {
|
|
542
|
+
const e = `${typeof n == "number" ? It.format(n) : q(n)}`.replaceAll(",", ".").split(".");
|
|
543
|
+
return e.length > 1 ? `${e.slice(0, -1).join("")}.${e.at(-1)}` : e[0];
|
|
544
|
+
}
|
|
545
|
+
function Y(n) {
|
|
546
|
+
var e;
|
|
547
|
+
const t = ((e = n.split(".")[1]) == null ? void 0 : e.length) || 0;
|
|
548
|
+
return Math.max(t, T);
|
|
549
|
+
}
|
|
550
|
+
function q(n) {
|
|
500
551
|
return typeof n == "object" ? "getValue" in n ? n.getValue("string") : n.value : n;
|
|
501
552
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
this
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
553
|
+
class g extends V {
|
|
554
|
+
eq(t) {
|
|
555
|
+
return this.eqValue(t);
|
|
556
|
+
}
|
|
557
|
+
static fromBigInt(t, e) {
|
|
558
|
+
return new g({
|
|
559
|
+
decimal: e,
|
|
560
|
+
value: x({ value: t, bigIntDecimal: e, decimal: e })
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
const I = /* @__PURE__ */ new Map();
|
|
565
|
+
class p extends V {
|
|
566
|
+
constructor({
|
|
567
|
+
value: e,
|
|
568
|
+
decimal: r,
|
|
569
|
+
tax: i,
|
|
570
|
+
chain: s,
|
|
571
|
+
symbol: l,
|
|
572
|
+
identifier: o
|
|
573
|
+
}) {
|
|
574
|
+
super(typeof e == "object" ? e : { decimal: r, value: e });
|
|
575
|
+
f(this, "address");
|
|
576
|
+
f(this, "chain");
|
|
577
|
+
f(this, "isGasAsset", !1);
|
|
578
|
+
f(this, "isSynthetic", !1);
|
|
579
|
+
f(this, "symbol");
|
|
580
|
+
f(this, "tax");
|
|
581
|
+
f(this, "ticker");
|
|
582
|
+
f(this, "type");
|
|
583
|
+
const c = O(o || `${s}.${l}`);
|
|
584
|
+
this.type = pt(c), this.tax = i, this.chain = c.chain, this.ticker = c.ticker, this.symbol = c.symbol, this.address = c.address, this.isSynthetic = c.isSynthetic, this.isGasAsset = c.isGasAsset;
|
|
585
|
+
}
|
|
586
|
+
toString() {
|
|
587
|
+
return this.isSynthetic ? this.symbol : `${this.chain}.${this.symbol}`;
|
|
588
|
+
}
|
|
589
|
+
toUrl() {
|
|
590
|
+
return this.isSynthetic ? `${this.chain}.${this.symbol.replace("/", ".")}` : this.toString();
|
|
536
591
|
}
|
|
537
592
|
eq({ chain: e, symbol: r }) {
|
|
538
593
|
return this.chain === e && this.symbol === r;
|
|
539
594
|
}
|
|
540
|
-
|
|
541
|
-
return
|
|
595
|
+
chainId() {
|
|
596
|
+
return ut[this.chain];
|
|
597
|
+
}
|
|
598
|
+
// THOR.RUNE
|
|
599
|
+
// THOR.ETH.ETH
|
|
600
|
+
// ETH.THOR-0x1234567890
|
|
601
|
+
static fromUrl(e, r = 0) {
|
|
602
|
+
const [i, s, l] = e.split(".");
|
|
603
|
+
if (!(i && s))
|
|
604
|
+
throw new Error("Invalid asset url");
|
|
605
|
+
const o = i === a.THORChain && l ? `${i}.${s}/${l}` : e;
|
|
606
|
+
return D(o, r);
|
|
607
|
+
}
|
|
608
|
+
static fromString(e, r = 0) {
|
|
609
|
+
return D(e, r);
|
|
610
|
+
}
|
|
611
|
+
static fromIdentifier(e, r = 0) {
|
|
612
|
+
return D(e, r);
|
|
542
613
|
}
|
|
543
614
|
static fromStringSync(e, r = 0) {
|
|
544
|
-
const {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
615
|
+
const { chain: i, isSynthetic: s } = O(e), l = I.get(e.toUpperCase());
|
|
616
|
+
if (s)
|
|
617
|
+
return L(e, r);
|
|
618
|
+
const { tax: o, decimal: c, identifier: u } = l || {
|
|
619
|
+
decimal: m[i],
|
|
620
|
+
identifier: e
|
|
621
|
+
};
|
|
622
|
+
return new p({
|
|
623
|
+
tax: o,
|
|
624
|
+
value: S(r, c),
|
|
625
|
+
identifier: s ? e : u,
|
|
626
|
+
decimal: s ? 8 : c
|
|
627
|
+
});
|
|
548
628
|
}
|
|
549
|
-
static async
|
|
550
|
-
|
|
629
|
+
static async fromStringWithBase(e, r = 0, i = m.THOR) {
|
|
630
|
+
const s = V.shiftDecimals({
|
|
631
|
+
value: g.fromBigInt(BigInt(r)),
|
|
632
|
+
from: 0,
|
|
633
|
+
to: i
|
|
634
|
+
}).getBaseValue("string");
|
|
635
|
+
return (await p.fromString(e, r)).set(s);
|
|
636
|
+
}
|
|
637
|
+
static fromStringWithBaseSync(e, r = 0, i = m.THOR) {
|
|
638
|
+
const { chain: s, isSynthetic: l } = O(e), o = I.get(e.toUpperCase());
|
|
639
|
+
if (l)
|
|
640
|
+
return L(e, r);
|
|
641
|
+
const { tax: c, decimal: u, identifier: d } = o || {
|
|
642
|
+
decimal: m[s],
|
|
643
|
+
identifier: e
|
|
644
|
+
};
|
|
645
|
+
return new p({
|
|
646
|
+
tax: c,
|
|
647
|
+
value: S(BigInt(r), i),
|
|
648
|
+
identifier: d,
|
|
649
|
+
decimal: u
|
|
650
|
+
});
|
|
551
651
|
}
|
|
552
652
|
static fromIdentifierSync(e, r = 0) {
|
|
553
|
-
const {
|
|
554
|
-
|
|
653
|
+
const { chain: i, isSynthetic: s } = O(e), l = I.get(e);
|
|
654
|
+
if (s)
|
|
655
|
+
return L(e, r);
|
|
656
|
+
const { tax: o, decimal: c, identifier: u } = l || {
|
|
657
|
+
decimal: m[i],
|
|
658
|
+
identifier: e
|
|
659
|
+
};
|
|
660
|
+
return new p({ tax: o, decimal: c, identifier: u, value: S(r, c) });
|
|
555
661
|
}
|
|
556
662
|
static fromChainOrSignature(e, r = 0) {
|
|
557
|
-
const { decimal:
|
|
558
|
-
return new
|
|
559
|
-
}
|
|
560
|
-
static async fromTCQuote(e, r = 0) {
|
|
561
|
-
const s = await K(q(e)), a = this.shiftDecimals({ value: r, from: m.THOR, to: s });
|
|
562
|
-
return new f({ value: a, identifier: e, decimal: s });
|
|
563
|
-
}
|
|
564
|
-
static fromTCQuoteStatic(e, r = 0) {
|
|
565
|
-
const s = x(e), a = this.shiftDecimals({
|
|
566
|
-
value: r,
|
|
567
|
-
from: m.THOR,
|
|
568
|
-
to: s.decimal
|
|
569
|
-
});
|
|
570
|
-
return new f({ ...s, value: a });
|
|
663
|
+
const { decimal: i, identifier: s } = gt(e);
|
|
664
|
+
return new p({ value: S(r, i), decimal: i, identifier: s });
|
|
571
665
|
}
|
|
572
|
-
static
|
|
666
|
+
static loadStaticAssets() {
|
|
573
667
|
return new Promise(
|
|
574
|
-
|
|
668
|
+
(e, r) => {
|
|
575
669
|
try {
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
}), u),
|
|
588
|
-
/* @__PURE__ */ new Map()
|
|
589
|
-
), e({ ok: !0 });
|
|
590
|
-
} catch (s) {
|
|
591
|
-
console.error(s), r({
|
|
670
|
+
import("@swapkit/tokens").then((i) => {
|
|
671
|
+
for (const s of Object.values(i))
|
|
672
|
+
for (const { identifier: l, chain: o, ...c } of s.tokens)
|
|
673
|
+
I.set(l.toUpperCase(), {
|
|
674
|
+
identifier: l,
|
|
675
|
+
decimal: "decimals" in c ? c.decimals : m[o]
|
|
676
|
+
});
|
|
677
|
+
e({ ok: !0 });
|
|
678
|
+
});
|
|
679
|
+
} catch (i) {
|
|
680
|
+
console.error(i), r({
|
|
592
681
|
ok: !1,
|
|
593
|
-
error:
|
|
682
|
+
error: i,
|
|
594
683
|
message: "Couldn't load static assets. Ensure you have installed @swapkit/tokens package"
|
|
595
684
|
});
|
|
596
685
|
}
|
|
@@ -598,35 +687,60 @@ class f extends y {
|
|
|
598
687
|
);
|
|
599
688
|
}
|
|
600
689
|
}
|
|
601
|
-
|
|
602
|
-
const t =
|
|
690
|
+
function qt(n) {
|
|
691
|
+
const t = p.fromChainOrSignature(n);
|
|
603
692
|
switch (n) {
|
|
604
|
-
case
|
|
605
|
-
case
|
|
606
|
-
case
|
|
607
|
-
return t.
|
|
608
|
-
case
|
|
609
|
-
return t.
|
|
610
|
-
case
|
|
611
|
-
case
|
|
612
|
-
return t.
|
|
613
|
-
case
|
|
614
|
-
case
|
|
615
|
-
return t.
|
|
693
|
+
case a.Bitcoin:
|
|
694
|
+
case a.Litecoin:
|
|
695
|
+
case a.BitcoinCash:
|
|
696
|
+
return t.set(10001e-8);
|
|
697
|
+
case a.Dogecoin:
|
|
698
|
+
return t.set(1.00000001);
|
|
699
|
+
case a.Avalanche:
|
|
700
|
+
case a.Ethereum:
|
|
701
|
+
return t.set(1e-8);
|
|
702
|
+
case a.THORChain:
|
|
703
|
+
case a.Maya:
|
|
704
|
+
return t.set(0);
|
|
705
|
+
case a.Cosmos:
|
|
706
|
+
return t.set(1e-6);
|
|
616
707
|
default:
|
|
617
|
-
return t.
|
|
708
|
+
return t.set(1e-8);
|
|
618
709
|
}
|
|
619
|
-
}
|
|
620
|
-
|
|
710
|
+
}
|
|
711
|
+
async function D(n, t = 0) {
|
|
712
|
+
Ct(n);
|
|
713
|
+
const e = I.get(n.toUpperCase()), r = (e == null ? void 0 : e.decimal) || await ft(O(n));
|
|
714
|
+
return e || I.set(n.toUpperCase(), { identifier: n, decimal: r }), new p({ decimal: r, value: S(t, r), identifier: n });
|
|
715
|
+
}
|
|
716
|
+
function L(n, t = 0) {
|
|
717
|
+
const [e, r] = n.split(".")[0].toUpperCase() === a.THORChain ? n.split(".").slice(1).join().split("/") : n.split("/");
|
|
718
|
+
if (!(e && r))
|
|
719
|
+
throw new Error("Invalid asset identifier");
|
|
720
|
+
return new p({
|
|
721
|
+
decimal: 8,
|
|
722
|
+
value: S(t, 8),
|
|
723
|
+
identifier: `${a.THORChain}.${e}/${r}`
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
function S(n, t) {
|
|
727
|
+
return typeof n == "bigint" ? x({ value: n, bigIntDecimal: t, decimal: t }) : n;
|
|
728
|
+
}
|
|
729
|
+
function O(n) {
|
|
730
|
+
const t = n.slice(0, 14).includes("/"), [e, r] = n.split(".")[0].toUpperCase() === a.THORChain ? n.split(".").slice(1).join().split("/") : n.split("/");
|
|
731
|
+
if (t && !(e && r))
|
|
732
|
+
throw new Error("Invalid asset identifier");
|
|
733
|
+
const i = n.includes(".") && !t ? n : `${a.THORChain}.${r}`, [s, ...l] = i.split("."), [o, c] = (t ? r : l.join(".")).split("-"), u = t ? r : l.join(".");
|
|
621
734
|
return {
|
|
622
735
|
address: c == null ? void 0 : c.toLowerCase(),
|
|
623
|
-
chain:
|
|
624
|
-
isGasAsset:
|
|
736
|
+
chain: s,
|
|
737
|
+
isGasAsset: J({ chain: s, symbol: u }),
|
|
625
738
|
isSynthetic: t,
|
|
626
|
-
symbol: c ? `${
|
|
627
|
-
ticker:
|
|
739
|
+
symbol: (t ? `${e}/` : "") + (c ? `${o}-${(c == null ? void 0 : c.toLowerCase()) ?? ""}` : u),
|
|
740
|
+
ticker: o
|
|
628
741
|
};
|
|
629
|
-
}
|
|
742
|
+
}
|
|
743
|
+
const St = {
|
|
630
744
|
/**
|
|
631
745
|
* Core
|
|
632
746
|
*/
|
|
@@ -635,6 +749,7 @@ const Pt = (n) => {
|
|
|
635
749
|
core_extend_error: 10003,
|
|
636
750
|
core_inbound_data_not_found: 10004,
|
|
637
751
|
core_approve_asset_address_or_from_not_found: 10005,
|
|
752
|
+
core_plugin_not_found: 10006,
|
|
638
753
|
core_chain_halted: 10099,
|
|
639
754
|
/**
|
|
640
755
|
* Core - Wallet Connection
|
|
@@ -647,6 +762,7 @@ const Pt = (n) => {
|
|
|
647
762
|
core_wallet_trezor_not_installed: 10106,
|
|
648
763
|
core_wallet_keplr_not_installed: 10107,
|
|
649
764
|
core_wallet_okx_not_installed: 10108,
|
|
765
|
+
core_wallet_keepkey_not_installed: 10109,
|
|
650
766
|
/**
|
|
651
767
|
* Core - Swap
|
|
652
768
|
*/
|
|
@@ -673,52 +789,68 @@ const Pt = (n) => {
|
|
|
673
789
|
core_transaction_deposit_to_pool_error: 10310,
|
|
674
790
|
core_transaction_deposit_insufficient_funds_error: 10311,
|
|
675
791
|
core_transaction_deposit_gas_error: 10312,
|
|
676
|
-
|
|
792
|
+
core_transaction_invalid_sender_address: 10313,
|
|
793
|
+
core_transaction_deposit_server_error: 10314,
|
|
794
|
+
core_transaction_user_rejected: 10315,
|
|
677
795
|
/**
|
|
678
796
|
* Wallets
|
|
679
797
|
*/
|
|
680
798
|
wallet_ledger_connection_error: 20001,
|
|
799
|
+
wallet_ledger_connection_claimed: 20002,
|
|
800
|
+
wallet_ledger_get_address_error: 20003,
|
|
801
|
+
wallet_ledger_device_not_found: 20004,
|
|
802
|
+
wallet_ledger_device_locked: 20005,
|
|
803
|
+
/**
|
|
804
|
+
* Chainflip
|
|
805
|
+
*/
|
|
806
|
+
chainflip_channel_error: 30001,
|
|
807
|
+
chainflip_broker_recipient_error: 30002,
|
|
808
|
+
/**
|
|
809
|
+
* THORChain
|
|
810
|
+
*/
|
|
681
811
|
/**
|
|
682
812
|
* Helpers
|
|
683
813
|
*/
|
|
684
814
|
helpers_number_different_decimals: 99101
|
|
685
815
|
};
|
|
686
|
-
class
|
|
816
|
+
class X extends Error {
|
|
687
817
|
constructor(t, e) {
|
|
688
|
-
console.error(e
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
818
|
+
e && console.error(e, {
|
|
819
|
+
stack: e == null ? void 0 : e.stack,
|
|
820
|
+
message: e == null ? void 0 : e.message
|
|
821
|
+
}), super(t, {
|
|
822
|
+
cause: { code: St[t], message: t }
|
|
823
|
+
}), Object.setPrototypeOf(this, X.prototype);
|
|
694
824
|
}
|
|
695
825
|
}
|
|
696
826
|
export {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
pt as
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
kt as
|
|
715
|
-
Ht as
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
827
|
+
p as AssetValue,
|
|
828
|
+
V as BigIntArithmetics,
|
|
829
|
+
X as SwapKitError,
|
|
830
|
+
g as SwapKitNumber,
|
|
831
|
+
Tt as assetFromString,
|
|
832
|
+
Ft as derivationPathToString,
|
|
833
|
+
Vt as filterAssets,
|
|
834
|
+
Nt as findAssetBy,
|
|
835
|
+
x as formatBigIntToSafeValue,
|
|
836
|
+
Ot as gasFeeMultiplier,
|
|
837
|
+
pt as getAssetType,
|
|
838
|
+
wt as getAsymmetricAssetShare,
|
|
839
|
+
Rt as getAsymmetricAssetWithdrawAmount,
|
|
840
|
+
bt as getAsymmetricRuneShare,
|
|
841
|
+
Et as getAsymmetricRuneWithdrawAmount,
|
|
842
|
+
gt as getCommonAssetInfo,
|
|
843
|
+
ft as getDecimal,
|
|
844
|
+
kt as getEstimatedPoolShare,
|
|
845
|
+
Ht as getLiquiditySlippage,
|
|
846
|
+
Dt as getMAYANameCost,
|
|
847
|
+
jt as getMemoFor,
|
|
848
|
+
qt as getMinAmountByChain,
|
|
849
|
+
vt as getSymmetricPoolShare,
|
|
850
|
+
xt as getSymmetricWithdraw,
|
|
851
|
+
Pt as getTHORNameCost,
|
|
852
|
+
J as isGasAsset,
|
|
853
|
+
Ut as validateMAYAName,
|
|
854
|
+
Lt as validateTHORName
|
|
724
855
|
};
|
|
856
|
+
//# sourceMappingURL=index.es.js.map
|