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
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Account,
|
|
3
|
+
Chain,
|
|
4
|
+
PublicClient,
|
|
5
|
+
WalletClient,
|
|
6
|
+
TransactionReceipt,
|
|
7
|
+
} from "viem"
|
|
8
|
+
import { parseUnits } from "viem"
|
|
9
|
+
import type { TransactionState } from "../../transactions.js"
|
|
10
|
+
import type { CheckoutOnHandlers } from "../../widget/hooks/useCheckout.js"
|
|
11
|
+
import { logger } from "../../logger.js"
|
|
12
|
+
import { getNeedsLifiNativeFee } from "../utils/lifiHelpers.js"
|
|
13
|
+
import {
|
|
14
|
+
buildCrossChainDepositParams,
|
|
15
|
+
buildSameChainSameTokenTransactionParams,
|
|
16
|
+
sendOriginTransaction,
|
|
17
|
+
} from "../../intents.js"
|
|
18
|
+
import { estimateGasLimit } from "../../estimate.js"
|
|
19
|
+
import { attemptSwitchChain } from "../../chainSwitch.js"
|
|
20
|
+
import { requestWithTimeout } from "../../utils.js"
|
|
21
|
+
import { updatePersistentToast } from "../../toast.js"
|
|
22
|
+
import { getChainInfo } from "../../chains.js"
|
|
23
|
+
import { trackTransactionConfirmed } from "../../analytics.js"
|
|
24
|
+
|
|
25
|
+
export async function attemptStandardDeposit({
|
|
26
|
+
originTokenAddress,
|
|
27
|
+
firstPreconditionMin,
|
|
28
|
+
onOriginSend,
|
|
29
|
+
publicClient,
|
|
30
|
+
walletClient,
|
|
31
|
+
originChainId,
|
|
32
|
+
chain,
|
|
33
|
+
account,
|
|
34
|
+
fee,
|
|
35
|
+
dryMode,
|
|
36
|
+
sourceTokenPriceUsd,
|
|
37
|
+
destinationTokenPriceUsd,
|
|
38
|
+
swapAmount,
|
|
39
|
+
destinationTokenDecimals,
|
|
40
|
+
sourceTokenDecimals,
|
|
41
|
+
originIntentAddress,
|
|
42
|
+
onTransactionStateChange,
|
|
43
|
+
transactionStates,
|
|
44
|
+
originTokenSymbol,
|
|
45
|
+
destinationTokenSymbol,
|
|
46
|
+
depositAmountUsd,
|
|
47
|
+
checkoutOnHandlers,
|
|
48
|
+
isSameChainSameToken,
|
|
49
|
+
recipient,
|
|
50
|
+
}: {
|
|
51
|
+
originTokenAddress: string
|
|
52
|
+
firstPreconditionMin: string
|
|
53
|
+
onOriginSend?: () => void
|
|
54
|
+
publicClient: PublicClient
|
|
55
|
+
walletClient: WalletClient
|
|
56
|
+
originChainId: number
|
|
57
|
+
chain: Chain
|
|
58
|
+
account: Account
|
|
59
|
+
fee: string
|
|
60
|
+
dryMode: boolean
|
|
61
|
+
sourceTokenPriceUsd?: number | null
|
|
62
|
+
destinationTokenPriceUsd?: number | null
|
|
63
|
+
swapAmount: string
|
|
64
|
+
destinationTokenDecimals: number
|
|
65
|
+
sourceTokenDecimals: number
|
|
66
|
+
originIntentAddress: string
|
|
67
|
+
onTransactionStateChange: (transactionStates: TransactionState[]) => void
|
|
68
|
+
transactionStates: TransactionState[]
|
|
69
|
+
originTokenSymbol: string
|
|
70
|
+
destinationTokenSymbol: string
|
|
71
|
+
depositAmountUsd: number
|
|
72
|
+
checkoutOnHandlers?: CheckoutOnHandlers
|
|
73
|
+
isSameChainSameToken?: boolean
|
|
74
|
+
recipient?: string
|
|
75
|
+
}): Promise<TransactionReceipt | null> {
|
|
76
|
+
let depositUserTxnReceipt: TransactionReceipt | null = null
|
|
77
|
+
const usingLIfi = false
|
|
78
|
+
let needsNativeFee = false
|
|
79
|
+
|
|
80
|
+
if (usingLIfi) {
|
|
81
|
+
needsNativeFee = getNeedsLifiNativeFee({
|
|
82
|
+
originTokenAddress,
|
|
83
|
+
destinationTokenAmount: swapAmount,
|
|
84
|
+
destinationTokenDecimals,
|
|
85
|
+
sourceTokenDecimals,
|
|
86
|
+
sourceTokenPriceUsd: sourceTokenPriceUsd ?? null,
|
|
87
|
+
destinationTokenPriceUsd: destinationTokenPriceUsd ?? null,
|
|
88
|
+
depositAmount: firstPreconditionMin,
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
let nativeFee = parseUnits("0.00005", 18).toString()
|
|
92
|
+
if (originChainId === 137) {
|
|
93
|
+
nativeFee = parseUnits("1.5", 18).toString()
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
logger.console.log("[trails-sdk] needsNativeFee", needsNativeFee)
|
|
97
|
+
|
|
98
|
+
// Build origin call params
|
|
99
|
+
// For same-chain deposits, send directly to recipient (not intent address)
|
|
100
|
+
// For cross-chain deposits, send to intent address for backend processing
|
|
101
|
+
const originCallParamsBase = isSameChainSameToken
|
|
102
|
+
? buildSameChainSameTokenTransactionParams({
|
|
103
|
+
hasCustomCalldata: false,
|
|
104
|
+
recipient: recipient || originIntentAddress,
|
|
105
|
+
effectiveOriginTokenAddress: originTokenAddress,
|
|
106
|
+
swapAmount: firstPreconditionMin,
|
|
107
|
+
effectiveOriginChainId: originChainId,
|
|
108
|
+
effectiveOriginChain: chain,
|
|
109
|
+
})
|
|
110
|
+
: buildCrossChainDepositParams({
|
|
111
|
+
originTokenAddress,
|
|
112
|
+
originIntentAddress,
|
|
113
|
+
depositAmount: firstPreconditionMin,
|
|
114
|
+
fee,
|
|
115
|
+
originChainId,
|
|
116
|
+
chain,
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
// Estimate gas limit for consistency with actual transaction
|
|
120
|
+
const gasLimit = await estimateGasLimit(
|
|
121
|
+
publicClient,
|
|
122
|
+
{
|
|
123
|
+
account: account.address,
|
|
124
|
+
to: originCallParamsBase.to,
|
|
125
|
+
data: originCallParamsBase.data,
|
|
126
|
+
value: BigInt(originCallParamsBase.value),
|
|
127
|
+
},
|
|
128
|
+
"deposit",
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
const originCallParams = {
|
|
132
|
+
...originCallParamsBase,
|
|
133
|
+
gasLimit,
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
await attemptSwitchChain({
|
|
137
|
+
walletClient,
|
|
138
|
+
desiredChainId: originChainId,
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
let useSendCalls = false
|
|
142
|
+
const moreThan1Tx = needsNativeFee
|
|
143
|
+
|
|
144
|
+
if (moreThan1Tx) {
|
|
145
|
+
try {
|
|
146
|
+
// the reason for the timeout is some users experience this call to hang indefinitely on metamask on all chains.
|
|
147
|
+
// not sure why this is happening, but it happens.
|
|
148
|
+
const capabilities = await requestWithTimeout<Record<string, any>>(
|
|
149
|
+
walletClient,
|
|
150
|
+
[
|
|
151
|
+
{
|
|
152
|
+
method: "wallet_getCapabilities",
|
|
153
|
+
params: [account.address],
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
10000,
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
logger.console.log("[trails-sdk] capabilities", capabilities)
|
|
160
|
+
|
|
161
|
+
// Check if the chain supports atomic transactions
|
|
162
|
+
const chainHex = `0x${originChainId.toString(16)}` as const
|
|
163
|
+
const chainCapabilities = capabilities[chainHex]
|
|
164
|
+
useSendCalls = chainCapabilities?.atomic?.status === "supported"
|
|
165
|
+
} catch (error) {
|
|
166
|
+
logger.console.error("[trails-sdk] Error getting capabilities", error)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (dryMode) {
|
|
171
|
+
logger.console.log("[trails-sdk] dry mode, skipping send calls")
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (useSendCalls) {
|
|
175
|
+
logger.console.log("[trails-sdk] using sendCalls")
|
|
176
|
+
} else {
|
|
177
|
+
logger.console.log("[trails-sdk] using sendTransaction")
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (useSendCalls) {
|
|
181
|
+
if (!dryMode) {
|
|
182
|
+
const calls: Array<{
|
|
183
|
+
to: `0x${string}`
|
|
184
|
+
data: `0x${string}`
|
|
185
|
+
value?: `0x${string}`
|
|
186
|
+
}> = []
|
|
187
|
+
if (needsNativeFee) {
|
|
188
|
+
calls.push({
|
|
189
|
+
to: originIntentAddress as `0x${string}`,
|
|
190
|
+
data: "0x00",
|
|
191
|
+
value: `0x${BigInt(nativeFee).toString(16)}` as `0x${string}`,
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Add the origin call
|
|
196
|
+
calls.push({
|
|
197
|
+
to: originCallParams.to as `0x${string}`,
|
|
198
|
+
data: originCallParams.data as `0x${string}`,
|
|
199
|
+
value: originCallParams.value
|
|
200
|
+
? `0x${BigInt(originCallParams.value).toString(16)}`
|
|
201
|
+
: "0x0",
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
// Update persistent toast before wallet interaction
|
|
205
|
+
updatePersistentToast(
|
|
206
|
+
"Waiting for Confirmation",
|
|
207
|
+
"Please confirm the transaction in your wallet...",
|
|
208
|
+
"info",
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
// Send the batched call via EIP-7702
|
|
212
|
+
const result = (await walletClient.request({
|
|
213
|
+
method: "wallet_sendCalls",
|
|
214
|
+
params: [
|
|
215
|
+
{
|
|
216
|
+
version: "2.0.0",
|
|
217
|
+
chainId: `0x${originChainId.toString(16)}`,
|
|
218
|
+
atomicRequired: true,
|
|
219
|
+
calls,
|
|
220
|
+
},
|
|
221
|
+
],
|
|
222
|
+
})) as { requestId: `0x${string}` }
|
|
223
|
+
|
|
224
|
+
logger.console.log("[trails-sdk] sendCalls result", result)
|
|
225
|
+
const requestId = result.requestId || (result as any).id
|
|
226
|
+
|
|
227
|
+
// Poll to check if the tx has been submitted
|
|
228
|
+
let txHash: `0x${string}` | undefined
|
|
229
|
+
while (!txHash) {
|
|
230
|
+
const status = (await walletClient.request({
|
|
231
|
+
method: "wallet_getCallsStatus",
|
|
232
|
+
params: [requestId],
|
|
233
|
+
})) as {
|
|
234
|
+
status: "pending" | "submitted" | "failed"
|
|
235
|
+
transactionHash?: `0x${string}`
|
|
236
|
+
error?: string
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
logger.console.log("[trails-sdk] getCallsStatus result", status)
|
|
240
|
+
const receipt = (status as any)?.receipts?.[0]
|
|
241
|
+
|
|
242
|
+
if ((status as any).status === 200 && receipt?.transactionHash) {
|
|
243
|
+
txHash = receipt.transactionHash
|
|
244
|
+
break
|
|
245
|
+
} else if ((status as any).status === 500) {
|
|
246
|
+
throw new Error(`Transaction failed: ${status.error}`)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// wait a bit before polling again
|
|
250
|
+
await new Promise((r) => setTimeout(r, 2000))
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (onOriginSend) {
|
|
254
|
+
onOriginSend()
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Update persistent toast after transaction sent
|
|
258
|
+
const chainInfo = getChainInfo(originChainId)
|
|
259
|
+
updatePersistentToast(
|
|
260
|
+
"Transaction Submitted",
|
|
261
|
+
`Waiting for confirmation on ${chainInfo?.name || "chain"}...`,
|
|
262
|
+
"info",
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
const receipt = await publicClient.waitForTransactionReceipt({
|
|
266
|
+
hash: txHash as `0x${string}`,
|
|
267
|
+
})
|
|
268
|
+
logger.console.log("[trails-sdk] receipt", receipt)
|
|
269
|
+
depositUserTxnReceipt = receipt
|
|
270
|
+
}
|
|
271
|
+
} else {
|
|
272
|
+
if (!dryMode) {
|
|
273
|
+
if (needsNativeFee) {
|
|
274
|
+
// Trigger signature request callback before prompting wallet
|
|
275
|
+
if (checkoutOnHandlers?.triggerCheckoutSignatureRequest) {
|
|
276
|
+
checkoutOnHandlers.triggerCheckoutSignatureRequest()
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const txHashNativeFee = await sendOriginTransaction(
|
|
280
|
+
account,
|
|
281
|
+
walletClient,
|
|
282
|
+
{
|
|
283
|
+
to: originIntentAddress,
|
|
284
|
+
data: "0x00",
|
|
285
|
+
value: nativeFee,
|
|
286
|
+
chainId: originChainId,
|
|
287
|
+
chain,
|
|
288
|
+
} as any,
|
|
289
|
+
{
|
|
290
|
+
depositTokenAmountUsd: depositAmountUsd?.toString(),
|
|
291
|
+
},
|
|
292
|
+
) // TODO: Add proper type
|
|
293
|
+
logger.console.log("[trails-sdk] origin tx native fee", txHashNativeFee)
|
|
294
|
+
|
|
295
|
+
// Trigger signature confirmed callback after successful signing
|
|
296
|
+
if (checkoutOnHandlers?.triggerCheckoutSignatureConfirmed) {
|
|
297
|
+
checkoutOnHandlers.triggerCheckoutSignatureConfirmed()
|
|
298
|
+
}
|
|
299
|
+
// Wait for transaction receipt
|
|
300
|
+
const feeReceipt = await publicClient.waitForTransactionReceipt({
|
|
301
|
+
hash: txHashNativeFee,
|
|
302
|
+
})
|
|
303
|
+
logger.console.log("[trails-sdk] nativeFeeReceipt", feeReceipt)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Show persistent toast for checkout flow
|
|
307
|
+
updatePersistentToast(
|
|
308
|
+
"Payment Started",
|
|
309
|
+
"Waiting for wallet confirmation...",
|
|
310
|
+
"info",
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
// Trigger signature request callback before prompting wallet
|
|
314
|
+
if (checkoutOnHandlers?.triggerCheckoutSignatureRequest) {
|
|
315
|
+
checkoutOnHandlers.triggerCheckoutSignatureRequest()
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const txHash = await sendOriginTransaction(
|
|
319
|
+
account,
|
|
320
|
+
walletClient,
|
|
321
|
+
originCallParams as any,
|
|
322
|
+
{
|
|
323
|
+
depositTokenAmountUsd: depositAmountUsd?.toString(),
|
|
324
|
+
},
|
|
325
|
+
) // TODO: Add proper type
|
|
326
|
+
logger.console.log("[trails-sdk] origin tx", txHash)
|
|
327
|
+
|
|
328
|
+
// Trigger signature confirmed callback after successful signing
|
|
329
|
+
if (checkoutOnHandlers?.triggerCheckoutSignatureConfirmed) {
|
|
330
|
+
checkoutOnHandlers.triggerCheckoutSignatureConfirmed()
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (onOriginSend) {
|
|
334
|
+
onOriginSend()
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (transactionStates[0]) {
|
|
338
|
+
transactionStates[0].state = "pending"
|
|
339
|
+
|
|
340
|
+
try {
|
|
341
|
+
onTransactionStateChange(transactionStates)
|
|
342
|
+
} catch (error) {
|
|
343
|
+
logger.console.error(
|
|
344
|
+
"[trails-sdk] Error calling onTransactionStateChange:",
|
|
345
|
+
error,
|
|
346
|
+
)
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// Wait for transaction receipt
|
|
351
|
+
const receipt = await publicClient.waitForTransactionReceipt({
|
|
352
|
+
hash: txHash,
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
const chainInfo = getChainInfo(originChainId)
|
|
356
|
+
updatePersistentToast(
|
|
357
|
+
"Transfer Confirmed",
|
|
358
|
+
`Your transaction on ${chainInfo?.name || "chain"} has been confirmed`,
|
|
359
|
+
"info",
|
|
360
|
+
)
|
|
361
|
+
|
|
362
|
+
trackTransactionConfirmed({
|
|
363
|
+
transactionHash: txHash,
|
|
364
|
+
chainId: originChainId,
|
|
365
|
+
userAddress: account.address,
|
|
366
|
+
blockNumber: Number(receipt.blockNumber),
|
|
367
|
+
originIntentAddress,
|
|
368
|
+
originTokenSymbol,
|
|
369
|
+
destinationTokenSymbol,
|
|
370
|
+
depositTokenAmountUsd: depositAmountUsd?.toString(),
|
|
371
|
+
})
|
|
372
|
+
|
|
373
|
+
logger.console.log("[trails-sdk] receipt", receipt)
|
|
374
|
+
depositUserTxnReceipt = receipt
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
return depositUserTxnReceipt
|
|
379
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./transactionState.js"
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { TransactionReceipt } from "viem"
|
|
2
|
+
import type { MetaTxnReceipt } from "../types.js"
|
|
3
|
+
import type {
|
|
4
|
+
TransactionState,
|
|
5
|
+
TransactionStateStatus,
|
|
6
|
+
} from "../../transactions.js"
|
|
7
|
+
import { getExplorerUrl } from "../../explorer.js"
|
|
8
|
+
|
|
9
|
+
export function getTransactionStateFromReceipt(
|
|
10
|
+
receipt: TransactionReceipt | MetaTxnReceipt,
|
|
11
|
+
chainId: number,
|
|
12
|
+
label: string = "Transaction",
|
|
13
|
+
): TransactionState {
|
|
14
|
+
let txHash: string = ""
|
|
15
|
+
let state: TransactionStateStatus = "pending"
|
|
16
|
+
let blockNumber: number = 0
|
|
17
|
+
if ("transactionHash" in receipt) {
|
|
18
|
+
txHash = receipt.transactionHash
|
|
19
|
+
state = receipt.status === "success" ? "confirmed" : "failed"
|
|
20
|
+
blockNumber = Number(receipt.blockNumber)
|
|
21
|
+
} else if ("txnHash" in receipt) {
|
|
22
|
+
txHash = receipt.txnHash || ""
|
|
23
|
+
state = receipt.status === "SUCCEEDED" ? "confirmed" : "failed"
|
|
24
|
+
blockNumber = 0 // IntentTransaction doesn't have blockNumber
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
transactionHash: txHash,
|
|
29
|
+
explorerUrl: getExplorerUrl({ txHash, chainId }),
|
|
30
|
+
chainId,
|
|
31
|
+
blockNumber,
|
|
32
|
+
state,
|
|
33
|
+
label,
|
|
34
|
+
}
|
|
35
|
+
}
|