@dhedge/trading-widget 5.11.0 → 5.12.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/README.md +51 -22
- package/const.cjs +1 -1
- package/const.js +30 -29
- package/core-kit/const/default-data.d.ts +1 -0
- package/core-kit/hooks/trading/withdraw-v2/init-step/use-fetch-init-withdraw-complex-asset-data.d.ts +2 -1
- package/core-kit/utils/complex-withdraw-asset-data.d.ts +6 -0
- package/core-kit/utils/deposit.d.ts +3 -1
- package/core-kit/utils/index.d.ts +1 -0
- package/core-kit/utils/slippage-auto-simulation.d.ts +8 -0
- package/core-kit/utils/transaction.d.ts +2 -1
- package/gmx-C0ZAKA5h.cjs +1 -0
- package/{gmx-BroDb_q_.js → gmx-CKRd5jcU.js} +283 -270
- package/index.cjs +1 -1
- package/index.js +3195 -3132
- package/package.json +1 -1
- package/slippage-auto-simulation-CI3FlyW_.js +400 -0
- package/slippage-auto-simulation-Cy2F0kyJ.cjs +1 -0
- package/style.css +1 -1
- package/trading-widget/providers/config-provider/config-provider.types.d.ts +1 -1
- package/trading-widget/providers/config-provider/index.d.ts +1 -0
- package/trading-widget/providers/config-provider/use-resolved-default-swap-transaction-slippage.d.ts +1 -0
- package/utils.cjs +1 -1
- package/utils.js +30 -28
- package/complex-withdraw-asset-data-DKDPznHy.cjs +0 -1
- package/complex-withdraw-asset-data-DzhKTztw.js +0 -366
- package/gmx-CLiWBUH_.cjs +0 -1
package/package.json
CHANGED
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import i from "bignumber.js";
|
|
2
|
+
import { ak as L, ai as R, aj as b, b as T, q as S, al as B, am as O, a3 as C, c as F, a8 as M, ae as P, ad as $, Z as v, an as y, f as U, e as x, M as W, R as K, P as V, ao as Y, ap as G, Q as Z, N as H, ab as g, _ as Q, W as k, X as j, U as q, a7 as z } from "./gmx-CKRd5jcU.js";
|
|
3
|
+
import { stringToHex as f, encodeAbiParameters as _ } from "viem";
|
|
4
|
+
const X = () => typeof window < "u";
|
|
5
|
+
function J() {
|
|
6
|
+
return X() && typeof window.ethereum < "u";
|
|
7
|
+
}
|
|
8
|
+
async function wt(t) {
|
|
9
|
+
try {
|
|
10
|
+
if (J())
|
|
11
|
+
return window.ethereum.request({
|
|
12
|
+
method: "wallet_watchAsset",
|
|
13
|
+
params: {
|
|
14
|
+
type: "ERC20",
|
|
15
|
+
options: t
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
} catch {
|
|
19
|
+
return !1;
|
|
20
|
+
}
|
|
21
|
+
return !1;
|
|
22
|
+
}
|
|
23
|
+
const l = (t, e) => t?.toLowerCase() === e?.toLowerCase(), Dt = (t) => l(t, L), tt = (t, e) => b[e]?.[t] ?? T, Nt = (t) => R[t], Et = (t) => t && `${t.substring(0, 6)}...${t.substring(
|
|
24
|
+
t.length - 4,
|
|
25
|
+
t.length
|
|
26
|
+
)}`, ht = ({
|
|
27
|
+
address: t,
|
|
28
|
+
chainId: e
|
|
29
|
+
}) => {
|
|
30
|
+
const s = tt(
|
|
31
|
+
"aaveLendingPoolV3",
|
|
32
|
+
e
|
|
33
|
+
);
|
|
34
|
+
return l(t, s);
|
|
35
|
+
}, et = ({
|
|
36
|
+
sourceAddress: t,
|
|
37
|
+
amount: e
|
|
38
|
+
}) => `${t}_${e}`, yt = (t, e) => {
|
|
39
|
+
const s = t.slice(0, e), a = t.slice(e);
|
|
40
|
+
return { firstPart: s, secondPart: a };
|
|
41
|
+
}, st = (t, e) => t / e * 100, It = (t) => t < 1 ? 4 : t < 10 ? 3 : 2, Lt = (t, e = S) => new i(t.toString()).shiftedBy(e).toFixed(0), Rt = (t, e, s, a) => new i(e).dividedBy(s).multipliedBy(t).shiftedBy(-(a || S)).toNumber(), bt = (t) => BigInt(
|
|
42
|
+
new i(t || "0").shiftedBy(S).toFixed(0, i.ROUND_DOWN)
|
|
43
|
+
), at = (t) => {
|
|
44
|
+
const e = new i(0.01), s = new i(t), a = !s.isZero() && s.lt(e) ? e : s;
|
|
45
|
+
return BigInt(a.multipliedBy(100).toFixed(0));
|
|
46
|
+
}, Bt = ({
|
|
47
|
+
vaultAddress: t,
|
|
48
|
+
swapData: e,
|
|
49
|
+
sendTokenAddress: s,
|
|
50
|
+
sendTokenAmount: a,
|
|
51
|
+
vaultDepositTokenAddress: n,
|
|
52
|
+
minVaultTokensReceivedAmount: r,
|
|
53
|
+
routerKey: o = "ONE_INCH",
|
|
54
|
+
swapDestinationAmount: u,
|
|
55
|
+
swapSlippage: c
|
|
56
|
+
}) => {
|
|
57
|
+
const d = new i(u).multipliedBy(1 - c / 100).toFixed(0), A = [f(o, { size: 32 }), e];
|
|
58
|
+
return [t, [[s, a, A], [n, d]], r];
|
|
59
|
+
}, Ot = ({
|
|
60
|
+
receiveAssetAddress: t,
|
|
61
|
+
assets: e,
|
|
62
|
+
swapData: s,
|
|
63
|
+
slippage: a
|
|
64
|
+
}) => {
|
|
65
|
+
const n = {
|
|
66
|
+
srcData: [],
|
|
67
|
+
destAmount: new i("0")
|
|
68
|
+
}, { srcData: r, destAmount: o } = e?.reduce((u, c) => {
|
|
69
|
+
const d = s?.[c.address];
|
|
70
|
+
if (!d)
|
|
71
|
+
return u;
|
|
72
|
+
const A = [
|
|
73
|
+
f(d.routerKey, { size: 32 }),
|
|
74
|
+
d.rawTransaction.data
|
|
75
|
+
], m = [c.address, c.rawBalance, A];
|
|
76
|
+
return {
|
|
77
|
+
srcData: [...u.srcData, m],
|
|
78
|
+
destAmount: u.destAmount.plus(d.destinationAmount)
|
|
79
|
+
};
|
|
80
|
+
}, n) ?? n;
|
|
81
|
+
return [
|
|
82
|
+
r,
|
|
83
|
+
[
|
|
84
|
+
t,
|
|
85
|
+
o.times(1 - a / 100).toFixed(0, i.ROUND_DOWN)
|
|
86
|
+
]
|
|
87
|
+
];
|
|
88
|
+
}, nt = ({
|
|
89
|
+
assetAddress: t,
|
|
90
|
+
swapQuotes: e,
|
|
91
|
+
swapParams: s,
|
|
92
|
+
slippageToleranceForContractTransaction: a,
|
|
93
|
+
routerKey: n
|
|
94
|
+
}) => {
|
|
95
|
+
if (!s)
|
|
96
|
+
return {
|
|
97
|
+
supportedAsset: t,
|
|
98
|
+
withdrawData: "",
|
|
99
|
+
slippageTolerance: BigInt(0)
|
|
100
|
+
};
|
|
101
|
+
const { srcData: r, dstData: o } = s, u = r.map(({ asset: A, amount: m }) => {
|
|
102
|
+
const p = e?.[et({
|
|
103
|
+
sourceAddress: A,
|
|
104
|
+
amount: m.toString()
|
|
105
|
+
})]?.find((I) => I.routerKey === n);
|
|
106
|
+
return {
|
|
107
|
+
asset: A,
|
|
108
|
+
amount: m,
|
|
109
|
+
swapData: {
|
|
110
|
+
routerKey: f(p?.routerKey ?? "", { size: 32 }),
|
|
111
|
+
txData: p?.rawTransaction.data ?? "0x"
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}), c = _(
|
|
115
|
+
B,
|
|
116
|
+
[u]
|
|
117
|
+
), d = _(O, [
|
|
118
|
+
{
|
|
119
|
+
encodedSrcData: c,
|
|
120
|
+
dstData: {
|
|
121
|
+
dstAddress: o.asset,
|
|
122
|
+
dstAmount: o.amount
|
|
123
|
+
},
|
|
124
|
+
slippage: a
|
|
125
|
+
}
|
|
126
|
+
]);
|
|
127
|
+
return {
|
|
128
|
+
supportedAsset: t,
|
|
129
|
+
withdrawData: d,
|
|
130
|
+
slippageTolerance: a
|
|
131
|
+
};
|
|
132
|
+
}, Ct = (t, e) => F[e]?.nativeTokenSymbol === t, Ft = ({
|
|
133
|
+
nativeTokenBalance: t,
|
|
134
|
+
tokenDecimals: e,
|
|
135
|
+
gasPrice: s
|
|
136
|
+
}) => {
|
|
137
|
+
const a = new i(s).multipliedBy(C).shiftedBy(-e), n = new i(t).minus(
|
|
138
|
+
a
|
|
139
|
+
);
|
|
140
|
+
return n.gt("0") ? n : new i("0");
|
|
141
|
+
}, Mt = (t) => M.includes(t), Pt = (t) => {
|
|
142
|
+
const e = Object.values(t).reduce(
|
|
143
|
+
(s, { type: a }) => (s[a] = s[a] + 1, s),
|
|
144
|
+
{ string: 0, number: 0 }
|
|
145
|
+
);
|
|
146
|
+
if (e.string > 10)
|
|
147
|
+
throw new Error("logger params must contain up to 10 string values");
|
|
148
|
+
if (e.number > 40)
|
|
149
|
+
throw new Error("logger params must contain up to 40 numeric values");
|
|
150
|
+
return !0;
|
|
151
|
+
}, rt = (t, e = 150) => t.length > e ? t.substring(0, e) : t, w = (t, e = P) => {
|
|
152
|
+
const s = t.toLowerCase();
|
|
153
|
+
return e.sort((a, n) => n.length - a.length).find((a) => s.includes(a.toLowerCase()));
|
|
154
|
+
}, D = (t) => $[t] ?? v[t], $t = ({
|
|
155
|
+
errorMessage: t,
|
|
156
|
+
abiErrors: e
|
|
157
|
+
}) => {
|
|
158
|
+
if (!t || t.includes("User rejected"))
|
|
159
|
+
return null;
|
|
160
|
+
const s = e.find((r) => t.includes(r));
|
|
161
|
+
if (s && w(s))
|
|
162
|
+
return D(s);
|
|
163
|
+
const a = w(t);
|
|
164
|
+
if (a)
|
|
165
|
+
return D(a);
|
|
166
|
+
const [n] = t.split(s ? "." : "Contract").map((r) => r.trim());
|
|
167
|
+
return {
|
|
168
|
+
title: "Transaction failed",
|
|
169
|
+
hint: `${rt(n ?? "")} ${s ? `: ${s}` : ""}`
|
|
170
|
+
};
|
|
171
|
+
}, vt = (t) => typeof t == "number" && Number.isFinite(t), Ut = (t) => typeof t == "bigint" && t !== BigInt(0), ot = (t, e = y) => new i(t).shiftedBy(-e).toNumber(), it = (t) => !isNaN(parseFloat(t)) && !isNaN(t), ct = ({
|
|
172
|
+
value: t,
|
|
173
|
+
minimumFractionDigits: e = 2,
|
|
174
|
+
maximumFractionDigits: s = 2,
|
|
175
|
+
compact: a = !1,
|
|
176
|
+
normalize: n = !1
|
|
177
|
+
}) => new Intl.NumberFormat("en-US", {
|
|
178
|
+
style: "currency",
|
|
179
|
+
currency: "USD",
|
|
180
|
+
notation: a ? "compact" : void 0,
|
|
181
|
+
minimumFractionDigits: e,
|
|
182
|
+
maximumFractionDigits: s
|
|
183
|
+
}).format(n ? ot(t) : Number(t)), N = (t) => it(t) ? new i(t).toFixed() : "", E = ["₀", "₁", "₂", "₃", "₄", "₅", "₆", "₇", "₈", "₉"], ut = ({
|
|
184
|
+
value: t,
|
|
185
|
+
decimals: e = 4
|
|
186
|
+
}) => {
|
|
187
|
+
const s = new i(t);
|
|
188
|
+
if (s.isGreaterThan(1) || s.isZero())
|
|
189
|
+
return N(s.toFixed(e));
|
|
190
|
+
const n = (/e/i.test(t.toString()) ? parseFloat(t.toString()).toFixed(y) : t.toString()).match(/^0\.(0+)(\d+)$/);
|
|
191
|
+
if (n) {
|
|
192
|
+
const [, r, o] = n;
|
|
193
|
+
if (r.length >= e && r.length < E.length)
|
|
194
|
+
return `0.0${E[r.length]}${o.slice(0, 3)}`;
|
|
195
|
+
}
|
|
196
|
+
return N(s.toFixed(e));
|
|
197
|
+
}, dt = (t, e = 0) => `${t.toLocaleString("en-US", { maximumFractionDigits: e })}%`, xt = (t) => t.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), Wt = (t, e, s = 0) => {
|
|
198
|
+
const a = st(+t, e);
|
|
199
|
+
return dt(a, s);
|
|
200
|
+
}, Kt = ({
|
|
201
|
+
currency: t,
|
|
202
|
+
value: e
|
|
203
|
+
}) => t === "USD" ? ct({ value: e }) : `${U[t]} ${ut({
|
|
204
|
+
value: e,
|
|
205
|
+
decimals: x[t]
|
|
206
|
+
})}`, lt = (t, e) => new i(
|
|
207
|
+
new i(t).toFixed(e, i.ROUND_DOWN)
|
|
208
|
+
).toString(), At = (t, e = 3, s = 2) => {
|
|
209
|
+
if (t.length <= 5)
|
|
210
|
+
return t;
|
|
211
|
+
const a = "...";
|
|
212
|
+
return t.length <= e + s + a.length ? t : `${t.slice(0, e)}${a}${t.slice(-s)}`;
|
|
213
|
+
}, Vt = ({
|
|
214
|
+
balance: t,
|
|
215
|
+
symbol: e,
|
|
216
|
+
precision: s,
|
|
217
|
+
truncateSymbol: a
|
|
218
|
+
}) => `${lt(t, s)} ${a ? At(e) : e}`, Yt = (t) => {
|
|
219
|
+
if (!t)
|
|
220
|
+
return;
|
|
221
|
+
const e = t.match(/0x[a-fA-F0-9]{64}/);
|
|
222
|
+
if (!e)
|
|
223
|
+
return;
|
|
224
|
+
const s = e[0];
|
|
225
|
+
return `${s.slice(0, 4)}...${s.slice(-3)}`;
|
|
226
|
+
}, Gt = typeof window < "u", Zt = (t) => l(Y, t) || l(G, t), Ht = (t) => H.some(
|
|
227
|
+
(e) => l(e, t)
|
|
228
|
+
), Qt = (t) => W[t.toLowerCase()] ?? {
|
|
229
|
+
symbol: "",
|
|
230
|
+
decimals: 18,
|
|
231
|
+
address: T
|
|
232
|
+
}, kt = (t) => l(t, Z) ? K : V, mt = (t) => `eth_${t}`, jt = ({
|
|
233
|
+
action: t,
|
|
234
|
+
log: e,
|
|
235
|
+
symbol: s,
|
|
236
|
+
vaultAddress: a,
|
|
237
|
+
chainId: n
|
|
238
|
+
}) => {
|
|
239
|
+
const r = {
|
|
240
|
+
[g.SYMBOL.NAME]: s,
|
|
241
|
+
[g.CHAIN_ID.NAME]: n,
|
|
242
|
+
[g.ADDRESS.NAME]: mt(a)
|
|
243
|
+
};
|
|
244
|
+
Q[t].forEach((o) => {
|
|
245
|
+
e?.(o, r);
|
|
246
|
+
});
|
|
247
|
+
}, qt = (t) => q.some((e) => l(e, t)), zt = (t) => k[t.toLowerCase()] ?? {
|
|
248
|
+
symbol: "",
|
|
249
|
+
decimals: 18,
|
|
250
|
+
address: T
|
|
251
|
+
}, Xt = (t) => j[t.toLowerCase()], pt = (t) => {
|
|
252
|
+
const e = t.find(
|
|
253
|
+
({ swapQuotes: s }) => s
|
|
254
|
+
);
|
|
255
|
+
return e?.swapQuotes ? Object.values(e.swapQuotes)[0]?.map(
|
|
256
|
+
({ routerKey: s }) => s
|
|
257
|
+
) ?? [] : [];
|
|
258
|
+
}, gt = (t, e, s) => t.map(({ asset: a, swapParams: n, swapQuotes: r }) => !n || !r ? {
|
|
259
|
+
supportedAsset: a,
|
|
260
|
+
withdrawData: "",
|
|
261
|
+
slippageTolerance: s
|
|
262
|
+
} : nt({
|
|
263
|
+
assetAddress: a,
|
|
264
|
+
swapQuotes: r,
|
|
265
|
+
swapParams: n,
|
|
266
|
+
slippageToleranceForContractTransaction: s,
|
|
267
|
+
routerKey: e
|
|
268
|
+
})), Tt = async (t, e, s, a, n) => {
|
|
269
|
+
for (const r of t) {
|
|
270
|
+
const o = gt(
|
|
271
|
+
e,
|
|
272
|
+
r,
|
|
273
|
+
s
|
|
274
|
+
), { error: u } = await a(...n, o);
|
|
275
|
+
if (!u)
|
|
276
|
+
return o;
|
|
277
|
+
}
|
|
278
|
+
return null;
|
|
279
|
+
}, Jt = (t, e) => (t ?? []).map((s) => ({
|
|
280
|
+
supportedAsset: s,
|
|
281
|
+
withdrawData: "",
|
|
282
|
+
slippageTolerance: e
|
|
283
|
+
})), te = async (t, e, s, a) => {
|
|
284
|
+
for (const n of t) {
|
|
285
|
+
const r = at(n);
|
|
286
|
+
try {
|
|
287
|
+
const o = await e(n), u = pt(
|
|
288
|
+
o
|
|
289
|
+
), c = await Tt(
|
|
290
|
+
u,
|
|
291
|
+
o,
|
|
292
|
+
r,
|
|
293
|
+
s,
|
|
294
|
+
a
|
|
295
|
+
);
|
|
296
|
+
if (c)
|
|
297
|
+
return console.debug(
|
|
298
|
+
`[Init Withdraw] Auto slippage simulation succeeded: slippage=${n}%`
|
|
299
|
+
), console.debug("[Init Withdraw] Complex asset data:", c), c;
|
|
300
|
+
} catch (o) {
|
|
301
|
+
console.error(
|
|
302
|
+
`[Init Withdraw] Failed to fetch quotes for slippage=${n}%:`,
|
|
303
|
+
o
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return null;
|
|
308
|
+
}, ee = async (t, e, {
|
|
309
|
+
fetchAaveSwapParams: s,
|
|
310
|
+
fetchAaveSwapQuotes: a,
|
|
311
|
+
withdrawAmountD18: n,
|
|
312
|
+
slippage: r
|
|
313
|
+
}) => Promise.all(
|
|
314
|
+
(t ?? []).map(async (o) => {
|
|
315
|
+
if (!l(o, e))
|
|
316
|
+
return { asset: o };
|
|
317
|
+
try {
|
|
318
|
+
const c = await s({
|
|
319
|
+
withdrawAmountD18: n,
|
|
320
|
+
slippage: r
|
|
321
|
+
});
|
|
322
|
+
if (c?.srcData.length) {
|
|
323
|
+
const d = await a({
|
|
324
|
+
swapParams: c,
|
|
325
|
+
slippage: r
|
|
326
|
+
});
|
|
327
|
+
return { asset: o, swapParams: c, swapQuotes: d };
|
|
328
|
+
}
|
|
329
|
+
return { asset: o };
|
|
330
|
+
} catch (c) {
|
|
331
|
+
return console.error(c), { asset: o };
|
|
332
|
+
}
|
|
333
|
+
})
|
|
334
|
+
), h = (t) => Math.round(t * 100) / 100, se = ({
|
|
335
|
+
maxSlippage: t,
|
|
336
|
+
candidates: e = z
|
|
337
|
+
}) => {
|
|
338
|
+
if (!Number.isFinite(t) || t <= 0)
|
|
339
|
+
return [];
|
|
340
|
+
const s = h(Math.min(t, 100)), a = e.filter((r) => r > 0 && r <= s).map(h), n = new Set(a);
|
|
341
|
+
return n.add(s), n.add(t), Array.from(n).sort((r, o) => r - o);
|
|
342
|
+
};
|
|
343
|
+
export {
|
|
344
|
+
it as $,
|
|
345
|
+
Yt as A,
|
|
346
|
+
ht as B,
|
|
347
|
+
Ht as C,
|
|
348
|
+
Zt as D,
|
|
349
|
+
qt as E,
|
|
350
|
+
Ct as F,
|
|
351
|
+
Mt as G,
|
|
352
|
+
jt as H,
|
|
353
|
+
bt as I,
|
|
354
|
+
$t as J,
|
|
355
|
+
Lt as K,
|
|
356
|
+
Et as L,
|
|
357
|
+
yt as M,
|
|
358
|
+
mt as N,
|
|
359
|
+
At as O,
|
|
360
|
+
Tt as P,
|
|
361
|
+
te as Q,
|
|
362
|
+
Pt as R,
|
|
363
|
+
Dt as S,
|
|
364
|
+
vt as T,
|
|
365
|
+
l as U,
|
|
366
|
+
ct as V,
|
|
367
|
+
Ut as W,
|
|
368
|
+
ot as X,
|
|
369
|
+
ut as Y,
|
|
370
|
+
wt as Z,
|
|
371
|
+
dt as _,
|
|
372
|
+
gt as a,
|
|
373
|
+
xt as a0,
|
|
374
|
+
N as a1,
|
|
375
|
+
nt as b,
|
|
376
|
+
et as c,
|
|
377
|
+
Ot as d,
|
|
378
|
+
Bt as e,
|
|
379
|
+
Gt as f,
|
|
380
|
+
Jt as g,
|
|
381
|
+
ee as h,
|
|
382
|
+
pt as i,
|
|
383
|
+
lt as j,
|
|
384
|
+
Kt as k,
|
|
385
|
+
Wt as l,
|
|
386
|
+
Vt as m,
|
|
387
|
+
se as n,
|
|
388
|
+
Nt as o,
|
|
389
|
+
tt as p,
|
|
390
|
+
It as q,
|
|
391
|
+
w as r,
|
|
392
|
+
Qt as s,
|
|
393
|
+
kt as t,
|
|
394
|
+
zt as u,
|
|
395
|
+
Xt as v,
|
|
396
|
+
Ft as w,
|
|
397
|
+
st as x,
|
|
398
|
+
Rt as y,
|
|
399
|
+
at as z
|
|
400
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const c=require("bignumber.js"),o=require("./gmx-C0ZAKA5h.cjs"),T=require("viem"),U=()=>typeof window<"u";function $(){return U()&&typeof window.ethereum<"u"}async function G(t){try{if($())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(),V=t=>A(t,o.AddressZero$1),w=(t,e)=>o.contractsAddressesMap[e]?.[t]??o.AddressZero,K=t=>o.contractsAbisMap[t],Y=t=>t&&`${t.substring(0,6)}...${t.substring(t.length-4,t.length)}`,Z=({address:t,chainId:e})=>{const r=w("aaveLendingPoolV3",e);return A(t,r)},y=({sourceAddress:t,amount:e})=>`${t}_${e}`,k=(t,e)=>{const r=t.slice(0,e),n=t.slice(e);return{firstPart:r,secondPart:n}},N=(t,e)=>t/e*100,H=t=>t<1?4:t<10?3:2,q=(t,e=o.DEFAULT_PRECISION)=>new c(t.toString()).shiftedBy(e).toFixed(0),Q=(t,e,r,n)=>new c(e).dividedBy(r).multipliedBy(t).shiftedBy(-(n||o.DEFAULT_PRECISION)).toNumber(),z=t=>BigInt(new c(t||"0").shiftedBy(o.DEFAULT_PRECISION).toFixed(0,c.ROUND_DOWN)),h=t=>{const e=new c(.01),r=new c(t),n=!r.isZero()&&r.lt(e)?e:r;return BigInt(n.multipliedBy(100).toFixed(0))},j=({vaultAddress:t,swapData:e,sendTokenAddress:r,sendTokenAmount:n,vaultDepositTokenAddress:s,minVaultTokensReceivedAmount:a,routerKey:i="ONE_INCH",swapDestinationAmount:u,swapSlippage:d})=>{const l=new c(u).multipliedBy(1-d/100).toFixed(0),m=[T.stringToHex(i,{size:32}),e];return[t,[[r,n,m],[s,l]],a]},X=({receiveAssetAddress:t,assets:e,swapData:r,slippage:n})=>{const s={srcData:[],destAmount:new c("0")},{srcData:a,destAmount:i}=e?.reduce((u,d)=>{const l=r?.[d.address];if(!l)return u;const m=[T.stringToHex(l.routerKey,{size:32}),l.rawTransaction.data],g=[d.address,d.rawBalance,m];return{srcData:[...u.srcData,g],destAmount:u.destAmount.plus(l.destinationAmount)}},s)??s;return[a,[t,i.times(1-n/100).toFixed(0,c.ROUND_DOWN)]]},I=({assetAddress:t,swapQuotes:e,swapParams:r,slippageToleranceForContractTransaction:n,routerKey:s})=>{if(!r)return{supportedAsset:t,withdrawData:"",slippageTolerance:BigInt(0)};const{srcData:a,dstData:i}=r,u=a.map(({asset:m,amount:g})=>{const p=e?.[y({sourceAddress:m,amount:g.toString()})]?.find(W=>W.routerKey===s);return{asset:m,amount:g,swapData:{routerKey:T.stringToHex(p?.routerKey??"",{size:32}),txData:p?.rawTransaction.data??"0x"}}}),d=T.encodeAbiParameters(o.ComplexWithdrawalAssetSrcDataAbiItem,[u]),l=T.encodeAbiParameters(o.ComplexWithdrawalDataAbiItem,[{encodedSrcData:d,dstData:{dstAddress:i.asset,dstAmount:i.amount},slippage:n}]);return{supportedAsset:t,withdrawData:l,slippageTolerance:n}},J=(t,e)=>o.CHAIN_NATIVE_TOKENS[e]?.nativeTokenSymbol===t,tt=({nativeTokenBalance:t,tokenDecimals:e,gasPrice:r})=>{const n=new c(r).multipliedBy(o.NATIVE_TOKEN_DEPOSIT_GAS_LIMIT).shiftedBy(-e),s=new c(t).minus(n);return s.gt("0")?s:new c("0")},et=t=>o.STABLE_TOKEN_SYMBOLS.includes(t),rt=t=>{const e=Object.values(t).reduce((r,{type:n})=>(r[n]=r[n]+1,r),{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},nt=(t,e=150)=>t.length>e?t.substring(0,e):t,S=(t,e=o.TRANSACTION_ERROR_KEYS)=>{const r=t.toLowerCase();return e.sort((n,s)=>s.length-n.length).find(n=>r.includes(n.toLowerCase()))},f=t=>o.TRANSACTION_ERRORS[t]??o.LIMIT_ORDER_TRANSACTION_ERRORS[t],st=({errorMessage:t,abiErrors:e})=>{if(!t||t.includes("User rejected"))return null;const r=e.find(a=>t.includes(a));if(r&&S(r))return f(r);const n=S(t);if(n)return f(n);const[s]=t.split(r?".":"Contract").map(a=>a.trim());return{title:"Transaction failed",hint:`${nt(s??"")} ${r?`: ${r}`:""}`}},ot=t=>typeof t=="number"&&Number.isFinite(t),at=t=>typeof t=="bigint"&&t!==BigInt(0),L=(t,e=o.DEFAULT_PRECISION$1)=>new c(t).shiftedBy(-e).toNumber(),B=t=>!isNaN(parseFloat(t))&&!isNaN(t),b=({value:t,minimumFractionDigits:e=2,maximumFractionDigits:r=2,compact:n=!1,normalize:s=!1})=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",notation:n?"compact":void 0,minimumFractionDigits:e,maximumFractionDigits:r}).format(s?L(t):Number(t)),D=t=>B(t)?new c(t).toFixed():"",_=["₀","₁","₂","₃","₄","₅","₆","₇","₈","₉"],R=({value:t,decimals:e=4})=>{const r=new c(t);if(r.isGreaterThan(1)||r.isZero())return D(r.toFixed(e));const s=(/e/i.test(t.toString())?parseFloat(t.toString()).toFixed(o.DEFAULT_PRECISION$1):t.toString()).match(/^0\.(0+)(\d+)$/);if(s){const[,a,i]=s;if(a.length>=e&&a.length<_.length)return`0.0${_[a.length]}${i.slice(0,3)}`}return D(r.toFixed(e))},C=(t,e=0)=>`${t.toLocaleString("en-US",{maximumFractionDigits:e})}%`,it=t=>t.toString().replace(/\B(?=(\d{3})+(?!\d))/g,","),ct=(t,e,r=0)=>{const n=N(+t,e);return C(n,r)},dt=({currency:t,value:e})=>t==="USD"?b({value:e}):`${o.CURRENCY_SYMBOL_MAP[t]} ${R({value:e,decimals:o.CURRENCY_DECIMALS_MAP[t]})}`,F=(t,e)=>new c(new c(t).toFixed(e,c.ROUND_DOWN)).toString(),O=(t,e=3,r=2)=>{if(t.length<=5)return t;const n="...";return t.length<=e+r+n.length?t:`${t.slice(0,e)}${n}${t.slice(-r)}`},ut=({balance:t,symbol:e,precision:r,truncateSymbol:n})=>`${F(t,r)} ${n?O(e):e}`,lt=t=>{if(!t)return;const e=t.match(/0x[a-fA-F0-9]{64}/);if(!e)return;const r=e[0];return`${r.slice(0,4)}...${r.slice(-3)}`},At=typeof window<"u",mt=t=>A(o.FLATMONEY_EARLY_DEPOSITOR_VAULT_ADDRESS_BASE,t)||A(o.FLATMONEY_DHT_STAKING_VAULT_ADDRESS_BASE,t),gt=t=>o.FLAT_MONEY_LEVERAGED_ASSET_ADDRESSES.some(e=>A(e,t)),Tt=t=>o.FLAT_MONEY_COLLATERAL_MAP[t.toLowerCase()]??{symbol:"",decimals:18,address:o.AddressZero},pt=t=>A(t,o.FLAT_MONEY_V1_UNIT_ADDRESS)?o.FLAT_MONEY_V1_UNIT_LINK:o.FLAT_MONEY_UNIT_LINK,v=t=>`eth_${t}`,St=({action:t,log:e,symbol:r,vaultAddress:n,chainId:s})=>{const a={[o.TRADING_LOG_EVENT_PARAM.SYMBOL.NAME]:r,[o.TRADING_LOG_EVENT_PARAM.CHAIN_ID.NAME]:s,[o.TRADING_LOG_EVENT_PARAM.ADDRESS.NAME]:v(n)};o.LOG_EVENT_BY_TRANSACTION_ACTION_MAP[t].forEach(i=>{e?.(i,a)})},Dt=t=>o.GMX_MARKET_ASSETS.some(e=>A(e,t)),ft=t=>o.GMX_WITHDRAW_ASSET_MAP[t.toLowerCase()]??{symbol:"",decimals:18,address:o.AddressZero},_t=t=>o.GMX_WITHDRAW_ASSET_MAP_BY_VAULT_ADDRESS[t.toLowerCase()],M=t=>{const e=t.find(({swapQuotes:r})=>r);return e?.swapQuotes?Object.values(e.swapQuotes)[0]?.map(({routerKey:r})=>r)??[]:[]},P=(t,e,r)=>t.map(({asset:n,swapParams:s,swapQuotes:a})=>!s||!a?{supportedAsset:n,withdrawData:"",slippageTolerance:r}:I({assetAddress:n,swapQuotes:a,swapParams:s,slippageToleranceForContractTransaction:r,routerKey:e})),x=async(t,e,r,n,s)=>{for(const a of t){const i=P(e,a,r),{error:u}=await n(...s,i);if(!u)return i}return null},Et=(t,e)=>(t??[]).map(r=>({supportedAsset:r,withdrawData:"",slippageTolerance:e})),wt=async(t,e,r,n)=>{for(const s of t){const a=h(s);try{const i=await e(s),u=M(i),d=await x(u,i,a,r,n);if(d)return console.debug(`[Init Withdraw] Auto slippage simulation succeeded: slippage=${s}%`),console.debug("[Init Withdraw] Complex asset data:",d),d}catch(i){console.error(`[Init Withdraw] Failed to fetch quotes for slippage=${s}%:`,i)}}return null},yt=async(t,e,{fetchAaveSwapParams:r,fetchAaveSwapQuotes:n,withdrawAmountD18:s,slippage:a})=>Promise.all((t??[]).map(async i=>{if(!A(i,e))return{asset:i};try{const d=await r({withdrawAmountD18:s,slippage:a});if(d?.srcData.length){const l=await n({swapParams:d,slippage:a});return{asset:i,swapParams:d,swapQuotes:l}}return{asset:i}}catch(d){return console.error(d),{asset:i}}})),E=t=>Math.round(t*100)/100,Nt=({maxSlippage:t,candidates:e=o.SLIPPAGE_AUTO_SIMULATION_CANDIDATES})=>{if(!Number.isFinite(t)||t<=0)return[];const r=E(Math.min(t,100)),n=e.filter(a=>a>0&&a<=r).map(E),s=new Set(n);return s.add(r),s.add(t),Array.from(s).sort((a,i)=>a-i)};exports.addTokenToWallet=G;exports.buildAaveWithdrawAssetTransactionData=I;exports.buildComplexAssetDataForRouter=P;exports.buildSwapQuoteKeyForAave=y;exports.buildSwapWithdrawTransactionData=X;exports.buildZapDepositTransactionArguments=j;exports.clientSide=At;exports.commify=it;exports.createDefaultComplexAssetData=Et;exports.enrichAssetsWithSwapQuotes=yt;exports.extractAvailableRouterKeys=M;exports.formatBalance=F;exports.formatByCurrency=dt;exports.formatNumberToLimitedDecimals=R;exports.formatNumeratorToPercentage=ct;exports.formatPercentage=C;exports.formatToUsd=b;exports.formatTokenBalance=ut;exports.getAutoSlippageSimulationCandidates=Nt;exports.getContractAbiById=K;exports.getContractAddressById=w;exports.getConventionalTokenPriceDecimals=H;exports.getErrorKey=S;exports.getFlatMoneyCollateralByLeverageAddress=Tt;exports.getFlatMoneyLinkByUnitAddress=pt;exports.getGmxWithdrawAssetByLeverageAddress=ft;exports.getGmxWithdrawAssetByVaultAddress=_t;exports.getNativeTokenInvestableBalance=tt;exports.getPercent=N;exports.getPoolFraction=Q;exports.getSlippageToleranceForContractTransaction=h;exports.getTxHashShort=lt;exports.isAaveLendAndBorrowAsset=Z;exports.isEqualAddress=A;exports.isFlatMoneyLeveragedAsset=gt;exports.isFmpAirdropVaultAddress=mt;exports.isGmxLeveragedAsset=Dt;exports.isNativeToken=J;exports.isNumberType=ot;exports.isNumeric=B;exports.isStableSymbol=et;exports.isZeroAddress=V;exports.logTransactionByActionType=St;exports.nonZeroBigInt=at;exports.normalizeNumber=L;exports.parseAmountToD18=z;exports.parseContractErrorMessage=st;exports.removeInsignificantTrailingZeros=D;exports.shiftBy=q;exports.shortenAddress=Y;exports.sliceByIndex=k;exports.transformAddressForAnalytics=v;exports.truncateString=O;exports.tryEstimateWithRouters=x;exports.tryEstimateWithSlippageValues=wt;exports.validateLoggerEventParams=rt;
|