0xtrails 0.2.5 → 0.3.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/aave.d.ts +2 -0
- package/dist/aave.d.ts.map +1 -1
- package/dist/abortController.d.ts +8 -0
- package/dist/abortController.d.ts.map +1 -0
- package/dist/{ccip-CXlshvBY.js → ccip-BMB3uDZt.js} +1 -1
- package/dist/config.d.ts +0 -5
- package/dist/config.d.ts.map +1 -1
- package/dist/constants.d.ts +4 -4
- package/dist/constants.d.ts.map +1 -1
- package/dist/error.d.ts +4 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/fees.d.ts +19 -0
- package/dist/fees.d.ts.map +1 -0
- package/dist/{index-_QuyGrjU.js → index-QXPUrZVv.js} +48719 -50852
- package/dist/index.d.ts +9 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +811 -784
- package/dist/intentReceiptMonitor.d.ts +24 -0
- package/dist/intentReceiptMonitor.d.ts.map +1 -0
- package/dist/intentReceiptPoller.d.ts +69 -0
- package/dist/intentReceiptPoller.d.ts.map +1 -0
- package/dist/intents.d.ts +15 -11
- package/dist/intents.d.ts.map +1 -1
- package/dist/morpho.d.ts +6 -5
- package/dist/morpho.d.ts.map +1 -1
- package/dist/mutations.d.ts +16 -0
- package/dist/mutations.d.ts.map +1 -0
- package/dist/preconditions.d.ts +5 -4
- package/dist/preconditions.d.ts.map +1 -1
- package/dist/prepareSend.d.ts +7 -258
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/prices.d.ts +9 -6
- package/dist/prices.d.ts.map +1 -1
- package/dist/sequenceWallet.d.ts +3 -16
- package/dist/sequenceWallet.d.ts.map +1 -1
- package/dist/tokenBalances.d.ts +17 -13
- package/dist/tokenBalances.d.ts.map +1 -1
- package/dist/trails.d.ts +24 -40
- package/dist/trails.d.ts.map +1 -1
- package/dist/transactionIntent/constants.d.ts +7 -0
- package/dist/transactionIntent/constants.d.ts.map +1 -0
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts +44 -0
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts.map +1 -0
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts +30 -0
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -0
- package/dist/transactionIntent/deposits/index.d.ts +4 -0
- package/dist/transactionIntent/deposits/index.d.ts.map +1 -0
- package/dist/transactionIntent/deposits/standardDeposit.d.ts +30 -0
- package/dist/transactionIntent/deposits/standardDeposit.d.ts.map +1 -0
- package/dist/transactionIntent/execution/index.d.ts +2 -0
- package/dist/transactionIntent/execution/index.d.ts.map +1 -0
- package/dist/transactionIntent/execution/transactionState.d.ts +5 -0
- package/dist/transactionIntent/execution/transactionState.d.ts.map +1 -0
- package/dist/transactionIntent/handlers/crossChain.d.ts +82 -0
- package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -0
- package/dist/transactionIntent/handlers/index.d.ts +4 -0
- package/dist/transactionIntent/handlers/index.d.ts.map +1 -0
- package/dist/transactionIntent/handlers/sameChainDifferentToken.d.ts +62 -0
- package/dist/transactionIntent/handlers/sameChainDifferentToken.d.ts.map +1 -0
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts +72 -0
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -0
- package/dist/transactionIntent/index.d.ts +9 -0
- package/dist/transactionIntent/index.d.ts.map +1 -0
- package/dist/transactionIntent/quote/feeExtractors.d.ts +17 -0
- package/dist/transactionIntent/quote/feeExtractors.d.ts.map +1 -0
- package/dist/transactionIntent/quote/index.d.ts +4 -0
- package/dist/transactionIntent/quote/index.d.ts.map +1 -0
- package/dist/transactionIntent/quote/normalizeQuote.d.ts +34 -0
- package/dist/transactionIntent/quote/normalizeQuote.d.ts.map +1 -0
- package/dist/transactionIntent/quote/quoteHelpers.d.ts +5 -0
- package/dist/transactionIntent/quote/quoteHelpers.d.ts.map +1 -0
- package/dist/transactionIntent/types.d.ts +131 -0
- package/dist/transactionIntent/types.d.ts.map +1 -0
- package/dist/transactionIntent/utils/balanceChecker.d.ts +18 -0
- package/dist/transactionIntent/utils/balanceChecker.d.ts.map +1 -0
- package/dist/transactionIntent/utils/index.d.ts +4 -0
- package/dist/transactionIntent/utils/index.d.ts.map +1 -0
- package/dist/transactionIntent/utils/lifiHelpers.d.ts +10 -0
- package/dist/transactionIntent/utils/lifiHelpers.d.ts.map +1 -0
- package/dist/transactionIntent/utils/testnetHelpers.d.ts +3 -0
- package/dist/transactionIntent/utils/testnetHelpers.d.ts.map +1 -0
- package/dist/transactionIntent/validators.d.ts +6 -0
- package/dist/transactionIntent/validators.d.ts.map +1 -0
- package/dist/transactions.d.ts +6 -3
- package/dist/transactions.d.ts.map +1 -1
- package/dist/widget/components/AccountIntentTransactionHistoryButton.d.ts +4 -0
- package/dist/widget/components/AccountIntentTransactionHistoryButton.d.ts.map +1 -0
- package/dist/widget/components/AccountSettings.d.ts.map +1 -1
- package/dist/widget/components/ChainFilterDropdown.d.ts.map +1 -1
- package/dist/widget/components/ClassicSwap.d.ts +2 -3
- package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
- package/dist/widget/components/ConfigDisplay.d.ts.map +1 -1
- package/dist/widget/components/ConnectWallet.d.ts.map +1 -1
- package/dist/widget/components/ConnectedWallets.d.ts.map +1 -1
- package/dist/widget/components/DynamicInputStyles.d.ts +18 -0
- package/dist/widget/components/DynamicInputStyles.d.ts.map +1 -0
- package/dist/widget/components/DynamicSizeInputField.d.ts +13 -0
- package/dist/widget/components/DynamicSizeInputField.d.ts.map +1 -0
- package/dist/widget/components/Earn.d.ts +2 -3
- package/dist/widget/components/Earn.d.ts.map +1 -1
- package/dist/widget/components/ErrorAnimationIcon.d.ts +2 -0
- package/dist/widget/components/ErrorAnimationIcon.d.ts.map +1 -0
- package/dist/widget/components/FeeBreakdown.d.ts +9 -0
- package/dist/widget/components/FeeBreakdown.d.ts.map +1 -0
- package/dist/widget/components/FeeOptions.d.ts +5 -13
- package/dist/widget/components/FeeOptions.d.ts.map +1 -1
- package/dist/widget/components/Fund.d.ts +2 -3
- package/dist/widget/components/Fund.d.ts.map +1 -1
- package/dist/widget/components/FundMethods.d.ts.map +1 -1
- package/dist/widget/components/FundSwap.d.ts +2 -3
- package/dist/widget/components/FundSwap.d.ts.map +1 -1
- package/dist/widget/components/FundingMethodSelectorButton.d.ts.map +1 -1
- package/dist/widget/components/Identicon.d.ts.map +1 -1
- package/dist/widget/components/MeshConnectExchanges.d.ts +0 -3
- package/dist/widget/components/MeshConnectExchanges.d.ts.map +1 -1
- package/dist/widget/components/Modal.d.ts.map +1 -1
- package/dist/widget/components/Pay.d.ts +2 -3
- package/dist/widget/components/Pay.d.ts.map +1 -1
- package/dist/widget/components/PoolDeposit.d.ts +3 -3
- package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
- package/dist/widget/components/PoolWithdraw.d.ts +3 -20
- package/dist/widget/components/PoolWithdraw.d.ts.map +1 -1
- package/dist/widget/components/QuoteDetails.d.ts +2 -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/RecipientSelectorButton.d.ts.map +1 -1
- package/dist/widget/components/ScreenHeader.d.ts.map +1 -1
- package/dist/widget/components/Swap.d.ts +2 -3
- package/dist/widget/components/Swap.d.ts.map +1 -1
- package/dist/widget/components/ThemeProvider.d.ts.map +1 -1
- package/dist/widget/components/TokenDisplayNonSelectable.d.ts +11 -0
- package/dist/widget/components/TokenDisplayNonSelectable.d.ts.map +1 -0
- package/dist/widget/components/TokenSelector.d.ts.map +1 -1
- package/dist/widget/components/TokenSelectorButton.d.ts.map +1 -1
- package/dist/widget/components/Tooltip.d.ts +9 -0
- package/dist/widget/components/Tooltip.d.ts.map +1 -0
- package/dist/widget/components/TransferPendingVertical.d.ts.map +1 -1
- package/dist/widget/components/WaasFeeOptions.d.ts +1 -0
- package/dist/widget/components/WaasFeeOptions.d.ts.map +1 -1
- package/dist/widget/components/WalletConfirmation.d.ts.map +1 -1
- package/dist/widget/components/WalletConnect.d.ts.map +1 -1
- package/dist/widget/css/compiled.css +2 -2
- package/dist/widget/hooks/useCheckout.d.ts +17 -4
- package/dist/widget/hooks/useCheckout.d.ts.map +1 -1
- package/dist/widget/hooks/useDefaultTokenSelection.d.ts.map +1 -1
- package/dist/widget/hooks/useQuote.d.ts +82 -0
- package/dist/widget/hooks/useQuote.d.ts.map +1 -0
- package/dist/widget/hooks/useSelectedFeeToken.d.ts +1 -0
- package/dist/widget/hooks/useSelectedFeeToken.d.ts.map +1 -1
- package/dist/widget/hooks/useSendForm.d.ts +5 -6
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
- package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
- package/dist/widget/hooks/useWalletConnectionContext.d.ts +25 -0
- package/dist/widget/hooks/useWalletConnectionContext.d.ts.map +1 -0
- package/dist/widget/index.js +2 -2
- package/dist/widget/widget.d.ts +17 -7
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +19 -21
- package/src/aave.ts +54 -1
- package/src/abortController.ts +35 -0
- package/src/config.ts +57 -58
- package/src/constants.ts +11 -9
- package/src/error.ts +21 -3
- package/src/fees.ts +210 -0
- package/src/index.ts +35 -13
- package/src/intentReceiptMonitor.ts +102 -0
- package/src/intentReceiptPoller.ts +299 -0
- package/src/intents.ts +205 -171
- package/src/morpho.ts +58 -9
- package/src/mutations.ts +129 -0
- package/src/preconditions.ts +16 -21
- package/src/prepareSend.ts +92 -4699
- package/src/prices.ts +26 -22
- package/src/relaySdk.ts +2 -2
- package/src/sequenceWallet.ts +6 -73
- package/src/tokenBalances.ts +175 -69
- package/src/trails.ts +230 -722
- package/src/transactionIntent/constants.ts +11 -0
- package/src/transactionIntent/deposits/depositOrchestrator.ts +210 -0
- package/src/transactionIntent/deposits/gaslessDeposit.ts +588 -0
- package/src/transactionIntent/deposits/index.ts +3 -0
- package/src/transactionIntent/deposits/standardDeposit.ts +379 -0
- package/src/transactionIntent/execution/index.ts +1 -0
- package/src/transactionIntent/execution/transactionState.ts +35 -0
- package/src/transactionIntent/handlers/crossChain.ts +1707 -0
- package/src/transactionIntent/handlers/index.ts +3 -0
- package/src/transactionIntent/handlers/sameChainDifferentToken.ts +323 -0
- package/src/transactionIntent/handlers/sameChainSameToken.ts +712 -0
- package/src/transactionIntent/index.ts +9 -0
- package/src/transactionIntent/quote/feeExtractors.ts +81 -0
- package/src/transactionIntent/quote/index.ts +3 -0
- package/src/transactionIntent/quote/normalizeQuote.ts +367 -0
- package/src/transactionIntent/quote/quoteHelpers.ts +53 -0
- package/src/transactionIntent/types.ts +157 -0
- package/src/transactionIntent/utils/balanceChecker.ts +96 -0
- package/src/transactionIntent/utils/index.ts +3 -0
- package/src/transactionIntent/utils/lifiHelpers.ts +68 -0
- package/src/transactionIntent/utils/testnetHelpers.ts +10 -0
- package/src/transactionIntent/validators.ts +57 -0
- package/src/transactions.ts +98 -71
- package/src/widget/compiled.css +2 -2
- package/src/widget/components/AccountIntentTransactionHistory.tsx +36 -36
- package/src/widget/components/AccountIntentTransactionHistoryButton.tsx +22 -0
- package/src/widget/components/AccountSettings.tsx +70 -41
- package/src/widget/components/ChainFilterDropdown.tsx +24 -3
- package/src/widget/components/ClassicSwap.tsx +44 -107
- package/src/widget/components/ConfigDisplay.tsx +0 -11
- package/src/widget/components/ConnectWallet.tsx +4 -1
- package/src/widget/components/ConnectedWallets.tsx +51 -25
- package/src/widget/components/DynamicInputStyles.tsx +76 -0
- package/src/widget/components/DynamicSizeInputField.tsx +109 -0
- package/src/widget/components/Earn.tsx +34 -45
- package/src/widget/components/ErrorAnimationIcon.tsx +130 -0
- package/src/widget/components/FeeBreakdown.tsx +155 -0
- package/src/widget/components/FeeOption.tsx +2 -2
- package/src/widget/components/FeeOptions.tsx +151 -112
- package/src/widget/components/Fund.tsx +10 -29
- package/src/widget/components/FundMethods.tsx +4 -3
- package/src/widget/components/FundSwap.tsx +2 -3
- package/src/widget/components/FundingMethodSelectorButton.tsx +24 -14
- package/src/widget/components/Identicon.tsx +164 -95
- package/src/widget/components/MeshConnectExchanges.tsx +2 -15
- package/src/widget/components/Modal.tsx +0 -12
- package/src/widget/components/Pay.tsx +72 -75
- package/src/widget/components/PoolDeposit.tsx +221 -242
- package/src/widget/components/PoolWithdraw.tsx +347 -469
- package/src/widget/components/PriceImpactWarning.tsx +1 -1
- package/src/widget/components/QuoteDetails.tsx +906 -484
- package/src/widget/components/Receipt.tsx +16 -2
- package/src/widget/components/RecipientSelectorButton.tsx +7 -5
- package/src/widget/components/Recipients.tsx +1 -1
- package/src/widget/components/ScreenHeader.tsx +60 -36
- package/src/widget/components/Swap.tsx +2 -3
- package/src/widget/components/ThemeProvider.tsx +2 -1
- package/src/widget/components/TokenDisplayNonSelectable.tsx +40 -0
- package/src/widget/components/TokenImage.tsx +1 -1
- package/src/widget/components/TokenSelector.tsx +62 -53
- package/src/widget/components/TokenSelectorButton.tsx +38 -15
- package/src/widget/components/Tooltip.tsx +51 -0
- package/src/widget/components/TransferPendingVertical.tsx +12 -8
- package/src/widget/components/WaasFeeOptions.tsx +139 -4
- package/src/widget/components/WalletConfirmation.tsx +23 -13
- package/src/widget/components/WalletConnect.tsx +93 -29
- package/src/widget/hooks/useAmountUsd.ts +9 -9
- package/src/widget/hooks/useCheckout.ts +97 -9
- package/src/widget/hooks/useDefaultTokenSelection.tsx +27 -21
- package/src/widget/hooks/useQuote.ts +466 -0
- package/src/widget/hooks/useSelectedFeeToken.tsx +32 -37
- package/src/widget/hooks/useSendForm.ts +45 -51
- package/src/widget/hooks/useTokenList.ts +34 -26
- package/src/widget/hooks/useWalletConnectionContext.tsx +128 -0
- package/src/widget/widget.tsx +365 -390
- package/dist/apiClient.d.ts +0 -9
- package/dist/apiClient.d.ts.map +0 -1
- package/dist/intentEntrypoint.d.ts +0 -114
- package/dist/intentEntrypoint.d.ts.map +0 -1
- package/dist/metaTxnMonitor.d.ts +0 -15
- package/dist/metaTxnMonitor.d.ts.map +0 -1
- package/dist/metaTxns.d.ts +0 -11
- package/dist/metaTxns.d.ts.map +0 -1
- package/dist/relayer.d.ts +0 -43
- package/dist/relayer.d.ts.map +0 -1
- package/src/apiClient.ts +0 -35
- package/src/intentEntrypoint.ts +0 -203
- package/src/metaTxnMonitor.ts +0 -171
- package/src/metaTxns.ts +0 -45
- package/src/relayer.ts +0 -289
package/src/trails.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
TransactionPrecondition,
|
|
3
|
+
Intent,
|
|
4
|
+
QuoteIntentRequest,
|
|
5
|
+
MetaTxn,
|
|
6
|
+
IntentCalls,
|
|
7
7
|
} from "@0xsequence/trails-api"
|
|
8
8
|
import type { TrailsClient } from "./trailsClient.js"
|
|
9
|
-
import type { RelayerOperationStatus } from "./relayer.js"
|
|
10
9
|
import { useMutation, useQuery } from "@tanstack/react-query"
|
|
11
10
|
import { Address } from "ox"
|
|
12
|
-
import { useCallback, useEffect,
|
|
11
|
+
import { useCallback, useEffect, useState } from "react"
|
|
13
12
|
import type { Hex } from "viem"
|
|
14
13
|
import {
|
|
15
|
-
createPublicClient,
|
|
16
14
|
createWalletClient,
|
|
17
15
|
custom,
|
|
18
|
-
|
|
16
|
+
ethAddress,
|
|
19
17
|
isAddress,
|
|
20
18
|
isAddressEqual,
|
|
21
19
|
zeroAddress,
|
|
@@ -32,23 +30,23 @@ import { attemptSwitchChain } from "./chainSwitch.js"
|
|
|
32
30
|
import { getChainInfo } from "./chains.js"
|
|
33
31
|
import { getERC20TransferData } from "./encoders.js"
|
|
34
32
|
import type {
|
|
35
|
-
GetIntentCallsPayloadsReturn,
|
|
36
33
|
OriginCallParams,
|
|
37
|
-
|
|
38
|
-
TrailsFee,
|
|
34
|
+
TrailsFee as LocalTrailsFee,
|
|
39
35
|
} from "./intents.js"
|
|
40
36
|
import {
|
|
41
37
|
calculateIntentAddress,
|
|
42
38
|
calculateOriginAndDestinationIntentAddresses,
|
|
43
|
-
|
|
39
|
+
getIntent as getIntentFromIntents,
|
|
44
40
|
} from "./intents.js"
|
|
45
|
-
import
|
|
46
|
-
|
|
41
|
+
import {
|
|
42
|
+
useIntentReceiptMonitor,
|
|
43
|
+
type IntentReceiptStatus,
|
|
44
|
+
} from "./intentReceiptMonitor.js"
|
|
47
45
|
import { findPreconditionAddresses } from "./preconditions.js"
|
|
48
|
-
import { getBackupRelayer, useRelayers } from "./relayer.js"
|
|
49
46
|
import { queueCCTPTransfer } from "./cctpqueue.js"
|
|
50
47
|
import { logger } from "./logger.js"
|
|
51
|
-
import {
|
|
48
|
+
import { useCommitIntent, useExecuteIntent } from "./mutations.js"
|
|
49
|
+
// Removed: import { SEQUENCE_V3_CONTRACT_ADDRESSES_OVERRIDES } from "./constants.js"
|
|
52
50
|
|
|
53
51
|
export type WagmiAccount = {
|
|
54
52
|
address: `0x${string}`
|
|
@@ -60,18 +58,15 @@ export type WagmiAccount = {
|
|
|
60
58
|
export type UseTrailsConfig = {
|
|
61
59
|
account: WagmiAccount
|
|
62
60
|
disableAutoExecute?: boolean
|
|
63
|
-
env: "local" | "cors-anywhere" | "dev" | "prod"
|
|
64
61
|
sequenceProjectAccessKey?: string
|
|
65
62
|
}
|
|
66
63
|
|
|
67
64
|
export type UseTrailsReturn = {
|
|
68
65
|
trailsClient: TrailsClient
|
|
69
|
-
metaTxns:
|
|
70
|
-
intentCallsPayloads:
|
|
71
|
-
intentPreconditions:
|
|
72
|
-
|
|
73
|
-
| null
|
|
74
|
-
trailsFee: TrailsFee | null
|
|
66
|
+
metaTxns: MetaTxn[] | null
|
|
67
|
+
intentCallsPayloads: IntentCalls[] | null
|
|
68
|
+
intentPreconditions: TransactionPrecondition[] | null
|
|
69
|
+
trailsFee: LocalTrailsFee | null
|
|
75
70
|
txnHash: Hex | undefined
|
|
76
71
|
committedOriginIntentAddress: string | null
|
|
77
72
|
committedDestinationIntentAddress: string | null
|
|
@@ -82,39 +77,29 @@ export type UseTrailsReturn = {
|
|
|
82
77
|
receivedOriginAddress?: string
|
|
83
78
|
receivedDestinationAddress?: string
|
|
84
79
|
} | null
|
|
85
|
-
getRelayer: (chainId: number) => any // TODO: Add proper type
|
|
86
80
|
estimatedGas: bigint | undefined
|
|
87
81
|
isEstimateError: boolean
|
|
88
82
|
estimateError: Error | null
|
|
89
83
|
calculateIntentAddress: typeof calculateIntentAddress
|
|
90
84
|
calculateOriginAndDestinationIntentAddresses: typeof calculateOriginAndDestinationIntentAddresses
|
|
91
|
-
committedIntentConfig:
|
|
85
|
+
committedIntentConfig: Intent | undefined
|
|
92
86
|
isLoadingCommittedConfig: boolean
|
|
93
87
|
committedConfigError: Error | null
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
88
|
+
commitIntent: (intent: Intent) => void
|
|
89
|
+
commitIntentPending: boolean
|
|
90
|
+
commitIntentSuccess: boolean
|
|
91
|
+
commitIntentError: Error | null
|
|
92
|
+
commitIntentArgs: Intent | undefined
|
|
93
|
+
executeIntent: (args: {
|
|
94
|
+
intentId: string
|
|
95
|
+
depositTransactionHash: string
|
|
100
96
|
}) => void
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
| {
|
|
106
|
-
mainSignerAddress: string
|
|
107
|
-
calls: IntentCallsPayload[]
|
|
108
|
-
preconditions: IntentPrecondition[]
|
|
109
|
-
quoteProvider: QuoteProvider
|
|
110
|
-
addressOverrides?: AddressOverrides
|
|
111
|
-
}
|
|
112
|
-
| undefined
|
|
113
|
-
getIntentCallsPayloads: (
|
|
114
|
-
args: GetIntentCallsPayloadsArgs,
|
|
115
|
-
) => Promise<GetIntentCallsPayloadsReturn>
|
|
97
|
+
executeIntentPending: boolean
|
|
98
|
+
executeIntentSuccess: boolean
|
|
99
|
+
executeIntentError: Error | null
|
|
100
|
+
getIntent: (args: QuoteIntentRequest) => Promise<Intent>
|
|
116
101
|
operationHashes: { [key: string]: Hex }
|
|
117
|
-
callIntentCallsPayload: (args:
|
|
102
|
+
callIntentCallsPayload: (args: QuoteIntentRequest) => void
|
|
118
103
|
sendOriginTransaction: () => Promise<void>
|
|
119
104
|
switchChain: any // TODO: Add proper type
|
|
120
105
|
isSwitchingChain: boolean
|
|
@@ -148,18 +133,13 @@ export type UseTrailsReturn = {
|
|
|
148
133
|
hasAutoExecuted: boolean
|
|
149
134
|
originCallSuccess: boolean
|
|
150
135
|
sentMetaTxns: { [key: string]: number }
|
|
151
|
-
sendMetaTxn: (selectedId: string | null) => void
|
|
152
|
-
sendMetaTxnPending: boolean
|
|
153
|
-
sendMetaTxnSuccess: boolean
|
|
154
|
-
sendMetaTxnError: Error | null
|
|
155
|
-
sendMetaTxnArgs: { selectedId: string | null } | undefined
|
|
156
136
|
clearIntent: () => void
|
|
157
|
-
|
|
158
|
-
createIntent: (args:
|
|
137
|
+
intentReceiptStatus: IntentReceiptStatus | null
|
|
138
|
+
createIntent: (args: QuoteIntentRequest) => void
|
|
159
139
|
createIntentPending: boolean
|
|
160
140
|
createIntentSuccess: boolean
|
|
161
141
|
createIntentError: Error | null
|
|
162
|
-
createIntentArgs:
|
|
142
|
+
createIntentArgs: QuoteIntentRequest | undefined
|
|
163
143
|
originCallParams: OriginCallParams | null
|
|
164
144
|
updateOriginCallParams: (
|
|
165
145
|
args: { originChainId: number; tokenAddress: string } | null,
|
|
@@ -172,13 +152,10 @@ export type UseTrailsReturn = {
|
|
|
172
152
|
destinationIntentAddress: string | null
|
|
173
153
|
}
|
|
174
154
|
|
|
175
|
-
const RETRY_WINDOW_MS = 10_000
|
|
176
|
-
|
|
177
155
|
export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
178
156
|
const {
|
|
179
157
|
account,
|
|
180
158
|
disableAutoExecute = false,
|
|
181
|
-
env,
|
|
182
159
|
sequenceProjectAccessKey,
|
|
183
160
|
} = config
|
|
184
161
|
const trailsClient = useTrailsClient({
|
|
@@ -194,16 +171,15 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
194
171
|
)
|
|
195
172
|
|
|
196
173
|
// State declarations
|
|
197
|
-
const [metaTxns, setMetaTxns] = useState<
|
|
198
|
-
GetIntentCallsPayloadsReturn["payloads"]["metaTxns"] | null
|
|
199
|
-
>(null)
|
|
174
|
+
const [metaTxns, setMetaTxns] = useState<MetaTxn[] | null>(null)
|
|
200
175
|
const [intentCallsPayloads, setIntentCallsPayloads] = useState<
|
|
201
|
-
|
|
176
|
+
IntentCalls[] | null
|
|
202
177
|
>(null)
|
|
203
178
|
const [intentPreconditions, setIntentPreconditions] = useState<
|
|
204
|
-
|
|
179
|
+
TransactionPrecondition[] | null
|
|
205
180
|
>(null)
|
|
206
|
-
const [trailsFee, setTrailsFee] = useState<
|
|
181
|
+
const [trailsFee, setTrailsFee] = useState<LocalTrailsFee | null>(null)
|
|
182
|
+
const [quoteIntent, setQuoteIntent] = useState<Intent | null>(null)
|
|
207
183
|
const [txnHash, setTxnHash] = useState<Hex | undefined>()
|
|
208
184
|
const [committedOriginIntentAddress, setCommittedOriginIntentAddress] =
|
|
209
185
|
useState<string | null>(null)
|
|
@@ -259,10 +235,6 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
259
235
|
receivedDestinationAddress?: string
|
|
260
236
|
} | null>(null)
|
|
261
237
|
|
|
262
|
-
const { getRelayer, relayers } = useRelayers({
|
|
263
|
-
env,
|
|
264
|
-
})
|
|
265
|
-
|
|
266
238
|
// Add gas estimation hook with proper types
|
|
267
239
|
const {
|
|
268
240
|
data: estimatedGas,
|
|
@@ -279,36 +251,20 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
279
251
|
: undefined,
|
|
280
252
|
)
|
|
281
253
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
quoteProvider: QuoteProvider
|
|
288
|
-
addressOverrides?: AddressOverrides
|
|
289
|
-
}) => {
|
|
254
|
+
// Commit intent mutation with verification logic wrapper
|
|
255
|
+
const baseCommitIntentMutation = useCommitIntent()
|
|
256
|
+
|
|
257
|
+
const commitIntentMutation = useMutation({
|
|
258
|
+
mutationFn: async (intent: Intent) => {
|
|
290
259
|
logger.console.log(
|
|
291
|
-
"[useTrails]
|
|
292
|
-
|
|
260
|
+
"[useTrails] commitIntentMutation started with intent:",
|
|
261
|
+
intent,
|
|
293
262
|
)
|
|
294
|
-
if (!trailsClient) {
|
|
295
|
-
logger.console.error("[useTrails] API client not available")
|
|
296
|
-
throw new Error("API client not available")
|
|
297
|
-
}
|
|
298
|
-
if (!args.quoteProvider) {
|
|
299
|
-
logger.console.error("[useTrails] quoteProvider is required")
|
|
300
|
-
throw new Error("quoteProvider is required")
|
|
301
|
-
}
|
|
302
263
|
|
|
303
264
|
try {
|
|
304
|
-
|
|
305
|
-
logger.console.log("[useTrails] Main signer:", args.mainSignerAddress)
|
|
306
|
-
logger.console.log("[useTrails] Calls:", args.calls)
|
|
307
|
-
|
|
308
|
-
const originChainId =
|
|
309
|
-
createIntentMutation.variables?.params.originChainId
|
|
265
|
+
const originChainId = createIntentMutation.variables?.originChainId
|
|
310
266
|
const destinationChainId =
|
|
311
|
-
createIntentMutation.variables?.
|
|
267
|
+
createIntentMutation.variables?.destinationChainId
|
|
312
268
|
|
|
313
269
|
if (!originChainId || !destinationChainId) {
|
|
314
270
|
logger.console.error(
|
|
@@ -319,17 +275,21 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
319
275
|
)
|
|
320
276
|
}
|
|
321
277
|
|
|
278
|
+
logger.console.log("[useTrails] Calculating intent address...")
|
|
279
|
+
logger.console.log("[useTrails] Main signer:", intent.ownerAddress)
|
|
280
|
+
logger.console.log("[useTrails] Calls:", intent.calls)
|
|
281
|
+
|
|
322
282
|
const { originIntentAddress, destinationIntentAddress } =
|
|
323
283
|
calculateOriginAndDestinationIntentAddresses(
|
|
324
|
-
|
|
325
|
-
|
|
284
|
+
intent.ownerAddress,
|
|
285
|
+
intent.calls,
|
|
326
286
|
)
|
|
327
287
|
|
|
328
288
|
const {
|
|
329
289
|
originAddress: originPreconditionAddress,
|
|
330
290
|
destinationAddress: destinationPreconditionAddress,
|
|
331
291
|
} = findPreconditionAddresses(
|
|
332
|
-
|
|
292
|
+
intent.preconditions,
|
|
333
293
|
originChainId,
|
|
334
294
|
destinationChainId,
|
|
335
295
|
)
|
|
@@ -387,21 +347,9 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
387
347
|
)
|
|
388
348
|
}
|
|
389
349
|
|
|
390
|
-
// Commit the intent
|
|
391
|
-
logger.console.log("[useTrails] Committing intent
|
|
392
|
-
const response = await
|
|
393
|
-
params: {
|
|
394
|
-
originIntentAddress: originIntentAddress.toString(),
|
|
395
|
-
destinationIntentAddress: destinationIntentAddress.toString(),
|
|
396
|
-
mainSigner: args.mainSignerAddress,
|
|
397
|
-
calls: args.calls,
|
|
398
|
-
preconditions: args.preconditions,
|
|
399
|
-
addressOverrides: {
|
|
400
|
-
...SEQUENCE_V3_CONTRACT_ADDRESSES_OVERRIDES,
|
|
401
|
-
...args.addressOverrides,
|
|
402
|
-
},
|
|
403
|
-
},
|
|
404
|
-
})
|
|
350
|
+
// Commit the intent that was returned from quoteIntent
|
|
351
|
+
logger.console.log("[useTrails] Committing intent to API...")
|
|
352
|
+
const response = await baseCommitIntentMutation.mutateAsync(intent)
|
|
405
353
|
logger.console.log("[useTrails] API Commit Response:", response)
|
|
406
354
|
return {
|
|
407
355
|
originIntentAddress: originIntentAddress.toString(),
|
|
@@ -432,13 +380,16 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
432
380
|
},
|
|
433
381
|
})
|
|
434
382
|
|
|
383
|
+
// Execute intent mutation
|
|
384
|
+
const executeIntentMutation = useExecuteIntent()
|
|
385
|
+
|
|
435
386
|
// New Query to fetch committed intent config
|
|
436
387
|
const {
|
|
437
388
|
data: committedIntentConfig,
|
|
438
389
|
isLoading: isLoadingCommittedConfig,
|
|
439
390
|
error: committedConfigError,
|
|
440
|
-
} = useQuery<
|
|
441
|
-
queryKey: ["
|
|
391
|
+
} = useQuery<Intent, Error>({
|
|
392
|
+
queryKey: ["getIntent", committedOriginIntentAddress],
|
|
442
393
|
queryFn: async () => {
|
|
443
394
|
if (!trailsClient || !committedOriginIntentAddress) {
|
|
444
395
|
throw new Error("API client or committed intent address not available")
|
|
@@ -447,42 +398,32 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
447
398
|
"Fetching intent config for address:",
|
|
448
399
|
committedOriginIntentAddress,
|
|
449
400
|
)
|
|
450
|
-
|
|
451
|
-
|
|
401
|
+
const response = await trailsClient.getIntent({
|
|
402
|
+
intentId: committedOriginIntentAddress,
|
|
452
403
|
})
|
|
404
|
+
return response.intent
|
|
453
405
|
},
|
|
454
406
|
enabled:
|
|
455
407
|
!!committedOriginIntentAddress &&
|
|
456
408
|
!!trailsClient &&
|
|
457
|
-
|
|
409
|
+
commitIntentMutation.isSuccess,
|
|
458
410
|
staleTime: 1000 * 60 * 5, // 5 minutes
|
|
459
411
|
retry: 1,
|
|
460
412
|
})
|
|
461
413
|
|
|
462
|
-
async function
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
...args.params,
|
|
466
|
-
addressOverrides: {
|
|
467
|
-
...SEQUENCE_V3_CONTRACT_ADDRESSES_OVERRIDES,
|
|
468
|
-
...args.params.addressOverrides,
|
|
469
|
-
},
|
|
470
|
-
},
|
|
471
|
-
})
|
|
414
|
+
async function getIntent(args: QuoteIntentRequest) {
|
|
415
|
+
const { intent } = await getIntentFromIntents(trailsClient, args)
|
|
416
|
+
return intent
|
|
472
417
|
}
|
|
473
418
|
|
|
474
419
|
// TODO: Add type for args
|
|
475
|
-
const createIntentMutation = useMutation<
|
|
476
|
-
|
|
477
|
-
Error,
|
|
478
|
-
GetIntentCallsPayloadsArgs
|
|
479
|
-
>({
|
|
480
|
-
mutationFn: async (args: GetIntentCallsPayloadsArgs) => {
|
|
420
|
+
const createIntentMutation = useMutation<Intent, Error, QuoteIntentRequest>({
|
|
421
|
+
mutationFn: async (args: QuoteIntentRequest) => {
|
|
481
422
|
if (
|
|
482
|
-
args.
|
|
423
|
+
args.originChainId === args.destinationChainId &&
|
|
483
424
|
isAddressEqual(
|
|
484
|
-
Address.from(args.
|
|
485
|
-
Address.from(args.
|
|
425
|
+
Address.from(args.originTokenAddress),
|
|
426
|
+
Address.from(args.destinationTokenAddress),
|
|
486
427
|
)
|
|
487
428
|
) {
|
|
488
429
|
throw new Error(
|
|
@@ -503,14 +444,15 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
503
444
|
setOriginIntentAddress(null)
|
|
504
445
|
setDestinationIntentAddress(null)
|
|
505
446
|
|
|
506
|
-
const data = await
|
|
447
|
+
const { intent: data } = await getIntentFromIntents(trailsClient, args)
|
|
507
448
|
|
|
508
|
-
setMetaTxns(data.
|
|
509
|
-
setIntentCallsPayloads(data.
|
|
510
|
-
setIntentPreconditions(data.
|
|
511
|
-
setTrailsFee(data.
|
|
512
|
-
setOriginIntentAddress(data.
|
|
513
|
-
setDestinationIntentAddress(data.
|
|
449
|
+
setMetaTxns(data.metaTxns)
|
|
450
|
+
setIntentCallsPayloads(data.calls)
|
|
451
|
+
setIntentPreconditions(data.preconditions)
|
|
452
|
+
setTrailsFee(data.fees as any)
|
|
453
|
+
setOriginIntentAddress(data.originIntentAddress)
|
|
454
|
+
setDestinationIntentAddress(data.destinationIntentAddress)
|
|
455
|
+
setQuoteIntent(data)
|
|
514
456
|
setCommittedOriginIntentAddress(null)
|
|
515
457
|
setCommittedDestinationIntentAddress(null)
|
|
516
458
|
|
|
@@ -520,21 +462,21 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
520
462
|
onSuccess: (data) => {
|
|
521
463
|
logger.console.log("Intent Config Success:", data)
|
|
522
464
|
|
|
523
|
-
setTrailsFee(data.
|
|
524
|
-
setOriginIntentAddress(data.
|
|
525
|
-
setDestinationIntentAddress(data.
|
|
465
|
+
setTrailsFee((data.fees || null) as any)
|
|
466
|
+
setOriginIntentAddress(data.originIntentAddress)
|
|
467
|
+
setDestinationIntentAddress(data.destinationIntentAddress)
|
|
526
468
|
|
|
527
469
|
if (
|
|
528
|
-
data
|
|
529
|
-
data.
|
|
530
|
-
data.
|
|
531
|
-
data.
|
|
532
|
-
data.
|
|
533
|
-
data.
|
|
470
|
+
data?.calls &&
|
|
471
|
+
data.calls.length > 0 &&
|
|
472
|
+
data.preconditions &&
|
|
473
|
+
data.preconditions.length > 0 &&
|
|
474
|
+
data.metaTxns &&
|
|
475
|
+
data.metaTxns.length > 0
|
|
534
476
|
) {
|
|
535
|
-
setIntentCallsPayloads(data.
|
|
536
|
-
setIntentPreconditions(data.
|
|
537
|
-
setMetaTxns(data.
|
|
477
|
+
setIntentCallsPayloads(data.calls)
|
|
478
|
+
setIntentPreconditions(data.preconditions)
|
|
479
|
+
setMetaTxns(data.metaTxns)
|
|
538
480
|
} else {
|
|
539
481
|
logger.console.warn("API returned success but no operations found.")
|
|
540
482
|
setIntentCallsPayloads(null)
|
|
@@ -553,7 +495,7 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
553
495
|
},
|
|
554
496
|
})
|
|
555
497
|
|
|
556
|
-
function callIntentCallsPayload(args:
|
|
498
|
+
function callIntentCallsPayload(args: QuoteIntentRequest) {
|
|
557
499
|
createIntentMutation.mutate(args)
|
|
558
500
|
}
|
|
559
501
|
|
|
@@ -819,7 +761,6 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
819
761
|
})
|
|
820
762
|
|
|
821
763
|
// Modify the effect that watches for transaction status
|
|
822
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: False positive
|
|
823
764
|
useEffect(() => {
|
|
824
765
|
if (!txnHash) {
|
|
825
766
|
// Only reset these when txnHash is cleared
|
|
@@ -871,35 +812,8 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
871
812
|
: undefined,
|
|
872
813
|
})
|
|
873
814
|
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
try {
|
|
877
|
-
if (!originCallParams?.chainId) {
|
|
878
|
-
logger.console.error(
|
|
879
|
-
"[Trails] Origin chainId not available for fetching origin block timestamp.",
|
|
880
|
-
)
|
|
881
|
-
setOriginBlockTimestamp(null)
|
|
882
|
-
return
|
|
883
|
-
}
|
|
884
|
-
const chainConfig = getChainInfo(originCallParams.chainId)!
|
|
885
|
-
const client = createPublicClient({
|
|
886
|
-
chain: chainConfig,
|
|
887
|
-
transport: http(),
|
|
888
|
-
})
|
|
889
|
-
const block = await client.getBlock({
|
|
890
|
-
blockNumber: BigInt(receipt.blockNumber),
|
|
891
|
-
})
|
|
892
|
-
setOriginBlockTimestamp(Number(block.timestamp))
|
|
893
|
-
} catch (error) {
|
|
894
|
-
logger.console.error(
|
|
895
|
-
"[Trails] Error fetching origin block timestamp:",
|
|
896
|
-
error,
|
|
897
|
-
)
|
|
898
|
-
setOriginBlockTimestamp(null)
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
fetchTimestamp()
|
|
902
|
-
} else if (newStatus !== "Success") {
|
|
815
|
+
// Timestamp is now available from transaction receipts via the API (txnMinedAt)
|
|
816
|
+
if (newStatus !== "Success") {
|
|
903
817
|
setOriginBlockTimestamp(null)
|
|
904
818
|
}
|
|
905
819
|
|
|
@@ -911,9 +825,16 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
911
825
|
!metaTxns.some((tx: MetaTxn) => sentMetaTxns[`${tx.chainId}-${tx.id}`])
|
|
912
826
|
) {
|
|
913
827
|
logger.console.log(
|
|
914
|
-
"Origin transaction successful, auto-sending all meta transactions...",
|
|
828
|
+
"Origin transaction successful, calling executeIntent and auto-sending all meta transactions...",
|
|
915
829
|
)
|
|
916
|
-
|
|
830
|
+
|
|
831
|
+
// Call executeIntent with intentId and depositTransactionHash
|
|
832
|
+
if (committedOriginIntentAddress && txnHash) {
|
|
833
|
+
executeIntentMutation.mutate({
|
|
834
|
+
intentId: committedOriginIntentAddress,
|
|
835
|
+
depositTransactionHash: txnHash,
|
|
836
|
+
})
|
|
837
|
+
}
|
|
917
838
|
}
|
|
918
839
|
} else if (receiptIsError) {
|
|
919
840
|
setOriginCallStatus({
|
|
@@ -937,16 +858,17 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
937
858
|
metaTxns,
|
|
938
859
|
sentMetaTxns,
|
|
939
860
|
isAutoExecute,
|
|
940
|
-
originCallParams?.chainId,
|
|
941
861
|
originCallStatus?.status,
|
|
942
862
|
originCallStatus?.txnHash,
|
|
863
|
+
committedOriginIntentAddress,
|
|
864
|
+
executeIntentMutation,
|
|
943
865
|
])
|
|
944
866
|
|
|
945
867
|
// Modify the auto-execute effect
|
|
946
868
|
useEffect(() => {
|
|
947
869
|
const shouldAutoSend =
|
|
948
870
|
isAutoExecute &&
|
|
949
|
-
|
|
871
|
+
commitIntentMutation.isSuccess &&
|
|
950
872
|
originCallParams?.chainId &&
|
|
951
873
|
account.chainId === originCallParams.chainId &&
|
|
952
874
|
!originCallParams.error &&
|
|
@@ -1002,7 +924,7 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
1002
924
|
}
|
|
1003
925
|
}, [
|
|
1004
926
|
isAutoExecute,
|
|
1005
|
-
|
|
927
|
+
commitIntentMutation.isSuccess,
|
|
1006
928
|
originCallParams,
|
|
1007
929
|
account.chainId,
|
|
1008
930
|
sendOriginTxn.isPending,
|
|
@@ -1023,286 +945,25 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
1023
945
|
trailsFee &&
|
|
1024
946
|
account.address &&
|
|
1025
947
|
originIntentAddress &&
|
|
1026
|
-
!
|
|
1027
|
-
!
|
|
948
|
+
!commitIntentMutation.isPending &&
|
|
949
|
+
!commitIntentMutation.isSuccess
|
|
1028
950
|
) {
|
|
1029
951
|
logger.console.log("Auto-committing intent configuration...")
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
preconditions: intentPreconditions,
|
|
1034
|
-
quoteProvider: trailsFee.quoteProvider as QuoteProvider,
|
|
1035
|
-
addressOverrides:
|
|
1036
|
-
createIntentMutation.variables?.params.addressOverrides,
|
|
1037
|
-
})
|
|
952
|
+
if (quoteIntent) {
|
|
953
|
+
commitIntentMutation.mutate(quoteIntent)
|
|
954
|
+
}
|
|
1038
955
|
}
|
|
1039
956
|
}, [
|
|
1040
957
|
isAutoExecute,
|
|
958
|
+
quoteIntent,
|
|
1041
959
|
intentCallsPayloads,
|
|
1042
960
|
intentPreconditions,
|
|
1043
961
|
trailsFee,
|
|
1044
962
|
account.address,
|
|
1045
963
|
originIntentAddress,
|
|
1046
|
-
|
|
1047
|
-
createIntentMutation.variables,
|
|
964
|
+
commitIntentMutation,
|
|
1048
965
|
])
|
|
1049
966
|
|
|
1050
|
-
// Update the sendMetaTxn mutation
|
|
1051
|
-
const sendMetaTxnMutation = useMutation({
|
|
1052
|
-
mutationFn: async ({ selectedId }: { selectedId: string | null }) => {
|
|
1053
|
-
logger.console.log("[trails-sdk] Starting sendMetaTxn mutation", {
|
|
1054
|
-
selectedId,
|
|
1055
|
-
hasIntentCallsPayloads: !!intentCallsPayloads,
|
|
1056
|
-
hasIntentPreconditions: !!intentPreconditions,
|
|
1057
|
-
hasMetaTxns: !!metaTxns,
|
|
1058
|
-
hasAccountAddress: !!account.address,
|
|
1059
|
-
quoteProvider: trailsFee?.quoteProvider,
|
|
1060
|
-
})
|
|
1061
|
-
|
|
1062
|
-
if (
|
|
1063
|
-
!intentCallsPayloads ||
|
|
1064
|
-
!intentPreconditions ||
|
|
1065
|
-
!metaTxns ||
|
|
1066
|
-
!account.address
|
|
1067
|
-
) {
|
|
1068
|
-
throw new Error("Missing required data for meta-transaction")
|
|
1069
|
-
}
|
|
1070
|
-
|
|
1071
|
-
if (!trailsFee?.quoteProvider) {
|
|
1072
|
-
throw new Error("quoteProvider is required")
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
|
-
const intentAddress = calculateIntentAddress(
|
|
1076
|
-
account.address,
|
|
1077
|
-
intentCallsPayloads as any[],
|
|
1078
|
-
)
|
|
1079
|
-
|
|
1080
|
-
// If no specific ID is selected, send all meta transactions
|
|
1081
|
-
const txnsToSend = selectedId
|
|
1082
|
-
? [metaTxns.find((tx: MetaTxn) => tx.id === selectedId)]
|
|
1083
|
-
: metaTxns
|
|
1084
|
-
|
|
1085
|
-
logger.console.log("[trails-sdk] Selected transactions to send", {
|
|
1086
|
-
selectedId,
|
|
1087
|
-
totalMetaTxns: metaTxns.length,
|
|
1088
|
-
txnsToSendCount: txnsToSend.filter((tx) => tx).length,
|
|
1089
|
-
txnsToSend: txnsToSend
|
|
1090
|
-
.filter((tx) => tx)
|
|
1091
|
-
.map((tx) => ({
|
|
1092
|
-
id: tx?.id,
|
|
1093
|
-
chainId: tx?.chainId,
|
|
1094
|
-
walletAddress: tx?.walletAddress,
|
|
1095
|
-
contract: tx?.contract,
|
|
1096
|
-
})),
|
|
1097
|
-
})
|
|
1098
|
-
|
|
1099
|
-
if (!txnsToSend || (selectedId && !txnsToSend[0])) {
|
|
1100
|
-
throw new Error("Meta transaction not found")
|
|
1101
|
-
}
|
|
1102
|
-
|
|
1103
|
-
const results = []
|
|
1104
|
-
|
|
1105
|
-
for (const metaTxn of txnsToSend) {
|
|
1106
|
-
if (!metaTxn) continue
|
|
1107
|
-
|
|
1108
|
-
const operationKey = `${metaTxn.chainId}-${metaTxn.id}`
|
|
1109
|
-
const lastSentTime = sentMetaTxns[operationKey]
|
|
1110
|
-
const now = Date.now()
|
|
1111
|
-
|
|
1112
|
-
logger.console.log(
|
|
1113
|
-
`[trails-sdk] Processing meta transaction ${operationKey}`,
|
|
1114
|
-
{
|
|
1115
|
-
metaTxnId: metaTxn.id,
|
|
1116
|
-
chainId: metaTxn.chainId,
|
|
1117
|
-
walletAddress: metaTxn.walletAddress,
|
|
1118
|
-
contract: metaTxn.contract,
|
|
1119
|
-
intentAddress,
|
|
1120
|
-
},
|
|
1121
|
-
)
|
|
1122
|
-
|
|
1123
|
-
if (lastSentTime && now - lastSentTime < RETRY_WINDOW_MS) {
|
|
1124
|
-
const timeLeft = Math.ceil(
|
|
1125
|
-
(RETRY_WINDOW_MS - (now - lastSentTime)) / 1000,
|
|
1126
|
-
)
|
|
1127
|
-
logger.console.log(
|
|
1128
|
-
`[trails-sdk] Meta transaction for ${operationKey} was sent recently. Wait ${timeLeft}s before retry`,
|
|
1129
|
-
{
|
|
1130
|
-
lastSentTime,
|
|
1131
|
-
now,
|
|
1132
|
-
timeLeft,
|
|
1133
|
-
},
|
|
1134
|
-
)
|
|
1135
|
-
continue
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
|
-
try {
|
|
1139
|
-
const chainId = parseInt(metaTxn.chainId, 10)
|
|
1140
|
-
if (Number.isNaN(chainId) || chainId <= 0) {
|
|
1141
|
-
logger.console.error(
|
|
1142
|
-
`[trails-sdk] Invalid chainId for meta transaction`,
|
|
1143
|
-
{
|
|
1144
|
-
chainId,
|
|
1145
|
-
operationKey,
|
|
1146
|
-
metaTxn,
|
|
1147
|
-
},
|
|
1148
|
-
)
|
|
1149
|
-
throw new Error(`Invalid chainId for meta transaction: ${chainId}`)
|
|
1150
|
-
}
|
|
1151
|
-
const chainRelayer = getRelayer(chainId)
|
|
1152
|
-
if (!chainRelayer) {
|
|
1153
|
-
logger.console.error(`[trails-sdk] No relayer found for chainId`, {
|
|
1154
|
-
chainId,
|
|
1155
|
-
operationKey,
|
|
1156
|
-
availableRelayers: Array.from(relayers.keys()),
|
|
1157
|
-
})
|
|
1158
|
-
throw new Error(`No relayer found for chainId: ${chainId}`)
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
const relevantPreconditions = intentPreconditions.filter(
|
|
1162
|
-
(p: IntentPrecondition) =>
|
|
1163
|
-
p.chainId && parseInt(p.chainId, 10) === chainId,
|
|
1164
|
-
)
|
|
1165
|
-
|
|
1166
|
-
logger.console.log(
|
|
1167
|
-
`[trails-sdk] Relaying meta transaction ${operationKey} to intent ${intentAddress} via relayer`,
|
|
1168
|
-
{
|
|
1169
|
-
chainId,
|
|
1170
|
-
operationKey,
|
|
1171
|
-
intentAddress,
|
|
1172
|
-
relayer: !!chainRelayer,
|
|
1173
|
-
preconditionsCount: relevantPreconditions.length,
|
|
1174
|
-
},
|
|
1175
|
-
)
|
|
1176
|
-
|
|
1177
|
-
const { opHash } = await chainRelayer.sendMetaTxn(
|
|
1178
|
-
metaTxn.walletAddress as Address.Address,
|
|
1179
|
-
metaTxn.contract as Address.Address,
|
|
1180
|
-
metaTxn.input as Hex,
|
|
1181
|
-
Number(metaTxn.chainId),
|
|
1182
|
-
undefined,
|
|
1183
|
-
relevantPreconditions,
|
|
1184
|
-
)
|
|
1185
|
-
|
|
1186
|
-
logger.console.log(
|
|
1187
|
-
`[trails-sdk] Successfully sent meta transaction ${operationKey}`,
|
|
1188
|
-
{
|
|
1189
|
-
operationKey,
|
|
1190
|
-
opHash,
|
|
1191
|
-
chainId,
|
|
1192
|
-
},
|
|
1193
|
-
)
|
|
1194
|
-
|
|
1195
|
-
const useBackupRelayer = false // Disable backup relayer for now
|
|
1196
|
-
if (useBackupRelayer) {
|
|
1197
|
-
try {
|
|
1198
|
-
// Fire and forget send tx to backup relayer
|
|
1199
|
-
const backupRelayer = getBackupRelayer(chainId)
|
|
1200
|
-
|
|
1201
|
-
backupRelayer
|
|
1202
|
-
?.sendMetaTxn(
|
|
1203
|
-
metaTxn.walletAddress as Address.Address,
|
|
1204
|
-
metaTxn.contract as Address.Address,
|
|
1205
|
-
metaTxn.input as Hex,
|
|
1206
|
-
Number(metaTxn.chainId),
|
|
1207
|
-
undefined,
|
|
1208
|
-
relevantPreconditions,
|
|
1209
|
-
)
|
|
1210
|
-
.then(() => {
|
|
1211
|
-
logger.console.log(
|
|
1212
|
-
`[trails-sdk] Backup relayer sent for ${operationKey}`,
|
|
1213
|
-
)
|
|
1214
|
-
})
|
|
1215
|
-
.catch((backupError) => {
|
|
1216
|
-
logger.console.warn(
|
|
1217
|
-
`[trails-sdk] Backup relayer failed for ${operationKey}`,
|
|
1218
|
-
backupError,
|
|
1219
|
-
)
|
|
1220
|
-
})
|
|
1221
|
-
} catch {}
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
results.push({
|
|
1225
|
-
operationKey,
|
|
1226
|
-
opHash,
|
|
1227
|
-
success: true,
|
|
1228
|
-
})
|
|
1229
|
-
} catch (error: unknown) {
|
|
1230
|
-
const errorMessage =
|
|
1231
|
-
error instanceof Error ? error.message : "Unknown error"
|
|
1232
|
-
logger.console.error(
|
|
1233
|
-
`[trails-sdk] Failed to send meta transaction ${operationKey}`,
|
|
1234
|
-
{
|
|
1235
|
-
operationKey,
|
|
1236
|
-
error: errorMessage,
|
|
1237
|
-
chainId: metaTxn.chainId,
|
|
1238
|
-
metaTxnId: metaTxn.id,
|
|
1239
|
-
walletAddress: metaTxn.walletAddress,
|
|
1240
|
-
contract: metaTxn.contract,
|
|
1241
|
-
},
|
|
1242
|
-
)
|
|
1243
|
-
|
|
1244
|
-
results.push({
|
|
1245
|
-
operationKey,
|
|
1246
|
-
error: errorMessage,
|
|
1247
|
-
success: false,
|
|
1248
|
-
})
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
return results
|
|
1253
|
-
},
|
|
1254
|
-
onSuccess: (results) => {
|
|
1255
|
-
logger.console.log(
|
|
1256
|
-
"[trails-sdk] sendMetaTxn mutation completed successfully",
|
|
1257
|
-
{
|
|
1258
|
-
totalResults: results.length,
|
|
1259
|
-
successfulResults: results.filter((r) => r.success).length,
|
|
1260
|
-
failedResults: results.filter((r) => !r.success).length,
|
|
1261
|
-
results: results.map((r) => ({
|
|
1262
|
-
operationKey: r.operationKey,
|
|
1263
|
-
success: r.success,
|
|
1264
|
-
opHash: r.opHash || null,
|
|
1265
|
-
error: r.error || null,
|
|
1266
|
-
})),
|
|
1267
|
-
},
|
|
1268
|
-
)
|
|
1269
|
-
|
|
1270
|
-
// Update states based on results
|
|
1271
|
-
results.forEach(({ operationKey, opHash, success }) => {
|
|
1272
|
-
if (success && opHash) {
|
|
1273
|
-
setSentMetaTxns((prev) => ({
|
|
1274
|
-
...prev,
|
|
1275
|
-
[operationKey]: Date.now(),
|
|
1276
|
-
}))
|
|
1277
|
-
|
|
1278
|
-
setOperationHashes((prev) => ({
|
|
1279
|
-
...prev,
|
|
1280
|
-
[operationKey]: opHash,
|
|
1281
|
-
}))
|
|
1282
|
-
} else {
|
|
1283
|
-
logger.console.warn(
|
|
1284
|
-
`[trails-sdk] Not updating state for failed meta transaction ${operationKey}`,
|
|
1285
|
-
{
|
|
1286
|
-
operationKey,
|
|
1287
|
-
error: results.find((r) => r.operationKey === operationKey)
|
|
1288
|
-
?.error,
|
|
1289
|
-
},
|
|
1290
|
-
)
|
|
1291
|
-
}
|
|
1292
|
-
})
|
|
1293
|
-
},
|
|
1294
|
-
onError: (error) => {
|
|
1295
|
-
logger.console.error("[trails-sdk] Error in meta-transaction process", {
|
|
1296
|
-
error: error instanceof Error ? error.message : String(error),
|
|
1297
|
-
errorType:
|
|
1298
|
-
error instanceof Error ? error.constructor.name : typeof error,
|
|
1299
|
-
stack: error instanceof Error ? error.stack : undefined,
|
|
1300
|
-
})
|
|
1301
|
-
},
|
|
1302
|
-
retry: 5, // Allow up to 2 retries
|
|
1303
|
-
retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000), // Exponential backoff
|
|
1304
|
-
})
|
|
1305
|
-
|
|
1306
967
|
const [tokenAddress, setTokenAddress] = useState<string | null>(null)
|
|
1307
968
|
const [originChainId, setOriginChainId] = useState<number | null>(null)
|
|
1308
969
|
|
|
@@ -1333,39 +994,36 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
1333
994
|
|
|
1334
995
|
const recipientAddress = intentAddressString
|
|
1335
996
|
|
|
1336
|
-
const isNative =
|
|
997
|
+
const isNative =
|
|
998
|
+
tokenAddress === zeroAddress || tokenAddress === ethAddress
|
|
1337
999
|
|
|
1338
1000
|
if (isNative) {
|
|
1339
1001
|
const nativePrecondition = intentPreconditions.find(
|
|
1340
|
-
(p:
|
|
1002
|
+
(p: TransactionPrecondition) =>
|
|
1341
1003
|
(p.type === "transfer-native" || p.type === "native-balance") &&
|
|
1342
|
-
p.chainId === originChainId
|
|
1004
|
+
p.chainId === originChainId,
|
|
1343
1005
|
)
|
|
1344
|
-
const nativeMinAmount = nativePrecondition?.
|
|
1006
|
+
const nativeMinAmount = nativePrecondition?.minAmount?.toString()
|
|
1345
1007
|
if (nativeMinAmount === undefined) {
|
|
1346
|
-
throw new Error(
|
|
1347
|
-
"Could not find native precondition (transfer-native or native-balance) or min amount",
|
|
1348
|
-
)
|
|
1008
|
+
throw new Error("Could not find precondition or min amount")
|
|
1349
1009
|
}
|
|
1350
1010
|
calcValue = BigInt(nativeMinAmount)
|
|
1351
1011
|
calcTo = recipientAddress
|
|
1352
1012
|
} else {
|
|
1353
1013
|
const erc20Precondition = intentPreconditions.find(
|
|
1354
|
-
(p:
|
|
1014
|
+
(p: TransactionPrecondition) =>
|
|
1355
1015
|
p.type === "erc20-balance" &&
|
|
1356
|
-
p.chainId === originChainId
|
|
1357
|
-
p.
|
|
1016
|
+
p.chainId === originChainId &&
|
|
1017
|
+
p.tokenAddress &&
|
|
1358
1018
|
isAddressEqual(
|
|
1359
|
-
Address.from(p.
|
|
1019
|
+
Address.from(p.tokenAddress),
|
|
1360
1020
|
Address.from(tokenAddress),
|
|
1361
1021
|
),
|
|
1362
1022
|
)
|
|
1363
1023
|
|
|
1364
|
-
const erc20MinAmount = erc20Precondition?.
|
|
1024
|
+
const erc20MinAmount = erc20Precondition?.minAmount?.toString()
|
|
1365
1025
|
if (erc20MinAmount === undefined) {
|
|
1366
|
-
throw new Error(
|
|
1367
|
-
"Could not find ERC20 balance precondition or min amount",
|
|
1368
|
-
)
|
|
1026
|
+
throw new Error("Could not find precondition or min amount")
|
|
1369
1027
|
}
|
|
1370
1028
|
calcData = getERC20TransferData({
|
|
1371
1029
|
recipient: recipientAddress,
|
|
@@ -1444,232 +1102,91 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
1444
1102
|
// }
|
|
1445
1103
|
// }, [intentPreconditions, checkPreconditionStatuses])
|
|
1446
1104
|
|
|
1447
|
-
//
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1105
|
+
// Use the new WaitIntentReceipt API to monitor intent execution
|
|
1106
|
+
// This replaces the old per-meta-transaction polling approach
|
|
1107
|
+
const intentReceiptStatus = useIntentReceiptMonitor(
|
|
1108
|
+
committedOriginIntentAddress ?? undefined,
|
|
1109
|
+
trailsClient,
|
|
1451
1110
|
)
|
|
1452
1111
|
|
|
1453
|
-
//
|
|
1454
|
-
|
|
1455
|
-
if (!metaTxns || Object.keys(metaTxnMonitorStatuses).length === 0) {
|
|
1456
|
-
return "no_statuses"
|
|
1457
|
-
}
|
|
1458
|
-
// Sort by a stable key (e.g., id) to ensure consistent order if metaTxns array order changes
|
|
1459
|
-
// but content is the same, though metaTxns itself is a dependency, so this might be redundant if metaTxns order is stable.
|
|
1460
|
-
const sortedTxnIds = metaTxns
|
|
1461
|
-
.map((tx: MetaTxn) => `${tx.chainId}-${tx.id}`)
|
|
1462
|
-
.sort()
|
|
1463
|
-
|
|
1464
|
-
return sortedTxnIds
|
|
1465
|
-
.map((key: string) => {
|
|
1466
|
-
const statusObj = metaTxnMonitorStatuses[key]
|
|
1467
|
-
return `${key}:${statusObj ? statusObj.status : "loading"}`
|
|
1468
|
-
})
|
|
1469
|
-
.join(",")
|
|
1470
|
-
}, [metaTxns, metaTxnMonitorStatuses])
|
|
1471
|
-
|
|
1472
|
-
const processedTxns = useRef(new Set<string>())
|
|
1473
|
-
const lastQueuedCctpSourceTxHash = useRef<string | null>(null)
|
|
1474
|
-
|
|
1475
|
-
// Effect to fetch meta-transaction block timestamps
|
|
1112
|
+
// Simplified block timestamp tracking using IntentReceipt API
|
|
1113
|
+
// The IntentReceipt provides unified status for both origin and destination transactions
|
|
1476
1114
|
useEffect(() => {
|
|
1477
|
-
logger.console.log(
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
},
|
|
1483
|
-
)
|
|
1484
|
-
|
|
1485
|
-
if (!metaTxns || metaTxns.length === 0) {
|
|
1486
|
-
logger.console.log(
|
|
1487
|
-
"[trails-sdk] No meta transactions, clearing timestamps",
|
|
1488
|
-
)
|
|
1489
|
-
processedTxns.current.clear()
|
|
1490
|
-
if (Object.keys(metaTxnBlockTimestamps).length > 0) {
|
|
1491
|
-
setMetaTxnBlockTimestamps({})
|
|
1492
|
-
}
|
|
1493
|
-
return
|
|
1494
|
-
}
|
|
1115
|
+
logger.console.log("[trails-sdk] Intent receipt status update:", {
|
|
1116
|
+
intentId: committedOriginIntentAddress,
|
|
1117
|
+
done: intentReceiptStatus.done,
|
|
1118
|
+
hasReceipt: !!intentReceiptStatus.intentReceipt,
|
|
1119
|
+
})
|
|
1495
1120
|
|
|
1496
|
-
if (!
|
|
1497
|
-
logger.console.log("[trails-sdk] No
|
|
1121
|
+
if (!intentReceiptStatus.intentReceipt) {
|
|
1122
|
+
logger.console.log("[trails-sdk] No intent receipt yet, waiting...")
|
|
1498
1123
|
return
|
|
1499
1124
|
}
|
|
1500
1125
|
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
// Skip if already processed
|
|
1505
|
-
if (processedTxns.current.has(operationKey)) {
|
|
1506
|
-
logger.console.log(
|
|
1507
|
-
`[trails-sdk] MetaTxn ${operationKey}: Already processed, skipping`,
|
|
1508
|
-
)
|
|
1509
|
-
return
|
|
1510
|
-
}
|
|
1511
|
-
|
|
1512
|
-
const monitorStatus = metaTxnMonitorStatuses[operationKey]
|
|
1513
|
-
if (!monitorStatus || monitorStatus.status !== "confirmed") {
|
|
1514
|
-
logger.console.log(
|
|
1515
|
-
`[trails-sdk] MetaTxn ${operationKey}: Status not confirmed, skipping`,
|
|
1516
|
-
)
|
|
1517
|
-
return
|
|
1518
|
-
}
|
|
1126
|
+
// Update block timestamps from intent receipt transactions
|
|
1127
|
+
const newTimestamps: typeof metaTxnBlockTimestamps = {}
|
|
1519
1128
|
|
|
1520
|
-
|
|
1521
|
-
const
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
)
|
|
1526
|
-
return
|
|
1527
|
-
}
|
|
1528
|
-
|
|
1529
|
-
logger.console.log(
|
|
1530
|
-
`[trails-sdk] MetaTxn ${operationKey}: Processing transaction ${transactionHash}`,
|
|
1531
|
-
)
|
|
1532
|
-
processedTxns.current.add(operationKey)
|
|
1129
|
+
if (intentReceiptStatus.intentReceipt.originTransaction) {
|
|
1130
|
+
const originTx = intentReceiptStatus.intentReceipt.originTransaction
|
|
1131
|
+
const key = `${originTx.chainId}-${originTx.metaTxnId}`
|
|
1132
|
+
newTimestamps[key] = { timestamp: null } // TODO: fetch actual block timestamp
|
|
1133
|
+
}
|
|
1533
1134
|
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
)
|
|
1540
|
-
}
|
|
1135
|
+
if (intentReceiptStatus.intentReceipt.destinationTransaction) {
|
|
1136
|
+
const destTx = intentReceiptStatus.intentReceipt.destinationTransaction
|
|
1137
|
+
const key = `${destTx.chainId}-${destTx.metaTxnId}`
|
|
1138
|
+
newTimestamps[key] = { timestamp: null } // TODO: fetch actual block timestamp
|
|
1139
|
+
}
|
|
1541
1140
|
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1141
|
+
setMetaTxnBlockTimestamps(newTimestamps)
|
|
1142
|
+
}, [
|
|
1143
|
+
intentReceiptStatus.intentReceipt,
|
|
1144
|
+
intentReceiptStatus.done,
|
|
1145
|
+
committedOriginIntentAddress,
|
|
1146
|
+
])
|
|
1547
1147
|
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1148
|
+
// Effect to handle completed intent
|
|
1149
|
+
useEffect(() => {
|
|
1150
|
+
if (intentReceiptStatus.done && intentReceiptStatus.intentReceipt) {
|
|
1151
|
+
logger.console.log("[trails-sdk] Intent execution completed", {
|
|
1152
|
+
intentId: committedOriginIntentAddress,
|
|
1153
|
+
status: intentReceiptStatus.intentReceipt.status,
|
|
1154
|
+
})
|
|
1551
1155
|
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
// Queue CCTP transfer using the first confirmed origin meta-tx hash
|
|
1156
|
+
// Handle CCTP transfers if needed
|
|
1157
|
+
if (intentReceiptStatus.intentReceipt.originTransaction?.txnHash) {
|
|
1158
|
+
const providerFromQuote = trailsFee?.quoteProvider
|
|
1159
|
+
? String(trailsFee.quoteProvider).toLowerCase()
|
|
1160
|
+
: undefined
|
|
1161
|
+
const providerFromArgs = createIntentMutation.variables?.options
|
|
1162
|
+
?.quoteProvider
|
|
1163
|
+
? String(
|
|
1164
|
+
createIntentMutation.variables.options.quoteProvider,
|
|
1165
|
+
).toLowerCase()
|
|
1166
|
+
: undefined
|
|
1167
|
+
const isCctp =
|
|
1168
|
+
providerFromQuote === "cctp" || providerFromArgs === "cctp"
|
|
1169
|
+
|
|
1170
|
+
if (isCctp && createIntentMutation.variables) {
|
|
1568
1171
|
try {
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
providerFromQuote === "cctp" || providerFromArgs === "cctp"
|
|
1580
|
-
|
|
1581
|
-
const originChainIdForCctp =
|
|
1582
|
-
createIntentMutation.variables?.params.originChainId
|
|
1583
|
-
const destinationChainIdForCctp =
|
|
1584
|
-
createIntentMutation.variables?.params.destinationChainId
|
|
1585
|
-
|
|
1586
|
-
logger.console.log("[Trails] isCctp", isCctp)
|
|
1587
|
-
logger.console.log("[Trails] providerFromQuote", providerFromQuote)
|
|
1588
|
-
logger.console.log("[Trails] providerFromArgs", providerFromArgs)
|
|
1589
|
-
logger.console.log("[Trails] trailsFee", trailsFee)
|
|
1590
|
-
logger.console.log(
|
|
1591
|
-
"[Trails] createIntentMutation.variables",
|
|
1592
|
-
createIntentMutation.variables,
|
|
1593
|
-
)
|
|
1594
|
-
logger.console.log(
|
|
1595
|
-
"[Trails] createIntentMutation.variables.params.provider",
|
|
1596
|
-
createIntentMutation.variables?.params.provider,
|
|
1597
|
-
)
|
|
1598
|
-
logger.console.log(
|
|
1599
|
-
"[Trails] createIntentMutation.variables.params.originChainId",
|
|
1600
|
-
createIntentMutation.variables?.params.originChainId,
|
|
1601
|
-
)
|
|
1602
|
-
logger.console.log(
|
|
1603
|
-
"[Trails] createIntentMutation.variables.params.destinationChainId",
|
|
1604
|
-
createIntentMutation.variables?.params.destinationChainId,
|
|
1605
|
-
)
|
|
1606
|
-
logger.console.log(
|
|
1607
|
-
"[Trails] lastQueuedCctpSourceTxHash",
|
|
1608
|
-
lastQueuedCctpSourceTxHash.current,
|
|
1609
|
-
)
|
|
1610
|
-
logger.console.log("[Trails] transactionHash", transactionHash)
|
|
1611
|
-
logger.console.log(
|
|
1612
|
-
"[Trails] originChainIdForCctp",
|
|
1613
|
-
originChainIdForCctp,
|
|
1614
|
-
)
|
|
1615
|
-
logger.console.log(
|
|
1616
|
-
"[Trails] destinationChainIdForCctp",
|
|
1617
|
-
destinationChainIdForCctp,
|
|
1618
|
-
)
|
|
1619
|
-
|
|
1620
|
-
if (
|
|
1621
|
-
isCctp &&
|
|
1622
|
-
trailsClient &&
|
|
1623
|
-
transactionHash &&
|
|
1624
|
-
typeof originChainIdForCctp === "number" &&
|
|
1625
|
-
typeof destinationChainIdForCctp === "number" &&
|
|
1626
|
-
lastQueuedCctpSourceTxHash.current !== transactionHash &&
|
|
1627
|
-
index === 0
|
|
1628
|
-
) {
|
|
1629
|
-
lastQueuedCctpSourceTxHash.current = transactionHash
|
|
1630
|
-
await queueCCTPTransfer({
|
|
1631
|
-
trailsClient,
|
|
1632
|
-
sourceTxHash: transactionHash,
|
|
1633
|
-
sourceChainId: originChainIdForCctp,
|
|
1634
|
-
destinationChainId: destinationChainIdForCctp,
|
|
1635
|
-
})
|
|
1636
|
-
}
|
|
1637
|
-
} catch (err) {
|
|
1638
|
-
logger.console.error(
|
|
1639
|
-
`[trails-sdk] Queue CCTP on meta-tx error (${operationKey}):`,
|
|
1640
|
-
err,
|
|
1641
|
-
)
|
|
1172
|
+
queueCCTPTransfer({
|
|
1173
|
+
sourceTxHash: intentReceiptStatus.intentReceipt.originTransaction
|
|
1174
|
+
.txnHash as `0x${string}`,
|
|
1175
|
+
sourceChainId: createIntentMutation.variables.originChainId,
|
|
1176
|
+
destinationChainId:
|
|
1177
|
+
createIntentMutation.variables.destinationChainId,
|
|
1178
|
+
trailsClient,
|
|
1179
|
+
})
|
|
1180
|
+
} catch (error) {
|
|
1181
|
+
logger.console.error("[Trails] queueCCTPTransfer error", error)
|
|
1642
1182
|
}
|
|
1643
|
-
} else {
|
|
1644
|
-
logger.console.warn(
|
|
1645
|
-
`[trails-sdk] MetaTxn ${operationKey}: No block number in receipt`,
|
|
1646
|
-
)
|
|
1647
|
-
setMetaTxnBlockTimestamps((prev) => ({
|
|
1648
|
-
...prev,
|
|
1649
|
-
[operationKey]: {
|
|
1650
|
-
timestamp: null,
|
|
1651
|
-
error: "Block number not found in receipt",
|
|
1652
|
-
},
|
|
1653
|
-
}))
|
|
1654
1183
|
}
|
|
1655
|
-
} catch (error: any) {
|
|
1656
|
-
logger.console.error(
|
|
1657
|
-
`[trails-sdk] MetaTxn ${operationKey}: Error:`,
|
|
1658
|
-
error,
|
|
1659
|
-
)
|
|
1660
|
-
setMetaTxnBlockTimestamps((prev) => ({
|
|
1661
|
-
...prev,
|
|
1662
|
-
[operationKey]: {
|
|
1663
|
-
timestamp: null,
|
|
1664
|
-
error: error.message || "Failed to fetch receipt/timestamp",
|
|
1665
|
-
},
|
|
1666
|
-
}))
|
|
1667
1184
|
}
|
|
1668
|
-
}
|
|
1185
|
+
}
|
|
1669
1186
|
}, [
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1187
|
+
intentReceiptStatus.done,
|
|
1188
|
+
intentReceiptStatus.intentReceipt,
|
|
1189
|
+
committedOriginIntentAddress,
|
|
1673
1190
|
trailsFee,
|
|
1674
1191
|
createIntentMutation.variables,
|
|
1675
1192
|
trailsClient,
|
|
@@ -1679,22 +1196,13 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
1679
1196
|
setIsAutoExecute(enabled)
|
|
1680
1197
|
}
|
|
1681
1198
|
|
|
1682
|
-
function createIntent(args:
|
|
1683
|
-
createIntentMutation.mutate(
|
|
1684
|
-
...args,
|
|
1685
|
-
destinationSalt: Date.now().toString(),
|
|
1686
|
-
} as GetIntentCallsPayloadsArgs)
|
|
1199
|
+
function createIntent(args: QuoteIntentRequest) {
|
|
1200
|
+
createIntentMutation.mutate(args)
|
|
1687
1201
|
}
|
|
1688
1202
|
|
|
1689
|
-
function
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
preconditions: IntentPrecondition[]
|
|
1693
|
-
quoteProvider: QuoteProvider
|
|
1694
|
-
addressOverrides?: AddressOverrides
|
|
1695
|
-
}) {
|
|
1696
|
-
logger.console.log("[trails-sdk] commitIntentConfig", args)
|
|
1697
|
-
commitIntentConfigMutation.mutate(args)
|
|
1203
|
+
function commitIntent(intent: Intent) {
|
|
1204
|
+
logger.console.log("[trails-sdk] commitIntent", intent)
|
|
1205
|
+
commitIntentMutation.mutate(intent)
|
|
1698
1206
|
}
|
|
1699
1207
|
|
|
1700
1208
|
function updateOriginCallParams(
|
|
@@ -1709,10 +1217,6 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
1709
1217
|
setTokenAddress(tokenAddress)
|
|
1710
1218
|
}
|
|
1711
1219
|
|
|
1712
|
-
function sendMetaTxn(selectedId: string | null) {
|
|
1713
|
-
sendMetaTxnMutation.mutate({ selectedId })
|
|
1714
|
-
}
|
|
1715
|
-
|
|
1716
1220
|
const { chainId } = account
|
|
1717
1221
|
|
|
1718
1222
|
const originChainIdFromParams = originCallParams?.chainId
|
|
@@ -1722,15 +1226,21 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
1722
1226
|
const createIntentError = createIntentMutation.error
|
|
1723
1227
|
const createIntentArgs = createIntentMutation.variables
|
|
1724
1228
|
|
|
1725
|
-
const
|
|
1726
|
-
const
|
|
1727
|
-
const
|
|
1728
|
-
const
|
|
1229
|
+
const commitIntentPending = commitIntentMutation.isPending
|
|
1230
|
+
const commitIntentSuccess = commitIntentMutation.isSuccess
|
|
1231
|
+
const commitIntentError = commitIntentMutation.error
|
|
1232
|
+
const commitIntentArgs = commitIntentMutation.variables
|
|
1233
|
+
|
|
1234
|
+
const executeIntentPending = executeIntentMutation.isPending
|
|
1235
|
+
const executeIntentSuccess = executeIntentMutation.isSuccess
|
|
1236
|
+
const executeIntentError = executeIntentMutation.error
|
|
1729
1237
|
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1238
|
+
function executeIntent(args: {
|
|
1239
|
+
intentId: string
|
|
1240
|
+
depositTransactionHash: string
|
|
1241
|
+
}) {
|
|
1242
|
+
executeIntentMutation.mutate(args)
|
|
1243
|
+
}
|
|
1734
1244
|
|
|
1735
1245
|
return {
|
|
1736
1246
|
trailsClient,
|
|
@@ -1742,7 +1252,6 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
1742
1252
|
committedOriginIntentAddress,
|
|
1743
1253
|
committedDestinationIntentAddress,
|
|
1744
1254
|
verificationStatus,
|
|
1745
|
-
getRelayer,
|
|
1746
1255
|
estimatedGas,
|
|
1747
1256
|
isEstimateError,
|
|
1748
1257
|
estimateError,
|
|
@@ -1751,12 +1260,16 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
1751
1260
|
committedIntentConfig,
|
|
1752
1261
|
isLoadingCommittedConfig,
|
|
1753
1262
|
committedConfigError,
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1263
|
+
commitIntent,
|
|
1264
|
+
commitIntentPending,
|
|
1265
|
+
commitIntentSuccess,
|
|
1266
|
+
commitIntentError,
|
|
1267
|
+
commitIntentArgs,
|
|
1268
|
+
executeIntent,
|
|
1269
|
+
executeIntentPending,
|
|
1270
|
+
executeIntentSuccess,
|
|
1271
|
+
executeIntentError,
|
|
1272
|
+
getIntent,
|
|
1760
1273
|
operationHashes,
|
|
1761
1274
|
callIntentCallsPayload,
|
|
1762
1275
|
sendOriginTransaction,
|
|
@@ -1781,13 +1294,8 @@ export function useTrails(config: UseTrailsConfig): UseTrailsReturn {
|
|
|
1781
1294
|
hasAutoExecuted,
|
|
1782
1295
|
originCallSuccess: sendOriginTxn.isSuccess,
|
|
1783
1296
|
sentMetaTxns,
|
|
1784
|
-
sendMetaTxn,
|
|
1785
|
-
sendMetaTxnPending,
|
|
1786
|
-
sendMetaTxnSuccess,
|
|
1787
|
-
sendMetaTxnError,
|
|
1788
|
-
sendMetaTxnArgs,
|
|
1789
1297
|
clearIntent,
|
|
1790
|
-
|
|
1298
|
+
intentReceiptStatus,
|
|
1791
1299
|
createIntent,
|
|
1792
1300
|
createIntentPending,
|
|
1793
1301
|
createIntentSuccess,
|