@dhedge/trading-widget 6.0.4 → 6.0.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 { mainnet as D, hyperEvm as U, polygon as F, optimism as W, base as $, arbitrum as v } from "wagmi/chains";
2
- import { ao as Y, am as G, an as V, a as y, q as E, ap as H, aq as q, a4 as K, ai as k, a3 as z, b as Z, ab as Q, ah as X, ag as j, Z as J, ar as B, e as tt, d as et, M as st, R as at, P as nt, as as ot, at as rt, Q as it, N as ct, ae as _, _ as ut, W as dt, X as lt, U as At, au as M, av as mt, aw as pt, ax as Tt, ay as gt, az as _t, o as St, aa as Dt } from "./gmx-CzVsBV3W.js";
2
+ import { ao as Y, am as V, an as G, a as y, q as E, ap as H, aq as q, a4 as K, ai as k, a3 as z, b as Z, ab as Q, ah as X, ag as j, Z as J, ar as B, e as tt, d as et, M as st, R as at, P as nt, as as ot, at as rt, Q as it, N as ct, ae as S, _ as ut, W as dt, X as lt, U as At, au as M, av as mt, aw as pt, ax as Tt, ay as gt, az as St, o as _t, aa as Dt } from "./gmx-DQ-wSifY.js";
3
3
  import u from "bignumber.js";
