@dhedge/trading-widget 6.2.2 → 6.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dytm-3a5llKkf.js DELETED
@@ -1,911 +0,0 @@
1
- import { hyperEvm as F, mainnet as w, polygon as Z, optimism as J, base as tt, arbitrum as et } from "wagmi/chains";
2
- import { aq as st, ao as nt, ap as at, a as b, q as D, ar as rt, as as ot, a5 as it, ak as ct, a3 as ut, b as dt, ae as pt, Z as v, aj as lt, at as Y, e as mt, d as yt, M as At, R as gt, P as Et, au as ht, av as ft, Q as Tt, N as _t, ah as T, _ as St, W as wt, X as bt, U as Dt, aw as G, ax as Rt, ay as It, az as Nt, aA as Ot, aB as Ct, ad as Mt } from "./gmx-Cyz_GmV5.js";
3
- import u from "bignumber.js";
4
- import { zeroHash as xt, bytesToHex as Lt, pad as Bt, stringToHex as R, encodeAbiParameters as h, encodeFunctionData as g, erc20Abi as W, maxUint256 as I } from "viem";
5
- const xe = typeof window < "u", Le = [
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
- ], Pt = [
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
- ], Ut = [
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
- ], Be = [
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: Ut
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
- ], k = [
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
- ], $t = [
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
- ], Ft = [
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
- ], S = {
179
- stringErrors: {
180
- // Ondo tokenized assets trade only during market hours; the full message
181
- // includes a dynamic reopen time (e.g. "QUBTon is currently closed for
182
- // trading. It will be open in 29 minutes."), so there is no fixed literal
183
- // the registry could key on.
184
- "currently closed for trading": {
185
- title: "The market for this tokenized asset is closed right now",
186
- hint: "Wait until the market reopens (the error message says when) and simply retry."
187
- },
188
- // Synthetix revert hit when a vault still holds deprecated synths.
189
- "Synth exchange suspended. Operation prohibited": {
190
- title: "Vault includes deprecated synths in portfolio",
191
- hint: "Redeem deprecated synth to be able to withdraw."
192
- }
193
- },
194
- selectorErrors: {
195
- // EasySwapperV2 swap periphery (see core-kit/abi/easy-swapper-v2.ts).
196
- "0x54971d46": {
197
- signature: "SwapFailed(address,(address,uint256,(bytes32,bytes)),bytes)",
198
- title: "The token swap failed to execute",
199
- hint: "Your assets are still in your wallet — try again, or retry with a higher slippage tolerance."
200
- },
201
- "0x81a815ef": {
202
- signature: "InsufficientAmountReceived(address,uint256,uint256)",
203
- title: "Swap output was below the minimum received amount",
204
- hint: "Increase slippage tolerance and try again."
205
- }
206
- }
207
- }, H = (t) => ({
208
- stringErrors: {
209
- ...t.stringErrors,
210
- ...S.stringErrors
211
- },
212
- selectorErrors: {
213
- ...t.selectorErrors,
214
- ...S.selectorErrors
215
- }
216
- }), vt = [
217
- "https://cdn.jsdelivr.net/gh/dhedge/V2-Public@master/readmes/errorCodes/registry.json",
218
- "https://raw.githubusercontent.com/dhedge/V2-Public/master/readmes/errorCodes/registry.json"
219
- ], Yt = 1, Gt = 1e4, N = 2e6, Wt = 2e3, kt = 500, Ht = 120, Vt = 300, Kt = 4, qt = /^dh\d{1,3}$/i, V = /[\u0000-\u001f\u007f]/, jt = /https?:\/\/|[<>`]/i, Xt = (t) => t.length <= Ht && !V.test(t) && (qt.test(t) || t.length >= Kt), A = (t) => typeof t == "string" && t.length > 0 && t.length <= Vt && !V.test(t) && !jt.test(t);
220
- let K = S, _ = null;
221
- const q = () => K, zt = (t) => {
222
- K = H(t);
223
- }, Qt = (t) => {
224
- const e = t;
225
- if (e?.schemaVersion !== Yt)
226
- throw new Error(
227
- `Unsupported error registry schemaVersion: ${String(e?.schemaVersion)}`
228
- );
229
- const s = {};
230
- for (const [r, a] of Object.entries(e.stringErrors ?? {}))
231
- a?.curated === !0 && Xt(r) && A(a.description) && A(a.action) && (s[r] = { title: a.description, hint: a.action });
232
- const n = {};
233
- for (const [r, a] of Object.entries(e.selectorErrors ?? {}))
234
- a?.curated === !0 && /^0x[0-9a-f]{8}$/.test(r) && A(a.signature) && A(a.description) && A(a.action) && (n[r] = {
235
- signature: a.signature,
236
- title: a.description,
237
- hint: a.action
238
- });
239
- if (!Object.keys(s).length)
240
- throw new Error("Error registry contained no curated string errors");
241
- if (Object.keys(s).length > Wt || Object.keys(n).length > kt)
242
- throw new Error("Error registry exceeded expected entry counts");
243
- return { stringErrors: s, selectorErrors: n };
244
- }, Zt = async ({
245
- timeoutMs: t = Gt
246
- } = {}) => {
247
- const e = [];
248
- for (const s of vt) {
249
- const n = new AbortController(), r = setTimeout(() => n.abort(), t);
250
- try {
251
- const a = await fetch(s, {
252
- headers: { accept: "application/json" },
253
- signal: n.signal
254
- });
255
- if (!a.ok) throw new Error(`HTTP ${a.status}`);
256
- const o = Number(a.headers.get("content-length"));
257
- if (o > N)
258
- throw new Error(`Response too large: ${o} bytes`);
259
- const i = await a.text();
260
- if (i.length > N)
261
- throw new Error(`Response too large: ${i.length} chars`);
262
- return H(Qt(JSON.parse(i)));
263
- } catch (a) {
264
- e.push(
265
- `${s}: ${a instanceof Error ? a.message : String(a)}`
266
- );
267
- } finally {
268
- clearTimeout(r);
269
- }
270
- }
271
- throw new Error(`All error registry sources failed: ${e.join("; ")}`);
272
- }, Pe = () => (_ ?? (_ = Zt().then(zt).catch(() => {
273
- _ = null;
274
- })), _), Jt = () => typeof window < "u";
275
- function te() {
276
- return Jt() && typeof window.ethereum < "u";
277
- }
278
- async function Ue(t) {
279
- try {
280
- if (te())
281
- return window.ethereum.request({
282
- method: "wallet_watchAsset",
283
- params: {
284
- type: "ERC20",
285
- options: t
286
- }
287
- });
288
- } catch {
289
- return !1;
290
- }
291
- return !1;
292
- }
293
- const l = (t, e) => t?.toLowerCase() === e?.toLowerCase(), $e = (t) => l(t, st), E = (t) => {
294
- if (!t) throw new Error("Cannot prefix an empty hex value");
295
- return t.startsWith("0x") ? t : `0x${t}`;
296
- }, p = (t, e) => {
297
- try {
298
- return BigInt(t);
299
- } catch {
300
- throw new Error(`Cannot convert "${e}" value "${t}" to bigint`);
301
- }
302
- }, O = (t) => t ? Bt(E(t), { size: 32 }) : xt, ee = (t) => {
303
- if (!t) throw new Error("Cannot decode an empty base64 string");
304
- return Lt(Uint8Array.from(atob(t), (e) => e.charCodeAt(0)));
305
- }, se = (t, e) => at[e]?.[t] ?? b, Fe = (t) => nt[t], ve = (t) => t && `${t.substring(0, 6)}...${t.substring(
306
- t.length - 4,
307
- t.length
308
- )}`, Ye = ({
309
- address: t,
310
- chainId: e
311
- }) => {
312
- const s = se(
313
- "aaveLendingPoolV3",
314
- e
315
- );
316
- return l(t, s);
317
- }, ne = ({
318
- sourceAddress: t,
319
- amount: e
320
- }) => `${t}_${e}`, Ge = (t, e) => {
321
- const s = t.slice(0, e), n = t.slice(e);
322
- return { firstPart: s, secondPart: n };
323
- }, ae = (t, e) => t / e * 100, We = (t) => t < 1 ? 4 : t < 10 ? 3 : 2, ke = (t, e = D) => new u(t.toString()).shiftedBy(e).toFixed(0), He = (t, e, s, n) => new u(e).dividedBy(s).multipliedBy(t).shiftedBy(-(n || D)).toNumber(), Ve = (t) => BigInt(
324
- new u(t || "0").shiftedBy(D).toFixed(0, u.ROUND_DOWN)
325
- ), j = (t) => {
326
- const e = new u(0.01), s = new u(t), n = !s.isZero() && s.lt(e) ? e : s;
327
- return BigInt(n.multipliedBy(100).toFixed(0));
328
- }, Ke = ({
329
- chainId: t,
330
- slippage: e
331
- }) => t === F.id ? BigInt(0) : j(e), qe = ({
332
- vaultAddress: t,
333
- swapData: e,
334
- sendTokenAddress: s,
335
- sendTokenAmount: n,
336
- vaultDepositTokenAddress: r,
337
- minVaultTokensReceivedAmount: a,
338
- routerKey: o = "ONE_INCH",
339
- swapDestinationAmount: i,
340
- swapSlippage: c
341
- }) => {
342
- const d = new u(i).multipliedBy(1 - c / 100).toFixed(0), m = [R(o, { size: 32 }), e];
343
- return [t, [[s, n, m], [r, d]], a];
344
- }, je = ({
345
- receiveAssetAddress: t,
346
- assets: e,
347
- swapData: s,
348
- slippage: n
349
- }) => {
350
- const r = {
351
- srcData: [],
352
- destAmount: new u("0")
353
- }, { srcData: a, destAmount: o } = e?.reduce((i, c) => {
354
- const d = s?.[c.address];
355
- if (!d)
356
- return i;
357
- const m = [
358
- R(d.routerKey, { size: 32 }),
359
- d.rawTransaction.data
360
- ], y = [c.address, c.rawBalance, m];
361
- return {
362
- srcData: [...i.srcData, y],
363
- destAmount: i.destAmount.plus(d.destinationAmount)
364
- };
365
- }, r) ?? r;
366
- return [
367
- a,
368
- [
369
- t,
370
- o.times(1 - n / 100).toFixed(0, u.ROUND_DOWN)
371
- ]
372
- ];
373
- }, re = ({
374
- assetAddress: t,
375
- swapQuotes: e,
376
- swapParams: s,
377
- slippageToleranceForContractTransaction: n,
378
- routerKey: r
379
- }) => {
380
- if (!s)
381
- return {
382
- supportedAsset: t,
383
- withdrawData: "",
384
- slippageTolerance: BigInt(0)
385
- };
386
- const { srcData: a, dstData: o } = s, i = a.map(({ asset: m, amount: y }) => {
387
- const f = e?.[ne({
388
- sourceAddress: m,
389
- amount: y.toString()
390
- })]?.find((Q) => Q.routerKey === r);
391
- return {
392
- asset: m,
393
- amount: y,
394
- swapData: {
395
- routerKey: R(f?.routerKey ?? "", { size: 32 }),
396
- txData: f?.rawTransaction.data ?? "0x"
397
- }
398
- };
399
- }), c = h(
400
- rt,
401
- [i]
402
- ), d = h(ot, [
403
- {
404
- encodedSrcData: c,
405
- dstData: {
406
- dstAddress: o.asset,
407
- dstAmount: o.amount
408
- },
409
- slippage: n
410
- }
411
- ]);
412
- return {
413
- supportedAsset: t,
414
- withdrawData: d,
415
- slippageTolerance: n
416
- };
417
- }, Xe = ({
418
- chainId: t,
419
- txHash: e,
420
- error: s
421
- }) => {
422
- if (t !== w.id || !e || !s)
423
- return !1;
424
- const n = s instanceof Error ? s.message : String(s);
425
- return /\bNo Result\b/i.test(n);
426
- }, ze = ({
427
- chainId: t,
428
- action: e,
429
- isRabbyWallet: s
430
- }) => e === "update_ondo_prices" && t === w.id && s ? it : t ? ct[t] ?? 0 : 0, Qe = (t, e) => dt[e]?.nativeTokenSymbol === t, Ze = ({
431
- nativeTokenBalance: t,
432
- tokenDecimals: e,
433
- gasPrice: s
434
- }) => {
435
- const n = new u(s).multipliedBy(ut).shiftedBy(-e), r = new u(t).minus(
436
- n
437
- );
438
- return r.gt("0") ? r : new u("0");
439
- }, Je = (t) => pt.includes(t), ts = (t) => {
440
- const e = Object.values(t).reduce(
441
- (s, { type: n }) => (s[n] = s[n] + 1, s),
442
- { string: 0, number: 0 }
443
- );
444
- if (e.string > 10)
445
- throw new Error("logger params must contain up to 10 string values");
446
- if (e.number > 40)
447
- throw new Error("logger params must contain up to 40 numeric values");
448
- return !0;
449
- }, oe = (t, e = 150) => t.length > e ? t.substring(0, e) : t, X = () => ({
450
- ...q().stringErrors,
451
- ...lt
452
- }), ie = () => [
453
- ...Object.keys(X()),
454
- ...Object.keys(v)
455
- ], ce = /^dh\d+$/i, ue = (t, e) => ce.test(e) ? new RegExp(`\\b${e}\\b`, "i").test(t) : t.includes(e.toLowerCase()), C = (t, e) => {
456
- const s = t.toLowerCase();
457
- return [...e ?? ie()].sort((n, r) => r.length - n.length).find((n) => ue(s, n));
458
- }, M = (t) => X()[t] ?? v[t], de = /\b0x[0-9a-f]{8}\b/i, pe = (t) => t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), le = (t) => {
459
- const { selectorErrors: e } = q(), s = t.match(de)?.[0]?.toLowerCase(), n = s ? e[s] : void 0;
460
- if (n)
461
- return { title: n.title, hint: n.hint };
462
- const r = Object.values(e).find(
463
- (a) => new RegExp(
464
- `\\b${pe(a.signature.split("(")[0] ?? "")}\\b`
465
- ).test(t)
466
- );
467
- return r ? { title: r.title, hint: r.hint } : void 0;
468
- }, es = ({
469
- errorMessage: t,
470
- abiErrors: e
471
- }) => {
472
- if (!t || t.includes("User rejected"))
473
- return null;
474
- const s = e.find((o) => t.includes(o));
475
- if (s) {
476
- const o = C(s);
477
- if (o)
478
- return M(o);
479
- }
480
- const n = C(t);
481
- if (n)
482
- return M(n);
483
- const r = le(t);
484
- if (r)
485
- return r;
486
- const [a] = t.split(s ? "." : "Contract").map((o) => o.trim());
487
- return {
488
- title: "Transaction failed",
489
- hint: `${oe(a ?? "")} ${s ? `: ${s}` : ""}`
490
- };
491
- }, ss = (t) => typeof t == "number" && Number.isFinite(t), ns = (t) => typeof t == "bigint" && t !== BigInt(0), me = (t, e = Y) => new u(t).shiftedBy(-e).toNumber(), ye = (t) => !isNaN(parseFloat(t)) && !isNaN(t), Ae = ({
492
- value: t,
493
- minimumFractionDigits: e = 2,
494
- maximumFractionDigits: s = 2,
495
- compact: n = !1,
496
- normalize: r = !1
497
- }) => new Intl.NumberFormat("en-US", {
498
- style: "currency",
499
- currency: "USD",
500
- notation: n ? "compact" : void 0,
501
- minimumFractionDigits: e,
502
- maximumFractionDigits: s
503
- }).format(r ? me(t) : Number(t)), x = (t) => ye(t) ? new u(t).toFixed() : "", L = ["₀", "₁", "₂", "₃", "₄", "₅", "₆", "₇", "₈", "₉"], ge = ({
504
- value: t,
505
- decimals: e = 4
506
- }) => {
507
- const s = new u(t);
508
- if (s.isGreaterThan(1) || s.isZero())
509
- return x(s.toFixed(e));
510
- const r = (/e/i.test(t.toString()) ? parseFloat(t.toString()).toFixed(Y) : t.toString()).match(/^0\.(0+)(\d+)$/);
511
- if (r) {
512
- const [, a, o] = r;
513
- if (a.length >= e && a.length < L.length)
514
- return `0.0${L[a.length]}${o.slice(0, 3)}`;
515
- }
516
- return x(s.toFixed(e));
517
- }, Ee = (t, e = 0) => `${t.toLocaleString("en-US", { maximumFractionDigits: e })}%`, as = (t) => t.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), rs = (t, e, s = 0) => {
518
- const n = ae(+t, e);
519
- return Ee(n, s);
520
- }, os = ({
521
- currency: t,
522
- value: e
523
- }) => t === "USD" ? Ae({ value: e }) : `${mt[t]} ${ge({
524
- value: e,
525
- decimals: yt[t]
526
- })}`, he = (t, e) => new u(
527
- new u(t).toFixed(e, u.ROUND_DOWN)
528
- ).toString(), fe = (t, e = 3, s = 2) => {
529
- if (t.length <= 5)
530
- return t;
531
- const n = "...";
532
- return t.length <= e + s + n.length ? t : `${t.slice(0, e)}${n}${t.slice(-s)}`;
533
- }, is = ({
534
- balance: t,
535
- symbol: e,
536
- precision: s,
537
- truncateSymbol: n
538
- }) => `${he(t, s)} ${n ? fe(e) : e}`, cs = (t) => {
539
- if (!t)
540
- return;
541
- const e = t.match(/0x[a-fA-F0-9]{64}/);
542
- if (!e)
543
- return;
544
- const s = e[0];
545
- return `${s.slice(0, 4)}...${s.slice(-3)}`;
546
- }, us = (t) => l(ht, t) || l(ft, t), ds = (t) => _t.some(
547
- (e) => l(e, t)
548
- ), ps = (t) => At[t.toLowerCase()] ?? {
549
- symbol: "",
550
- decimals: 18,
551
- address: b
552
- }, ls = (t) => l(t, Tt) ? gt : Et, Te = (t) => `eth_${t}`, ms = ({
553
- action: t,
554
- log: e,
555
- symbol: s,
556
- vaultAddress: n,
557
- chainId: r
558
- }) => {
559
- const a = {
560
- [T.SYMBOL.NAME]: s,
561
- [T.CHAIN_ID.NAME]: r,
562
- [T.ADDRESS.NAME]: Te(n)
563
- };
564
- St[t].forEach((o) => {
565
- e?.(o, a);
566
- });
567
- }, ys = (t) => Dt.some((e) => l(e, t)), As = (t) => wt[t.toLowerCase()] ?? {
568
- symbol: "",
569
- decimals: 18,
570
- address: b
571
- }, gs = (t) => bt[t.toLowerCase()], _e = "0x3333333333333333333333333333333333333333";
572
- et.id + "", Ct.address, tt.id + "", Ot.address, J.id + "", Nt.address, Z.id + "", It.address, w.id + "", Rt.address, F.id + "", G.address;
573
- const Es = (t) => l(t, _e), hs = () => G, fs = /* @__PURE__ */ new Map(), z = (t, e) => !e || e.size === 0 ? t : t.map((s) => {
574
- const n = e.get(
575
- s.supportedAsset.toLowerCase()
576
- );
577
- return n ? {
578
- ...s,
579
- withdrawData: n.withdrawData,
580
- slippageTolerance: n.slippageTolerance
581
- } : s;
582
- }), Se = (t) => {
583
- const e = t.find(
584
- ({ swapQuotes: s }) => s
585
- );
586
- return e?.swapQuotes ? Object.values(e.swapQuotes)[0]?.map(
587
- ({ routerKey: s }) => s
588
- ) ?? [] : [];
589
- }, we = (t, e, s) => t.map(({ asset: n, swapParams: r, swapQuotes: a }) => !r || !a ? {
590
- supportedAsset: n,
591
- withdrawData: "",
592
- slippageTolerance: s
593
- } : re({
594
- assetAddress: n,
595
- swapQuotes: a,
596
- swapParams: r,
597
- slippageToleranceForContractTransaction: s,
598
- routerKey: e
599
- })), be = async (t, e, s, n, r, a) => {
600
- for (const o of t) {
601
- const i = z(
602
- we(
603
- e,
604
- o,
605
- s
606
- ),
607
- a
608
- ), { error: c } = await n(...r, i);
609
- if (!c)
610
- return i;
611
- }
612
- return null;
613
- }, Ts = (t, e, s) => {
614
- const n = (t ?? []).map((r) => ({
615
- supportedAsset: r,
616
- withdrawData: "",
617
- slippageTolerance: e
618
- }));
619
- return z(n, s);
620
- }, _s = async (t, e, s, n, r) => {
621
- for (const a of t) {
622
- const o = j(a);
623
- try {
624
- const i = await e(a), c = Se(
625
- i
626
- ), d = await be(
627
- c,
628
- i,
629
- o,
630
- s,
631
- n,
632
- r
633
- );
634
- if (d)
635
- return console.debug(
636
- `[Init Withdraw] Auto slippage simulation succeeded: slippage=${a}%`
637
- ), console.debug("[Init Withdraw] Complex asset data:", d), d;
638
- } catch (i) {
639
- console.error(
640
- `[Init Withdraw] Failed to fetch quotes for slippage=${a}%:`,
641
- i
642
- );
643
- }
644
- }
645
- return null;
646
- }, Ss = async (t, e, {
647
- fetchAaveSwapParams: s,
648
- fetchAaveSwapQuotes: n,
649
- withdrawAmountD18: r,
650
- slippage: a
651
- }) => Promise.all(
652
- (t ?? []).map(async (o) => {
653
- if (!l(o, e))
654
- return { asset: o };
655
- try {
656
- const c = await s({
657
- withdrawAmountD18: r,
658
- slippage: a
659
- });
660
- if (c?.srcData.length) {
661
- const d = await n({
662
- swapParams: c,
663
- slippage: a
664
- });
665
- return { asset: o, swapParams: c, swapQuotes: d };
666
- }
667
- return { asset: o };
668
- } catch (c) {
669
- return console.error(c), { asset: o };
670
- }
671
- })
672
- ), B = (t) => Math.round(t * 100) / 100, ws = ({
673
- maxSlippage: t,
674
- candidates: e = Mt
675
- }) => {
676
- if (!Number.isFinite(t) || t <= 0)
677
- return [];
678
- const s = B(Math.min(t, 100)), n = e.filter((a) => a > 0 && a <= s).map(B), r = new Set(n);
679
- return r.add(s), r.add(t), Array.from(r).sort((a, o) => a - o);
680
- }, P = 1000000000000000000n, De = 1000000n, U = 10000n, $ = 100n, bs = (t) => ({
681
- quotes: t.quotes.map(
682
- (e) => ({
683
- chainId: p(e.chainId, "chainId"),
684
- attestationId: p(e.attestationId, "attestationId"),
685
- userId: E(e.userId),
686
- asset: e.asset,
687
- price: p(e.price, "price"),
688
- quantity: p(e.quantity, "quantity"),
689
- expiration: p(e.expiration, "expiration"),
690
- side: Number(e.side),
691
- additionalData: E(e.additionalData)
692
- })
693
- ),
694
- signatures: t.signatures.map(E)
695
- }), Re = (t, e, s) => {
696
- const n = BigInt(Math.max(0, Math.round(s * 100))), r = n > $ ? $ : n, a = U - r, i = t * e / P * a * De, c = U * P;
697
- return (i + c - 1n) / c;
698
- }, Ie = (t, e) => ({
699
- chainId: e,
700
- attestationId: p(t.attestationId, "attestationId"),
701
- userId: O(t.userId),
702
- asset: t.assetAddress,
703
- price: p(t.price, "price"),
704
- quantity: p(t.tokenAmount, "tokenAmount"),
705
- expiration: p(t.expiration, "expiration"),
706
- side: Number(t.side),
707
- additionalData: O(t.additionalData)
708
- }), Ds = ({
709
- attestation: t,
710
- chainId: e,
711
- slippagePercent: s
712
- }) => {
713
- const n = Ie(t, e);
714
- return h(Pt, [
715
- {
716
- attestationSignature: ee(t.signature),
717
- quote: n,
718
- amountOutMinimum: Re(
719
- n.quantity,
720
- n.price,
721
- s
722
- )
723
- }
724
- ]);
725
- }, Rs = (t) => [...t.reduce(
726
- (s, n) => s.has(n.accountId) ? s : s.set(n.accountId, n),
727
- /* @__PURE__ */ new Map()
728
- ).values()].map(({ accountId: s, marketId: n }) => ({
729
- accountId: s,
730
- marketId: n,
731
- collaterals: t.filter(
732
- (r) => r.accountId === s && !r.isDebt
733
- ),
734
- debt: t.find(
735
- (r) => r.accountId === s && r.isDebt
736
- )
737
- })), Is = ({
738
- collateral: t,
739
- dytmOffice: e,
740
- processor: s,
741
- gmToken: n,
742
- ondoGMSwap: r,
743
- usdc: a,
744
- gmAmount: o,
745
- amountOutMinimum: i,
746
- signature: c,
747
- quote: d
748
- }) => [
749
- {
750
- // 1 · pull GM collateral out of the split account -> processor
751
- to: e,
752
- data: g({
753
- abi: k,
754
- functionName: "withdraw",
755
- args: [
756
- {
757
- account: t.accountId,
758
- tokenId: t.tokenId,
759
- receiver: s,
760
- assets: o,
761
- shares: 0n,
762
- extraData: "0x"
763
- }
764
- ]
765
- })
766
- },
767
- {
768
- // 2 · approve the GM token to Ondo's swap contract
769
- to: n,
770
- data: g({
771
- abi: W,
772
- functionName: "approve",
773
- args: [r, o]
774
- })
775
- },
776
- {
777
- // 3 · redeem GM -> USDC with the signed attestation
778
- to: r,
779
- data: g({
780
- abi: $t,
781
- functionName: "swapExactInWithAttestation",
782
- args: [n, o, a, i, c, d]
783
- })
784
- }
785
- ], Ns = ({
786
- accountId: t,
787
- debtKey: e,
788
- dytmOffice: s,
789
- usdc: n
790
- }) => [
791
- {
792
- // approve USDC to the DYTM Office for the repay
793
- to: n,
794
- data: g({
795
- abi: W,
796
- functionName: "approve",
797
- args: [s, I]
798
- })
799
- },
800
- {
801
- // repay the slice's whole USDC debt
802
- to: s,
803
- data: g({
804
- abi: k,
805
- functionName: "repay",
806
- args: [
807
- {
808
- account: t,
809
- key: e,
810
- withCollateralType: 0,
811
- // DytmParamStructs.TokenType.NONE
812
- assets: I,
813
- // repay all
814
- shares: 0n,
815
- extraData: "0x"
816
- }
817
- ]
818
- })
819
- }
820
- ], Os = ({
821
- actions: t,
822
- outputAsset: e,
823
- minOutputAmount: s
824
- }) => h(Ft, [
825
- { actions: t, outputAsset: e, minOutputAmount: s }
826
- ]);
827
- export {
828
- bs as $,
829
- se as A,
830
- q as B,
831
- We as C,
832
- C as D,
833
- fs as E,
834
- ps as F,
835
- ls as G,
836
- As as H,
837
- gs as I,
838
- hs as J,
839
- Ze as K,
840
- ae as L,
841
- He as M,
842
- ze as N,
843
- j as O,
844
- cs as P,
845
- Rs as Q,
846
- Ye as R,
847
- ds as S,
848
- S as T,
849
- us as U,
850
- ys as V,
851
- Es as W,
852
- Qe as X,
853
- Je as Y,
854
- ms as Z,
855
- Ie as _,
856
- zt as a,
857
- z as a0,
858
- Ve as a1,
859
- es as a2,
860
- ke as a3,
861
- ve as a4,
862
- Xe as a5,
863
- Ge as a6,
864
- p as a7,
865
- O as a8,
866
- Te as a9,
867
- fe as aa,
868
- be as ab,
869
- _s as ac,
870
- ts as ad,
871
- $e as ae,
872
- ss as af,
873
- l as ag,
874
- Ae as ah,
875
- ns as ai,
876
- me as aj,
877
- Be as ak,
878
- Le as al,
879
- _e as am,
880
- ge as an,
881
- Ue as ao,
882
- Ee as ap,
883
- ye as aq,
884
- as as ar,
885
- x as as,
886
- ee as b,
887
- re as c,
888
- we as d,
889
- Is as e,
890
- Ns as f,
891
- ne as g,
892
- je as h,
893
- qe as i,
894
- xe as j,
895
- Re as k,
896
- Ts as l,
897
- Ds as m,
898
- Os as n,
899
- Ss as o,
900
- Pe as p,
901
- E as q,
902
- Se as r,
903
- Zt as s,
904
- he as t,
905
- os as u,
906
- rs as v,
907
- is as w,
908
- ws as x,
909
- Ke as y,
910
- Fe as z
911
- };