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