@swapkit/helpers 1.0.0-rc.6 → 1.0.0-rc.60

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