@dhedge/trading-widget 6.3.5 → 6.3.6

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.
@@ -1,7 +1,7 @@
1
1
  import { hyperEvm as H, mainnet as I, polygon as at, optimism as rt, base as ot, arbitrum as it } from "wagmi/chains";
2
- import { aq as ct, ao as ut, ap as dt, a as R, q as N, ar as pt, as as lt, a5 as mt, ak as yt, a3 as At, b as gt, ae as Et, Z as k, aj as ht, at as V, e as ft, d as St, M as Tt, R as wt, P as _t, au as bt, av as Dt, Q as It, N as Rt, ah as _, _ as Nt, W as Ot, X as Ct, U as xt, aw as q, ax as Bt, ay as Lt, az as Mt, aA as Pt, aB as Ut, ad as $t } from "./gmx-Cyz_GmV5.js";
2
+ import { aq as ct, ao as ut, ap as dt, a as N, q as R, ar as pt, as as lt, a5 as mt, ak as yt, a3 as gt, b as At, ae as Et, Z as k, aj as ht, at as V, e as ft, d as St, M as Tt, R as wt, P as _t, au as bt, av as Dt, Q as It, N as Nt, ah as _, _ as Rt, W as Ot, X as Ct, U as xt, aw as q, ax as Bt, ay as Lt, az as Mt, aA as Pt, aB as Ut, ad as $t } from "./gmx-Cyz_GmV5.js";
3
3
  import d from "bignumber.js";
4
- import { zeroHash as vt, bytesToHex as Ft, pad as Yt, stringToHex as O, encodeAbiParameters as T, encodeFunctionData as g, maxUint256 as w, erc20Abi as K } from "viem";
4
+ import { zeroHash as vt, bytesToHex as Ft, pad as Yt, stringToHex as O, encodeAbiParameters as T, encodeFunctionData as A, maxUint256 as w, erc20Abi as K } from "viem";
5
5
  const B = "application/json";
