0xtrails 0.4.2 → 0.5.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/dist/{ccip-Dl3umoGg.js → ccip-DhEkQ6QC.js} +27 -27
- package/dist/cctpqueue.d.ts.map +1 -1
- package/dist/chains.d.ts +3 -1
- package/dist/chains.d.ts.map +1 -1
- package/dist/config.d.ts +17 -52
- package/dist/config.d.ts.map +1 -1
- package/dist/constants.d.ts +0 -6
- package/dist/constants.d.ts.map +1 -1
- package/dist/{index-sMS_ge1R.js → index-MhD2DA7_.js} +23613 -23893
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +319 -944
- package/dist/indexerClient.d.ts +9 -6
- package/dist/indexerClient.d.ts.map +1 -1
- package/dist/intents.d.ts +0 -1
- package/dist/intents.d.ts.map +1 -1
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/sequenceWallet.d.ts +1 -1
- package/dist/sequenceWallet.d.ts.map +1 -1
- package/dist/trailsClient.d.ts +3 -3
- package/dist/trailsClient.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/standardDeposit.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/crossChain.d.ts +3 -1
- package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -1
- package/dist/transactionIntent/types.d.ts +1 -0
- package/dist/transactionIntent/types.d.ts.map +1 -1
- package/dist/transactions.d.ts +8 -2
- package/dist/transactions.d.ts.map +1 -1
- package/dist/wallets.d.ts.map +1 -1
- package/dist/widget/components/AccountIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/components/ConfigDisplay.d.ts.map +1 -1
- package/dist/widget/components/FeeOptions.d.ts.map +1 -1
- package/dist/widget/components/SlippageToleranceSettings.d.ts +1 -0
- package/dist/widget/components/SlippageToleranceSettings.d.ts.map +1 -1
- package/dist/widget/components/WalletConnect.d.ts.map +1 -1
- package/dist/widget/hooks/useIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/hooks/useQuote.d.ts +2 -4
- package/dist/widget/hooks/useQuote.d.ts.map +1 -1
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
- package/dist/widget/index.d.ts +1 -0
- package/dist/widget/index.d.ts.map +1 -1
- package/dist/widget/index.js +4 -2
- package/dist/widget/providers/TrailsProvider.d.ts +18 -0
- package/dist/widget/providers/TrailsProvider.d.ts.map +1 -0
- package/dist/widget/widget.d.ts +3 -3
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/analytics.ts +2 -2
- package/src/cctpqueue.ts +6 -3
- package/src/chains.ts +62 -29
- package/src/config.ts +36 -210
- package/src/constants.ts +0 -9
- package/src/index.ts +12 -35
- package/src/indexerClient.ts +39 -48
- package/src/intents.ts +0 -21
- package/src/prepareSend.ts +16 -2
- package/src/sequenceWallet.ts +1 -2
- package/src/trailsClient.ts +17 -12
- package/src/transactionIntent/deposits/gaslessDeposit.ts +88 -43
- package/src/transactionIntent/deposits/standardDeposit.ts +91 -53
- package/src/transactionIntent/handlers/crossChain.ts +88 -0
- package/src/transactionIntent/handlers/sameChainSameToken.ts +22 -0
- package/src/transactionIntent/types.ts +1 -0
- package/src/transactions.ts +122 -24
- package/src/wallets.ts +5 -6
- package/src/widget/components/AccountIntentTransactionHistory.tsx +5 -0
- package/src/widget/components/ConfigDisplay.tsx +19 -59
- package/src/widget/components/FeeOptions.tsx +1 -1
- package/src/widget/components/SlippageToleranceSettings.tsx +63 -14
- package/src/widget/components/WalletConnect.tsx +37 -99
- package/src/widget/hooks/useIntentTransactionHistory.ts +9 -1
- package/src/widget/hooks/useQuote.ts +11 -17
- package/src/widget/hooks/useSendForm.ts +4 -0
- package/src/widget/index.tsx +8 -0
- package/src/widget/providers/TrailsProvider.tsx +95 -0
- package/src/widget/widget.tsx +49 -98
- package/dist/trails.d.ts +0 -110
- package/dist/trails.d.ts.map +0 -1
- package/src/trails.ts +0 -1303
package/dist/index.js
CHANGED
|
@@ -1,358 +1,361 @@
|
|
|
1
|
-
import { l as
|
|
2
|
-
import {
|
|
3
|
-
import { useQuery as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { l as r, u as h, t as se, a as oe, b as re, I as ae, g as T, c as ie, d as ce, e as le, f as ue, h as de, T as ge, p as me, i as q, j as pe, k as S } from "./index-MhD2DA7_.js";
|
|
2
|
+
import { m as Re, P as Le, _ as Oe, X as Me, a0 as qe, U as Ne, s as He, v as Be, w as Pe, $ as Fe, E as Qe, B as _e, r as Je, W as $e, R as Ge, V as Ke, Q as We, F as je, G as ze, A as Ve, n as Xe, Y as Ye, S as Ze, o as et, M as tt, Z as nt, O as st, z as ot, x as rt, y as at, H as it, C as ct, J as lt, K as ut, D as dt, q as gt, L as mt, N as pt } from "./index-MhD2DA7_.js";
|
|
3
|
+
import { useQuery as B, useMutation as P } from "@tanstack/react-query";
|
|
4
|
+
import { useIndexerGatewayClient as fe } from "@0xsequence/hooks";
|
|
5
|
+
import { useIndexerGatewayClient as Et } from "@0xsequence/hooks";
|
|
6
|
+
import { useRef as Ee } from "react";
|
|
7
|
+
import { zeroAddress as N } from "viem";
|
|
8
|
+
const H = 150, Ue = (i, e) => {
|
|
9
|
+
const t = B({
|
|
10
|
+
queryKey: ["waitIntentReceipt", i],
|
|
10
11
|
queryFn: async () => {
|
|
11
|
-
if (!
|
|
12
|
+
if (!i)
|
|
12
13
|
throw new Error("Intent ID is required for monitoring");
|
|
13
|
-
|
|
14
|
-
`[trails-sdk] 🔍 Monitoring intent receipt for ${
|
|
14
|
+
r.console.log(
|
|
15
|
+
`[trails-sdk] 🔍 Monitoring intent receipt for ${i}`
|
|
15
16
|
);
|
|
16
|
-
const
|
|
17
|
-
intentId:
|
|
17
|
+
const n = await e.waitIntentReceipt({
|
|
18
|
+
intentId: i
|
|
18
19
|
});
|
|
19
|
-
return
|
|
20
|
-
`[trails-sdk] 📊 Intent ${
|
|
21
|
-
),
|
|
20
|
+
return r.console.log(
|
|
21
|
+
`[trails-sdk] 📊 Intent ${i} status: ${n.intentReceipt.status}, done: ${n.done}`
|
|
22
|
+
), n;
|
|
22
23
|
},
|
|
23
|
-
enabled: !!
|
|
24
|
+
enabled: !!i,
|
|
24
25
|
refetchIntervalInBackground: !0,
|
|
25
|
-
refetchInterval: (
|
|
26
|
-
const
|
|
27
|
-
return
|
|
28
|
-
`[trails-sdk] ✅ Intent monitoring complete for ${
|
|
29
|
-
), !1) :
|
|
26
|
+
refetchInterval: (n) => {
|
|
27
|
+
const s = n.state.data;
|
|
28
|
+
return s && s.done ? (r.console.log(
|
|
29
|
+
`[trails-sdk] ✅ Intent monitoring complete for ${i}`
|
|
30
|
+
), !1) : H;
|
|
30
31
|
},
|
|
31
|
-
retry: (
|
|
32
|
-
`[trails-sdk] ❌ Giving up on intent ${
|
|
33
|
-
|
|
32
|
+
retry: (n, s) => n >= 30 ? (r.console.error(
|
|
33
|
+
`[trails-sdk] ❌ Giving up on intent ${i} after 30 failed API attempts:`,
|
|
34
|
+
s
|
|
34
35
|
), !1) : !0
|
|
35
36
|
});
|
|
36
37
|
return {
|
|
37
|
-
intentReceipt:
|
|
38
|
-
done:
|
|
39
|
-
isLoading:
|
|
40
|
-
isError:
|
|
41
|
-
error:
|
|
38
|
+
intentReceipt: t.data?.intentReceipt ?? null,
|
|
39
|
+
done: t.data?.done ?? !1,
|
|
40
|
+
isLoading: t.isLoading,
|
|
41
|
+
isError: t.isError,
|
|
42
|
+
error: t.error
|
|
42
43
|
};
|
|
43
44
|
};
|
|
44
|
-
function
|
|
45
|
-
const
|
|
46
|
-
return
|
|
47
|
-
mutationFn: async (
|
|
48
|
-
|
|
49
|
-
intentId:
|
|
50
|
-
originIntentAddress:
|
|
45
|
+
function Ce() {
|
|
46
|
+
const i = h();
|
|
47
|
+
return P({
|
|
48
|
+
mutationFn: async (e) => {
|
|
49
|
+
r.console.log("[trails-sdk] useCommitIntent: Starting commit", {
|
|
50
|
+
intentId: e.intentId,
|
|
51
|
+
originIntentAddress: e.originIntentAddress
|
|
51
52
|
});
|
|
52
|
-
const
|
|
53
|
+
const t = e.calls[0]?.chainId, n = e.calls[1]?.chainId;
|
|
53
54
|
try {
|
|
54
|
-
|
|
55
|
-
intentAddress:
|
|
56
|
-
userAddress:
|
|
57
|
-
originChainId:
|
|
58
|
-
destinationChainId:
|
|
55
|
+
se({
|
|
56
|
+
intentAddress: e.originIntentAddress,
|
|
57
|
+
userAddress: e.ownerAddress,
|
|
58
|
+
originChainId: t ? Number(t) : void 0,
|
|
59
|
+
destinationChainId: n ? Number(n) : void 0
|
|
59
60
|
});
|
|
60
|
-
const
|
|
61
|
-
return
|
|
62
|
-
intentId:
|
|
63
|
-
response:
|
|
64
|
-
}),
|
|
65
|
-
intentAddress:
|
|
66
|
-
userAddress:
|
|
67
|
-
originChainId:
|
|
68
|
-
destinationChainId:
|
|
69
|
-
}),
|
|
70
|
-
} catch (
|
|
71
|
-
throw
|
|
72
|
-
error:
|
|
73
|
-
userAddress:
|
|
74
|
-
intentAddress:
|
|
75
|
-
originChainId:
|
|
76
|
-
destinationChainId:
|
|
77
|
-
}),
|
|
61
|
+
const s = await i.commitIntent({ intent: e });
|
|
62
|
+
return r.console.log("[trails-sdk] useCommitIntent: Commit successful", {
|
|
63
|
+
intentId: e.intentId,
|
|
64
|
+
response: s
|
|
65
|
+
}), oe({
|
|
66
|
+
intentAddress: e.originIntentAddress,
|
|
67
|
+
userAddress: e.ownerAddress,
|
|
68
|
+
originChainId: t ? Number(t) : void 0,
|
|
69
|
+
destinationChainId: n ? Number(n) : void 0
|
|
70
|
+
}), s;
|
|
71
|
+
} catch (s) {
|
|
72
|
+
throw re({
|
|
73
|
+
error: T(s),
|
|
74
|
+
userAddress: e.ownerAddress,
|
|
75
|
+
intentAddress: e.originIntentAddress,
|
|
76
|
+
originChainId: t ? Number(t) : void 0,
|
|
77
|
+
destinationChainId: n ? Number(n) : void 0
|
|
78
|
+
}), s;
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
});
|
|
81
82
|
}
|
|
82
|
-
function
|
|
83
|
-
const
|
|
84
|
-
return
|
|
83
|
+
function ke() {
|
|
84
|
+
const i = h();
|
|
85
|
+
return P({
|
|
85
86
|
mutationFn: async ({
|
|
86
|
-
intentId:
|
|
87
|
-
depositTransactionHash:
|
|
88
|
-
depositSignature:
|
|
87
|
+
intentId: e,
|
|
88
|
+
depositTransactionHash: t,
|
|
89
|
+
depositSignature: n
|
|
89
90
|
}) => {
|
|
90
|
-
if (
|
|
91
|
-
intentId:
|
|
92
|
-
depositTransactionHash:
|
|
93
|
-
hasDepositSignature: !!
|
|
94
|
-
}), !
|
|
91
|
+
if (r.console.log("[trails-sdk] useExecuteIntent: Starting execution", {
|
|
92
|
+
intentId: e,
|
|
93
|
+
depositTransactionHash: t,
|
|
94
|
+
hasDepositSignature: !!n
|
|
95
|
+
}), !t && !n)
|
|
95
96
|
throw new Error(
|
|
96
97
|
"[trails-sdk] Either depositTransactionHash or depositSignature must be provided"
|
|
97
98
|
);
|
|
98
|
-
let
|
|
99
|
+
let s;
|
|
99
100
|
try {
|
|
100
|
-
|
|
101
|
-
intentId:
|
|
102
|
-
depositTransactionHash:
|
|
103
|
-
depositSignature:
|
|
101
|
+
s = await i.executeIntent({
|
|
102
|
+
intentId: e,
|
|
103
|
+
depositTransactionHash: t,
|
|
104
|
+
depositSignature: n
|
|
104
105
|
});
|
|
105
|
-
} catch (
|
|
106
|
-
if (
|
|
106
|
+
} catch (c) {
|
|
107
|
+
if (r.console.error(
|
|
107
108
|
"[trails-sdk] useExecuteIntent: Error executing intent",
|
|
108
109
|
{
|
|
109
|
-
intentId:
|
|
110
|
-
error:
|
|
111
|
-
errorJSON: JSON.stringify(
|
|
110
|
+
intentId: e,
|
|
111
|
+
error: c,
|
|
112
|
+
errorJSON: JSON.stringify(c, null, 2)
|
|
112
113
|
}
|
|
113
|
-
),
|
|
114
|
-
return
|
|
114
|
+
), c instanceof Error && c?.message?.includes("status=SUCCEEDED") || c instanceof Error && c?.cause?.message?.includes("status=SUCCEEDED") || c instanceof Error && JSON.stringify(c).includes("status=SUCCEEDED") || c instanceof ae && c?.cause?.toString().includes("status=SUCCEEDED") || JSON.stringify(c).includes("status=SUCCEEDED"))
|
|
115
|
+
return r.console.error(
|
|
115
116
|
"[trails-sdk] useExecuteIntent: Intent already succeeded, treating as success",
|
|
116
|
-
{ intentId:
|
|
117
|
+
{ intentId: e }
|
|
117
118
|
), {
|
|
118
|
-
intentId:
|
|
119
|
+
intentId: e,
|
|
119
120
|
intentStatus: "SUCCEEDED"
|
|
120
121
|
};
|
|
121
|
-
throw
|
|
122
|
+
throw r.console.error(
|
|
122
123
|
"[trails-sdk] useExecuteIntent did not throw IntentStatusError and is not a SUCCEEDED intent",
|
|
123
124
|
{
|
|
124
|
-
intentId:
|
|
125
|
-
error:
|
|
126
|
-
errorJSON: JSON.stringify(
|
|
125
|
+
intentId: e,
|
|
126
|
+
error: c,
|
|
127
|
+
errorJSON: JSON.stringify(c, null, 2)
|
|
127
128
|
}
|
|
128
|
-
),
|
|
129
|
+
), c;
|
|
129
130
|
}
|
|
130
|
-
return
|
|
131
|
+
return r.console.log(
|
|
131
132
|
"[trails-sdk] useExecuteIntent: Execution successful",
|
|
132
133
|
{
|
|
133
|
-
intentId:
|
|
134
|
-
response:
|
|
134
|
+
intentId: e,
|
|
135
|
+
response: s
|
|
135
136
|
}
|
|
136
|
-
),
|
|
137
|
+
), s;
|
|
137
138
|
}
|
|
138
139
|
});
|
|
139
140
|
}
|
|
140
|
-
function
|
|
141
|
-
walletClient:
|
|
142
|
-
fromTokenAddress:
|
|
143
|
-
fromChainId:
|
|
144
|
-
toTokenAddress:
|
|
145
|
-
toChainId:
|
|
146
|
-
swapAmount:
|
|
147
|
-
tradeType:
|
|
148
|
-
toRecipient:
|
|
149
|
-
toCalldata:
|
|
150
|
-
slippageTolerance:
|
|
151
|
-
onStatusUpdate:
|
|
152
|
-
checkoutOnHandlers:
|
|
153
|
-
quoteProvider:
|
|
154
|
-
paymasterUrl:
|
|
155
|
-
selectedFeeToken:
|
|
156
|
-
nodeGatewayEnv:
|
|
157
|
-
abortSignal:
|
|
158
|
-
apiKey:
|
|
141
|
+
function ve({
|
|
142
|
+
walletClient: i,
|
|
143
|
+
fromTokenAddress: e,
|
|
144
|
+
fromChainId: t,
|
|
145
|
+
toTokenAddress: n,
|
|
146
|
+
toChainId: s,
|
|
147
|
+
swapAmount: c,
|
|
148
|
+
tradeType: I,
|
|
149
|
+
toRecipient: m,
|
|
150
|
+
toCalldata: A,
|
|
151
|
+
slippageTolerance: b,
|
|
152
|
+
onStatusUpdate: F,
|
|
153
|
+
checkoutOnHandlers: Q,
|
|
154
|
+
quoteProvider: w,
|
|
155
|
+
paymasterUrl: _,
|
|
156
|
+
selectedFeeToken: U,
|
|
157
|
+
nodeGatewayEnv: v,
|
|
158
|
+
abortSignal: D,
|
|
159
|
+
apiKey: J
|
|
159
160
|
} = {}) {
|
|
160
|
-
|
|
161
|
-
const
|
|
162
|
-
const
|
|
163
|
-
return
|
|
164
|
-
|
|
165
|
-
}),
|
|
166
|
-
|
|
167
|
-
}),
|
|
168
|
-
})() :
|
|
169
|
-
|
|
170
|
-
|
|
161
|
+
v && (globalThis.__testNodeGatewayEnv = v);
|
|
162
|
+
const d = Ee(new AbortController()), $ = D ? (() => {
|
|
163
|
+
const u = new AbortController();
|
|
164
|
+
return D.addEventListener("abort", () => {
|
|
165
|
+
u.abort(), d.current?.abort();
|
|
166
|
+
}), d.current?.signal.addEventListener("abort", () => {
|
|
167
|
+
u.abort();
|
|
168
|
+
}), u.signal;
|
|
169
|
+
})() : d.current.signal, { trailsApiKey: G, trailsApiUrl: K, sequenceIndexerUrl: W } = ie(), g = h({
|
|
170
|
+
apiKey: G,
|
|
171
|
+
hostname: K
|
|
172
|
+
}), E = fe(), { supportedTokens: p } = ce(), j = Ce(), z = ke(), { data: x, isLoading: V, error: R, refetch: X } = B({
|
|
171
173
|
queryKey: [
|
|
172
174
|
"prepareSend",
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
175
|
+
e,
|
|
176
|
+
t,
|
|
177
|
+
n,
|
|
178
|
+
s,
|
|
179
|
+
c?.toString(),
|
|
180
|
+
m,
|
|
181
|
+
A,
|
|
182
|
+
I,
|
|
183
|
+
b,
|
|
184
|
+
w,
|
|
185
|
+
J
|
|
184
186
|
],
|
|
185
187
|
queryFn: async () => {
|
|
186
188
|
try {
|
|
187
|
-
if (
|
|
189
|
+
if (d.current.signal.aborted && (r.console.log(
|
|
188
190
|
"[trails-sdk] Resetting aborted controller for new query"
|
|
189
|
-
),
|
|
191
|
+
), d.current = new AbortController()), !i || !g || !e || !n || !c || !m || !t || !s || !E)
|
|
190
192
|
return null;
|
|
191
|
-
let
|
|
193
|
+
let u = [];
|
|
192
194
|
try {
|
|
193
|
-
|
|
194
|
-
account:
|
|
195
|
-
indexerGatewayClient:
|
|
196
|
-
trailsClient:
|
|
195
|
+
u = (await le({
|
|
196
|
+
account: i.account.address,
|
|
197
|
+
indexerGatewayClient: E,
|
|
198
|
+
trailsClient: g
|
|
197
199
|
})).balances;
|
|
198
|
-
} catch (
|
|
199
|
-
const
|
|
200
|
-
if (
|
|
201
|
-
|
|
200
|
+
} catch (a) {
|
|
201
|
+
const l = T(a), f = l.includes("Cross-Origin") || l.includes("CORS") || l.includes("Same Origin Policy"), ne = l.includes("fetch failed") || l.includes("network");
|
|
202
|
+
if (f || ne)
|
|
203
|
+
r.console.warn(
|
|
202
204
|
"[trails-sdk] [useQuote] Network or CORS error fetching balances, proceeding with quote using zero balance:",
|
|
203
205
|
{
|
|
204
|
-
error:
|
|
205
|
-
account:
|
|
206
|
+
error: l,
|
|
207
|
+
account: i.account.address
|
|
206
208
|
}
|
|
207
|
-
),
|
|
209
|
+
), u = [];
|
|
208
210
|
else
|
|
209
|
-
throw
|
|
211
|
+
throw a;
|
|
210
212
|
}
|
|
211
|
-
const
|
|
212
|
-
(
|
|
213
|
+
const Y = u.find(
|
|
214
|
+
(a) => a.chainId === t && (a.contractAddress?.toLowerCase() === e.toLowerCase() || !a.contractAddress && e === N)
|
|
213
215
|
)?.balance ?? "0";
|
|
214
|
-
let
|
|
216
|
+
let C = 0;
|
|
215
217
|
try {
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
tokenSymbol:
|
|
219
|
-
tokenAddress:
|
|
220
|
-
chainId:
|
|
221
|
-
}))?.priceUsd ?? 0,
|
|
218
|
+
const l = ue(t)?.nativeCurrency?.symbol ?? "";
|
|
219
|
+
l && (C = (await de(g, {
|
|
220
|
+
tokenSymbol: l,
|
|
221
|
+
tokenAddress: N,
|
|
222
|
+
chainId: t
|
|
223
|
+
}))?.priceUsd ?? 0, r.console.log(
|
|
222
224
|
"[trails-sdk] [useQuote] Origin native token price:",
|
|
223
225
|
{
|
|
224
|
-
chainId:
|
|
225
|
-
symbol:
|
|
226
|
-
priceUsd:
|
|
226
|
+
chainId: t,
|
|
227
|
+
symbol: l,
|
|
228
|
+
priceUsd: C
|
|
227
229
|
}
|
|
228
230
|
));
|
|
229
|
-
} catch (
|
|
230
|
-
|
|
231
|
+
} catch (a) {
|
|
232
|
+
r.console.error(
|
|
231
233
|
"[trails-sdk] [useQuote] Error getting origin native token price:",
|
|
232
|
-
|
|
234
|
+
a
|
|
233
235
|
);
|
|
234
236
|
}
|
|
235
|
-
const
|
|
236
|
-
(
|
|
237
|
-
),
|
|
238
|
-
(
|
|
239
|
-
),
|
|
240
|
-
if (!
|
|
241
|
-
throw
|
|
237
|
+
const k = p?.find(
|
|
238
|
+
(a) => a.contractAddress?.toLowerCase() === e?.toLowerCase() && a.chainId === t
|
|
239
|
+
), y = p?.find(
|
|
240
|
+
(a) => a.contractAddress?.toLowerCase() === n?.toLowerCase() && a.chainId === s
|
|
241
|
+
), L = k?.decimals;
|
|
242
|
+
if (!L)
|
|
243
|
+
throw r.console.error(
|
|
242
244
|
"[trails-sdk] [useQuote] Missing source token decimals:",
|
|
243
245
|
{
|
|
244
|
-
originToken:
|
|
245
|
-
fromTokenAddress:
|
|
246
|
-
fromChainId:
|
|
246
|
+
originToken: k,
|
|
247
|
+
fromTokenAddress: e,
|
|
248
|
+
fromChainId: t
|
|
247
249
|
}
|
|
248
250
|
), new Error("Source token decimals not found");
|
|
249
|
-
const
|
|
250
|
-
if (!
|
|
251
|
-
throw
|
|
251
|
+
const O = y?.decimals;
|
|
252
|
+
if (!O)
|
|
253
|
+
throw r.console.error(
|
|
252
254
|
"[trails-sdk] Missing destination token decimals:",
|
|
253
255
|
{
|
|
254
|
-
destinationToken:
|
|
255
|
-
toTokenAddress:
|
|
256
|
-
toChainId:
|
|
256
|
+
destinationToken: y,
|
|
257
|
+
toTokenAddress: n,
|
|
258
|
+
toChainId: s
|
|
257
259
|
}
|
|
258
260
|
), new Error("Destination token decimals not found");
|
|
259
|
-
const
|
|
260
|
-
account:
|
|
261
|
-
originTokenAddress:
|
|
262
|
-
originChainId:
|
|
263
|
-
originTokenBalance:
|
|
264
|
-
destinationChainId:
|
|
265
|
-
recipient:
|
|
266
|
-
destinationTokenAddress:
|
|
267
|
-
swapAmount:
|
|
268
|
-
tradeType:
|
|
269
|
-
originTokenSymbol:
|
|
270
|
-
destinationTokenSymbol:
|
|
271
|
-
destinationCalldata:
|
|
272
|
-
client:
|
|
273
|
-
trailsClient:
|
|
274
|
-
sourceTokenDecimals:
|
|
275
|
-
destinationTokenDecimals:
|
|
261
|
+
const Z = y?.symbol ?? "", ee = k?.symbol ?? "", M = {
|
|
262
|
+
account: i.account,
|
|
263
|
+
originTokenAddress: e,
|
|
264
|
+
originChainId: t,
|
|
265
|
+
originTokenBalance: Y,
|
|
266
|
+
destinationChainId: s,
|
|
267
|
+
recipient: m,
|
|
268
|
+
destinationTokenAddress: n,
|
|
269
|
+
swapAmount: c.toString(),
|
|
270
|
+
tradeType: I ?? ge.EXACT_OUTPUT,
|
|
271
|
+
originTokenSymbol: ee,
|
|
272
|
+
destinationTokenSymbol: Z,
|
|
273
|
+
destinationCalldata: A,
|
|
274
|
+
client: i,
|
|
275
|
+
trailsClient: g,
|
|
276
|
+
sourceTokenDecimals: L,
|
|
277
|
+
destinationTokenDecimals: O,
|
|
276
278
|
fee: "0",
|
|
277
279
|
dryMode: !1,
|
|
278
|
-
onTransactionStateChange:
|
|
280
|
+
onTransactionStateChange: F ?? (() => {
|
|
279
281
|
}),
|
|
280
|
-
slippageTolerance:
|
|
281
|
-
quoteProvider:
|
|
282
|
-
paymasterUrl:
|
|
283
|
-
selectedFeeToken:
|
|
284
|
-
abortSignal:
|
|
285
|
-
originNativeTokenPriceUsd:
|
|
286
|
-
commitIntentFn:
|
|
287
|
-
executeIntentFn:
|
|
288
|
-
checkoutOnHandlers:
|
|
282
|
+
slippageTolerance: b?.toString(),
|
|
283
|
+
quoteProvider: w,
|
|
284
|
+
paymasterUrl: _,
|
|
285
|
+
selectedFeeToken: U ?? void 0,
|
|
286
|
+
abortSignal: $,
|
|
287
|
+
originNativeTokenPriceUsd: C,
|
|
288
|
+
commitIntentFn: j.mutateAsync,
|
|
289
|
+
executeIntentFn: z.mutateAsync,
|
|
290
|
+
checkoutOnHandlers: Q,
|
|
291
|
+
sequenceIndexerUrl: W
|
|
289
292
|
};
|
|
290
|
-
|
|
291
|
-
const { quote:
|
|
293
|
+
r.console.log("[trails-sdk] options", M);
|
|
294
|
+
const { quote: o, send: te } = await me(M);
|
|
292
295
|
return {
|
|
293
296
|
quote: {
|
|
294
|
-
fromAmount:
|
|
295
|
-
toAmount:
|
|
296
|
-
fromAmountMin:
|
|
297
|
-
toAmountMin:
|
|
298
|
-
originToken:
|
|
299
|
-
destinationToken:
|
|
300
|
-
originChain:
|
|
301
|
-
destinationChain:
|
|
302
|
-
fees:
|
|
303
|
-
priceImpact:
|
|
304
|
-
completionEstimateSeconds:
|
|
305
|
-
slippageTolerance:
|
|
306
|
-
transactionStates:
|
|
307
|
-
originTokenRate:
|
|
308
|
-
destinationTokenRate:
|
|
309
|
-
quoteProvider:
|
|
310
|
-
fromAmountUsdDisplay:
|
|
311
|
-
toAmountUsdDisplay:
|
|
312
|
-
gasCostUsd:
|
|
313
|
-
gasCostUsdDisplay:
|
|
314
|
-
gasCost:
|
|
315
|
-
gasCostFormatted:
|
|
297
|
+
fromAmount: o.originAmount,
|
|
298
|
+
toAmount: o.destinationAmount,
|
|
299
|
+
fromAmountMin: o.originAmountMin,
|
|
300
|
+
toAmountMin: o.destinationAmountMin,
|
|
301
|
+
originToken: o.originToken,
|
|
302
|
+
destinationToken: o.destinationToken,
|
|
303
|
+
originChain: o.originChain,
|
|
304
|
+
destinationChain: o.destinationChain,
|
|
305
|
+
fees: o.fees,
|
|
306
|
+
priceImpact: o.priceImpact,
|
|
307
|
+
completionEstimateSeconds: o.completionEstimateSeconds,
|
|
308
|
+
slippageTolerance: o.slippageTolerance,
|
|
309
|
+
transactionStates: o.transactionStates,
|
|
310
|
+
originTokenRate: o.originTokenRate,
|
|
311
|
+
destinationTokenRate: o.destinationTokenRate,
|
|
312
|
+
quoteProvider: o.quoteProvider,
|
|
313
|
+
fromAmountUsdDisplay: o.originAmountUsdDisplay ?? void 0,
|
|
314
|
+
toAmountUsdDisplay: o.destinationAmountUsdDisplay ?? void 0,
|
|
315
|
+
gasCostUsd: o.gasCostUsd ?? void 0,
|
|
316
|
+
gasCostUsdDisplay: o.gasCostUsdDisplay ?? void 0,
|
|
317
|
+
gasCost: o.gasCost ?? void 0,
|
|
318
|
+
gasCostFormatted: o.gasCostFormatted ?? void 0
|
|
316
319
|
},
|
|
317
320
|
swap: async () => {
|
|
318
321
|
const {
|
|
319
|
-
depositUserTxnReceipt:
|
|
320
|
-
destinationMetaTxnReceipt:
|
|
321
|
-
totalCompletionSeconds:
|
|
322
|
-
} = await
|
|
323
|
-
selectedFeeToken:
|
|
322
|
+
depositUserTxnReceipt: a,
|
|
323
|
+
destinationMetaTxnReceipt: l,
|
|
324
|
+
totalCompletionSeconds: f
|
|
325
|
+
} = await te({
|
|
326
|
+
selectedFeeToken: U ?? void 0
|
|
324
327
|
});
|
|
325
328
|
return {
|
|
326
329
|
originTransaction: {
|
|
327
|
-
transactionHash:
|
|
328
|
-
explorerUrl:
|
|
329
|
-
txHash:
|
|
330
|
-
chainId:
|
|
330
|
+
transactionHash: a?.transactionHash,
|
|
331
|
+
explorerUrl: q({
|
|
332
|
+
txHash: a?.transactionHash,
|
|
333
|
+
chainId: t
|
|
331
334
|
}),
|
|
332
|
-
receipt:
|
|
335
|
+
receipt: a
|
|
333
336
|
},
|
|
334
337
|
destinationTransaction: {
|
|
335
|
-
transactionHash:
|
|
336
|
-
explorerUrl:
|
|
337
|
-
txHash:
|
|
338
|
-
chainId:
|
|
338
|
+
transactionHash: l?.txnHash,
|
|
339
|
+
explorerUrl: q({
|
|
340
|
+
txHash: l?.txnHash,
|
|
341
|
+
chainId: s
|
|
339
342
|
}),
|
|
340
|
-
receipt:
|
|
343
|
+
receipt: l
|
|
341
344
|
},
|
|
342
|
-
totalCompletionSeconds:
|
|
345
|
+
totalCompletionSeconds: f
|
|
343
346
|
};
|
|
344
347
|
}
|
|
345
348
|
};
|
|
346
|
-
} catch (
|
|
347
|
-
throw
|
|
349
|
+
} catch (u) {
|
|
350
|
+
throw r.console.error(
|
|
348
351
|
"[trails-sdk] [useQuote] Error getting quote:",
|
|
349
|
-
|
|
350
|
-
),
|
|
352
|
+
u
|
|
353
|
+
), T(u);
|
|
351
354
|
}
|
|
352
355
|
},
|
|
353
356
|
// Prevent unnecessary refetching
|
|
354
|
-
enabled: !!(
|
|
355
|
-
|
|
357
|
+
enabled: !!(i && g && e && n && c && m && t && s && E && // !isLoadingTokens &&
|
|
358
|
+
p && p.length > 0),
|
|
356
359
|
staleTime: 30 * 1e3,
|
|
357
360
|
// Consider data fresh for 30 seconds
|
|
358
361
|
refetchOnWindowFocus: !1,
|
|
@@ -367,700 +370,72 @@ function Kn({
|
|
|
367
370
|
// Refetch when network reconnects
|
|
368
371
|
});
|
|
369
372
|
return {
|
|
370
|
-
quote:
|
|
371
|
-
swap:
|
|
372
|
-
isLoadingQuote:
|
|
373
|
-
quoteError:
|
|
374
|
-
quoteErrorPrettified:
|
|
375
|
-
refetchQuote: () =>
|
|
373
|
+
quote: x?.quote || null,
|
|
374
|
+
swap: x?.swap || null,
|
|
375
|
+
isLoadingQuote: V,
|
|
376
|
+
quoteError: R,
|
|
377
|
+
quoteErrorPrettified: pe(R),
|
|
378
|
+
refetchQuote: () => X(),
|
|
376
379
|
abort: () => {
|
|
377
|
-
|
|
380
|
+
r.console.log("[trails-sdk] useQuote abort() called"), r.console.log(
|
|
378
381
|
"[trails-sdk] Active operations before abort:",
|
|
379
|
-
|
|
380
|
-
),
|
|
382
|
+
S.getAll()
|
|
383
|
+
), d.current.abort(), S.abortAll(), r.console.log(
|
|
381
384
|
"[trails-sdk] Abort completed, active operations:",
|
|
382
|
-
|
|
383
|
-
);
|
|
384
|
-
}
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
function Xn(g) {
|
|
388
|
-
const {
|
|
389
|
-
account: i,
|
|
390
|
-
disableAutoExecute: a = !1,
|
|
391
|
-
sequenceProjectAccessKey: l
|
|
392
|
-
} = g, o = Ie({
|
|
393
|
-
apiKey: l
|
|
394
|
-
}), [d, j] = u(!a), [F, X] = u(!1), [Q, he] = u(
|
|
395
|
-
{}
|
|
396
|
-
), [W, U] = u(null), [V, R] = u(null), [w, q] = u(null), [v, S] = u(null), [se, pe] = u(null), [p, D] = u(), [m, k] = u(null), [
|
|
397
|
-
ve,
|
|
398
|
-
_
|
|
399
|
-
] = u(null), [O, J] = u(
|
|
400
|
-
null
|
|
401
|
-
), [le, z] = u(null), [s, Y] = u(null), [Ce, ie] = u({}), [L, N] = u(!1), [oe, B] = u(!1), {
|
|
402
|
-
switchChain: Te,
|
|
403
|
-
isPending: Se,
|
|
404
|
-
error: G
|
|
405
|
-
} = Bn(), r = Gn(), [Ae, Ee] = u(!1), [y, c] = u(null), [h, $] = u(null), [we, De] = u({}), [Je, de] = u(null), {
|
|
406
|
-
data: ue,
|
|
407
|
-
isError: ke,
|
|
408
|
-
error: ye
|
|
409
|
-
} = $n(
|
|
410
|
-
s?.to && s?.chainId && !s.error ? {
|
|
411
|
-
to: s.to || void 0,
|
|
412
|
-
data: s.data || void 0,
|
|
413
|
-
value: s.value || void 0,
|
|
414
|
-
chainId: s.chainId || void 0
|
|
415
|
-
} : void 0
|
|
416
|
-
), ze = Ve(), A = me({
|
|
417
|
-
mutationFn: async (e) => {
|
|
418
|
-
t.console.log(
|
|
419
|
-
"[useTrails] commitIntentMutation started with intent:",
|
|
420
|
-
e
|
|
385
|
+
S.getAll()
|
|
421
386
|
);
|
|
422
|
-
try {
|
|
423
|
-
const n = C.variables?.originChainId, f = C.variables?.destinationChainId;
|
|
424
|
-
if (!n || !f)
|
|
425
|
-
throw t.console.error(
|
|
426
|
-
"[useTrails] Could not determine origin/destination chain IDs for verification."
|
|
427
|
-
), new Error(
|
|
428
|
-
"Could not determine origin/destination chain IDs for verification."
|
|
429
|
-
);
|
|
430
|
-
t.console.log("[useTrails] Calculating intent address..."), t.console.log("[useTrails] Main signer:", e.ownerAddress), t.console.log("[useTrails] Calls:", e.calls);
|
|
431
|
-
const { originIntentAddress: E, destinationIntentAddress: b } = Le(
|
|
432
|
-
e.ownerAddress,
|
|
433
|
-
e.calls
|
|
434
|
-
), {
|
|
435
|
-
originAddress: ae,
|
|
436
|
-
destinationAddress: K
|
|
437
|
-
} = Dn(
|
|
438
|
-
e.preconditions,
|
|
439
|
-
n,
|
|
440
|
-
f
|
|
441
|
-
);
|
|
442
|
-
t.console.log("[useTrails] Verification addresses:", {
|
|
443
|
-
calculatedOrigin: E.toString(),
|
|
444
|
-
calculatedDestination: b.toString(),
|
|
445
|
-
preconditionOrigin: ae,
|
|
446
|
-
preconditionDestination: K
|
|
447
|
-
});
|
|
448
|
-
const x = !!ae && ce(
|
|
449
|
-
te(ae),
|
|
450
|
-
E
|
|
451
|
-
);
|
|
452
|
-
t.console.log("[useTrails] Origin verified:", x);
|
|
453
|
-
const T = K && ce(
|
|
454
|
-
te(K),
|
|
455
|
-
b
|
|
456
|
-
) || !K && n === f && ce(b, fe);
|
|
457
|
-
t.console.log(
|
|
458
|
-
"[useTrails] Destination verified:",
|
|
459
|
-
T
|
|
460
|
-
);
|
|
461
|
-
const Me = x && T;
|
|
462
|
-
if (de({
|
|
463
|
-
success: Me,
|
|
464
|
-
receivedOriginAddress: ae,
|
|
465
|
-
receivedDestinationAddress: K,
|
|
466
|
-
calculatedOriginAddress: E.toString(),
|
|
467
|
-
calculatedDestinationAddress: b.toString()
|
|
468
|
-
}), !Me)
|
|
469
|
-
throw t.console.error("[useTrails] Address verification failed.", {
|
|
470
|
-
isOriginVerified: x,
|
|
471
|
-
isDestinationVerified: T
|
|
472
|
-
}), new Error(
|
|
473
|
-
`Address verification failed. Origin verified: ${x}, Destination verified: ${T}`
|
|
474
|
-
);
|
|
475
|
-
t.console.log("[useTrails] Committing intent to API...");
|
|
476
|
-
const He = await ze.mutateAsync(e);
|
|
477
|
-
return t.console.log("[useTrails] API Commit Response:", He), {
|
|
478
|
-
originIntentAddress: E.toString(),
|
|
479
|
-
destinationIntentAddress: b.toString(),
|
|
480
|
-
response: He
|
|
481
|
-
};
|
|
482
|
-
} catch (n) {
|
|
483
|
-
throw console.error("[useTrails] Error during commit intent mutation:", n), n;
|
|
484
|
-
}
|
|
485
|
-
},
|
|
486
|
-
onSuccess: (e) => {
|
|
487
|
-
t.console.log(
|
|
488
|
-
"[useTrails] Intent config committed successfully. Data:",
|
|
489
|
-
e
|
|
490
|
-
), t.console.log(
|
|
491
|
-
"[useTrails] Setting committedOriginIntentAddress:",
|
|
492
|
-
e.originIntentAddress
|
|
493
|
-
), k(e.originIntentAddress), _(e.destinationIntentAddress);
|
|
494
|
-
},
|
|
495
|
-
onError: (e) => {
|
|
496
|
-
t.console.error("[useTrails] Failed to commit intent config:", e), k(null), _(null);
|
|
497
|
-
}
|
|
498
|
-
}), Z = _e(), {
|
|
499
|
-
data: Ke,
|
|
500
|
-
isLoading: Xe,
|
|
501
|
-
error: Ye
|
|
502
|
-
} = qe({
|
|
503
|
-
queryKey: ["getIntent", m],
|
|
504
|
-
queryFn: async () => {
|
|
505
|
-
if (!o || !m)
|
|
506
|
-
throw new Error("API client or committed intent address not available");
|
|
507
|
-
return t.console.log(
|
|
508
|
-
"Fetching intent config for address:",
|
|
509
|
-
m
|
|
510
|
-
), (await o.getIntent({
|
|
511
|
-
intentId: m
|
|
512
|
-
})).intent;
|
|
513
|
-
},
|
|
514
|
-
enabled: !!m && !!o && A.isSuccess,
|
|
515
|
-
staleTime: 1e3 * 60 * 5,
|
|
516
|
-
// 5 minutes
|
|
517
|
-
retry: 1
|
|
518
|
-
});
|
|
519
|
-
async function Ze(e) {
|
|
520
|
-
const { intent: n } = await Ne(o, e);
|
|
521
|
-
return n;
|
|
522
|
-
}
|
|
523
|
-
const C = me({
|
|
524
|
-
mutationFn: async (e) => {
|
|
525
|
-
if (e.originChainId === e.destinationChainId && ce(
|
|
526
|
-
te(e.originTokenAddress),
|
|
527
|
-
te(e.destinationTokenAddress)
|
|
528
|
-
))
|
|
529
|
-
throw new Error(
|
|
530
|
-
"The same token cannot be used as both the source and destination token."
|
|
531
|
-
);
|
|
532
|
-
if (!i.address)
|
|
533
|
-
throw new Error("Missing selected token or account address");
|
|
534
|
-
k(null), _(null), de(null), S(null), U(null), R(null), q(null), J(null), z(null);
|
|
535
|
-
const { intent: n } = await Ne(o, e);
|
|
536
|
-
return U(n.metaTxns), R(n.calls), q(n.preconditions), S(n.fees), J(n.originIntentAddress), z(n.destinationIntentAddress), pe(n), k(null), _(null), de(null), n;
|
|
537
|
-
},
|
|
538
|
-
onSuccess: (e) => {
|
|
539
|
-
t.console.log("Intent Config Success:", e), S(e.fees || null), J(e.originIntentAddress), z(e.destinationIntentAddress), e?.calls && e.calls.length > 0 && e.preconditions && e.preconditions.length > 0 && e.metaTxns && e.metaTxns.length > 0 ? (R(e.calls), q(e.preconditions), U(e.metaTxns)) : (t.console.warn("API returned success but no operations found."), R(null), q(null), U(null));
|
|
540
|
-
},
|
|
541
|
-
onError: (e) => {
|
|
542
|
-
console.error("Intent Config Error:", e), R(null), q(null), U(null), S(null), J(null), z(null);
|
|
543
|
-
}
|
|
544
|
-
}), en = $e(() => {
|
|
545
|
-
t.console.log("[Trails] Clearing intent state"), R(null), q(null), U(null), S(null), k(null), _(null), de(null), J(null), z(null), ie({}), X(!1), De({});
|
|
546
|
-
}, []), M = $e(
|
|
547
|
-
(e, n, f, E, b) => {
|
|
548
|
-
c({
|
|
549
|
-
txnHash: e,
|
|
550
|
-
status: n === "success" ? "Success" : n === "reverted" ? "Failed" : n === "sending" ? "Sending..." : "Pending",
|
|
551
|
-
revertReason: n === "reverted" ? b || "Transaction reverted" : void 0,
|
|
552
|
-
gasUsed: f ? Number(f) : void 0,
|
|
553
|
-
effectiveGasPrice: E?.toString()
|
|
554
|
-
});
|
|
555
|
-
},
|
|
556
|
-
[]
|
|
557
|
-
), nn = async () => {
|
|
558
|
-
if (t.console.log("Sending origin transaction..."), t.console.log(
|
|
559
|
-
L,
|
|
560
|
-
s,
|
|
561
|
-
s?.error,
|
|
562
|
-
s?.to,
|
|
563
|
-
s?.data,
|
|
564
|
-
s?.value,
|
|
565
|
-
s?.chainId
|
|
566
|
-
), L || // Prevent duplicate transactions
|
|
567
|
-
!s || s.error || !s.to || s.data === null || s.value === null || s.chainId === null) {
|
|
568
|
-
t.console.error(
|
|
569
|
-
"Origin call parameters not available or invalid:",
|
|
570
|
-
s
|
|
571
|
-
), M(
|
|
572
|
-
void 0,
|
|
573
|
-
"reverted",
|
|
574
|
-
void 0,
|
|
575
|
-
void 0,
|
|
576
|
-
"Origin call parameters not ready"
|
|
577
|
-
);
|
|
578
|
-
return;
|
|
579
|
-
}
|
|
580
|
-
if (i.chainId !== s.chainId) {
|
|
581
|
-
B(!0), M(
|
|
582
|
-
void 0,
|
|
583
|
-
"pending",
|
|
584
|
-
void 0,
|
|
585
|
-
void 0,
|
|
586
|
-
`Switching to chain ${s.chainId}...`
|
|
587
|
-
);
|
|
588
|
-
const e = je({
|
|
589
|
-
chain: Re(s.chainId),
|
|
590
|
-
transport: Qe(await i.connector.getProvider())
|
|
591
|
-
// TODO: Add proper type
|
|
592
|
-
});
|
|
593
|
-
try {
|
|
594
|
-
await Be({
|
|
595
|
-
walletClient: e,
|
|
596
|
-
desiredChainId: s.chainId
|
|
597
|
-
}), B(!1);
|
|
598
|
-
} catch (n) {
|
|
599
|
-
t.console.error("Chain switch failed:", n), n instanceof Error && n.message.includes("User rejected") && j(!1), M(
|
|
600
|
-
void 0,
|
|
601
|
-
"reverted",
|
|
602
|
-
void 0,
|
|
603
|
-
void 0,
|
|
604
|
-
n instanceof Error ? n.message : "Unknown error switching chain"
|
|
605
|
-
), B(!1);
|
|
606
|
-
return;
|
|
607
|
-
}
|
|
608
387
|
}
|
|
609
|
-
if (L)
|
|
610
|
-
t.console.warn(
|
|
611
|
-
"Transaction already in progress. Skipping duplicate request."
|
|
612
|
-
);
|
|
613
|
-
else {
|
|
614
|
-
if (N(!0), D(void 0), M(void 0, "sending"), !ue && !ke) {
|
|
615
|
-
Ee(!0);
|
|
616
|
-
return;
|
|
617
|
-
}
|
|
618
|
-
if (ke) {
|
|
619
|
-
t.console.error("Gas estimation failed:", ye), M(
|
|
620
|
-
void 0,
|
|
621
|
-
"reverted",
|
|
622
|
-
void 0,
|
|
623
|
-
void 0,
|
|
624
|
-
`Gas estimation failed: ${ye?.message}`
|
|
625
|
-
), N(!1);
|
|
626
|
-
return;
|
|
627
|
-
}
|
|
628
|
-
const e = ue ? BigInt(Math.floor(Number(ue) * 1.2)) : void 0;
|
|
629
|
-
r.sendTransaction(
|
|
630
|
-
{
|
|
631
|
-
to: s.to,
|
|
632
|
-
data: s.data,
|
|
633
|
-
value: s.value,
|
|
634
|
-
chainId: s.chainId,
|
|
635
|
-
gas: e
|
|
636
|
-
},
|
|
637
|
-
{
|
|
638
|
-
onSuccess: (n) => {
|
|
639
|
-
t.console.log("Transaction sent, hash:", n), D(n), N(!1);
|
|
640
|
-
},
|
|
641
|
-
onError: (n) => {
|
|
642
|
-
t.console.error("Transaction failed:", n), n instanceof Error && (n.message.includes("User rejected") || n.message.includes("user rejected")) && j(!1), M(
|
|
643
|
-
void 0,
|
|
644
|
-
"reverted",
|
|
645
|
-
void 0,
|
|
646
|
-
void 0,
|
|
647
|
-
n instanceof Error ? n.message : "Unknown error"
|
|
648
|
-
), N(!1);
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
);
|
|
652
|
-
}
|
|
653
|
-
};
|
|
654
|
-
P(() => {
|
|
655
|
-
G && (t.console.error("Chain switch error:", G), M(
|
|
656
|
-
void 0,
|
|
657
|
-
"reverted",
|
|
658
|
-
void 0,
|
|
659
|
-
void 0,
|
|
660
|
-
`Chain switch failed: ${G.message || "Unknown error"}`
|
|
661
|
-
), B(!1));
|
|
662
|
-
}, [G, M]), P(() => {
|
|
663
|
-
Ee(!1);
|
|
664
|
-
}, []), P(() => {
|
|
665
|
-
s?.chainId && i.chainId === s.chainId && (t.console.log("No chain switch required"), B(!1));
|
|
666
|
-
}, [i.chainId, s?.chainId]), P(() => {
|
|
667
|
-
if (s?.chainId && i.chainId !== s.chainId) {
|
|
668
|
-
async function e() {
|
|
669
|
-
try {
|
|
670
|
-
const n = s.chainId, f = je({
|
|
671
|
-
chain: Re(n),
|
|
672
|
-
transport: Qe(await i.connector.getProvider())
|
|
673
|
-
// TODO: Add proper type
|
|
674
|
-
});
|
|
675
|
-
await Be({
|
|
676
|
-
walletClient: f,
|
|
677
|
-
desiredChainId: n
|
|
678
|
-
});
|
|
679
|
-
} catch (n) {
|
|
680
|
-
t.console.error("Chain switch failed:", n);
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
e().catch(t.console.error);
|
|
684
|
-
}
|
|
685
|
-
}, [i, s]);
|
|
686
|
-
const {
|
|
687
|
-
data: H,
|
|
688
|
-
isLoading: ee,
|
|
689
|
-
isSuccess: be,
|
|
690
|
-
isError: xe,
|
|
691
|
-
error: ge
|
|
692
|
-
} = jn({
|
|
693
|
-
hash: p,
|
|
694
|
-
confirmations: 1,
|
|
695
|
-
query: {
|
|
696
|
-
enabled: !!p
|
|
697
|
-
}
|
|
698
|
-
});
|
|
699
|
-
P(() => {
|
|
700
|
-
if (!p) {
|
|
701
|
-
y?.txnHash && c(null), $(null), Object.keys(Q).length > 0 && he({});
|
|
702
|
-
return;
|
|
703
|
-
}
|
|
704
|
-
if (!(y?.txnHash === p && (y?.status === "Success" || y?.status === "Failed") && !ee)) {
|
|
705
|
-
if (ee) {
|
|
706
|
-
c((e) => ({
|
|
707
|
-
...e?.txnHash === p ? e : {
|
|
708
|
-
gasUsed: void 0,
|
|
709
|
-
effectiveGasPrice: void 0,
|
|
710
|
-
revertReason: void 0
|
|
711
|
-
},
|
|
712
|
-
txnHash: p,
|
|
713
|
-
status: "Pending"
|
|
714
|
-
}));
|
|
715
|
-
return;
|
|
716
|
-
}
|
|
717
|
-
if (be && H) {
|
|
718
|
-
const e = H.status === "success" ? "Success" : "Failed";
|
|
719
|
-
c({
|
|
720
|
-
txnHash: H.transactionHash,
|
|
721
|
-
status: e,
|
|
722
|
-
gasUsed: H.gasUsed ? Number(H.gasUsed) : void 0,
|
|
723
|
-
effectiveGasPrice: H.effectiveGasPrice?.toString(),
|
|
724
|
-
revertReason: H.status === "reverted" ? ge?.message || "Transaction reverted by receipt" : void 0
|
|
725
|
-
}), e !== "Success" && $(null), e === "Success" && W && W.length > 0 && d && !W.some((n) => Q[`${n.chainId}-${n.id}`]) && (t.console.log(
|
|
726
|
-
"Origin transaction successful, calling executeIntent and auto-sending all meta transactions..."
|
|
727
|
-
), m && p && Z.mutate({
|
|
728
|
-
intentId: m,
|
|
729
|
-
depositTransactionHash: p
|
|
730
|
-
}));
|
|
731
|
-
} else xe && (c({
|
|
732
|
-
txnHash: p,
|
|
733
|
-
status: "Failed",
|
|
734
|
-
revertReason: ge?.message || "Failed to get receipt",
|
|
735
|
-
gasUsed: void 0,
|
|
736
|
-
effectiveGasPrice: void 0
|
|
737
|
-
}), $(null));
|
|
738
|
-
}
|
|
739
|
-
}, [
|
|
740
|
-
p,
|
|
741
|
-
ee,
|
|
742
|
-
be,
|
|
743
|
-
xe,
|
|
744
|
-
H,
|
|
745
|
-
ge,
|
|
746
|
-
W,
|
|
747
|
-
Q,
|
|
748
|
-
d,
|
|
749
|
-
y?.status,
|
|
750
|
-
y?.txnHash,
|
|
751
|
-
m,
|
|
752
|
-
Z
|
|
753
|
-
]), P(() => {
|
|
754
|
-
d && A.isSuccess && s?.chainId && i.chainId === s.chainId && !s.error && s.to && s.data !== null && s.value !== null && !r.isPending && !ee && !p && !oe && !y && !F && (t.console.log("Auto-executing transaction: All conditions met."), X(!0), c({
|
|
755
|
-
status: "Sending..."
|
|
756
|
-
}), r.sendTransaction(
|
|
757
|
-
{
|
|
758
|
-
to: s.to,
|
|
759
|
-
data: s.data,
|
|
760
|
-
value: s.value,
|
|
761
|
-
chainId: s.chainId
|
|
762
|
-
},
|
|
763
|
-
{
|
|
764
|
-
onSuccess: (n) => {
|
|
765
|
-
t.console.log("Auto-executed transaction sent, hash:", n), D(n);
|
|
766
|
-
},
|
|
767
|
-
onError: (n) => {
|
|
768
|
-
t.console.error("Auto-executed transaction failed:", n), n instanceof Error && (n.message.includes("User rejected") || n.message.includes("user rejected")) && j(!1), c({
|
|
769
|
-
status: "Failed",
|
|
770
|
-
revertReason: n instanceof Error ? n.message : "Unknown error"
|
|
771
|
-
}), X(!1);
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
));
|
|
775
|
-
}, [
|
|
776
|
-
d,
|
|
777
|
-
A.isSuccess,
|
|
778
|
-
s,
|
|
779
|
-
i.chainId,
|
|
780
|
-
r.isPending,
|
|
781
|
-
ee,
|
|
782
|
-
p,
|
|
783
|
-
oe,
|
|
784
|
-
y,
|
|
785
|
-
F,
|
|
786
|
-
r
|
|
787
|
-
]), P(() => {
|
|
788
|
-
d && V && w && v && i.address && O && !A.isPending && !A.isSuccess && (t.console.log("Auto-committing intent configuration..."), se && A.mutate(se));
|
|
789
|
-
}, [
|
|
790
|
-
d,
|
|
791
|
-
se,
|
|
792
|
-
V,
|
|
793
|
-
w,
|
|
794
|
-
v,
|
|
795
|
-
i.address,
|
|
796
|
-
O,
|
|
797
|
-
A
|
|
798
|
-
]);
|
|
799
|
-
const [ne, tn] = u(null), [re, sn] = u(null);
|
|
800
|
-
P(() => {
|
|
801
|
-
if (!O || !V?.[0]?.chainId || !ne || !re || !w || !i.address) {
|
|
802
|
-
Y(null);
|
|
803
|
-
return;
|
|
804
|
-
}
|
|
805
|
-
try {
|
|
806
|
-
const e = O;
|
|
807
|
-
if (!e || !Ln(e)) {
|
|
808
|
-
Y(null);
|
|
809
|
-
return;
|
|
810
|
-
}
|
|
811
|
-
let n, f = "0x", E = 0n;
|
|
812
|
-
const b = e;
|
|
813
|
-
if (ne === fe || ne === Nn) {
|
|
814
|
-
const x = w.find(
|
|
815
|
-
(T) => (T.type === "transfer-native" || T.type === "native-balance") && T.chainId === re
|
|
816
|
-
)?.minAmount?.toString();
|
|
817
|
-
if (x === void 0)
|
|
818
|
-
throw new Error("Could not find precondition or min amount");
|
|
819
|
-
E = BigInt(x), n = b;
|
|
820
|
-
} else {
|
|
821
|
-
const x = w.find(
|
|
822
|
-
(T) => T.type === "erc20-balance" && T.chainId === re && T.tokenAddress && ce(
|
|
823
|
-
te(T.tokenAddress),
|
|
824
|
-
te(ne)
|
|
825
|
-
)
|
|
826
|
-
)?.minAmount?.toString();
|
|
827
|
-
if (x === void 0)
|
|
828
|
-
throw new Error("Could not find precondition or min amount");
|
|
829
|
-
f = On({
|
|
830
|
-
recipient: b,
|
|
831
|
-
amount: BigInt(x)
|
|
832
|
-
}), n = ne;
|
|
833
|
-
}
|
|
834
|
-
Y({
|
|
835
|
-
to: n,
|
|
836
|
-
data: f,
|
|
837
|
-
value: E,
|
|
838
|
-
chainId: re,
|
|
839
|
-
error: void 0
|
|
840
|
-
});
|
|
841
|
-
} catch (e) {
|
|
842
|
-
t.console.error(
|
|
843
|
-
"[trails-sdk] Failed to calculate origin call params for UI:",
|
|
844
|
-
e
|
|
845
|
-
), Y({
|
|
846
|
-
to: null,
|
|
847
|
-
data: null,
|
|
848
|
-
value: null,
|
|
849
|
-
chainId: null,
|
|
850
|
-
error: e instanceof Error ? e.message : "Unknown error"
|
|
851
|
-
});
|
|
852
|
-
}
|
|
853
|
-
}, [
|
|
854
|
-
V,
|
|
855
|
-
ne,
|
|
856
|
-
re,
|
|
857
|
-
w,
|
|
858
|
-
i.address,
|
|
859
|
-
O
|
|
860
|
-
]);
|
|
861
|
-
const I = Qn(
|
|
862
|
-
m ?? void 0,
|
|
863
|
-
o
|
|
864
|
-
);
|
|
865
|
-
P(() => {
|
|
866
|
-
if (t.console.log("[trails-sdk] Intent receipt status update:", {
|
|
867
|
-
intentId: m,
|
|
868
|
-
done: I.done,
|
|
869
|
-
hasReceipt: !!I.intentReceipt
|
|
870
|
-
}), !I.intentReceipt) {
|
|
871
|
-
t.console.log("[trails-sdk] No intent receipt yet, waiting...");
|
|
872
|
-
return;
|
|
873
|
-
}
|
|
874
|
-
const e = {};
|
|
875
|
-
if (I.intentReceipt.originTransaction) {
|
|
876
|
-
const n = I.intentReceipt.originTransaction, f = `${n.chainId}-${n.metaTxnId}`;
|
|
877
|
-
e[f] = { timestamp: null };
|
|
878
|
-
}
|
|
879
|
-
if (I.intentReceipt.destinationTransaction) {
|
|
880
|
-
const n = I.intentReceipt.destinationTransaction, f = `${n.chainId}-${n.metaTxnId}`;
|
|
881
|
-
e[f] = { timestamp: null };
|
|
882
|
-
}
|
|
883
|
-
De(e);
|
|
884
|
-
}, [
|
|
885
|
-
I.intentReceipt,
|
|
886
|
-
I.done,
|
|
887
|
-
m
|
|
888
|
-
]), P(() => {
|
|
889
|
-
if (I.done && I.intentReceipt && (t.console.log("[trails-sdk] Intent execution completed", {
|
|
890
|
-
intentId: m,
|
|
891
|
-
status: I.intentReceipt.status
|
|
892
|
-
}), I.intentReceipt.originTransaction?.txnHash)) {
|
|
893
|
-
const e = v?.quoteProvider ? String(v.quoteProvider).toLowerCase() : void 0, n = C.variables?.options?.quoteProvider ? String(
|
|
894
|
-
C.variables.options.quoteProvider
|
|
895
|
-
).toLowerCase() : void 0;
|
|
896
|
-
if ((e === "cctp" || n === "cctp") && C.variables)
|
|
897
|
-
try {
|
|
898
|
-
Mn({
|
|
899
|
-
sourceTxHash: I.intentReceipt.originTransaction.txnHash,
|
|
900
|
-
sourceChainId: C.variables.originChainId,
|
|
901
|
-
destinationChainId: C.variables.destinationChainId,
|
|
902
|
-
trailsClient: o
|
|
903
|
-
});
|
|
904
|
-
} catch (E) {
|
|
905
|
-
t.console.error("[Trails] queueCCTPTransfer error", E);
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
}, [
|
|
909
|
-
I.done,
|
|
910
|
-
I.intentReceipt,
|
|
911
|
-
m,
|
|
912
|
-
v,
|
|
913
|
-
C.variables,
|
|
914
|
-
o
|
|
915
|
-
]);
|
|
916
|
-
const on = (e) => {
|
|
917
|
-
j(e);
|
|
918
|
-
};
|
|
919
|
-
function rn(e) {
|
|
920
|
-
C.mutate(e);
|
|
921
|
-
}
|
|
922
|
-
function an(e) {
|
|
923
|
-
t.console.log("[trails-sdk] commitIntent", e), A.mutate(e);
|
|
924
|
-
}
|
|
925
|
-
function cn(e) {
|
|
926
|
-
if (!e) {
|
|
927
|
-
Y(null);
|
|
928
|
-
return;
|
|
929
|
-
}
|
|
930
|
-
const { originChainId: n, tokenAddress: f } = e;
|
|
931
|
-
sn(n), tn(f);
|
|
932
|
-
}
|
|
933
|
-
const { chainId: ln } = i, Oe = s?.chainId, dn = C.isPending, un = C.isSuccess, gn = C.error, mn = C.variables, fn = A.isPending, In = A.isSuccess, hn = A.error, pn = A.variables, vn = Z.isPending, Cn = Z.isSuccess, Tn = Z.error;
|
|
934
|
-
function Sn(e) {
|
|
935
|
-
Z.mutate(e);
|
|
936
|
-
}
|
|
937
|
-
return {
|
|
938
|
-
trailsClient: o,
|
|
939
|
-
metaTxns: W,
|
|
940
|
-
intentCalls: V,
|
|
941
|
-
intentPreconditions: w,
|
|
942
|
-
trailsFee: v,
|
|
943
|
-
txnHash: p,
|
|
944
|
-
committedOriginIntentAddress: m,
|
|
945
|
-
committedDestinationIntentAddress: ve,
|
|
946
|
-
verificationStatus: Je,
|
|
947
|
-
estimatedGas: ue,
|
|
948
|
-
isEstimateError: ke,
|
|
949
|
-
estimateError: ye,
|
|
950
|
-
calculateIntentAddress: Hn,
|
|
951
|
-
calculateOriginAndDestinationIntentAddresses: Le,
|
|
952
|
-
committedIntent: Ke,
|
|
953
|
-
isLoadingCommittedIntent: Xe,
|
|
954
|
-
committedConfigError: Ye,
|
|
955
|
-
commitIntent: an,
|
|
956
|
-
commitIntentPending: fn,
|
|
957
|
-
commitIntentSuccess: In,
|
|
958
|
-
commitIntentError: hn,
|
|
959
|
-
commitIntentArgs: pn,
|
|
960
|
-
executeIntent: Sn,
|
|
961
|
-
executeIntentPending: vn,
|
|
962
|
-
executeIntentSuccess: Cn,
|
|
963
|
-
executeIntentError: Tn,
|
|
964
|
-
getIntentFromQuoteIntent: Ze,
|
|
965
|
-
operationHashes: Ce,
|
|
966
|
-
sendOriginTransaction: nn,
|
|
967
|
-
switchChain: Te,
|
|
968
|
-
isSwitchingChain: Se,
|
|
969
|
-
switchChainError: G,
|
|
970
|
-
isTransactionInProgress: L,
|
|
971
|
-
isChainSwitchRequired: ln !== Oe && !!Oe,
|
|
972
|
-
sendTransaction: r.sendTransaction,
|
|
973
|
-
isSendingTransaction: r.isPending,
|
|
974
|
-
originCallStatus: y,
|
|
975
|
-
updateOriginCallStatus: M,
|
|
976
|
-
isEstimatingGas: Ae,
|
|
977
|
-
isAutoExecute: d,
|
|
978
|
-
updateAutoExecute: on,
|
|
979
|
-
receipt: H,
|
|
980
|
-
isWaitingForReceipt: ee,
|
|
981
|
-
receiptIsSuccess: be,
|
|
982
|
-
receiptIsError: xe,
|
|
983
|
-
receiptError: ge,
|
|
984
|
-
hasAutoExecuted: F,
|
|
985
|
-
originCallSuccess: r.isSuccess,
|
|
986
|
-
sentMetaTxns: Q,
|
|
987
|
-
clearIntent: en,
|
|
988
|
-
intentReceiptStatus: I,
|
|
989
|
-
quoteIntent: rn,
|
|
990
|
-
quoteIntentPending: dn,
|
|
991
|
-
quoteIntentSuccess: un,
|
|
992
|
-
quoteIntentError: gn,
|
|
993
|
-
quoteIntentArgs: mn,
|
|
994
|
-
originCallParams: s,
|
|
995
|
-
updateOriginCallParams: cn,
|
|
996
|
-
originBlockTimestamp: h,
|
|
997
|
-
metaTxnBlockTimestamps: we,
|
|
998
|
-
originIntentAddress: O,
|
|
999
|
-
destinationIntentAddress: le
|
|
1000
388
|
};
|
|
1001
389
|
}
|
|
1002
390
|
export {
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
_e as useExecuteIntent,
|
|
1054
|
-
Gt as useHasSufficientBalanceToken,
|
|
1055
|
-
$t as useHasSufficientBalanceUsd,
|
|
1056
|
-
yn as useIndexerGatewayClient,
|
|
1057
|
-
Qn as useIntentReceiptMonitor,
|
|
1058
|
-
jt as useIntentTransactionHistory,
|
|
1059
|
-
Kn as useQuote,
|
|
1060
|
-
Qt as useSupportedChains,
|
|
1061
|
-
bn as useSupportedTokens,
|
|
1062
|
-
Wt as useTokenBalances,
|
|
1063
|
-
Vt as useTokenList,
|
|
1064
|
-
Xn as useTrails,
|
|
1065
|
-
Ie as useTrailsClient
|
|
391
|
+
Re as InsufficientBalanceError,
|
|
392
|
+
Le as TRAILS_ROUTER_PLACEHOLDER_AMOUNT,
|
|
393
|
+
ge as TradeType,
|
|
394
|
+
Oe as TrailsClient,
|
|
395
|
+
Me as TrailsProvider,
|
|
396
|
+
qe as TrailsWidget,
|
|
397
|
+
Ne as UserRejectionError,
|
|
398
|
+
He as calculateIntentAddress,
|
|
399
|
+
Be as calculateOriginAndDestinationIntentAddresses,
|
|
400
|
+
Pe as commitIntent,
|
|
401
|
+
Fe as createModalController,
|
|
402
|
+
Qe as getAccountTotalBalanceUsd,
|
|
403
|
+
_e as getAccountTransactionHistory,
|
|
404
|
+
Je as getAllChains,
|
|
405
|
+
ue as getChainInfo,
|
|
406
|
+
$e as getCommitHash,
|
|
407
|
+
Ge as getConfig,
|
|
408
|
+
Ke as getDebug,
|
|
409
|
+
We as getERC20TransferData,
|
|
410
|
+
je as getHasSufficientBalanceToken,
|
|
411
|
+
ze as getHasSufficientBalanceUsd,
|
|
412
|
+
Ve as getIntentTransactionHistory,
|
|
413
|
+
Xe as getIsUserRejectionError,
|
|
414
|
+
Ye as getMinLogLevel,
|
|
415
|
+
Ze as getSlippageTolerance,
|
|
416
|
+
et as getSupportedChains,
|
|
417
|
+
tt as getSupportedTokens,
|
|
418
|
+
nt as getTrailsClient,
|
|
419
|
+
st as getTxTimeDiff,
|
|
420
|
+
r as logger,
|
|
421
|
+
ot as pollIntentReceipt,
|
|
422
|
+
me as prepareSend,
|
|
423
|
+
rt as quoteIntent,
|
|
424
|
+
at as sendOriginTransaction,
|
|
425
|
+
it as useAccountTotalBalanceUsd,
|
|
426
|
+
ct as useAccountTransactionHistory,
|
|
427
|
+
Ce as useCommitIntent,
|
|
428
|
+
ke as useExecuteIntent,
|
|
429
|
+
lt as useHasSufficientBalanceToken,
|
|
430
|
+
ut as useHasSufficientBalanceUsd,
|
|
431
|
+
Et as useIndexerGatewayClient,
|
|
432
|
+
Ue as useIntentReceiptMonitor,
|
|
433
|
+
dt as useIntentTransactionHistory,
|
|
434
|
+
ve as useQuote,
|
|
435
|
+
gt as useSupportedChains,
|
|
436
|
+
ce as useSupportedTokens,
|
|
437
|
+
mt as useTokenBalances,
|
|
438
|
+
pt as useTokenList,
|
|
439
|
+
ie as useTrails,
|
|
440
|
+
h as useTrailsClient
|
|
1066
441
|
};
|