@dhedge/trading-widget 6.0.6 → 6.2.0-canary.0

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.
Files changed (88) hide show
  1. package/README.md +136 -125
  2. package/const.cjs +1 -1
  3. package/const.js +96 -89
  4. package/core-kit/abi/dytm-office-asset-guard.d.ts +194 -0
  5. package/core-kit/abi/hyperliquid-withdrawal-manager.d.ts +301 -0
  6. package/core-kit/abi/index.d.ts +2 -0
  7. package/core-kit/abi/ondo-gm-token-asset-guard.d.ts +20 -0
  8. package/core-kit/abi/ondo-price-oracle.d.ts +18 -0
  9. package/core-kit/const/config.d.ts +1 -1
  10. package/core-kit/const/hyperliquid.d.ts +8 -0
  11. package/core-kit/const/index.d.ts +1 -0
  12. package/core-kit/const/logger.d.ts +4 -0
  13. package/core-kit/const/trading.d.ts +3 -0
  14. package/core-kit/hooks/pool/index.d.ts +4 -0
  15. package/core-kit/hooks/pool/use-asset-guard-address.d.ts +8 -0
  16. package/core-kit/hooks/pool/use-dytm-vault-data.d.ts +8 -0
  17. package/core-kit/hooks/pool/use-ondo-price-deviation.d.ts +10 -0
  18. package/core-kit/hooks/pool/use-ondo-vault-data.d.ts +1 -0
  19. package/core-kit/hooks/pool/use-pool-assets-with-type.d.ts +14 -0
  20. package/core-kit/hooks/trading/hyperliquid-withdraw/index.d.ts +12 -0
  21. package/core-kit/hooks/trading/hyperliquid-withdraw/use-handle-hyperliquid-withdraw-step.d.ts +12 -0
  22. package/core-kit/hooks/trading/hyperliquid-withdraw/use-hyperliquid-announce-transaction.d.ts +9 -0
  23. package/core-kit/hooks/trading/hyperliquid-withdraw/use-hyperliquid-cancel-availability.d.ts +5 -0
  24. package/core-kit/hooks/trading/hyperliquid-withdraw/use-hyperliquid-manager-transaction.d.ts +8 -0
  25. package/core-kit/hooks/trading/hyperliquid-withdraw/use-hyperliquid-pending-withdrawal.d.ts +313 -0
  26. package/core-kit/hooks/trading/hyperliquid-withdraw/use-hyperliquid-withdraw-expected-amount.d.ts +4 -0
  27. package/core-kit/hooks/trading/hyperliquid-withdraw/use-hyperliquid-withdrawal-allowance.d.ts +10 -0
  28. package/core-kit/hooks/trading/hyperliquid-withdraw/use-is-hyperliquid-withdraw.d.ts +4 -0
  29. package/core-kit/hooks/trading/hyperliquid-withdraw/use-is-hyperliquid-withdrawal-vault.d.ts +1 -0
  30. package/core-kit/hooks/trading/hyperliquid-withdraw/use-purge-hyperliquid-pending-transactions.d.ts +1 -0
  31. package/core-kit/hooks/trading/withdraw-v2/init-step/use-fetch-dytm-withdraw-asset-data.d.ts +3 -0
  32. package/core-kit/hooks/trading/withdraw-v2/init-step/use-fetch-ondo-withdraw-asset-data.d.ts +3 -2
  33. package/core-kit/services/ondo/api.d.ts +5 -1
  34. package/core-kit/services/ondo/index.d.ts +2 -2
  35. package/core-kit/services/ondo/types.d.ts +9 -0
  36. package/core-kit/types/trading-panel.types.d.ts +1 -1
  37. package/core-kit/utils/complex-withdraw-asset-data.d.ts +9 -5
  38. package/core-kit/utils/dytm.d.ts +51 -0
  39. package/core-kit/utils/error.d.ts +1 -0
  40. package/core-kit/utils/hyperliquid-asset-ids.d.ts +32 -0
  41. package/core-kit/utils/index.d.ts +2 -0
  42. package/core-kit/utils/ondo.d.ts +2 -1
  43. package/core-kit/utils/web3.d.ts +5 -1
  44. package/dytm-C7rdytdA.cjs +1 -0
  45. package/dytm-DIQAbDy2.js +833 -0
  46. package/{geoblocking-NkujbQRm.js → geoblocking-C4bMDd1o.js} +15 -9
  47. package/geoblocking-CUDTwbrq.cjs +1 -0
  48. package/gmx-BTx7XZoO.cjs +1 -0
  49. package/{gmx-DQ-wSifY.js → gmx-D2b-KeY_.js} +622 -353
  50. package/index.cjs +1 -1
  51. package/index.js +5830 -4447
  52. package/package.json +2 -2
  53. package/style.css +1 -1
  54. package/trading-widget/components/common/tab/tab-button/tab-button.d.ts +1 -0
  55. package/trading-widget/components/widget/widget-overlay/hyperliquid-withdraw-stepper-overlay/hyperliquid-withdraw-stepper-overlay.d.ts +3 -0
  56. package/trading-widget/components/widget/widget-overlay/hyperliquid-withdraw-stepper-overlay/hyperliquid-withdraw-stepper-overlay.hooks.d.ts +21 -0
  57. package/trading-widget/components/widget/widget-overlay/hyperliquid-withdraw-stepper-overlay/steps/announce-step.d.ts +3 -0
  58. package/trading-widget/components/widget/widget-overlay/hyperliquid-withdraw-stepper-overlay/steps/announce-step.hooks.d.ts +11 -0
  59. package/trading-widget/components/widget/widget-overlay/hyperliquid-withdraw-stepper-overlay/steps/approve-step.d.ts +3 -0
  60. package/trading-widget/components/widget/widget-overlay/hyperliquid-withdraw-stepper-overlay/steps/approve-step.hooks.d.ts +10 -0
  61. package/trading-widget/components/widget/widget-overlay/hyperliquid-withdraw-stepper-overlay/steps/bridge-step.d.ts +3 -0
  62. package/trading-widget/components/widget/widget-overlay/hyperliquid-withdraw-stepper-overlay/steps/bridge-step.hooks.d.ts +10 -0
  63. package/trading-widget/components/widget/widget-overlay/hyperliquid-withdraw-stepper-overlay/steps/settle-step.d.ts +3 -0
  64. package/trading-widget/components/widget/widget-overlay/hyperliquid-withdraw-stepper-overlay/steps/settle-step.hooks.d.ts +10 -0
  65. package/trading-widget/components/widget/widget-overlay/hyperliquid-withdraw-stepper-overlay/steps/use-hyperliquid-manager-step.d.ts +14 -0
  66. package/trading-widget/components/widget/widget-overlay/hyperliquid-withdraw-stepper-overlay/use-auto-fire-hyperliquid-step.d.ts +11 -0
  67. package/trading-widget/components/widget/widget-overlay/hyperliquid-withdraw-stepper-overlay/use-hyperliquid-step-failure.d.ts +4 -0
  68. package/trading-widget/components/widget/widget-overlay/index.d.ts +1 -0
  69. package/trading-widget/components/widget/widget-overlay/withdraw-stepper-overlay/steps/init-withdraw-step.hooks.d.ts +1 -1
  70. package/trading-widget/components/widget/widget-overlay/withdraw-stepper-overlay/steps/oracle-update-step.d.ts +3 -0
  71. package/trading-widget/components/widget/widget-overlay/withdraw-stepper-overlay/steps/oracle-update-step.hooks.d.ts +11 -0
  72. package/trading-widget/components/widget/widget-overlay/withdraw-stepper-overlay/withdraw-stepper-overlay.hooks.d.ts +10 -2
  73. package/trading-widget/components/widget/widget-overlay/withdraw-stepper-overlay/withdraw-steps.d.ts +2 -9
  74. package/trading-widget/components/widget/widget-overlay/withdraw-stepper-overlay/withdraw-steps.hooks.d.ts +26 -0
  75. package/trading-widget/components/widget/widget-tabs/widget-tabs.hooks.d.ts +1 -0
  76. package/trading-widget/components/withdraw/init-step/button/hyperliquid-withdraw-button/hyperliquid-withdraw-button.d.ts +2 -0
  77. package/trading-widget/components/withdraw/init-step/button/hyperliquid-withdraw-button/hyperliquid-withdraw-button.hooks.d.ts +4 -0
  78. package/trading-widget/components/withdraw/init-step/button/valid-init-withdraw-button/valid-init-withdraw-button.hooks.d.ts +2 -0
  79. package/trading-widget/components/withdraw/init-step/meta/pending-hyperliquid-withdraw-banner.d.ts +2 -0
  80. package/trading-widget/providers/theme-provider/theme-provider.types.d.ts +1 -0
  81. package/trading-widget/providers/translation-provider/translation-provider.types.d.ts +10 -0
  82. package/trading-widget/types/overlay.types.d.ts +1 -0
  83. package/utils.cjs +1 -1
  84. package/utils.js +72 -60
  85. package/geoblocking-9FD_O0-h.cjs +0 -1
  86. package/gmx-Dejxb5_t.cjs +0 -1
  87. package/ondo-GwhTVXds.js +0 -540
  88. package/ondo-rQybmFLf.cjs +0 -1
