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,299 @@
|
|
|
1
|
+
import type { TrailsClient } from "./trailsClient.js"
|
|
2
|
+
import type {
|
|
3
|
+
IntentReceipt,
|
|
4
|
+
WaitIntentReceiptResponse,
|
|
5
|
+
TransactionStatus,
|
|
6
|
+
} from "@0xsequence/trails-api"
|
|
7
|
+
import { logger } from "./logger.js"
|
|
8
|
+
|
|
9
|
+
const POLL_INTERVAL = 150 // 150 ms
|
|
10
|
+
const MAX_WAIT_TIME = 5 * 60 * 1000 // 5 minutes
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Callback invoked when the deposit transaction hash is discovered (for gasless flows).
|
|
14
|
+
* @param txHash - The transaction hash of the deposit transaction
|
|
15
|
+
* @param receipt - The full IntentReceipt containing additional metadata
|
|
16
|
+
*/
|
|
17
|
+
export type OnDepositTransactionFound = (
|
|
18
|
+
txHash: string,
|
|
19
|
+
receipt: IntentReceipt,
|
|
20
|
+
) => Promise<void>
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Callback invoked when the origin transaction hash is discovered.
|
|
24
|
+
* @param txHash - The transaction hash of the origin transaction
|
|
25
|
+
* @param receipt - The full IntentReceipt containing additional metadata
|
|
26
|
+
*/
|
|
27
|
+
export type OnOriginTransactionFound = (
|
|
28
|
+
txHash: string,
|
|
29
|
+
receipt: IntentReceipt,
|
|
30
|
+
) => Promise<void>
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Callback invoked when the destination transaction hash is discovered.
|
|
34
|
+
* @param txHash - The transaction hash of the destination transaction
|
|
35
|
+
* @param receipt - The full IntentReceipt containing additional metadata
|
|
36
|
+
*/
|
|
37
|
+
export type OnDestinationTransactionFound = (
|
|
38
|
+
txHash: string,
|
|
39
|
+
receipt: IntentReceipt,
|
|
40
|
+
) => Promise<void>
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Callback invoked when the intent receipt is updated (regardless of which field changed).
|
|
44
|
+
* @param receipt - The full IntentReceipt
|
|
45
|
+
* @param done - Whether the intent has reached a terminal status
|
|
46
|
+
*/
|
|
47
|
+
export type OnReceiptUpdate = (
|
|
48
|
+
receipt: IntentReceipt,
|
|
49
|
+
done: boolean,
|
|
50
|
+
) => Promise<void>
|
|
51
|
+
|
|
52
|
+
export interface IntentReceiptPollerCallbacks {
|
|
53
|
+
onDepositTransactionFound?: OnDepositTransactionFound
|
|
54
|
+
onOriginTransactionFound?: OnOriginTransactionFound
|
|
55
|
+
onDestinationTransactionFound?: OnDestinationTransactionFound
|
|
56
|
+
onReceiptUpdate?: OnReceiptUpdate
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface IntentReceiptPollerOptions {
|
|
60
|
+
intentId: string
|
|
61
|
+
trailsClient: TrailsClient
|
|
62
|
+
callbacks?: IntentReceiptPollerCallbacks
|
|
63
|
+
maxWaitTime?: number
|
|
64
|
+
pollInterval?: number
|
|
65
|
+
abortSignal?: AbortSignal
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Unified intent receipt poller that monitors a single intent ID and invokes callbacks
|
|
70
|
+
* as origin and destination transactions are discovered. This consolidates what was
|
|
71
|
+
* previously done via separate polling loops.
|
|
72
|
+
*
|
|
73
|
+
* @param options - Configuration for polling including intent ID, client, and callbacks
|
|
74
|
+
* @returns A promise that resolves when the intent reaches a terminal status or times out
|
|
75
|
+
*
|
|
76
|
+
* Usage:
|
|
77
|
+
* ```
|
|
78
|
+
* const poller = pollIntentReceipt({
|
|
79
|
+
* intentId: intent.intentId,
|
|
80
|
+
* trailsClient,
|
|
81
|
+
* callbacks: {
|
|
82
|
+
* onOriginTransactionFound: async (txHash, receipt) => {
|
|
83
|
+
* // Handle origin transaction discovery
|
|
84
|
+
* },
|
|
85
|
+
* onDestinationTransactionFound: async (txHash, receipt) => {
|
|
86
|
+
* // Handle destination transaction discovery
|
|
87
|
+
* },
|
|
88
|
+
* onReceiptUpdate: async (receipt, done) => {
|
|
89
|
+
* // Handle any receipt update
|
|
90
|
+
* },
|
|
91
|
+
* },
|
|
92
|
+
* })
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export async function pollIntentReceipt(
|
|
96
|
+
options: IntentReceiptPollerOptions,
|
|
97
|
+
): Promise<IntentReceipt | null> {
|
|
98
|
+
const {
|
|
99
|
+
intentId,
|
|
100
|
+
trailsClient,
|
|
101
|
+
callbacks,
|
|
102
|
+
maxWaitTime = MAX_WAIT_TIME,
|
|
103
|
+
pollInterval = POLL_INTERVAL,
|
|
104
|
+
abortSignal,
|
|
105
|
+
} = options
|
|
106
|
+
|
|
107
|
+
const startTime = Date.now()
|
|
108
|
+
let lastDepositTxHash: string | undefined
|
|
109
|
+
let lastOriginTxHash: string | undefined
|
|
110
|
+
let lastDestinationTxHash: string | undefined
|
|
111
|
+
let lastReceipt: IntentReceipt | null = null
|
|
112
|
+
let lastReceiptStates: TransactionStatus[] = []
|
|
113
|
+
|
|
114
|
+
logger.console.log("[trails-sdk] Starting unified intent receipt polling", {
|
|
115
|
+
intentId,
|
|
116
|
+
maxWaitTime,
|
|
117
|
+
pollInterval,
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
try {
|
|
121
|
+
while (Date.now() - startTime < maxWaitTime) {
|
|
122
|
+
// Check abort signal
|
|
123
|
+
if (abortSignal?.aborted) {
|
|
124
|
+
logger.console.log(
|
|
125
|
+
"[trails-sdk] Intent receipt polling aborted via signal",
|
|
126
|
+
{
|
|
127
|
+
intentId,
|
|
128
|
+
},
|
|
129
|
+
)
|
|
130
|
+
return lastReceipt
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
// Perform single waitIntentReceipt call
|
|
135
|
+
const response: WaitIntentReceiptResponse =
|
|
136
|
+
await trailsClient.waitIntentReceipt({
|
|
137
|
+
intentId,
|
|
138
|
+
lastReceiptStates,
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
const receipt = response.intentReceipt
|
|
142
|
+
lastReceipt = receipt
|
|
143
|
+
lastReceiptStates = response.receiptStates
|
|
144
|
+
|
|
145
|
+
logger.console.log("[trails-sdk] Unified intent receipt update", {
|
|
146
|
+
intentId,
|
|
147
|
+
status: receipt.status,
|
|
148
|
+
done: response.done,
|
|
149
|
+
depositTxHash: receipt.depositTransaction?.txnHash,
|
|
150
|
+
originTxHash: receipt.originTransaction?.txnHash,
|
|
151
|
+
destinationTxHash: receipt.destinationTransaction?.txnHash,
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
// Check if deposit transaction was discovered (and not already reported)
|
|
155
|
+
// This is used for gasless flows where the user's deposit is tracked separately
|
|
156
|
+
if (
|
|
157
|
+
receipt.depositTransaction?.txnHash &&
|
|
158
|
+
receipt.depositTransaction.txnHash !== lastDepositTxHash
|
|
159
|
+
) {
|
|
160
|
+
lastDepositTxHash = receipt.depositTransaction.txnHash
|
|
161
|
+
logger.console.log(
|
|
162
|
+
"[trails-sdk] Deposit transaction discovered via unified poller",
|
|
163
|
+
{
|
|
164
|
+
intentId,
|
|
165
|
+
txHash: lastDepositTxHash,
|
|
166
|
+
},
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
if (callbacks?.onDepositTransactionFound) {
|
|
170
|
+
try {
|
|
171
|
+
await callbacks.onDepositTransactionFound(
|
|
172
|
+
lastDepositTxHash,
|
|
173
|
+
receipt,
|
|
174
|
+
)
|
|
175
|
+
} catch (error) {
|
|
176
|
+
logger.console.error(
|
|
177
|
+
"[trails-sdk] Error in onDepositTransactionFound callback",
|
|
178
|
+
{
|
|
179
|
+
error: error instanceof Error ? error.message : String(error),
|
|
180
|
+
},
|
|
181
|
+
)
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Check if origin transaction was discovered (and not already reported)
|
|
187
|
+
if (
|
|
188
|
+
receipt.originTransaction?.txnHash &&
|
|
189
|
+
receipt.originTransaction.txnHash !== lastOriginTxHash
|
|
190
|
+
) {
|
|
191
|
+
lastOriginTxHash = receipt.originTransaction.txnHash
|
|
192
|
+
logger.console.log(
|
|
193
|
+
"[trails-sdk] Origin transaction discovered via unified poller",
|
|
194
|
+
{
|
|
195
|
+
intentId,
|
|
196
|
+
txHash: lastOriginTxHash,
|
|
197
|
+
},
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
if (callbacks?.onOriginTransactionFound) {
|
|
201
|
+
try {
|
|
202
|
+
await callbacks.onOriginTransactionFound(
|
|
203
|
+
lastOriginTxHash,
|
|
204
|
+
receipt,
|
|
205
|
+
)
|
|
206
|
+
} catch (error) {
|
|
207
|
+
logger.console.error(
|
|
208
|
+
"[trails-sdk] Error in onOriginTransactionFound callback",
|
|
209
|
+
{
|
|
210
|
+
error: error instanceof Error ? error.message : String(error),
|
|
211
|
+
},
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Check if destination transaction was discovered (and not already reported)
|
|
218
|
+
if (
|
|
219
|
+
receipt.destinationTransaction?.txnHash &&
|
|
220
|
+
receipt.destinationTransaction.txnHash !== lastDestinationTxHash
|
|
221
|
+
) {
|
|
222
|
+
lastDestinationTxHash = receipt.destinationTransaction.txnHash
|
|
223
|
+
logger.console.log(
|
|
224
|
+
"[trails-sdk] Destination transaction discovered via unified poller",
|
|
225
|
+
{
|
|
226
|
+
intentId,
|
|
227
|
+
txHash: lastDestinationTxHash,
|
|
228
|
+
},
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
if (callbacks?.onDestinationTransactionFound) {
|
|
232
|
+
try {
|
|
233
|
+
await callbacks.onDestinationTransactionFound(
|
|
234
|
+
lastDestinationTxHash,
|
|
235
|
+
receipt,
|
|
236
|
+
)
|
|
237
|
+
} catch (error) {
|
|
238
|
+
logger.console.error(
|
|
239
|
+
"[trails-sdk] Error in onDestinationTransactionFound callback",
|
|
240
|
+
{
|
|
241
|
+
error: error instanceof Error ? error.message : String(error),
|
|
242
|
+
},
|
|
243
|
+
)
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Invoke generic receipt update callback
|
|
249
|
+
if (callbacks?.onReceiptUpdate) {
|
|
250
|
+
try {
|
|
251
|
+
await callbacks.onReceiptUpdate(receipt, response.done)
|
|
252
|
+
} catch (error) {
|
|
253
|
+
logger.console.error(
|
|
254
|
+
"[trails-sdk] Error in onReceiptUpdate callback",
|
|
255
|
+
{
|
|
256
|
+
error: error instanceof Error ? error.message : String(error),
|
|
257
|
+
},
|
|
258
|
+
)
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// If intent is done, stop polling
|
|
263
|
+
if (response.done) {
|
|
264
|
+
logger.console.log("[trails-sdk] Intent receipt polling complete", {
|
|
265
|
+
intentId,
|
|
266
|
+
status: receipt.status,
|
|
267
|
+
})
|
|
268
|
+
return receipt
|
|
269
|
+
}
|
|
270
|
+
} catch (error) {
|
|
271
|
+
logger.console.warn("[trails-sdk] Error polling intent receipt", {
|
|
272
|
+
intentId,
|
|
273
|
+
error: error instanceof Error ? error.message : String(error),
|
|
274
|
+
})
|
|
275
|
+
// Continue polling on error
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Wait a very short period of time before next poll.
|
|
279
|
+
// We do not want to wait long, as we want quick feedback to users
|
|
280
|
+
// on state changes.
|
|
281
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval))
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
logger.console.warn("[trails-sdk] Intent receipt polling timeout", {
|
|
285
|
+
intentId,
|
|
286
|
+
maxWaitTime,
|
|
287
|
+
})
|
|
288
|
+
return lastReceipt
|
|
289
|
+
} catch (error) {
|
|
290
|
+
logger.console.error(
|
|
291
|
+
"[trails-sdk] Unexpected error in intent receipt polling",
|
|
292
|
+
{
|
|
293
|
+
intentId,
|
|
294
|
+
error: error instanceof Error ? error.message : String(error),
|
|
295
|
+
},
|
|
296
|
+
)
|
|
297
|
+
return lastReceipt
|
|
298
|
+
}
|
|
299
|
+
}
|