@dhedge/trading-widget 6.0.6 → 6.1.1

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 (51) hide show
  1. package/const.cjs +1 -1
  2. package/const.js +94 -89
  3. package/core-kit/abi/dytm-office-asset-guard.d.ts +194 -0
  4. package/core-kit/abi/index.d.ts +1 -0
  5. package/core-kit/abi/ondo-gm-token-asset-guard.d.ts +20 -0
  6. package/core-kit/abi/ondo-price-oracle.d.ts +18 -0
  7. package/core-kit/const/index.d.ts +1 -0
  8. package/core-kit/const/midas.d.ts +2 -0
  9. package/core-kit/const/trading.d.ts +3 -0
  10. package/core-kit/hooks/pool/index.d.ts +4 -0
  11. package/core-kit/hooks/pool/use-asset-guard-address.d.ts +8 -0
  12. package/core-kit/hooks/pool/use-dytm-vault-data.d.ts +8 -0
  13. package/core-kit/hooks/pool/use-ondo-price-deviation.d.ts +10 -0
  14. package/core-kit/hooks/pool/use-ondo-vault-data.d.ts +1 -0
  15. package/core-kit/hooks/pool/use-pool-assets-with-type.d.ts +14 -0
  16. package/core-kit/hooks/trading/deposit-v2/deposit-transaction/use-ondo-price-freshness.d.ts +4 -4
  17. package/core-kit/hooks/trading/withdraw-v2/init-step/use-fetch-dytm-withdraw-asset-data.d.ts +3 -0
  18. package/core-kit/hooks/trading/withdraw-v2/init-step/use-fetch-ondo-withdraw-asset-data.d.ts +3 -2
  19. package/core-kit/hooks/trading/withdraw-v2/init-step/use-init-withdraw-simulation-withdraw-data.d.ts +7 -0
  20. package/core-kit/services/ondo/api.d.ts +5 -1
  21. package/core-kit/services/ondo/index.d.ts +2 -2
  22. package/core-kit/services/ondo/types.d.ts +9 -0
  23. package/core-kit/utils/complex-withdraw-asset-data.d.ts +9 -5
  24. package/core-kit/utils/dytm.d.ts +51 -0
  25. package/core-kit/utils/index.d.ts +1 -0
  26. package/core-kit/utils/ondo.d.ts +2 -1
  27. package/core-kit/utils/web3.d.ts +5 -1
  28. package/dytm-CQG65-Rc.cjs +1 -0
  29. package/dytm-CWhBYz0P.js +784 -0
  30. package/{geoblocking-NkujbQRm.js → geoblocking-DtB4yr5l.js} +10 -8
  31. package/geoblocking-peuNwHMJ.cjs +1 -0
  32. package/gmx-U3Bnivj2.cjs +1 -0
  33. package/{gmx-DQ-wSifY.js → gmx-c42QlKyJ.js} +389 -369
  34. package/index.cjs +1 -1
  35. package/index.d.ts +1 -1
  36. package/index.js +4276 -3682
  37. package/package.json +1 -1
  38. package/trading-widget/components/widget/widget-input/all-assets-composition-table/all-assets-composition-table.hooks.d.ts +2 -0
  39. package/trading-widget/components/widget/widget-overlay/withdraw-stepper-overlay/steps/init-withdraw-step.hooks.d.ts +1 -1
  40. package/trading-widget/components/widget/widget-overlay/withdraw-stepper-overlay/steps/oracle-update-step.d.ts +3 -0
  41. package/trading-widget/components/widget/widget-overlay/withdraw-stepper-overlay/steps/oracle-update-step.hooks.d.ts +11 -0
  42. package/trading-widget/components/widget/widget-overlay/withdraw-stepper-overlay/withdraw-stepper-overlay.hooks.d.ts +10 -2
  43. package/trading-widget/components/widget/widget-overlay/withdraw-stepper-overlay/withdraw-steps.d.ts +2 -9
  44. package/trading-widget/components/widget/widget-overlay/withdraw-stepper-overlay/withdraw-steps.hooks.d.ts +26 -0
  45. package/utils.cjs +1 -1
  46. package/utils.js +67 -58
  47. package/core-kit/hooks/trading/withdraw-v2/init-step/use-init-withdraw-estimated-receive-assets.d.ts +0 -235
  48. package/geoblocking-9FD_O0-h.cjs +0 -1
  49. package/gmx-Dejxb5_t.cjs +0 -1
  50. package/ondo-GwhTVXds.js +0 -540
  51. package/ondo-rQybmFLf.cjs +0 -1
