0xtrails 0.6.0 → 0.6.2
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-Dw5AN7oU.js → ccip-CZfykYU7.js} +4 -4
- package/dist/chains.d.ts +9 -2
- package/dist/chains.d.ts.map +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/contractUtils.d.ts +2 -1
- package/dist/contractUtils.d.ts.map +1 -1
- package/dist/{index-BtVUTbEZ.js → index-S9pphnT9.js} +29732 -36767
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +300 -242
- package/dist/prepareSend.d.ts.map +1 -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 +3 -1
- package/dist/transactionIntent/types.d.ts.map +1 -1
- package/dist/widget/components/ChainImage.d.ts.map +1 -1
- package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
- package/dist/widget/components/DepositTracker.d.ts +12 -0
- package/dist/widget/components/DepositTracker.d.ts.map +1 -0
- package/dist/widget/components/Disconnect.d.ts.map +1 -1
- package/dist/widget/components/FeeBreakdown.d.ts.map +1 -1
- package/dist/widget/components/QRCodeDeposit.d.ts.map +1 -1
- package/dist/widget/components/QRCodeOptions.d.ts +9 -0
- package/dist/widget/components/QRCodeOptions.d.ts.map +1 -0
- package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
- package/dist/widget/components/Receipt.d.ts.map +1 -1
- package/dist/widget/components/ThemeProvider.d.ts.map +1 -1
- package/dist/widget/components/Toast.d.ts.map +1 -1
- package/dist/widget/components/TransferPendingVertical.d.ts.map +1 -1
- package/dist/widget/components/WalletConnectionPending.d.ts.map +1 -1
- package/dist/widget/css/compiled.css +1 -1
- package/dist/widget/css/index.css +103 -38
- package/dist/widget/hooks/useCheckout.d.ts.map +1 -1
- package/dist/widget/hooks/useCurrentScreen.d.ts +1 -1
- package/dist/widget/hooks/useCurrentScreen.d.ts.map +1 -1
- package/dist/widget/hooks/useDebugScreens.d.ts +1 -1
- package/dist/widget/hooks/useDebugScreens.d.ts.map +1 -1
- package/dist/widget/hooks/useIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/hooks/useQuote.d.ts.map +1 -1
- package/dist/widget/hooks/useSelectedFeeOption.d.ts.map +1 -1
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
- package/dist/widget/index.js +1 -1
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +6 -9
- package/src/chains.ts +37 -4
- package/src/constants.ts +1 -0
- package/src/contractUtils.ts +8 -7
- package/src/estimate.ts +2 -2
- package/src/index.ts +2 -0
- package/src/intents.ts +2 -2
- package/src/paymasterSend.ts +2 -2
- package/src/prepareSend.ts +34 -3
- package/src/sendUserOp.ts +2 -2
- package/src/tokens.ts +2 -2
- package/src/transactionIntent/deposits/gaslessDeposit.ts +2 -2
- package/src/transactionIntent/handlers/crossChain.ts +51 -2
- package/src/transactionIntent/handlers/sameChainSameToken.ts +52 -2
- package/src/transactionIntent/quote/normalizeQuote.ts +2 -2
- package/src/transactionIntent/types.ts +9 -1
- package/src/widget/compiled.css +1 -1
- package/src/widget/components/ChainImage.tsx +10 -7
- package/src/widget/components/ChainList.tsx +1 -1
- package/src/widget/components/ClassicSwap.tsx +8 -4
- package/src/widget/components/ConnectedWallets.tsx +1 -1
- package/src/widget/components/DepositTracker.tsx +298 -0
- package/src/widget/components/Disconnect.tsx +24 -3
- package/src/widget/components/FeeBreakdown.tsx +3 -3
- package/src/widget/components/QRCodeDeposit.tsx +29 -19
- package/src/widget/components/QRCodeOptions.tsx +65 -0
- package/src/widget/components/QuoteDetails.tsx +694 -803
- package/src/widget/components/Receipt.tsx +76 -40
- package/src/widget/components/ThemeProvider.tsx +7 -12
- package/src/widget/components/Toast.tsx +3 -2
- package/src/widget/components/TokenSelector.tsx +1 -1
- package/src/widget/components/Tooltip.tsx +1 -1
- package/src/widget/components/TransferPendingVertical.tsx +11 -2
- package/src/widget/components/WalletConnectionPending.tsx +28 -5
- package/src/widget/hooks/useCheckout.ts +10 -2
- package/src/widget/hooks/useCurrentScreen.tsx +1 -0
- package/src/widget/hooks/useDebugScreens.ts +1 -0
- package/src/widget/hooks/useIntentTransactionHistory.ts +114 -143
- package/src/widget/hooks/useQuote.ts +92 -6
- package/src/widget/hooks/useSelectedFeeOption.tsx +86 -29
- package/src/widget/hooks/useSendForm.ts +43 -7
- package/src/widget/index.css +103 -38
- package/src/widget/widget.tsx +48 -5
- package/dist/0xtrails.css +0 -1
package/dist/index.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { l as r, u as
|
|
2
|
-
import {
|
|
3
|
-
import { useQuery as
|
|
4
|
-
import { useIndexerGatewayClient as
|
|
5
|
-
import { useIndexerGatewayClient as
|
|
6
|
-
import { useRef as
|
|
7
|
-
import { zeroAddress as
|
|
8
|
-
const
|
|
9
|
-
const t =
|
|
10
|
-
queryKey: ["waitIntentReceipt",
|
|
1
|
+
import { l as r, u as v, t as le, a as ue, b as de, I as ge, g as A, c as me, d as Q, e as pe, f as fe, h as $, i as Ce, T as Ee, p as ye, j as _, k as he, m as w } from "./index-S9pphnT9.js";
|
|
2
|
+
import { n as He, S as Be, a0 as Fe, Z as Qe, a2 as $e, U as _e, x as Je, y as Ge, z as Ke, a1 as je, G as We, D as ze, s as Ve, w as Xe, Y as Ye, X as Ze, V as et, H as tt, J as nt, o as ot, _ as st, v as rt, W as it, q as at, O as ct, $ as lt, R as ut, C as dt, A as gt, B as mt, K as pt, E as ft, Q as Ct, L as Et, M as yt, F as ht, r as kt, N as St, P as bt } from "./index-S9pphnT9.js";
|
|
3
|
+
import { useQuery as G, useMutation as K } from "@tanstack/react-query";
|
|
4
|
+
import { useIndexerGatewayClient as ke } from "@0xsequence/hooks";
|
|
5
|
+
import { useIndexerGatewayClient as Tt } from "@0xsequence/hooks";
|
|
6
|
+
import { useRef as Se } from "react";
|
|
7
|
+
import { zeroAddress as T, erc20Abi as be } from "viem";
|
|
8
|
+
const J = 150, Oe = (c, e) => {
|
|
9
|
+
const t = G({
|
|
10
|
+
queryKey: ["waitIntentReceipt", c],
|
|
11
11
|
queryFn: async () => {
|
|
12
|
-
if (!
|
|
12
|
+
if (!c)
|
|
13
13
|
throw new Error("Intent ID is required for monitoring");
|
|
14
14
|
r.console.log(
|
|
15
|
-
`[trails-sdk] 🔍 Monitoring intent receipt for ${
|
|
15
|
+
`[trails-sdk] 🔍 Monitoring intent receipt for ${c}`
|
|
16
16
|
);
|
|
17
|
-
const
|
|
18
|
-
intentId:
|
|
17
|
+
const o = await e.waitIntentReceipt({
|
|
18
|
+
intentId: c
|
|
19
19
|
});
|
|
20
20
|
return r.console.log(
|
|
21
|
-
`[trails-sdk] 📊 Intent ${
|
|
22
|
-
),
|
|
21
|
+
`[trails-sdk] 📊 Intent ${c} status: ${o.intentReceipt.status}, done: ${o.done}`
|
|
22
|
+
), o;
|
|
23
23
|
},
|
|
24
|
-
enabled: !!
|
|
24
|
+
enabled: !!c,
|
|
25
25
|
refetchIntervalInBackground: !0,
|
|
26
|
-
refetchInterval: (
|
|
27
|
-
const s =
|
|
26
|
+
refetchInterval: (o) => {
|
|
27
|
+
const s = o.state.data;
|
|
28
28
|
return s && s.done ? (r.console.log(
|
|
29
|
-
`[trails-sdk] ✅ Intent monitoring complete for ${
|
|
30
|
-
), !1) :
|
|
29
|
+
`[trails-sdk] ✅ Intent monitoring complete for ${c}`
|
|
30
|
+
), !1) : J;
|
|
31
31
|
},
|
|
32
|
-
retry: (
|
|
33
|
-
`[trails-sdk] ❌ Giving up on intent ${
|
|
32
|
+
retry: (o, s) => o >= 30 ? (r.console.error(
|
|
33
|
+
`[trails-sdk] ❌ Giving up on intent ${c} after 30 failed API attempts:`,
|
|
34
34
|
s
|
|
35
35
|
), !1) : !0
|
|
36
36
|
});
|
|
@@ -42,76 +42,76 @@ const B = 150, ve = (i, e) => {
|
|
|
42
42
|
error: t.error
|
|
43
43
|
};
|
|
44
44
|
};
|
|
45
|
-
function
|
|
46
|
-
const
|
|
47
|
-
return
|
|
45
|
+
function we() {
|
|
46
|
+
const c = v();
|
|
47
|
+
return K({
|
|
48
48
|
mutationFn: async (e) => {
|
|
49
49
|
r.console.log("[trails-sdk] useCommitIntent: Starting commit", {
|
|
50
50
|
intentId: e.intentId,
|
|
51
51
|
originIntentAddress: e.originIntentAddress
|
|
52
52
|
});
|
|
53
|
-
const t = e.quoteRequest.originChainId.toString(),
|
|
53
|
+
const t = e.quoteRequest.originChainId.toString(), o = e.quoteRequest.destinationChainId.toString();
|
|
54
54
|
try {
|
|
55
|
-
|
|
55
|
+
le({
|
|
56
56
|
intentAddress: e.originIntentAddress,
|
|
57
57
|
userAddress: e.ownerAddress,
|
|
58
58
|
originChainId: t ? Number(t) : void 0,
|
|
59
|
-
destinationChainId:
|
|
59
|
+
destinationChainId: o ? Number(o) : void 0
|
|
60
60
|
});
|
|
61
|
-
const s = await
|
|
61
|
+
const s = await c.commitIntent({ intent: e });
|
|
62
62
|
return r.console.log("[trails-sdk] useCommitIntent: Commit successful", {
|
|
63
63
|
intentId: e.intentId,
|
|
64
64
|
response: s
|
|
65
|
-
}),
|
|
65
|
+
}), ue({
|
|
66
66
|
intentAddress: e.originIntentAddress,
|
|
67
67
|
userAddress: e.ownerAddress,
|
|
68
68
|
originChainId: t ? Number(t) : void 0,
|
|
69
|
-
destinationChainId:
|
|
69
|
+
destinationChainId: o ? Number(o) : void 0
|
|
70
70
|
}), s;
|
|
71
71
|
} catch (s) {
|
|
72
|
-
throw
|
|
73
|
-
error:
|
|
72
|
+
throw de({
|
|
73
|
+
error: A(s),
|
|
74
74
|
userAddress: e.ownerAddress,
|
|
75
75
|
intentAddress: e.originIntentAddress,
|
|
76
76
|
originChainId: t ? Number(t) : void 0,
|
|
77
|
-
destinationChainId:
|
|
77
|
+
destinationChainId: o ? Number(o) : void 0
|
|
78
78
|
}), s;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
|
-
function
|
|
84
|
-
const
|
|
85
|
-
return
|
|
83
|
+
function Te() {
|
|
84
|
+
const c = v();
|
|
85
|
+
return K({
|
|
86
86
|
mutationFn: async ({
|
|
87
87
|
intentId: e,
|
|
88
88
|
depositTransactionHash: t,
|
|
89
|
-
depositSignature:
|
|
89
|
+
depositSignature: o
|
|
90
90
|
}) => {
|
|
91
91
|
if (r.console.log("[trails-sdk] useExecuteIntent: Starting execution", {
|
|
92
92
|
intentId: e,
|
|
93
93
|
depositTransactionHash: t,
|
|
94
|
-
hasDepositSignature: !!
|
|
95
|
-
}), !t && !
|
|
94
|
+
hasDepositSignature: !!o
|
|
95
|
+
}), !t && !o)
|
|
96
96
|
throw new Error(
|
|
97
97
|
"[trails-sdk] Either depositTransactionHash or depositSignature must be provided"
|
|
98
98
|
);
|
|
99
99
|
let s;
|
|
100
100
|
try {
|
|
101
|
-
s = await
|
|
101
|
+
s = await c.executeIntent({
|
|
102
102
|
intentId: e,
|
|
103
103
|
depositTransactionHash: t,
|
|
104
|
-
depositSignature:
|
|
104
|
+
depositSignature: o
|
|
105
105
|
});
|
|
106
|
-
} catch (
|
|
106
|
+
} catch (l) {
|
|
107
107
|
if (r.console.error(
|
|
108
108
|
"[trails-sdk] useExecuteIntent: Error executing intent",
|
|
109
109
|
{
|
|
110
110
|
intentId: e,
|
|
111
|
-
error:
|
|
112
|
-
errorJSON: JSON.stringify(
|
|
111
|
+
error: l,
|
|
112
|
+
errorJSON: JSON.stringify(l, null, 2)
|
|
113
113
|
}
|
|
114
|
-
),
|
|
114
|
+
), l instanceof Error && l?.message?.includes("status=SUCCEEDED") || l instanceof Error && l?.cause?.message?.includes("status=SUCCEEDED") || l instanceof Error && JSON.stringify(l).includes("status=SUCCEEDED") || l instanceof ge && l?.cause?.toString().includes("status=SUCCEEDED") || JSON.stringify(l).includes("status=SUCCEEDED"))
|
|
115
115
|
return r.console.error(
|
|
116
116
|
"[trails-sdk] useExecuteIntent: Intent already succeeded, treating as success",
|
|
117
117
|
{ intentId: e }
|
|
@@ -123,10 +123,10 @@ function ye() {
|
|
|
123
123
|
"[trails-sdk] useExecuteIntent did not throw IntentStatusError and is not a SUCCEEDED intent",
|
|
124
124
|
{
|
|
125
125
|
intentId: e,
|
|
126
|
-
error:
|
|
127
|
-
errorJSON: JSON.stringify(
|
|
126
|
+
error: l,
|
|
127
|
+
errorJSON: JSON.stringify(l, null, 2)
|
|
128
128
|
}
|
|
129
|
-
),
|
|
129
|
+
), l;
|
|
130
130
|
}
|
|
131
131
|
return r.console.log(
|
|
132
132
|
"[trails-sdk] useExecuteIntent: Execution successful",
|
|
@@ -138,212 +138,268 @@ function ye() {
|
|
|
138
138
|
}
|
|
139
139
|
});
|
|
140
140
|
}
|
|
141
|
-
function
|
|
142
|
-
walletClient:
|
|
141
|
+
function Ne({
|
|
142
|
+
walletClient: c,
|
|
143
143
|
fromTokenAddress: e,
|
|
144
144
|
fromChainId: t,
|
|
145
|
-
toTokenAddress:
|
|
145
|
+
toTokenAddress: o,
|
|
146
146
|
toChainId: s,
|
|
147
|
-
swapAmount:
|
|
147
|
+
swapAmount: l,
|
|
148
148
|
tradeType: I,
|
|
149
|
-
toRecipient:
|
|
150
|
-
toCalldata:
|
|
151
|
-
slippageTolerance:
|
|
152
|
-
onStatusUpdate:
|
|
153
|
-
checkoutOnHandlers:
|
|
154
|
-
quoteProvider:
|
|
155
|
-
paymasterUrl:
|
|
156
|
-
selectedFeeOption:
|
|
157
|
-
nodeGatewayEnv:
|
|
158
|
-
abortSignal:
|
|
159
|
-
apiKey:
|
|
149
|
+
toRecipient: p,
|
|
150
|
+
toCalldata: U,
|
|
151
|
+
slippageTolerance: D,
|
|
152
|
+
onStatusUpdate: j,
|
|
153
|
+
checkoutOnHandlers: W,
|
|
154
|
+
quoteProvider: R,
|
|
155
|
+
paymasterUrl: z,
|
|
156
|
+
selectedFeeOption: x,
|
|
157
|
+
nodeGatewayEnv: q,
|
|
158
|
+
abortSignal: L,
|
|
159
|
+
apiKey: V
|
|
160
160
|
} = {}) {
|
|
161
|
-
|
|
162
|
-
const
|
|
161
|
+
q && (globalThis.__testNodeGatewayEnv = q);
|
|
162
|
+
const g = Se(new AbortController()), X = L ? (() => {
|
|
163
163
|
const u = new AbortController();
|
|
164
|
-
return
|
|
165
|
-
u.abort(),
|
|
166
|
-
}),
|
|
164
|
+
return L.addEventListener("abort", () => {
|
|
165
|
+
u.abort(), g.current?.abort();
|
|
166
|
+
}), g.current?.signal.addEventListener("abort", () => {
|
|
167
167
|
u.abort();
|
|
168
168
|
}), u.signal;
|
|
169
|
-
})() :
|
|
170
|
-
apiKey:
|
|
171
|
-
hostname:
|
|
172
|
-
}),
|
|
169
|
+
})() : g.current.signal, { trailsApiKey: O, trailsApiUrl: Y, sequenceIndexerUrl: Z } = me(), ee = O, m = v({
|
|
170
|
+
apiKey: O,
|
|
171
|
+
hostname: Y
|
|
172
|
+
}), S = ke(), N = Q(t ?? void 0), P = Q(s ?? void 0), { supportedTokens: f } = pe(), te = we(), ne = Te(), { data: M, isLoading: oe, error: H, refetch: se } = G({
|
|
173
173
|
queryKey: [
|
|
174
174
|
"prepareSend",
|
|
175
175
|
e,
|
|
176
176
|
t,
|
|
177
|
-
|
|
177
|
+
o,
|
|
178
178
|
s,
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
179
|
+
l?.toString(),
|
|
180
|
+
p,
|
|
181
|
+
U,
|
|
182
182
|
I,
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
183
|
+
D,
|
|
184
|
+
R,
|
|
185
|
+
V
|
|
186
186
|
],
|
|
187
187
|
queryFn: async () => {
|
|
188
188
|
try {
|
|
189
|
-
if (
|
|
189
|
+
if (g.current.signal.aborted && (r.console.log(
|
|
190
190
|
"[trails-sdk] Resetting aborted controller for new query"
|
|
191
|
-
),
|
|
191
|
+
), g.current = new AbortController()), !c || !m || !e || !o || !l || !p || !t || !s || !S)
|
|
192
192
|
return null;
|
|
193
193
|
let u = [];
|
|
194
194
|
try {
|
|
195
|
-
u = (await
|
|
196
|
-
account:
|
|
197
|
-
indexerGatewayClient:
|
|
198
|
-
trailsClient:
|
|
195
|
+
u = (await fe({
|
|
196
|
+
account: c.account.address,
|
|
197
|
+
indexerGatewayClient: S,
|
|
198
|
+
trailsClient: m
|
|
199
199
|
})).balances;
|
|
200
|
-
} catch (
|
|
201
|
-
const
|
|
202
|
-
if (
|
|
200
|
+
} catch (n) {
|
|
201
|
+
const a = A(n), d = a.includes("Cross-Origin") || a.includes("CORS") || a.includes("Same Origin Policy"), k = a.includes("fetch failed") || a.includes("network");
|
|
202
|
+
if (d || k)
|
|
203
203
|
r.console.warn(
|
|
204
204
|
"[trails-sdk] [useQuote] Network or CORS error fetching balances, proceeding with quote using zero balance:",
|
|
205
205
|
{
|
|
206
|
-
error:
|
|
207
|
-
account:
|
|
206
|
+
error: a,
|
|
207
|
+
account: c.account.address
|
|
208
208
|
}
|
|
209
209
|
), u = [];
|
|
210
210
|
else
|
|
211
|
-
throw
|
|
211
|
+
throw n;
|
|
212
212
|
}
|
|
213
|
-
const
|
|
214
|
-
(
|
|
213
|
+
const re = u.find(
|
|
214
|
+
(n) => n.chainId === t && (n.contractAddress?.toLowerCase() === e.toLowerCase() || !n.contractAddress && e === T)
|
|
215
215
|
)?.balance ?? "0";
|
|
216
|
-
let
|
|
216
|
+
let b = 0;
|
|
217
217
|
try {
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
tokenSymbol:
|
|
221
|
-
tokenAddress:
|
|
218
|
+
const a = $(t)?.nativeCurrency?.symbol ?? "";
|
|
219
|
+
a && (b = (await Ce(m, {
|
|
220
|
+
tokenSymbol: a,
|
|
221
|
+
tokenAddress: T,
|
|
222
222
|
chainId: t
|
|
223
223
|
}))?.priceUsd ?? 0, r.console.log(
|
|
224
224
|
"[trails-sdk] [useQuote] Origin native token price:",
|
|
225
225
|
{
|
|
226
226
|
chainId: t,
|
|
227
|
-
symbol:
|
|
228
|
-
priceUsd:
|
|
227
|
+
symbol: a,
|
|
228
|
+
priceUsd: b
|
|
229
229
|
}
|
|
230
230
|
));
|
|
231
|
-
} catch (
|
|
231
|
+
} catch (n) {
|
|
232
232
|
r.console.error(
|
|
233
233
|
"[trails-sdk] [useQuote] Error getting origin native token price:",
|
|
234
|
-
|
|
234
|
+
n
|
|
235
235
|
);
|
|
236
236
|
}
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
237
|
+
const B = async (n, a) => {
|
|
238
|
+
try {
|
|
239
|
+
const d = a === t ? N : a === s ? P : null;
|
|
240
|
+
if (!d)
|
|
241
|
+
return r.console.warn(
|
|
242
|
+
`[trails-sdk] No RPC client available for chain ${a}`
|
|
243
|
+
), null;
|
|
244
|
+
if (n.toLowerCase() === T.toLowerCase())
|
|
245
|
+
return $(a)?.nativeCurrency.decimals ?? 18;
|
|
246
|
+
const k = await d.readContract({
|
|
247
|
+
address: n,
|
|
248
|
+
abi: be,
|
|
249
|
+
functionName: "decimals"
|
|
250
|
+
});
|
|
251
|
+
return r.console.log(
|
|
252
|
+
`[trails-sdk] Fetched decimals on-chain for token ${n} on chain ${a}: ${k}`
|
|
253
|
+
), k;
|
|
254
|
+
} catch (d) {
|
|
255
|
+
return r.console.error(
|
|
256
|
+
`[trails-sdk] Error fetching decimals on-chain for token ${n} on chain ${a}:`,
|
|
257
|
+
d
|
|
258
|
+
), null;
|
|
259
|
+
}
|
|
260
|
+
}, C = f?.find(
|
|
261
|
+
(n) => n.contractAddress?.toLowerCase() === e?.toLowerCase() && n.chainId === t
|
|
262
|
+
), E = f?.find(
|
|
263
|
+
(n) => n.contractAddress?.toLowerCase() === o?.toLowerCase() && n.chainId === s
|
|
264
|
+
);
|
|
265
|
+
let y = C?.decimals;
|
|
266
|
+
if (!y && e && t) {
|
|
267
|
+
r.console.warn(
|
|
268
|
+
"[trails-sdk] [useQuote] Source token decimals not found in token list, fetching on-chain:",
|
|
269
|
+
{
|
|
270
|
+
originToken: C,
|
|
271
|
+
fromTokenAddress: e,
|
|
272
|
+
fromChainId: t
|
|
273
|
+
}
|
|
274
|
+
);
|
|
275
|
+
const n = await B(
|
|
276
|
+
e,
|
|
277
|
+
t
|
|
278
|
+
);
|
|
279
|
+
n !== null && (y = n);
|
|
280
|
+
}
|
|
281
|
+
if (!y)
|
|
243
282
|
throw r.console.error(
|
|
244
|
-
"[trails-sdk] [useQuote]
|
|
283
|
+
"[trails-sdk] [useQuote] Source token decimals not found:",
|
|
245
284
|
{
|
|
246
|
-
originToken:
|
|
285
|
+
originToken: C,
|
|
247
286
|
fromTokenAddress: e,
|
|
248
287
|
fromChainId: t
|
|
249
288
|
}
|
|
250
289
|
), new Error("Source token decimals not found");
|
|
251
|
-
|
|
252
|
-
if (!
|
|
290
|
+
let h = E?.decimals;
|
|
291
|
+
if (!h && o && s) {
|
|
292
|
+
r.console.warn(
|
|
293
|
+
"[trails-sdk] Destination token decimals not found in token list, fetching on-chain:",
|
|
294
|
+
{
|
|
295
|
+
destinationToken: E,
|
|
296
|
+
toTokenAddress: o,
|
|
297
|
+
toChainId: s
|
|
298
|
+
}
|
|
299
|
+
);
|
|
300
|
+
const n = await B(
|
|
301
|
+
o,
|
|
302
|
+
s
|
|
303
|
+
);
|
|
304
|
+
n !== null && (h = n);
|
|
305
|
+
}
|
|
306
|
+
if (!h)
|
|
253
307
|
throw r.console.error(
|
|
254
|
-
"[trails-sdk]
|
|
308
|
+
"[trails-sdk] Destination token decimals not found:",
|
|
255
309
|
{
|
|
256
|
-
destinationToken:
|
|
257
|
-
toTokenAddress:
|
|
310
|
+
destinationToken: E,
|
|
311
|
+
toTokenAddress: o,
|
|
258
312
|
toChainId: s
|
|
259
313
|
}
|
|
260
314
|
), new Error("Destination token decimals not found");
|
|
261
|
-
const
|
|
262
|
-
account:
|
|
315
|
+
const ie = E?.symbol ?? "", ae = C?.symbol ?? "", F = {
|
|
316
|
+
account: c.account,
|
|
263
317
|
originTokenAddress: e,
|
|
264
318
|
originChainId: t,
|
|
265
|
-
originTokenBalance:
|
|
319
|
+
originTokenBalance: re,
|
|
266
320
|
destinationChainId: s,
|
|
267
|
-
recipient:
|
|
268
|
-
destinationTokenAddress:
|
|
269
|
-
swapAmount:
|
|
270
|
-
tradeType: I ??
|
|
271
|
-
originTokenSymbol:
|
|
272
|
-
destinationTokenSymbol:
|
|
273
|
-
destinationCalldata:
|
|
274
|
-
client:
|
|
275
|
-
trailsClient:
|
|
276
|
-
sourceTokenDecimals:
|
|
277
|
-
destinationTokenDecimals:
|
|
321
|
+
recipient: p,
|
|
322
|
+
destinationTokenAddress: o,
|
|
323
|
+
swapAmount: l.toString(),
|
|
324
|
+
tradeType: I ?? Ee.EXACT_OUTPUT,
|
|
325
|
+
originTokenSymbol: ae,
|
|
326
|
+
destinationTokenSymbol: ie,
|
|
327
|
+
destinationCalldata: U,
|
|
328
|
+
client: c,
|
|
329
|
+
trailsClient: m,
|
|
330
|
+
sourceTokenDecimals: y,
|
|
331
|
+
destinationTokenDecimals: h,
|
|
278
332
|
fee: "0",
|
|
279
333
|
dryMode: !1,
|
|
280
|
-
onTransactionStateChange:
|
|
334
|
+
onTransactionStateChange: j ?? (() => {
|
|
281
335
|
}),
|
|
282
|
-
slippageTolerance:
|
|
283
|
-
quoteProvider:
|
|
284
|
-
paymasterUrl:
|
|
285
|
-
selectedFeeOption:
|
|
286
|
-
abortSignal:
|
|
287
|
-
originNativeTokenPriceUsd:
|
|
288
|
-
commitIntentFn:
|
|
289
|
-
executeIntentFn:
|
|
290
|
-
checkoutOnHandlers:
|
|
291
|
-
sequenceIndexerUrl:
|
|
292
|
-
sequenceProjectAccessKey:
|
|
336
|
+
slippageTolerance: D?.toString(),
|
|
337
|
+
quoteProvider: R,
|
|
338
|
+
paymasterUrl: z,
|
|
339
|
+
selectedFeeOption: x ?? null,
|
|
340
|
+
abortSignal: X,
|
|
341
|
+
originNativeTokenPriceUsd: b,
|
|
342
|
+
commitIntentFn: te.mutateAsync,
|
|
343
|
+
executeIntentFn: ne.mutateAsync,
|
|
344
|
+
checkoutOnHandlers: W,
|
|
345
|
+
sequenceIndexerUrl: Z,
|
|
346
|
+
sequenceProjectAccessKey: ee,
|
|
347
|
+
originPublicClient: N ?? void 0,
|
|
348
|
+
destinationPublicClient: P ?? void 0
|
|
293
349
|
};
|
|
294
|
-
r.console.log("[trails-sdk] options",
|
|
295
|
-
const { quote:
|
|
350
|
+
r.console.log("[trails-sdk] options", F);
|
|
351
|
+
const { quote: i, send: ce } = await ye(F);
|
|
296
352
|
return {
|
|
297
353
|
quote: {
|
|
298
|
-
fromAmount:
|
|
299
|
-
toAmount:
|
|
300
|
-
fromAmountMin:
|
|
301
|
-
toAmountMin:
|
|
302
|
-
originToken:
|
|
303
|
-
destinationToken:
|
|
304
|
-
originChain:
|
|
305
|
-
destinationChain:
|
|
306
|
-
fees:
|
|
307
|
-
priceImpact:
|
|
308
|
-
completionEstimateSeconds:
|
|
309
|
-
slippageTolerance:
|
|
310
|
-
transactionStates:
|
|
311
|
-
originTokenRate:
|
|
312
|
-
destinationTokenRate:
|
|
313
|
-
quoteProvider:
|
|
314
|
-
fromAmountUsdDisplay:
|
|
315
|
-
toAmountUsdDisplay:
|
|
316
|
-
gasCostUsd:
|
|
317
|
-
gasCostUsdDisplay:
|
|
318
|
-
gasCost:
|
|
319
|
-
gasCostFormatted:
|
|
354
|
+
fromAmount: i.originAmount,
|
|
355
|
+
toAmount: i.destinationAmount,
|
|
356
|
+
fromAmountMin: i.originAmountMin,
|
|
357
|
+
toAmountMin: i.destinationAmountMin,
|
|
358
|
+
originToken: i.originToken,
|
|
359
|
+
destinationToken: i.destinationToken,
|
|
360
|
+
originChain: i.originChain,
|
|
361
|
+
destinationChain: i.destinationChain,
|
|
362
|
+
fees: i.fees,
|
|
363
|
+
priceImpact: i.priceImpact,
|
|
364
|
+
completionEstimateSeconds: i.completionEstimateSeconds,
|
|
365
|
+
slippageTolerance: i.slippageTolerance,
|
|
366
|
+
transactionStates: i.transactionStates,
|
|
367
|
+
originTokenRate: i.originTokenRate,
|
|
368
|
+
destinationTokenRate: i.destinationTokenRate,
|
|
369
|
+
quoteProvider: i.quoteProvider,
|
|
370
|
+
fromAmountUsdDisplay: i.originAmountUsdDisplay ?? void 0,
|
|
371
|
+
toAmountUsdDisplay: i.destinationAmountUsdDisplay ?? void 0,
|
|
372
|
+
gasCostUsd: i.gasCostUsd ?? void 0,
|
|
373
|
+
gasCostUsdDisplay: i.gasCostUsdDisplay ?? void 0,
|
|
374
|
+
gasCost: i.gasCost ?? void 0,
|
|
375
|
+
gasCostFormatted: i.gasCostFormatted ?? void 0
|
|
320
376
|
},
|
|
321
377
|
swap: async () => {
|
|
322
378
|
const {
|
|
323
|
-
depositUserTxnReceipt:
|
|
324
|
-
destinationIntentTransaction:
|
|
325
|
-
totalCompletionSeconds:
|
|
326
|
-
} = await
|
|
327
|
-
selectedFeeOption:
|
|
379
|
+
depositUserTxnReceipt: n,
|
|
380
|
+
destinationIntentTransaction: a,
|
|
381
|
+
totalCompletionSeconds: d
|
|
382
|
+
} = await ce({
|
|
383
|
+
selectedFeeOption: x ?? null
|
|
328
384
|
});
|
|
329
385
|
return {
|
|
330
386
|
originTransaction: {
|
|
331
|
-
transactionHash:
|
|
332
|
-
explorerUrl:
|
|
333
|
-
txHash:
|
|
387
|
+
transactionHash: n?.transactionHash,
|
|
388
|
+
explorerUrl: _({
|
|
389
|
+
txHash: n?.transactionHash,
|
|
334
390
|
chainId: t
|
|
335
391
|
}),
|
|
336
|
-
receipt:
|
|
392
|
+
receipt: n
|
|
337
393
|
},
|
|
338
394
|
destinationTransaction: {
|
|
339
|
-
transactionHash:
|
|
340
|
-
explorerUrl:
|
|
341
|
-
txHash:
|
|
395
|
+
transactionHash: a?.txnHash,
|
|
396
|
+
explorerUrl: _({
|
|
397
|
+
txHash: a?.txnHash,
|
|
342
398
|
chainId: s
|
|
343
399
|
}),
|
|
344
|
-
receipt:
|
|
400
|
+
receipt: a
|
|
345
401
|
},
|
|
346
|
-
totalCompletionSeconds:
|
|
402
|
+
totalCompletionSeconds: d
|
|
347
403
|
};
|
|
348
404
|
}
|
|
349
405
|
};
|
|
@@ -351,12 +407,12 @@ function De({
|
|
|
351
407
|
throw r.console.error(
|
|
352
408
|
"[trails-sdk] [useQuote] Error getting quote:",
|
|
353
409
|
u
|
|
354
|
-
),
|
|
410
|
+
), A(u);
|
|
355
411
|
}
|
|
356
412
|
},
|
|
357
413
|
// Prevent unnecessary refetching
|
|
358
|
-
enabled: !!(
|
|
359
|
-
|
|
414
|
+
enabled: !!(c && m && e && o && l && p && t && s && S && // !isLoadingTokens &&
|
|
415
|
+
f && f.length > 0),
|
|
360
416
|
staleTime: 30 * 1e3,
|
|
361
417
|
// Consider data fresh for 30 seconds
|
|
362
418
|
refetchOnWindowFocus: !1,
|
|
@@ -371,72 +427,74 @@ function De({
|
|
|
371
427
|
// Refetch when network reconnects
|
|
372
428
|
});
|
|
373
429
|
return {
|
|
374
|
-
quote:
|
|
375
|
-
swap:
|
|
376
|
-
isLoadingQuote:
|
|
377
|
-
quoteError:
|
|
378
|
-
quoteErrorPrettified:
|
|
379
|
-
refetchQuote: () =>
|
|
430
|
+
quote: M?.quote || null,
|
|
431
|
+
swap: M?.swap || null,
|
|
432
|
+
isLoadingQuote: oe,
|
|
433
|
+
quoteError: H,
|
|
434
|
+
quoteErrorPrettified: he(H),
|
|
435
|
+
refetchQuote: () => se(),
|
|
380
436
|
abort: () => {
|
|
381
437
|
r.console.log("[trails-sdk] useQuote abort() called"), r.console.log(
|
|
382
438
|
"[trails-sdk] Active operations before abort:",
|
|
383
|
-
|
|
384
|
-
),
|
|
439
|
+
w.getAll()
|
|
440
|
+
), g.current.abort(), w.abortAll(), r.console.log(
|
|
385
441
|
"[trails-sdk] Abort completed, active operations:",
|
|
386
|
-
|
|
442
|
+
w.getAll()
|
|
387
443
|
);
|
|
388
444
|
}
|
|
389
445
|
};
|
|
390
446
|
}
|
|
391
447
|
export {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
448
|
+
He as InsufficientBalanceError,
|
|
449
|
+
Be as TRAILS_ROUTER_PLACEHOLDER_AMOUNT,
|
|
450
|
+
Ee as TradeType,
|
|
451
|
+
Fe as TrailsClient,
|
|
452
|
+
Qe as TrailsProvider,
|
|
453
|
+
$e as TrailsWidget,
|
|
454
|
+
_e as UserRejectionError,
|
|
455
|
+
Je as calculateIntentAddress,
|
|
456
|
+
Ge as calculateOriginAndDestinationIntentAddresses,
|
|
457
|
+
Ke as commitIntent,
|
|
458
|
+
je as createModalController,
|
|
459
|
+
We as getAccountTotalBalanceUsd,
|
|
460
|
+
ze as getAccountTransactionHistory,
|
|
461
|
+
Ve as getAllChains,
|
|
462
|
+
$ as getChainInfo,
|
|
463
|
+
Xe as getChainRpcClient,
|
|
464
|
+
Ye as getCommitHash,
|
|
465
|
+
Ze as getDebug,
|
|
466
|
+
et as getERC20TransferData,
|
|
467
|
+
tt as getHasSufficientBalanceToken,
|
|
468
|
+
nt as getHasSufficientBalanceUsd,
|
|
469
|
+
ot as getIsUserRejectionError,
|
|
470
|
+
st as getMinLogLevel,
|
|
471
|
+
rt as getRpcUrl,
|
|
472
|
+
it as getSlippageTolerance,
|
|
473
|
+
at as getSupportedChains,
|
|
474
|
+
ct as getSupportedTokens,
|
|
475
|
+
lt as getTrailsClient,
|
|
476
|
+
ut as getTxTimeDiff,
|
|
420
477
|
r as logger,
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
478
|
+
dt as pollIntentReceipt,
|
|
479
|
+
ye as prepareSend,
|
|
480
|
+
gt as quoteIntent,
|
|
481
|
+
mt as sendOriginTransaction,
|
|
482
|
+
pt as useAccountTotalBalanceUsd,
|
|
483
|
+
ft as useAccountTransactionHistory,
|
|
484
|
+
Q as useChainRpcClient,
|
|
485
|
+
we as useCommitIntent,
|
|
486
|
+
Te as useExecuteIntent,
|
|
487
|
+
Ct as useGetTokenImageUrl,
|
|
488
|
+
Et as useHasSufficientBalanceToken,
|
|
489
|
+
yt as useHasSufficientBalanceUsd,
|
|
490
|
+
Tt as useIndexerGatewayClient,
|
|
491
|
+
Oe as useIntentReceiptMonitor,
|
|
492
|
+
ht as useIntentTransactionHistory,
|
|
493
|
+
Ne as useQuote,
|
|
494
|
+
kt as useSupportedChains,
|
|
495
|
+
pe as useSupportedTokens,
|
|
496
|
+
St as useTokenBalances,
|
|
497
|
+
bt as useTokenList,
|
|
498
|
+
me as useTrails,
|
|
499
|
+
v as useTrailsClient
|
|
442
500
|
};
|