@@ -0,0 +1,833 @@
1
+ import { mainnet as _, hyperEvm as G, polygon as V, optimism as K, base as Z, arbitrum as z } from "wagmi/chains";
2
+ import { ar as Q, ap as X, aq as j, a as w, q as E, as as J, at as tt, a5 as et, al as nt, a3 as at, b as st, ae as ot, ak as rt, aj as it, Z as ut, au as $, e as ct, d as dt, M as pt, R as mt, P as lt, av as yt, aw as At, Q as Tt, N as ft, ah as g, _ as Dt, W as gt, X as St, U as _t, ax as W, ay as wt, az as Et, aA as It, aB as ht, aC as bt, ad as Nt } from "./gmx-D2b-KeY_.js";
3
+ import d from "bignumber.js";
4
+ import { zeroHash as Mt, bytesToHex as Ot, pad as Rt, stringToHex as I, encodeAbiParameters as f, encodeFunctionData as A, erc20Abi as q, maxUint256 as h } from "viem";
5
+ const ye = typeof window < "u", Ae = [
6
+ {
7
+ inputs: [
8
+ { internalType: "address", name: "_pool", type: "address" },
9
+ { internalType: "address", name: "_asset", type: "address" },
10
+ { internalType: "uint256", name: "_poolTokenAmount", type: "uint256" }
11
+ ],
12
+ name: "previewGmTokenAmount",
13
+ outputs: [
14
+ { internalType: "uint256", name: "gmTokenAmount", type: "uint256" }
15
+ ],
16
+ stateMutability: "nonpayable",
17
+ type: "function"
18
+ },
19
+ {
20
+ inputs: [],
21
+ name: "ondoGMSwap",
22
+ outputs: [{ internalType: "address", name: "", type: "address" }],
23
+ stateMutability: "view",
24
+ type: "function"
25
+ },
26
+ {
27
+ inputs: [],
28
+ name: "usdc",
29
+ outputs: [{ internalType: "address", name: "", type: "address" }],
30
+ stateMutability: "view",
31
+ type: "function"
32
+ }
33
+ ], Ct = [
34
+ {
35
+ type: "tuple",
36
+ components: [
37
+ { name: "attestationSignature", type: "bytes" },
38
+ {
39
+ name: "quote",
40
+ type: "tuple",
41
+ components: [
42
+ { name: "chainId", type: "uint256" },
43
+ { name: "attestationId", type: "uint256" },
44
+ { name: "userId", type: "bytes32" },
45
+ { name: "asset", type: "address" },
46
+ { name: "price", type: "uint256" },
47
+ { name: "quantity", type: "uint256" },
48
+ { name: "expiration", type: "uint256" },
49
+ { name: "side", type: "uint8" },
50
+ { name: "additionalData", type: "bytes32" }
51
+ ]
52
+ },
53
+ { name: "amountOutMinimum", type: "uint256" }
54
+ ]
55
+ }
56
+ ], Bt = [
57
+ { name: "asset", type: "address" },
58
+ { name: "amount", type: "uint256" },
59
+ { name: "assetType", type: "uint16" },
60
+ { name: "isPool", type: "bool" },
61
+ { name: "isDebt", type: "bool" },
62
+ { name: "marketId", type: "uint88" },
63
+ { name: "accountId", type: "uint256" },
64
+ { name: "tokenId", type: "uint256" },
65
+ { name: "debtKey", type: "uint248" },
66
+ { name: "shares", type: "uint256" }
67
+ ], Te = [
68
+ {
69
+ inputs: [
70
+ { internalType: "address", name: "_pool", type: "address" },
71
+ { internalType: "uint256", name: "_poolTokenAmount", type: "uint256" }
72
+ ],
73
+ name: "previewWithdrawal",
74
+ outputs: [
75
+ {
76
+ name: "assetData",
77
+ type: "tuple[]",
78
+ components: Bt
79
+ }
80
+ ],
81
+ stateMutability: "nonpayable",
82
+ type: "function"
83
+ },
84
+ {
85
+ inputs: [],
86
+ name: "dytmWithdrawProcessor",
87
+ outputs: [{ name: "", type: "address" }],
88
+ stateMutability: "view",
89
+ type: "function"
90
+ }
91
+ ], H = [
92
+ {
93
+ inputs: [
94
+ {
95
+ name: "params",
96
+ type: "tuple",
97
+ components: [
98
+ { name: "account", type: "uint256" },
99
+ { name: "tokenId", type: "uint256" },
100
+ { name: "receiver", type: "address" },
101
+ { name: "assets", type: "uint256" },
102
+ { name: "shares", type: "uint256" },
103
+ { name: "extraData", type: "bytes" }
104
+ ]
105
+ }
106
+ ],
107
+ name: "withdraw",
108
+ outputs: [{ name: "assets", type: "uint256" }],
109
+ stateMutability: "nonpayable",
110
+ type: "function"
111
+ },
112
+ {
113
+ inputs: [
114
+ {
115
+ name: "params",
116
+ type: "tuple",
117
+ components: [
118
+ { name: "account", type: "uint256" },
119
+ { name: "key", type: "uint248" },
120
+ // DytmParamStructs.TokenType enum — 0 = NONE.
121
+ { name: "withCollateralType", type: "uint8" },
122
+ { name: "assets", type: "uint256" },
123
+ { name: "shares", type: "uint256" },
124
+ { name: "extraData", type: "bytes" }
125
+ ]
126
+ }
127
+ ],
128
+ name: "repay",
129
+ outputs: [{ name: "assetsRepaid", type: "uint256" }],
130
+ stateMutability: "nonpayable",
131
+ type: "function"
132
+ }
133
+ ], Lt = [
134
+ {
135
+ inputs: [
136
+ { name: "tokenIn", type: "address" },
137
+ { name: "amountIn", type: "uint256" },
138
+ { name: "tokenOut", type: "address" },
139
+ { name: "amountOutMinimum", type: "uint256" },
140
+ { name: "attestationSignature", type: "bytes" },
141
+ {
142
+ name: "quote",
143
+ type: "tuple",
144
+ components: [
145
+ { name: "chainId", type: "uint256" },
146
+ { name: "attestationId", type: "uint256" },
147
+ { name: "userId", type: "bytes32" },
148
+ { name: "asset", type: "address" },
149
+ { name: "price", type: "uint256" },
150
+ { name: "quantity", type: "uint256" },
151
+ { name: "expiration", type: "uint256" },
152
+ { name: "side", type: "uint8" },
153
+ { name: "additionalData", type: "bytes32" }
154
+ ]
155
+ }
156
+ ],
157
+ name: "swapExactInWithAttestation",
158
+ outputs: [],
159
+ stateMutability: "nonpayable",
160
+ type: "function"
161
+ }
162
+ ], xt = [
163
+ {
164
+ type: "tuple",
165
+ components: [
166
+ {
167
+ name: "actions",
168
+ type: "tuple[]",
169
+ components: [
170
+ { name: "to", type: "address" },
171
+ { name: "data", type: "bytes" }
172
+ ]
173
+ },
174
+ { name: "outputAsset", type: "address" },
175
+ { name: "minOutputAmount", type: "uint256" }
176
+ ]
177
+ }
178
+ ], Pt = () => typeof window < "u";
179
+ function Ut() {
180
+ return Pt() && typeof window.ethereum < "u";
181
+ }
182
+ async function fe(t) {
183
+ try {
184
+ if (Ut())
185
+ return window.ethereum.request({
186
+ method: "wallet_watchAsset",
187
+ params: {
188
+ type: "ERC20",
189
+ options: t
190
+ }
191
+ });
192
+ } catch {
193
+ return !1;
194
+ }
195
+ return !1;
196
+ }
197
+ const m = (t, e) => t?.toLowerCase() === e?.toLowerCase(), De = (t) => m(t, Q), T = (t) => {
198
+ if (!t) throw new Error("Cannot prefix an empty hex value");
199
+ return t.startsWith("0x") ? t : `0x${t}`;
200
+ }, p = (t, e) => {
201
+ try {
202
+ return BigInt(t);
203
+ } catch {
204
+ throw new Error(`Cannot convert "${e}" value "${t}" to bigint`);
205
+ }
206
+ }, b = (t) => t ? Rt(T(t), { size: 32 }) : Mt, Ft = (t) => {
207
+ if (!t) throw new Error("Cannot decode an empty base64 string");
208
+ return Ot(Uint8Array.from(atob(t), (e) => e.charCodeAt(0)));
209
+ }, vt = (t, e) => j[e]?.[t] ?? w, ge = (t) => X[t], Se = (t) => t && `${t.substring(0, 6)}...${t.substring(
210
+ t.length - 4,
211
+ t.length
212
+ )}`, _e = ({
213
+ address: t,
214
+ chainId: e
215
+ }) => {
216
+ const n = vt(
217
+ "aaveLendingPoolV3",
218
+ e
219
+ );
220
+ return m(t, n);
221
+ }, $t = ({
222
+ sourceAddress: t,
223
+ amount: e
224
+ }) => `${t}_${e}`, we = (t, e) => {
225
+ const n = t.slice(0, e), a = t.slice(e);
226
+ return { firstPart: n, secondPart: a };
227
+ }, Wt = (t, e) => t / e * 100, Ee = (t) => t < 1 ? 4 : t < 10 ? 3 : 2, Ie = (t, e = E) => new d(t.toString()).shiftedBy(e).toFixed(0), he = (t, e, n, a) => new d(e).dividedBy(n).multipliedBy(t).shiftedBy(-(a || E)).toNumber(), be = (t) => BigInt(
228
+ new d(t || "0").shiftedBy(E).toFixed(0, d.ROUND_DOWN)
229
+ ), qt = (t) => {
230
+ const e = new d(0.01), n = new d(t), a = !n.isZero() && n.lt(e) ? e : n;
231
+ return BigInt(a.multipliedBy(100).toFixed(0));
232
+ }, Ne = ({
233
+ vaultAddress: t,
234
+ swapData: e,
235
+ sendTokenAddress: n,
236
+ sendTokenAmount: a,
237
+ vaultDepositTokenAddress: s,
238
+ minVaultTokensReceivedAmount: o,
239
+ routerKey: r = "ONE_INCH",
240
+ swapDestinationAmount: u,
241
+ swapSlippage: i
242
+ }) => {
243
+ const c = new d(u).multipliedBy(1 - i / 100).toFixed(0), l = [I(r, { size: 32 }), e];
244
+ return [t, [[n, a, l], [s, c]], o];
245
+ }, Me = ({
246
+ receiveAssetAddress: t,
247
+ assets: e,
248
+ swapData: n,
249
+ slippage: a
250
+ }) => {
251
+ const s = {
252
+ srcData: [],
253
+ destAmount: new d("0")
254
+ }, { srcData: o, destAmount: r } = e?.reduce((u, i) => {
255
+ const c = n?.[i.address];
256
+ if (!c)
257
+ return u;
258
+ const l = [
259
+ I(c.routerKey, { size: 32 }),
260
+ c.rawTransaction.data
261
+ ], y = [i.address, i.rawBalance, l];
262
+ return {
263
+ srcData: [...u.srcData, y],
264
+ destAmount: u.destAmount.plus(c.destinationAmount)
265
+ };
266
+ }, s) ?? s;
267
+ return [
268
+ o,
269
+ [
270
+ t,
271
+ r.times(1 - a / 100).toFixed(0, d.ROUND_DOWN)
272
+ ]
273
+ ];
274
+ }, Ht = ({
275
+ assetAddress: t,
276
+ swapQuotes: e,
277
+ swapParams: n,
278
+ slippageToleranceForContractTransaction: a,
279
+ routerKey: s
280
+ }) => {
281
+ if (!n)
282
+ return {
283
+ supportedAsset: t,
284
+ withdrawData: "",
285
+ slippageTolerance: BigInt(0)
286
+ };
287
+ const { srcData: o, dstData: r } = n, u = o.map(({ asset: l, amount: y }) => {
288
+ const D = e?.[$t({
289
+ sourceAddress: l,
290
+ amount: y.toString()
291
+ })]?.find((k) => k.routerKey === s);
292
+ return {
293
+ asset: l,
294
+ amount: y,
295
+ swapData: {
296
+ routerKey: I(D?.routerKey ?? "", { size: 32 }),
297
+ txData: D?.rawTransaction.data ?? "0x"
298
+ }
299
+ };
300
+ }), i = f(
301
+ J,
302
+ [u]
303
+ ), c = f(tt, [
304
+ {
305
+ encodedSrcData: i,
306
+ dstData: {
307
+ dstAddress: r.asset,
308
+ dstAmount: r.amount
309
+ },
310
+ slippage: a
311
+ }
312
+ ]);
313
+ return {
314
+ supportedAsset: t,
315
+ withdrawData: c,
316
+ slippageTolerance: a
317
+ };
318
+ }, Oe = ({
319
+ chainId: t,
320
+ txHash: e,
321
+ error: n
322
+ }) => {
323
+ if (t !== _.id || !e || !n)
324
+ return !1;
325
+ const a = n instanceof Error ? n.message : String(n);
326
+ return /\bNo Result\b/i.test(a);
327
+ }, Re = ({
328
+ chainId: t,
329
+ action: e,
330
+ isRabbyWallet: n
331
+ }) => e === "update_ondo_prices" && t === _.id && n ? et : t ? nt[t] ?? 0 : 0, Ce = (t, e) => st[e]?.nativeTokenSymbol === t, Be = ({
332
+ nativeTokenBalance: t,
333
+ tokenDecimals: e,
334
+ gasPrice: n
335
+ }) => {
336
+ const a = new d(n).multipliedBy(at).shiftedBy(-e), s = new d(t).minus(
337
+ a
338
+ );
339
+ return s.gt("0") ? s : new d("0");
340
+ }, Le = (t) => ot.includes(t), xe = (t) => {
341
+ const e = Object.values(t).reduce(
342
+ (n, { type: a }) => (n[a] = n[a] + 1, n),
343
+ { string: 0, number: 0 }
344
+ );
345
+ if (e.string > 10)
346
+ throw new Error("logger params must contain up to 10 string values");
347
+ if (e.number > 40)
348
+ throw new Error("logger params must contain up to 40 numeric values");
349
+ return !0;
350
+ }, Yt = (t, e = 150) => t.length > e ? t.substring(0, e) : t, kt = (t) => !!t?.includes("User rejected"), N = (t, e = rt) => {
351
+ const n = t.toLowerCase();
352
+ return e.sort((a, s) => s.length - a.length).find((a) => n.includes(a.toLowerCase()));
353
+ }, M = (t) => it[t] ?? ut[t], Pe = ({
354
+ errorMessage: t,
355
+ abiErrors: e
356
+ }) => {
357
+ if (!t || kt(t))
358
+ return null;
359
+ const n = e.find((o) => t.includes(o));
360
+ if (n && N(n))
361
+ return M(n);
362
+ const a = N(t);
363
+ if (a)
364
+ return M(a);
365
+ const [s] = t.split(n ? "." : "Contract").map((o) => o.trim());
366
+ return {
367
+ title: "Transaction failed",
368
+ hint: `${Yt(s ?? "")} ${n ? `: ${n}` : ""}`
369
+ };
370
+ }, Ue = (t) => typeof t == "number" && Number.isFinite(t), Fe = (t) => typeof t == "bigint" && t !== BigInt(0), Gt = (t, e = $) => new d(t).shiftedBy(-e).toNumber(), Vt = (t) => !isNaN(parseFloat(t)) && !isNaN(t), Kt = ({
371
+ value: t,
372
+ minimumFractionDigits: e = 2,
373
+ maximumFractionDigits: n = 2,
374
+ compact: a = !1,
375
+ normalize: s = !1
376
+ }) => new Intl.NumberFormat("en-US", {
377
+ style: "currency",
378
+ currency: "USD",
379
+ notation: a ? "compact" : void 0,
380
+ minimumFractionDigits: e,
381
+ maximumFractionDigits: n
382
+ }).format(s ? Gt(t) : Number(t)), O = (t) => Vt(t) ? new d(t).toFixed() : "", R = ["₀", "₁", "₂", "₃", "₄", "₅", "₆", "₇", "₈", "₉"], Zt = ({
383
+ value: t,
384
+ decimals: e = 4
385
+ }) => {
386
+ const n = new d(t);
387
+ if (n.isGreaterThan(1) || n.isZero())
388
+ return O(n.toFixed(e));
389
+ const s = (/e/i.test(t.toString()) ? parseFloat(t.toString()).toFixed($) : t.toString()).match(/^0\.(0+)(\d+)$/);
390
+ if (s) {
391
+ const [, o, r] = s;
392
+ if (o.length >= e && o.length < R.length)
393
+ return `0.0${R[o.length]}${r.slice(0, 3)}`;
394
+ }
395
+ return O(n.toFixed(e));
396
+ }, zt = (t, e = 0) => `${t.toLocaleString("en-US", { maximumFractionDigits: e })}%`, ve = (t) => t.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), $e = (t, e, n = 0) => {
397
+ const a = Wt(+t, e);
398
+ return zt(a, n);
399
+ }, We = ({
400
+ currency: t,
401
+ value: e
402
+ }) => t === "USD" ? Kt({ value: e }) : `${ct[t]} ${Zt({
403
+ value: e,
404
+ decimals: dt[t]
405
+ })}`, Qt = (t, e) => new d(
406
+ new d(t).toFixed(e, d.ROUND_DOWN)
407
+ ).toString(), Xt = (t, e = 3, n = 2) => {
408
+ if (t.length <= 5)
409
+ return t;
410
+ const a = "...";
411
+ return t.length <= e + n + a.length ? t : `${t.slice(0, e)}${a}${t.slice(-n)}`;
412
+ }, qe = ({
413
+ balance: t,
414
+ symbol: e,
415
+ precision: n,
416
+ truncateSymbol: a
417
+ }) => `${Qt(t, n)} ${a ? Xt(e) : e}`, He = (t) => {
418
+ if (!t)
419
+ return;
420
+ const e = t.match(/0x[a-fA-F0-9]{64}/);
421
+ if (!e)
422
+ return;
423
+ const n = e[0];
424
+ return `${n.slice(0, 4)}...${n.slice(-3)}`;
425
+ }, Ye = (t) => m(yt, t) || m(At, t), ke = (t) => ft.some(
426
+ (e) => m(e, t)
427
+ ), Ge = (t) => pt[t.toLowerCase()] ?? {
428
+ symbol: "",
429
+ decimals: 18,
430
+ address: w
431
+ }, Ve = (t) => m(t, Tt) ? mt : lt, jt = (t) => `eth_${t}`, Ke = ({
432
+ action: t,
433
+ log: e,
434
+ symbol: n,
435
+ vaultAddress: a,
436
+ chainId: s
437
+ }) => {
438
+ const o = {
439
+ [g.SYMBOL.NAME]: n,
440
+ [g.CHAIN_ID.NAME]: s,
441
+ [g.ADDRESS.NAME]: jt(a)
442
+ };
443
+ Dt[t].forEach((r) => {
444
+ e?.(r, o);
445
+ });
446
+ }, Ze = (t) => _t.some((e) => m(e, t)), ze = (t) => gt[t.toLowerCase()] ?? {
447
+ symbol: "",
448
+ decimals: 18,
449
+ address: w
450
+ }, Qe = (t) => St[t.toLowerCase()], Jt = "0x3333333333333333333333333333333333333333";
451
+ z.id + "", bt.address, Z.id + "", ht.address, K.id + "", It.address, V.id + "", Et.address, _.id + "", wt.address, G.id + "", W.address;
452
+ const Xe = (t) => m(t, Jt), je = () => W, te = 1e5, ee = 1e4, ne = 1e4, C = 0, ae = 4294967295;
453
+ class S extends Error {
454
+ constructor(e) {
455
+ super(e), this.name = "HyperliquidAssetIdMappingError";
456
+ }
457
+ }
458
+ const B = (t) => {
459
+ const e = Number(t);
460
+ return Number.isFinite(e) && e !== 0;
461
+ }, L = (t, e) => {
462
+ if (!Number.isInteger(t) || t < 0 || t > ae)
463
+ throw new S(
464
+ `Asset id ${t} for ${e} is out of uint32 range`
465
+ );
466
+ return t;
467
+ }, x = (t) => [...new Set(t)].sort((e, n) => e - n), Je = ({
468
+ perpDexStates: t,
469
+ spotBalances: e,
470
+ spotPairs: n
471
+ }) => {
472
+ const a = t.flatMap(
473
+ ({ dexId: o, positions: r, universe: u }) => r.filter(({ szi: i }) => B(i)).map(({ coin: i }) => {
474
+ const c = u.findIndex(({ name: y }) => y === i);
475
+ if (c === -1)
476
+ throw new S(
477
+ `Open perp position "${i}" not found in dex ${o} universe`
478
+ );
479
+ const l = o === 0 ? c : te + o * ee + c;
480
+ return L(l, `perp "${i}"`);
481
+ })
482
+ ), s = e.filter(
483
+ ({ token: o, total: r }) => o !== C && B(r)
484
+ ).map(({ coin: o, token: r }) => {
485
+ const u = n.find(
486
+ ({ tokens: i }) => i[0] === r && i[1] === C
487
+ );
488
+ if (!u)
489
+ throw new S(
490
+ `No token/USDC spot pair found for held spot token "${o}" (index ${r})`
491
+ );
492
+ return L(ne + u.index, `spot "${o}"`);
493
+ });
494
+ return {
495
+ perpAssetIds: x(a),
496
+ spotAssetIds: x(s)
497
+ };
498
+ }, tn = /* @__PURE__ */ new Map(), Y = (t, e) => !e || e.size === 0 ? t : t.map((n) => {
499
+ const a = e.get(
500
+ n.supportedAsset.toLowerCase()
501
+ );
502
+ return a ? {
503
+ ...n,
504
+ withdrawData: a.withdrawData,
505
+ slippageTolerance: a.slippageTolerance
506
+ } : n;
507
+ }), se = (t) => {
508
+ const e = t.find(
509
+ ({ swapQuotes: n }) => n
510
+ );
511
+ return e?.swapQuotes ? Object.values(e.swapQuotes)[0]?.map(
512
+ ({ routerKey: n }) => n
513
+ ) ?? [] : [];
514
+ }, oe = (t, e, n) => t.map(({ asset: a, swapParams: s, swapQuotes: o }) => !s || !o ? {
515
+ supportedAsset: a,
516
+ withdrawData: "",
517
+ slippageTolerance: n
518
+ } : Ht({
519
+ assetAddress: a,
520
+ swapQuotes: o,
521
+ swapParams: s,
522
+ slippageToleranceForContractTransaction: n,
523
+ routerKey: e
524
+ })), re = async (t, e, n, a, s, o) => {
525
+ for (const r of t) {
526
+ const u = Y(
527
+ oe(
528
+ e,
529
+ r,
530
+ n
531
+ ),
532
+ o
533
+ ), { error: i } = await a(...s, u);
534
+ if (!i)
535
+ return u;
536
+ }
537
+ return null;
538
+ }, en = (t, e, n) => {
539
+ const a = (t ?? []).map((s) => ({
540
+ supportedAsset: s,
541
+ withdrawData: "",
542
+ slippageTolerance: e
543
+ }));
544
+ return Y(a, n);
545
+ }, nn = async (t, e, n, a, s) => {
546
+ for (const o of t) {
547
+ const r = qt(o);
548
+ try {
549
+ const u = await e(o), i = se(
550
+ u
551
+ ), c = await re(
552
+ i,
553
+ u,
554
+ r,
555
+ n,
556
+ a,
557
+ s
558
+ );
559
+ if (c)
560
+ return console.debug(
561
+ `[Init Withdraw] Auto slippage simulation succeeded: slippage=${o}%`
562
+ ), console.debug("[Init Withdraw] Complex asset data:", c), c;
563
+ } catch (u) {
564
+ console.error(
565
+ `[Init Withdraw] Failed to fetch quotes for slippage=${o}%:`,
566
+ u
567
+ );
568
+ }
569
+ }
570
+ return null;
571
+ }, an = async (t, e, {
572
+ fetchAaveSwapParams: n,
573
+ fetchAaveSwapQuotes: a,
574
+ withdrawAmountD18: s,
575
+ slippage: o
576
+ }) => Promise.all(
577
+ (t ?? []).map(async (r) => {
578
+ if (!m(r, e))
579
+ return { asset: r };
580
+ try {
581
+ const i = await n({
582
+ withdrawAmountD18: s,
583
+ slippage: o
584
+ });
585
+ if (i?.srcData.length) {
586
+ const c = await a({
587
+ swapParams: i,
588
+ slippage: o
589
+ });
590
+ return { asset: r, swapParams: i, swapQuotes: c };
591
+ }
592
+ return { asset: r };
593
+ } catch (i) {
594
+ return console.error(i), { asset: r };
595
+ }
596
+ })
597
+ ), P = (t) => Math.round(t * 100) / 100, sn = ({
598
+ maxSlippage: t,
599
+ candidates: e = Nt
600
+ }) => {
601
+ if (!Number.isFinite(t) || t <= 0)
602
+ return [];
603
+ const n = P(Math.min(t, 100)), a = e.filter((o) => o > 0 && o <= n).map(P), s = new Set(a);
604
+ return s.add(n), s.add(t), Array.from(s).sort((o, r) => o - r);
605
+ }, U = 1000000000000000000n, ie = 1000000n, F = 10000n, v = 100n, on = (t) => ({
606
+ quotes: t.quotes.map(
607
+ (e) => ({
608
+ chainId: p(e.chainId, "chainId"),
609
+ attestationId: p(e.attestationId, "attestationId"),
610
+ userId: T(e.userId),
611
+ asset: e.asset,
612
+ price: p(e.price, "price"),
613
+ quantity: p(e.quantity, "quantity"),
614
+ expiration: p(e.expiration, "expiration"),
615
+ side: Number(e.side),
616
+ additionalData: T(e.additionalData)
617
+ })
618
+ ),
619
+ signatures: t.signatures.map(T)
620
+ }), ue = (t, e, n) => {
621
+ const a = BigInt(Math.max(0, Math.round(n * 100))), s = a > v ? v : a, o = F - s, u = t * e / U * o * ie, i = F * U;
622
+ return (u + i - 1n) / i;
623
+ }, ce = (t, e) => ({
624
+ chainId: e,
625
+ attestationId: p(t.attestationId, "attestationId"),
626
+ userId: b(t.userId),
627
+ asset: t.assetAddress,
628
+ price: p(t.price, "price"),
629
+ quantity: p(t.tokenAmount, "tokenAmount"),
630
+ expiration: p(t.expiration, "expiration"),
631
+ side: Number(t.side),
632
+ additionalData: b(t.additionalData)
633
+ }), rn = ({
634
+ attestation: t,
635
+ chainId: e,
636
+ slippagePercent: n
637
+ }) => {
638
+ const a = ce(t, e);
639
+ return f(Ct, [
640
+ {
641
+ attestationSignature: Ft(t.signature),
642
+ quote: a,
643
+ amountOutMinimum: ue(
644
+ a.quantity,
645
+ a.price,
646
+ n
647
+ )
648
+ }
649
+ ]);
650
+ }, un = (t) => [...t.reduce(
651
+ (n, a) => n.has(a.accountId) ? n : n.set(a.accountId, a),
652
+ /* @__PURE__ */ new Map()
653
+ ).values()].map(({ accountId: n, marketId: a }) => ({
654
+ accountId: n,
655
+ marketId: a,
656
+ collaterals: t.filter(
657
+ (s) => s.accountId === n && !s.isDebt
658
+ ),
659
+ debt: t.find(
660
+ (s) => s.accountId === n && s.isDebt
661
+ )
662
+ })), cn = ({
663
+ collateral: t,
664
+ dytmOffice: e,
665
+ processor: n,
666
+ gmToken: a,
667
+ ondoGMSwap: s,
668
+ usdc: o,
669
+ gmAmount: r,
670
+ amountOutMinimum: u,
671
+ signature: i,
672
+ quote: c
673
+ }) => [
674
+ {
675
+ // 1 · pull GM collateral out of the split account -> processor
676
+ to: e,
677
+ data: A({
678
+ abi: H,
679
+ functionName: "withdraw",
680
+ args: [
681
+ {
682
+ account: t.accountId,
683
+ tokenId: t.tokenId,
684
+ receiver: n,
685
+ assets: r,
686
+ shares: 0n,
687
+ extraData: "0x"
688
+ }
689
+ ]
690
+ })
691
+ },
692
+ {
693
+ // 2 · approve the GM token to Ondo's swap contract
694
+ to: a,
695
+ data: A({
696
+ abi: q,
697
+ functionName: "approve",
698
+ args: [s, r]
699
+ })
700
+ },
701
+ {
702
+ // 3 · redeem GM -> USDC with the signed attestation
703
+ to: s,
704
+ data: A({
705
+ abi: Lt,
706
+ functionName: "swapExactInWithAttestation",
707
+ args: [a, r, o, u, i, c]
708
+ })
709
+ }
710
+ ], dn = ({
711
+ accountId: t,
712
+ debtKey: e,
713
+ dytmOffice: n,
714
+ usdc: a
715
+ }) => [
716
+ {
717
+ // approve USDC to the DYTM Office for the repay
718
+ to: a,
719
+ data: A({
720
+ abi: q,
721
+ functionName: "approve",
722
+ args: [n, h]
723
+ })
724
+ },
725
+ {
726
+ // repay the slice's whole USDC debt
727
+ to: n,
728
+ data: A({
729
+ abi: H,
730
+ functionName: "repay",
731
+ args: [
732
+ {
733
+ account: t,
734
+ key: e,
735
+ withCollateralType: 0,
736
+ // DytmParamStructs.TokenType.NONE
737
+ assets: h,
738
+ // repay all
739
+ shares: 0n,
740
+ extraData: "0x"
741
+ }
742
+ ]
743
+ })
744
+ }
745
+ ], pn = ({
746
+ actions: t,
747
+ outputAsset: e,
748
+ minOutputAmount: n
749
+ }) => f(xt, [
750
+ { actions: t, outputAsset: e, minOutputAmount: n }
751
+ ]);
752
+ export {
753
+ Pe as $,
754
+ Ge as A,
755
+ Ve as B,
756
+ ze as C,
757
+ Qe as D,
758
+ tn as E,
759
+ je as F,
760
+ Be as G,
761
+ S as H,
762
+ Wt as I,
763
+ he as J,
764
+ Re as K,
765
+ qt as L,
766
+ He as M,
767
+ un as N,
768
+ _e as O,
769
+ ke as P,
770
+ Ye as Q,
771
+ Ze as R,
772
+ Xe as S,
773
+ Ce as T,
774
+ Le as U,
775
+ kt as V,
776
+ Ke as W,
777
+ ce as X,
778
+ on as Y,
779
+ Y as Z,
780
+ be as _,
781
+ Ht as a,
782
+ Ie as a0,
783
+ Se as a1,
784
+ Oe as a2,
785
+ we as a3,
786
+ p as a4,
787
+ b as a5,
788
+ jt as a6,
789
+ Xt as a7,
790
+ re as a8,
791
+ nn as a9,
792
+ xe as aa,
793
+ De as ab,
794
+ Ue as ac,
795
+ m as ad,
796
+ Kt as ae,
797
+ Fe as af,
798
+ Gt as ag,
799
+ Te as ah,
800
+ Ae as ai,
801
+ Jt as aj,
802
+ Zt as ak,
803
+ fe as al,
804
+ zt as am,
805
+ Vt as an,
806
+ ve as ao,
807
+ O as ap,
808
+ Ft as b,
809
+ oe as c,
810
+ cn as d,
811
+ dn as e,
812
+ Je as f,
813
+ $t as g,
814
+ Me as h,
815
+ Ne as i,
816
+ ye as j,
817
+ ue as k,
818
+ en as l,
819
+ rn as m,
820
+ pn as n,
821
+ an as o,
822
+ T as p,
823
+ se as q,
824
+ Qt as r,
825
+ We as s,
826
+ $e as t,
827
+ qe as u,
828
+ sn as v,
829
+ ge as w,
830
+ vt as x,
831
+ Ee as y,
832
+ N as z
833
+ };