4
- import { stringToHex as f, encodeAbiParameters as S, bytesToHex as yt, zeroHash as Et, pad as ft } from "viem";
4
+ import { stringToHex as f, encodeAbiParameters as _, bytesToHex as yt, zeroHash as Et, pad as ft } from "viem";
5
5
  const Xt = typeof window < "u", jt = [
6
6
  {
7
7
  inputs: [
@@ -40,12 +40,12 @@ const Xt = typeof window < "u", jt = [
40
40
  ]
41
41
  }
42
42
  ], wt = () => typeof window < "u";
43
- function It() {
43
+ function ht() {
44
44
  return wt() && typeof window.ethereum < "u";
45
45
  }
46
46
  async function Jt(t) {
47
47
  try {
48
- if (It())
48
+ if (ht())
49
49
  return window.ethereum.request({
50
50
  method: "wallet_watchAsset",
51
51
  params: {
@@ -58,14 +58,14 @@ async function Jt(t) {
58
58
  }
59
59
  return !1;
60
60
  }
61
- const A = (t, e) => t?.toLowerCase() === e?.toLowerCase(), te = (t) => A(t, Y), ht = (t, e) => V[e]?.[t] ?? y, ee = (t) => G[t], se = (t) => t && `${t.substring(0, 6)}...${t.substring(
61
+ const A = (t, e) => t?.toLowerCase() === e?.toLowerCase(), te = (t) => A(t, Y), It = (t, e) => G[e]?.[t] ?? y, ee = (t) => V[t], se = (t) => t && `${t.substring(0, 6)}...${t.substring(
62
62
  t.length - 4,
63
63
  t.length
64
64
  )}`, ae = ({
65
65
  address: t,
66
66
  chainId: e
67
67
  }) => {
68
- const s = ht(
68
+ const s = It(
69
69
  "aaveLendingPoolV3",
70
70
  e
71
71
  );
@@ -76,9 +76,9 @@ const A = (t, e) => t?.toLowerCase() === e?.toLowerCase(), te = (t) => A(t, Y),
76
76
  }) => `${t}_${e}`, ne = (t, e) => {
77
77
  const s = t.slice(0, e), a = t.slice(e);
78
78
  return { firstPart: s, secondPart: a };
79
- }, bt = (t, e) => t / e * 100, oe = (t) => t < 1 ? 4 : t < 10 ? 3 : 2, re = (t, e = E) => new u(t.toString()).shiftedBy(e).toFixed(0), ie = (t, e, s, a) => new u(e).dividedBy(s).multipliedBy(t).shiftedBy(-(a || E)).toNumber(), ce = (t) => BigInt(
79
+ }, Rt = (t, e) => t / e * 100, oe = (t) => t < 1 ? 4 : t < 10 ? 3 : 2, re = (t, e = E) => new u(t.toString()).shiftedBy(e).toFixed(0), ie = (t, e, s, a) => new u(e).dividedBy(s).multipliedBy(t).shiftedBy(-(a || E)).toNumber(), ce = (t) => BigInt(
80
80
  new u(t || "0").shiftedBy(E).toFixed(0, u.ROUND_DOWN)
81
- ), Rt = (t) => {
81
+ ), bt = (t) => {
82
82
  const e = new u(0.01), s = new u(t), a = !s.isZero() && s.lt(e) ? e : s;
83
83
  return BigInt(a.multipliedBy(100).toFixed(0));
84
84
  }, ue = ({
@@ -123,7 +123,7 @@ const A = (t, e) => t?.toLowerCase() === e?.toLowerCase(), te = (t) => A(t, Y),
123
123
  r.times(1 - a / 100).toFixed(0, u.ROUND_DOWN)
124
124
  ]
125
125
  ];
126
- }, Lt = ({
126
+ }, Ct = ({
127
127
  assetAddress: t,
128
128
  swapQuotes: e,
129
129
  swapParams: s,
@@ -149,10 +149,10 @@ const A = (t, e) => t?.toLowerCase() === e?.toLowerCase(), te = (t) => A(t, Y),
149
149
  txData: g?.rawTransaction.data ?? "0x"
150
150
  }
151
151
  };
152
- }), i = S(
152
+ }), i = _(
153
153
  H,
154
154
  [c]
155
- ), d = S(q, [
155
+ ), d = _(q, [
156
156
  {
157
157
  encodedSrcData: i,
158
158
  dstData: {
@@ -199,10 +199,10 @@ const A = (t, e) => t?.toLowerCase() === e?.toLowerCase(), te = (t) => A(t, Y),
199
199
  if (e.number > 40)
200
200
  throw new Error("logger params must contain up to 40 numeric values");
201
201
  return !0;
202
- }, Ct = (t, e = 150) => t.length > e ? t.substring(0, e) : t, N = (t, e = X) => {
202
+ }, Lt = (t, e = 150) => t.length > e ? t.substring(0, e) : t, N = (t, e = X) => {
203
203
  const s = t.toLowerCase();
204
204
  return e.sort((a, n) => n.length - a.length).find((a) => s.includes(a.toLowerCase()));
205
- }, w = (t) => j[t] ?? J[t], _e = ({
205
+ }, w = (t) => j[t] ?? J[t], Se = ({
206
206
  errorMessage: t,
207
207
  abiErrors: e
208
208
  }) => {
@@ -217,9 +217,9 @@ const A = (t, e) => t?.toLowerCase() === e?.toLowerCase(), te = (t) => A(t, Y),
217
217
  const [n] = t.split(s ? "." : "Contract").map((o) => o.trim());
218
218
  return {
219
219
  title: "Transaction failed",
220
- hint: `${Ct(n ?? "")} ${s ? `: ${s}` : ""}`
220
+ hint: `${Lt(n ?? "")} ${s ? `: ${s}` : ""}`
221
221
  };
222
- }, Se = (t) => typeof t == "number" && Number.isFinite(t), De = (t) => typeof t == "bigint" && t !== BigInt(0), Bt = (t, e = B) => new u(t).shiftedBy(-e).toNumber(), Mt = (t) => !isNaN(parseFloat(t)) && !isNaN(t), Pt = ({
222
+ }, _e = (t) => typeof t == "number" && Number.isFinite(t), De = (t) => typeof t == "bigint" && t !== BigInt(0), Bt = (t, e = B) => new u(t).shiftedBy(-e).toNumber(), Mt = (t) => !isNaN(parseFloat(t)) && !isNaN(t), Pt = ({
223
223
  value: t,
224
224
  minimumFractionDigits: e = 2,
225
225
  maximumFractionDigits: s = 2,
@@ -231,22 +231,22 @@ const A = (t, e) => t?.toLowerCase() === e?.toLowerCase(), te = (t) => A(t, Y),
231
231
  notation: a ? "compact" : void 0,
232
232
  minimumFractionDigits: e,
233
233
  maximumFractionDigits: s
234
- }).format(n ? Bt(t) : Number(t)), I = (t) => Mt(t) ? new u(t).toFixed() : "", h = ["₀", "₁", "₂", "₃", "₄", "₅", "₆", "₇", "₈", "₉"], xt = ({
234
+ }).format(n ? Bt(t) : Number(t)), h = (t) => Mt(t) ? new u(t).toFixed() : "", I = ["₀", "₁", "₂", "₃", "₄", "₅", "₆", "₇", "₈", "₉"], xt = ({
235
235
  value: t,
236
236
  decimals: e = 4
237
237
  }) => {
238
238
  const s = new u(t);
239
239
  if (s.isGreaterThan(1) || s.isZero())
240
- return I(s.toFixed(e));
240
+ return h(s.toFixed(e));
241
241
  const n = (/e/i.test(t.toString()) ? parseFloat(t.toString()).toFixed(B) : t.toString()).match(/^0\.(0+)(\d+)$/);
242
242
  if (n) {
243
243
  const [, o, r] = n;
244
- if (o.length >= e && o.length < h.length)
245
- return `0.0${h[o.length]}${r.slice(0, 3)}`;
244
+ if (o.length >= e && o.length < I.length)
245
+ return `0.0${I[o.length]}${r.slice(0, 3)}`;
246
246
  }
247
- return I(s.toFixed(e));
247
+ return h(s.toFixed(e));
248
248
  }, Ut = (t, e = 0) => `${t.toLocaleString("en-US", { maximumFractionDigits: e })}%`, ye = (t) => t.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), Ee = (t, e, s = 0) => {
249
- const a = bt(+t, e);
249
+ const a = Rt(+t, e);
250
250
  return Ut(a, s);
251
251
  }, fe = ({
252
252
  currency: t,
@@ -274,13 +274,13 @@ const A = (t, e) => t?.toLowerCase() === e?.toLowerCase(), te = (t) => A(t, Y),
274
274
  return;
275
275
  const s = e[0];
276
276
  return `${s.slice(0, 4)}...${s.slice(-3)}`;
277
- }, Ie = (t) => A(ot, t) || A(rt, t), he = (t) => ct.some(
277
+ }, he = (t) => A(ot, t) || A(rt, t), Ie = (t) => ct.some(
278
278
  (e) => A(e, t)
279
279
  ), Oe = (t) => st[t.toLowerCase()] ?? {
280
280
  symbol: "",
281
281
  decimals: 18,
282
282
  address: y
283
- }, be = (t) => A(t, it) ? at : nt, $t = (t) => `eth_${t}`, Re = ({
283
+ }, Re = (t) => A(t, it) ? at : nt, $t = (t) => `eth_${t}`, be = ({
284
284
  action: t,
285
285
  log: e,
286
286
  symbol: s,
@@ -288,19 +288,19 @@ const A = (t, e) => t?.toLowerCase() === e?.toLowerCase(), te = (t) => A(t, Y),
288
288
  chainId: n
289
289
  }) => {
290
290
  const o = {
291
- [_.SYMBOL.NAME]: s,
292
- [_.CHAIN_ID.NAME]: n,
293
- [_.ADDRESS.NAME]: $t(a)
291
+ [S.SYMBOL.NAME]: s,
292
+ [S.CHAIN_ID.NAME]: n,
293
+ [S.ADDRESS.NAME]: $t(a)
294
294
  };
295
295
  ut[t].forEach((r) => {
296
296
  e?.(r, o);
297
297
  });
298
- }, Le = (t) => At.some((e) => A(e, t)), Ce = (t) => dt[t.toLowerCase()] ?? {
298
+ }, Ce = (t) => At.some((e) => A(e, t)), Le = (t) => dt[t.toLowerCase()] ?? {
299
299
  symbol: "",
300
300
  decimals: 18,
301
301
  address: y
302
302
  }, Be = (t) => lt[t.toLowerCase()], vt = "0x3333333333333333333333333333333333333333";
303
- v.id + "", _t.address, $.id + "", gt.address, W.id + "", Tt.address, F.id + "", pt.address, D.id + "", mt.address, U.id + "", M.address;
303
+ v.id + "", St.address, $.id + "", gt.address, W.id + "", Tt.address, F.id + "", pt.address, D.id + "", mt.address, U.id + "", M.address;
304
304
  const Me = (t) => A(t, vt), Pe = () => M, xe = /* @__PURE__ */ new Map(), P = (t, e) => !e || e.size === 0 ? t : t.map((s) => {
305
305
  const a = e.get(
306
306
  s.supportedAsset.toLowerCase()
@@ -309,7 +309,7 @@ const Me = (t) => A(t, vt), Pe = () => M, xe = /* @__PURE__ */ new Map(), P = (t
309
309
  ...s,
310
310
  withdrawData: a,
311
311
  // Ondo assets require a hardcoded increased slippage
312
- slippageTolerance: St
312
+ slippageTolerance: _t
313
313
  } : s;
314
314
  }), Yt = (t) => {
315
315
  const e = t.find(
@@ -318,20 +318,20 @@ const Me = (t) => A(t, vt), Pe = () => M, xe = /* @__PURE__ */ new Map(), P = (t
318
318
  return e?.swapQuotes ? Object.values(e.swapQuotes)[0]?.map(
319
319
  ({ routerKey: s }) => s
320
320
  ) ?? [] : [];
321
- }, Gt = (t, e, s) => t.map(({ asset: a, swapParams: n, swapQuotes: o }) => !n || !o ? {
321
+ }, Vt = (t, e, s) => t.map(({ asset: a, swapParams: n, swapQuotes: o }) => !n || !o ? {
322
322
  supportedAsset: a,
323
323
  withdrawData: "",
324
324
  slippageTolerance: s
325
- } : Lt({
325
+ } : Ct({
326
326
  assetAddress: a,
327
327
  swapQuotes: o,
328
328
  swapParams: n,
329
329
  slippageToleranceForContractTransaction: s,
330
330
  routerKey: e
331
- })), Vt = async (t, e, s, a, n, o) => {
331
+ })), Gt = async (t, e, s, a, n, o) => {
332
332
  for (const r of t) {
333
333
  const c = P(
334
- Gt(
334
+ Vt(
335
335
  e,
336
336
  r,
337
337
  s
@@ -351,11 +351,11 @@ const Me = (t) => A(t, vt), Pe = () => M, xe = /* @__PURE__ */ new Map(), P = (t
351
351
  return P(a, s);
352
352
  }, Fe = async (t, e, s, a, n) => {
353
353
  for (const o of t) {
354
- const r = Rt(o);
354
+ const r = bt(o);
355
355
  try {
356
356
  const c = await e(o), i = Yt(
357
357
  c
358
- ), d = await Vt(
358
+ ), d = await Gt(
359
359
  i,
360
360
  c,
361
361
  r,
@@ -409,7 +409,7 @@ const Me = (t) => A(t, vt), Pe = () => M, xe = /* @__PURE__ */ new Map(), P = (t
409
409
  return [];
410
410
  const s = O(Math.min(t, 100)), a = e.filter((o) => o > 0 && o <= s).map(O), n = new Set(a);
411
411
  return n.add(s), n.add(t), Array.from(n).sort((o, r) => o - r);
412
- }, b = 1000000000000000000n, Ht = 1000000n, R = 10000n, L = 100n, T = (t) => {
412
+ }, R = 1000000000000000000n, Ht = 1000000n, b = 10000n, C = 100n, T = (t) => {
413
413
  if (!t) throw new Error("Ondo: empty hex value");
414
414
  return t.startsWith("0x") ? t : `0x${t}`;
415
415
  }, l = (t, e) => {
@@ -420,7 +420,7 @@ const Me = (t) => A(t, vt), Pe = () => M, xe = /* @__PURE__ */ new Map(), P = (t
420
420
  `Ondo: cannot convert "${e}" value "${t}" to bigint`
421
421
  );
422
422
  }
423
- }, C = (t) => t ? ft(T(t), { size: 32 }) : Et, qt = (t) => {
423
+ }, L = (t) => t ? ft(T(t), { size: 32 }) : Et, qt = (t) => {
424
424
  if (!t) throw new Error("Ondo: empty signature");
425
425
  return yt(Uint8Array.from(atob(t), (e) => e.charCodeAt(0)));
426
426
  }, ve = (t) => ({
@@ -439,7 +439,7 @@ const Me = (t) => A(t, vt), Pe = () => M, xe = /* @__PURE__ */ new Map(), P = (t
439
439
  ),
440
440
  signatures: t.signatures.map(T)
441
441
  }), Kt = (t, e, s) => {
442
- const a = BigInt(Math.max(0, Math.round(s * 100))), n = a > L ? L : a, o = R - n, c = t * e / b * o * Ht, i = R * b;
442
+ const a = BigInt(Math.max(0, Math.round(s * 100))), n = a > C ? C : a, o = b - n, c = t * e / R * o * Ht, i = b * R;
443
443
  return (c + i - 1n) / i;
444
444
  }, Ye = ({
445
445
  attestation: t,
@@ -447,19 +447,19 @@ const Me = (t) => A(t, vt), Pe = () => M, xe = /* @__PURE__ */ new Map(), P = (t
447
447
  slippagePercent: s
448
448
  }) => {
449
449
  const a = l(t.tokenAmount, "tokenAmount"), n = l(t.price, "price");
450
- return S(Nt, [
450
+ return _(Nt, [
451
451
  {
452
452
  attestationSignature: qt(t.signature),
453
453
  quote: {
454
454
  chainId: e,
455
455
  attestationId: l(t.attestationId, "attestationId"),
456
- userId: C(t.userId),
456
+ userId: L(t.userId),
457
457
  asset: t.assetAddress,
458
458
  price: n,
459
459
  quantity: a,
460
460
  expiration: l(t.expiration, "expiration"),
461
461
  side: Number(t.side),
462
- additionalData: C(t.additionalData)
462
+ additionalData: L(t.additionalData)
463
463
  },
464
464
  amountOutMinimum: Kt(
465
465
  a,
@@ -471,35 +471,35 @@ const Me = (t) => A(t, vt), Pe = () => M, xe = /* @__PURE__ */ new Map(), P = (t
471
471
  };
472
472
  export {
473
473
  te as $,
474
- bt as A,
474
+ Rt as A,
475
475
  ie as B,
476
476
  Ae as C,
477
- Rt as D,
477
+ bt as D,
478
478
  xe as E,
479
479
  we as F,
480
480
  ae as G,
481
- he as H,
482
- Ie as I,
483
- Le as J,
481
+ Ie as H,
482
+ he as I,
483
+ Ce as J,
484
484
  Me as K,
485
485
  me as L,
486
486
  Te as M,
487
- Re as N,
487
+ be as N,
488
488
  ve as O,
489
489
  P,
490
490
  ce as Q,
491
- _e as R,
491
+ Se as R,
492
492
  re as S,
493
493
  se as T,
494
494
  le as U,
495
495
  ne as V,
496
496
  $t as W,
497
497
  Wt as X,
498
- Vt as Y,
498
+ Gt as Y,
499
499
  Fe as Z,
500
500
  ge as _,
501
- Lt as a,
502
- Se as a0,
501
+ Ct as a,
502
+ _e as a0,
503
503
  A as a1,
504
504
  Pt as a2,
505
505
  De as a3,
@@ -511,9 +511,9 @@ export {
511
511
  Ut as a9,
512
512
  Mt as aa,
513
513
  ye as ab,
514
- I as ac,
514
+ h as ac,
515
515
  qt as b,
516
- Gt as c,
516
+ Vt as c,
517
517
  Ot as d,
518
518
  de as e,
519
519
  ue as f,
@@ -528,12 +528,12 @@ export {
528
528
  Ne as o,
529
529
  $e as p,
530
530
  ee as q,
531
- ht as r,
531
+ It as r,
532
532
  oe as s,
533
533
  N as t,
534
534
  Oe as u,
535
- be as v,
536
- Ce as w,
535
+ Re as v,
536
+ Le as w,
537
537
  Be as x,
538
538
  Pe as y,
539
539
  pe as z
@@ -1 +1 @@
1
- "use strict";const T=require("wagmi/chains"),r=require("./gmx-DT_j1_Y4.cjs"),u=require("bignumber.js"),p=require("viem"),Q=typeof window<"u",z=[{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"}],j=[{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"}]}],X=()=>typeof window<"u";function J(){return X()&&typeof window.ethereum<"u"}async function tt(t){try{if(J())return window.ethereum.request({method:"wallet_watchAsset",params:{type:"ERC20",options:t}})}catch{return!1}return!1}const A=(t,e)=>t?.toLowerCase()===e?.toLowerCase(),et=t=>A(t,r.AddressZero$1),O=(t,e)=>r.contractsAddressesMap[e]?.[t]??r.AddressZero,nt=t=>r.contractsAbisMap[t],st=t=>t&&`${t.substring(0,6)}...${t.substring(t.length-4,t.length)}`,rt=({address:t,chainId:e})=>{const n=O("aaveLendingPoolV3",e);return A(t,n)},L=({sourceAddress:t,amount:e})=>`${t}_${e}`,ot=(t,e)=>{const n=t.slice(0,e),s=t.slice(e);return{firstPart:n,secondPart:s}},B=(t,e)=>t/e*100,at=t=>t<1?4:t<10?3:2,it=(t,e=r.DEFAULT_PRECISION)=>new u(t.toString()).shiftedBy(e).toFixed(0),ct=(t,e,n,s)=>new u(e).dividedBy(n).multipliedBy(t).shiftedBy(-(s||r.DEFAULT_PRECISION)).toNumber(),dt=t=>BigInt(new u(t||"0").shiftedBy(r.DEFAULT_PRECISION).toFixed(0,u.ROUND_DOWN)),P=t=>{const e=new u(.01),n=new u(t),s=!n.isZero()&&n.lt(e)?e:n;return BigInt(s.multipliedBy(100).toFixed(0))},ut=({vaultAddress:t,swapData:e,sendTokenAddress:n,sendTokenAmount:s,vaultDepositTokenAddress:o,minVaultTokensReceivedAmount:a,routerKey:i="ONE_INCH",swapDestinationAmount:d,swapSlippage:c})=>{const l=new u(d).multipliedBy(1-c/100).toFixed(0),g=[p.stringToHex(i,{size:32}),e];return[t,[[n,s,g],[o,l]],a]},lt=({receiveAssetAddress:t,assets:e,swapData:n,slippage:s})=>{const o={srcData:[],destAmount:new u("0")},{srcData:a,destAmount:i}=e?.reduce((d,c)=>{const l=n?.[c.address];if(!l)return d;const g=[p.stringToHex(l.routerKey,{size:32}),l.rawTransaction.data],S=[c.address,c.rawBalance,g];return{srcData:[...d.srcData,S],destAmount:d.destAmount.plus(l.destinationAmount)}},o)??o;return[a,[t,i.times(1-s/100).toFixed(0,u.ROUND_DOWN)]]},M=({assetAddress:t,swapQuotes:e,swapParams:n,slippageToleranceForContractTransaction:s,routerKey:o})=>{if(!n)return{supportedAsset:t,withdrawData:"",slippageTolerance:BigInt(0)};const{srcData:a,dstData:i}=n,d=a.map(({asset:g,amount:S})=>{const D=e?.[L({sourceAddress:g,amount:S.toString()})]?.find(Z=>Z.routerKey===o);return{asset:g,amount:S,swapData:{routerKey:p.stringToHex(D?.routerKey??"",{size:32}),txData:D?.rawTransaction.data??"0x"}}}),c=p.encodeAbiParameters(r.ComplexWithdrawalAssetSrcDataAbiItem,[d]),l=p.encodeAbiParameters(r.ComplexWithdrawalDataAbiItem,[{encodedSrcData:c,dstData:{dstAddress:i.asset,dstAmount:i.amount},slippage:s}]);return{supportedAsset:t,withdrawData:l,slippageTolerance:s}},At=({chainId:t,txHash:e,error:n})=>{if(t!==T.mainnet.id||!e||!n)return!1;const s=n instanceof Error?n.message:String(n);return/\bNo Result\b/i.test(s)},mt=({chainId:t,action:e,isRabbyWallet:n})=>e==="update_ondo_prices"&&t===T.mainnet.id&&n?r.ONDO_PRICES_RABBY_SETTLE_DELAY:t?r.TRANSACTION_SETTLE_DELAY[t]??0:0,pt=(t,e)=>r.CHAIN_NATIVE_TOKENS[e]?.nativeTokenSymbol===t,Tt=({nativeTokenBalance:t,tokenDecimals:e,gasPrice:n})=>{const s=new u(n).multipliedBy(r.NATIVE_TOKEN_DEPOSIT_GAS_LIMIT).shiftedBy(-e),o=new u(t).minus(s);return o.gt("0")?o:new u("0")},gt=t=>r.STABLE_TOKEN_SYMBOLS.includes(t),St=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},yt=(t,e=150)=>t.length>e?t.substring(0,e):t,_=(t,e=r.TRANSACTION_ERROR_KEYS)=>{const n=t.toLowerCase();return e.sort((s,o)=>o.length-s.length).find(s=>n.includes(s.toLowerCase()))},N=t=>r.TRANSACTION_ERRORS[t]??r.LIMIT_ORDER_TRANSACTION_ERRORS[t],Dt=({errorMessage:t,abiErrors:e})=>{if(!t||t.includes("User rejected"))return null;const n=e.find(a=>t.includes(a));if(n&&_(n))return N(n);const s=_(t);if(s)return N(s);const[o]=t.split(n?".":"Contract").map(a=>a.trim());return{title:"Transaction failed",hint:`${yt(o??"")} ${n?`: ${n}`:""}`}},_t=t=>typeof t=="number"&&Number.isFinite(t),Et=t=>typeof t=="bigint"&&t!==BigInt(0),x=(t,e=r.DEFAULT_PRECISION$1)=>new u(t).shiftedBy(-e).toNumber(),F=t=>!isNaN(parseFloat(t))&&!isNaN(t),U=({value:t,minimumFractionDigits:e=2,maximumFractionDigits:n=2,compact:s=!1,normalize:o=!1})=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",notation:s?"compact":void 0,minimumFractionDigits:e,maximumFractionDigits:n}).format(o?x(t):Number(t)),E=t=>F(t)?new u(t).toFixed():"",f=["₀","₁","₂","₃","₄","₅","₆","₇","₈","₉"],v=({value:t,decimals:e=4})=>{const n=new u(t);if(n.isGreaterThan(1)||n.isZero())return E(n.toFixed(e));const o=(/e/i.test(t.toString())?parseFloat(t.toString()).toFixed(r.DEFAULT_PRECISION$1):t.toString()).match(/^0\.(0+)(\d+)$/);if(o){const[,a,i]=o;if(a.length>=e&&a.length<f.length)return`0.0${f[a.length]}${i.slice(0,3)}`}return E(n.toFixed(e))},W=(t,e=0)=>`${t.toLocaleString("en-US",{maximumFractionDigits:e})}%`,It=t=>t.toString().replace(/\B(?=(\d{3})+(?!\d))/g,","),Nt=(t,e,n=0)=>{const s=B(+t,e);return W(s,n)},ft=({currency:t,value:e})=>t==="USD"?U({value:e}):`${r.CURRENCY_SYMBOL_MAP[t]} ${v({value:e,decimals:r.CURRENCY_DECIMALS_MAP[t]})}`,G=(t,e)=>new u(new u(t).toFixed(e,u.ROUND_DOWN)).toString(),$=(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)}`},ht=({balance:t,symbol:e,precision:n,truncateSymbol:s})=>`${G(t,n)} ${s?$(e):e}`,wt=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)}`},Rt=t=>A(r.FLATMONEY_EARLY_DEPOSITOR_VAULT_ADDRESS_BASE,t)||A(r.FLATMONEY_DHT_STAKING_VAULT_ADDRESS_BASE,t),bt=t=>r.FLAT_MONEY_LEVERAGED_ASSET_ADDRESSES.some(e=>A(e,t)),Ct=t=>r.FLAT_MONEY_COLLATERAL_MAP[t.toLowerCase()]??{symbol:"",decimals:18,address:r.AddressZero},Ot=t=>A(t,r.FLAT_MONEY_V1_UNIT_ADDRESS)?r.FLAT_MONEY_V1_UNIT_LINK:r.FLAT_MONEY_UNIT_LINK,H=t=>`eth_${t}`,Lt=({action:t,log:e,symbol:n,vaultAddress:s,chainId:o})=>{const a={[r.TRADING_LOG_EVENT_PARAM.SYMBOL.NAME]:n,[r.TRADING_LOG_EVENT_PARAM.CHAIN_ID.NAME]:o,[r.TRADING_LOG_EVENT_PARAM.ADDRESS.NAME]:H(s)};r.LOG_EVENT_BY_TRANSACTION_ACTION_MAP[t].forEach(i=>{e?.(i,a)})},Bt=t=>r.GMX_MARKET_ASSETS.some(e=>A(e,t)),Pt=t=>r.GMX_WITHDRAW_ASSET_MAP[t.toLowerCase()]??{symbol:"",decimals:18,address:r.AddressZero},Mt=t=>r.GMX_WITHDRAW_ASSET_MAP_BY_VAULT_ADDRESS[t.toLowerCase()],V="0x3333333333333333333333333333333333333333";T.arbitrum.id+"",r.USDC_ARBITRUM.address,T.base.id+"",r.USDC_BASE.address,T.optimism.id+"",r.USDC_OPTIMISM.address,T.polygon.id+"",r.USDC_POLYGON.address,T.mainnet.id+"",r.USDC_MAINNET.address,T.hyperEvm.id+"",r.USDC_HYPEREVM.address;const xt=t=>A(t,V),Ft=()=>r.USDC_HYPEREVM,Ut=new Map,I=(t,e)=>!e||e.size===0?t:t.map(n=>{const s=e.get(n.supportedAsset.toLowerCase());return s?{...n,withdrawData:s,slippageTolerance:r.DEFAULT_ONDO_WITHDRAWAL_CONTRACT_SLIPPAGE}:n}),Y=t=>{const e=t.find(({swapQuotes:n})=>n);return e?.swapQuotes?Object.values(e.swapQuotes)[0]?.map(({routerKey:n})=>n)??[]:[]},q=(t,e,n)=>t.map(({asset:s,swapParams:o,swapQuotes:a})=>!o||!a?{supportedAsset:s,withdrawData:"",slippageTolerance:n}:M({assetAddress:s,swapQuotes:a,swapParams:o,slippageToleranceForContractTransaction:n,routerKey:e})),K=async(t,e,n,s,o,a)=>{for(const i of t){const d=I(q(e,i,n),a),{error:c}=await s(...o,d);if(!c)return d}return null},vt=(t,e,n)=>{const s=(t??[]).map(o=>({supportedAsset:o,withdrawData:"",slippageTolerance:e}));return I(s,n)},Wt=async(t,e,n,s,o)=>{for(const a of t){const i=P(a);try{const d=await e(a),c=Y(d),l=await K(c,d,i,n,s,o);if(l)return console.debug(`[Init Withdraw] Auto slippage simulation succeeded: slippage=${a}%`),console.debug("[Init Withdraw] Complex asset data:",l),l}catch(d){console.error(`[Init Withdraw] Failed to fetch quotes for slippage=${a}%:`,d)}}return null},Gt=async(t,e,{fetchAaveSwapParams:n,fetchAaveSwapQuotes:s,withdrawAmountD18:o,slippage:a})=>Promise.all((t??[]).map(async i=>{if(!A(i,e))return{asset:i};try{const c=await n({withdrawAmountD18:o,slippage:a});if(c?.srcData.length){const l=await s({swapParams:c,slippage:a});return{asset:i,swapParams:c,swapQuotes:l}}return{asset:i}}catch(c){return console.error(c),{asset:i}}})),h=t=>Math.round(t*100)/100,$t=({maxSlippage:t,candidates:e=r.SLIPPAGE_AUTO_SIMULATION_CANDIDATES})=>{if(!Number.isFinite(t)||t<=0)return[];const n=h(Math.min(t,100)),s=e.filter(a=>a>0&&a<=n).map(h),o=new Set(s);return o.add(n),o.add(t),Array.from(o).sort((a,i)=>a-i)},w=1000000000000000000n,Ht=1000000n,R=10000n,b=100n,y=t=>{if(!t)throw new Error("Ondo: empty hex value");return t.startsWith("0x")?t:`0x${t}`},m=(t,e)=>{try{return BigInt(t)}catch{throw new Error(`Ondo: cannot convert "${e}" value "${t}" to bigint`)}},C=t=>t?p.pad(y(t),{size:32}):p.zeroHash,k=t=>{if(!t)throw new Error("Ondo: empty signature");return p.bytesToHex(Uint8Array.from(atob(t),e=>e.charCodeAt(0)))},Vt=t=>({quotes:t.quotes.map(e=>({chainId:m(e.chainId,"chainId"),attestationId:m(e.attestationId,"attestationId"),userId:y(e.userId),asset:e.asset,price:m(e.price,"price"),quantity:m(e.quantity,"quantity"),expiration:m(e.expiration,"expiration"),side:Number(e.side),additionalData:y(e.additionalData)})),signatures:t.signatures.map(y)}),Yt=(t,e,n)=>{const s=BigInt(Math.max(0,Math.round(n*100))),o=s>b?b:s,a=R-o,d=t*e/w*a*Ht,c=R*w;return(d+c-1n)/c},qt=({attestation:t,chainId:e,slippagePercent:n})=>{const s=m(t.tokenAmount,"tokenAmount"),o=m(t.price,"price");return p.encodeAbiParameters(j,[{attestationSignature:k(t.signature),quote:{chainId:e,attestationId:m(t.attestationId,"attestationId"),userId:C(t.userId),asset:t.assetAddress,price:o,quantity:s,expiration:m(t.expiration,"expiration"),side:Number(t.side),additionalData:C(t.additionalData)},amountOutMinimum:Yt(s,o,n)}])};exports.EMPTY_PER_ASSET_WITHDRAW_DATA=Ut;exports.HYPERLIQUID_PERPS_ACCOUNT_ADDRESS=V;exports.OndoGMTokenAssetGuardAbi=z;exports.addTokenToWallet=tt;exports.base64SignatureToHex=k;exports.buildAaveWithdrawAssetTransactionData=M;exports.buildComplexAssetDataForRouter=q;exports.buildSwapQuoteKeyForAave=L;exports.buildSwapWithdrawTransactionData=lt;exports.buildZapDepositTransactionArguments=ut;exports.clientSide=Q;exports.commify=It;exports.createDefaultComplexAssetData=vt;exports.encodeOndoWithdrawData=qt;exports.enrichAssetsWithSwapQuotes=Gt;exports.extractAvailableRouterKeys=Y;exports.formatBalance=G;exports.formatByCurrency=ft;exports.formatNumberToLimitedDecimals=v;exports.formatNumeratorToPercentage=Nt;exports.formatPercentage=W;exports.formatToUsd=U;exports.formatTokenBalance=ht;exports.getAutoSlippageSimulationCandidates=$t;exports.getContractAbiById=nt;exports.getContractAddressById=O;exports.getConventionalTokenPriceDecimals=at;exports.getErrorKey=_;exports.getFlatMoneyCollateralByLeverageAddress=Ct;exports.getFlatMoneyLinkByUnitAddress=Ot;exports.getGmxWithdrawAssetByLeverageAddress=Pt;exports.getGmxWithdrawAssetByVaultAddress=Mt;exports.getHyperliquidWithdrawAsset=Ft;exports.getNativeTokenInvestableBalance=Tt;exports.getPercent=B;exports.getPoolFraction=ct;exports.getSettleDelay=mt;exports.getSlippageToleranceForContractTransaction=P;exports.getTxHashShort=wt;exports.isAaveLendAndBorrowAsset=rt;exports.isEqualAddress=A;exports.isFlatMoneyLeveragedAsset=bt;exports.isFmpAirdropVaultAddress=Rt;exports.isGmxLeveragedAsset=Bt;exports.isHyperliquidPerpsAsset=xt;exports.isNativeToken=pt;exports.isNumberType=_t;exports.isNumeric=F;exports.isStableSymbol=gt;exports.isZeroAddress=et;exports.logTransactionByActionType=Lt;exports.mapOndoApiResponseToUpdatePricesArgs=Vt;exports.nonZeroBigInt=Et;exports.normalizeNumber=x;exports.overlayWithdrawData=I;exports.parseAmountToD18=dt;exports.parseContractErrorMessage=Dt;exports.removeInsignificantTrailingZeros=E;exports.shiftBy=it;exports.shortenAddress=st;exports.shouldSwallowMainnetPollError=At;exports.sliceByIndex=ot;exports.transformAddressForAnalytics=H;exports.truncateString=$;exports.tryEstimateWithRouters=K;exports.tryEstimateWithSlippageValues=Wt;exports.validateLoggerEventParams=St;
1
+ "use strict";const g=require("wagmi/chains"),r=require("./gmx-Dejxb5_t.cjs"),u=require("bignumber.js"),p=require("viem"),Q=typeof window<"u",z=[{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"}],j=[{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"}]}],X=()=>typeof window<"u";function J(){return X()&&typeof window.ethereum<"u"}async function tt(t){try{if(J())return window.ethereum.request({method:"wallet_watchAsset",params:{type:"ERC20",options:t}})}catch{return!1}return!1}const A=(t,e)=>t?.toLowerCase()===e?.toLowerCase(),et=t=>A(t,r.AddressZero$1),O=(t,e)=>r.contractsAddressesMap[e]?.[t]??r.AddressZero,nt=t=>r.contractsAbisMap[t],st=t=>t&&`${t.substring(0,6)}...${t.substring(t.length-4,t.length)}`,rt=({address:t,chainId:e})=>{const n=O("aaveLendingPoolV3",e);return A(t,n)},L=({sourceAddress:t,amount:e})=>`${t}_${e}`,ot=(t,e)=>{const n=t.slice(0,e),s=t.slice(e);return{firstPart:n,secondPart:s}},B=(t,e)=>t/e*100,at=t=>t<1?4:t<10?3:2,it=(t,e=r.DEFAULT_PRECISION)=>new u(t.toString()).shiftedBy(e).toFixed(0),ct=(t,e,n,s)=>new u(e).dividedBy(n).multipliedBy(t).shiftedBy(-(s||r.DEFAULT_PRECISION)).toNumber(),dt=t=>BigInt(new u(t||"0").shiftedBy(r.DEFAULT_PRECISION).toFixed(0,u.ROUND_DOWN)),P=t=>{const e=new u(.01),n=new u(t),s=!n.isZero()&&n.lt(e)?e:n;return BigInt(s.multipliedBy(100).toFixed(0))},ut=({vaultAddress:t,swapData:e,sendTokenAddress:n,sendTokenAmount:s,vaultDepositTokenAddress:o,minVaultTokensReceivedAmount:a,routerKey:i="ONE_INCH",swapDestinationAmount:d,swapSlippage:c})=>{const l=new u(d).multipliedBy(1-c/100).toFixed(0),T=[p.stringToHex(i,{size:32}),e];return[t,[[n,s,T],[o,l]],a]},lt=({receiveAssetAddress:t,assets:e,swapData:n,slippage:s})=>{const o={srcData:[],destAmount:new u("0")},{srcData:a,destAmount:i}=e?.reduce((d,c)=>{const l=n?.[c.address];if(!l)return d;const T=[p.stringToHex(l.routerKey,{size:32}),l.rawTransaction.data],S=[c.address,c.rawBalance,T];return{srcData:[...d.srcData,S],destAmount:d.destAmount.plus(l.destinationAmount)}},o)??o;return[a,[t,i.times(1-s/100).toFixed(0,u.ROUND_DOWN)]]},M=({assetAddress:t,swapQuotes:e,swapParams:n,slippageToleranceForContractTransaction:s,routerKey:o})=>{if(!n)return{supportedAsset:t,withdrawData:"",slippageTolerance:BigInt(0)};const{srcData:a,dstData:i}=n,d=a.map(({asset:T,amount:S})=>{const D=e?.[L({sourceAddress:T,amount:S.toString()})]?.find(Z=>Z.routerKey===o);return{asset:T,amount:S,swapData:{routerKey:p.stringToHex(D?.routerKey??"",{size:32}),txData:D?.rawTransaction.data??"0x"}}}),c=p.encodeAbiParameters(r.ComplexWithdrawalAssetSrcDataAbiItem,[d]),l=p.encodeAbiParameters(r.ComplexWithdrawalDataAbiItem,[{encodedSrcData:c,dstData:{dstAddress:i.asset,dstAmount:i.amount},slippage:s}]);return{supportedAsset:t,withdrawData:l,slippageTolerance:s}},At=({chainId:t,txHash:e,error:n})=>{if(t!==g.mainnet.id||!e||!n)return!1;const s=n instanceof Error?n.message:String(n);return/\bNo Result\b/i.test(s)},mt=({chainId:t,action:e,isRabbyWallet:n})=>e==="update_ondo_prices"&&t===g.mainnet.id&&n?r.ONDO_PRICES_RABBY_SETTLE_DELAY:t?r.TRANSACTION_SETTLE_DELAY[t]??0:0,pt=(t,e)=>r.CHAIN_NATIVE_TOKENS[e]?.nativeTokenSymbol===t,gt=({nativeTokenBalance:t,tokenDecimals:e,gasPrice:n})=>{const s=new u(n).multipliedBy(r.NATIVE_TOKEN_GAS_RESERVE_UNITS).shiftedBy(-e),o=new u(t).minus(s);return o.gt("0")?o:new u("0")},Tt=t=>r.STABLE_TOKEN_SYMBOLS.includes(t),St=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},yt=(t,e=150)=>t.length>e?t.substring(0,e):t,_=(t,e=r.TRANSACTION_ERROR_KEYS)=>{const n=t.toLowerCase();return e.sort((s,o)=>o.length-s.length).find(s=>n.includes(s.toLowerCase()))},f=t=>r.TRANSACTION_ERRORS[t]??r.LIMIT_ORDER_TRANSACTION_ERRORS[t],Dt=({errorMessage:t,abiErrors:e})=>{if(!t||t.includes("User rejected"))return null;const n=e.find(a=>t.includes(a));if(n&&_(n))return f(n);const s=_(t);if(s)return f(s);const[o]=t.split(n?".":"Contract").map(a=>a.trim());return{title:"Transaction failed",hint:`${yt(o??"")} ${n?`: ${n}`:""}`}},_t=t=>typeof t=="number"&&Number.isFinite(t),Et=t=>typeof t=="bigint"&&t!==BigInt(0),x=(t,e=r.DEFAULT_PRECISION$1)=>new u(t).shiftedBy(-e).toNumber(),F=t=>!isNaN(parseFloat(t))&&!isNaN(t),U=({value:t,minimumFractionDigits:e=2,maximumFractionDigits:n=2,compact:s=!1,normalize:o=!1})=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",notation:s?"compact":void 0,minimumFractionDigits:e,maximumFractionDigits:n}).format(o?x(t):Number(t)),E=t=>F(t)?new u(t).toFixed():"",h=["₀","₁","₂","₃","₄","₅","₆","₇","₈","₉"],v=({value:t,decimals:e=4})=>{const n=new u(t);if(n.isGreaterThan(1)||n.isZero())return E(n.toFixed(e));const o=(/e/i.test(t.toString())?parseFloat(t.toString()).toFixed(r.DEFAULT_PRECISION$1):t.toString()).match(/^0\.(0+)(\d+)$/);if(o){const[,a,i]=o;if(a.length>=e&&a.length<h.length)return`0.0${h[a.length]}${i.slice(0,3)}`}return E(n.toFixed(e))},W=(t,e=0)=>`${t.toLocaleString("en-US",{maximumFractionDigits:e})}%`,Nt=t=>t.toString().replace(/\B(?=(\d{3})+(?!\d))/g,","),ft=(t,e,n=0)=>{const s=B(+t,e);return W(s,n)},ht=({currency:t,value:e})=>t==="USD"?U({value:e}):`${r.CURRENCY_SYMBOL_MAP[t]} ${v({value:e,decimals:r.CURRENCY_DECIMALS_MAP[t]})}`,G=(t,e)=>new u(new u(t).toFixed(e,u.ROUND_DOWN)).toString(),$=(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)}`},It=({balance:t,symbol:e,precision:n,truncateSymbol:s})=>`${G(t,n)} ${s?$(e):e}`,wt=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)}`},Rt=t=>A(r.FLATMONEY_EARLY_DEPOSITOR_VAULT_ADDRESS_BASE,t)||A(r.FLATMONEY_DHT_STAKING_VAULT_ADDRESS_BASE,t),bt=t=>r.FLAT_MONEY_LEVERAGED_ASSET_ADDRESSES.some(e=>A(e,t)),Ct=t=>r.FLAT_MONEY_COLLATERAL_MAP[t.toLowerCase()]??{symbol:"",decimals:18,address:r.AddressZero},Ot=t=>A(t,r.FLAT_MONEY_V1_UNIT_ADDRESS)?r.FLAT_MONEY_V1_UNIT_LINK:r.FLAT_MONEY_UNIT_LINK,H=t=>`eth_${t}`,Lt=({action:t,log:e,symbol:n,vaultAddress:s,chainId:o})=>{const a={[r.TRADING_LOG_EVENT_PARAM.SYMBOL.NAME]:n,[r.TRADING_LOG_EVENT_PARAM.CHAIN_ID.NAME]:o,[r.TRADING_LOG_EVENT_PARAM.ADDRESS.NAME]:H(s)};r.LOG_EVENT_BY_TRANSACTION_ACTION_MAP[t].forEach(i=>{e?.(i,a)})},Bt=t=>r.GMX_MARKET_ASSETS.some(e=>A(e,t)),Pt=t=>r.GMX_WITHDRAW_ASSET_MAP[t.toLowerCase()]??{symbol:"",decimals:18,address:r.AddressZero},Mt=t=>r.GMX_WITHDRAW_ASSET_MAP_BY_VAULT_ADDRESS[t.toLowerCase()],V="0x3333333333333333333333333333333333333333";g.arbitrum.id+"",r.USDC_ARBITRUM.address,g.base.id+"",r.USDC_BASE.address,g.optimism.id+"",r.USDC_OPTIMISM.address,g.polygon.id+"",r.USDC_POLYGON.address,g.mainnet.id+"",r.USDC_MAINNET.address,g.hyperEvm.id+"",r.USDC_HYPEREVM.address;const xt=t=>A(t,V),Ft=()=>r.USDC_HYPEREVM,Ut=new Map,N=(t,e)=>!e||e.size===0?t:t.map(n=>{const s=e.get(n.supportedAsset.toLowerCase());return s?{...n,withdrawData:s,slippageTolerance:r.DEFAULT_ONDO_WITHDRAWAL_CONTRACT_SLIPPAGE}:n}),Y=t=>{const e=t.find(({swapQuotes:n})=>n);return e?.swapQuotes?Object.values(e.swapQuotes)[0]?.map(({routerKey:n})=>n)??[]:[]},q=(t,e,n)=>t.map(({asset:s,swapParams:o,swapQuotes:a})=>!o||!a?{supportedAsset:s,withdrawData:"",slippageTolerance:n}:M({assetAddress:s,swapQuotes:a,swapParams:o,slippageToleranceForContractTransaction:n,routerKey:e})),K=async(t,e,n,s,o,a)=>{for(const i of t){const d=N(q(e,i,n),a),{error:c}=await s(...o,d);if(!c)return d}return null},vt=(t,e,n)=>{const s=(t??[]).map(o=>({supportedAsset:o,withdrawData:"",slippageTolerance:e}));return N(s,n)},Wt=async(t,e,n,s,o)=>{for(const a of t){const i=P(a);try{const d=await e(a),c=Y(d),l=await K(c,d,i,n,s,o);if(l)return console.debug(`[Init Withdraw] Auto slippage simulation succeeded: slippage=${a}%`),console.debug("[Init Withdraw] Complex asset data:",l),l}catch(d){console.error(`[Init Withdraw] Failed to fetch quotes for slippage=${a}%:`,d)}}return null},Gt=async(t,e,{fetchAaveSwapParams:n,fetchAaveSwapQuotes:s,withdrawAmountD18:o,slippage:a})=>Promise.all((t??[]).map(async i=>{if(!A(i,e))return{asset:i};try{const c=await n({withdrawAmountD18:o,slippage:a});if(c?.srcData.length){const l=await s({swapParams:c,slippage:a});return{asset:i,swapParams:c,swapQuotes:l}}return{asset:i}}catch(c){return console.error(c),{asset:i}}})),I=t=>Math.round(t*100)/100,$t=({maxSlippage:t,candidates:e=r.SLIPPAGE_AUTO_SIMULATION_CANDIDATES})=>{if(!Number.isFinite(t)||t<=0)return[];const n=I(Math.min(t,100)),s=e.filter(a=>a>0&&a<=n).map(I),o=new Set(s);return o.add(n),o.add(t),Array.from(o).sort((a,i)=>a-i)},w=1000000000000000000n,Ht=1000000n,R=10000n,b=100n,y=t=>{if(!t)throw new Error("Ondo: empty hex value");return t.startsWith("0x")?t:`0x${t}`},m=(t,e)=>{try{return BigInt(t)}catch{throw new Error(`Ondo: cannot convert "${e}" value "${t}" to bigint`)}},C=t=>t?p.pad(y(t),{size:32}):p.zeroHash,k=t=>{if(!t)throw new Error("Ondo: empty signature");return p.bytesToHex(Uint8Array.from(atob(t),e=>e.charCodeAt(0)))},Vt=t=>({quotes:t.quotes.map(e=>({chainId:m(e.chainId,"chainId"),attestationId:m(e.attestationId,"attestationId"),userId:y(e.userId),asset:e.asset,price:m(e.price,"price"),quantity:m(e.quantity,"quantity"),expiration:m(e.expiration,"expiration"),side:Number(e.side),additionalData:y(e.additionalData)})),signatures:t.signatures.map(y)}),Yt=(t,e,n)=>{const s=BigInt(Math.max(0,Math.round(n*100))),o=s>b?b:s,a=R-o,d=t*e/w*a*Ht,c=R*w;return(d+c-1n)/c},qt=({attestation:t,chainId:e,slippagePercent:n})=>{const s=m(t.tokenAmount,"tokenAmount"),o=m(t.price,"price");return p.encodeAbiParameters(j,[{attestationSignature:k(t.signature),quote:{chainId:e,attestationId:m(t.attestationId,"attestationId"),userId:C(t.userId),asset:t.assetAddress,price:o,quantity:s,expiration:m(t.expiration,"expiration"),side:Number(t.side),additionalData:C(t.additionalData)},amountOutMinimum:Yt(s,o,n)}])};exports.EMPTY_PER_ASSET_WITHDRAW_DATA=Ut;exports.HYPERLIQUID_PERPS_ACCOUNT_ADDRESS=V;exports.OndoGMTokenAssetGuardAbi=z;exports.addTokenToWallet=tt;exports.base64SignatureToHex=k;exports.buildAaveWithdrawAssetTransactionData=M;exports.buildComplexAssetDataForRouter=q;exports.buildSwapQuoteKeyForAave=L;exports.buildSwapWithdrawTransactionData=lt;exports.buildZapDepositTransactionArguments=ut;exports.clientSide=Q;exports.commify=Nt;exports.createDefaultComplexAssetData=vt;exports.encodeOndoWithdrawData=qt;exports.enrichAssetsWithSwapQuotes=Gt;exports.extractAvailableRouterKeys=Y;exports.formatBalance=G;exports.formatByCurrency=ht;exports.formatNumberToLimitedDecimals=v;exports.formatNumeratorToPercentage=ft;exports.formatPercentage=W;exports.formatToUsd=U;exports.formatTokenBalance=It;exports.getAutoSlippageSimulationCandidates=$t;exports.getContractAbiById=nt;exports.getContractAddressById=O;exports.getConventionalTokenPriceDecimals=at;exports.getErrorKey=_;exports.getFlatMoneyCollateralByLeverageAddress=Ct;exports.getFlatMoneyLinkByUnitAddress=Ot;exports.getGmxWithdrawAssetByLeverageAddress=Pt;exports.getGmxWithdrawAssetByVaultAddress=Mt;exports.getHyperliquidWithdrawAsset=Ft;exports.getNativeTokenInvestableBalance=gt;exports.getPercent=B;exports.getPoolFraction=ct;exports.getSettleDelay=mt;exports.getSlippageToleranceForContractTransaction=P;exports.getTxHashShort=wt;exports.isAaveLendAndBorrowAsset=rt;exports.isEqualAddress=A;exports.isFlatMoneyLeveragedAsset=bt;exports.isFmpAirdropVaultAddress=Rt;exports.isGmxLeveragedAsset=Bt;exports.isHyperliquidPerpsAsset=xt;exports.isNativeToken=pt;exports.isNumberType=_t;exports.isNumeric=F;exports.isStableSymbol=Tt;exports.isZeroAddress=et;exports.logTransactionByActionType=Lt;exports.mapOndoApiResponseToUpdatePricesArgs=Vt;exports.nonZeroBigInt=Et;exports.normalizeNumber=x;exports.overlayWithdrawData=N;exports.parseAmountToD18=dt;exports.parseContractErrorMessage=Dt;exports.removeInsignificantTrailingZeros=E;exports.shiftBy=it;exports.shortenAddress=st;exports.shouldSwallowMainnetPollError=At;exports.sliceByIndex=ot;exports.transformAddressForAnalytics=H;exports.truncateString=$;exports.tryEstimateWithRouters=K;exports.tryEstimateWithSlippageValues=Wt;exports.validateLoggerEventParams=St;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhedge/trading-widget",
3
- "version": "6.0.4",
3
+ "version": "6.0.6",
4
4
  "dependencies": {
5
5
  "@headlessui/react": "^2.1.2",
6
6
  "@heroicons/react": "^2.1.5",
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "engines": {
15
15
  "node": ">=24",
16
- "pnpm": ">=9"
16
+ "pnpm": ">=11"
17
17
  },
18
18
  "exports": {
19
19
  ".": {
@@ -45,7 +45,7 @@
45
45
  "@tanstack/react-query": "^5.81.2",
46
46
  "firebase": "^10.0.0 || ^11.0.0 || ^12.0.0",
47
47
  "react": "^18.3.1",
48
- "viem": "^2.44.2",
48
+ "viem": "^2.52.2",
49
49
  "wagmi": "^2.19.5"
50
50
  },
51
51
  "peerDependenciesMeta": {
package/utils.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./ondo-CANFUt4H.cjs"),t=require("viem");exports.EMPTY_PER_ASSET_WITHDRAW_DATA=e.EMPTY_PER_ASSET_WITHDRAW_DATA;exports.base64SignatureToHex=e.base64SignatureToHex;exports.buildAaveWithdrawAssetTransactionData=e.buildAaveWithdrawAssetTransactionData;exports.buildComplexAssetDataForRouter=e.buildComplexAssetDataForRouter;exports.buildSwapQuoteKeyForAave=e.buildSwapQuoteKeyForAave;exports.buildSwapWithdrawTransactionData=e.buildSwapWithdrawTransactionData;exports.buildZapDepositTransactionArguments=e.buildZapDepositTransactionArguments;exports.clientSide=e.clientSide;exports.createDefaultComplexAssetData=e.createDefaultComplexAssetData;exports.encodeOndoWithdrawData=e.encodeOndoWithdrawData;exports.enrichAssetsWithSwapQuotes=e.enrichAssetsWithSwapQuotes;exports.extractAvailableRouterKeys=e.extractAvailableRouterKeys;exports.formatBalance=e.formatBalance;exports.formatByCurrency=e.formatByCurrency;exports.formatNumeratorToPercentage=e.formatNumeratorToPercentage;exports.formatTokenBalance=e.formatTokenBalance;exports.getAutoSlippageSimulationCandidates=e.getAutoSlippageSimulationCandidates;exports.getContractAbiById=e.getContractAbiById;exports.getContractAddressById=e.getContractAddressById;exports.getConventionalTokenPriceDecimals=e.getConventionalTokenPriceDecimals;exports.getErrorKey=e.getErrorKey;exports.getFlatMoneyCollateralByLeverageAddress=e.getFlatMoneyCollateralByLeverageAddress;exports.getFlatMoneyLinkByUnitAddress=e.getFlatMoneyLinkByUnitAddress;exports.getGmxWithdrawAssetByLeverageAddress=e.getGmxWithdrawAssetByLeverageAddress;exports.getGmxWithdrawAssetByVaultAddress=e.getGmxWithdrawAssetByVaultAddress;exports.getHyperliquidWithdrawAsset=e.getHyperliquidWithdrawAsset;exports.getNativeTokenInvestableBalance=e.getNativeTokenInvestableBalance;exports.getPercent=e.getPercent;exports.getPoolFraction=e.getPoolFraction;exports.getSettleDelay=e.getSettleDelay;exports.getSlippageToleranceForContractTransaction=e.getSlippageToleranceForContractTransaction;exports.getTxHashShort=e.getTxHashShort;exports.isAaveLendAndBorrowAsset=e.isAaveLendAndBorrowAsset;exports.isFlatMoneyLeveragedAsset=e.isFlatMoneyLeveragedAsset;exports.isFmpAirdropVaultAddress=e.isFmpAirdropVaultAddress;exports.isGmxLeveragedAsset=e.isGmxLeveragedAsset;exports.isHyperliquidPerpsAsset=e.isHyperliquidPerpsAsset;exports.isNativeToken=e.isNativeToken;exports.isStableSymbol=e.isStableSymbol;exports.logTransactionByActionType=e.logTransactionByActionType;exports.mapOndoApiResponseToUpdatePricesArgs=e.mapOndoApiResponseToUpdatePricesArgs;exports.overlayWithdrawData=e.overlayWithdrawData;exports.parseAmountToD18=e.parseAmountToD18;exports.parseContractErrorMessage=e.parseContractErrorMessage;exports.shiftBy=e.shiftBy;exports.shortenAddress=e.shortenAddress;exports.shouldSwallowMainnetPollError=e.shouldSwallowMainnetPollError;exports.sliceByIndex=e.sliceByIndex;exports.transformAddressForAnalytics=e.transformAddressForAnalytics;exports.truncateString=e.truncateString;exports.tryEstimateWithRouters=e.tryEstimateWithRouters;exports.tryEstimateWithSlippageValues=e.tryEstimateWithSlippageValues;exports.validateLoggerEventParams=e.validateLoggerEventParams;Object.defineProperty(exports,"decodeErrorResult",{enumerable:!0,get:()=>t.decodeErrorResult});Object.defineProperty(exports,"encodeFunctionData",{enumerable:!0,get:()=>t.encodeFunctionData});Object.defineProperty(exports,"formatEther",{enumerable:!0,get:()=>t.formatEther});Object.defineProperty(exports,"formatUnits",{enumerable:!0,get:()=>t.formatUnits});Object.defineProperty(exports,"hexToString",{enumerable:!0,get:()=>t.hexToString});Object.defineProperty(exports,"trim",{enumerable:!0,get:()=>t.trim});
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./ondo-rQybmFLf.cjs"),t=require("viem");exports.EMPTY_PER_ASSET_WITHDRAW_DATA=e.EMPTY_PER_ASSET_WITHDRAW_DATA;exports.base64SignatureToHex=e.base64SignatureToHex;exports.buildAaveWithdrawAssetTransactionData=e.buildAaveWithdrawAssetTransactionData;exports.buildComplexAssetDataForRouter=e.buildComplexAssetDataForRouter;exports.buildSwapQuoteKeyForAave=e.buildSwapQuoteKeyForAave;exports.buildSwapWithdrawTransactionData=e.buildSwapWithdrawTransactionData;exports.buildZapDepositTransactionArguments=e.buildZapDepositTransactionArguments;exports.clientSide=e.clientSide;exports.createDefaultComplexAssetData=e.createDefaultComplexAssetData;exports.encodeOndoWithdrawData=e.encodeOndoWithdrawData;exports.enrichAssetsWithSwapQuotes=e.enrichAssetsWithSwapQuotes;exports.extractAvailableRouterKeys=e.extractAvailableRouterKeys;exports.formatBalance=e.formatBalance;exports.formatByCurrency=e.formatByCurrency;exports.formatNumeratorToPercentage=e.formatNumeratorToPercentage;exports.formatTokenBalance=e.formatTokenBalance;exports.getAutoSlippageSimulationCandidates=e.getAutoSlippageSimulationCandidates;exports.getContractAbiById=e.getContractAbiById;exports.getContractAddressById=e.getContractAddressById;exports.getConventionalTokenPriceDecimals=e.getConventionalTokenPriceDecimals;exports.getErrorKey=e.getErrorKey;exports.getFlatMoneyCollateralByLeverageAddress=e.getFlatMoneyCollateralByLeverageAddress;exports.getFlatMoneyLinkByUnitAddress=e.getFlatMoneyLinkByUnitAddress;exports.getGmxWithdrawAssetByLeverageAddress=e.getGmxWithdrawAssetByLeverageAddress;exports.getGmxWithdrawAssetByVaultAddress=e.getGmxWithdrawAssetByVaultAddress;exports.getHyperliquidWithdrawAsset=e.getHyperliquidWithdrawAsset;exports.getNativeTokenInvestableBalance=e.getNativeTokenInvestableBalance;exports.getPercent=e.getPercent;exports.getPoolFraction=e.getPoolFraction;exports.getSettleDelay=e.getSettleDelay;exports.getSlippageToleranceForContractTransaction=e.getSlippageToleranceForContractTransaction;exports.getTxHashShort=e.getTxHashShort;exports.isAaveLendAndBorrowAsset=e.isAaveLendAndBorrowAsset;exports.isFlatMoneyLeveragedAsset=e.isFlatMoneyLeveragedAsset;exports.isFmpAirdropVaultAddress=e.isFmpAirdropVaultAddress;exports.isGmxLeveragedAsset=e.isGmxLeveragedAsset;exports.isHyperliquidPerpsAsset=e.isHyperliquidPerpsAsset;exports.isNativeToken=e.isNativeToken;exports.isStableSymbol=e.isStableSymbol;exports.logTransactionByActionType=e.logTransactionByActionType;exports.mapOndoApiResponseToUpdatePricesArgs=e.mapOndoApiResponseToUpdatePricesArgs;exports.overlayWithdrawData=e.overlayWithdrawData;exports.parseAmountToD18=e.parseAmountToD18;exports.parseContractErrorMessage=e.parseContractErrorMessage;exports.shiftBy=e.shiftBy;exports.shortenAddress=e.shortenAddress;exports.shouldSwallowMainnetPollError=e.shouldSwallowMainnetPollError;exports.sliceByIndex=e.sliceByIndex;exports.transformAddressForAnalytics=e.transformAddressForAnalytics;exports.truncateString=e.truncateString;exports.tryEstimateWithRouters=e.tryEstimateWithRouters;exports.tryEstimateWithSlippageValues=e.tryEstimateWithSlippageValues;exports.validateLoggerEventParams=e.validateLoggerEventParams;Object.defineProperty(exports,"decodeErrorResult",{enumerable:!0,get:()=>t.decodeErrorResult});Object.defineProperty(exports,"encodeFunctionData",{enumerable:!0,get:()=>t.encodeFunctionData});Object.defineProperty(exports,"formatEther",{enumerable:!0,get:()=>t.formatEther});Object.defineProperty(exports,"formatUnits",{enumerable:!0,get:()=>t.formatUnits});Object.defineProperty(exports,"hexToString",{enumerable:!0,get:()=>t.hexToString});Object.defineProperty(exports,"trim",{enumerable:!0,get:()=>t.trim});
package/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- import { E as s, b as t, a as r, c as o, d as i, e as n, f as d, g as l, h as A, i as g, j as c, k as p, l as u, m, n as y, o as T, p as h, q as S, r as v, s as B, t as D, u as w, v as x, w as W, x as b, y as f, z as E, A as C, B as F, C as P, D as L, F as R, G as M, H as k, I as H, J as I, K as _, L as G, M as K, N, O as U, P as V, Q as q, R as O, S as Q, T as Y, U as Z, V as j, W as z, X as J, Y as X, Z as $, _ as aa } from "./ondo-BVTXZqmD.js";
1
+ import { E as s, b as t, a as r, c as o, d as i, e as n, f as d, g as l, h as A, i as g, j as c, k as p, l as u, m, n as y, o as T, p as h, q as S, r as v, s as B, t as D, u as w, v as x, w as W, x as b, y as f, z as E, A as C, B as F, C as P, D as L, F as R, G as M, H as k, I as H, J as I, K as _, L as G, M as K, N, O as U, P as V, Q as q, R as O, S as Q, T as Y, U as Z, V as j, W as z, X as J, Y as X, Z as $, _ as aa } from "./ondo-GwhTVXds.js";
2
2
  import { decodeErrorResult as sa, encodeFunctionData as ta, formatEther as ra, formatUnits as oa, hexToString as ia, trim as na } from "viem";
3
3
  export {
4
4
  s as EMPTY_PER_ASSET_WITHDRAW_DATA,