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/config.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
PROD_SEQUENCE_INDEXER_URL,
|
|
3
|
-
PROD_SEQUENCE_API_URL,
|
|
4
3
|
DEFAULT_WALLETCONNECT_PROJECT_ID,
|
|
5
4
|
DEFAULT_SLIPPAGE_TOLERANCE,
|
|
6
5
|
PROD_SEQUENCE_PROJECT_ACCESS_KEY,
|
|
7
6
|
DEV_SEQUENCE_INDEXER_URL,
|
|
8
|
-
DEV_SEQUENCE_API_URL,
|
|
9
7
|
DEV_TRAILS_API_URL,
|
|
10
8
|
DEV_SEQUENCE_PROJECT_ACCESS_KEY,
|
|
11
9
|
DEFAULT_SEQUENCE_ENV,
|
|
@@ -23,7 +21,6 @@ export const globalConfig: {
|
|
|
23
21
|
sequenceProjectAccessKey: string
|
|
24
22
|
sequenceIndexerUrl: string
|
|
25
23
|
sequenceNodeGatewayUrl: string
|
|
26
|
-
sequenceApiUrl: string
|
|
27
24
|
trailsApiUrl: string
|
|
28
25
|
sequenceEnv: SequenceEnv
|
|
29
26
|
walletConnectProjectId: string
|
|
@@ -36,7 +33,6 @@ export const globalConfig: {
|
|
|
36
33
|
sequenceProjectAccessKey: declareSequenceProjectAccessKey(),
|
|
37
34
|
sequenceIndexerUrl: declareSequenceIndexerUrl(),
|
|
38
35
|
sequenceNodeGatewayUrl: declareSequenceNodeGatewayUrl(),
|
|
39
|
-
sequenceApiUrl: declareSequenceApiUrl(),
|
|
40
36
|
trailsApiUrl: declareTrailsApiUrl(),
|
|
41
37
|
walletConnectProjectId: DEFAULT_WALLETCONNECT_PROJECT_ID,
|
|
42
38
|
slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
|
|
@@ -48,27 +44,38 @@ export function declareSequenceEnv(): SequenceEnv {
|
|
|
48
44
|
if (typeof window !== "undefined" && (import.meta as any)?.hot) {
|
|
49
45
|
return "local"
|
|
50
46
|
}
|
|
51
|
-
if (typeof process !== "undefined") {
|
|
52
|
-
if (getEnvVar("ENV") === "local") {
|
|
53
|
-
return "local"
|
|
54
|
-
}
|
|
55
|
-
if (getEnvVar("ENV") === "development" || getEnvVar("ENV") === "dev") {
|
|
56
|
-
return "dev"
|
|
57
|
-
}
|
|
58
47
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
48
|
+
// Check explicit ENV variable first
|
|
49
|
+
const explicitEnv = getEnvVar("ENV")
|
|
50
|
+
if (explicitEnv === "local") {
|
|
51
|
+
return "local"
|
|
52
|
+
}
|
|
53
|
+
if (explicitEnv === "development" || explicitEnv === "dev") {
|
|
54
|
+
return "dev"
|
|
55
|
+
}
|
|
56
|
+
if (explicitEnv === "production" || explicitEnv === "prod") {
|
|
57
|
+
return "prod"
|
|
58
|
+
}
|
|
68
59
|
|
|
69
|
-
|
|
60
|
+
// Special handling for Cloudflare Pages branches
|
|
61
|
+
const cfPagesBranch = getEnvVar("CF_PAGES_BRANCH")
|
|
62
|
+
if (cfPagesBranch) {
|
|
63
|
+
// If running on Cloudflare Pages, all branches except "production" default to dev
|
|
64
|
+
if (cfPagesBranch === "prod" || cfPagesBranch === "production") {
|
|
70
65
|
return "prod"
|
|
71
66
|
}
|
|
67
|
+
// Preview mode and other branches default to dev
|
|
68
|
+
return "dev"
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// If we're in a browser/Cloudflare environment but no explicit env is set,
|
|
72
|
+
// check if we have dev environment variables set (indicating non-prod)
|
|
73
|
+
// This helps with Cloudflare Workers preview mode
|
|
74
|
+
if (typeof window !== "undefined" || typeof process === "undefined") {
|
|
75
|
+
// In browser/Cloudflare Workers context, if no explicit prod indicators,
|
|
76
|
+
// default to dev for safety (unless explicitly set to prod)
|
|
77
|
+
// This prevents accidental prod usage in preview/staging environments
|
|
78
|
+
return "dev"
|
|
72
79
|
}
|
|
73
80
|
|
|
74
81
|
return DEFAULT_SEQUENCE_ENV
|
|
@@ -81,16 +88,6 @@ export function declareSequenceIndexerUrl() {
|
|
|
81
88
|
return DEV_SEQUENCE_INDEXER_URL
|
|
82
89
|
}
|
|
83
90
|
|
|
84
|
-
export function declareSequenceApiUrl() {
|
|
85
|
-
if (declareSequenceEnv() === "prod") {
|
|
86
|
-
return PROD_SEQUENCE_API_URL
|
|
87
|
-
}
|
|
88
|
-
if (declareSequenceEnv() === "local") {
|
|
89
|
-
return getEnvVar("SEQUENCE_API_URL") || DEV_SEQUENCE_API_URL
|
|
90
|
-
}
|
|
91
|
-
return DEV_SEQUENCE_API_URL
|
|
92
|
-
}
|
|
93
|
-
|
|
94
91
|
export function declareTrailsApiUrl() {
|
|
95
92
|
if (declareSequenceEnv() === "prod") {
|
|
96
93
|
return PROD_TRAILS_API_URL
|
|
@@ -109,17 +106,18 @@ export function declareSequenceNodeGatewayUrl() {
|
|
|
109
106
|
}
|
|
110
107
|
|
|
111
108
|
export function declareSequenceProjectAccessKey() {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
109
|
+
// Check for explicit env var override first (works in all environments)
|
|
110
|
+
const envVarKey =
|
|
111
|
+
getEnvVar("SEQUENCE_PROJECT_ACCESS_KEY") ||
|
|
112
|
+
getEnvVar("PROJECT_ACCESS_KEY") ||
|
|
113
|
+
getEnvVar("VITE_SEQUENCE_PROJECT_ACCESS_KEY") ||
|
|
114
|
+
getEnvVar("VITE_PROJECT_ACCESS_KEY")
|
|
115
|
+
if (envVarKey) {
|
|
116
|
+
return envVarKey
|
|
120
117
|
}
|
|
121
118
|
|
|
122
119
|
// Use dev/prod keys based on environment
|
|
120
|
+
const sequenceEnv = declareSequenceEnv()
|
|
123
121
|
if (sequenceEnv === "prod") {
|
|
124
122
|
return PROD_SEQUENCE_PROJECT_ACCESS_KEY
|
|
125
123
|
}
|
|
@@ -171,14 +169,6 @@ export function getSequenceNodeGatewayUrl() {
|
|
|
171
169
|
return globalConfig.sequenceNodeGatewayUrl
|
|
172
170
|
}
|
|
173
171
|
|
|
174
|
-
export function setSequenceApiUrl(sequenceApiUrl: string) {
|
|
175
|
-
globalConfig.sequenceApiUrl = sequenceApiUrl
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export function getSequenceApiUrl() {
|
|
179
|
-
return globalConfig.sequenceApiUrl
|
|
180
|
-
}
|
|
181
|
-
|
|
182
172
|
export function setTrailsApiUrl(trailsApiUrl: string) {
|
|
183
173
|
globalConfig.trailsApiUrl = trailsApiUrl
|
|
184
174
|
}
|
|
@@ -192,16 +182,12 @@ export function setSequenceEnv(sequenceEnv: SequenceEnv) {
|
|
|
192
182
|
|
|
193
183
|
if (sequenceEnv === "prod") {
|
|
194
184
|
setSequenceIndexerUrl(PROD_SEQUENCE_INDEXER_URL)
|
|
195
|
-
setSequenceApiUrl(PROD_SEQUENCE_API_URL)
|
|
196
185
|
setTrailsApiUrl(PROD_TRAILS_API_URL)
|
|
197
186
|
setSequenceNodeGatewayUrl(PROD_SEQUENCE_NODE_GATEWAY_URL)
|
|
198
187
|
setSequenceProjectAccessKey(PROD_SEQUENCE_PROJECT_ACCESS_KEY)
|
|
199
188
|
}
|
|
200
189
|
|
|
201
190
|
if (sequenceEnv === "local") {
|
|
202
|
-
if (getEnvVar("SEQUENCE_API_URL")) {
|
|
203
|
-
setSequenceApiUrl(getEnvVar("SEQUENCE_API_URL"))
|
|
204
|
-
}
|
|
205
191
|
if (getEnvVar("TRAILS_API_URL")) {
|
|
206
192
|
setTrailsApiUrl(getEnvVar("TRAILS_API_URL"))
|
|
207
193
|
}
|
|
@@ -209,7 +195,6 @@ export function setSequenceEnv(sequenceEnv: SequenceEnv) {
|
|
|
209
195
|
|
|
210
196
|
if (sequenceEnv === "dev") {
|
|
211
197
|
setSequenceIndexerUrl(DEV_SEQUENCE_INDEXER_URL)
|
|
212
|
-
setSequenceApiUrl(DEV_SEQUENCE_API_URL)
|
|
213
198
|
setTrailsApiUrl(DEV_TRAILS_API_URL)
|
|
214
199
|
setSequenceNodeGatewayUrl(DEV_SEQUENCE_NODE_GATEWAY_URL)
|
|
215
200
|
setSequenceProjectAccessKey(DEV_SEQUENCE_PROJECT_ACCESS_KEY)
|
|
@@ -272,14 +257,28 @@ export const FeatureFlags = {
|
|
|
272
257
|
}
|
|
273
258
|
|
|
274
259
|
export function getEnvVar(name: string) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
260
|
+
// In Vite/browser environments, check import.meta.env first
|
|
261
|
+
// This is where Vite injects environment variables at build time
|
|
278
262
|
if ((import.meta as any)?.env) {
|
|
279
|
-
|
|
263
|
+
// Check for VITE_ prefixed version first (Vite convention)
|
|
264
|
+
const vitePrefixed = (import.meta as any).env[`VITE_${name}`]
|
|
265
|
+
if (vitePrefixed !== undefined && vitePrefixed !== "") {
|
|
266
|
+
return vitePrefixed
|
|
267
|
+
}
|
|
268
|
+
// Check direct name (for variables injected via vite.config.ts define)
|
|
269
|
+
const direct = (import.meta as any).env[name]
|
|
270
|
+
if (direct !== undefined && direct !== "") {
|
|
271
|
+
return direct
|
|
272
|
+
}
|
|
280
273
|
}
|
|
281
|
-
|
|
282
|
-
|
|
274
|
+
|
|
275
|
+
// Fall back to process.env for Node.js environments
|
|
276
|
+
if (typeof process !== "undefined" && process?.env) {
|
|
277
|
+
const value = process.env[name]
|
|
278
|
+
if (value !== undefined && value !== "") {
|
|
279
|
+
return value
|
|
280
|
+
}
|
|
283
281
|
}
|
|
282
|
+
|
|
284
283
|
return undefined
|
|
285
284
|
}
|
package/src/constants.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TrailsAddressOverrides } from "@0xsequence/trails-api"
|
|
2
2
|
import type { Context as ContextLike } from "@0xsequence/wallet-primitives"
|
|
3
3
|
import type { Address } from "ox"
|
|
4
4
|
|
|
@@ -10,12 +10,13 @@ export const SEQUENCE_V3_CONTRACT_ADDRESSES: ContextLike.Context = {
|
|
|
10
10
|
"0x6041600e3d396021805130553df33d3d36153402601f57363d3d373d363d30545af43d82803e903d91601f57fd5bf3" as Address.Address,
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export const SEQUENCE_V3_CONTRACT_ADDRESSES_OVERRIDES:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
export const SEQUENCE_V3_CONTRACT_ADDRESSES_OVERRIDES: TrailsAddressOverrides =
|
|
14
|
+
{
|
|
15
|
+
sequenceWalletFactoryAddress: SEQUENCE_V3_CONTRACT_ADDRESSES.factory,
|
|
16
|
+
sequenceWalletMainModuleAddress: SEQUENCE_V3_CONTRACT_ADDRESSES.stage1,
|
|
17
|
+
sequenceWalletMainModuleUpgradableAddress:
|
|
18
|
+
SEQUENCE_V3_CONTRACT_ADDRESSES.stage2,
|
|
19
|
+
} as TrailsAddressOverrides
|
|
19
20
|
|
|
20
21
|
export const TRAILS_ROUTER_ADDRESS: Address.Address =
|
|
21
22
|
"0xc4415c5CabD726bA06042af752a528B3dbc263F7"
|
|
@@ -30,11 +31,9 @@ export const DEFAULT_SEQUENCE_ENV = "prod"
|
|
|
30
31
|
|
|
31
32
|
export const PROD_SEQUENCE_NODE_GATEWAY_URL = "https://nodes.sequence.app"
|
|
32
33
|
export const PROD_SEQUENCE_INDEXER_URL = "https://indexer.sequence.app"
|
|
33
|
-
export const PROD_SEQUENCE_API_URL = "https://api.sequence.app"
|
|
34
34
|
export const PROD_TRAILS_API_URL = "https://trails-api.sequence.app"
|
|
35
35
|
export const DEV_SEQUENCE_NODE_GATEWAY_URL = "https://dev-nodes.sequence.app"
|
|
36
36
|
export const DEV_SEQUENCE_INDEXER_URL = "https://dev-indexer.sequence.app"
|
|
37
|
-
export const DEV_SEQUENCE_API_URL = "https://dev-api.sequence.app"
|
|
38
37
|
export const DEV_TRAILS_API_URL = "https://dev-trails-api.sequence-dev.app"
|
|
39
38
|
|
|
40
39
|
export const LOCAL_TRAILS_API_URL = "http://localhost:4422"
|
|
@@ -55,3 +54,6 @@ export const DEFAULT_WALLETCONNECT_PROJECT_ID =
|
|
|
55
54
|
export const SITE_URL = "https://trails.build/"
|
|
56
55
|
|
|
57
56
|
export const DEFAULT_SLIPPAGE_TOLERANCE = "0.05" // 0.001 = 0.1%, 0.005 = 0.5%, 0.03 = 3%, 0.05 = 5%
|
|
57
|
+
|
|
58
|
+
export const DEFAULT_MODE = "pay"
|
|
59
|
+
export const DEFAULT_THEME = "light"
|
package/src/error.ts
CHANGED
|
@@ -21,7 +21,18 @@ export function getErrorString(err: unknown): string {
|
|
|
21
21
|
return err instanceof Error ? err.message : (err?.toString() ?? "")
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function
|
|
24
|
+
export function getIsUserRejectionError(
|
|
25
|
+
err: unknown,
|
|
26
|
+
): err is UserRejectionError {
|
|
27
|
+
// Check if it's an instance of UserRejectionError (or has the name property)
|
|
28
|
+
if (
|
|
29
|
+
err instanceof UserRejectionError ||
|
|
30
|
+
(err instanceof Error && err.name === "UserRejectionError")
|
|
31
|
+
) {
|
|
32
|
+
return true
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Check if the error message indicates a user rejection
|
|
25
36
|
const isRejected = /rejected|denied|user rejected the request/gi.test(
|
|
26
37
|
getErrorString(err).toLowerCase(),
|
|
27
38
|
)
|
|
@@ -43,6 +54,13 @@ export class InsufficientBalanceError extends Error {
|
|
|
43
54
|
}
|
|
44
55
|
}
|
|
45
56
|
|
|
57
|
+
export class UserRejectionError extends Error {
|
|
58
|
+
constructor(message: string) {
|
|
59
|
+
super(message)
|
|
60
|
+
this.name = "UserRejectionError"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
46
64
|
export function getIsApiError(err: unknown) {
|
|
47
65
|
const isApiError = /request aborted|not deployed/gi.test(
|
|
48
66
|
getErrorString(err).toLowerCase(),
|
|
@@ -144,8 +162,8 @@ export function getPrettifiedErrorMessage(
|
|
|
144
162
|
if (isApiError) {
|
|
145
163
|
return "An API error occurred. Please try again later."
|
|
146
164
|
}
|
|
147
|
-
const
|
|
148
|
-
if (
|
|
165
|
+
const isUserRejectionError = getIsUserRejectionError(err)
|
|
166
|
+
if (isUserRejectionError) {
|
|
149
167
|
return "The wallet rejected the request. Please try again."
|
|
150
168
|
}
|
|
151
169
|
const isWalletAlreadyConnected = getIsWalletAlreadyConnectedError(err)
|
package/src/fees.ts
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import type { Intent } from "@0xsequence/trails-api"
|
|
2
|
+
import { getTokenInfo } from "./tokens.js"
|
|
3
|
+
import { formatRawAmount, formatUsdAmountDisplay } from "./tokenBalances.js"
|
|
4
|
+
import { zeroAddress } from "viem"
|
|
5
|
+
|
|
6
|
+
export interface FeeItem {
|
|
7
|
+
amount: string
|
|
8
|
+
tokenSymbol: string
|
|
9
|
+
tokenAddress: string
|
|
10
|
+
chainId: number
|
|
11
|
+
usdValue: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface TrailsFeeBreakdown {
|
|
15
|
+
originRelayFee?: FeeItem
|
|
16
|
+
destinationRelayFee?: FeeItem
|
|
17
|
+
providerFee?: FeeItem
|
|
18
|
+
trailsFee?: FeeItem
|
|
19
|
+
totalUsdValue?: string
|
|
20
|
+
originChainId?: number
|
|
21
|
+
destinationChainId?: number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Helper function to format token amounts with proper decimal conversion
|
|
25
|
+
async function formatTokenAmount(
|
|
26
|
+
amount: string | number | undefined,
|
|
27
|
+
tokenAddress: string,
|
|
28
|
+
chainId: number,
|
|
29
|
+
): Promise<string> {
|
|
30
|
+
if (!amount) return "0"
|
|
31
|
+
const num = typeof amount === "string" ? parseFloat(amount) : amount
|
|
32
|
+
if (num === 0) return "0"
|
|
33
|
+
|
|
34
|
+
// Get token info to determine decimals
|
|
35
|
+
const tokenInfo = await getTokenInfo(chainId, tokenAddress)
|
|
36
|
+
if (!tokenInfo?.decimals) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
`Token decimals not found for token ${tokenAddress} on chain ${chainId}`,
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Use existing formatRawAmount utility
|
|
43
|
+
const formatted = formatRawAmount(BigInt(Math.floor(num)), tokenInfo.decimals)
|
|
44
|
+
|
|
45
|
+
// Handle very small amounts
|
|
46
|
+
const numFormatted = parseFloat(formatted)
|
|
47
|
+
if (numFormatted < 0.000001 && numFormatted > 0) return "<0.000001"
|
|
48
|
+
|
|
49
|
+
return formatted
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Extract fee breakdown from intent data
|
|
53
|
+
export async function extractTrailsFeeBreakdown(
|
|
54
|
+
intent: Intent,
|
|
55
|
+
): Promise<TrailsFeeBreakdown | null> {
|
|
56
|
+
const fees = intent?.fees
|
|
57
|
+
if (!fees) {
|
|
58
|
+
return null
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Get chain IDs from the calls array to determine origin and destination chains
|
|
62
|
+
const calls = intent?.calls || []
|
|
63
|
+
const originChainId: number | undefined = calls[0]?.chainId // First call is origin chain
|
|
64
|
+
const destinationChainId: number | undefined = calls[1]?.chainId // Second call is destination chain
|
|
65
|
+
|
|
66
|
+
// Use the origin and destination gas fees
|
|
67
|
+
const originChainQuote = fees.originGas
|
|
68
|
+
const destinationChainQuote = fees.destinationGas
|
|
69
|
+
|
|
70
|
+
// If we can't find any chain quotes, return null
|
|
71
|
+
if (!originChainQuote && !destinationChainQuote) {
|
|
72
|
+
console.warn(
|
|
73
|
+
"[trails-sdk] Could not find any chain quotes for fee breakdown",
|
|
74
|
+
{
|
|
75
|
+
originChainId,
|
|
76
|
+
destinationChainId,
|
|
77
|
+
},
|
|
78
|
+
)
|
|
79
|
+
return null
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const breakdown: TrailsFeeBreakdown = {}
|
|
83
|
+
|
|
84
|
+
// Extract origin relay fee if available
|
|
85
|
+
if (originChainQuote && originChainId !== undefined) {
|
|
86
|
+
const originTokenSymbol = originChainQuote.nativeTokenSymbol || "ETH"
|
|
87
|
+
const originChainIdNum =
|
|
88
|
+
typeof originChainId === "bigint" ? Number(originChainId) : originChainId
|
|
89
|
+
const nativeTokenAddress = zeroAddress
|
|
90
|
+
|
|
91
|
+
breakdown.originRelayFee = {
|
|
92
|
+
amount: await formatTokenAmount(
|
|
93
|
+
originChainQuote.totalFeeAmount.toString(),
|
|
94
|
+
nativeTokenAddress,
|
|
95
|
+
originChainIdNum,
|
|
96
|
+
),
|
|
97
|
+
tokenSymbol: originTokenSymbol,
|
|
98
|
+
tokenAddress: nativeTokenAddress,
|
|
99
|
+
chainId: originChainIdNum,
|
|
100
|
+
usdValue: formatUsdAmountDisplay(originChainQuote.totalFeeUsd),
|
|
101
|
+
}
|
|
102
|
+
breakdown.originChainId = originChainIdNum
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Extract destination relay fee if available
|
|
106
|
+
if (destinationChainQuote && destinationChainId !== undefined) {
|
|
107
|
+
const destinationTokenSymbol =
|
|
108
|
+
destinationChainQuote.nativeTokenSymbol || "ETH"
|
|
109
|
+
const destinationChainIdNum =
|
|
110
|
+
typeof destinationChainId === "bigint"
|
|
111
|
+
? Number(destinationChainId)
|
|
112
|
+
: destinationChainId
|
|
113
|
+
const nativeTokenAddress = zeroAddress
|
|
114
|
+
|
|
115
|
+
breakdown.destinationRelayFee = {
|
|
116
|
+
amount: await formatTokenAmount(
|
|
117
|
+
destinationChainQuote.totalFeeAmount.toString(),
|
|
118
|
+
nativeTokenAddress,
|
|
119
|
+
destinationChainIdNum,
|
|
120
|
+
),
|
|
121
|
+
tokenSymbol: destinationTokenSymbol,
|
|
122
|
+
tokenAddress: nativeTokenAddress,
|
|
123
|
+
chainId: destinationChainIdNum,
|
|
124
|
+
usdValue: formatUsdAmountDisplay(destinationChainQuote.totalFeeUsd),
|
|
125
|
+
}
|
|
126
|
+
breakdown.destinationChainId = destinationChainIdNum
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Extract provider fee from provider fees if available
|
|
130
|
+
const providerFeeAmount = fees.provider?.quoteProviderFeeUsd
|
|
131
|
+
const providerFeeRawAmount = fees.provider?.quoteProviderFee
|
|
132
|
+
if (
|
|
133
|
+
(providerFeeAmount !== undefined || providerFeeRawAmount !== undefined) &&
|
|
134
|
+
originChainId !== undefined
|
|
135
|
+
) {
|
|
136
|
+
const feeTokenAddress = fees.feeTokenAddress || zeroAddress
|
|
137
|
+
const originChainIdNum =
|
|
138
|
+
typeof originChainId === "bigint" ? Number(originChainId) : originChainId
|
|
139
|
+
|
|
140
|
+
// Get token info to determine the actual token symbol
|
|
141
|
+
const feeTokenInfo = await getTokenInfo(originChainIdNum, feeTokenAddress)
|
|
142
|
+
if (!feeTokenInfo?.symbol) {
|
|
143
|
+
throw new Error(
|
|
144
|
+
`Token symbol not found for provider fee token ${feeTokenAddress} on chain ${originChainIdNum}`,
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
breakdown.providerFee = {
|
|
149
|
+
amount: await formatTokenAmount(
|
|
150
|
+
providerFeeRawAmount?.toString(),
|
|
151
|
+
feeTokenAddress,
|
|
152
|
+
originChainIdNum,
|
|
153
|
+
),
|
|
154
|
+
tokenSymbol: feeTokenInfo.symbol,
|
|
155
|
+
tokenAddress: feeTokenAddress,
|
|
156
|
+
chainId: originChainIdNum,
|
|
157
|
+
usdValue: formatUsdAmountDisplay(providerFeeAmount),
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Extract Trails platform fee from provider fees if available
|
|
162
|
+
const trailsFeeAmount = fees.provider?.trailsFeeUsd
|
|
163
|
+
const trailsFeeRawAmount = fees.provider?.trailsFee
|
|
164
|
+
if (
|
|
165
|
+
(trailsFeeAmount !== undefined || trailsFeeRawAmount !== undefined) &&
|
|
166
|
+
originChainId !== undefined
|
|
167
|
+
) {
|
|
168
|
+
const feeTokenAddress = fees.feeTokenAddress || zeroAddress
|
|
169
|
+
const originChainIdNum =
|
|
170
|
+
typeof originChainId === "bigint" ? Number(originChainId) : originChainId
|
|
171
|
+
|
|
172
|
+
// Get token info to determine the actual token symbol
|
|
173
|
+
const feeTokenInfo = await getTokenInfo(originChainIdNum, feeTokenAddress)
|
|
174
|
+
if (!feeTokenInfo?.symbol) {
|
|
175
|
+
throw new Error(
|
|
176
|
+
`Token symbol not found for trails fee token ${feeTokenAddress} on chain ${originChainIdNum}`,
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
breakdown.trailsFee = {
|
|
181
|
+
amount: await formatTokenAmount(
|
|
182
|
+
trailsFeeRawAmount?.toString(),
|
|
183
|
+
feeTokenAddress,
|
|
184
|
+
originChainIdNum,
|
|
185
|
+
),
|
|
186
|
+
tokenSymbol: feeTokenInfo.symbol,
|
|
187
|
+
tokenAddress: feeTokenAddress,
|
|
188
|
+
chainId: originChainIdNum,
|
|
189
|
+
usdValue: formatUsdAmountDisplay(trailsFeeAmount),
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Calculate total USD value from the actual data
|
|
194
|
+
const originUsd =
|
|
195
|
+
typeof originChainQuote?.totalFeeUsd === "string"
|
|
196
|
+
? parseFloat(originChainQuote.totalFeeUsd)
|
|
197
|
+
: originChainQuote?.totalFeeUsd || 0
|
|
198
|
+
const destinationUsd =
|
|
199
|
+
typeof destinationChainQuote?.totalFeeUsd === "string"
|
|
200
|
+
? parseFloat(destinationChainQuote.totalFeeUsd)
|
|
201
|
+
: destinationChainQuote?.totalFeeUsd || 0
|
|
202
|
+
const providerUsd =
|
|
203
|
+
typeof providerFeeAmount === "number" ? providerFeeAmount : 0
|
|
204
|
+
const trailsUsd = typeof trailsFeeAmount === "number" ? trailsFeeAmount : 0
|
|
205
|
+
const totalUsd = originUsd + destinationUsd + providerUsd + trailsUsd
|
|
206
|
+
|
|
207
|
+
breakdown.totalUsdValue = formatUsdAmountDisplay(totalUsd)
|
|
208
|
+
|
|
209
|
+
return breakdown
|
|
210
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
// Be explicit about what we export
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export {
|
|
4
|
+
InsufficientBalanceError,
|
|
5
|
+
UserRejectionError,
|
|
6
|
+
getIsUserRejectionError,
|
|
7
|
+
} from "./error.js"
|
|
4
8
|
export {
|
|
5
9
|
getSupportedChains,
|
|
6
10
|
useSupportedChains,
|
|
@@ -13,7 +17,6 @@ export {
|
|
|
13
17
|
useIndexerGatewayClient,
|
|
14
18
|
} from "./indexerClient.js"
|
|
15
19
|
export type {
|
|
16
|
-
GetIntentCallsPayloadsReturn,
|
|
17
20
|
OriginCallParams,
|
|
18
21
|
QuoteProvider,
|
|
19
22
|
TrailsFee,
|
|
@@ -21,15 +24,20 @@ export type {
|
|
|
21
24
|
export {
|
|
22
25
|
calculateIntentAddress,
|
|
23
26
|
calculateOriginAndDestinationIntentAddresses,
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
commitIntent,
|
|
28
|
+
getIntent,
|
|
26
29
|
sendOriginTransaction,
|
|
27
30
|
} from "./intents.js"
|
|
28
|
-
export type {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
export type { IntentReceiptStatus } from "./intentReceiptMonitor.js"
|
|
32
|
+
export { useIntentReceiptMonitor } from "./intentReceiptMonitor.js"
|
|
33
|
+
export {
|
|
34
|
+
pollIntentReceipt,
|
|
35
|
+
type IntentReceiptPollerOptions,
|
|
36
|
+
type IntentReceiptPollerCallbacks,
|
|
37
|
+
type OnOriginTransactionFound,
|
|
38
|
+
type OnDestinationTransactionFound,
|
|
39
|
+
type OnReceiptUpdate,
|
|
40
|
+
} from "./intentReceiptPoller.js"
|
|
33
41
|
export {
|
|
34
42
|
prepareSend,
|
|
35
43
|
useQuote,
|
|
@@ -82,20 +90,20 @@ export type { SupportedToken } from "./tokens.js"
|
|
|
82
90
|
export { getTxTimeDiff } from "./transactions.js"
|
|
83
91
|
export { useTrails } from "./trails.js"
|
|
84
92
|
export type { WagmiAccount } from "./trails.js"
|
|
93
|
+
export {
|
|
94
|
+
useCommitIntent,
|
|
95
|
+
useExecuteIntent,
|
|
96
|
+
} from "./mutations.js"
|
|
85
97
|
export type { Mode } from "./mode.js"
|
|
86
98
|
export { TRAILS_ROUTER_PLACEHOLDER_AMOUNT } from "./trailsRouter.js"
|
|
87
99
|
export { getERC20TransferData } from "./encoders.js"
|
|
88
|
-
export { getRelayer, useRelayers } from "./relayer.js"
|
|
89
|
-
export { relayerSendMetaTx, getMetaTxnReceipt } from "./metaTxns.js"
|
|
90
100
|
export {
|
|
91
101
|
declareSequenceEnv,
|
|
92
102
|
getSequenceProjectAccessKey,
|
|
93
|
-
getSequenceApiUrl,
|
|
94
103
|
getTrailsApiUrl,
|
|
95
104
|
getSequenceIndexerUrl,
|
|
96
105
|
getSequenceEnv,
|
|
97
106
|
setSequenceProjectAccessKey,
|
|
98
|
-
setSequenceApiUrl,
|
|
99
107
|
setTrailsApiUrl,
|
|
100
108
|
setSequenceIndexerUrl,
|
|
101
109
|
setSequenceNodeGatewayUrl,
|
|
@@ -115,3 +123,17 @@ export {
|
|
|
115
123
|
useTrailsClient,
|
|
116
124
|
TrailsClient,
|
|
117
125
|
} from "./trailsClient.js"
|
|
126
|
+
export type {
|
|
127
|
+
IntentReceipt,
|
|
128
|
+
IntentTransaction as IntentTransactionReceipt,
|
|
129
|
+
IntentStatus,
|
|
130
|
+
TransactionStatus,
|
|
131
|
+
WaitIntentReceiptRequest,
|
|
132
|
+
WaitIntentReceiptResponse,
|
|
133
|
+
GetIntentReceiptRequest,
|
|
134
|
+
GetIntentReceiptResponse,
|
|
135
|
+
QuoteIntentRequest,
|
|
136
|
+
Intent,
|
|
137
|
+
ExecuteIntentRequest,
|
|
138
|
+
ExecuteIntentResponse,
|
|
139
|
+
} from "@0xsequence/trails-api"
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { TrailsClient } from "./trailsClient.js"
|
|
2
|
+
import type {
|
|
3
|
+
IntentReceipt,
|
|
4
|
+
WaitIntentReceiptResponse,
|
|
5
|
+
} from "@0xsequence/trails-api"
|
|
6
|
+
import { type Query, useQuery } from "@tanstack/react-query"
|
|
7
|
+
import { logger } from "./logger.js"
|
|
8
|
+
|
|
9
|
+
const POLL_INTERVAL = 150 // 150 ms
|
|
10
|
+
|
|
11
|
+
export type IntentReceiptStatus = {
|
|
12
|
+
intentReceipt: IntentReceipt | null
|
|
13
|
+
done: boolean
|
|
14
|
+
isLoading: boolean
|
|
15
|
+
isError: boolean
|
|
16
|
+
error: Error | null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Hook to monitor intent execution status using the WaitIntentReceipt API.
|
|
21
|
+
* This replaces the old useMetaTxnsMonitor approach which polled individual meta-transactions.
|
|
22
|
+
*
|
|
23
|
+
* The WaitIntentReceipt API is a long-polling endpoint that:
|
|
24
|
+
* - Blocks up to 28 seconds waiting for status changes
|
|
25
|
+
* - Returns unified status for both origin and destination transactions
|
|
26
|
+
* - Sets done=true when intent reaches terminal status (SUCCEEDED or FAILED)
|
|
27
|
+
*
|
|
28
|
+
* @param intentId - The intent ID to monitor (usually committedOriginIntentAddress)
|
|
29
|
+
* @param trailsClient - TrailsClient instance for API calls
|
|
30
|
+
* @returns IntentReceiptStatus with current receipt, done flag, and loading states
|
|
31
|
+
*/
|
|
32
|
+
export const useIntentReceiptMonitor = (
|
|
33
|
+
intentId: string | undefined,
|
|
34
|
+
trailsClient: TrailsClient,
|
|
35
|
+
): IntentReceiptStatus => {
|
|
36
|
+
const queryResult = useQuery({
|
|
37
|
+
queryKey: ["waitIntentReceipt", intentId],
|
|
38
|
+
queryFn: async (): Promise<WaitIntentReceiptResponse> => {
|
|
39
|
+
if (!intentId) {
|
|
40
|
+
throw new Error("Intent ID is required for monitoring")
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
logger.console.log(
|
|
44
|
+
`[trails-sdk] 🔍 Monitoring intent receipt for ${intentId}`,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
const response = await trailsClient.waitIntentReceipt({
|
|
48
|
+
intentId,
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
logger.console.log(
|
|
52
|
+
`[trails-sdk] 📊 Intent ${intentId} status: ${response.intentReceipt.status}, done: ${response.done}`,
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
return response
|
|
56
|
+
},
|
|
57
|
+
enabled: !!intentId,
|
|
58
|
+
refetchIntervalInBackground: true,
|
|
59
|
+
refetchInterval: (
|
|
60
|
+
query: Query<
|
|
61
|
+
WaitIntentReceiptResponse,
|
|
62
|
+
Error,
|
|
63
|
+
WaitIntentReceiptResponse,
|
|
64
|
+
ReadonlyArray<unknown>
|
|
65
|
+
>,
|
|
66
|
+
) => {
|
|
67
|
+
const data = query.state.data
|
|
68
|
+
|
|
69
|
+
// If no data yet, continue polling
|
|
70
|
+
if (!data) return POLL_INTERVAL
|
|
71
|
+
|
|
72
|
+
// If done flag is true, stop polling
|
|
73
|
+
if (data.done) {
|
|
74
|
+
logger.console.log(
|
|
75
|
+
`[trails-sdk] ✅ Intent monitoring complete for ${intentId}`,
|
|
76
|
+
)
|
|
77
|
+
return false
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Otherwise continue polling
|
|
81
|
+
return POLL_INTERVAL
|
|
82
|
+
},
|
|
83
|
+
retry: (failureCount: number, error: Error) => {
|
|
84
|
+
if (failureCount >= 30) {
|
|
85
|
+
logger.console.error(
|
|
86
|
+
`[trails-sdk] ❌ Giving up on intent ${intentId} after 30 failed API attempts:`,
|
|
87
|
+
error,
|
|
88
|
+
)
|
|
89
|
+
return false
|
|
90
|
+
}
|
|
91
|
+
return true
|
|
92
|
+
},
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
intentReceipt: queryResult.data?.intentReceipt ?? null,
|
|
97
|
+
done: queryResult.data?.done ?? false,
|
|
98
|
+
isLoading: queryResult.isLoading,
|
|
99
|
+
isError: queryResult.isError,
|
|
100
|
+
error: queryResult.error,
|
|
101
|
+
}
|
|
102
|
+
}
|