@dhedge/trading-widget 5.13.1 → 5.13.3

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