@swapkit/helpers 1.0.0-rc.8 → 1.0.0-rc.80

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.es.js CHANGED
@@ -1,330 +1,351 @@
1
- var nt = Object.defineProperty;
2
- var rt = (n, t, e) => t in n ? nt(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
- var _ = (n, t, e) => (rt(n, typeof t != "symbol" ? t + "" : t, e), e), st = (n, t, e) => {
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 $ = (n, t, e) => {
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 g = (n, t, e) => (st(n, t, "access private method"), e);
13
- import { FeeOption as H, BaseDecimal as m, Chain as i, ChainToRPC as it, MemoType as p } from "@swapkit/types";
14
- const vt = (n) => {
15
- if (n < 0)
16
- throw new Error("Invalid number of year");
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 = Object.entries(t || {}).reduce(
26
- (s, [a, c]) => (c && (s[a] = c), s),
27
- {}
28
- );
29
- return (await fetch(
30
- `${n}${t ? `?${new URLSearchParams(e).toString()}` : ""}`,
31
- { method: "GET", mode: "cors", credentials: "omit", referrer: "https://sk.thorswap.net" }
32
- )).json();
33
- } catch (e) {
34
- return console.error(e), {};
35
- }
36
- }, at = async (n, t, e, r = !1) => {
37
- try {
38
- const s = await fetch(`${n}`, {
39
- body: t,
40
- headers: e,
41
- method: "POST",
42
- referrer: "https://sk.thorswap.net"
43
- });
44
- return r ? s.text() : s.json();
45
- } catch {
46
- return {};
47
- }
48
- }, ct = "0x313ce567", Y = async ({ chain: n, to: t }) => {
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
- { accept: "*/*", "cache-control": "no-cache", "content-type": "application/json" },
59
- !0
60
- ), { result: r } = JSON.parse(e);
61
- return parseInt(BigInt(r).toString());
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
- }, ot = async (n) => {
66
- if (n === i.Ethereum)
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") ? Y({ chain: i.Ethereum, to: t }) : m.ETH;
70
- }, ut = async (n) => {
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") ? Y({ chain: i.Avalanche, to: t.toLowerCase() }) : m.AVAX;
73
- }, lt = async (n) => n === i.BinanceSmartChain ? m.BSC : m.BSC, K = async ({ chain: n, symbol: t }) => {
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 i.Ethereum:
76
- return ot(t);
77
- case i.Avalanche:
78
- return ut(t);
79
- case i.BinanceSmartChain:
80
- return lt(t);
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
- }, Bt = {
85
- [H.Average]: 1.2,
86
- [H.Fast]: 1.5,
87
- [H.Fastest]: 2
88
- }, dt = ({ chain: n, symbol: t }) => {
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 i.Bitcoin:
91
- case i.BitcoinCash:
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 i.Maya:
63
+ case a.Maya:
102
64
  return t === "CACAO";
103
- case i.Kujira:
65
+ case a.Kujira:
104
66
  return t === "KUJI";
105
- case i.Cosmos:
67
+ case a.Cosmos:
106
68
  return t === "ATOM";
107
- case i.Polygon:
69
+ case a.Polygon:
108
70
  return t === "MATIC";
109
- case i.BinanceSmartChain:
71
+ case a.BinanceSmartChain:
110
72
  return t === "BNB";
111
- case i.THORChain:
73
+ case a.THORChain:
112
74
  return t === "RUNE";
75
+ default:
76
+ return t === n;
113
77
  }
114
- }, ht = (n) => {
78
+ }, gt = (n) => {
115
79
  switch (n) {
116
- case "ETH.THOR":
80
+ case `${a.Ethereum}.THOR`:
117
81
  return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
118
- case "ETH.vTHOR":
82
+ case `${a.Ethereum}.vTHOR`:
119
83
  return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
120
- case i.Cosmos:
84
+ case a.Cosmos:
121
85
  return { identifier: "GAIA.ATOM", decimal: m[n] };
122
- case i.THORChain:
86
+ case a.THORChain:
123
87
  return { identifier: "THOR.RUNE", decimal: m[n] };
124
- case i.BinanceSmartChain:
88
+ case a.BinanceSmartChain:
125
89
  return { identifier: "BSC.BNB", decimal: m[n] };
126
- case i.Maya:
90
+ case a.Maya:
127
91
  return { identifier: "MAYA.CACAO", decimal: m.MAYA };
128
- case "MAYA.MAYA":
92
+ case `${a.Maya}.MAYA`:
129
93
  return { identifier: "MAYA.MAYA", decimal: 4 };
130
- case i.Kujira:
131
- case i.Arbitrum:
132
- case i.Optimism:
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
- }, mt = ({ chain: n, symbol: t }) => {
99
+ }, pt = ({ chain: n, symbol: t }) => {
144
100
  if (t.includes("/"))
145
101
  return "Synth";
146
102
  switch (n) {
147
- case i.Bitcoin:
148
- case i.BitcoinCash:
149
- case i.Dogecoin:
150
- case i.Litecoin:
151
- case i.Maya:
152
- case i.THORChain:
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
- case i.Cosmos:
155
- return t === "ATOM" ? "Native" : i.Cosmos;
156
- case i.Kujira:
157
- return t === i.Kujira ? "Native" : i.Kujira;
158
- case i.Binance:
159
- return t === i.Binance ? "Native" : "BEP2";
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
- ), Et = (n) => n.filter(
181
- (t) => !gt.test(t.toString()) && !t.toString().includes("undefined")
182
- ), _t = ({
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 = h(n), s = h(t), a = h(e), c = r.mul(a), o = s.mul(s).mul(2), u = s.mul(r).mul(2), l = r.mul(r), d = s.mul(s).mul(s);
188
- return c.mul(o.sub(u).add(l)).div(d);
189
- }, pt = ({
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 = h(n), s = h(t), a = h(e), c = r.mul(a), o = s.mul(s).mul(2), u = s.mul(r).mul(2), l = r.mul(r), d = c.mul(o.sub(u).add(l)), A = s.mul(s).mul(s);
195
- return d.div(A);
196
- }, Ot = ({
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
- }) => _t({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(n), Mt = ({
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
- }) => pt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(n), h = (n) => new bt({ value: n, decimal: m.THOR }), ft = ({
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
- assetAmount: h(r).mul(n).div(t),
213
- runeAmount: h(e).mul(n).div(t)
214
- }), Nt = ({
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: s
220
- }) => Object.fromEntries(
221
- Object.entries(ft({ liquidityUnits: n, poolUnits: t, runeDepth: e, assetDepth: r })).map(
222
- ([a, c]) => [a, c.mul(s)]
223
- )
224
- ), Rt = ({
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: s,
230
- assetAmount: a
231
- }) => {
232
- const c = h(n), o = h(e), u = h(t), l = h(s), d = h(a), A = l.mul(o), I = d.mul(c), R = l.mul(d), X = c.mul(o), Z = u.mul(A.add(I.add(R.mul(2)))), tt = A.add(I.add(X.mul(2))), F = Z.div(tt), k = h(r).add(F);
233
- if (F.baseValueNumber === 0)
234
- return k.div(u).baseValueNumber;
235
- const et = u.add(k);
236
- return k.div(et).baseValueNumber;
237
- }, kt = ({
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
- const s = h(e), a = h(r), c = h(t), o = h(n), u = c.mul(s).sub(a.mul(o)), l = a.mul(o).add(s.mul(a));
244
- return Math.abs(u.div(l).baseValueNumber);
245
- }, At = ({
246
- symbol: n,
247
- ticker: t,
248
- chain: e
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 p.LEAVE:
252
- case p.BOND: {
234
+ case $.LEAVE:
235
+ case $.BOND: {
253
236
  const { address: e } = t;
254
237
  return `${n}:${e}`;
255
238
  }
256
- case p.UNBOND: {
239
+ case $.UNBOND: {
257
240
  const { address: e, unbondAmount: r } = t;
258
- return `${n}:${e}:${r * 10 ** 8}`;
241
+ return `${n}:${e}:${r}`;
259
242
  }
260
- case p.THORNAME_REGISTER: {
261
- const { name: e, chain: r, address: s, owner: a } = t;
262
- return `${n}:${e}:${r}:${s}${a ? `:${a}` : ""}`;
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 p.DEPOSIT: {
265
- const { chain: e, symbol: r, address: s, singleSide: a } = t;
266
- return a ? `${n}:${e}/${r}::t:0` : `${n}:${e}.${r}:${s || ""}:t:0`;
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 p.WITHDRAW: {
269
- const { chain: e, ticker: r, symbol: s, basisPoints: a, targetAssetString: c, singleSide: o } = t, u = !o && c ? `:${c}` : "", l = At({ chain: e, symbol: s, ticker: r });
270
- return `${n}:${e}${o ? "/" : "."}${l}:${a}${u}`;
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 p.OPEN_LOAN:
273
- case p.CLOSE_LOAN: {
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
- }, G = Object.values(i), $t = (n = "") => {
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 (G.includes(e))
303
+ if (K.includes(e))
283
304
  return !0;
284
305
  const [r] = t.split("/");
285
- if (G.includes(r))
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
- }, T = 8, S = (n) => 10n ** BigInt(n), v = (n) => Math.log10(parseFloat(n.toString()));
291
- function U({
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 s = n.toString().substring(r ? 1 : 0);
298
- const a = e - (s.length - 1);
299
- a > 0 && (s = "0".repeat(a) + s);
300
- const c = s.length - e;
301
- let o = s.slice(-e);
302
- return parseInt(o[t]) >= 5 ? o = `${o.substring(0, t - 1)}${(parseInt(o[t - 1]) + 1).toString()}` : o = o.substring(0, t), `${r ? "-" : ""}${s.slice(0, c)}.${o}`.replace(
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, C, M, z, N, J, E, D, b, V, O, L;
308
- const B = class B {
331
+ var w, M, A, C, k, Q, N, U, E, F;
332
+ const H = class H {
309
333
  constructor(t) {
310
- $(this, w);
311
- $(this, M);
312
- $(this, N);
313
- $(this, E);
314
- $(this, b);
315
- $(this, O);
316
- _(this, "decimalMultiplier", 10n ** 8n);
317
- _(this, "bigIntValue", 0n);
318
- _(this, "decimal");
319
- const e = P(t);
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 B({
346
+ return new H({
326
347
  decimal: e,
327
- value: U({ value: t, bigIntDecimal: e, decimal: e })
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 B.fromBigInt(
336
- new B(t).bigIntValue * S(r) / S(e),
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 g(this, w, C).call(this, "add", ...t);
365
+ return h(this, w, M).call(this, "add", ...t);
363
366
  }
364
367
  sub(...t) {
365
- return g(this, w, C).call(this, "sub", ...t);
368
+ return h(this, w, M).call(this, "sub", ...t);
366
369
  }
367
370
  mul(...t) {
368
- return g(this, w, C).call(this, "mul", ...t);
371
+ return h(this, w, M).call(this, "mul", ...t);
369
372
  }
370
373
  div(...t) {
371
- return g(this, w, C).call(this, "div", ...t);
374
+ return h(this, w, M).call(this, "div", ...t);
372
375
  }
373
376
  gt(t) {
374
- return this.bigIntValue > this.getBigIntValue(t);
377
+ return h(this, A, C).call(this, "gt", t);
375
378
  }
376
379
  gte(t) {
377
- return this.bigIntValue >= this.getBigIntValue(t);
380
+ return h(this, A, C).call(this, "gte", t);
378
381
  }
379
382
  lt(t) {
380
- return this.bigIntValue < this.getBigIntValue(t);
383
+ return h(this, A, C).call(this, "lt", t);
381
384
  }
382
385
  lte(t) {
383
- return this.bigIntValue <= this.getBigIntValue(t);
386
+ return h(this, A, C).call(this, "lte", t);
384
387
  }
385
388
  eqValue(t) {
386
- return this.bigIntValue === this.getBigIntValue(t);
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 || v(this.decimalMultiplier)
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
- default:
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 / S(this.decimal || m.THOR), r = this.bigIntValue / e;
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
- default:
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 = P(t), s = g(this, b, V).call(this, r);
417
- return s === "0" || s === "undefined" ? 0n : g(this, E, D).call(this, s, e);
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("."), s = e || "", a = r || "", c = parseInt(s) ? s.length + a.length : a.length;
432
- if (c <= t)
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 (s.length >= t)
435
- return s.slice(0, t).padEnd(s.length, "0");
436
- if (parseInt(s))
437
- return `${s}.${a.slice(0, t - s.length)}`.padEnd(
438
- c - t,
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(a), u = `${o}`.slice(0, t);
442
- return `0.${u.padStart(
443
- a.length - `${o}`.length + u.length,
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(), C = function(t, ...e) {
449
- const r = g(this, N, J).call(this, this, ...e), s = S(r), a = e.reduce(
450
- (o, u) => {
451
- const l = this.getBigIntValue(u, r);
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 o + l;
485
+ return c + d;
455
486
  case "sub":
456
- return o - l;
487
+ return c - d;
457
488
  case "mul":
458
- return o * l / s;
489
+ return c * d / s;
459
490
  case "div": {
460
- if (l === 0n)
491
+ if (d === 0n)
461
492
  throw new RangeError("Division by zero");
462
- return o * s / l;
493
+ return c * s / d;
463
494
  }
464
495
  default:
465
- return o;
496
+ return c;
466
497
  }
467
498
  },
468
499
  //normalize is to precision multiplier base
469
500
  this.bigIntValue * s / this.decimalMultiplier
470
- ), c = U({
471
- bigIntDecimal: r,
472
- decimal: Math.max(r, v(this.decimalMultiplier)),
473
- value: a
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
- return new this.constructor({ decimal: this.decimal, value: c, identifier: this.toString() });
476
- }, M = new WeakSet(), z = function(t) {
477
- const e = g(this, b, V).call(this, t) || "0";
478
- this.bigIntValue = g(this, E, D).call(this, e);
479
- }, N = new WeakSet(), J = function(...t) {
480
- const e = t.map(
481
- (r) => typeof r == "object" ? r.decimal || v(r.decimalMultiplier) : g(this, O, L).call(this, g(this, b, V).call(this, r))
482
- ).filter(Boolean);
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(), D = function(t, e) {
485
- const r = e ? S(e) : this.decimalMultiplier, s = v(r), [a = "", c = ""] = t.split(".");
486
- return BigInt(`${a}${c.padEnd(s, "0")}`);
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 y = B;
499
- function P(n) {
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
- let j;
503
- const x = (n) => {
504
- if (!j)
505
- throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");
506
- return j.get(n.toUpperCase()) || { decimal: m.THOR, identifier: "" };
507
- }, W = async (n, t = 0) => {
508
- $t(n);
509
- const e = await K(q(n));
510
- return new f({ decimal: e, value: t, identifier: n });
511
- };
512
- class f extends y {
513
- constructor(e) {
514
- super(
515
- e.value instanceof y ? e.value : { decimal: e.decimal, value: e.value }
516
- );
517
- _(this, "address");
518
- _(this, "chain");
519
- _(this, "isSynthetic", !1);
520
- _(this, "isGasAsset", !1);
521
- _(this, "symbol");
522
- _(this, "ticker");
523
- _(this, "type");
524
- const r = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`, s = q(r);
525
- this.type = mt(s), this.chain = s.chain, this.ticker = s.ticker, this.symbol = s.symbol, this.address = s.address, this.isSynthetic = s.isSynthetic, this.isGasAsset = s.isGasAsset;
526
- }
527
- get assetValue() {
528
- return `${this.getValue("string")} ${this.ticker}`;
529
- }
530
- toString(e = !1) {
531
- const r = this.isSynthetic ? this.ticker : `${this.chain}.${this.ticker}`;
532
- return e ? r : (
533
- // THOR.ETH/ETH | ETH.USDT-0x1234567890
534
- `${this.chain}.${this.symbol}`
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
- static async fromString(e, r = 0) {
541
- return W(e, r);
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 { decimal: s, identifier: a } = x(
545
- e
546
- );
547
- return a ? new f({ decimal: s, identifier: a, value: r }) : void 0;
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 fromIdentifier(e, r = 0) {
550
- return W(e, r);
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 { decimal: s, identifier: a } = x(e);
554
- return new f({ decimal: s, identifier: a, value: r });
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: s, identifier: a } = ht(e);
558
- return new f({ value: r, decimal: s, identifier: a });
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 async loadStaticAssets() {
666
+ static loadStaticAssets() {
573
667
  return new Promise(
574
- async (e, r) => {
668
+ (e, r) => {
575
669
  try {
576
- const {
577
- // Omit ThorchainList from import to avoid decimals conflict (TC uses 8 for all)
578
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
579
- ThorchainList: s,
580
- NativeList: a,
581
- ...c
582
- } = await import("@swapkit/tokens");
583
- j = [a, ...Object.values(c)].reduce(
584
- (u, { tokens: l }) => (l.forEach(({ identifier: d, chain: A, ...I }) => {
585
- const R = "decimals" in I ? I.decimals : m[A];
586
- u.set(d, { identifier: d, decimal: R });
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: s,
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
- const Pt = (n) => {
602
- const t = f.fromChainOrSignature(n);
690
+ function qt(n) {
691
+ const t = p.fromChainOrSignature(n);
603
692
  switch (n) {
604
- case i.Bitcoin:
605
- case i.Litecoin:
606
- case i.BitcoinCash:
607
- return t.add(10001);
608
- case i.Dogecoin:
609
- return t.add(100000001);
610
- case i.Avalanche:
611
- case i.Ethereum:
612
- return t.add(10 * 10 ** 9);
613
- case i.THORChain:
614
- case i.Maya:
615
- return t.add(0);
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.add(1);
708
+ return t.set(1e-8);
618
709
  }
619
- }, q = (n) => {
620
- const t = n.slice(0, 14).includes("/"), e = n.includes(".") ? n : `${i.THORChain}.${n}`, [r, s] = e.split("."), [a, c] = s.split("-");
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: r,
624
- isGasAsset: dt({ chain: r, symbol: s }),
736
+ chain: s,
737
+ isGasAsset: J({ chain: s, symbol: u }),
625
738
  isSynthetic: t,
626
- symbol: c ? `${a}-${(c == null ? void 0 : c.toLowerCase()) ?? ""}` : s,
627
- ticker: t ? s : a
739
+ symbol: (t ? `${e}/` : "") + (c ? `${o}-${(c == null ? void 0 : c.toLowerCase()) ?? ""}` : u),
740
+ ticker: o
628
741
  };
629
- }, wt = {
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
- core_transaction_deposit_server_error: 10313,
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 Q extends Error {
816
+ class X extends Error {
687
817
  constructor(t, e) {
688
- console.error(e), super(t, { cause: { code: wt[t], message: t } }), Object.setPrototypeOf(this, Q.prototype);
689
- }
690
- }
691
- class bt extends y {
692
- eq(t) {
693
- return this.eqValue(t);
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
- f as AssetValue,
698
- y as BigIntArithmetics,
699
- Q as SwapKitError,
700
- bt as SwapKitNumber,
701
- yt as assetFromString,
702
- Vt as derivationPathToString,
703
- Et as filterAssets,
704
- U as formatBigIntToSafeValue,
705
- Bt as gasFeeMultiplier,
706
- mt as getAssetType,
707
- pt as getAsymmetricAssetShare,
708
- Mt as getAsymmetricAssetWithdrawAmount,
709
- _t as getAsymmetricRuneShare,
710
- Ot as getAsymmetricRuneWithdrawAmount,
711
- ht as getCommonAssetInfo,
712
- K as getDecimal,
713
- Rt as getEstimatedPoolShare,
714
- kt as getLiquiditySlippage,
715
- Ht as getMemoFor,
716
- Pt as getMinAmountByChain,
717
- Tt as getRequest,
718
- ft as getSymmetricPoolShare,
719
- Nt as getSymmetricWithdraw,
720
- vt as getTHORNameCost,
721
- dt as isGasAsset,
722
- at as postRequest,
723
- Ct as validateTHORName
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