@dhedge/trading-widget 5.11.0 → 5.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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-BroDb_q_.js → gmx-3UudxpaT.js} +175 -163
- package/gmx-Bmop5mtI.cjs +1 -0
- package/index.cjs +1 -1
- package/index.js +3193 -3130
- package/package.json +1 -1
- package/slippage-auto-simulation-B0sf5jE_.js +400 -0
- package/slippage-auto-simulation-yZX7Qmre.cjs +1 -0
- 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-3UudxpaT.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-Bmop5mtI.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;
|
|
@@ -7,7 +7,7 @@ export interface ConfigProviderParams {
|
|
|
7
7
|
depositQuoteDiffWarningThreshold: number;
|
|
8
8
|
depositQuoteDiffErrorThreshold: number;
|
|
9
9
|
defaultWithdrawSlippage: number | Partial<Record<ChainId, number>>;
|
|
10
|
-
defaultSwapTransactionSlippage: number
|
|
10
|
+
defaultSwapTransactionSlippage: number | Partial<Record<ChainId, number>>;
|
|
11
11
|
defaultNoSwapMinDepositAmountGap: number;
|
|
12
12
|
defaultNotificationDuration: number;
|
|
13
13
|
defaultLockTime: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { useConfigContext, useConfigContextParams, useConfigContextActions, } from '../../providers/config-provider/config-provider.hooks';
|
|
2
2
|
export { useResolvedDefaultWithdrawSlippage } from '../../providers/config-provider/use-resolved-default-withdraw-slippage';
|
|
3
|
+
export { useResolvedDefaultSwapTransactionSlippage } from '../../providers/config-provider/use-resolved-default-swap-transaction-slippage';
|
|
3
4
|
export { DEFAULT_CONFIG_PARAMS } from '../../providers/config-provider/config-provider.defaults';
|
|
4
5
|
export { ConfigProvider } from '../../providers/config-provider/config-provider';
|
|
5
6
|
export * from '../../providers/config-provider/config-provider.types';
|
package/trading-widget/providers/config-provider/use-resolved-default-swap-transaction-slippage.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useResolvedDefaultSwapTransactionSlippage: () => number;
|
package/utils.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./slippage-auto-simulation-yZX7Qmre.cjs"),t=require("viem");exports.buildAaveWithdrawAssetTransactionData=e.buildAaveWithdrawAssetTransactionData;exports.buildComplexAssetDataForRouter=e.buildComplexAssetDataForRouter;exports.buildSwapQuoteKeyForAave=e.buildSwapQuoteKeyForAave;exports.buildSwapWithdrawTransactionData=e.buildSwapWithdrawTransactionData;exports.buildZapDepositTransactionArguments=e.buildZapDepositTransactionArguments;exports.clientSide=e.clientSide;exports.createDefaultComplexAssetData=e.createDefaultComplexAssetData;exports.enrichAssetsWithSwapQuotes=e.enrichAssetsWithSwapQuotes;exports.extractAvailableRouterKeys=e.extractAvailableRouterKeys;exports.formatBalance=e.formatBalance;exports.formatByCurrency=e.formatByCurrency;exports.formatNumeratorToPercentage=e.formatNumeratorToPercentage;exports.formatTokenBalance=e.formatTokenBalance;exports.getAutoSlippageSimulationCandidates=e.getAutoSlippageSimulationCandidates;exports.getContractAbiById=e.getContractAbiById;exports.getContractAddressById=e.getContractAddressById;exports.getConventionalTokenPriceDecimals=e.getConventionalTokenPriceDecimals;exports.getErrorKey=e.getErrorKey;exports.getFlatMoneyCollateralByLeverageAddress=e.getFlatMoneyCollateralByLeverageAddress;exports.getFlatMoneyLinkByUnitAddress=e.getFlatMoneyLinkByUnitAddress;exports.getGmxWithdrawAssetByLeverageAddress=e.getGmxWithdrawAssetByLeverageAddress;exports.getGmxWithdrawAssetByVaultAddress=e.getGmxWithdrawAssetByVaultAddress;exports.getNativeTokenInvestableBalance=e.getNativeTokenInvestableBalance;exports.getPercent=e.getPercent;exports.getPoolFraction=e.getPoolFraction;exports.getSlippageToleranceForContractTransaction=e.getSlippageToleranceForContractTransaction;exports.getTxHashShort=e.getTxHashShort;exports.isAaveLendAndBorrowAsset=e.isAaveLendAndBorrowAsset;exports.isFlatMoneyLeveragedAsset=e.isFlatMoneyLeveragedAsset;exports.isFmpAirdropVaultAddress=e.isFmpAirdropVaultAddress;exports.isGmxLeveragedAsset=e.isGmxLeveragedAsset;exports.isNativeToken=e.isNativeToken;exports.isStableSymbol=e.isStableSymbol;exports.logTransactionByActionType=e.logTransactionByActionType;exports.parseAmountToD18=e.parseAmountToD18;exports.parseContractErrorMessage=e.parseContractErrorMessage;exports.shiftBy=e.shiftBy;exports.shortenAddress=e.shortenAddress;exports.sliceByIndex=e.sliceByIndex;exports.transformAddressForAnalytics=e.transformAddressForAnalytics;exports.truncateString=e.truncateString;exports.tryEstimateWithRouters=e.tryEstimateWithRouters;exports.tryEstimateWithSlippageValues=e.tryEstimateWithSlippageValues;exports.validateLoggerEventParams=e.validateLoggerEventParams;Object.defineProperty(exports,"decodeErrorResult",{enumerable:!0,get:()=>t.decodeErrorResult});Object.defineProperty(exports,"encodeFunctionData",{enumerable:!0,get:()=>t.encodeFunctionData});Object.defineProperty(exports,"formatEther",{enumerable:!0,get:()=>t.formatEther});Object.defineProperty(exports,"formatUnits",{enumerable:!0,get:()=>t.formatUnits});Object.defineProperty(exports,"hexToString",{enumerable:!0,get:()=>t.hexToString});Object.defineProperty(exports,"trim",{enumerable:!0,get:()=>t.trim});
|
package/utils.js
CHANGED
|
@@ -1,52 +1,54 @@
|
|
|
1
|
-
import { b as s, a as t, c as r, d as o, e as
|
|
2
|
-
import { decodeErrorResult as
|
|
1
|
+
import { b as s, a as t, c as r, d as o, e as i, f as n, g as d, h as l, i as c, j as g, k as A, l as m, m as u, n as y, o as p, p as h, q as v, r as B, s as T, t as S, u as f, v as x, w as b, x as C, y as F, z as D, A as w, B as E, C as L, D as W, E as k, F as P, G as I, H as M, I as R, J as G, K, L as N, M as Q, N as V, O as H, P as U, Q as j, R as q } from "./slippage-auto-simulation-B0sf5jE_.js";
|
|
2
|
+
import { decodeErrorResult as J, encodeFunctionData as O, formatEther as Z, formatUnits as X, hexToString as Y, trim as _ } from "viem";
|
|
3
3
|
export {
|
|
4
4
|
s as buildAaveWithdrawAssetTransactionData,
|
|
5
5
|
t as buildComplexAssetDataForRouter,
|
|
6
6
|
r as buildSwapQuoteKeyForAave,
|
|
7
7
|
o as buildSwapWithdrawTransactionData,
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
i as buildZapDepositTransactionArguments,
|
|
9
|
+
n as clientSide,
|
|
10
10
|
d as createDefaultComplexAssetData,
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
J as decodeErrorResult,
|
|
12
|
+
O as encodeFunctionData,
|
|
13
13
|
l as enrichAssetsWithSwapQuotes,
|
|
14
14
|
c as extractAvailableRouterKeys,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
g as formatBalance,
|
|
16
|
+
A as formatByCurrency,
|
|
17
|
+
Z as formatEther,
|
|
18
18
|
m as formatNumeratorToPercentage,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
p as
|
|
19
|
+
u as formatTokenBalance,
|
|
20
|
+
X as formatUnits,
|
|
21
|
+
y as getAutoSlippageSimulationCandidates,
|
|
22
|
+
p as getContractAbiById,
|
|
23
|
+
h as getContractAddressById,
|
|
23
24
|
v as getConventionalTokenPriceDecimals,
|
|
24
25
|
B as getErrorKey,
|
|
25
26
|
T as getFlatMoneyCollateralByLeverageAddress,
|
|
26
|
-
|
|
27
|
+
S as getFlatMoneyLinkByUnitAddress,
|
|
27
28
|
f as getGmxWithdrawAssetByLeverageAddress,
|
|
28
29
|
x as getGmxWithdrawAssetByVaultAddress,
|
|
29
30
|
b as getNativeTokenInvestableBalance,
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
C as getPercent,
|
|
32
|
+
F as getPoolFraction,
|
|
32
33
|
D as getSlippageToleranceForContractTransaction,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
w as getTxHashShort,
|
|
35
|
+
Y as hexToString,
|
|
36
|
+
E as isAaveLendAndBorrowAsset,
|
|
36
37
|
L as isFlatMoneyLeveragedAsset,
|
|
37
|
-
|
|
38
|
+
W as isFmpAirdropVaultAddress,
|
|
38
39
|
k as isGmxLeveragedAsset,
|
|
39
40
|
P as isNativeToken,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
I as isStableSymbol,
|
|
42
|
+
M as logTransactionByActionType,
|
|
43
|
+
R as parseAmountToD18,
|
|
43
44
|
G as parseContractErrorMessage,
|
|
44
45
|
K as shiftBy,
|
|
45
46
|
N as shortenAddress,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
Q as sliceByIndex,
|
|
48
|
+
V as transformAddressForAnalytics,
|
|
49
|
+
_ as trim,
|
|
50
|
+
H as truncateString,
|
|
50
51
|
U as tryEstimateWithRouters,
|
|
51
|
-
|
|
52
|
+
j as tryEstimateWithSlippageValues,
|
|
53
|
+
q as validateLoggerEventParams
|
|
52
54
|
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const c=require("bignumber.js"),s=require("./gmx-CLiWBUH_.cjs"),m=require("viem"),M=()=>typeof window<"u";function P(){return M()&&typeof window.ethereum<"u"}async function x(t){try{if(P())return window.ethereum.request({method:"wallet_watchAsset",params:{type:"ERC20",options:t}})}catch{return!1}return!1}const l=(t,e)=>t?.toLowerCase()===e?.toLowerCase(),U=t=>l(t,s.AddressZero$1),f=(t,e)=>s.contractsAddressesMap[e]?.[t]??s.AddressZero,$=t=>s.contractsAbisMap[t],W=t=>t&&`${t.substring(0,6)}...${t.substring(t.length-4,t.length)}`,G=({address:t,chainId:e})=>{const r=f("aaveLendingPoolV3",e);return l(t,r)},N=({sourceAddress:t,amount:e})=>`${t}_${e}`,K=(t,e)=>{const r=t.slice(0,e),n=t.slice(e);return{firstPart:r,secondPart:n}},y=(t,e)=>t/e*100,V=t=>t<1?4:t<10?3:2,Y=(t,e=s.DEFAULT_PRECISION)=>new c(t.toString()).shiftedBy(e).toFixed(0),Z=(t,e,r,n)=>new c(e).dividedBy(r).multipliedBy(t).shiftedBy(-(n||s.DEFAULT_PRECISION)).toNumber(),k=t=>BigInt(new c(t||"0").shiftedBy(s.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))},Q=({vaultAddress:t,swapData:e,sendTokenAddress:r,sendTokenAmount:n,vaultDepositTokenAddress:o,minVaultTokensReceivedAmount:a,routerKey:i="ONE_INCH",swapDestinationAmount:d,swapSlippage:u})=>{const A=new c(d).multipliedBy(1-u/100).toFixed(0),g=[m.stringToHex(i,{size:32}),e];return[t,[[r,n,g],[o,A]],a]},q=({receiveAssetAddress:t,assets:e,swapData:r})=>{const n={srcData:[],destAmount:new c("0")},{srcData:o}=e?.reduce((a,i)=>{const d=r?.[i.address];if(!d)return a;const u=[m.stringToHex(d.routerKey,{size:32}),d.rawTransaction.data],A=[i.address,i.rawBalance,u];return{srcData:[...a.srcData,A],destAmount:a.destAmount.plus(d.destinationAmount)}},n)??n;return[o,[t,"0"]]},w=({assetAddress:t,swapQuotes:e,swapParams:r,slippageToleranceForContractTransaction:n,routerKey:o})=>{if(!r)return{supportedAsset:t,withdrawData:"",slippageTolerance:BigInt(0)};const{srcData:a,dstData:i}=r,d=a.map(({asset:g,amount:T})=>{const p=e?.[N({sourceAddress:g,amount:T.toString()})]?.find(v=>v.routerKey===o);return{asset:g,amount:T,swapData:{routerKey:m.stringToHex(p?.routerKey??"",{size:32}),txData:p?.rawTransaction.data??"0x"}}}),u=m.encodeAbiParameters(s.ComplexWithdrawalAssetSrcDataAbiItem,[d]),A=m.encodeAbiParameters(s.ComplexWithdrawalDataAbiItem,[{encodedSrcData:u,dstData:{dstAddress:i.asset,dstAmount:i.amount},slippage:n}]);return{supportedAsset:t,withdrawData:A,slippageTolerance:n}},z=(t,e)=>s.CHAIN_NATIVE_TOKENS[e]?.nativeTokenSymbol===t,j=({nativeTokenBalance:t,tokenDecimals:e,gasPrice:r})=>{const n=new c(r).multipliedBy(s.NATIVE_TOKEN_DEPOSIT_GAS_LIMIT).shiftedBy(-e),o=new c(t).minus(n);return o.gt("0")?o:new c("0")},X=t=>s.STABLE_TOKEN_SYMBOLS.includes(t),J=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},tt=(t,e=150)=>t.length>e?t.substring(0,e):t,S=(t,e=s.TRANSACTION_ERROR_KEYS)=>{const r=t.toLowerCase();return e.sort((n,o)=>o.length-n.length).find(n=>r.includes(n.toLowerCase()))},_=t=>s.TRANSACTION_ERRORS[t]??s.LIMIT_ORDER_TRANSACTION_ERRORS[t],et=({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 _(r);const n=S(t);if(n)return _(n);const[o]=t.split(r?".":"Contract").map(a=>a.trim());return{title:"Transaction failed",hint:`${tt(o??"")} ${r?`: ${r}`:""}`}},rt=t=>typeof t=="number"&&Number.isFinite(t),nt=t=>typeof t=="bigint"&&t!==BigInt(0),h=(t,e=s.DEFAULT_PRECISION$1)=>new c(t).shiftedBy(-e).toNumber(),I=t=>!isNaN(parseFloat(t))&&!isNaN(t),L=({value:t,minimumFractionDigits:e=2,maximumFractionDigits:r=2,compact:n=!1,normalize:o=!1})=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",notation:n?"compact":void 0,minimumFractionDigits:e,maximumFractionDigits:r}).format(o?h(t):Number(t)),D=t=>I(t)?new c(t).toFixed():"",E=["₀","₁","₂","₃","₄","₅","₆","₇","₈","₉"],B=({value:t,decimals:e=4})=>{const r=new c(t);if(r.isGreaterThan(1)||r.isZero())return D(r.toFixed(e));const o=(/e/i.test(t.toString())?parseFloat(t.toString()).toFixed(s.DEFAULT_PRECISION$1):t.toString()).match(/^0\.(0+)(\d+)$/);if(o){const[,a,i]=o;if(a.length>=e&&a.length<E.length)return`0.0${E[a.length]}${i.slice(0,3)}`}return D(r.toFixed(e))},R=(t,e=0)=>`${t.toLocaleString("en-US",{maximumFractionDigits:e})}%`,st=t=>t.toString().replace(/\B(?=(\d{3})+(?!\d))/g,","),ot=(t,e,r=0)=>{const n=y(+t,e);return R(n,r)},at=({currency:t,value:e})=>t==="USD"?L({value:e}):`${s.CURRENCY_SYMBOL_MAP[t]} ${B({value:e,decimals:s.CURRENCY_DECIMALS_MAP[t]})}`,b=(t,e)=>new c(new c(t).toFixed(e,c.ROUND_DOWN)).toString(),C=(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)}`},it=({balance:t,symbol:e,precision:r,truncateSymbol:n})=>`${b(t,r)} ${n?C(e):e}`,ct=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)}`},dt=typeof window<"u",ut=t=>l(s.FLATMONEY_EARLY_DEPOSITOR_VAULT_ADDRESS_BASE,t)||l(s.FLATMONEY_DHT_STAKING_VAULT_ADDRESS_BASE,t),lt=t=>s.FLAT_MONEY_LEVERAGED_ASSET_ADDRESSES.some(e=>l(e,t)),At=t=>s.FLAT_MONEY_COLLATERAL_MAP[t.toLowerCase()]??{symbol:"",decimals:18,address:s.AddressZero},mt=t=>l(t,s.FLAT_MONEY_V1_UNIT_ADDRESS)?s.FLAT_MONEY_V1_UNIT_LINK:s.FLAT_MONEY_UNIT_LINK,F=t=>`eth_${t}`,gt=({action:t,log:e,symbol:r,vaultAddress:n,chainId:o})=>{const a={[s.TRADING_LOG_EVENT_PARAM.SYMBOL.NAME]:r,[s.TRADING_LOG_EVENT_PARAM.CHAIN_ID.NAME]:o,[s.TRADING_LOG_EVENT_PARAM.ADDRESS.NAME]:F(n)};s.LOG_EVENT_BY_TRANSACTION_ACTION_MAP[t].forEach(i=>{e?.(i,a)})},Tt=t=>s.GMX_MARKET_ASSETS.some(e=>l(e,t)),pt=t=>s.GMX_WITHDRAW_ASSET_MAP[t.toLowerCase()]??{symbol:"",decimals:18,address:s.AddressZero},St=t=>s.GMX_WITHDRAW_ASSET_MAP_BY_VAULT_ADDRESS[t.toLowerCase()],Dt=t=>{const e=t.find(({swapQuotes:r})=>r);return e?.swapQuotes?Object.values(e.swapQuotes)[0]?.map(({routerKey:r})=>r)??[]:[]},O=(t,e,r)=>t.map(({asset:n,swapParams:o,swapQuotes:a})=>!o||!a?{supportedAsset:n,withdrawData:"",slippageTolerance:r}:w({assetAddress:n,swapQuotes:a,swapParams:o,slippageToleranceForContractTransaction:r,routerKey:e})),_t=async(t,e,r,n,o)=>{for(const a of t){const i=O(e,a,r),{error:d}=await n(...o,i);if(!d)return i}return null},Et=(t,e)=>(t??[]).map(r=>({supportedAsset:r,withdrawData:"",slippageTolerance:e})),ft=async(t,e,{fetchAaveSwapParams:r,fetchAaveSwapQuotes:n,withdrawAmountD18:o,slippage:a})=>Promise.all((t??[]).map(async i=>{if(!l(i,e))return{asset:i};try{const u=await r({withdrawAmountD18:o,slippage:a});if(u?.srcData.length){const A=await n({swapParams:u,slippage:a});return{asset:i,swapParams:u,swapQuotes:A}}return{asset:i}}catch(u){return console.error(u),{asset:i}}}));exports.addTokenToWallet=x;exports.buildAaveWithdrawAssetTransactionData=w;exports.buildComplexAssetDataForRouter=O;exports.buildSwapQuoteKeyForAave=N;exports.buildSwapWithdrawTransactionData=q;exports.buildZapDepositTransactionArguments=Q;exports.clientSide=dt;exports.commify=st;exports.createDefaultComplexAssetData=Et;exports.enrichAssetsWithSwapQuotes=ft;exports.extractAvailableRouterKeys=Dt;exports.formatBalance=b;exports.formatByCurrency=at;exports.formatNumberToLimitedDecimals=B;exports.formatNumeratorToPercentage=ot;exports.formatPercentage=R;exports.formatToUsd=L;exports.formatTokenBalance=it;exports.getContractAbiById=$;exports.getContractAddressById=f;exports.getConventionalTokenPriceDecimals=V;exports.getErrorKey=S;exports.getFlatMoneyCollateralByLeverageAddress=At;exports.getFlatMoneyLinkByUnitAddress=mt;exports.getGmxWithdrawAssetByLeverageAddress=pt;exports.getGmxWithdrawAssetByVaultAddress=St;exports.getNativeTokenInvestableBalance=j;exports.getPercent=y;exports.getPoolFraction=Z;exports.getSlippageToleranceForContractTransaction=H;exports.getTxHashShort=ct;exports.isAaveLendAndBorrowAsset=G;exports.isEqualAddress=l;exports.isFlatMoneyLeveragedAsset=lt;exports.isFmpAirdropVaultAddress=ut;exports.isGmxLeveragedAsset=Tt;exports.isNativeToken=z;exports.isNumberType=rt;exports.isNumeric=I;exports.isStableSymbol=X;exports.isZeroAddress=U;exports.logTransactionByActionType=gt;exports.nonZeroBigInt=nt;exports.normalizeNumber=h;exports.parseAmountToD18=k;exports.parseContractErrorMessage=et;exports.removeInsignificantTrailingZeros=D;exports.shiftBy=Y;exports.shortenAddress=W;exports.sliceByIndex=K;exports.transformAddressForAnalytics=F;exports.truncateString=C;exports.tryEstimateWithRouters=_t;exports.validateLoggerEventParams=J;
|