0xtrails 0.8.2 → 0.8.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/dist/aave.d.ts.map +1 -1
- package/dist/{ccip-ru_Yzdas.js → ccip-Bs-QcZXm.js} +13 -13
- package/dist/constants.d.ts +2 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/fees.d.ts +11 -17
- package/dist/fees.d.ts.map +1 -1
- package/dist/{index-Si7cO9V7.js → index-C_EsqqSn.js} +20320 -20063
- package/dist/index.js +425 -847
- package/dist/intents.d.ts +1 -2
- package/dist/intents.d.ts.map +1 -1
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/recover.d.ts +8 -9
- package/dist/recover.d.ts.map +1 -1
- package/dist/tokenBalances.d.ts +51 -0
- package/dist/tokenBalances.d.ts.map +1 -1
- package/dist/trailsRouter.d.ts +15 -0
- package/dist/trailsRouter.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts +1 -3
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/standardDeposit.d.ts +1 -3
- package/dist/transactionIntent/deposits/standardDeposit.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/crossChain.d.ts +2 -4
- package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts +5 -4
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -1
- package/dist/transactionIntent/quote/normalizeQuote.d.ts +1 -1
- package/dist/transactionIntent/quote/normalizeQuote.d.ts.map +1 -1
- package/dist/transactionIntent/quote/quoteHelpers.d.ts +1 -1
- package/dist/transactionIntent/quote/quoteHelpers.d.ts.map +1 -1
- package/dist/transactionIntent/types.d.ts +11 -18
- package/dist/transactionIntent/types.d.ts.map +1 -1
- package/dist/widget/components/AccountIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
- package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
- package/dist/widget/components/SlippageToleranceSettings.d.ts +2 -1
- package/dist/widget/components/SlippageToleranceSettings.d.ts.map +1 -1
- package/dist/widget/css/compiled.css +1 -1
- package/dist/widget/hooks/useQuote.d.ts +94 -35
- package/dist/widget/hooks/useQuote.d.ts.map +1 -1
- package/dist/widget/hooks/useSendForm.d.ts +2 -2
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
- package/dist/widget/hooks/useTrailsSendTransaction.d.ts.map +1 -1
- package/dist/widget/index.js +1 -1
- package/package.json +2 -2
- package/src/aave.ts +4 -0
- package/src/constants.ts +4 -0
- package/src/fees.ts +47 -72
- package/src/intents.ts +1 -3
- package/src/morpho.ts +1 -1
- package/src/prepareSend.ts +42 -6
- package/src/recover.ts +116 -172
- package/src/tokenBalances.ts +301 -1
- package/src/trailsRouter.ts +77 -0
- package/src/transactionIntent/deposits/depositOrchestrator.ts +0 -6
- package/src/transactionIntent/deposits/standardDeposit.ts +167 -184
- package/src/transactionIntent/handlers/crossChain.ts +8 -11
- package/src/transactionIntent/handlers/sameChainSameToken.ts +619 -608
- package/src/transactionIntent/quote/normalizeQuote.ts +32 -46
- package/src/transactionIntent/quote/quoteHelpers.ts +4 -2
- package/src/transactionIntent/types.ts +11 -18
- package/src/widget/compiled.css +1 -1
- package/src/widget/components/AccountIntentTransactionHistory.tsx +50 -18
- package/src/widget/components/ClassicSwap.tsx +25 -30
- package/src/widget/components/QuoteDetails.tsx +18 -27
- package/src/widget/components/SlippageToleranceSettings.tsx +55 -25
- package/src/widget/hooks/useQuote.ts +317 -79
- package/src/widget/hooks/useSendForm.ts +123 -764
- package/src/widget/hooks/useTrailsSendTransaction.ts +0 -2
package/dist/index.js
CHANGED
|
@@ -1,993 +1,571 @@
|
|
|
1
|
-
import { l as
|
|
2
|
-
import {
|
|
3
|
-
import { useQuery as
|
|
4
|
-
import { useRef as
|
|
5
|
-
import { useWalletClient as
|
|
6
|
-
import { zeroAddress as
|
|
7
|
-
import { useIndexerGatewayClient as
|
|
8
|
-
import { useIndexerGatewayClient as
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
queryKey: ["waitIntentReceipt",
|
|
1
|
+
import { l as d, u as he, a as Ae, b as Ie, c as Ce, d as we, e as Ee, g as O, f as _, h as ee, T as H, i as Se, j as te, k as ye, p as pe, m as B } from "./index-C_EsqqSn.js";
|
|
2
|
+
import { I as Ve, aj as ze, ao as Ke, ay as ve, ax as Je, al as Ye, aw as Ze, U as be, G as et, aq as tt, ar as nt, ad as ot, H as st, J as rt, K as at, a4 as it, av as ct, at as dt, a5 as lt, a7 as ut, af as ft, a8 as Tt, a6 as mt, V as gt, P as kt, C as ht, E as At, ak as It, W as Ct, ap as wt, o as Et, n as St, x as yt, s as pt, t as Pt, w as Rt, v as Ut, q as Ht, r as xt, y as Lt, am as Ot, z as Bt, D as Dt, A as Mt, $ as Wt, a9 as qt, an as Ft, ai as Nt, ac as jt, ah as _t, ag as $t, ae as Qt, N as Gt, L as Xt, M as Vt, as as zt, X as Kt, Q as vt, F as Jt, S as Yt, a1 as Zt, Y as bt, Z as en, au as tn, R as nn, O as on, B as sn, a2 as rn, _ as an, a3 as cn, a0 as dn, aa as ln, ab as un } from "./index-C_EsqqSn.js";
|
|
3
|
+
import { useQuery as Pe, useMutation as Re } from "@tanstack/react-query";
|
|
4
|
+
import { useRef as Ue, useCallback as D } from "react";
|
|
5
|
+
import { useWalletClient as He, useAccount as xe, useChainId as Le } from "wagmi";
|
|
6
|
+
import { zeroAddress as p, erc20Abi as Oe } from "viem";
|
|
7
|
+
import { useIndexerGatewayClient as Be } from "@0xsequence/hooks";
|
|
8
|
+
import { useIndexerGatewayClient as Tn } from "@0xsequence/hooks";
|
|
9
|
+
const ne = 150, $e = (s, h) => {
|
|
10
|
+
const A = Pe({
|
|
11
|
+
queryKey: ["waitIntentReceipt", s],
|
|
12
12
|
queryFn: async () => {
|
|
13
|
-
if (!
|
|
13
|
+
if (!s)
|
|
14
14
|
throw new Error("Intent ID is required for monitoring");
|
|
15
|
-
|
|
16
|
-
`[trails-sdk] 🔍 Monitoring intent receipt for ${
|
|
15
|
+
d.console.log(
|
|
16
|
+
`[trails-sdk] 🔍 Monitoring intent receipt for ${s}`
|
|
17
17
|
);
|
|
18
|
-
const
|
|
19
|
-
intentId:
|
|
18
|
+
const T = await h.waitIntentReceipt({
|
|
19
|
+
intentId: s
|
|
20
20
|
});
|
|
21
|
-
return
|
|
22
|
-
`[trails-sdk] 📊 Intent ${
|
|
23
|
-
),
|
|
21
|
+
return d.console.log(
|
|
22
|
+
`[trails-sdk] 📊 Intent ${s} status: ${T.intentReceipt.status}, done: ${T.done}`
|
|
23
|
+
), T;
|
|
24
24
|
},
|
|
25
|
-
enabled: !!
|
|
25
|
+
enabled: !!s,
|
|
26
26
|
refetchIntervalInBackground: !0,
|
|
27
|
-
refetchInterval: (
|
|
28
|
-
const
|
|
29
|
-
return
|
|
30
|
-
`[trails-sdk] ✅ Intent monitoring complete for ${
|
|
31
|
-
), !1) :
|
|
27
|
+
refetchInterval: (T) => {
|
|
28
|
+
const I = T.state.data;
|
|
29
|
+
return I && I.done ? (d.console.log(
|
|
30
|
+
`[trails-sdk] ✅ Intent monitoring complete for ${s}`
|
|
31
|
+
), !1) : ne;
|
|
32
32
|
},
|
|
33
|
-
retry: (
|
|
34
|
-
`[trails-sdk] ❌ Giving up on intent ${
|
|
35
|
-
|
|
33
|
+
retry: (T, I) => T >= 30 ? (d.console.error(
|
|
34
|
+
`[trails-sdk] ❌ Giving up on intent ${s} after 30 failed API attempts:`,
|
|
35
|
+
I
|
|
36
36
|
), !1) : !0
|
|
37
37
|
});
|
|
38
38
|
return {
|
|
39
|
-
intentReceipt:
|
|
40
|
-
done:
|
|
41
|
-
isLoading:
|
|
42
|
-
isError:
|
|
43
|
-
error:
|
|
39
|
+
intentReceipt: A.data?.intentReceipt ?? null,
|
|
40
|
+
done: A.data?.done ?? !1,
|
|
41
|
+
isLoading: A.isLoading,
|
|
42
|
+
isError: A.isError,
|
|
43
|
+
error: A.error
|
|
44
44
|
};
|
|
45
45
|
};
|
|
46
|
-
function
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
intentId: n.intentId,
|
|
67
|
-
response: i
|
|
68
|
-
}), Ot({
|
|
69
|
-
intentAddress: n.originIntentAddress,
|
|
70
|
-
userAddress: n.ownerAddress,
|
|
71
|
-
originChainId: s ? Number(s) : void 0,
|
|
72
|
-
destinationChainId: a ? Number(a) : void 0
|
|
73
|
-
}), i;
|
|
74
|
-
} catch (i) {
|
|
75
|
-
throw Lt({
|
|
76
|
-
error: M(i),
|
|
77
|
-
userAddress: n.ownerAddress,
|
|
78
|
-
intentAddress: n.originIntentAddress,
|
|
79
|
-
originChainId: s ? Number(s) : void 0,
|
|
80
|
-
destinationChainId: a ? Number(a) : void 0
|
|
81
|
-
}), i;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
function vt() {
|
|
87
|
-
const d = gt();
|
|
88
|
-
return kt({
|
|
89
|
-
mutationFn: async ({
|
|
90
|
-
intentId: n,
|
|
91
|
-
depositTransactionHash: s,
|
|
92
|
-
depositSignature: a
|
|
93
|
-
}) => {
|
|
94
|
-
if (o.console.log("[trails-sdk] useExecuteIntent: Starting execution", {
|
|
95
|
-
intentId: n,
|
|
96
|
-
depositTransactionHash: s,
|
|
97
|
-
hasDepositSignature: !!a
|
|
98
|
-
}), !s && !a)
|
|
99
|
-
throw new Error(
|
|
100
|
-
"[trails-sdk] Either depositTransactionHash or depositSignature must be provided"
|
|
101
|
-
);
|
|
102
|
-
let i;
|
|
103
|
-
try {
|
|
104
|
-
i = await d.executeIntent({
|
|
105
|
-
intentId: n,
|
|
106
|
-
depositTransactionHash: s,
|
|
107
|
-
depositSignature: a
|
|
108
|
-
});
|
|
109
|
-
} catch (T) {
|
|
110
|
-
if (o.console.error(
|
|
111
|
-
"[trails-sdk] useExecuteIntent: Error executing intent",
|
|
112
|
-
{
|
|
113
|
-
intentId: n,
|
|
114
|
-
error: T,
|
|
115
|
-
errorJSON: JSON.stringify(T, null, 2)
|
|
116
|
-
}
|
|
117
|
-
), T instanceof Error && T?.message?.includes("status=SUCCEEDED") || T instanceof Error && T?.cause?.message?.includes("status=SUCCEEDED") || T instanceof Error && JSON.stringify(T).includes("status=SUCCEEDED") || T instanceof bt && T?.cause?.toString().includes("status=SUCCEEDED") || JSON.stringify(T).includes("status=SUCCEEDED"))
|
|
118
|
-
return o.console.error(
|
|
119
|
-
"[trails-sdk] useExecuteIntent: Intent already succeeded, treating as success",
|
|
120
|
-
{ intentId: n }
|
|
121
|
-
), {
|
|
122
|
-
intentId: n,
|
|
123
|
-
intentStatus: "SUCCEEDED"
|
|
124
|
-
};
|
|
125
|
-
throw o.console.error(
|
|
126
|
-
"[trails-sdk] useExecuteIntent did not throw IntentStatusError and is not a SUCCEEDED intent",
|
|
127
|
-
{
|
|
128
|
-
intentId: n,
|
|
129
|
-
error: T,
|
|
130
|
-
errorJSON: JSON.stringify(T, null, 2)
|
|
131
|
-
}
|
|
132
|
-
), T;
|
|
133
|
-
}
|
|
134
|
-
return o.console.log(
|
|
135
|
-
"[trails-sdk] useExecuteIntent: Execution successful",
|
|
136
|
-
{
|
|
137
|
-
intentId: n,
|
|
138
|
-
response: i
|
|
139
|
-
}
|
|
140
|
-
), i;
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
function zt({
|
|
145
|
-
walletClient: d,
|
|
146
|
-
fromTokenAddress: n,
|
|
147
|
-
fromChainId: s,
|
|
148
|
-
toTokenAddress: a,
|
|
149
|
-
toChainId: i,
|
|
150
|
-
swapAmount: T,
|
|
151
|
-
tradeType: nt,
|
|
152
|
-
toRecipient: H,
|
|
153
|
-
toCalldata: ot,
|
|
154
|
-
slippageTolerance: X,
|
|
155
|
-
onStatusUpdate: z,
|
|
156
|
-
checkoutOnHandlers: V,
|
|
157
|
-
swapProvider: Q,
|
|
158
|
-
bridgeProvider: O,
|
|
159
|
-
paymasterUrl: mt,
|
|
160
|
-
selectedFeeOption: st,
|
|
161
|
-
nodeGatewayEnv: rt,
|
|
162
|
-
abortSignal: W,
|
|
163
|
-
apiKey: L,
|
|
164
|
-
isSmartWallet: at
|
|
165
|
-
} = {}) {
|
|
166
|
-
rt && (globalThis.__testNodeGatewayEnv = rt);
|
|
167
|
-
const R = Pt(new AbortController()), it = W ? (() => {
|
|
168
|
-
const g = new AbortController();
|
|
169
|
-
return W.addEventListener("abort", () => {
|
|
170
|
-
g.abort(), R.current?.abort();
|
|
171
|
-
}), R.current?.signal.addEventListener("abort", () => {
|
|
172
|
-
g.abort();
|
|
173
|
-
}), g.signal;
|
|
174
|
-
})() : R.current.signal, { trailsApiKey: C, trailsApiUrl: Z, sequenceIndexerUrl: A } = pt(), Y = C, b = gt({
|
|
175
|
-
apiKey: C,
|
|
176
|
-
hostname: Z
|
|
177
|
-
}), $ = xt(), t = Ct(s ?? void 0), r = Ct(i ?? void 0), { supportedTokens: u } = yt(), k = Rt(), m = vt(), { data: E, isLoading: P, error: w, refetch: I } = Ut({
|
|
178
|
-
queryKey: [
|
|
179
|
-
"prepareSend",
|
|
180
|
-
n,
|
|
181
|
-
s,
|
|
182
|
-
a,
|
|
183
|
-
i,
|
|
184
|
-
T?.toString(),
|
|
185
|
-
H,
|
|
186
|
-
ot,
|
|
187
|
-
nt,
|
|
188
|
-
X,
|
|
189
|
-
Q,
|
|
190
|
-
O,
|
|
191
|
-
L,
|
|
192
|
-
at
|
|
193
|
-
],
|
|
194
|
-
queryFn: async () => {
|
|
195
|
-
try {
|
|
196
|
-
if (R.current.signal.aborted && (o.console.log(
|
|
197
|
-
"[trails-sdk] Resetting aborted controller for new query"
|
|
198
|
-
), R.current = new AbortController()), !d || !b || !n || !a || !T || !H || !s || !i || !$)
|
|
199
|
-
return null;
|
|
200
|
-
let g = [];
|
|
201
|
-
try {
|
|
202
|
-
g = (await It({
|
|
203
|
-
account: d.account.address,
|
|
204
|
-
indexerGatewayClient: $,
|
|
205
|
-
trailsClient: b
|
|
206
|
-
})).balances;
|
|
207
|
-
} catch (l) {
|
|
208
|
-
const f = M(l), D = f.includes("Cross-Origin") || f.includes("CORS") || f.includes("Same Origin Policy"), j = f.includes("fetch failed") || f.includes("network");
|
|
209
|
-
if (D || j)
|
|
210
|
-
o.console.warn(
|
|
211
|
-
"[trails-sdk] [useQuote] Network or CORS error fetching balances, proceeding with quote using zero balance:",
|
|
212
|
-
{
|
|
213
|
-
error: f,
|
|
214
|
-
account: d.account.address
|
|
215
|
-
}
|
|
216
|
-
), g = [];
|
|
217
|
-
else
|
|
218
|
-
throw l;
|
|
219
|
-
}
|
|
220
|
-
const y = g.find(
|
|
221
|
-
(l) => l.chainId === s && (l.contractAddress?.toLowerCase() === n.toLowerCase() || !l.contractAddress && n === x)
|
|
222
|
-
)?.balance ?? "0";
|
|
223
|
-
let v = 0;
|
|
224
|
-
try {
|
|
225
|
-
const f = ut(s)?.nativeCurrency?.symbol ?? "";
|
|
226
|
-
f && (v = (await St(b, {
|
|
227
|
-
tokenSymbol: f,
|
|
228
|
-
tokenAddress: x,
|
|
229
|
-
chainId: s
|
|
230
|
-
}))?.priceUsd ?? 0, o.console.log(
|
|
231
|
-
"[trails-sdk] [useQuote] Origin native token price:",
|
|
232
|
-
{
|
|
233
|
-
chainId: s,
|
|
234
|
-
symbol: f,
|
|
235
|
-
priceUsd: v
|
|
236
|
-
}
|
|
237
|
-
));
|
|
238
|
-
} catch (l) {
|
|
239
|
-
o.console.error(
|
|
240
|
-
"[trails-sdk] [useQuote] Error getting origin native token price:",
|
|
241
|
-
l
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
const U = async (l, f) => {
|
|
245
|
-
try {
|
|
246
|
-
const D = f === s ? t : f === i ? r : null;
|
|
247
|
-
if (!D)
|
|
248
|
-
return o.console.warn(
|
|
249
|
-
`[trails-sdk] No RPC client available for chain ${f}`
|
|
250
|
-
), null;
|
|
251
|
-
if (l.toLowerCase() === x.toLowerCase())
|
|
252
|
-
return ut(f)?.nativeCurrency.decimals ?? 18;
|
|
253
|
-
const j = await D.readContract({
|
|
254
|
-
address: l,
|
|
255
|
-
abi: Dt,
|
|
256
|
-
functionName: "decimals"
|
|
257
|
-
});
|
|
258
|
-
return o.console.log(
|
|
259
|
-
`[trails-sdk] Fetched decimals on-chain for token ${l} on chain ${f}: ${j}`
|
|
260
|
-
), j;
|
|
261
|
-
} catch (D) {
|
|
262
|
-
return o.console.error(
|
|
263
|
-
`[trails-sdk] Error fetching decimals on-chain for token ${l} on chain ${f}:`,
|
|
264
|
-
D
|
|
265
|
-
), null;
|
|
266
|
-
}
|
|
267
|
-
}, S = u?.find(
|
|
268
|
-
(l) => l.contractAddress?.toLowerCase() === n?.toLowerCase() && l.chainId === s
|
|
269
|
-
), q = u?.find(
|
|
270
|
-
(l) => l.contractAddress?.toLowerCase() === a?.toLowerCase() && l.chainId === i
|
|
271
|
-
);
|
|
272
|
-
let N = S?.decimals;
|
|
273
|
-
if (!N && n && s) {
|
|
274
|
-
o.console.warn(
|
|
275
|
-
"[trails-sdk] [useQuote] Source token decimals not found in token list, fetching on-chain:",
|
|
276
|
-
{
|
|
277
|
-
originToken: S,
|
|
278
|
-
fromTokenAddress: n,
|
|
279
|
-
fromChainId: s
|
|
280
|
-
}
|
|
281
|
-
);
|
|
282
|
-
const l = await U(
|
|
283
|
-
n,
|
|
284
|
-
s
|
|
285
|
-
);
|
|
286
|
-
l !== null && (N = l);
|
|
287
|
-
}
|
|
288
|
-
if (!N)
|
|
289
|
-
throw o.console.error(
|
|
290
|
-
"[trails-sdk] [useQuote] Source token decimals not found:",
|
|
291
|
-
{
|
|
292
|
-
originToken: S,
|
|
293
|
-
fromTokenAddress: n,
|
|
294
|
-
fromChainId: s
|
|
295
|
-
}
|
|
296
|
-
), new Error("Source token decimals not found");
|
|
297
|
-
let B = q?.decimals;
|
|
298
|
-
if (!B && a && i) {
|
|
299
|
-
o.console.warn(
|
|
300
|
-
"[trails-sdk] Destination token decimals not found in token list, fetching on-chain:",
|
|
301
|
-
{
|
|
302
|
-
destinationToken: q,
|
|
303
|
-
toTokenAddress: a,
|
|
304
|
-
toChainId: i
|
|
305
|
-
}
|
|
306
|
-
);
|
|
307
|
-
const l = await U(
|
|
308
|
-
a,
|
|
309
|
-
i
|
|
310
|
-
);
|
|
311
|
-
l !== null && (B = l);
|
|
312
|
-
}
|
|
313
|
-
if (!B)
|
|
314
|
-
throw o.console.error(
|
|
315
|
-
"[trails-sdk] Destination token decimals not found:",
|
|
316
|
-
{
|
|
317
|
-
destinationToken: q,
|
|
318
|
-
toTokenAddress: a,
|
|
319
|
-
toChainId: i
|
|
320
|
-
}
|
|
321
|
-
), new Error("Destination token decimals not found");
|
|
322
|
-
const ct = q?.symbol ?? "", tt = S?.symbol ?? "", et = {
|
|
323
|
-
account: d.account,
|
|
324
|
-
originTokenAddress: n,
|
|
325
|
-
originChainId: s,
|
|
326
|
-
originTokenBalance: y,
|
|
327
|
-
destinationChainId: i,
|
|
328
|
-
recipient: H,
|
|
329
|
-
destinationTokenAddress: a,
|
|
330
|
-
swapAmount: T.toString(),
|
|
331
|
-
tradeType: nt ?? K.EXACT_OUTPUT,
|
|
332
|
-
originTokenSymbol: tt,
|
|
333
|
-
destinationTokenSymbol: ct,
|
|
334
|
-
destinationCalldata: ot,
|
|
335
|
-
client: d,
|
|
336
|
-
trailsClient: b,
|
|
337
|
-
sourceTokenDecimals: N,
|
|
338
|
-
destinationTokenDecimals: B,
|
|
339
|
-
fee: "0",
|
|
340
|
-
dryMode: !1,
|
|
341
|
-
onTransactionStateChange: z ?? (() => {
|
|
342
|
-
}),
|
|
343
|
-
slippageTolerance: X?.toString(),
|
|
344
|
-
swapProvider: Q,
|
|
345
|
-
bridgeProvider: O,
|
|
346
|
-
paymasterUrl: mt,
|
|
347
|
-
selectedFeeOption: st ?? null,
|
|
348
|
-
abortSignal: it,
|
|
349
|
-
originNativeTokenPriceUsd: v,
|
|
350
|
-
commitIntentFn: k.mutateAsync,
|
|
351
|
-
executeIntentFn: m.mutateAsync,
|
|
352
|
-
checkoutOnHandlers: V,
|
|
353
|
-
sequenceIndexerUrl: A,
|
|
354
|
-
sequenceProjectAccessKey: Y,
|
|
355
|
-
originPublicClient: t ?? void 0,
|
|
356
|
-
destinationPublicClient: r ?? void 0,
|
|
357
|
-
isSmartWallet: at ?? void 0,
|
|
358
|
-
trailsApiKey: C,
|
|
359
|
-
trailsApiUrl: Z
|
|
360
|
-
};
|
|
361
|
-
o.console.log("[trails-sdk] options", et);
|
|
362
|
-
const { quote: c, send: lt } = await wt(et);
|
|
363
|
-
return {
|
|
364
|
-
quote: {
|
|
365
|
-
fromAmount: c.originAmount,
|
|
366
|
-
toAmount: c.destinationAmount,
|
|
367
|
-
fromAmountMin: c.originAmountMin,
|
|
368
|
-
toAmountMin: c.destinationAmountMin,
|
|
369
|
-
originToken: c.originToken,
|
|
370
|
-
destinationToken: c.destinationToken,
|
|
371
|
-
originChain: c.originChain,
|
|
372
|
-
destinationChain: c.destinationChain,
|
|
373
|
-
fees: c.fees,
|
|
374
|
-
priceImpact: c.priceImpact,
|
|
375
|
-
priceImpactUsd: c.priceImpactUsd ?? void 0,
|
|
376
|
-
priceImpactUsdDisplay: c.priceImpactUsdDisplay ?? void 0,
|
|
377
|
-
completionEstimateSeconds: c.completionEstimateSeconds,
|
|
378
|
-
slippageTolerance: c.slippageTolerance,
|
|
379
|
-
transactionStates: c.transactionStates,
|
|
380
|
-
originTokenRate: c.originTokenRate,
|
|
381
|
-
destinationTokenRate: c.destinationTokenRate,
|
|
382
|
-
routeProviders: c.routeProviders,
|
|
383
|
-
fromAmountUsdDisplay: c.originAmountUsdDisplay ?? void 0,
|
|
384
|
-
toAmountUsdDisplay: c.destinationAmountUsdDisplay ?? void 0,
|
|
385
|
-
gasCostUsd: c.gasCostUsd ?? void 0,
|
|
386
|
-
gasCostUsdDisplay: c.gasCostUsdDisplay ?? void 0,
|
|
387
|
-
gasCost: c.gasCost ?? void 0,
|
|
388
|
-
gasCostFormatted: c.gasCostFormatted ?? void 0,
|
|
389
|
-
totalFeesUsd: c.grandTotalUsd ?? void 0,
|
|
390
|
-
totalFeesUsdDisplay: c.grandTotalUsdDisplay ?? void 0,
|
|
391
|
-
totalGasUsd: c.totalGasUsd ?? void 0,
|
|
392
|
-
totalGasUsdDisplay: c.totalGasUsdDisplay ?? void 0,
|
|
393
|
-
allProviderFeesUsd: c.allProviderFeesUsd ?? void 0,
|
|
394
|
-
allProviderFeesUsdDisplay: c.allProviderFeesUsdDisplay ?? void 0
|
|
395
|
-
},
|
|
396
|
-
swap: async () => {
|
|
397
|
-
const {
|
|
398
|
-
depositUserTxnReceipt: l,
|
|
399
|
-
destinationIntentTransaction: f,
|
|
400
|
-
totalCompletionSeconds: D
|
|
401
|
-
} = await lt({
|
|
402
|
-
selectedFeeOption: st ?? null
|
|
403
|
-
});
|
|
404
|
-
return {
|
|
405
|
-
originTransaction: {
|
|
406
|
-
transactionHash: l?.transactionHash,
|
|
407
|
-
explorerUrl: J({
|
|
408
|
-
txHash: l?.transactionHash,
|
|
409
|
-
chainId: s
|
|
410
|
-
}),
|
|
411
|
-
receipt: l
|
|
412
|
-
},
|
|
413
|
-
destinationTransaction: {
|
|
414
|
-
transactionHash: f?.txnHash,
|
|
415
|
-
explorerUrl: J({
|
|
416
|
-
txHash: f?.txnHash,
|
|
417
|
-
chainId: i
|
|
418
|
-
}),
|
|
419
|
-
receipt: f
|
|
420
|
-
},
|
|
421
|
-
totalCompletionSeconds: D
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
};
|
|
425
|
-
} catch (g) {
|
|
426
|
-
throw o.console.error(
|
|
427
|
-
"[trails-sdk] [useQuote] Error getting quote:",
|
|
428
|
-
g
|
|
429
|
-
), M(g);
|
|
430
|
-
}
|
|
431
|
-
},
|
|
432
|
-
// Prevent unnecessary refetching
|
|
433
|
-
enabled: !!(d && b && n && a && T && H && s && i && $ && // !isLoadingTokens &&
|
|
434
|
-
u && u.length > 0),
|
|
435
|
-
staleTime: 30 * 1e3,
|
|
436
|
-
// Consider data fresh for 30 seconds
|
|
437
|
-
refetchOnWindowFocus: !1,
|
|
438
|
-
// Don't refetch when window regains focus
|
|
439
|
-
refetchOnMount: !1,
|
|
440
|
-
// Don't refetch on component remount if data exists
|
|
441
|
-
refetchInterval: !1,
|
|
442
|
-
// Disable automatic polling
|
|
443
|
-
retry: 2,
|
|
444
|
-
// Limit retry attempts
|
|
445
|
-
refetchOnReconnect: !0
|
|
446
|
-
// Refetch when network reconnects
|
|
447
|
-
});
|
|
448
|
-
return {
|
|
449
|
-
quote: E?.quote || null,
|
|
450
|
-
swap: E?.swap || null,
|
|
451
|
-
isLoadingQuote: P,
|
|
452
|
-
quoteError: w,
|
|
453
|
-
quoteErrorPrettified: qt(w),
|
|
454
|
-
refetchQuote: () => I(),
|
|
455
|
-
abort: () => {
|
|
456
|
-
o.console.log("[trails-sdk] useQuote abort() called"), o.console.log(
|
|
457
|
-
"[trails-sdk] Active operations before abort:",
|
|
458
|
-
ft.getAll()
|
|
459
|
-
), R.current.abort(), ft.abortAll(), o.console.log(
|
|
460
|
-
"[trails-sdk] Abort completed, active operations:",
|
|
461
|
-
ft.getAll()
|
|
462
|
-
);
|
|
463
|
-
}
|
|
464
|
-
};
|
|
465
|
-
}
|
|
466
|
-
function Vt(d) {
|
|
467
|
-
const { data: n } = Bt(), { chainId: s } = Ft(), a = Mt(), i = gt(), { trailsApiKey: T, sequenceIndexerUrl: nt } = pt(), {
|
|
468
|
-
openModal: H,
|
|
469
|
-
setPendingSelection: ot,
|
|
470
|
-
setHostTransactionState: X,
|
|
471
|
-
setHostTransactionQuote: z,
|
|
472
|
-
setHostTransactionStates: V,
|
|
473
|
-
setHostTransactionTimestamp: Q,
|
|
474
|
-
hostTransactionState: O,
|
|
475
|
-
setReceiptActionButtonText: mt,
|
|
476
|
-
setOnReceiptAction: st,
|
|
477
|
-
retryTransactionRef: rt
|
|
478
|
-
} = Nt(), W = xt(), { supportedTokens: L } = yt(), at = Rt(), R = vt(), it = Pt(null), C = dt(
|
|
479
|
-
(t) => {
|
|
480
|
-
X((r) => ({
|
|
481
|
-
status: t.status ?? r.status,
|
|
482
|
-
details: t.details === null ? void 0 : t.details ? { ...r.details, ...t.details } : r.details,
|
|
483
|
-
error: t.error === null ? void 0 : t.error !== void 0 ? t.error : r.error,
|
|
484
|
-
result: t.result === null ? void 0 : t.result ? { ...r.result, ...t.result } : r.result,
|
|
485
|
-
retryEnabled: t.retryEnabled !== void 0 ? t.retryEnabled : r.retryEnabled
|
|
46
|
+
function Qe(s) {
|
|
47
|
+
const { data: h } = He(), { chainId: A } = xe(), T = Le(), I = he(), { trailsApiKey: oe, sequenceIndexerUrl: se } = Ae(), {
|
|
48
|
+
openModal: $,
|
|
49
|
+
setPendingSelection: re,
|
|
50
|
+
setHostTransactionState: Q,
|
|
51
|
+
setHostTransactionQuote: M,
|
|
52
|
+
setHostTransactionStates: W,
|
|
53
|
+
setHostTransactionTimestamp: q,
|
|
54
|
+
hostTransactionState: x,
|
|
55
|
+
setReceiptActionButtonText: ae,
|
|
56
|
+
setOnReceiptAction: ie,
|
|
57
|
+
retryTransactionRef: ce
|
|
58
|
+
} = Ie(), F = Be(), { supportedTokens: P } = Ce(), de = we(), le = Ee(), G = Ue(null), m = D(
|
|
59
|
+
(e) => {
|
|
60
|
+
Q((n) => ({
|
|
61
|
+
status: e.status ?? n.status,
|
|
62
|
+
details: e.details === null ? void 0 : e.details ? { ...n.details, ...e.details } : n.details,
|
|
63
|
+
error: e.error === null ? void 0 : e.error !== void 0 ? e.error : n.error,
|
|
64
|
+
result: e.result === null ? void 0 : e.result ? { ...n.result, ...e.result } : n.result,
|
|
65
|
+
retryEnabled: e.retryEnabled !== void 0 ? e.retryEnabled : n.retryEnabled
|
|
486
66
|
}));
|
|
487
67
|
},
|
|
488
|
-
[
|
|
489
|
-
),
|
|
490
|
-
if (
|
|
68
|
+
[Q]
|
|
69
|
+
), X = async (e, n, o) => {
|
|
70
|
+
if (d.console.log(
|
|
491
71
|
"[trails-sdk] [useTrailsSendTransaction] Executing transaction",
|
|
492
|
-
{ variables:
|
|
493
|
-
), !
|
|
72
|
+
{ variables: e, originSelection: n }
|
|
73
|
+
), !h || !h.account)
|
|
494
74
|
throw new Error(
|
|
495
75
|
"Wallet client not available. Please connect your wallet."
|
|
496
76
|
);
|
|
497
|
-
if (!
|
|
77
|
+
if (!e.to)
|
|
498
78
|
throw new Error("Transaction 'to' address is required.");
|
|
499
|
-
let
|
|
500
|
-
if (
|
|
501
|
-
|
|
502
|
-
else if (
|
|
503
|
-
|
|
504
|
-
else if (
|
|
505
|
-
const
|
|
506
|
-
if (!
|
|
79
|
+
let a, r, g;
|
|
80
|
+
if (n)
|
|
81
|
+
a = n.fromTokenAddress, r = n.fromChainId, g = n.fromAmount;
|
|
82
|
+
else if (e.fromTokenAddress && e.fromChainId && e.fromAmount)
|
|
83
|
+
a = e.fromTokenAddress, r = e.fromChainId, g = e.fromAmount;
|
|
84
|
+
else if (e.to && e.value !== void 0) {
|
|
85
|
+
const t = A || T;
|
|
86
|
+
if (!t)
|
|
507
87
|
throw new Error("Chain ID not available. Please connect your wallet.");
|
|
508
|
-
|
|
88
|
+
r = t, a = p, g = e.value.toString();
|
|
509
89
|
} else
|
|
510
90
|
throw new Error(
|
|
511
91
|
"Origin token parameters are required. Please provide 'value' (native token), or 'fromTokenAddress'/'fromChainId'/'fromAmount' (ERC20 token), or select via modal."
|
|
512
92
|
);
|
|
513
|
-
const
|
|
514
|
-
if (!
|
|
93
|
+
const w = A || T;
|
|
94
|
+
if (!w)
|
|
515
95
|
throw new Error("Chain ID not available. Please connect your wallet.");
|
|
516
|
-
let
|
|
517
|
-
if (
|
|
518
|
-
|
|
519
|
-
(
|
|
520
|
-
)?.chainId ??
|
|
521
|
-
else if (
|
|
522
|
-
|
|
96
|
+
let C, k, c, l;
|
|
97
|
+
if (e.tokenAddress && e.tokenAmount)
|
|
98
|
+
C = e.tokenAddress, k = P?.find(
|
|
99
|
+
(i) => i.contractAddress?.toLowerCase() === e.tokenAddress?.toLowerCase()
|
|
100
|
+
)?.chainId ?? w, c = e.tokenAmount, l = e.to;
|
|
101
|
+
else if (e.to && e.value !== void 0)
|
|
102
|
+
C = p, k = w, c = e.value.toString(), l = e.to;
|
|
523
103
|
else
|
|
524
104
|
throw new Error(
|
|
525
105
|
"Either 'value' or 'tokenAddress'/'tokenAmount' must be provided."
|
|
526
106
|
);
|
|
527
|
-
const
|
|
528
|
-
if (
|
|
107
|
+
const f = e.tokenAddress && e.tokenAmount ? H.EXACT_OUTPUT : H.EXACT_INPUT;
|
|
108
|
+
if (f === H.EXACT_INPUT && !g)
|
|
529
109
|
throw new Error(
|
|
530
110
|
"Origin amount is required for this transaction. Please provide 'value' or 'fromAmount'."
|
|
531
111
|
);
|
|
532
|
-
const
|
|
533
|
-
let
|
|
112
|
+
const L = f === H.EXACT_OUTPUT ? c : g;
|
|
113
|
+
let E = [];
|
|
534
114
|
try {
|
|
535
|
-
|
|
536
|
-
account:
|
|
537
|
-
indexerGatewayClient:
|
|
538
|
-
trailsClient:
|
|
115
|
+
E = (await Se({
|
|
116
|
+
account: h.account.address,
|
|
117
|
+
indexerGatewayClient: F,
|
|
118
|
+
trailsClient: I
|
|
539
119
|
})).balances;
|
|
540
|
-
} catch (
|
|
541
|
-
|
|
120
|
+
} catch (t) {
|
|
121
|
+
d.console.warn(
|
|
542
122
|
"[trails-sdk] [useTrailsSendTransaction] Error fetching balances, proceeding with zero balance",
|
|
543
|
-
|
|
544
|
-
),
|
|
123
|
+
t
|
|
124
|
+
), E = [];
|
|
545
125
|
}
|
|
546
|
-
const
|
|
547
|
-
(
|
|
126
|
+
const z = E.find(
|
|
127
|
+
(t) => t.chainId === r && (t.contractAddress?.toLowerCase() === a?.toLowerCase() || !t.contractAddress && a === p)
|
|
548
128
|
)?.balance ?? "0";
|
|
549
|
-
let
|
|
129
|
+
let K = 0;
|
|
550
130
|
try {
|
|
551
|
-
const
|
|
552
|
-
|
|
553
|
-
tokenSymbol:
|
|
554
|
-
tokenAddress:
|
|
555
|
-
chainId:
|
|
131
|
+
const i = te(r)?.nativeCurrency?.symbol ?? "";
|
|
132
|
+
i && (K = (await ye(I, {
|
|
133
|
+
tokenSymbol: i,
|
|
134
|
+
tokenAddress: p,
|
|
135
|
+
chainId: r
|
|
556
136
|
}))?.priceUsd ?? 0);
|
|
557
|
-
} catch (
|
|
558
|
-
|
|
137
|
+
} catch (t) {
|
|
138
|
+
d.console.warn(
|
|
559
139
|
"[trails-sdk] [useTrailsSendTransaction] Error getting native token price",
|
|
560
|
-
|
|
140
|
+
t
|
|
561
141
|
);
|
|
562
142
|
}
|
|
563
|
-
const
|
|
564
|
-
(
|
|
565
|
-
),
|
|
566
|
-
(
|
|
567
|
-
), { getChainRpcClient:
|
|
143
|
+
const v = P?.find(
|
|
144
|
+
(t) => t.contractAddress?.toLowerCase() === a?.toLowerCase() && t.chainId === r
|
|
145
|
+
), J = P?.find(
|
|
146
|
+
(t) => t.contractAddress?.toLowerCase() === C?.toLowerCase() && t.chainId === k
|
|
147
|
+
), { getChainRpcClient: j } = await import("./index-C_EsqqSn.js").then((t) => t.aX), Y = j(r), Z = j(k), b = async (t, i) => {
|
|
568
148
|
try {
|
|
569
|
-
const
|
|
570
|
-
return
|
|
571
|
-
address:
|
|
572
|
-
abi:
|
|
149
|
+
const y = i === r ? Y : i === k ? Z : j(i);
|
|
150
|
+
return y ? t.toLowerCase() === p.toLowerCase() ? te(i)?.nativeCurrency.decimals ?? 18 : await y.readContract({
|
|
151
|
+
address: t,
|
|
152
|
+
abi: Oe,
|
|
573
153
|
functionName: "decimals"
|
|
574
154
|
}) : null;
|
|
575
|
-
} catch (
|
|
576
|
-
return
|
|
577
|
-
`[trails-sdk] Error fetching decimals on-chain for token ${
|
|
578
|
-
|
|
155
|
+
} catch (y) {
|
|
156
|
+
return d.console.error(
|
|
157
|
+
`[trails-sdk] Error fetching decimals on-chain for token ${t} on chain ${i}:`,
|
|
158
|
+
y
|
|
579
159
|
), null;
|
|
580
160
|
}
|
|
581
161
|
};
|
|
582
|
-
let
|
|
583
|
-
if (!
|
|
584
|
-
const
|
|
585
|
-
|
|
586
|
-
|
|
162
|
+
let R = v?.decimals;
|
|
163
|
+
if (!R && a) {
|
|
164
|
+
const t = await b(
|
|
165
|
+
a,
|
|
166
|
+
r
|
|
587
167
|
);
|
|
588
|
-
|
|
168
|
+
t !== null && (R = t);
|
|
589
169
|
}
|
|
590
|
-
|
|
591
|
-
let
|
|
592
|
-
if (!
|
|
593
|
-
const
|
|
594
|
-
|
|
595
|
-
|
|
170
|
+
R || (R = 18);
|
|
171
|
+
let U = J?.decimals;
|
|
172
|
+
if (!U && C) {
|
|
173
|
+
const t = await b(
|
|
174
|
+
C,
|
|
175
|
+
k
|
|
596
176
|
);
|
|
597
|
-
|
|
177
|
+
t !== null && (U = t);
|
|
598
178
|
}
|
|
599
|
-
|
|
600
|
-
const
|
|
601
|
-
|
|
602
|
-
}, { send:
|
|
603
|
-
account:
|
|
604
|
-
originTokenAddress:
|
|
605
|
-
originChainId:
|
|
606
|
-
originTokenBalance:
|
|
607
|
-
destinationChainId:
|
|
608
|
-
recipient:
|
|
609
|
-
destinationTokenAddress:
|
|
610
|
-
swapAmount:
|
|
611
|
-
tradeType:
|
|
612
|
-
originTokenSymbol:
|
|
613
|
-
destinationTokenSymbol:
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
destinationPublicClient: c ?? void 0,
|
|
634
|
-
isSmartWallet: d?.isSmartWallet ?? void 0
|
|
179
|
+
U || (U = 18);
|
|
180
|
+
const fe = J?.symbol ?? "", Te = v?.symbol ?? "", me = (t) => {
|
|
181
|
+
o?.trackInWidget && W(t), s?.onStatusUpdate?.(t);
|
|
182
|
+
}, { send: ge, quote: ke } = await pe({
|
|
183
|
+
account: h.account,
|
|
184
|
+
originTokenAddress: a,
|
|
185
|
+
originChainId: r,
|
|
186
|
+
originTokenBalance: z,
|
|
187
|
+
destinationChainId: k,
|
|
188
|
+
recipient: l,
|
|
189
|
+
destinationTokenAddress: C,
|
|
190
|
+
swapAmount: L,
|
|
191
|
+
tradeType: f,
|
|
192
|
+
originTokenSymbol: Te,
|
|
193
|
+
destinationTokenSymbol: fe,
|
|
194
|
+
client: h,
|
|
195
|
+
trailsClient: I,
|
|
196
|
+
destinationCalldata: e.data ? e.data.toString() : void 0,
|
|
197
|
+
onTransactionStateChange: me,
|
|
198
|
+
sourceTokenDecimals: R,
|
|
199
|
+
destinationTokenDecimals: U,
|
|
200
|
+
paymasterUrl: s?.paymasterUrl,
|
|
201
|
+
slippageTolerance: s?.slippageTolerance?.toString(),
|
|
202
|
+
originNativeTokenPriceUsd: K,
|
|
203
|
+
swapProvider: s?.swapProvider,
|
|
204
|
+
bridgeProvider: s?.bridgeProvider,
|
|
205
|
+
commitIntentFn: de.mutateAsync,
|
|
206
|
+
executeIntentFn: le.mutateAsync,
|
|
207
|
+
checkoutOnHandlers: s?.checkoutOnHandlers,
|
|
208
|
+
sequenceIndexerUrl: se,
|
|
209
|
+
sequenceProjectAccessKey: oe,
|
|
210
|
+
originPublicClient: Y ?? void 0,
|
|
211
|
+
destinationPublicClient: Z ?? void 0,
|
|
212
|
+
isSmartWallet: s?.isSmartWallet ?? void 0
|
|
635
213
|
});
|
|
636
|
-
|
|
214
|
+
o?.trackInWidget && (M(ke ?? null), x.details || m({
|
|
637
215
|
details: {
|
|
638
|
-
to:
|
|
639
|
-
tokenAddress:
|
|
640
|
-
tokenAmount:
|
|
641
|
-
toChainId:
|
|
642
|
-
data:
|
|
216
|
+
to: l,
|
|
217
|
+
tokenAddress: C,
|
|
218
|
+
tokenAmount: f === H.EXACT_OUTPUT ? c : void 0,
|
|
219
|
+
toChainId: k,
|
|
220
|
+
data: e.data
|
|
643
221
|
}
|
|
644
|
-
}), (!
|
|
222
|
+
}), (!x.status || x.status === "idle") && q(Date.now()));
|
|
645
223
|
try {
|
|
646
|
-
|
|
224
|
+
o?.trackInWidget && m({ retryEnabled: !1 });
|
|
647
225
|
const {
|
|
648
|
-
depositUserTxnReceipt:
|
|
649
|
-
destinationIntentTransaction:
|
|
650
|
-
totalCompletionSeconds:
|
|
651
|
-
} = await
|
|
226
|
+
depositUserTxnReceipt: t,
|
|
227
|
+
destinationIntentTransaction: i,
|
|
228
|
+
totalCompletionSeconds: y
|
|
229
|
+
} = await ge({
|
|
652
230
|
selectedFeeOption: null,
|
|
653
231
|
// Transition to "pending" when wallet signature is complete
|
|
654
232
|
onOriginSend: () => {
|
|
655
|
-
|
|
233
|
+
o?.trackInWidget && m({ status: "pending", error: null });
|
|
656
234
|
}
|
|
657
235
|
});
|
|
658
|
-
return
|
|
236
|
+
return o?.trackInWidget && m({
|
|
659
237
|
status: "success",
|
|
660
238
|
result: {
|
|
661
|
-
originTxHash:
|
|
662
|
-
originExplorerUrl:
|
|
663
|
-
txHash:
|
|
664
|
-
chainId:
|
|
239
|
+
originTxHash: t?.transactionHash,
|
|
240
|
+
originExplorerUrl: t?.transactionHash ? B({
|
|
241
|
+
txHash: t.transactionHash,
|
|
242
|
+
chainId: r
|
|
665
243
|
}) : void 0,
|
|
666
|
-
destinationTxHash:
|
|
667
|
-
destinationExplorerUrl:
|
|
668
|
-
txHash:
|
|
669
|
-
chainId:
|
|
244
|
+
destinationTxHash: i?.txnHash,
|
|
245
|
+
destinationExplorerUrl: i?.txnHash ? B({
|
|
246
|
+
txHash: i.txnHash,
|
|
247
|
+
chainId: k
|
|
670
248
|
}) : void 0
|
|
671
249
|
}
|
|
672
250
|
}), {
|
|
673
251
|
originTransaction: {
|
|
674
|
-
transactionHash:
|
|
675
|
-
explorerUrl:
|
|
676
|
-
txHash:
|
|
677
|
-
chainId:
|
|
252
|
+
transactionHash: t?.transactionHash,
|
|
253
|
+
explorerUrl: B({
|
|
254
|
+
txHash: t?.transactionHash,
|
|
255
|
+
chainId: r
|
|
678
256
|
}),
|
|
679
|
-
receipt:
|
|
257
|
+
receipt: t
|
|
680
258
|
},
|
|
681
259
|
destinationTransaction: {
|
|
682
|
-
transactionHash:
|
|
683
|
-
explorerUrl:
|
|
684
|
-
txHash:
|
|
685
|
-
chainId:
|
|
260
|
+
transactionHash: i?.txnHash,
|
|
261
|
+
explorerUrl: B({
|
|
262
|
+
txHash: i?.txnHash,
|
|
263
|
+
chainId: k
|
|
686
264
|
}),
|
|
687
|
-
receipt:
|
|
265
|
+
receipt: i
|
|
688
266
|
},
|
|
689
|
-
totalCompletionSeconds:
|
|
267
|
+
totalCompletionSeconds: y
|
|
690
268
|
};
|
|
691
|
-
} catch (
|
|
692
|
-
if (
|
|
693
|
-
const
|
|
694
|
-
|
|
269
|
+
} catch (t) {
|
|
270
|
+
if (o?.trackInWidget) {
|
|
271
|
+
const i = _(t);
|
|
272
|
+
m(i ? {
|
|
695
273
|
status: "confirmation",
|
|
696
274
|
error: null,
|
|
697
275
|
retryEnabled: !0
|
|
698
276
|
} : {
|
|
699
277
|
status: "error",
|
|
700
|
-
error:
|
|
278
|
+
error: O(t),
|
|
701
279
|
retryEnabled: !1
|
|
702
280
|
});
|
|
703
281
|
}
|
|
704
|
-
throw
|
|
282
|
+
throw t;
|
|
705
283
|
}
|
|
706
|
-
},
|
|
707
|
-
mutationFn: async (
|
|
708
|
-
|
|
284
|
+
}, u = Re({
|
|
285
|
+
mutationFn: async (e) => {
|
|
286
|
+
d.console.log(
|
|
709
287
|
"[trails-sdk] [useTrailsSendTransaction] Starting transaction",
|
|
710
|
-
|
|
711
|
-
),
|
|
712
|
-
|
|
713
|
-
),
|
|
714
|
-
const
|
|
715
|
-
let
|
|
716
|
-
if (
|
|
717
|
-
const
|
|
718
|
-
(
|
|
288
|
+
e
|
|
289
|
+
), ae(
|
|
290
|
+
s?.receiptActionButtonText ?? "Transact Again"
|
|
291
|
+
), ie(s?.onReceiptAction ?? null);
|
|
292
|
+
const n = e.value !== void 0, o = e.fromTokenAddress !== void 0 && e.fromChainId !== void 0, a = n || o;
|
|
293
|
+
let r;
|
|
294
|
+
if (e.tokenAddress && P) {
|
|
295
|
+
const c = P.find(
|
|
296
|
+
(l) => l.contractAddress?.toLowerCase() === e.tokenAddress?.toLowerCase()
|
|
719
297
|
);
|
|
720
|
-
|
|
298
|
+
c && (r = c.chainId);
|
|
721
299
|
}
|
|
722
|
-
|
|
723
|
-
let
|
|
724
|
-
if (
|
|
300
|
+
r || (r = A || T);
|
|
301
|
+
let g = !0, w = !0;
|
|
302
|
+
if (h?.account)
|
|
725
303
|
try {
|
|
726
|
-
if (
|
|
727
|
-
let
|
|
728
|
-
|
|
729
|
-
account:
|
|
730
|
-
token:
|
|
731
|
-
amount:
|
|
732
|
-
chainId:
|
|
733
|
-
indexerGatewayClient:
|
|
734
|
-
trailsClient:
|
|
735
|
-
}),
|
|
304
|
+
if (a) {
|
|
305
|
+
let c, l, f;
|
|
306
|
+
e.value !== void 0 ? (c = p, l = A || T || 1, f = e.value.toString()) : e.fromTokenAddress && e.fromChainId && (c = e.fromTokenAddress, l = e.fromChainId, f = e.fromAmount), c && l && f && f !== "0" && (g = await ee({
|
|
307
|
+
account: h.account.address,
|
|
308
|
+
token: c,
|
|
309
|
+
amount: f,
|
|
310
|
+
chainId: l,
|
|
311
|
+
indexerGatewayClient: F,
|
|
312
|
+
trailsClient: I
|
|
313
|
+
}), d.console.log(
|
|
736
314
|
"[trails-sdk] [useTrailsSendTransaction] Origin token balance check:",
|
|
737
315
|
{
|
|
738
|
-
tokenAddress:
|
|
739
|
-
amount:
|
|
740
|
-
chainId:
|
|
741
|
-
hasSufficientBalance:
|
|
316
|
+
tokenAddress: c,
|
|
317
|
+
amount: f,
|
|
318
|
+
chainId: l,
|
|
319
|
+
hasSufficientBalance: g
|
|
742
320
|
}
|
|
743
321
|
));
|
|
744
322
|
}
|
|
745
|
-
|
|
746
|
-
account:
|
|
747
|
-
token:
|
|
748
|
-
amount:
|
|
749
|
-
chainId:
|
|
750
|
-
indexerGatewayClient:
|
|
751
|
-
trailsClient:
|
|
752
|
-
}),
|
|
323
|
+
g && e.tokenAddress && e.tokenAmount && (w = await ee({
|
|
324
|
+
account: h.account.address,
|
|
325
|
+
token: e.tokenAddress,
|
|
326
|
+
amount: e.tokenAmount,
|
|
327
|
+
chainId: r,
|
|
328
|
+
indexerGatewayClient: F,
|
|
329
|
+
trailsClient: I
|
|
330
|
+
}), d.console.log(
|
|
753
331
|
"[trails-sdk] [useTrailsSendTransaction] Destination token balance check:",
|
|
754
332
|
{
|
|
755
|
-
tokenAddress:
|
|
756
|
-
tokenAmount:
|
|
757
|
-
chainId:
|
|
758
|
-
hasSufficientBalance:
|
|
333
|
+
tokenAddress: e.tokenAddress,
|
|
334
|
+
tokenAmount: e.tokenAmount,
|
|
335
|
+
chainId: r,
|
|
336
|
+
hasSufficientBalance: w
|
|
759
337
|
}
|
|
760
338
|
));
|
|
761
|
-
} catch (
|
|
762
|
-
|
|
339
|
+
} catch (c) {
|
|
340
|
+
d.console.warn(
|
|
763
341
|
"[trails-sdk] [useTrailsSendTransaction] Error checking balances, defaulting to origin selection:",
|
|
764
|
-
|
|
765
|
-
),
|
|
342
|
+
c
|
|
343
|
+
), g = !1, w = !1;
|
|
766
344
|
}
|
|
767
|
-
const
|
|
768
|
-
if (
|
|
345
|
+
const C = !a || !g || !w;
|
|
346
|
+
if (d.console.log(
|
|
769
347
|
"[trails-sdk] [useTrailsSendTransaction] Origin selection decision:",
|
|
770
348
|
{
|
|
771
|
-
hasOriginParams:
|
|
772
|
-
hasSufficientOriginBalance:
|
|
773
|
-
hasSufficientDestinationTokenBalance:
|
|
774
|
-
needsOriginSelection:
|
|
349
|
+
hasOriginParams: a,
|
|
350
|
+
hasSufficientOriginBalance: g,
|
|
351
|
+
hasSufficientDestinationTokenBalance: w,
|
|
352
|
+
needsOriginSelection: C
|
|
775
353
|
}
|
|
776
|
-
),
|
|
777
|
-
const
|
|
778
|
-
to:
|
|
779
|
-
tokenAddress:
|
|
780
|
-
tokenAmount:
|
|
781
|
-
toChainId:
|
|
782
|
-
data:
|
|
354
|
+
), C) {
|
|
355
|
+
const c = !(e.tokenAddress && e.tokenAmount), l = {
|
|
356
|
+
to: e.to,
|
|
357
|
+
tokenAddress: e.tokenAddress,
|
|
358
|
+
tokenAmount: e.tokenAmount,
|
|
359
|
+
toChainId: r,
|
|
360
|
+
data: e.data
|
|
783
361
|
};
|
|
784
|
-
return
|
|
362
|
+
return m({
|
|
785
363
|
status: "awaiting-origin",
|
|
786
|
-
details:
|
|
364
|
+
details: l,
|
|
787
365
|
error: null,
|
|
788
366
|
result: null
|
|
789
|
-
}),
|
|
790
|
-
|
|
791
|
-
resolve: async (
|
|
367
|
+
}), M(null), W([]), q(Date.now()), new Promise((f, L) => {
|
|
368
|
+
re({
|
|
369
|
+
resolve: async (E) => {
|
|
792
370
|
try {
|
|
793
|
-
|
|
794
|
-
const S = await
|
|
371
|
+
m({ status: "confirmation" });
|
|
372
|
+
const S = await X(e, E, {
|
|
795
373
|
trackInWidget: !0
|
|
796
374
|
});
|
|
797
|
-
|
|
375
|
+
f(S);
|
|
798
376
|
} catch (S) {
|
|
799
|
-
|
|
377
|
+
_(S) || m({
|
|
800
378
|
status: "error",
|
|
801
|
-
error:
|
|
802
|
-
}),
|
|
379
|
+
error: O(S)
|
|
380
|
+
}), L(S);
|
|
803
381
|
}
|
|
804
382
|
},
|
|
805
|
-
reject: (
|
|
806
|
-
const S =
|
|
807
|
-
|
|
383
|
+
reject: (E) => {
|
|
384
|
+
const S = E instanceof Error ? E : new Error(String(E));
|
|
385
|
+
m({
|
|
808
386
|
status: "error",
|
|
809
|
-
error:
|
|
810
|
-
}),
|
|
387
|
+
error: O(S)
|
|
388
|
+
}), L(S);
|
|
811
389
|
},
|
|
812
|
-
requireAmountInput:
|
|
390
|
+
requireAmountInput: c
|
|
813
391
|
}), setTimeout(() => {
|
|
814
|
-
|
|
392
|
+
d.console.log(
|
|
815
393
|
"[trails-sdk] [useTrailsSendTransaction] Calling openModal()"
|
|
816
|
-
),
|
|
394
|
+
), $();
|
|
817
395
|
}, 0);
|
|
818
396
|
});
|
|
819
397
|
}
|
|
820
|
-
const
|
|
821
|
-
to:
|
|
822
|
-
tokenAddress:
|
|
823
|
-
tokenAmount:
|
|
824
|
-
toChainId:
|
|
825
|
-
data:
|
|
398
|
+
const k = {
|
|
399
|
+
to: e.to,
|
|
400
|
+
tokenAddress: e.tokenAddress,
|
|
401
|
+
tokenAmount: e.tokenAmount,
|
|
402
|
+
toChainId: r,
|
|
403
|
+
data: e.data
|
|
826
404
|
};
|
|
827
|
-
return
|
|
405
|
+
return m({
|
|
828
406
|
status: "confirmation",
|
|
829
|
-
details:
|
|
407
|
+
details: k,
|
|
830
408
|
error: null,
|
|
831
409
|
result: null
|
|
832
|
-
}),
|
|
410
|
+
}), M(null), W([]), q(Date.now()), $(), X(e, void 0, { trackInWidget: !0 });
|
|
833
411
|
},
|
|
834
|
-
onSuccess: (
|
|
835
|
-
|
|
412
|
+
onSuccess: (e, n) => {
|
|
413
|
+
d.console.log(
|
|
836
414
|
"[trails-sdk] [useTrailsSendTransaction] Transaction successful",
|
|
837
|
-
{ data:
|
|
838
|
-
),
|
|
415
|
+
{ data: e, variables: n }
|
|
416
|
+
), s?.onSuccess?.(e, n);
|
|
839
417
|
},
|
|
840
|
-
onError: (
|
|
841
|
-
|
|
418
|
+
onError: (e, n) => {
|
|
419
|
+
d.console.error(
|
|
842
420
|
"[trails-sdk] [useTrailsSendTransaction] Transaction error",
|
|
843
|
-
{ error:
|
|
421
|
+
{ error: e, variables: n }
|
|
844
422
|
);
|
|
845
|
-
const
|
|
846
|
-
|
|
423
|
+
const o = O(e), a = _(e);
|
|
424
|
+
x.status !== "idle" && !a && m({
|
|
847
425
|
status: "error",
|
|
848
|
-
error:
|
|
849
|
-
}),
|
|
426
|
+
error: o
|
|
427
|
+
}), s?.onError?.(new Error(o), n);
|
|
850
428
|
},
|
|
851
|
-
onSettled: (
|
|
852
|
-
|
|
429
|
+
onSettled: (e, n, o) => {
|
|
430
|
+
d.console.log(
|
|
853
431
|
"[trails-sdk] [useTrailsSendTransaction] Transaction settled",
|
|
854
|
-
{ data:
|
|
855
|
-
),
|
|
432
|
+
{ data: e, error: n, variables: o }
|
|
433
|
+
), s?.onSettled?.(e, n, o);
|
|
856
434
|
}
|
|
857
|
-
}),
|
|
858
|
-
(
|
|
859
|
-
|
|
860
|
-
onSuccess: (
|
|
861
|
-
|
|
435
|
+
}), N = D(
|
|
436
|
+
(e, n) => {
|
|
437
|
+
u.mutate(e, {
|
|
438
|
+
onSuccess: (o) => {
|
|
439
|
+
n?.onSuccess?.(o);
|
|
862
440
|
},
|
|
863
|
-
onError: (
|
|
864
|
-
|
|
441
|
+
onError: (o) => {
|
|
442
|
+
n?.onError?.(o);
|
|
865
443
|
},
|
|
866
|
-
onSettled: (
|
|
867
|
-
|
|
444
|
+
onSettled: (o, a) => {
|
|
445
|
+
n?.onSettled?.(o, a);
|
|
868
446
|
}
|
|
869
447
|
});
|
|
870
448
|
},
|
|
871
|
-
[
|
|
872
|
-
),
|
|
873
|
-
async (
|
|
874
|
-
onSuccess: (
|
|
875
|
-
|
|
449
|
+
[u]
|
|
450
|
+
), ue = D(
|
|
451
|
+
async (e, n) => u.mutateAsync(e, {
|
|
452
|
+
onSuccess: (o) => {
|
|
453
|
+
n?.onSuccess?.(o);
|
|
876
454
|
},
|
|
877
|
-
onError: (
|
|
878
|
-
|
|
455
|
+
onError: (o) => {
|
|
456
|
+
n?.onError?.(o);
|
|
879
457
|
},
|
|
880
|
-
onSettled: (
|
|
881
|
-
|
|
458
|
+
onSettled: (o, a) => {
|
|
459
|
+
n?.onSettled?.(o, a);
|
|
882
460
|
}
|
|
883
461
|
}),
|
|
884
|
-
[
|
|
885
|
-
),
|
|
886
|
-
|
|
887
|
-
}, [
|
|
888
|
-
return
|
|
889
|
-
sendTransaction:
|
|
890
|
-
sendTransactionAsync:
|
|
891
|
-
retry:
|
|
892
|
-
data:
|
|
893
|
-
error:
|
|
894
|
-
isPending:
|
|
895
|
-
isSuccess:
|
|
896
|
-
isError:
|
|
897
|
-
isIdle:
|
|
898
|
-
status:
|
|
899
|
-
reset:
|
|
900
|
-
variables:
|
|
462
|
+
[u]
|
|
463
|
+
), V = D(() => {
|
|
464
|
+
G.current && N(G.current);
|
|
465
|
+
}, [N]);
|
|
466
|
+
return ce.current = V, {
|
|
467
|
+
sendTransaction: N,
|
|
468
|
+
sendTransactionAsync: ue,
|
|
469
|
+
retry: V,
|
|
470
|
+
data: u.data,
|
|
471
|
+
error: u.error,
|
|
472
|
+
isPending: u.isPending,
|
|
473
|
+
isSuccess: u.isSuccess,
|
|
474
|
+
isError: u.isError,
|
|
475
|
+
isIdle: u.isIdle,
|
|
476
|
+
status: u.status,
|
|
477
|
+
reset: u.reset,
|
|
478
|
+
variables: u.variables
|
|
901
479
|
};
|
|
902
480
|
}
|
|
903
481
|
export {
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
482
|
+
Ve as InsufficientBalanceError,
|
|
483
|
+
ze as TRAILS_ROUTER_PLACEHOLDER_AMOUNT,
|
|
484
|
+
H as TradeType,
|
|
485
|
+
Ke as TrailsClient,
|
|
486
|
+
ve as TrailsHookModal,
|
|
487
|
+
Je as TrailsModalProvider,
|
|
488
|
+
Ye as TrailsProvider,
|
|
489
|
+
Ze as TrailsWidget,
|
|
490
|
+
be as UserRejectionError,
|
|
491
|
+
et as attemptSwitchChain,
|
|
492
|
+
tt as buildRefundTransaction,
|
|
493
|
+
nt as buildRefundTransactionWithSignature,
|
|
494
|
+
ot as calcAmountUsdPrice,
|
|
495
|
+
st as calculateIntentAddress,
|
|
496
|
+
rt as calculateOriginAndDestinationIntentAddresses,
|
|
497
|
+
at as commitIntent,
|
|
498
|
+
it as convertApiTokenInfoToToken,
|
|
499
|
+
ct as createModalController,
|
|
500
|
+
dt as determineRefundCall,
|
|
501
|
+
lt as formatBalanceFields,
|
|
502
|
+
ut as formatPriceFields,
|
|
503
|
+
ft as formatTvl,
|
|
504
|
+
Tt as formatUsdAmountFormatted,
|
|
505
|
+
mt as formatUsdFields,
|
|
506
|
+
gt as getAccountTotalBalanceUsd,
|
|
507
|
+
kt as getAccountTransactionHistory,
|
|
508
|
+
ht as getAllChains,
|
|
509
|
+
te as getChainInfo,
|
|
510
|
+
At as getChainRpcClient,
|
|
511
|
+
It as getERC20TransferData,
|
|
512
|
+
ee as getHasSufficientBalanceToken,
|
|
513
|
+
Ct as getHasSufficientBalanceUsd,
|
|
514
|
+
wt as getIntent,
|
|
515
|
+
Et as getIsApiError,
|
|
516
|
+
St as getIsBalanceTooLowError,
|
|
517
|
+
yt as getIsInsufficientLiquidityError,
|
|
518
|
+
pt as getIsNoAvailableQuoteError,
|
|
519
|
+
Pt as getIsQuoteFailedError,
|
|
520
|
+
Rt as getIsQuoteInputError,
|
|
521
|
+
Ut as getIsQuoteTokenError,
|
|
522
|
+
Ht as getIsRateLimitedError,
|
|
523
|
+
xt as getIsRequiredAmountNotMetError,
|
|
524
|
+
_ as getIsUserRejectionError,
|
|
525
|
+
Lt as getIsWalletAlreadyConnectedError,
|
|
526
|
+
Ot as getMinLogLevel,
|
|
527
|
+
Bt as getPrettifiedErrorMessage,
|
|
528
|
+
Dt as getRpcUrl,
|
|
529
|
+
Mt as getSupportedChains,
|
|
530
|
+
Wt as getSupportedTokens,
|
|
531
|
+
ye as getTokenPrice,
|
|
532
|
+
qt as getTokenPrices,
|
|
533
|
+
Ft as getTrailsClient,
|
|
534
|
+
Nt as getTxTimeDiff,
|
|
535
|
+
jt as invalidateTokenPricesCache,
|
|
536
|
+
_t as isValidInteger,
|
|
537
|
+
$t as isValidNumeric,
|
|
538
|
+
d as logger,
|
|
539
|
+
Qt as normalizeNumber,
|
|
540
|
+
Gt as pollIntentReceipt,
|
|
541
|
+
pe as prepareSend,
|
|
542
|
+
Xt as quoteIntent,
|
|
543
|
+
Vt as sendOriginTransaction,
|
|
544
|
+
zt as signPayload,
|
|
545
|
+
Kt as useAccountTotalBalanceUsd,
|
|
546
|
+
vt as useAccountTransactionHistory,
|
|
547
|
+
Jt as useChainRpcClient,
|
|
548
|
+
we as useCommitIntent,
|
|
549
|
+
Ee as useExecuteIntent,
|
|
550
|
+
Yt as useGetIntent,
|
|
551
|
+
Zt as useGetTokenImageUrl,
|
|
552
|
+
bt as useHasSufficientBalanceToken,
|
|
553
|
+
en as useHasSufficientBalanceUsd,
|
|
554
|
+
Tn as useIndexerGatewayClient,
|
|
555
|
+
$e as useIntentReceiptMonitor,
|
|
556
|
+
tn as useIntentRecover,
|
|
557
|
+
nn as useIntentTransactionHistory,
|
|
558
|
+
on as useQuote,
|
|
559
|
+
sn as useSupportedChains,
|
|
560
|
+
Ce as useSupportedTokens,
|
|
561
|
+
rn as useTokenAddress,
|
|
562
|
+
an as useTokenBalances,
|
|
563
|
+
cn as useTokenInfo,
|
|
564
|
+
dn as useTokenList,
|
|
565
|
+
ln as useTokenPrice,
|
|
566
|
+
un as useTokenPrices,
|
|
567
|
+
Ae as useTrails,
|
|
568
|
+
he as useTrailsClient,
|
|
569
|
+
Ie as useTrailsModal,
|
|
570
|
+
Qe as useTrailsSendTransaction
|
|
993
571
|
};
|