6
6
  class j extends Error {
7
7
  constructor(e, s, n) {
@@ -60,14 +60,14 @@ const Xe = (t) => {
60
60
  timeoutMs: i,
61
61
  maxResponseBytes: u
62
62
  }) => {
63
- const l = n !== void 0 && s !== "GET", A = l && !Gt(n), m = new Headers(e);
64
- o === "json" && !m.has("Accept") && m.set("Accept", B), A && !m.has("Content-Type") && m.set("Content-Type", B);
63
+ const l = n !== void 0 && s !== "GET", g = l && !Gt(n), m = new Headers(e);
64
+ o === "json" && !m.has("Accept") && m.set("Accept", B), g && !m.has("Content-Type") && m.set("Content-Type", B);
65
65
  const f = i ? Ht(i, r) : void 0, nt = {
66
66
  method: s,
67
67
  headers: m,
68
68
  signal: f?.signal ?? r,
69
69
  ...c && { cache: c },
70
- ...l && { body: A ? JSON.stringify(n) : n }
70
+ ...l && { body: g ? JSON.stringify(n) : n }
71
71
  };
72
72
  try {
73
73
  const E = await fetch(Wt(t, a), nt);
@@ -368,7 +368,7 @@ const p = (t, e) => t?.toLowerCase() === e?.toLowerCase(), es = (t) => p(t, ct),
368
368
  }, L = (t) => t ? Yt(S(t), { size: 32 }) : vt, me = (t) => {
369
369
  if (!t) throw new Error("Cannot decode an empty base64 string");
370
370
  return Ft(Uint8Array.from(atob(t), (e) => e.charCodeAt(0)));
371
- }, ye = (t, e) => dt[e]?.[t] ?? R, ss = (t) => ut[t], ns = (t) => t && `${t.substring(0, 6)}...${t.substring(
371
+ }, ye = (t, e) => dt[e]?.[t] ?? N, ss = (t) => ut[t], ns = (t) => t && `${t.substring(0, 6)}...${t.substring(
372
372
  t.length - 4,
373
373
  t.length
374
374
  )}`, as = ({
@@ -380,21 +380,25 @@ const p = (t, e) => t?.toLowerCase() === e?.toLowerCase(), es = (t) => p(t, ct),
380
380
  e
381
381
  );
382
382
  return p(t, s);
383
- }, Ae = ({
383
+ }, ge = ({
384
384
  sourceAddress: t,
385
385
  amount: e
386
386
  }) => `${t}_${e}`, rs = (t, e) => {
387
387
  const s = t.slice(0, e), n = t.slice(e);
388
388
  return { firstPart: s, secondPart: n };
389
- }, ge = (t, e) => t / e * 100, os = (t) => t < 1 ? 4 : t < 10 ? 3 : 2, is = (t, e = N) => new d(t.toString()).shiftedBy(e).toFixed(0), cs = (t, e, s, n) => new d(e).dividedBy(s).multipliedBy(t).shiftedBy(-(n || N)).toNumber(), us = (t) => BigInt(
390
- new d(t || "0").shiftedBy(N).toFixed(0, d.ROUND_DOWN)
391
- ), J = (t) => {
389
+ }, Ae = (t, e) => t / e * 100, os = (t) => t < 1 ? 4 : t < 10 ? 3 : 2, is = (t, e = R) => new d(t.toString()).shiftedBy(e).toFixed(0), cs = (t) => {
390
+ const e = t?.trim();
391
+ return e ? !isNaN(Number(e)) && Number(e) > 0 : !1;
392
+ }, us = (t, e, s, n) => new d(e).dividedBy(s).multipliedBy(t).shiftedBy(-(n || R)).toNumber(), ds = (t) => {
393
+ const e = new d(t || "0").shiftedBy(R);
394
+ return e.isFinite() ? BigInt(e.toFixed(0, d.ROUND_DOWN)) : BigInt(0);
395
+ }, J = (t) => {
392
396
  const e = new d(0.01), s = new d(t), n = !s.isZero() && s.lt(e) ? e : s;
393
397
  return BigInt(n.multipliedBy(100).toFixed(0));
394
- }, ds = ({
398
+ }, ps = ({
395
399
  chainId: t,
396
400
  slippage: e
397
- }) => t === H.id ? BigInt(0) : J(e), ps = ({
401
+ }) => t === H.id ? BigInt(0) : J(e), ls = ({
398
402
  vaultAddress: t,
399
403
  swapData: e,
400
404
  sendTokenAddress: s,
@@ -407,7 +411,7 @@ const p = (t, e) => t?.toLowerCase() === e?.toLowerCase(), es = (t) => p(t, ct),
407
411
  }) => {
408
412
  const u = new d(c).multipliedBy(1 - i / 100).toFixed(0), l = [O(o, { size: 32 }), e];
409
413
  return [t, [[s, n, l], [a, u]], r];
410
- }, ls = ({
414
+ }, ms = ({
411
415
  receiveAssetAddress: t,
412
416
  assets: e,
413
417
  swapData: s,
@@ -423,9 +427,9 @@ const p = (t, e) => t?.toLowerCase() === e?.toLowerCase(), es = (t) => p(t, ct),
423
427
  const l = [
424
428
  O(u.routerKey, { size: 32 }),
425
429
  u.rawTransaction.data
426
- ], A = [i.address, i.rawBalance, l];
430
+ ], g = [i.address, i.rawBalance, l];
427
431
  return {
428
- srcData: [...c.srcData, A],
432
+ srcData: [...c.srcData, g],
429
433
  destAmount: c.destAmount.plus(u.destinationAmount)
430
434
  };
431
435
  }, a) ?? a;
@@ -449,14 +453,14 @@ const p = (t, e) => t?.toLowerCase() === e?.toLowerCase(), es = (t) => p(t, ct),
449
453
  withdrawData: "",
450
454
  slippageTolerance: BigInt(0)
451
455
  };
452
- const { srcData: r, dstData: o } = s, c = r.map(({ asset: l, amount: A }) => {
453
- const m = e?.[Ae({
456
+ const { srcData: r, dstData: o } = s, c = r.map(({ asset: l, amount: g }) => {
457
+ const m = e?.[ge({
454
458
  sourceAddress: l,
455
- amount: A.toString()
459
+ amount: g.toString()
456
460
  })]?.find((f) => f.routerKey === a);
457
461
  return {
458
462
  asset: l,
459
- amount: A,
463
+ amount: g,
460
464
  swapData: {
461
465
  routerKey: O(m?.routerKey ?? "", { size: 32 }),
462
466
  txData: m?.rawTransaction.data ?? "0x"
@@ -480,7 +484,7 @@ const p = (t, e) => t?.toLowerCase() === e?.toLowerCase(), es = (t) => p(t, ct),
480
484
  withdrawData: u,
481
485
  slippageTolerance: n
482
486
  };
483
- }, ms = ({
487
+ }, ys = ({
484
488
  chainId: t,
485
489
  txHash: e,
486
490
  error: s
@@ -489,20 +493,20 @@ const p = (t, e) => t?.toLowerCase() === e?.toLowerCase(), es = (t) => p(t, ct),
489
493
  return !1;
490
494
  const n = s instanceof Error ? s.message : String(s);
491
495
  return /\bNo Result\b/i.test(n);
492
- }, ys = ({
496
+ }, gs = ({
493
497
  chainId: t,
494
498
  action: e,
495
499
  isRabbyWallet: s
496
- }) => e === "update_ondo_prices" && t === I.id && s ? mt : t ? yt[t] ?? 0 : 0, As = (t, e) => gt[e]?.nativeTokenSymbol === t, gs = ({
500
+ }) => e === "update_ondo_prices" && t === I.id && s ? mt : t ? yt[t] ?? 0 : 0, As = (t, e) => At[e]?.nativeTokenSymbol === t, Es = ({
497
501
  nativeTokenBalance: t,
498
502
  tokenDecimals: e,
499
503
  gasPrice: s
500
504
  }) => {
501
- const n = new d(s).multipliedBy(At).shiftedBy(-e), a = new d(t).minus(
505
+ const n = new d(s).multipliedBy(gt).shiftedBy(-e), a = new d(t).minus(
502
506
  n
503
507
  );
504
508
  return a.gt("0") ? a : new d("0");
505
- }, Es = (t) => Et.includes(t), hs = (t) => {
509
+ }, hs = (t) => Et.includes(t), fs = (t) => {
506
510
  const e = Object.values(t).reduce(
507
511
  (s, { type: n }) => (s[n] = s[n] + 1, s),
508
512
  { string: 0, number: 0 }
@@ -531,7 +535,7 @@ const p = (t, e) => t?.toLowerCase() === e?.toLowerCase(), es = (t) => p(t, ct),
531
535
  ).test(t)
532
536
  );
533
537
  return a ? { title: a.title, hint: a.hint } : void 0;
534
- }, fs = ({
538
+ }, Ss = ({
535
539
  errorMessage: t,
536
540
  abiErrors: e
537
541
  }) => {
@@ -554,7 +558,7 @@ const p = (t, e) => t?.toLowerCase() === e?.toLowerCase(), es = (t) => p(t, ct),
554
558
  title: "Transaction failed",
555
559
  hint: `${he(r ?? "")} ${s ? `: ${s}` : ""}`
556
560
  };
557
- }, Ss = (t) => typeof t == "number" && Number.isFinite(t), Ts = (t) => typeof t == "bigint" && t !== BigInt(0), De = (t, e = V) => new d(t).shiftedBy(-e).toNumber(), Ie = (t) => !isNaN(parseFloat(t)) && !isNaN(t), Re = ({
561
+ }, Ts = (t) => typeof t == "number" && Number.isFinite(t), ws = (t) => typeof t == "bigint" && t !== BigInt(0), De = (t, e = V) => new d(t).shiftedBy(-e).toNumber(), Ie = (t) => !isNaN(parseFloat(t)) && !isNaN(t), Ne = ({
558
562
  value: t,
559
563
  minimumFractionDigits: e = 2,
560
564
  maximumFractionDigits: s = 2,
@@ -566,7 +570,7 @@ const p = (t, e) => t?.toLowerCase() === e?.toLowerCase(), es = (t) => p(t, ct),
566
570
  notation: n ? "compact" : void 0,
567
571
  minimumFractionDigits: e,
568
572
  maximumFractionDigits: s
569
- }).format(a ? De(t) : Number(t)), U = (t) => Ie(t) ? new d(t).toFixed() : "", $ = ["₀", "₁", "₂", "₃", "₄", "₅", "₆", "₇", "₈", "₉"], Ne = ({
573
+ }).format(a ? De(t) : Number(t)), U = (t) => Ie(t) ? new d(t).toFixed() : "", $ = ["₀", "₁", "₂", "₃", "₄", "₅", "₆", "₇", "₈", "₉"], Re = ({
570
574
  value: t,
571
575
  decimals: e = 4
572
576
  }) => {
@@ -580,13 +584,13 @@ const p = (t, e) => t?.toLowerCase() === e?.toLowerCase(), es = (t) => p(t, ct),
580
584
  return `0.0${$[r.length]}${o.slice(0, 3)}`;
581
585
  }
582
586
  return U(s.toFixed(e));
583
- }, Oe = (t, e = 0) => `${t.toLocaleString("en-US", { maximumFractionDigits: e })}%`, ws = (t) => t.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), _s = (t, e, s = 0) => {
584
- const n = ge(+t, e);
587
+ }, Oe = (t, e = 0) => `${t.toLocaleString("en-US", { maximumFractionDigits: e })}%`, _s = (t) => t.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), bs = (t, e, s = 0) => {
588
+ const n = Ae(+t, e);
585
589
  return Oe(n, s);
586
- }, bs = ({
590
+ }, Ds = ({
587
591
  currency: t,
588
592
  value: e
589
- }) => t === "USD" ? Re({ value: e }) : `${ft[t]} ${Ne({
593
+ }) => t === "USD" ? Ne({ value: e }) : `${ft[t]} ${Re({
590
594
  value: e,
591
595
  decimals: St[t]
592
596
  })}`, Ce = (t, e) => new d(
@@ -596,12 +600,12 @@ const p = (t, e) => t?.toLowerCase() === e?.toLowerCase(), es = (t) => p(t, ct),
596
600
  return t;
597
601
  const n = "...";
598
602
  return t.length <= e + s + n.length ? t : `${t.slice(0, e)}${n}${t.slice(-s)}`;
599
- }, Ds = ({
603
+ }, Is = ({
600
604
  balance: t,
601
605
  symbol: e,
602
606
  precision: s,
603
607
  truncateSymbol: n
604
- }) => `${Ce(t, s)} ${n ? xe(e) : e}`, Is = (t) => {
608
+ }) => `${Ce(t, s)} ${n ? xe(e) : e}`, Ns = (t) => {
605
609
  if (!t)
606
610
  return;
607
611
  const e = t.match(/0x[a-fA-F0-9]{64}/);
@@ -609,13 +613,13 @@ const p = (t, e) => t?.toLowerCase() === e?.toLowerCase(), es = (t) => p(t, ct),
609
613
  return;
610
614
  const s = e[0];
611
615
  return `${s.slice(0, 4)}...${s.slice(-3)}`;
612
- }, Rs = (t) => p(bt, t) || p(Dt, t), Ns = (t) => Rt.some(
616
+ }, Rs = (t) => p(bt, t) || p(Dt, t), Os = (t) => Nt.some(
613
617
  (e) => p(e, t)
614
- ), Os = (t) => Tt[t.toLowerCase()] ?? {
618
+ ), Cs = (t) => Tt[t.toLowerCase()] ?? {
615
619
  symbol: "",
616
620
  decimals: 18,
617
- address: R
618
- }, Cs = (t) => p(t, It) ? wt : _t, Be = (t) => `eth_${t}`, xs = ({
621
+ address: N
622
+ }, xs = (t) => p(t, It) ? wt : _t, Be = (t) => `eth_${t}`, Bs = ({
619
623
  action: t,
620
624
  log: e,
621
625
  symbol: s,
@@ -627,14 +631,14 @@ const p = (t, e) => t?.toLowerCase() === e?.toLowerCase(), es = (t) => p(t, ct),
627
631
  [_.CHAIN_ID.NAME]: a,
628
632
  [_.ADDRESS.NAME]: Be(n)
629
633
  };
630
- Nt[t].forEach((o) => {
634
+ Rt[t].forEach((o) => {
631
635
  e?.(o, r);
632
636
  });
633
- }, Bs = (t) => xt.some((e) => p(e, t)), Ls = (t) => Ot[t.toLowerCase()] ?? {
637
+ }, Ls = (t) => xt.some((e) => p(e, t)), Ms = (t) => Ot[t.toLowerCase()] ?? {
634
638
  symbol: "",
635
639
  decimals: 18,
636
- address: R
637
- }, Ms = (t) => Ct[t.toLowerCase()], Le = "0x3333333333333333333333333333333333333333";
640
+ address: N
641
+ }, Ps = (t) => Ct[t.toLowerCase()], Le = "0x3333333333333333333333333333333333333333";
638
642
  it.id + "", Ut.address, ot.id + "", Pt.address, rt.id + "", Mt.address, at.id + "", Lt.address, I.id + "", Bt.address, H.id + "", q.address;
639
643
  const Me = "0x2222222222222222222222222222222222222222", v = BigInt("0x2000000000000000000000000000000000000000"), Pe = 10000n, Ue = (t) => p(t, Le), $e = (t) => {
640
644
  if (p(t, Me))
@@ -645,7 +649,7 @@ const Me = "0x2222222222222222222222222222222222222222", v = BigInt("0x200000000
645
649
  } catch {
646
650
  return !1;
647
651
  }
648
- }, Ps = (t) => Ue(t) || $e(t), Us = () => q, $s = /* @__PURE__ */ new Map(), et = (t, e) => !e || e.size === 0 ? t : t.map((s) => {
652
+ }, Us = (t) => Ue(t) || $e(t), $s = () => q, vs = /* @__PURE__ */ new Map(), et = (t, e) => !e || e.size === 0 ? t : t.map((s) => {
649
653
  const n = e.get(
650
654
  s.supportedAsset.toLowerCase()
651
655
  );
@@ -685,14 +689,14 @@ const Me = "0x2222222222222222222222222222222222222222", v = BigInt("0x200000000
685
689
  return c;
686
690
  }
687
691
  return null;
688
- }, vs = (t, e, s) => {
692
+ }, Fs = (t, e, s) => {
689
693
  const n = (t ?? []).map((a) => ({
690
694
  supportedAsset: a,
691
695
  withdrawData: "",
692
696
  slippageTolerance: e
693
697
  }));
694
698
  return et(n, s);
695
- }, Fs = async (t, e, s, n, a) => {
699
+ }, Ys = async (t, e, s, n, a) => {
696
700
  for (const r of t) {
697
701
  const o = J(r);
698
702
  try {
@@ -718,7 +722,7 @@ const Me = "0x2222222222222222222222222222222222222222", v = BigInt("0x200000000
718
722
  }
719
723
  }
720
724
  return null;
721
- }, Ys = async (t, e, {
725
+ }, Gs = async (t, e, {
722
726
  fetchAaveSwapParams: s,
723
727
  fetchAaveSwapQuotes: n,
724
728
  withdrawAmountD18: a,
@@ -744,7 +748,7 @@ const Me = "0x2222222222222222222222222222222222222222", v = BigInt("0x200000000
744
748
  return console.error(i), { asset: o };
745
749
  }
746
750
  })
747
- ), F = (t) => Math.round(t * 100) / 100, Gs = ({
751
+ ), F = (t) => Math.round(t * 100) / 100, Ws = ({
748
752
  maxSlippage: t,
749
753
  candidates: e = $t
750
754
  }) => {
@@ -752,7 +756,7 @@ const Me = "0x2222222222222222222222222222222222222222", v = BigInt("0x200000000
752
756
  return [];
753
757
  const s = F(Math.min(t, 100)), n = e.filter((r) => r > 0 && r <= s).map(F), a = new Set(n);
754
758
  return a.add(s), a.add(t), Array.from(a).sort((r, o) => r - o);
755
- }, x = 1000000000000000000n, Ge = 1000000n, Y = 10000n, G = 100n, Ws = (t) => ({
759
+ }, x = 1000000000000000000n, Ge = 1000000n, Y = 10000n, G = 100n, Hs = (t) => ({
756
760
  quotes: t.quotes.map(
757
761
  (e) => ({
758
762
  chainId: y(e.chainId, "chainId"),
@@ -767,7 +771,7 @@ const Me = "0x2222222222222222222222222222222222222222", v = BigInt("0x200000000
767
771
  })
768
772
  ),
769
773
  signatures: t.signatures.map(S)
770
- }), st = (t, e) => t * e / x, We = x, Hs = (t, e) => !!e && st(t, e) < We, He = (t, e, s) => {
774
+ }), st = (t, e) => t * e / x, We = x, ks = (t, e) => !!e && st(t, e) < We, He = (t, e, s) => {
771
775
  const n = BigInt(Math.max(0, Math.round(s * 100))), a = n > G ? G : n, r = Y - a, c = st(t, e) * r * Ge, i = Y * x;
772
776
  return (c + i - 1n) / i;
773
777
  }, ke = (t, e) => ({
@@ -780,7 +784,7 @@ const Me = "0x2222222222222222222222222222222222222222", v = BigInt("0x200000000
780
784
  expiration: y(t.expiration, "expiration"),
781
785
  side: Number(t.side),
782
786
  additionalData: L(t.additionalData)
783
- }), ks = ({
787
+ }), Vs = ({
784
788
  attestation: t,
785
789
  chainId: e,
786
790
  slippagePercent: s
@@ -797,7 +801,7 @@ const Me = "0x2222222222222222222222222222222222222222", v = BigInt("0x200000000
797
801
  )
798
802
  }
799
803
  ]);
800
- }, Vs = (t) => [...t.reduce(
804
+ }, qs = (t) => [...t.reduce(
801
805
  (s, n) => s.has(n.accountId) ? s : s.set(n.accountId, n),
802
806
  /* @__PURE__ */ new Map()
803
807
  ).values()].map(({ accountId: s, marketId: n }) => ({
@@ -809,7 +813,7 @@ const Me = "0x2222222222222222222222222222222222222222", v = BigInt("0x200000000
809
813
  debt: t.find(
810
814
  (a) => a.accountId === s && a.isDebt
811
815
  )
812
- })), qs = ({
816
+ })), Ks = ({
813
817
  collateral: t,
814
818
  dytmOffice: e,
815
819
  processor: s,
@@ -825,7 +829,7 @@ const Me = "0x2222222222222222222222222222222222222222", v = BigInt("0x200000000
825
829
  // 1 · drain GM collateral out of the split account -> processor with the
826
830
  // max-shares sentinel.
827
831
  to: e,
828
- data: g({
832
+ data: A({
829
833
  abi: C,
830
834
  functionName: "withdraw",
831
835
  args: [
@@ -843,7 +847,7 @@ const Me = "0x2222222222222222222222222222222222222222", v = BigInt("0x200000000
843
847
  {
844
848
  // 2 · approve the GM token to Ondo's swap contract
845
849
  to: n,
846
- data: g({
850
+ data: A({
847
851
  abi: K,
848
852
  functionName: "approve",
849
853
  args: [a, o]
@@ -852,19 +856,19 @@ const Me = "0x2222222222222222222222222222222222222222", v = BigInt("0x200000000
852
856
  {
853
857
  // 3 · redeem GM -> USDC with the signed attestation
854
858
  to: a,
855
- data: g({
859
+ data: A({
856
860
  abi: jt,
857
861
  functionName: "swapExactInWithAttestation",
858
862
  args: [n, o, r, c, i, u]
859
863
  })
860
864
  }
861
- ], Ks = ({
865
+ ], js = ({
862
866
  collateral: t,
863
867
  dytmOffice: e,
864
868
  processor: s
865
869
  }) => ({
866
870
  to: e,
867
- data: g({
871
+ data: A({
868
872
  abi: C,
869
873
  functionName: "withdraw",
870
874
  args: [
@@ -878,7 +882,7 @@ const Me = "0x2222222222222222222222222222222222222222", v = BigInt("0x200000000
878
882
  }
879
883
  ]
880
884
  })
881
- }), js = ({
885
+ }), Xs = ({
882
886
  accountId: t,
883
887
  debtKey: e,
884
888
  dytmOffice: s,
@@ -887,7 +891,7 @@ const Me = "0x2222222222222222222222222222222222222222", v = BigInt("0x200000000
887
891
  {
888
892
  // approve USDC to the DYTM Office for the repay
889
893
  to: n,
890
- data: g({
894
+ data: A({
891
895
  abi: K,
892
896
  functionName: "approve",
893
897
  args: [s, w]
@@ -896,7 +900,7 @@ const Me = "0x2222222222222222222222222222222222222222", v = BigInt("0x200000000
896
900
  {
897
901
  // repay the slice's whole USDC debt
898
902
  to: s,
899
- data: g({
903
+ data: A({
900
904
  abi: C,
901
905
  functionName: "repay",
902
906
  args: [
@@ -913,13 +917,13 @@ const Me = "0x2222222222222222222222222222222222222222", v = BigInt("0x200000000
913
917
  ]
914
918
  })
915
919
  }
916
- ], Xs = ({
920
+ ], zs = ({
917
921
  actions: t,
918
922
  outputAsset: e,
919
923
  minOutputAmount: s
920
924
  }) => T(Xt, [
921
925
  { actions: t, outputAsset: e, minOutputAmount: s }
922
- ]), W = /* @__PURE__ */ new Set(), zs = (t) => {
926
+ ]), W = /* @__PURE__ */ new Set(), Qs = (t) => {
923
927
  const e = t?.message;
924
928
  !e || W.has(e) || (W.add(e), console.warn(e));
925
929
  };
@@ -929,90 +933,91 @@ export {
929
933
  ye as B,
930
934
  Z as C,
931
935
  os as D,
932
- $s as E,
936
+ vs as E,
933
937
  M as F,
934
- Os as G,
935
- Cs as H,
936
- Ls as I,
937
- Ms as J,
938
- Us as K,
939
- gs as L,
938
+ Cs as G,
939
+ xs as H,
940
+ Ms as I,
941
+ Ps as J,
942
+ $s as K,
943
+ Es as L,
940
944
  We as M,
941
- ge as N,
942
- cs as O,
943
- ys as P,
945
+ Ae as N,
946
+ us as O,
947
+ gs as P,
944
948
  J as Q,
945
- Is as R,
946
- Vs as S,
949
+ Ns as R,
950
+ qs as S,
947
951
  D as T,
948
952
  as as U,
949
- Ns as V,
953
+ Os as V,
950
954
  Rs as W,
951
- Bs as X,
952
- Ps as Y,
955
+ Ls as X,
956
+ Us as Y,
953
957
  Ue as Z,
954
958
  $e as _,
955
959
  ce as a,
956
- Es as a0,
957
- Hs as a1,
958
- zs as a2,
959
- xs as a3,
960
- ke as a4,
961
- Ws as a5,
962
- et as a6,
963
- us as a7,
964
- fs as a8,
965
- is as a9,
966
- U as aA,
967
- ns as aa,
968
- ms as ab,
969
- rs as ac,
970
- y as ad,
971
- L as ae,
972
- Be as af,
973
- xe as ag,
974
- Ye as ah,
975
- Fs as ai,
976
- hs as aj,
977
- Vt as ak,
978
- Xe as al,
979
- es as am,
980
- Ss as an,
981
- p as ao,
982
- Re as ap,
983
- Ts as aq,
984
- De as ar,
985
- Ze as as,
986
- Qe as at,
987
- Le as au,
988
- Ne as av,
989
- ts as aw,
990
- Oe as ax,
991
- Ie as ay,
992
- ws as az,
960
+ cs as a0,
961
+ hs as a1,
962
+ ks as a2,
963
+ Qs as a3,
964
+ Bs as a4,
965
+ ke as a5,
966
+ Hs as a6,
967
+ et as a7,
968
+ ds as a8,
969
+ Ss as a9,
970
+ _s as aA,
971
+ U as aB,
972
+ is as aa,
973
+ ns as ab,
974
+ ys as ac,
975
+ rs as ad,
976
+ y as ae,
977
+ L as af,
978
+ Be as ag,
979
+ xe as ah,
980
+ Ye as ai,
981
+ Ys as aj,
982
+ fs as ak,
983
+ Vt as al,
984
+ Xe as am,
985
+ es as an,
986
+ Ts as ao,
987
+ p as ap,
988
+ Ne as aq,
989
+ ws as ar,
990
+ De as as,
991
+ Ze as at,
992
+ Qe as au,
993
+ Le as av,
994
+ Re as aw,
995
+ ts as ax,
996
+ Oe as ay,
997
+ Ie as az,
993
998
  me as b,
994
999
  Ee as c,
995
1000
  Fe as d,
996
- qs as e,
997
- Ks as f,
998
- js as g,
999
- Ae as h,
1000
- ls as i,
1001
- ps as j,
1001
+ Ks as e,
1002
+ js as f,
1003
+ Xs as g,
1004
+ ge as h,
1005
+ ms as i,
1006
+ ls as j,
1002
1007
  ze as k,
1003
1008
  He as l,
1004
- vs as m,
1005
- ks as n,
1006
- Xs as o,
1007
- Ys as p,
1009
+ Fs as m,
1010
+ Vs as n,
1011
+ zs as o,
1012
+ Gs as p,
1008
1013
  Je as q,
1009
1014
  S as r,
1010
1015
  ve as s,
1011
1016
  de as t,
1012
1017
  Ce as u,
1013
- bs as v,
1014
- _s as w,
1015
- Ds as x,
1016
- Gs as y,
1017
- ds as z
1018
+ Ds as v,
1019
+ bs as w,
1020
+ Is as x,
1021
+ Ws as y,
1022
+ ps as z
1018
1023
  };
@@ -0,0 +1 @@
1
+ "use strict";const E=require("wagmi/chains"),a=require("./gmx-DJ0gqvLq.cjs"),p=require("bignumber.js"),d=require("viem"),B="application/json";class W extends Error{constructor(e,n,s){super(`HTTP ${e}${s?`: ${s}`:""}`),this.name="FetchRequestError",this.status=e,this.statusText=n,this.body=s}}const Tt=t=>{if(!(t instanceof W)||!t.body)return null;try{return JSON.parse(t.body)}catch{return null}},St=t=>typeof t=="string"||t instanceof FormData||t instanceof URLSearchParams||t instanceof Blob||t instanceof ArrayBuffer||ArrayBuffer.isView(t),ft=(t,e)=>{const n=String(t),s=e?new URLSearchParams(e).toString():"";if(!s)return n;const r=n.indexOf("#"),o=r===-1?n:n.slice(0,r),i=r===-1?"":n.slice(r);return`${o}${o.includes("?")?"&":"?"}${s}${i}`},_t=(t,e)=>{const n=new AbortController,s=()=>n.abort();e?.aborted&&s();const r=setTimeout(s,t);return e?.addEventListener("abort",s),{signal:n.signal,cleanup:()=>{clearTimeout(r),e?.removeEventListener("abort",s)}}},Dt=async(t,e,n)=>{if(n===void 0)return await t[e]();const s=Number(t.headers.get("content-length"));if(s>n)throw new Error(`Response too large: ${s} bytes`);if(e==="blob"||e==="arrayBuffer"){const o=await t[e](),i=o instanceof Blob?o.size:o.byteLength;if(i>n)throw new Error(`Response too large: ${i} bytes`);return o}const r=await t.text();if(r.length>n)throw new Error(`Response too large: ${r.length} chars`);return e==="json"?JSON.parse(r):r},H=async({url:t,headers:e,method:n,body:s,params:r,signal:o,readMethod:i="json",cache:u,timeoutMs:c,maxResponseBytes:l})=>{const A=s!==void 0&&n!=="GET",h=A&&!St(s),g=new Headers(e);i==="json"&&!g.has("Accept")&&g.set("Accept",B),h&&!g.has("Content-Type")&&g.set("Content-Type",B);const _=c?_t(c,o):void 0,ht={method:n,headers:g,signal:_?.signal??o,...u&&{cache:u},...A&&{body:h?JSON.stringify(s):s}};try{const T=await fetch(ft(t,r),ht);if(!T.ok)throw new W(T.status,T.statusText,await T.text().catch(()=>""));return await Dt(T,i,l)}finally{_?.cleanup()}},wt=typeof window<"u",bt=[{inputs:[{internalType:"address",name:"_pool",type:"address"},{internalType:"address",name:"_asset",type:"address"},{internalType:"uint256",name:"_poolTokenAmount",type:"uint256"}],name:"previewGmTokenAmount",outputs:[{internalType:"uint256",name:"gmTokenAmount",type:"uint256"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"ondoGMSwap",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"usdc",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"}],Rt=[{type:"tuple",components:[{name:"attestationSignature",type:"bytes"},{name:"quote",type:"tuple",components:[{name:"chainId",type:"uint256"},{name:"attestationId",type:"uint256"},{name:"userId",type:"bytes32"},{name:"asset",type:"address"},{name:"price",type:"uint256"},{name:"quantity",type:"uint256"},{name:"expiration",type:"uint256"},{name:"side",type:"uint8"},{name:"additionalData",type:"bytes32"}]},{name:"amountOutMinimum",type:"uint256"}]}],It=[{name:"asset",type:"address"},{name:"amount",type:"uint256"},{name:"assetType",type:"uint16"},{name:"isPool",type:"bool"},{name:"isDebt",type:"bool"},{name:"marketId",type:"uint88"},{name:"accountId",type:"uint256"},{name:"tokenId",type:"uint256"},{name:"debtKey",type:"uint248"},{name:"shares",type:"uint256"}],Nt=[{inputs:[{internalType:"address",name:"_pool",type:"address"},{internalType:"uint256",name:"_poolTokenAmount",type:"uint256"}],name:"previewWithdrawal",outputs:[{name:"assetData",type:"tuple[]",components:It}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"dytmWithdrawProcessor",outputs:[{name:"",type:"address"}],stateMutability:"view",type:"function"}],N=[{inputs:[{name:"params",type:"tuple",components:[{name:"account",type:"uint256"},{name:"tokenId",type:"uint256"},{name:"receiver",type:"address"},{name:"assets",type:"uint256"},{name:"shares",type:"uint256"},{name:"extraData",type:"bytes"}]}],name:"withdraw",outputs:[{name:"assets",type:"uint256"}],stateMutability:"nonpayable",type:"function"},{inputs:[{name:"params",type:"tuple",components:[{name:"account",type:"uint256"},{name:"key",type:"uint248"},{name:"withCollateralType",type:"uint8"},{name:"assets",type:"uint256"},{name:"shares",type:"uint256"},{name:"extraData",type:"bytes"}]}],name:"repay",outputs:[{name:"assetsRepaid",type:"uint256"}],stateMutability:"nonpayable",type:"function"}],Ot=[{inputs:[{name:"tokenIn",type:"address"},{name:"amountIn",type:"uint256"},{name:"tokenOut",type:"address"},{name:"amountOutMinimum",type:"uint256"},{name:"attestationSignature",type:"bytes"},{name:"quote",type:"tuple",components:[{name:"chainId",type:"uint256"},{name:"attestationId",type:"uint256"},{name:"userId",type:"bytes32"},{name:"asset",type:"address"},{name:"price",type:"uint256"},{name:"quantity",type:"uint256"},{name:"expiration",type:"uint256"},{name:"side",type:"uint8"},{name:"additionalData",type:"bytes32"}]}],name:"swapExactInWithAttestation",outputs:[],stateMutability:"nonpayable",type:"function"}],Ct=[{type:"tuple",components:[{name:"actions",type:"tuple[]",components:[{name:"to",type:"address"},{name:"data",type:"bytes"}]},{name:"outputAsset",type:"address"},{name:"minOutputAmount",type:"uint256"}]}],D={stringErrors:{"currently closed for trading":{title:"The market for this tokenized asset is closed right now",hint:"Wait until the market reopens (the error message says when) and simply retry."},"Synth exchange suspended. Operation prohibited":{title:"Vault includes deprecated synths in portfolio",hint:"Redeem deprecated synth to be able to withdraw."}},selectorErrors:{"0x54971d46":{signature:"SwapFailed(address,(address,uint256,(bytes32,bytes)),bytes)",title:"The token swap failed to execute",hint:"Your assets are still in your wallet — try again, or retry with a higher slippage tolerance."},"0x81a815ef":{signature:"InsufficientAmountReceived(address,uint256,uint256)",title:"Swap output was below the minimum received amount",hint:"Increase slippage tolerance and try again."}}},Y=t=>({stringErrors:{...t.stringErrors,...D.stringErrors},selectorErrors:{...t.selectorErrors,...D.selectorErrors}}),Pt=["https://cdn.jsdelivr.net/gh/dhedge/V2-Public@master/readmes/errorCodes/registry.json","https://raw.githubusercontent.com/dhedge/V2-Public/master/readmes/errorCodes/registry.json"],xt=1,Bt=1e4,Lt=2e6,Mt=2e3,Ut=500,vt=120,Ft=300,$t=4,Gt=/^dh\d{1,3}$/i,V=/[\u0000-\u001f\u007f]/,Wt=/https?:\/\/|[<>`]/i,Ht=t=>t.length<=vt&&!V.test(t)&&(Gt.test(t)||t.length>=$t),S=t=>typeof t=="string"&&t.length>0&&t.length<=Ft&&!V.test(t)&&!Wt.test(t);let q=D,w=null;const O=()=>q,k=t=>{q=Y(t)},Yt=t=>{const e=t;if(e?.schemaVersion!==xt)throw new Error(`Unsupported error registry schemaVersion: ${String(e?.schemaVersion)}`);const n={};for(const[r,o]of Object.entries(e.stringErrors??{}))o?.curated===!0&&Ht(r)&&S(o.description)&&S(o.action)&&(n[r]={title:o.description,hint:o.action});const s={};for(const[r,o]of Object.entries(e.selectorErrors??{}))o?.curated===!0&&/^0x[0-9a-f]{8}$/.test(r)&&S(o.signature)&&S(o.description)&&S(o.action)&&(s[r]={signature:o.signature,title:o.description,hint:o.action});if(!Object.keys(n).length)throw new Error("Error registry contained no curated string errors");if(Object.keys(n).length>Mt||Object.keys(s).length>Ut)throw new Error("Error registry exceeded expected entry counts");return{stringErrors:n,selectorErrors:s}},K=async({timeoutMs:t=Bt}={})=>{const e=[];for(const n of Pt)try{const s=await H({url:n,method:"GET",timeoutMs:t,maxResponseBytes:Lt});return Y(Yt(s))}catch(s){e.push(`${n}: ${s instanceof Error?s.message:String(s)}`)}throw new Error(`All error registry sources failed: ${e.join("; ")}`)},Vt=()=>(w??(w=K().then(k).catch(()=>{w=null})),w),qt=()=>typeof window<"u";function kt(){return qt()&&typeof window.ethereum<"u"}async function Kt(t){try{if(kt())return window.ethereum.request({method:"wallet_watchAsset",params:{type:"ERC20",options:t}})}catch{return!1}return!1}const m=(t,e)=>t?.toLowerCase()===e?.toLowerCase(),jt=t=>m(t,a.AddressZero$1),f=t=>{if(!t)throw new Error("Cannot prefix an empty hex value");return t.startsWith("0x")?t:`0x${t}`},y=(t,e)=>{try{return BigInt(t)}catch{throw new Error(`Cannot convert "${e}" value "${t}" to bigint`)}},b=t=>t?d.pad(f(t),{size:32}):d.zeroHash,j=t=>{if(!t)throw new Error("Cannot decode an empty base64 string");return d.bytesToHex(Uint8Array.from(atob(t),e=>e.charCodeAt(0)))},X=(t,e)=>a.contractsAddressesMap[e]?.[t]??a.AddressZero,Xt=t=>a.contractsAbisMap[t],Zt=t=>t&&`${t.substring(0,6)}...${t.substring(t.length-4,t.length)}`,zt=({address:t,chainId:e})=>{const n=X("aaveLendingPoolV3",e);return m(t,n)},Z=({sourceAddress:t,amount:e})=>`${t}_${e}`,Qt=(t,e)=>{const n=t.slice(0,e),s=t.slice(e);return{firstPart:n,secondPart:s}},z=(t,e)=>t/e*100,Jt=t=>t<1?4:t<10?3:2,te=(t,e=a.DEFAULT_PRECISION)=>new p(t.toString()).shiftedBy(e).toFixed(0),ee=t=>{const e=t?.trim();return e?!isNaN(Number(e))&&Number(e)>0:!1},ne=(t,e,n,s)=>new p(e).dividedBy(n).multipliedBy(t).shiftedBy(-(s||a.DEFAULT_PRECISION)).toNumber(),se=t=>{const e=new p(t||"0").shiftedBy(a.DEFAULT_PRECISION);return e.isFinite()?BigInt(e.toFixed(0,p.ROUND_DOWN)):BigInt(0)},C=t=>{const e=new p(.01),n=new p(t),s=!n.isZero()&&n.lt(e)?e:n;return BigInt(s.multipliedBy(100).toFixed(0))},re=({chainId:t,slippage:e})=>t===E.hyperEvm.id?BigInt(0):C(e),oe=({vaultAddress:t,swapData:e,sendTokenAddress:n,sendTokenAmount:s,vaultDepositTokenAddress:r,minVaultTokensReceivedAmount:o,routerKey:i="ONE_INCH",swapDestinationAmount:u,swapSlippage:c})=>{const l=new p(u).multipliedBy(1-c/100).toFixed(0),A=[d.stringToHex(i,{size:32}),e];return[t,[[n,s,A],[r,l]],o]},ae=({receiveAssetAddress:t,assets:e,swapData:n,slippage:s})=>{const r={srcData:[],destAmount:new p("0")},{srcData:o,destAmount:i}=e?.reduce((u,c)=>{const l=n?.[c.address];if(!l)return u;const A=[d.stringToHex(l.routerKey,{size:32}),l.rawTransaction.data],h=[c.address,c.rawBalance,A];return{srcData:[...u.srcData,h],destAmount:u.destAmount.plus(l.destinationAmount)}},r)??r;return[o,[t,i.times(1-s/100).toFixed(0,p.ROUND_DOWN)]]},Q=({assetAddress:t,swapQuotes:e,swapParams:n,slippageToleranceForContractTransaction:s,routerKey:r})=>{if(!n)return{supportedAsset:t,withdrawData:"",slippageTolerance:BigInt(0)};const{srcData:o,dstData:i}=n,u=o.map(({asset:A,amount:h})=>{const g=e?.[Z({sourceAddress:A,amount:h.toString()})]?.find(_=>_.routerKey===r);return{asset:A,amount:h,swapData:{routerKey:d.stringToHex(g?.routerKey??"",{size:32}),txData:g?.rawTransaction.data??"0x"}}}),c=d.encodeAbiParameters(a.ComplexWithdrawalAssetSrcDataAbiItem,[u]),l=d.encodeAbiParameters(a.ComplexWithdrawalDataAbiItem,[{encodedSrcData:c,dstData:{dstAddress:i.asset,dstAmount:i.amount},slippage:s}]);return{supportedAsset:t,withdrawData:l,slippageTolerance:s}},ie=({chainId:t,txHash:e,error:n})=>{if(t!==E.mainnet.id||!e||!n)return!1;const s=n instanceof Error?n.message:String(n);return/\bNo Result\b/i.test(s)},ce=({chainId:t,action:e,isRabbyWallet:n})=>e==="update_ondo_prices"&&t===E.mainnet.id&&n?a.ONDO_PRICES_RABBY_SETTLE_DELAY:t?a.TRANSACTION_SETTLE_DELAY[t]??0:0,ue=(t,e)=>a.CHAIN_NATIVE_TOKENS[e]?.nativeTokenSymbol===t,de=({nativeTokenBalance:t,tokenDecimals:e,gasPrice:n})=>{const s=new p(n).multipliedBy(a.NATIVE_TOKEN_GAS_RESERVE_UNITS).shiftedBy(-e),r=new p(t).minus(s);return r.gt("0")?r:new p("0")},le=t=>a.STABLE_TOKEN_SYMBOLS.includes(t),pe=t=>{const e=Object.values(t).reduce((n,{type:s})=>(n[s]=n[s]+1,n),{string:0,number:0});if(e.string>10)throw new Error("logger params must contain up to 10 string values");if(e.number>40)throw new Error("logger params must contain up to 40 numeric values");return!0},me=(t,e=150)=>t.length>e?t.substring(0,e):t,J=()=>({...O().stringErrors,...a.TRANSACTION_ERRORS}),ye=()=>[...Object.keys(J()),...Object.keys(a.LIMIT_ORDER_TRANSACTION_ERRORS)],Ae=/^dh\d+$/i,ge=(t,e)=>Ae.test(e)?new RegExp(`\\b${e}\\b`,"i").test(t):t.includes(e.toLowerCase()),R=(t,e)=>{const n=t.toLowerCase();return[...e??ye()].sort((s,r)=>r.length-s.length).find(s=>ge(n,s))},L=t=>J()[t]??a.LIMIT_ORDER_TRANSACTION_ERRORS[t],Ee=/\b0x[0-9a-f]{8}\b/i,he=t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Te=t=>{const{selectorErrors:e}=O(),n=t.match(Ee)?.[0]?.toLowerCase(),s=n?e[n]:void 0;if(s)return{title:s.title,hint:s.hint};const r=Object.values(e).find(o=>new RegExp(`\\b${he(o.signature.split("(")[0]??"")}\\b`).test(t));return r?{title:r.title,hint:r.hint}:void 0},Se=({errorMessage:t,abiErrors:e})=>{if(!t||t.includes("User rejected"))return null;const n=e.find(i=>t.includes(i));if(n){const i=R(n);if(i)return L(i)}const s=R(t);if(s)return L(s);const r=Te(t);if(r)return r;const[o]=t.split(n?".":"Contract").map(i=>i.trim());return{title:"Transaction failed",hint:`${me(o??"")} ${n?`: ${n}`:""}`}},fe=t=>typeof t=="number"&&Number.isFinite(t),_e=t=>typeof t=="bigint"&&t!==BigInt(0),tt=(t,e=a.DEFAULT_PRECISION$1)=>new p(t).shiftedBy(-e).toNumber(),et=t=>!isNaN(parseFloat(t))&&!isNaN(t),nt=({value:t,minimumFractionDigits:e=2,maximumFractionDigits:n=2,compact:s=!1,normalize:r=!1})=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",notation:s?"compact":void 0,minimumFractionDigits:e,maximumFractionDigits:n}).format(r?tt(t):Number(t)),I=t=>et(t)?new p(t).toFixed():"",M=["₀","₁","₂","₃","₄","₅","₆","₇","₈","₉"],st=({value:t,decimals:e=4})=>{const n=new p(t);if(n.isGreaterThan(1)||n.isZero())return I(n.toFixed(e));const r=(/e/i.test(t.toString())?parseFloat(t.toString()).toFixed(a.DEFAULT_PRECISION$1):t.toString()).match(/^0\.(0+)(\d+)$/);if(r){const[,o,i]=r;if(o.length>=e&&o.length<M.length)return`0.0${M[o.length]}${i.slice(0,3)}`}return I(n.toFixed(e))},rt=(t,e=0)=>`${t.toLocaleString("en-US",{maximumFractionDigits:e})}%`,De=t=>t.toString().replace(/\B(?=(\d{3})+(?!\d))/g,","),we=(t,e,n=0)=>{const s=z(+t,e);return rt(s,n)},be=({currency:t,value:e})=>t==="USD"?nt({value:e}):`${a.CURRENCY_SYMBOL_MAP[t]} ${st({value:e,decimals:a.CURRENCY_DECIMALS_MAP[t]})}`,ot=(t,e)=>new p(new p(t).toFixed(e,p.ROUND_DOWN)).toString(),at=(t,e=3,n=2)=>{if(t.length<=5)return t;const s="...";return t.length<=e+n+s.length?t:`${t.slice(0,e)}${s}${t.slice(-n)}`},Re=({balance:t,symbol:e,precision:n,truncateSymbol:s})=>`${ot(t,n)} ${s?at(e):e}`,Ie=t=>{if(!t)return;const e=t.match(/0x[a-fA-F0-9]{64}/);if(!e)return;const n=e[0];return`${n.slice(0,4)}...${n.slice(-3)}`},Ne=t=>m(a.FLATMONEY_EARLY_DEPOSITOR_VAULT_ADDRESS_BASE,t)||m(a.FLATMONEY_DHT_STAKING_VAULT_ADDRESS_BASE,t),Oe=t=>a.FLAT_MONEY_LEVERAGED_ASSET_ADDRESSES.some(e=>m(e,t)),Ce=t=>a.FLAT_MONEY_COLLATERAL_MAP[t.toLowerCase()]??{symbol:"",decimals:18,address:a.AddressZero},Pe=t=>m(t,a.FLAT_MONEY_V1_UNIT_ADDRESS)?a.FLAT_MONEY_V1_UNIT_LINK:a.FLAT_MONEY_UNIT_LINK,it=t=>`eth_${t}`,xe=({action:t,log:e,symbol:n,vaultAddress:s,chainId:r})=>{const o={[a.TRADING_LOG_EVENT_PARAM.SYMBOL.NAME]:n,[a.TRADING_LOG_EVENT_PARAM.CHAIN_ID.NAME]:r,[a.TRADING_LOG_EVENT_PARAM.ADDRESS.NAME]:it(s)};a.LOG_EVENT_BY_TRANSACTION_ACTION_MAP[t].forEach(i=>{e?.(i,o)})},Be=t=>a.GMX_MARKET_ASSETS.some(e=>m(e,t)),Le=t=>a.GMX_WITHDRAW_ASSET_MAP[t.toLowerCase()]??{symbol:"",decimals:18,address:a.AddressZero},Me=t=>a.GMX_WITHDRAW_ASSET_MAP_BY_VAULT_ADDRESS[t.toLowerCase()],ct="0x3333333333333333333333333333333333333333";E.arbitrum.id+"",a.USDC_ARBITRUM.address,E.base.id+"",a.USDC_BASE.address,E.optimism.id+"",a.USDC_OPTIMISM.address,E.polygon.id+"",a.USDC_POLYGON.address,E.mainnet.id+"",a.USDC_MAINNET.address,E.hyperEvm.id+"",a.USDC_HYPEREVM.address;const Ue="0x2222222222222222222222222222222222222222",U=BigInt("0x2000000000000000000000000000000000000000"),ve=10000n,ut=t=>m(t,ct),dt=t=>{if(m(t,Ue))return!0;try{const e=BigInt(t);return e>=U&&e<U+ve}catch{return!1}},Fe=t=>ut(t)||dt(t),$e=()=>a.USDC_HYPEREVM,Ge=new Map,P=(t,e)=>!e||e.size===0?t:t.map(n=>{const s=e.get(n.supportedAsset.toLowerCase());return s?{...n,withdrawData:s.withdrawData,slippageTolerance:s.slippageTolerance}:n}),lt=t=>{const e=t.find(({swapQuotes:n})=>n);return e?.swapQuotes?Object.values(e.swapQuotes)[0]?.map(({routerKey:n})=>n)??[]:[]},pt=(t,e,n)=>t.map(({asset:s,swapParams:r,swapQuotes:o})=>!r||!o?{supportedAsset:s,withdrawData:"",slippageTolerance:n}:Q({assetAddress:s,swapQuotes:o,swapParams:r,slippageToleranceForContractTransaction:n,routerKey:e})),mt=async(t,e,n,s,r,o)=>{for(const i of t){const u=P(pt(e,i,n),o),{error:c}=await s(...r,u);if(!c)return u}return null},We=(t,e,n)=>{const s=(t??[]).map(r=>({supportedAsset:r,withdrawData:"",slippageTolerance:e}));return P(s,n)},He=async(t,e,n,s,r)=>{for(const o of t){const i=C(o);try{const u=await e(o),c=lt(u),l=await mt(c,u,i,n,s,r);if(l)return console.debug(`[Init Withdraw] Auto slippage simulation succeeded: slippage=${o}%`),console.debug("[Init Withdraw] Complex asset data:",l),l}catch(u){console.error(`[Init Withdraw] Failed to fetch quotes for slippage=${o}%:`,u)}}return null},Ye=async(t,e,{fetchAaveSwapParams:n,fetchAaveSwapQuotes:s,withdrawAmountD18:r,slippage:o})=>Promise.all((t??[]).map(async i=>{if(!m(i,e))return{asset:i};try{const c=await n({withdrawAmountD18:r,slippage:o});if(c?.srcData.length){const l=await s({swapParams:c,slippage:o});return{asset:i,swapParams:c,swapQuotes:l}}return{asset:i}}catch(c){return console.error(c),{asset:i}}})),v=t=>Math.round(t*100)/100,Ve=({maxSlippage:t,candidates:e=a.SLIPPAGE_AUTO_SIMULATION_CANDIDATES})=>{if(!Number.isFinite(t)||t<=0)return[];const n=v(Math.min(t,100)),s=e.filter(o=>o>0&&o<=n).map(v),r=new Set(s);return r.add(n),r.add(t),Array.from(r).sort((o,i)=>o-i)},x=1000000000000000000n,qe=1000000n,F=10000n,$=100n,ke=t=>({quotes:t.quotes.map(e=>({chainId:y(e.chainId,"chainId"),attestationId:y(e.attestationId,"attestationId"),userId:f(e.userId),asset:e.asset,price:y(e.price,"price"),quantity:y(e.quantity,"quantity"),expiration:y(e.expiration,"expiration"),side:Number(e.side),additionalData:f(e.additionalData)})),signatures:t.signatures.map(f)}),yt=(t,e)=>t*e/x,At=x,Ke=(t,e)=>!!e&&yt(t,e)<At,gt=(t,e,n)=>{const s=BigInt(Math.max(0,Math.round(n*100))),r=s>$?$:s,o=F-r,u=yt(t,e)*o*qe,c=F*x;return(u+c-1n)/c},Et=(t,e)=>({chainId:e,attestationId:y(t.attestationId,"attestationId"),userId:b(t.userId),asset:t.assetAddress,price:y(t.price,"price"),quantity:y(t.tokenAmount,"tokenAmount"),expiration:y(t.expiration,"expiration"),side:Number(t.side),additionalData:b(t.additionalData)}),je=({attestation:t,chainId:e,slippagePercent:n})=>{const s=Et(t,e);return d.encodeAbiParameters(Rt,[{attestationSignature:j(t.signature),quote:s,amountOutMinimum:gt(s.quantity,s.price,n)}])},Xe=t=>[...t.reduce((n,s)=>n.has(s.accountId)?n:n.set(s.accountId,s),new Map).values()].map(({accountId:n,marketId:s})=>({accountId:n,marketId:s,collaterals:t.filter(r=>r.accountId===n&&!r.isDebt),debt:t.find(r=>r.accountId===n&&r.isDebt)})),Ze=({collateral:t,dytmOffice:e,processor:n,gmToken:s,ondoGMSwap:r,usdc:o,gmAmount:i,amountOutMinimum:u,signature:c,quote:l})=>[{to:e,data:d.encodeFunctionData({abi:N,functionName:"withdraw",args:[{account:t.accountId,tokenId:t.tokenId,receiver:n,assets:0n,shares:d.maxUint256,extraData:"0x"}]})},{to:s,data:d.encodeFunctionData({abi:d.erc20Abi,functionName:"approve",args:[r,i]})},{to:r,data:d.encodeFunctionData({abi:Ot,functionName:"swapExactInWithAttestation",args:[s,i,o,u,c,l]})}],ze=({collateral:t,dytmOffice:e,processor:n})=>({to:e,data:d.encodeFunctionData({abi:N,functionName:"withdraw",args:[{account:t.accountId,tokenId:t.tokenId,receiver:n,assets:0n,shares:d.maxUint256,extraData:"0x"}]})}),Qe=({accountId:t,debtKey:e,dytmOffice:n,usdc:s})=>[{to:s,data:d.encodeFunctionData({abi:d.erc20Abi,functionName:"approve",args:[n,d.maxUint256]})},{to:n,data:d.encodeFunctionData({abi:N,functionName:"repay",args:[{account:t,key:e,withCollateralType:0,assets:d.maxUint256,shares:0n,extraData:"0x"}]})}],Je=({actions:t,outputAsset:e,minOutputAmount:n})=>d.encodeAbiParameters(Ct,[{actions:t,outputAsset:e,minOutputAmount:n}]),G=new Set,tn=t=>{const e=t?.message;!e||G.has(e)||(G.add(e),console.warn(e))};exports.DytmOfficeAssetGuardAbi=Nt;exports.EMPTY_PER_ASSET_WITHDRAW_DATA=Ge;exports.HYPERLIQUID_PERPS_ACCOUNT_ADDRESS=ct;exports.MIN_GM_UNWIND_VALUE_USD=At;exports.OndoGMTokenAssetGuardAbi=bt;exports.THIRD_PARTY_CONTRACT_ERRORS=D;exports.addTokenToWallet=Kt;exports.applyContractErrorRegistry=k;exports.base64ToHex=j;exports.buildAaveWithdrawAssetTransactionData=Q;exports.buildComplexAssetDataForRouter=pt;exports.buildDytmActions=Ze;exports.buildDytmOutputAssetWithdrawAction=ze;exports.buildDytmRepayActions=Qe;exports.buildSwapQuoteKeyForAave=Z;exports.buildSwapWithdrawTransactionData=ae;exports.buildZapDepositTransactionArguments=oe;exports.clientSide=wt;exports.commify=De;exports.computeAmountOutMinimumUsdc=gt;exports.createDefaultComplexAssetData=We;exports.encodeOndoWithdrawData=je;exports.encodeUnwindPlan=Je;exports.enrichAssetsWithSwapQuotes=Ye;exports.ensureContractErrorRegistryLoaded=Vt;exports.ensureHexPrefix=f;exports.extractAvailableRouterKeys=lt;exports.fetchContractErrorRegistry=K;exports.fetchRequest=H;exports.formatBalance=ot;exports.formatByCurrency=be;exports.formatNumberToLimitedDecimals=st;exports.formatNumeratorToPercentage=we;exports.formatPercentage=rt;exports.formatToUsd=nt;exports.formatTokenBalance=Re;exports.getAutoSlippageSimulationCandidates=Ve;exports.getComplexAssetDataSlippageTolerance=re;exports.getContractAbiById=Xt;exports.getContractAddressById=X;exports.getContractErrorRegistry=O;exports.getConventionalTokenPriceDecimals=Jt;exports.getErrorKey=R;exports.getFlatMoneyCollateralByLeverageAddress=Ce;exports.getFlatMoneyLinkByUnitAddress=Pe;exports.getGmxWithdrawAssetByLeverageAddress=Le;exports.getGmxWithdrawAssetByVaultAddress=Me;exports.getHyperliquidWithdrawAsset=$e;exports.getNativeTokenInvestableBalance=de;exports.getPercent=z;exports.getPoolFraction=ne;exports.getSettleDelay=ce;exports.getSlippageToleranceForContractTransaction=C;exports.getTxHashShort=Ie;exports.groupPreviewByAccount=Xe;exports.isAaveLendAndBorrowAsset=zt;exports.isEqualAddress=m;exports.isFlatMoneyLeveragedAsset=Oe;exports.isFmpAirdropVaultAddress=Ne;exports.isGmxLeveragedAsset=Be;exports.isHyperliquidCorePositionAsset=Fe;exports.isHyperliquidPerpsAsset=ut;exports.isHyperliquidSpotSystemAsset=dt;exports.isNativeToken=ue;exports.isNumberType=fe;exports.isNumeric=et;exports.isPositiveNumber=ee;exports.isStableSymbol=le;exports.isUnswappableGmDust=Ke;exports.isZeroAddress=jt;exports.logContractErrorOnce=tn;exports.logTransactionByActionType=xe;exports.mapAttestationToOndoQuote=Et;exports.mapOndoApiResponseToUpdatePricesArgs=ke;exports.nonZeroBigInt=_e;exports.normalizeNumber=tt;exports.overlayWithdrawData=P;exports.parseAmountToD18=se;exports.parseContractErrorMessage=Se;exports.parseFetchErrorBody=Tt;exports.removeInsignificantTrailingZeros=I;exports.shiftBy=te;exports.shortenAddress=Zt;exports.shouldSwallowMainnetPollError=ie;exports.sliceByIndex=Qt;exports.toBigInt=y;exports.toBytes32Hex=b;exports.transformAddressForAnalytics=it;exports.truncateString=at;exports.tryEstimateWithRouters=mt;exports.tryEstimateWithSlippageValues=He;exports.validateLoggerEventParams=pe;
@@ -1,6 +1,7 @@
1
1
  export declare const getPercent: (numerator: number, denominator: number) => number;
2
2
  export declare const getConventionalTokenPriceDecimals: (tokenPrice: number) => number;
3
3
  export declare const shiftBy: (value: bigint | string | number, n?: number) => string;
4
+ export declare const isPositiveNumber: (value?: string | null) => boolean;
4
5
  export declare const getPoolFraction: (poolTotalValue: string, amountToSell: string, poolTotalSupply: string, precision?: number) => number;
5
6
  /**
6
7
  * Parses a string amount to a bigint with 18 decimals precision (D18)