@swapkit/helpers 1.0.0-rc.1 → 1.0.0-rc.3

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,49 +1,57 @@
1
- var rt = Object.defineProperty;
2
- var st = (n, t, e) => t in n ? rt(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
- var _ = (n, t, e) => (st(n, typeof t != "symbol" ? t + "" : t, e), e), it = (n, t, e) => {
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
4
  if (!t.has(n))
5
5
  throw TypeError("Cannot " + e);
6
6
  };
7
- var p = (n, t, e) => {
7
+ var $ = (n, t, e) => {
8
8
  if (t.has(n))
9
9
  throw TypeError("Cannot add the same private member more than once");
10
10
  t instanceof WeakSet ? t.add(n) : t.set(n, e);
11
11
  };
12
- var d = (n, t, e) => (it(n, t, "access private method"), e);
13
- import { FeeOption as x, BaseDecimal as h, Chain as i, ChainToRPC as at, MemoType as f } from "@swapkit/types";
14
- const vt = (n) => {
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
15
  if (n < 0)
16
16
  throw new Error("Invalid number of year");
17
17
  return 10 + n;
18
- }, Ct = (n) => {
18
+ }, vt = (n) => {
19
19
  if (n.length > 30)
20
20
  return !1;
21
21
  const t = /^[a-zA-Z0-9+_-]+$/g;
22
22
  return !!n.match(t);
23
- }, yt = ([n, t, e, r, s]) => `${n}'/${t}'/${e}'/${r}${typeof s != "number" ? "" : `/${s}`}`, Tt = async (n, t) => {
24
- const e = Object.entries(t || {}).reduce(
25
- (s, [a, c]) => (c && (s[a] = c), s),
26
- {}
27
- );
28
- return (await fetch(
29
- `${n}${t ? `?${new URLSearchParams(e).toString()}` : ""}`,
30
- { method: "GET", mode: "cors", credentials: "omit", referrer: "https://sk.thorswap.net" }
31
- )).json();
32
- }, ct = async (n, t, e, r = !1) => {
33
- const s = await fetch(`${n}`, {
34
- body: t,
35
- headers: e,
36
- method: "POST",
37
- referrer: "https://sk.thorswap.net"
38
- });
39
- return r ? s.text() : s.json();
40
- }, ot = "0x313ce567", z = async ({ chain: n, to: 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) => {
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 }) => {
41
49
  try {
42
- const e = await ct(
43
- at[n],
50
+ const e = await at(
51
+ it[n],
44
52
  JSON.stringify({
45
53
  method: "eth_call",
46
- params: [{ to: t.toLowerCase(), data: ot }, "latest"],
54
+ params: [{ to: t.toLowerCase(), data: ct }, "latest"],
47
55
  id: 44,
48
56
  jsonrpc: "2.0"
49
57
  }),
@@ -52,32 +60,32 @@ const vt = (n) => {
52
60
  ), { result: r } = JSON.parse(e);
53
61
  return parseInt(BigInt(r).toString());
54
62
  } catch (e) {
55
- return console.error(e), h[n];
63
+ return console.error(e), m[n];
56
64
  }
57
- }, ut = async (n) => {
65
+ }, ot = async (n) => {
58
66
  if (n === i.Ethereum)
59
- return h.ETH;
67
+ return m.ETH;
60
68
  const [, t] = n.split("-");
61
- return t != null && t.startsWith("0x") ? z({ chain: i.Ethereum, to: t }) : h.ETH;
62
- }, lt = async (n) => {
69
+ return t != null && t.startsWith("0x") ? Y({ chain: i.Ethereum, to: t }) : m.ETH;
70
+ }, ut = async (n) => {
63
71
  const [, t] = n.split("-");
64
- return t != null && t.startsWith("0x") ? z({ chain: i.Avalanche, to: t.toLowerCase() }) : h.AVAX;
65
- }, dt = async (n) => n === i.BinanceSmartChain ? h.BSC : h.BSC, X = async ({ chain: n, symbol: t }) => {
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 }) => {
66
74
  switch (n) {
67
75
  case i.Ethereum:
68
- return ut(t);
76
+ return ot(t);
69
77
  case i.Avalanche:
70
- return lt(t);
78
+ return ut(t);
71
79
  case i.BinanceSmartChain:
72
- return dt(t);
80
+ return lt(t);
73
81
  default:
74
- return h[n];
82
+ return m[n];
75
83
  }
76
- }, Bt = {
77
- [x.Average]: 1.2,
78
- [x.Fast]: 1.5,
79
- [x.Fastest]: 2
80
- }, mt = ({ chain: n, symbol: t }) => {
84
+ }, Ct = {
85
+ [H.Average]: 1.2,
86
+ [H.Fast]: 1.5,
87
+ [H.Fastest]: 2
88
+ }, dt = ({ chain: n, symbol: t }) => {
81
89
  switch (n) {
82
90
  case i.Bitcoin:
83
91
  case i.BitcoinCash:
@@ -92,6 +100,8 @@ const vt = (n) => {
92
100
  return t === "ETH";
93
101
  case i.Maya:
94
102
  return t === "CACAO";
103
+ case i.Kujira:
104
+ return t === "KUJI";
95
105
  case i.Cosmos:
96
106
  return t === "ATOM";
97
107
  case i.Polygon:
@@ -108,15 +118,16 @@ const vt = (n) => {
108
118
  case "ETH.vTHOR":
109
119
  return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
110
120
  case i.Cosmos:
111
- return { identifier: "GAIA.ATOM", decimal: h[n] };
121
+ return { identifier: "GAIA.ATOM", decimal: m[n] };
112
122
  case i.THORChain:
113
- return { identifier: "THOR.RUNE", decimal: h[n] };
123
+ return { identifier: "THOR.RUNE", decimal: m[n] };
114
124
  case i.BinanceSmartChain:
115
- return { identifier: "BSC.BNB", decimal: h[n] };
125
+ return { identifier: "BSC.BNB", decimal: m[n] };
116
126
  case i.Maya:
117
- return { identifier: "MAYA.CACAO", decimal: h.MAYA };
127
+ return { identifier: "MAYA.CACAO", decimal: m.MAYA };
118
128
  case "MAYA.MAYA":
119
129
  return { identifier: "MAYA.MAYA", decimal: 4 };
130
+ case i.Kujira:
120
131
  case i.Arbitrum:
121
132
  case i.Optimism:
122
133
  case i.BitcoinCash:
@@ -127,9 +138,9 @@ const vt = (n) => {
127
138
  case i.Polygon:
128
139
  case i.Bitcoin:
129
140
  case i.Ethereum:
130
- return { identifier: `${n}.${n}`, decimal: h[n] };
141
+ return { identifier: `${n}.${n}`, decimal: m[n] };
131
142
  }
132
- }, _t = ({ chain: n, symbol: t }) => {
143
+ }, mt = ({ chain: n, symbol: t }) => {
133
144
  if (t.includes("/"))
134
145
  return "Synth";
135
146
  switch (n) {
@@ -142,6 +153,8 @@ const vt = (n) => {
142
153
  return "Native";
143
154
  case i.Cosmos:
144
155
  return t === "ATOM" ? "Native" : "GAIA";
156
+ case i.Kujira:
157
+ return t === "KUJI" ? "Native" : "KUJI";
145
158
  case i.Binance:
146
159
  return t === i.Binance ? "Native" : "BEP2";
147
160
  case i.BinanceSmartChain:
@@ -157,53 +170,53 @@ const vt = (n) => {
157
170
  case i.Optimism:
158
171
  return [i.Ethereum, i.Optimism].includes(t) ? "Native" : "OPTIMISM";
159
172
  }
160
- }, Mt = (n) => {
173
+ }, yt = (n) => {
161
174
  var c;
162
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];
163
176
  return { chain: t, symbol: s, ticker: a, synth: r };
164
- }, gt = ({
177
+ }, _t = ({
165
178
  liquidityUnits: n,
166
179
  poolUnits: t,
167
180
  runeDepth: e
168
181
  }) => {
169
- const r = m(n), s = m(t), a = m(e), c = r.mul(a), o = s.mul(s).mul(2), l = s.mul(r).mul(2), u = r.mul(r), g = s.mul(s).mul(s);
170
- return c.mul(o.sub(l).add(u)).div(g);
171
- }, pt = ({
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 = ({
172
185
  liquidityUnits: n,
173
186
  poolUnits: t,
174
187
  assetDepth: e
175
188
  }) => {
176
- const r = m(n), s = m(t), a = m(e), c = r.mul(a), o = s.mul(s).mul(2), l = s.mul(r).mul(2), u = r.mul(r), g = c.mul(o.sub(l).add(u)), $ = s.mul(s).mul(s);
177
- return g.div($);
178
- }, Et = ({
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 = ({
179
192
  percent: n,
180
193
  runeDepth: t,
181
194
  liquidityUnits: e,
182
195
  poolUnits: r
183
- }) => gt({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(n), Ot = ({
196
+ }) => _t({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(n), Et = ({
184
197
  percent: n,
185
198
  assetDepth: t,
186
199
  liquidityUnits: e,
187
200
  poolUnits: r
188
- }) => pt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(n), m = (n) => new bt({ value: n, decimal: h.THOR }), ft = ({
201
+ }) => gt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(n), h = (n) => new wt({ value: n, decimal: m.THOR }), pt = ({
189
202
  liquidityUnits: n,
190
203
  poolUnits: t,
191
204
  runeDepth: e,
192
205
  assetDepth: r
193
206
  }) => ({
194
- assetAmount: m(r).mul(n).div(t),
195
- runeAmount: m(e).mul(n).div(t)
196
- }), Vt = ({
207
+ assetAmount: h(r).mul(n).div(t),
208
+ runeAmount: h(e).mul(n).div(t)
209
+ }), Ot = ({
197
210
  liquidityUnits: n,
198
211
  poolUnits: t,
199
212
  runeDepth: e,
200
213
  assetDepth: r,
201
214
  percent: s
202
215
  }) => Object.fromEntries(
203
- Object.entries(ft({ liquidityUnits: n, poolUnits: t, runeDepth: e, assetDepth: r })).map(
216
+ Object.entries(pt({ liquidityUnits: n, poolUnits: t, runeDepth: e, assetDepth: r })).map(
204
217
  ([a, c]) => [a, c.mul(s)]
205
218
  )
206
- ), Nt = ({
219
+ ), Mt = ({
207
220
  runeDepth: n,
208
221
  poolUnits: t,
209
222
  assetDepth: e,
@@ -211,59 +224,70 @@ const vt = (n) => {
211
224
  runeAmount: s,
212
225
  assetAmount: a
213
226
  }) => {
214
- const c = m(n), o = m(e), l = m(t), u = m(s), g = m(a), $ = u.mul(o), v = g.mul(c), D = u.mul(g), K = c.mul(o), tt = l.mul($.add(v.add(D.mul(2)))), et = $.add(v.add(K.mul(2))), G = tt.div(et), H = m(r).add(G);
215
- if (G.baseValueNumber === 0)
216
- return H.div(l).baseValueNumber;
217
- const nt = l.add(H);
218
- return H.div(nt).baseValueNumber;
219
- }, Rt = ({
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 = ({
220
233
  runeAmount: n,
221
234
  assetAmount: t,
222
235
  runeDepth: e,
223
236
  assetDepth: r
224
237
  }) => {
225
- const s = m(e), a = m(r), c = m(t), o = m(n), l = c.mul(s).sub(a.mul(o)), u = a.mul(o).add(s.mul(a));
226
- return Math.abs(l.div(u).baseValueNumber);
227
- }, At = ({
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 = ({
228
241
  symbol: n,
229
242
  ticker: t,
230
243
  chain: e
231
- }) => e === "ETH" && t !== "ETH" ? `${t}-${n.slice(-3)}` : n, kt = (n, t) => {
244
+ }) => e === "ETH" && t !== "ETH" ? `${t}-${n.slice(-3)}` : n, Rt = (n, t) => {
232
245
  switch (n) {
233
- case f.LEAVE:
234
- case f.BOND: {
246
+ case p.LEAVE:
247
+ case p.BOND: {
235
248
  const { address: e } = t;
236
249
  return `${n}:${e}`;
237
250
  }
238
- case f.UNBOND: {
251
+ case p.UNBOND: {
239
252
  const { address: e, unbondAmount: r } = t;
240
253
  return `${n}:${e}:${r * 10 ** 8}`;
241
254
  }
242
- case f.THORNAME_REGISTER: {
255
+ case p.THORNAME_REGISTER: {
243
256
  const { name: e, chain: r, address: s, owner: a } = t;
244
257
  return `${n}:${e}:${r}:${s}${a ? `:${a}` : ""}`;
245
258
  }
246
- case f.DEPOSIT: {
259
+ case p.DEPOSIT: {
247
260
  const { chain: e, symbol: r, address: s, singleSide: a } = t;
248
261
  return a ? `${n}:${e}/${r}::t:0` : `${n}:${e}.${r}:${s || ""}:t:0`;
249
262
  }
250
- case f.WITHDRAW: {
251
- const { chain: e, ticker: r, symbol: s, basisPoints: a, targetAssetString: c, singleSide: o } = t, l = !o && c ? `:${c}` : "", u = At({ chain: e, symbol: s, ticker: r });
252
- return `${n}:${e}${o ? "/" : "."}${u}:${a}${l}`;
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}`;
253
266
  }
254
- case f.OPEN_LOAN:
255
- case f.CLOSE_LOAN: {
267
+ case p.OPEN_LOAN:
268
+ case p.CLOSE_LOAN: {
256
269
  const { asset: e, address: r } = t;
257
270
  return `${n}:${e}:${r}`;
258
271
  }
259
272
  default:
260
273
  return "";
261
274
  }
262
- }, B = 8, U = ({
275
+ }, F = Object.values(i), At = (n = "") => {
276
+ const t = n.toUpperCase(), [e] = t.split(".");
277
+ if (F.includes(e))
278
+ return !0;
279
+ const [r] = t.split("/");
280
+ if (F.includes(r))
281
+ return !0;
282
+ throw new Error(
283
+ `Invalid identifier: ${n}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
284
+ );
285
+ }, C = 8, I = (n) => 10n ** BigInt(n), v = (n) => Math.log10(parseFloat(n.toString()));
286
+ function G({
263
287
  value: n,
264
- bigIntDecimal: t = B,
265
- decimal: e = B
266
- }) => {
288
+ bigIntDecimal: t = C,
289
+ decimal: e = C
290
+ }) {
267
291
  const r = n < 0n;
268
292
  let s = n.toString().substring(r ? 1 : 0);
269
293
  const a = e - (s.length - 1);
@@ -274,39 +298,28 @@ const vt = (n) => {
274
298
  /\.?0*$/,
275
299
  ""
276
300
  );
277
- }, W = Object.values(i), $t = (n = "") => {
278
- const t = n.toUpperCase(), [e] = t.split(".");
279
- if (W.includes(e))
280
- return !0;
281
- const [r] = t.split("/");
282
- if (W.includes(r))
283
- return !0;
284
- throw new Error(
285
- `Invalid identifier: ${n}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
286
- );
287
- }, S = (n) => 10n ** BigInt(n), C = (n) => Math.log10(parseFloat(n.toString()));
288
- var w, y, R, J, k, Q, O, L, b, T, V, j, I, N;
289
- const M = class M {
301
+ }
302
+ var w, V, M, J, N, z, E, L, b, B, O, x;
303
+ const y = class y {
290
304
  constructor(t) {
291
- p(this, w);
292
- p(this, R);
293
- p(this, k);
294
- p(this, O);
295
- p(this, b);
296
- p(this, V);
297
- p(this, I);
298
- _(this, "decimalMultiplier", 10n ** 8n);
299
- _(this, "bigIntValue", 0n);
300
- _(this, "decimal");
301
- const e = typeof t == "object", r = e ? t.value : t;
302
- this.decimal = e ? t.decimal : void 0, this.decimalMultiplier = S(
303
- Math.max(d(this, V, j).call(this, d(this, b, T).call(this, r)), this.decimal || 0)
304
- ), d(this, R, J).call(this, r);
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);
305
318
  }
306
319
  static fromBigInt(t, e) {
307
- return new M({
320
+ return new y({
308
321
  decimal: e,
309
- value: U({ value: t, bigIntDecimal: e, decimal: e })
322
+ value: G({ value: t, bigIntDecimal: e, decimal: e })
310
323
  });
311
324
  }
312
325
  static shiftDecimals({
@@ -314,40 +327,34 @@ const M = class M {
314
327
  from: e,
315
328
  to: r
316
329
  }) {
317
- return M.fromBigInt(
318
- new M(t).bigIntValue * S(r) / S(e),
330
+ return y.fromBigInt(
331
+ new y(t).bigIntValue * I(r) / I(e),
319
332
  r
320
333
  );
321
334
  }
322
- get unsafeNumber() {
323
- return parseFloat((this.bigIntValue / this.decimalMultiplier).toString());
324
- }
325
335
  get baseValue() {
326
- return d(this, I, N).call(this, "string");
336
+ return this.getBaseValue("string");
327
337
  }
328
338
  get baseValueNumber() {
329
- return d(this, I, N).call(this, "number");
339
+ return this.getBaseValue("number");
330
340
  }
331
341
  get baseValueBigInt() {
332
- return d(this, I, N).call(this, "number");
342
+ return this.getBaseValue("bigint");
333
343
  }
334
- get value() {
335
- return this.formatBigIntToSafeValue(
336
- this.bigIntValue,
337
- this.decimal || C(this.decimalMultiplier)
338
- );
344
+ set(t) {
345
+ return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
339
346
  }
340
347
  add(...t) {
341
- return d(this, w, y).call(this, "add", ...t);
348
+ return _(this, w, V).call(this, "add", ...t);
342
349
  }
343
350
  sub(...t) {
344
- return d(this, w, y).call(this, "sub", ...t);
351
+ return _(this, w, V).call(this, "sub", ...t);
345
352
  }
346
353
  mul(...t) {
347
- return d(this, w, y).call(this, "mul", ...t);
354
+ return _(this, w, V).call(this, "mul", ...t);
348
355
  }
349
356
  div(...t) {
350
- return d(this, w, y).call(this, "div", ...t);
357
+ return _(this, w, V).call(this, "div", ...t);
351
358
  }
352
359
  gt(t) {
353
360
  return this.bigIntValue > this.getBigIntValue(t);
@@ -364,136 +371,182 @@ const M = class M {
364
371
  eqValue(t) {
365
372
  return this.bigIntValue === this.getBigIntValue(t);
366
373
  }
374
+ getValue(t) {
375
+ const e = this.formatBigIntToSafeValue(
376
+ this.bigIntValue,
377
+ this.decimal || v(this.decimalMultiplier)
378
+ );
379
+ switch (t) {
380
+ case "number":
381
+ return Number(e);
382
+ case "string":
383
+ return e;
384
+ default:
385
+ return this.bigIntValue;
386
+ }
387
+ }
388
+ getBaseValue(t) {
389
+ const e = this.decimalMultiplier / I(this.decimal || 0), r = this.bigIntValue / e;
390
+ switch (t) {
391
+ case "number":
392
+ return Number(r);
393
+ case "string":
394
+ return r.toString();
395
+ default:
396
+ return this.bigIntValue;
397
+ }
398
+ }
367
399
  getBigIntValue(t, e) {
368
- return !e && typeof t == "object" ? t.bigIntValue : (t = typeof t == "object" ? t.value : t, d(this, O, L).call(this, d(this, b, T).call(this, t), e));
400
+ return !e && typeof t == "object" ? t.bigIntValue : _(this, E, L).call(this, _(this, b, B).call(this, P(t)), e);
369
401
  }
370
402
  formatBigIntToSafeValue(t, e) {
371
- const r = e || this.decimal || B, s = Math.max(
403
+ const r = e || this.decimal || C, s = Math.max(
372
404
  r,
373
- C(this.decimalMultiplier)
374
- ), a = t < 0n;
375
- let c = t.toString().substring(a ? 1 : 0);
376
- const o = s - (c.length - 1);
377
- o > 0 && (c = "0".repeat(o) + c);
378
- const l = c.length - s;
379
- let u = c.slice(-s);
380
- return parseInt(u[r]) >= 5 ? u = `${u.substring(0, r - 1)}${(parseInt(u[r - 1]) + 1).toString()}` : u = u.substring(0, r), `${a ? "-" : ""}${c.slice(0, l)}.${u}`.replace(
381
- /\.?0*$/,
382
- ""
383
- );
384
- }
385
- toSignificant(t) {
386
- const e = this.value.split("."), r = e[0], s = e[1];
387
- return s ? `${r}.${s.slice(0, t || this.decimal)}`.replace(
388
- /\.?0*$/,
389
- ""
390
- ) : 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*$/, "");
412
+ }
413
+ 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)
416
+ 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,
422
+ "0"
423
+ );
424
+ const o = parseInt(a), u = `${o}`.slice(0, t);
425
+ return `0.${u.padStart(
426
+ a.length - `${o}`.length + u.length,
427
+ "0"
428
+ )}`;
391
429
  }
392
430
  };
393
- w = new WeakSet(), y = function(t, ...e) {
394
- const r = d(this, k, Q).call(this, this, ...e), s = S(r), a = e.reduce(
395
- (o, l) => {
396
- const u = this.getBigIntValue(l, r);
397
- if (t === "div" && u === 0n)
398
- throw new RangeError("Division by zero");
399
- return t === "add" ? o + u : t === "sub" ? o - u : t === "mul" ? o * u / s : o * s / u;
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);
435
+ switch (t) {
436
+ case "add":
437
+ return o + l;
438
+ case "sub":
439
+ return o - l;
440
+ case "mul":
441
+ return o * l / s;
442
+ case "div": {
443
+ if (l === 0n)
444
+ throw new RangeError("Division by zero");
445
+ return o * s / l;
446
+ }
447
+ default:
448
+ return o;
449
+ }
400
450
  },
401
451
  //normalize is to precision multiplier base
402
452
  this.bigIntValue * s / this.decimalMultiplier
403
- ), c = U({
453
+ ), c = G({
404
454
  bigIntDecimal: r,
405
- decimal: Math.max(r, C(this.decimalMultiplier)),
455
+ decimal: Math.max(r, v(this.decimalMultiplier)),
406
456
  value: a
407
457
  });
408
458
  return new this.constructor({ decimal: this.decimal, value: c, identifier: this.toString() });
409
- }, R = new WeakSet(), J = function(t, e) {
410
- const r = d(this, b, T).call(this, t) || "0";
411
- this.bigIntValue = e || d(this, O, L).call(this, r);
412
- }, k = new WeakSet(), Q = function(...t) {
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) {
413
463
  const e = t.map(
414
- (r) => typeof r == "object" ? r.decimal || C(r.decimalMultiplier) : d(this, V, j).call(this, d(this, b, T).call(this, r))
464
+ (r) => typeof r == "object" ? r.decimal || v(r.decimalMultiplier) : _(this, O, x).call(this, _(this, b, B).call(this, r))
415
465
  ).filter(Boolean);
416
- return Math.max(...e, B);
417
- }, O = new WeakSet(), L = function(t, e) {
418
- const r = e ? S(e) : this.decimalMultiplier, s = C(r), [a, c = ""] = t.split(".");
466
+ 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(".");
419
469
  return BigInt(`${a}${c.padEnd(s, "0")}`);
420
- }, b = new WeakSet(), T = function(t) {
470
+ }, b = new WeakSet(), B = function(t) {
421
471
  const r = `${typeof t == "number" ? Number(t).toLocaleString("fullwide", {
422
472
  useGrouping: !1,
423
473
  maximumFractionDigits: 20
424
- }) : t}`.replaceAll(",", ".").split(".");
474
+ }) : P(t)}`.replaceAll(",", ".").split(".");
425
475
  return r.length > 1 ? `${r.slice(0, -1).join("")}.${r.at(-1)}` : r[0];
426
- }, V = new WeakSet(), j = function(t) {
476
+ }, O = new WeakSet(), x = function(t) {
427
477
  var r;
428
478
  const e = ((r = t.split(".")[1]) == null ? void 0 : r.length) || 0;
429
- return Math.max(e, B);
430
- }, I = new WeakSet(), N = function(t) {
431
- const e = this.decimalMultiplier / S(this.decimal || 0), r = this.bigIntValue / e;
432
- switch (t) {
433
- case "number":
434
- return Number(r);
435
- case "string":
436
- return r.toString();
437
- default:
438
- return r;
439
- }
479
+ return Math.max(e, C);
440
480
  };
441
- let E = M, q;
442
- const P = (n) => {
443
- if (!q)
481
+ let T = y;
482
+ function P(n) {
483
+ return typeof n == "object" ? "getValue" in n ? n.getValue("string") : n.value : n;
484
+ }
485
+ let j;
486
+ const D = (n) => {
487
+ if (!j)
444
488
  throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");
445
- return q.get(n.toUpperCase()) || { decimal: h.THOR, identifier: "" };
446
- }, Y = async (n, t = 0) => {
447
- $t(n);
448
- const e = await X(F(n));
449
- return new A({ decimal: e, value: t, identifier: n });
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 });
450
494
  };
451
- class A extends E {
495
+ class f extends T {
452
496
  constructor(e) {
453
497
  super(
454
- e.value instanceof E ? e.value : { decimal: e.decimal, value: e.value }
498
+ e.value instanceof T ? e.value : { decimal: e.decimal, value: e.value }
455
499
  );
456
- _(this, "address");
457
- _(this, "chain");
458
- _(this, "isSynthetic", !1);
459
- _(this, "isGasAsset", !1);
460
- _(this, "symbol");
461
- _(this, "ticker");
462
- _(this, "type");
463
- const r = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`, s = F(r);
464
- this.type = _t(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;
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}`;
512
+ }
513
+ toString() {
514
+ return `${this.chain}.${this.symbol}`;
515
+ }
516
+ eq({ chain: e, symbol: r }) {
517
+ return this.chain === e && this.symbol === r;
465
518
  }
466
519
  static async fromString(e, r = 0) {
467
- return Y(e, r);
520
+ return W(e, r);
468
521
  }
469
522
  static fromStringSync(e, r = 0) {
470
- const { decimal: s, identifier: a } = P(
523
+ const { decimal: s, identifier: a } = D(
471
524
  e
472
525
  );
473
- return a ? new A({ decimal: s, identifier: a, value: r }) : void 0;
526
+ return a ? new f({ decimal: s, identifier: a, value: r }) : void 0;
474
527
  }
475
528
  static async fromIdentifier(e, r = 0) {
476
- return Y(e, r);
529
+ return W(e, r);
477
530
  }
478
531
  static fromIdentifierSync(e, r = 0) {
479
- const { decimal: s, identifier: a } = P(e);
480
- return new A({ decimal: s, identifier: a, value: r });
532
+ const { decimal: s, identifier: a } = D(e);
533
+ return new f({ decimal: s, identifier: a, value: r });
481
534
  }
482
535
  static fromChainOrSignature(e, r = 0) {
483
536
  const { decimal: s, identifier: a } = ht(e);
484
- return new A({ value: r, decimal: s, identifier: a });
537
+ return new f({ value: r, decimal: s, identifier: a });
485
538
  }
486
539
  static async fromTCQuote(e, r = 0) {
487
- const s = await X(F(e)), a = this.shiftDecimals({ value: r, from: h.THOR, to: s });
488
- return new A({ value: a, identifier: e, decimal: s });
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 });
489
542
  }
490
543
  static fromTCQuoteStatic(e, r = 0) {
491
- const s = P(e), a = this.shiftDecimals({
544
+ const s = D(e), a = this.shiftDecimals({
492
545
  value: r,
493
- from: h.THOR,
546
+ from: m.THOR,
494
547
  to: s.decimal
495
548
  });
496
- return new A({ ...s, value: a });
549
+ return new f({ ...s, value: a });
497
550
  }
498
551
  static async loadStaticAssets() {
499
552
  return new Promise(
@@ -506,11 +559,11 @@ class A extends E {
506
559
  NativeList: a,
507
560
  ...c
508
561
  } = await import("@swapkit/tokens");
509
- q = [a, ...Object.values(c)].reduce(
510
- (l, { tokens: u }) => (u.forEach(({ identifier: g, chain: $, ...v }) => {
511
- const D = "decimals" in v ? v.decimals : h[$];
512
- l.set(g, { identifier: g, decimal: D });
513
- }), l),
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),
514
567
  /* @__PURE__ */ new Map()
515
568
  ), e({ ok: !0 });
516
569
  } catch (s) {
@@ -523,18 +576,9 @@ class A extends E {
523
576
  }
524
577
  );
525
578
  }
526
- get assetValue() {
527
- return `${this.value} ${this.ticker}`;
528
- }
529
- toString() {
530
- return `${this.chain}.${this.symbol}`;
531
- }
532
- eq({ chain: e, symbol: r }) {
533
- return this.chain === e && this.symbol === r;
534
- }
535
579
  }
536
- const Dt = (n) => {
537
- const t = A.fromChainOrSignature(n);
580
+ const kt = (n) => {
581
+ const t = f.fromChainOrSignature(n);
538
582
  switch (n) {
539
583
  case i.Bitcoin:
540
584
  case i.Litecoin:
@@ -551,17 +595,17 @@ const Dt = (n) => {
551
595
  default:
552
596
  return t.add(1);
553
597
  }
554
- }, F = (n) => {
598
+ }, q = (n) => {
555
599
  const t = n.slice(0, 14).includes("/"), e = n.includes(".") ? n : `${i.THORChain}.${n}`, [r, s] = e.split("."), [a, c] = s.split("-");
556
600
  return {
557
601
  address: c == null ? void 0 : c.toLowerCase(),
558
602
  chain: r,
559
- isGasAsset: mt({ chain: r, symbol: s }),
603
+ isGasAsset: dt({ chain: r, symbol: s }),
560
604
  isSynthetic: t,
561
605
  symbol: c ? `${a}-${(c == null ? void 0 : c.toLowerCase()) ?? ""}` : s,
562
606
  ticker: t ? s : a
563
607
  };
564
- }, wt = {
608
+ }, $t = {
565
609
  /**
566
610
  * Core
567
611
  */
@@ -618,44 +662,41 @@ const Dt = (n) => {
618
662
  */
619
663
  helpers_number_different_decimals: 99101
620
664
  };
621
- class Z extends Error {
665
+ class X extends Error {
622
666
  constructor(t, e) {
623
- console.error(e), super(t, { cause: { code: wt[t], message: t } }), Object.setPrototypeOf(this, Z.prototype);
667
+ console.error(e), super(t, { cause: { code: $t[t], message: t } }), Object.setPrototypeOf(this, X.prototype);
624
668
  }
625
669
  }
626
- class bt extends E {
670
+ class wt extends T {
627
671
  eq(t) {
628
672
  return this.eqValue(t);
629
673
  }
630
- toString() {
631
- return this.value;
632
- }
633
674
  }
634
675
  export {
635
- A as AssetValue,
636
- B as DEFAULT_DECIMAL,
637
- Z as SwapKitError,
638
- bt as SwapKitNumber,
639
- Mt as assetFromString,
640
- yt as derivationPathToString,
641
- U as formatBigIntToSafeValue,
642
- Bt as gasFeeMultiplier,
643
- _t as getAssetType,
644
- pt as getAsymmetricAssetShare,
645
- Ot as getAsymmetricAssetWithdrawAmount,
646
- gt as getAsymmetricRuneShare,
647
- Et as getAsymmetricRuneWithdrawAmount,
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,
648
689
  ht as getCommonAssetInfo,
649
- X as getDecimal,
650
- Nt as getEstimatedPoolShare,
651
- Rt as getLiquiditySlippage,
652
- kt as getMemoFor,
653
- Dt as getMinAmountByChain,
654
- Tt as getRequest,
655
- ft as getSymmetricPoolShare,
656
- Vt as getSymmetricWithdraw,
657
- vt as getTHORNameCost,
658
- mt as isGasAsset,
659
- ct as postRequest,
660
- Ct as validateTHORName
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
661
702
  };