0xtrails 0.5.0 → 0.6.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/analytics.d.ts +8 -3
- package/dist/analytics.d.ts.map +1 -1
- package/dist/{ccip-DhEkQ6QC.js → ccip-Dw5AN7oU.js} +1 -1
- package/dist/cctp.d.ts +0 -149
- package/dist/cctp.d.ts.map +1 -1
- package/dist/chains.d.ts +28 -3
- package/dist/chains.d.ts.map +1 -1
- package/dist/config.d.ts +11 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/contractUtils.d.ts.map +1 -1
- package/dist/estimate.d.ts.map +1 -1
- package/dist/fees.d.ts.map +1 -1
- package/dist/gasless.d.ts +12 -0
- package/dist/gasless.d.ts.map +1 -1
- package/dist/{index-MhD2DA7_.js → index-BtVUTbEZ.js} +30984 -38945
- package/dist/index.d.ts +7 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +108 -107
- package/dist/indexerClient.d.ts +2 -2
- package/dist/intents.d.ts +0 -17
- package/dist/intents.d.ts.map +1 -1
- package/dist/mutations.d.ts.map +1 -1
- package/dist/paymasterSend.d.ts.map +1 -1
- package/dist/prepareSend.d.ts +1 -1
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/sendUserOp.d.ts +0 -18
- package/dist/sendUserOp.d.ts.map +1 -1
- package/dist/tokenBalances.d.ts.map +1 -1
- package/dist/tokens.d.ts +10 -8
- package/dist/tokens.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts +4 -5
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts +4 -5
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/standardDeposit.d.ts +2 -2
- package/dist/transactionIntent/deposits/standardDeposit.d.ts.map +1 -1
- package/dist/transactionIntent/execution/transactionState.d.ts +2 -2
- package/dist/transactionIntent/execution/transactionState.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/crossChain.d.ts +4 -4
- package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/index.d.ts +0 -1
- package/dist/transactionIntent/handlers/index.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts +4 -34
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -1
- package/dist/transactionIntent/quote/normalizeQuote.d.ts.map +1 -1
- package/dist/transactionIntent/quote/quoteHelpers.d.ts +2 -1
- package/dist/transactionIntent/quote/quoteHelpers.d.ts.map +1 -1
- package/dist/transactionIntent/types.d.ts +6 -19
- package/dist/transactionIntent/types.d.ts.map +1 -1
- package/dist/transactionIntent/utils/index.d.ts +0 -1
- package/dist/transactionIntent/utils/index.d.ts.map +1 -1
- package/dist/transactions.d.ts +2 -20
- package/dist/transactions.d.ts.map +1 -1
- package/dist/utils.d.ts +8 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/walletUtils.d.ts +21 -0
- package/dist/walletUtils.d.ts.map +1 -0
- package/dist/wallets.d.ts +33 -240
- package/dist/wallets.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/FeeOption.d.ts +8 -13
- package/dist/widget/components/FeeOption.d.ts.map +1 -1
- package/dist/widget/components/FeeOptions.d.ts +11 -5
- package/dist/widget/components/FeeOptions.d.ts.map +1 -1
- package/dist/widget/components/NativeGasOption.d.ts.map +1 -1
- package/dist/widget/components/Pay.d.ts.map +1 -1
- package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
- package/dist/widget/components/QRCodeDeposit.d.ts +5 -0
- package/dist/widget/components/QRCodeDeposit.d.ts.map +1 -1
- package/dist/widget/components/QRCodeWalletSelect.d.ts +13 -0
- package/dist/widget/components/QRCodeWalletSelect.d.ts.map +1 -0
- package/dist/widget/components/QrCode.d.ts.map +1 -1
- package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
- package/dist/widget/components/Receipt.d.ts.map +1 -1
- package/dist/widget/components/ScreenHeader.d.ts +1 -1
- package/dist/widget/components/ScreenHeader.d.ts.map +1 -1
- package/dist/widget/components/Toast.d.ts.map +1 -1
- package/dist/widget/components/TokenImage.d.ts.map +1 -1
- package/dist/widget/css/compiled.css +1 -1
- package/dist/widget/hooks/useCheckout.d.ts +15 -1
- 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/useIsConnectedWalletSmartContract.d.ts +7 -0
- package/dist/widget/hooks/useIsConnectedWalletSmartContract.d.ts.map +1 -0
- package/dist/widget/hooks/useIsSequenceWallet.d.ts +6 -0
- package/dist/widget/hooks/useIsSequenceWallet.d.ts.map +1 -0
- package/dist/widget/hooks/useQuote.d.ts +5 -8
- package/dist/widget/hooks/useQuote.d.ts.map +1 -1
- package/dist/widget/hooks/useRecentTokens.d.ts.map +1 -1
- package/dist/widget/hooks/useSelectedFeeOption.d.ts +30 -0
- package/dist/widget/hooks/useSelectedFeeOption.d.ts.map +1 -0
- package/dist/widget/hooks/useSendForm.d.ts +6 -15
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
- package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
- package/dist/widget/index.js +1 -1
- package/dist/widget/providers/TrailsProvider.d.ts +23 -12
- package/dist/widget/providers/TrailsProvider.d.ts.map +1 -1
- package/dist/widget/widget.d.ts +11 -0
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/analytics.ts +53 -21
- package/src/cctp.ts +0 -1016
- package/src/chains.ts +93 -39
- package/src/config.ts +24 -6
- package/src/constants.ts +1 -4
- package/src/contractUtils.ts +6 -6
- package/src/estimate.ts +3 -6
- package/src/fees.ts +5 -10
- package/src/gasless.ts +45 -0
- package/src/index.ts +7 -6
- package/src/indexerClient.ts +2 -2
- package/src/intents.ts +52 -206
- package/src/mutations.ts +3 -2
- package/src/paymasterSend.ts +2 -5
- package/src/prepareSend.ts +9 -12
- package/src/sendUserOp.ts +3 -64
- package/src/tokenBalances.ts +2 -1
- package/src/tokens.ts +62 -133
- package/src/trailsClient.ts +1 -1
- package/src/transactionIntent/deposits/depositOrchestrator.ts +14 -15
- package/src/transactionIntent/deposits/gaslessDeposit.ts +70 -100
- package/src/transactionIntent/deposits/standardDeposit.ts +22 -28
- package/src/transactionIntent/execution/transactionState.ts +2 -2
- package/src/transactionIntent/handlers/crossChain.ts +165 -385
- package/src/transactionIntent/handlers/index.ts +0 -1
- package/src/transactionIntent/handlers/sameChainSameToken.ts +228 -94
- package/src/transactionIntent/quote/normalizeQuote.ts +4 -6
- package/src/transactionIntent/quote/quoteHelpers.ts +35 -3
- package/src/transactionIntent/types.ts +6 -27
- package/src/transactionIntent/utils/index.ts +0 -1
- package/src/transactions.ts +6 -203
- package/src/umd.tsx +1 -3
- package/src/utils.ts +28 -8
- package/src/walletUtils.ts +42 -0
- package/src/wallets.ts +361 -203
- package/src/widget/compiled.css +1 -1
- package/src/widget/components/AccountIntentTransactionHistory.tsx +73 -4
- package/src/widget/components/AccountSettings.tsx +17 -17
- package/src/widget/components/ChainList.tsx +3 -3
- package/src/widget/components/ClassicSwap.tsx +19 -10
- package/src/widget/components/ConfigDisplay.tsx +1 -1
- package/src/widget/components/FeeOption.tsx +63 -20
- package/src/widget/components/FeeOptions.tsx +54 -123
- package/src/widget/components/NativeGasOption.tsx +3 -1
- package/src/widget/components/Pay.tsx +18 -11
- package/src/widget/components/PoolDeposit.tsx +23 -10
- package/src/widget/components/QRCodeDeposit.tsx +50 -30
- package/src/widget/components/QRCodeWalletSelect.tsx +77 -0
- package/src/widget/components/QrCode.tsx +188 -233
- package/src/widget/components/QuoteDetails.tsx +48 -2
- package/src/widget/components/Receipt.tsx +5 -2
- package/src/widget/components/ScreenHeader.tsx +10 -8
- package/src/widget/components/Toast.tsx +10 -0
- package/src/widget/components/TokenImage.tsx +56 -13
- package/src/widget/hooks/useCheckout.ts +71 -0
- package/src/widget/hooks/useCurrentScreen.tsx +1 -0
- package/src/widget/hooks/useDebugScreens.ts +5 -0
- package/src/widget/hooks/useIntentTransactionHistory.ts +788 -418
- package/src/widget/hooks/useIsConnectedWalletSmartContract.ts +43 -0
- package/src/widget/hooks/useIsSequenceWallet.ts +17 -0
- package/src/widget/hooks/useQuote.ts +16 -17
- package/src/widget/hooks/useRecentTokens.ts +2 -1
- package/src/widget/hooks/useSelectedFeeOption.tsx +257 -0
- package/src/widget/hooks/useSendForm.ts +172 -47
- package/src/widget/hooks/useTokenList.ts +15 -2
- package/src/widget/providers/TrailsProvider.tsx +53 -25
- package/src/widget/widget.tsx +119 -48
- package/dist/cctpqueue.d.ts +0 -18
- package/dist/cctpqueue.d.ts.map +0 -1
- package/dist/preconditions.d.ts +0 -12
- package/dist/preconditions.d.ts.map +0 -1
- package/dist/transactionIntent/handlers/sameChainDifferentToken.d.ts +0 -62
- package/dist/transactionIntent/handlers/sameChainDifferentToken.d.ts.map +0 -1
- package/dist/transactionIntent/utils/lifiHelpers.d.ts +0 -10
- package/dist/transactionIntent/utils/lifiHelpers.d.ts.map +0 -1
- package/dist/widget/hooks/useSelectedFeeToken.d.ts +0 -33
- package/dist/widget/hooks/useSelectedFeeToken.d.ts.map +0 -1
- package/src/cctpqueue.ts +0 -69
- package/src/preconditions.ts +0 -47
- package/src/transactionIntent/handlers/sameChainDifferentToken.ts +0 -323
- package/src/transactionIntent/utils/lifiHelpers.ts +0 -68
- package/src/widget/hooks/useSelectedFeeToken.tsx +0 -288
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import type { Account, Chain, WalletClient } from "viem"
|
|
2
|
-
import {
|
|
3
|
-
createPublicClient,
|
|
4
|
-
ethAddress,
|
|
5
|
-
http,
|
|
6
|
-
maxUint256,
|
|
7
|
-
zeroAddress,
|
|
8
|
-
} from "viem"
|
|
2
|
+
import { maxUint256 } from "viem"
|
|
9
3
|
import type {
|
|
10
4
|
TrailsApi,
|
|
11
5
|
GasFeeOptions,
|
|
@@ -13,10 +7,10 @@ import type {
|
|
|
13
7
|
DepositSignature,
|
|
14
8
|
ExecuteIntentResponse,
|
|
15
9
|
} from "@0xsequence/trails-api"
|
|
16
|
-
import type { SelectedFeeToken } from "../types.js"
|
|
17
10
|
import type { CheckoutOnHandlers } from "../../widget/hooks/useCheckout.js"
|
|
18
11
|
import type { TransactionState } from "../../transactions.js"
|
|
19
12
|
import { logger } from "../../logger.js"
|
|
13
|
+
import { isNativeToken } from "../../utils.js"
|
|
20
14
|
import { attemptSwitchChain } from "../../chainSwitch.js"
|
|
21
15
|
import { getTransactionStateFromReceipt } from "../execution/transactionState.js"
|
|
22
16
|
import {
|
|
@@ -30,8 +24,10 @@ import {
|
|
|
30
24
|
getUserNonce,
|
|
31
25
|
signIntent,
|
|
32
26
|
getPermitSignature,
|
|
27
|
+
validateGaslessSignature,
|
|
33
28
|
} from "../../gasless.js"
|
|
34
29
|
import { getIsUserRejectionError } from "../../error.js"
|
|
30
|
+
import { getPublicRpcClient } from "../../chains.js"
|
|
35
31
|
|
|
36
32
|
export async function attemptGaslessDeposit({
|
|
37
33
|
paymasterUrl,
|
|
@@ -44,7 +40,7 @@ export async function attemptGaslessDeposit({
|
|
|
44
40
|
account,
|
|
45
41
|
trailsClient,
|
|
46
42
|
feeOptions,
|
|
47
|
-
|
|
43
|
+
selectedFeeOption: selectedFeeOptionParam,
|
|
48
44
|
checkoutOnHandlers,
|
|
49
45
|
intentId,
|
|
50
46
|
onTransactionStateChange,
|
|
@@ -61,7 +57,7 @@ export async function attemptGaslessDeposit({
|
|
|
61
57
|
account: Account
|
|
62
58
|
trailsClient: TrailsApi
|
|
63
59
|
feeOptions?: GasFeeOptions
|
|
64
|
-
|
|
60
|
+
selectedFeeOption?: FeeOption | null
|
|
65
61
|
abortSignal?: AbortSignal
|
|
66
62
|
checkoutOnHandlers?: Partial<CheckoutOnHandlers>
|
|
67
63
|
intentId?: string
|
|
@@ -84,16 +80,13 @@ export async function attemptGaslessDeposit({
|
|
|
84
80
|
depositRecipient,
|
|
85
81
|
hasFeeOptions: !!feeOptions,
|
|
86
82
|
feeOptionsLength: feeOptions?.feeOptions?.length,
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
selectedFeeOption: selectedFeeOptionParam,
|
|
84
|
+
hasSelectedFeeOption: !!selectedFeeOptionParam,
|
|
89
85
|
paymasterUrl,
|
|
90
86
|
},
|
|
91
87
|
)
|
|
92
88
|
|
|
93
|
-
const publicClient =
|
|
94
|
-
chain,
|
|
95
|
-
transport: http(),
|
|
96
|
-
})
|
|
89
|
+
const publicClient = getPublicRpcClient(chain)
|
|
97
90
|
|
|
98
91
|
logger.console.log("[trails-sdk] [GASLESS-FLOW] Intent entrypoint check:", {
|
|
99
92
|
chainId: chain.id,
|
|
@@ -101,9 +94,9 @@ export async function attemptGaslessDeposit({
|
|
|
101
94
|
intentEntrypoint: TRAILS_INTENT_ENTRYPOINT_ADDRESS,
|
|
102
95
|
})
|
|
103
96
|
|
|
104
|
-
// NEW FLOW: Use Intent Entrypoint API with
|
|
97
|
+
// NEW FLOW: Use Intent Entrypoint API with EIP-2162 permit signature support
|
|
105
98
|
logger.console.log(
|
|
106
|
-
"[trails-sdk] Using Intent Entrypoint API flow with
|
|
99
|
+
"[trails-sdk] Using Intent Entrypoint API flow with EIP-2162 permit signature support for gasless deposit",
|
|
107
100
|
)
|
|
108
101
|
|
|
109
102
|
// Switch to correct chain before requesting signatures
|
|
@@ -226,55 +219,55 @@ export async function attemptGaslessDeposit({
|
|
|
226
219
|
}
|
|
227
220
|
|
|
228
221
|
const deadline = Math.floor(Date.now() / 1000) + 3600 // 1 hour from now
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
222
|
+
const feeOptionsList = feeOptions?.feeOptions ?? []
|
|
223
|
+
const hasFeeOptions = feeOptionsList.length > 0
|
|
224
|
+
const userExplicitlySelectedNativeFee = selectedFeeOptionParam === null
|
|
232
225
|
|
|
233
226
|
// 1. Check if we need approval - check if we have enough allowance for this transaction (deposit + fee if same token)
|
|
234
227
|
let requiredAmount = BigInt(depositTokenAmount)
|
|
235
228
|
|
|
236
|
-
//
|
|
237
|
-
let selectedFeeOption: FeeOption | null =
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
229
|
+
// Start with the caller's selection (unless they explicitly chose native gas)
|
|
230
|
+
let selectedFeeOption: FeeOption | null | undefined =
|
|
231
|
+
userExplicitlySelectedNativeFee
|
|
232
|
+
? null
|
|
233
|
+
: (selectedFeeOptionParam ?? undefined)
|
|
234
|
+
|
|
235
|
+
if (selectedFeeOption && hasFeeOptions) {
|
|
236
|
+
const matchedOption =
|
|
237
|
+
feeOptionsList.find(
|
|
242
238
|
(opt) =>
|
|
243
239
|
opt.tokenAddress?.toLowerCase() ===
|
|
244
|
-
|
|
240
|
+
selectedFeeOption?.tokenAddress?.toLowerCase(),
|
|
245
241
|
) || null
|
|
246
|
-
logger.console.log(
|
|
247
|
-
"[trails-sdk] Matched selectedFeeToken to latest fee option:",
|
|
248
|
-
{
|
|
249
|
-
selectedFeeToken,
|
|
250
|
-
matchedOption: selectedFeeOption,
|
|
251
|
-
},
|
|
252
|
-
)
|
|
253
|
-
}
|
|
254
242
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
243
|
+
if (matchedOption) {
|
|
244
|
+
selectedFeeOption = matchedOption
|
|
245
|
+
logger.console.log(
|
|
246
|
+
"[trails-sdk] Matched selectedFeeOption to latest fee option:",
|
|
247
|
+
{
|
|
248
|
+
selectedFeeOption,
|
|
249
|
+
matchedOption,
|
|
250
|
+
},
|
|
251
|
+
)
|
|
252
|
+
}
|
|
262
253
|
}
|
|
263
254
|
|
|
255
|
+
const depositTokenAddressLower = depositTokenAddress.toLowerCase()
|
|
256
|
+
|
|
264
257
|
// Only include fee in required amount if the fee token is the same as the deposit token
|
|
265
258
|
if (selectedFeeOption?.amount && selectedFeeOption?.tokenAddress) {
|
|
266
|
-
const
|
|
259
|
+
const feeOptionIsSameAsDepositToken =
|
|
267
260
|
selectedFeeOption.tokenAddress.toLowerCase() ===
|
|
268
|
-
|
|
261
|
+
depositTokenAddressLower
|
|
269
262
|
|
|
270
|
-
if (
|
|
263
|
+
if (feeOptionIsSameAsDepositToken) {
|
|
271
264
|
requiredAmount = requiredAmount + BigInt(selectedFeeOption.amount)
|
|
272
265
|
logger.console.log(
|
|
273
266
|
"[trails-sdk] Fee token matches deposit token, including fee in required approval amount:",
|
|
274
267
|
{
|
|
275
268
|
depositAmount: depositTokenAmount,
|
|
276
269
|
feeAmount: selectedFeeOption.amount,
|
|
277
|
-
|
|
270
|
+
feeOptionAddress: selectedFeeOption.tokenAddress,
|
|
278
271
|
depositTokenAddress,
|
|
279
272
|
totalRequired: requiredAmount.toString(),
|
|
280
273
|
},
|
|
@@ -286,7 +279,7 @@ export async function attemptGaslessDeposit({
|
|
|
286
279
|
depositAmount: depositTokenAmount,
|
|
287
280
|
depositTokenAddress,
|
|
288
281
|
feeAmount: selectedFeeOption.amount,
|
|
289
|
-
|
|
282
|
+
feeOptionAddress: selectedFeeOption.tokenAddress,
|
|
290
283
|
depositTokenRequired: requiredAmount.toString(),
|
|
291
284
|
},
|
|
292
285
|
)
|
|
@@ -301,6 +294,9 @@ export async function attemptGaslessDeposit({
|
|
|
301
294
|
amount: requiredAmount, // Check if we have enough allowance for this specific transaction
|
|
302
295
|
})
|
|
303
296
|
|
|
297
|
+
const depositTokenIsNative = isNativeToken(depositTokenAddressLower)
|
|
298
|
+
const shouldAttachPermit = needsApproval && !depositTokenIsNative
|
|
299
|
+
|
|
304
300
|
logger.console.log(
|
|
305
301
|
"[trails-sdk] [GASLESS-FLOW] Checking permit requirements",
|
|
306
302
|
{
|
|
@@ -320,7 +316,7 @@ export async function attemptGaslessDeposit({
|
|
|
320
316
|
let permitSignature: string | undefined
|
|
321
317
|
let permitDeadline: number | undefined
|
|
322
318
|
|
|
323
|
-
if (
|
|
319
|
+
if (shouldAttachPermit) {
|
|
324
320
|
logger.console.log(
|
|
325
321
|
"[trails-sdk] Getting permit signature for deposit token infinite approval",
|
|
326
322
|
)
|
|
@@ -385,13 +381,12 @@ export async function attemptGaslessDeposit({
|
|
|
385
381
|
|
|
386
382
|
// 4. Get intent signature
|
|
387
383
|
logger.console.log("[trails-sdk] Requesting intent signature via EIP-712")
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
feeOptions?.feeCollectorAddress) as `0x${string}` | undefined
|
|
384
|
+
const feeCollectorAddress = feeOptions?.feeCollectorAddress as
|
|
385
|
+
| `0x${string}`
|
|
386
|
+
| undefined
|
|
392
387
|
|
|
393
388
|
// Validate that we have a valid fee collector address
|
|
394
|
-
if (!feeCollectorAddress || feeCollectorAddress
|
|
389
|
+
if (!feeCollectorAddress || isNativeToken(feeCollectorAddress)) {
|
|
395
390
|
throw new Error(
|
|
396
391
|
"[trails-sdk] Fee collector address not provided by API. Cannot proceed with gasless deposit. " +
|
|
397
392
|
"Please ensure the API is returning feeCollectorAddress in the gasFeeOptions response.",
|
|
@@ -428,6 +423,9 @@ export async function attemptGaslessDeposit({
|
|
|
428
423
|
intentSignature = result.signature
|
|
429
424
|
logger.console.log("[trails-sdk] Intent signature received")
|
|
430
425
|
|
|
426
|
+
// Validate signature length for gasless flow
|
|
427
|
+
validateGaslessSignature(intentSignature)
|
|
428
|
+
|
|
431
429
|
// Trigger signature confirmed callback after successful signing
|
|
432
430
|
if (checkoutOnHandlers?.triggerCheckoutSignatureConfirmed) {
|
|
433
431
|
checkoutOnHandlers.triggerCheckoutSignatureConfirmed()
|
|
@@ -460,8 +458,14 @@ export async function attemptGaslessDeposit({
|
|
|
460
458
|
)
|
|
461
459
|
}
|
|
462
460
|
|
|
463
|
-
// Validate that we have a selected fee option
|
|
461
|
+
// Validate that we have a selected fee option for gasless deposit signature
|
|
464
462
|
if (!selectedFeeOption) {
|
|
463
|
+
logger.console.error(
|
|
464
|
+
"[trails-sdk] Missing selected fee option for gasless deposit signature",
|
|
465
|
+
{
|
|
466
|
+
selectedFeeOption,
|
|
467
|
+
},
|
|
468
|
+
)
|
|
465
469
|
throw new Error(
|
|
466
470
|
"[trails-sdk] selectedFeeOption is required for gasless deposits",
|
|
467
471
|
)
|
|
@@ -517,7 +521,7 @@ export async function attemptGaslessDeposit({
|
|
|
517
521
|
}
|
|
518
522
|
} catch (error) {
|
|
519
523
|
logger.console.error(
|
|
520
|
-
"[trails-sdk] Error in Intent Entrypoint gasless deposit with
|
|
524
|
+
"[trails-sdk] Error in Intent Entrypoint gasless deposit with EIP-2162 permit signature",
|
|
521
525
|
error,
|
|
522
526
|
)
|
|
523
527
|
throw error
|
|
@@ -527,7 +531,7 @@ export async function attemptGaslessDeposit({
|
|
|
527
531
|
export function getDoGasless(
|
|
528
532
|
originTokenAddress: string,
|
|
529
533
|
feeOptions?: GasFeeOptions,
|
|
530
|
-
|
|
534
|
+
selectedFeeOption?: FeeOption | null,
|
|
531
535
|
walletId?: string,
|
|
532
536
|
): boolean {
|
|
533
537
|
// Don't use gasless flow for sequence-waas wallet
|
|
@@ -540,66 +544,33 @@ export function getDoGasless(
|
|
|
540
544
|
|
|
541
545
|
const hasFeeOptions = Boolean(feeOptions && feeOptions.feeOptions?.length > 0)
|
|
542
546
|
|
|
543
|
-
// Important: The UI passes
|
|
547
|
+
// Important: The UI passes selectedFeeOption in these states:
|
|
544
548
|
// - null: User explicitly chose "Pay with native gas"
|
|
545
549
|
// - {object}: User selected a fee token OR it was auto-selected
|
|
546
550
|
// - undefined: Should not happen (initial state auto-selects if options exist)
|
|
547
551
|
|
|
548
|
-
// If
|
|
549
|
-
if (
|
|
552
|
+
// If selectedFeeOption is null, user explicitly chose native gas
|
|
553
|
+
if (selectedFeeOption === null) {
|
|
550
554
|
logger.console.log(
|
|
551
555
|
"[trails-sdk] [GASLESS-FLOW] [FEE-SELECT] getDoGasless: User explicitly selected native gas (null)",
|
|
552
556
|
)
|
|
553
557
|
return false
|
|
554
558
|
}
|
|
555
559
|
|
|
556
|
-
// If
|
|
557
|
-
if (!
|
|
560
|
+
// If selectedFeeOption is undefined and no fee options, can't do gasless
|
|
561
|
+
if (!selectedFeeOption && !hasFeeOptions) {
|
|
558
562
|
logger.console.log(
|
|
559
563
|
"[trails-sdk] [GASLESS-FLOW] [FEE-SELECT] getDoGasless: No fee token selected and no fee options available",
|
|
560
564
|
)
|
|
561
565
|
return false
|
|
562
566
|
}
|
|
563
567
|
|
|
564
|
-
// If selectedFeeToken is undefined but fee options exist, use first ERC20 option
|
|
565
|
-
let effectiveFeeToken = selectedFeeToken
|
|
566
|
-
if (!effectiveFeeToken && hasFeeOptions && feeOptions) {
|
|
567
|
-
const firstFeeOption = feeOptions.feeOptions[0]
|
|
568
|
-
|
|
569
|
-
// Check if first option is native gas
|
|
570
|
-
const isFirstOptionNative =
|
|
571
|
-
firstFeeOption?.tokenAddress === zeroAddress ||
|
|
572
|
-
firstFeeOption?.tokenAddress?.toLowerCase() === zeroAddress ||
|
|
573
|
-
firstFeeOption?.tokenAddress === ethAddress ||
|
|
574
|
-
firstFeeOption?.tokenAddress?.toLowerCase() === ethAddress.toLowerCase()
|
|
575
|
-
|
|
576
|
-
if (!isFirstOptionNative && firstFeeOption?.tokenAddress) {
|
|
577
|
-
// First fee option is ERC20, use it
|
|
578
|
-
effectiveFeeToken = firstFeeOption
|
|
579
|
-
logger.console.log(
|
|
580
|
-
"[trails-sdk] [GASLESS-FLOW] [FEE-SELECT] getDoGasless: No fee token selected, using first ERC20 fee option",
|
|
581
|
-
{
|
|
582
|
-
feeOption: effectiveFeeToken,
|
|
583
|
-
},
|
|
584
|
-
)
|
|
585
|
-
} else {
|
|
586
|
-
logger.console.log(
|
|
587
|
-
"[trails-sdk] [GASLESS-FLOW] [FEE-SELECT] getDoGasless: First fee option is native gas, skipping gasless",
|
|
588
|
-
)
|
|
589
|
-
return false
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
|
|
593
568
|
// Check if the effective fee token is native gas
|
|
594
569
|
const isNativeGasFee =
|
|
595
|
-
!
|
|
596
|
-
effectiveFeeToken.tokenAddress === zeroAddress ||
|
|
597
|
-
effectiveFeeToken.tokenAddress?.toLowerCase() === zeroAddress ||
|
|
598
|
-
effectiveFeeToken.tokenAddress === ethAddress ||
|
|
599
|
-
effectiveFeeToken.tokenAddress?.toLowerCase() === ethAddress.toLowerCase()
|
|
570
|
+
!selectedFeeOption || isNativeToken(selectedFeeOption.tokenAddress)
|
|
600
571
|
|
|
601
572
|
// Don't use gasless if origin token is native (sending ETH)
|
|
602
|
-
if (originTokenAddress
|
|
573
|
+
if (isNativeToken(originTokenAddress)) {
|
|
603
574
|
logger.console.log(
|
|
604
575
|
"[trails-sdk] [GASLESS-FLOW] getDoGasless: Origin token is native, skipping gasless",
|
|
605
576
|
)
|
|
@@ -611,7 +582,7 @@ export function getDoGasless(
|
|
|
611
582
|
logger.console.log(
|
|
612
583
|
"[trails-sdk] [GASLESS-FLOW] [FEE-SELECT] getDoGasless: Fee token is native gas, skipping gasless",
|
|
613
584
|
{
|
|
614
|
-
|
|
585
|
+
selectedFeeOption,
|
|
615
586
|
},
|
|
616
587
|
)
|
|
617
588
|
return false
|
|
@@ -623,8 +594,7 @@ export function getDoGasless(
|
|
|
623
594
|
{
|
|
624
595
|
originTokenAddress,
|
|
625
596
|
hasFeeOptions,
|
|
626
|
-
|
|
627
|
-
effectiveFeeToken,
|
|
597
|
+
selectedFeeOption,
|
|
628
598
|
feeOptionsCount: feeOptions?.feeOptions?.length || 0,
|
|
629
599
|
},
|
|
630
600
|
)
|
|
@@ -9,7 +9,6 @@ import { parseUnits, encodeFunctionData } from "viem"
|
|
|
9
9
|
import type { TransactionState } from "../../transactions.js"
|
|
10
10
|
import type { CheckoutOnHandlers } from "../../widget/hooks/useCheckout.js"
|
|
11
11
|
import { logger } from "../../logger.js"
|
|
12
|
-
import { getNeedsLifiNativeFee } from "../utils/lifiHelpers.js"
|
|
13
12
|
import {
|
|
14
13
|
buildCrossChainDepositParams,
|
|
15
14
|
buildSameChainSameTokenTransactionParams,
|
|
@@ -18,16 +17,15 @@ import {
|
|
|
18
17
|
import { getIsCustomCalldata } from "../../contractUtils.js"
|
|
19
18
|
import { estimateGasLimit } from "../../estimate.js"
|
|
20
19
|
import { attemptSwitchChain } from "../../chainSwitch.js"
|
|
21
|
-
import { requestWithTimeout } from "../../utils.js"
|
|
20
|
+
import { requestWithTimeout, isNativeToken } from "../../utils.js"
|
|
22
21
|
import { updatePersistentToast } from "../../toast.js"
|
|
23
22
|
import { getChainInfo } from "../../chains.js"
|
|
24
23
|
import { trackTransactionConfirmed } from "../../analytics.js"
|
|
25
|
-
import { zeroAddress } from "viem"
|
|
26
24
|
import { getIsUserRejectionError } from "../../error.js"
|
|
27
25
|
|
|
28
26
|
export async function attemptStandardDeposit({
|
|
29
27
|
originTokenAddress,
|
|
30
|
-
|
|
28
|
+
depositAmount,
|
|
31
29
|
onOriginSend,
|
|
32
30
|
publicClient,
|
|
33
31
|
walletClient,
|
|
@@ -36,11 +34,6 @@ export async function attemptStandardDeposit({
|
|
|
36
34
|
account,
|
|
37
35
|
fee,
|
|
38
36
|
dryMode,
|
|
39
|
-
sourceTokenPriceUsd,
|
|
40
|
-
destinationTokenPriceUsd,
|
|
41
|
-
swapAmount,
|
|
42
|
-
destinationTokenDecimals,
|
|
43
|
-
sourceTokenDecimals,
|
|
44
37
|
originIntentAddress,
|
|
45
38
|
onTransactionStateChange,
|
|
46
39
|
transactionStates,
|
|
@@ -53,7 +46,7 @@ export async function attemptStandardDeposit({
|
|
|
53
46
|
destinationCalldata,
|
|
54
47
|
}: {
|
|
55
48
|
originTokenAddress: string
|
|
56
|
-
|
|
49
|
+
depositAmount: string
|
|
57
50
|
onOriginSend?: () => void
|
|
58
51
|
publicClient: PublicClient
|
|
59
52
|
walletClient: WalletClient
|
|
@@ -80,20 +73,8 @@ export async function attemptStandardDeposit({
|
|
|
80
73
|
}): Promise<TransactionReceipt | null> {
|
|
81
74
|
console.log("IN ATTEMPT STANDARD DEPOSIT!")
|
|
82
75
|
let depositUserTxnReceipt: TransactionReceipt | null = null
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (usingLIfi) {
|
|
87
|
-
needsNativeFee = getNeedsLifiNativeFee({
|
|
88
|
-
originTokenAddress,
|
|
89
|
-
destinationTokenAmount: swapAmount,
|
|
90
|
-
destinationTokenDecimals,
|
|
91
|
-
sourceTokenDecimals,
|
|
92
|
-
sourceTokenPriceUsd: sourceTokenPriceUsd ?? null,
|
|
93
|
-
destinationTokenPriceUsd: destinationTokenPriceUsd ?? null,
|
|
94
|
-
depositAmount: firstPreconditionMin,
|
|
95
|
-
})
|
|
96
|
-
}
|
|
76
|
+
const needsNativeFee = false
|
|
77
|
+
|
|
97
78
|
let nativeFee = parseUnits("0.00005", 18).toString()
|
|
98
79
|
if (originChainId === 137) {
|
|
99
80
|
nativeFee = parseUnits("1.5", 18).toString()
|
|
@@ -110,14 +91,14 @@ export async function attemptStandardDeposit({
|
|
|
110
91
|
recipient: recipient || originIntentAddress,
|
|
111
92
|
effectiveOriginTokenAddress: originTokenAddress,
|
|
112
93
|
destinationCalldata,
|
|
113
|
-
swapAmount:
|
|
94
|
+
swapAmount: depositAmount,
|
|
114
95
|
effectiveOriginChainId: originChainId,
|
|
115
96
|
effectiveOriginChain: chain,
|
|
116
97
|
})
|
|
117
98
|
: buildCrossChainDepositParams({
|
|
118
99
|
originTokenAddress,
|
|
119
100
|
originIntentAddress,
|
|
120
|
-
depositAmount:
|
|
101
|
+
depositAmount: depositAmount,
|
|
121
102
|
fee,
|
|
122
103
|
originChainId,
|
|
123
104
|
chain,
|
|
@@ -129,7 +110,7 @@ export async function attemptStandardDeposit({
|
|
|
129
110
|
|
|
130
111
|
if (
|
|
131
112
|
isSameChainSameToken &&
|
|
132
|
-
originTokenAddress
|
|
113
|
+
!isNativeToken(originTokenAddress) &&
|
|
133
114
|
hasCustomCalldata &&
|
|
134
115
|
!dryMode &&
|
|
135
116
|
recipient
|
|
@@ -165,7 +146,7 @@ export async function attemptStandardDeposit({
|
|
|
165
146
|
args: [account.address, recipient as `0x${string}`],
|
|
166
147
|
})) as bigint
|
|
167
148
|
|
|
168
|
-
const requiredAmount = BigInt(
|
|
149
|
+
const requiredAmount = BigInt(depositAmount)
|
|
169
150
|
|
|
170
151
|
if (currentAllowance < requiredAmount) {
|
|
171
152
|
logger.console.log(
|
|
@@ -178,6 +159,11 @@ export async function attemptStandardDeposit({
|
|
|
178
159
|
args: [recipient as `0x${string}`, requiredAmount],
|
|
179
160
|
}) as `0x${string}`
|
|
180
161
|
|
|
162
|
+
// Trigger approval request callback before sending transaction
|
|
163
|
+
if (checkoutOnHandlers?.triggerCheckoutApprovalRequest) {
|
|
164
|
+
checkoutOnHandlers.triggerCheckoutApprovalRequest()
|
|
165
|
+
}
|
|
166
|
+
|
|
181
167
|
let approveHash: `0x${string}`
|
|
182
168
|
let approveReceipt: TransactionReceipt
|
|
183
169
|
try {
|
|
@@ -196,12 +182,20 @@ export async function attemptStandardDeposit({
|
|
|
196
182
|
},
|
|
197
183
|
)
|
|
198
184
|
|
|
185
|
+
// Trigger approval confirmed callback after hash is received
|
|
186
|
+
if (checkoutOnHandlers?.triggerCheckoutApprovalConfirmed) {
|
|
187
|
+
checkoutOnHandlers.triggerCheckoutApprovalConfirmed(approveHash)
|
|
188
|
+
}
|
|
189
|
+
|
|
199
190
|
approveReceipt = await publicClient.waitForTransactionReceipt({
|
|
200
191
|
hash: approveHash,
|
|
201
192
|
})
|
|
202
193
|
} catch (error) {
|
|
203
194
|
// Check if this is a user rejection error
|
|
204
195
|
if (getIsUserRejectionError(error)) {
|
|
196
|
+
if (checkoutOnHandlers?.triggerCheckoutApprovalRejected) {
|
|
197
|
+
checkoutOnHandlers.triggerCheckoutApprovalRejected(error)
|
|
198
|
+
}
|
|
205
199
|
if (checkoutOnHandlers?.triggerCheckoutSignatureRejected) {
|
|
206
200
|
checkoutOnHandlers.triggerCheckoutSignatureRejected(error)
|
|
207
201
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TransactionReceipt } from "viem"
|
|
2
|
-
import type {
|
|
2
|
+
import type { IntentTransaction } from "@0xsequence/trails-api"
|
|
3
3
|
import type {
|
|
4
4
|
TransactionState,
|
|
5
5
|
TransactionStateStatus,
|
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
import { getExplorerUrl } from "../../explorer.js"
|
|
8
8
|
|
|
9
9
|
export function getTransactionStateFromReceipt(
|
|
10
|
-
receipt: TransactionReceipt |
|
|
10
|
+
receipt: TransactionReceipt | IntentTransaction,
|
|
11
11
|
chainId: number,
|
|
12
12
|
label: string = "Transaction",
|
|
13
13
|
): TransactionState {
|