package/ondo-GwhTVXds.js DELETED
@@ -1,540 +0,0 @@
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 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
- import u from "bignumber.js";
4
- import { stringToHex as f, encodeAbiParameters as _, bytesToHex as yt, zeroHash as Et, pad as ft } from "viem";
5
- const Xt = typeof window < "u", jt = [
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
- ], Nt = [
20
- {
21
- type: "tuple",
22
- components: [
23
- { name: "attestationSignature", type: "bytes" },
24
- {
25
- name: "quote",
26
- type: "tuple",
27
- components: [
28
- { name: "chainId", type: "uint256" },
29
- { name: "attestationId", type: "uint256" },
30
- { name: "userId", type: "bytes32" },
31
- { name: "asset", type: "address" },
32
- { name: "price", type: "uint256" },
33
- { name: "quantity", type: "uint256" },
34
- { name: "expiration", type: "uint256" },
35
- { name: "side", type: "uint8" },
36
- { name: "additionalData", type: "bytes32" }
37
- ]
38
- },
39
- { name: "amountOutMinimum", type: "uint256" }
40
- ]
41
- }
42
- ], wt = () => typeof window < "u";
43
- function ht() {
44
- return wt() && typeof window.ethereum < "u";
45
- }
46
- async function Jt(t) {
47
- try {
48
- if (ht())
49
- return window.ethereum.request({
50
- method: "wallet_watchAsset",
51
- params: {
52
- type: "ERC20",
53
- options: t
54
- }
55
- });
56
- } catch {
57
- return !1;
58
- }
59
- return !1;
60
- }
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
- t.length - 4,
63
- t.length
64
- )}`, ae = ({
65
- address: t,
66
- chainId: e
67
- }) => {
68
- const s = It(
69
- "aaveLendingPoolV3",
70
- e
71
- );
72
- return A(t, s);
73
- }, Ot = ({
74
- sourceAddress: t,
75
- amount: e
76
- }) => `${t}_${e}`, ne = (t, e) => {
77
- const s = t.slice(0, e), a = t.slice(e);
78
- return { firstPart: s, secondPart: a };
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
- new u(t || "0").shiftedBy(E).toFixed(0, u.ROUND_DOWN)
81
- ), bt = (t) => {
82
- const e = new u(0.01), s = new u(t), a = !s.isZero() && s.lt(e) ? e : s;
83
- return BigInt(a.multipliedBy(100).toFixed(0));
84
- }, ue = ({
85
- vaultAddress: t,
86
- swapData: e,
87
- sendTokenAddress: s,
88
- sendTokenAmount: a,
89
- vaultDepositTokenAddress: n,
90
- minVaultTokensReceivedAmount: o,
91
- routerKey: r = "ONE_INCH",
92
- swapDestinationAmount: c,
93
- swapSlippage: i
94
- }) => {
95
- const d = new u(c).multipliedBy(1 - i / 100).toFixed(0), m = [f(r, { size: 32 }), e];
96
- return [t, [[s, a, m], [n, d]], o];
97
- }, de = ({
98
- receiveAssetAddress: t,
99
- assets: e,
100
- swapData: s,
101
- slippage: a
102
- }) => {
103
- const n = {
104
- srcData: [],
105
- destAmount: new u("0")
106
- }, { srcData: o, destAmount: r } = e?.reduce((c, i) => {
107
- const d = s?.[i.address];
108
- if (!d)
109
- return c;
110
- const m = [
111
- f(d.routerKey, { size: 32 }),
112
- d.rawTransaction.data
113
- ], p = [i.address, i.rawBalance, m];
114
- return {
115
- srcData: [...c.srcData, p],
116
- destAmount: c.destAmount.plus(d.destinationAmount)
117
- };
118
- }, n) ?? n;
119
- return [
120
- o,
121
- [
122
- t,
123
- r.times(1 - a / 100).toFixed(0, u.ROUND_DOWN)
124
- ]
125
- ];
126
- }, Ct = ({
127
- assetAddress: t,
128
- swapQuotes: e,
129
- swapParams: s,
130
- slippageToleranceForContractTransaction: a,
131
- routerKey: n
132
- }) => {
133
- if (!s)
134
- return {
135
- supportedAsset: t,
136
- withdrawData: "",
137
- slippageTolerance: BigInt(0)
138
- };
139
- const { srcData: o, dstData: r } = s, c = o.map(({ asset: m, amount: p }) => {
140
- const g = e?.[Ot({
141
- sourceAddress: m,
142
- amount: p.toString()
143
- })]?.find((x) => x.routerKey === n);
144
- return {
145
- asset: m,
146
- amount: p,
147
- swapData: {
148
- routerKey: f(g?.routerKey ?? "", { size: 32 }),
149
- txData: g?.rawTransaction.data ?? "0x"
150
- }
151
- };
152
- }), i = _(
153
- H,
154
- [c]
155
- ), d = _(q, [
156
- {
157
- encodedSrcData: i,
158
- dstData: {
159
- dstAddress: r.asset,
160
- dstAmount: r.amount
161
- },
162
- slippage: a
163
- }
164
- ]);
165
- return {
166
- supportedAsset: t,
167
- withdrawData: d,
168
- slippageTolerance: a
169
- };
170
- }, le = ({
171
- chainId: t,
172
- txHash: e,
173
- error: s
174
- }) => {
175
- if (t !== D.id || !e || !s)
176
- return !1;
177
- const a = s instanceof Error ? s.message : String(s);
178
- return /\bNo Result\b/i.test(a);
179
- }, Ae = ({
180
- chainId: t,
181
- action: e,
182
- isRabbyWallet: s
183
- }) => e === "update_ondo_prices" && t === D.id && s ? K : t ? k[t] ?? 0 : 0, me = (t, e) => Z[e]?.nativeTokenSymbol === t, pe = ({
184
- nativeTokenBalance: t,
185
- tokenDecimals: e,
186
- gasPrice: s
187
- }) => {
188
- const a = new u(s).multipliedBy(z).shiftedBy(-e), n = new u(t).minus(
189
- a
190
- );
191
- return n.gt("0") ? n : new u("0");
192
- }, Te = (t) => Q.includes(t), ge = (t) => {
193
- const e = Object.values(t).reduce(
194
- (s, { type: a }) => (s[a] = s[a] + 1, s),
195
- { string: 0, number: 0 }
196
- );
197
- if (e.string > 10)
198
- throw new Error("logger params must contain up to 10 string values");
199
- if (e.number > 40)
200
- throw new Error("logger params must contain up to 40 numeric values");
201
- return !0;
202
- }, Lt = (t, e = 150) => t.length > e ? t.substring(0, e) : t, N = (t, e = X) => {
203
- const s = t.toLowerCase();
204
- return e.sort((a, n) => n.length - a.length).find((a) => s.includes(a.toLowerCase()));
205
- }, w = (t) => j[t] ?? J[t], Se = ({
206
- errorMessage: t,
207
- abiErrors: e
208
- }) => {
209
- if (!t || t.includes("User rejected"))
210
- return null;
211
- const s = e.find((o) => t.includes(o));
212
- if (s && N(s))
213
- return w(s);
214
- const a = N(t);
215
- if (a)
216
- return w(a);
217
- const [n] = t.split(s ? "." : "Contract").map((o) => o.trim());
218
- return {
219
- title: "Transaction failed",
220
- hint: `${Lt(n ?? "")} ${s ? `: ${s}` : ""}`
221
- };
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
- value: t,
224
- minimumFractionDigits: e = 2,
225
- maximumFractionDigits: s = 2,
226
- compact: a = !1,
227
- normalize: n = !1
228
- }) => new Intl.NumberFormat("en-US", {
229
- style: "currency",
230
- currency: "USD",
231
- notation: a ? "compact" : void 0,
232
- minimumFractionDigits: e,
233
- maximumFractionDigits: s
234
- }).format(n ? Bt(t) : Number(t)), h = (t) => Mt(t) ? new u(t).toFixed() : "", I = ["₀", "₁", "₂", "₃", "₄", "₅", "₆", "₇", "₈", "₉"], xt = ({
235
- value: t,
236
- decimals: e = 4
237
- }) => {
238
- const s = new u(t);
239
- if (s.isGreaterThan(1) || s.isZero())
240
- return h(s.toFixed(e));
241
- const n = (/e/i.test(t.toString()) ? parseFloat(t.toString()).toFixed(B) : t.toString()).match(/^0\.(0+)(\d+)$/);
242
- if (n) {
243
- const [, o, r] = n;
244
- if (o.length >= e && o.length < I.length)
245
- return `0.0${I[o.length]}${r.slice(0, 3)}`;
246
- }
247
- return h(s.toFixed(e));
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 = Rt(+t, e);
250
- return Ut(a, s);
251
- }, fe = ({
252
- currency: t,
253
- value: e
254
- }) => t === "USD" ? Pt({ value: e }) : `${tt[t]} ${xt({
255
- value: e,
256
- decimals: et[t]
257
- })}`, Ft = (t, e) => new u(
258
- new u(t).toFixed(e, u.ROUND_DOWN)
259
- ).toString(), Wt = (t, e = 3, s = 2) => {
260
- if (t.length <= 5)
261
- return t;
262
- const a = "...";
263
- return t.length <= e + s + a.length ? t : `${t.slice(0, e)}${a}${t.slice(-s)}`;
264
- }, Ne = ({
265
- balance: t,
266
- symbol: e,
267
- precision: s,
268
- truncateSymbol: a
269
- }) => `${Ft(t, s)} ${a ? Wt(e) : e}`, we = (t) => {
270
- if (!t)
271
- return;
272
- const e = t.match(/0x[a-fA-F0-9]{64}/);
273
- if (!e)
274
- return;
275
- const s = e[0];
276
- return `${s.slice(0, 4)}...${s.slice(-3)}`;
277
- }, he = (t) => A(ot, t) || A(rt, t), Ie = (t) => ct.some(
278
- (e) => A(e, t)
279
- ), Oe = (t) => st[t.toLowerCase()] ?? {
280
- symbol: "",
281
- decimals: 18,
282
- address: y
283
- }, Re = (t) => A(t, it) ? at : nt, $t = (t) => `eth_${t}`, be = ({
284
- action: t,
285
- log: e,
286
- symbol: s,
287
- vaultAddress: a,
288
- chainId: n
289
- }) => {
290
- const o = {
291
- [S.SYMBOL.NAME]: s,
292
- [S.CHAIN_ID.NAME]: n,
293
- [S.ADDRESS.NAME]: $t(a)
294
- };
295
- ut[t].forEach((r) => {
296
- e?.(r, o);
297
- });
298
- }, Ce = (t) => At.some((e) => A(e, t)), Le = (t) => dt[t.toLowerCase()] ?? {
299
- symbol: "",
300
- decimals: 18,
301
- address: y
302
- }, Be = (t) => lt[t.toLowerCase()], vt = "0x3333333333333333333333333333333333333333";
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
- const Me = (t) => A(t, vt), Pe = () => M, xe = /* @__PURE__ */ new Map(), P = (t, e) => !e || e.size === 0 ? t : t.map((s) => {
305
- const a = e.get(
306
- s.supportedAsset.toLowerCase()
307
- );
308
- return a ? {
309
- ...s,
310
- withdrawData: a,
311
- // Ondo assets require a hardcoded increased slippage
312
- slippageTolerance: _t
313
- } : s;
314
- }), Yt = (t) => {
315
- const e = t.find(
316
- ({ swapQuotes: s }) => s
317
- );
318
- return e?.swapQuotes ? Object.values(e.swapQuotes)[0]?.map(
319
- ({ routerKey: s }) => s
320
- ) ?? [] : [];
321
- }, Vt = (t, e, s) => t.map(({ asset: a, swapParams: n, swapQuotes: o }) => !n || !o ? {
322
- supportedAsset: a,
323
- withdrawData: "",
324
- slippageTolerance: s
325
- } : Ct({
326
- assetAddress: a,
327
- swapQuotes: o,
328
- swapParams: n,
329
- slippageToleranceForContractTransaction: s,
330
- routerKey: e
331
- })), Gt = async (t, e, s, a, n, o) => {
332
- for (const r of t) {
333
- const c = P(
334
- Vt(
335
- e,
336
- r,
337
- s
338
- ),
339
- o
340
- ), { error: i } = await a(...n, c);
341
- if (!i)
342
- return c;
343
- }
344
- return null;
345
- }, Ue = (t, e, s) => {
346
- const a = (t ?? []).map((n) => ({
347
- supportedAsset: n,
348
- withdrawData: "",
349
- slippageTolerance: e
350
- }));
351
- return P(a, s);
352
- }, Fe = async (t, e, s, a, n) => {
353
- for (const o of t) {
354
- const r = bt(o);
355
- try {
356
- const c = await e(o), i = Yt(
357
- c
358
- ), d = await Gt(
359
- i,
360
- c,
361
- r,
362
- s,
363
- a,
364
- n
365
- );
366
- if (d)
367
- return console.debug(
368
- `[Init Withdraw] Auto slippage simulation succeeded: slippage=${o}%`
369
- ), console.debug("[Init Withdraw] Complex asset data:", d), d;
370
- } catch (c) {
371
- console.error(
372
- `[Init Withdraw] Failed to fetch quotes for slippage=${o}%:`,
373
- c
374
- );
375
- }
376
- }
377
- return null;
378
- }, We = async (t, e, {
379
- fetchAaveSwapParams: s,
380
- fetchAaveSwapQuotes: a,
381
- withdrawAmountD18: n,
382
- slippage: o
383
- }) => Promise.all(
384
- (t ?? []).map(async (r) => {
385
- if (!A(r, e))
386
- return { asset: r };
387
- try {
388
- const i = await s({
389
- withdrawAmountD18: n,
390
- slippage: o
391
- });
392
- if (i?.srcData.length) {
393
- const d = await a({
394
- swapParams: i,
395
- slippage: o
396
- });
397
- return { asset: r, swapParams: i, swapQuotes: d };
398
- }
399
- return { asset: r };
400
- } catch (i) {
401
- return console.error(i), { asset: r };
402
- }
403
- })
404
- ), O = (t) => Math.round(t * 100) / 100, $e = ({
405
- maxSlippage: t,
406
- candidates: e = Dt
407
- }) => {
408
- if (!Number.isFinite(t) || t <= 0)
409
- return [];
410
- const s = O(Math.min(t, 100)), a = e.filter((o) => o > 0 && o <= s).map(O), n = new Set(a);
411
- return n.add(s), n.add(t), Array.from(n).sort((o, r) => o - r);
412
- }, R = 1000000000000000000n, Ht = 1000000n, b = 10000n, C = 100n, T = (t) => {
413
- if (!t) throw new Error("Ondo: empty hex value");
414
- return t.startsWith("0x") ? t : `0x${t}`;
415
- }, l = (t, e) => {
416
- try {
417
- return BigInt(t);
418
- } catch {
419
- throw new Error(
420
- `Ondo: cannot convert "${e}" value "${t}" to bigint`
421
- );
422
- }
423
- }, L = (t) => t ? ft(T(t), { size: 32 }) : Et, qt = (t) => {
424
- if (!t) throw new Error("Ondo: empty signature");
425
- return yt(Uint8Array.from(atob(t), (e) => e.charCodeAt(0)));
426
- }, ve = (t) => ({
427
- quotes: t.quotes.map(
428
- (e) => ({
429
- chainId: l(e.chainId, "chainId"),
430
- attestationId: l(e.attestationId, "attestationId"),
431
- userId: T(e.userId),
432
- asset: e.asset,
433
- price: l(e.price, "price"),
434
- quantity: l(e.quantity, "quantity"),
435
- expiration: l(e.expiration, "expiration"),
436
- side: Number(e.side),
437
- additionalData: T(e.additionalData)
438
- })
439
- ),
440
- signatures: t.signatures.map(T)
441
- }), Kt = (t, e, s) => {
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
- return (c + i - 1n) / i;
444
- }, Ye = ({
445
- attestation: t,
446
- chainId: e,
447
- slippagePercent: s
448
- }) => {
449
- const a = l(t.tokenAmount, "tokenAmount"), n = l(t.price, "price");
450
- return _(Nt, [
451
- {
452
- attestationSignature: qt(t.signature),
453
- quote: {
454
- chainId: e,
455
- attestationId: l(t.attestationId, "attestationId"),
456
- userId: L(t.userId),
457
- asset: t.assetAddress,
458
- price: n,
459
- quantity: a,
460
- expiration: l(t.expiration, "expiration"),
461
- side: Number(t.side),
462
- additionalData: L(t.additionalData)
463
- },
464
- amountOutMinimum: Kt(
465
- a,
466
- n,
467
- s
468
- )
469
- }
470
- ]);
471
- };
472
- export {
473
- te as $,
474
- Rt as A,
475
- ie as B,
476
- Ae as C,
477
- bt as D,
478
- xe as E,
479
- we as F,
480
- ae as G,
481
- Ie as H,
482
- he as I,
483
- Ce as J,
484
- Me as K,
485
- me as L,
486
- Te as M,
487
- be as N,
488
- ve as O,
489
- P,
490
- ce as Q,
491
- Se as R,
492
- re as S,
493
- se as T,
494
- le as U,
495
- ne as V,
496
- $t as W,
497
- Wt as X,
498
- Gt as Y,
499
- Fe as Z,
500
- ge as _,
501
- Ct as a,
502
- _e as a0,
503
- A as a1,
504
- Pt as a2,
505
- De as a3,
506
- Bt as a4,
507
- jt as a5,
508
- vt as a6,
509
- xt as a7,
510
- Jt as a8,
511
- Ut as a9,
512
- Mt as aa,
513
- ye as ab,
514
- h as ac,
515
- qt as b,
516
- Vt as c,
517
- Ot as d,
518
- de as e,
519
- ue as f,
520
- Xt as g,
521
- Ue as h,
522
- Ye as i,
523
- We as j,
524
- Yt as k,
525
- Ft as l,
526
- fe as m,
527
- Ee as n,
528
- Ne as o,
529
- $e as p,
530
- ee as q,
531
- It as r,
532
- oe as s,
533
- N as t,
534
- Oe as u,
535
- Re as v,
536
- Le as w,
537
- Be as x,
538
- Pe as y,
539
- pe as z
540
- };
package/ondo-rQybmFLf.cjs DELETED
@@ -1 +0,0 @@
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;