@swapkit/helpers 1.0.0-rc.5 → 1.0.0-rc.51

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