0xtrails 0.6.6 → 0.7.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 +10 -2
- package/dist/aave.d.ts.map +1 -1
- package/dist/analytics.d.ts +26 -0
- package/dist/analytics.d.ts.map +1 -1
- package/dist/{ccip-CbJrlK-L.js → ccip-fConRNoG.js} +21 -21
- package/dist/chains.d.ts +23 -8
- package/dist/chains.d.ts.map +1 -1
- package/dist/constants.d.ts +5 -5
- package/dist/constants.d.ts.map +1 -1
- package/dist/customTokens.d.ts +12 -0
- package/dist/customTokens.d.ts.map +1 -0
- package/dist/decoders.d.ts +2 -2
- package/dist/decoders.d.ts.map +1 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/fees.d.ts +37 -2
- package/dist/fees.d.ts.map +1 -1
- package/dist/gasless.d.ts +15 -36
- package/dist/gasless.d.ts.map +1 -1
- package/dist/{index-w7_dK4c5.js → index-BbajxCG_.js} +59269 -77146
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +828 -359
- package/dist/indexerClient.d.ts.map +1 -1
- package/dist/intentReceiptMonitor.d.ts +1 -1
- package/dist/intentReceiptMonitor.d.ts.map +1 -1
- package/dist/intentReceiptPoller.d.ts +1 -1
- package/dist/intentReceiptPoller.d.ts.map +1 -1
- package/dist/intents.d.ts +3 -2
- package/dist/intents.d.ts.map +1 -1
- package/dist/mode.d.ts +1 -1
- package/dist/mode.d.ts.map +1 -1
- package/dist/mutations.d.ts +2 -2
- package/dist/mutations.d.ts.map +1 -1
- package/dist/prepareSend.d.ts +2 -2
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/prices.d.ts +1 -1
- package/dist/prices.d.ts.map +1 -1
- package/dist/sequenceWallet.d.ts +2 -2
- package/dist/sequenceWallet.d.ts.map +1 -1
- package/dist/time.d.ts +6 -0
- package/dist/time.d.ts.map +1 -1
- package/dist/tokenBalances.d.ts +40 -25
- package/dist/tokenBalances.d.ts.map +1 -1
- package/dist/tokens.d.ts +54 -14
- package/dist/tokens.d.ts.map +1 -1
- package/dist/trailsClient.d.ts +1 -1
- package/dist/trailsClient.d.ts.map +1 -1
- package/dist/trailsRouter.d.ts +2 -1
- package/dist/trailsRouter.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts +3 -2
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts +2 -1
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -1
- package/dist/transactionIntent/execution/transactionState.d.ts +1 -1
- package/dist/transactionIntent/execution/transactionState.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/crossChain.d.ts +5 -3
- package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts +5 -3
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -1
- package/dist/transactionIntent/quote/feeExtractors.d.ts +1 -6
- package/dist/transactionIntent/quote/feeExtractors.d.ts.map +1 -1
- package/dist/transactionIntent/quote/normalizeQuote.d.ts +4 -2
- package/dist/transactionIntent/quote/normalizeQuote.d.ts.map +1 -1
- package/dist/transactionIntent/quote/quoteHelpers.d.ts +1 -1
- package/dist/transactionIntent/quote/quoteHelpers.d.ts.map +1 -1
- package/dist/transactionIntent/types.d.ts +28 -5
- package/dist/transactionIntent/types.d.ts.map +1 -1
- package/dist/transactionIntent/utils/testnetHelpers.d.ts +0 -1
- package/dist/transactionIntent/utils/testnetHelpers.d.ts.map +1 -1
- package/dist/transactionIntent/validators.d.ts +0 -2
- package/dist/transactionIntent/validators.d.ts.map +1 -1
- package/dist/transactions.d.ts +2 -2
- package/dist/transactions.d.ts.map +1 -1
- package/dist/utils.d.ts +7 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/wallets.d.ts +1 -0
- package/dist/wallets.d.ts.map +1 -1
- package/dist/widget/components/AccountIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/components/AddressWalletIcon.d.ts +6 -0
- package/dist/widget/components/AddressWalletIcon.d.ts.map +1 -0
- package/dist/widget/components/ChainFilterDropdown.d.ts +2 -6
- package/dist/widget/components/ChainFilterDropdown.d.ts.map +1 -1
- package/dist/widget/components/ChainImage.d.ts.map +1 -1
- package/dist/widget/components/ChainList.d.ts +0 -5
- package/dist/widget/components/ChainList.d.ts.map +1 -1
- package/dist/widget/components/ClassicSwap.d.ts +6 -6
- package/dist/widget/components/ClassicSwap.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/DebugMenu.d.ts +1 -1
- package/dist/widget/components/DebugMenu.d.ts.map +1 -1
- package/dist/widget/components/DebugScreensList.d.ts.map +1 -1
- package/dist/widget/components/DepositTracker.d.ts.map +1 -1
- package/dist/widget/components/Earn.d.ts +5 -5
- package/dist/widget/components/Earn.d.ts.map +1 -1
- package/dist/widget/components/FeeOption.d.ts +1 -1
- package/dist/widget/components/FeeOption.d.ts.map +1 -1
- package/dist/widget/components/FeeOptions.d.ts +2 -2
- package/dist/widget/components/FeeOptions.d.ts.map +1 -1
- package/dist/widget/components/Footer.d.ts +1 -1
- package/dist/widget/components/Footer.d.ts.map +1 -1
- package/dist/widget/components/Fund.d.ts +5 -5
- package/dist/widget/components/Fund.d.ts.map +1 -1
- package/dist/widget/components/FundMethods.d.ts +0 -1
- package/dist/widget/components/FundMethods.d.ts.map +1 -1
- package/dist/widget/components/FundSwap.d.ts +6 -6
- package/dist/widget/components/FundSwap.d.ts.map +1 -1
- package/dist/widget/components/HookModalContent.d.ts +8 -0
- package/dist/widget/components/HookModalContent.d.ts.map +1 -0
- package/dist/widget/components/OriginSelectionAmount.d.ts +11 -0
- package/dist/widget/components/OriginSelectionAmount.d.ts.map +1 -0
- package/dist/widget/components/Pay.d.ts +5 -5
- package/dist/widget/components/Pay.d.ts.map +1 -1
- package/dist/widget/components/PoolDeposit.d.ts +5 -5
- package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
- package/dist/widget/components/PoolWithdraw.d.ts +3 -3
- package/dist/widget/components/PoolWithdraw.d.ts.map +1 -1
- package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
- package/dist/widget/components/Receipt.d.ts +2 -1
- package/dist/widget/components/Receipt.d.ts.map +1 -1
- package/dist/widget/components/RecentTokens.d.ts +4 -4
- package/dist/widget/components/RecentTokens.d.ts.map +1 -1
- package/dist/widget/components/RecipientSelectorButton.d.ts.map +1 -1
- package/dist/widget/components/ShadowPortal.d.ts +6 -0
- package/dist/widget/components/ShadowPortal.d.ts.map +1 -0
- package/dist/widget/components/Swap.d.ts +6 -6
- package/dist/widget/components/Swap.d.ts.map +1 -1
- package/dist/widget/components/ThemeProvider.d.ts +1 -1
- package/dist/widget/components/ThemeProvider.d.ts.map +1 -1
- package/dist/widget/components/TokenList.d.ts +3 -4
- package/dist/widget/components/TokenList.d.ts.map +1 -1
- package/dist/widget/components/TokenSelector.d.ts +3 -4
- package/dist/widget/components/TokenSelector.d.ts.map +1 -1
- package/dist/widget/components/Tooltip.d.ts +6 -1
- package/dist/widget/components/Tooltip.d.ts.map +1 -1
- package/dist/widget/components/TrailsHookModal.d.ts +10 -0
- package/dist/widget/components/TrailsHookModal.d.ts.map +1 -0
- package/dist/widget/components/WaasFeeOptions.d.ts +3 -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/components/WidgetProviders.d.ts +14 -0
- package/dist/widget/components/WidgetProviders.d.ts.map +1 -0
- package/dist/widget/css/compiled.css +1 -1
- package/dist/widget/hooks/useAddressWalletIcon.d.ts +10 -0
- package/dist/widget/hooks/useAddressWalletIcon.d.ts.map +1 -0
- package/dist/widget/hooks/useBalanceVisible.d.ts +1 -1
- package/dist/widget/hooks/useBalanceVisible.d.ts.map +1 -1
- package/dist/widget/hooks/useChainFilter.d.ts +1 -1
- package/dist/widget/hooks/useChainFilter.d.ts.map +1 -1
- package/dist/widget/hooks/useCheckout.d.ts +13 -1
- package/dist/widget/hooks/useCheckout.d.ts.map +1 -1
- package/dist/widget/hooks/useConnector.d.ts +4 -0
- package/dist/widget/hooks/useConnector.d.ts.map +1 -0
- package/dist/widget/hooks/useCurrentScreen.d.ts +1 -1
- package/dist/widget/hooks/useCurrentScreen.d.ts.map +1 -1
- package/dist/widget/hooks/useCustomTokenFetch.d.ts +19 -0
- package/dist/widget/hooks/useCustomTokenFetch.d.ts.map +1 -0
- package/dist/widget/hooks/useCustomTokenSearch.d.ts +20 -0
- package/dist/widget/hooks/useCustomTokenSearch.d.ts.map +1 -0
- package/dist/widget/hooks/useDebounce.d.ts +10 -0
- package/dist/widget/hooks/useDebounce.d.ts.map +1 -0
- package/dist/widget/hooks/useDebugScreens.d.ts +7 -2
- package/dist/widget/hooks/useDebugScreens.d.ts.map +1 -1
- package/dist/widget/hooks/useDefaultTokenSelection.d.ts +3 -19
- package/dist/widget/hooks/useDefaultTokenSelection.d.ts.map +1 -1
- package/dist/widget/hooks/useDestinationSelectedToken.d.ts +1 -14
- package/dist/widget/hooks/useDestinationSelectedToken.d.ts.map +1 -1
- package/dist/widget/hooks/useEarnPool.d.ts +1 -1
- package/dist/widget/hooks/useEarnPool.d.ts.map +1 -1
- package/dist/widget/hooks/useIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/hooks/useIsMobile.d.ts +5 -0
- package/dist/widget/hooks/useIsMobile.d.ts.map +1 -0
- package/dist/widget/hooks/useMode.d.ts +2 -2
- package/dist/widget/hooks/useMode.d.ts.map +1 -1
- package/dist/widget/hooks/useOriginSelectedToken.d.ts +2 -15
- package/dist/widget/hooks/useOriginSelectedToken.d.ts.map +1 -1
- package/dist/widget/hooks/usePayMessage.d.ts.map +1 -1
- package/dist/widget/hooks/usePriceImpactWarning.d.ts +1 -1
- package/dist/widget/hooks/usePriceImpactWarning.d.ts.map +1 -1
- package/dist/widget/hooks/useQuote.d.ts +173 -4
- package/dist/widget/hooks/useQuote.d.ts.map +1 -1
- package/dist/widget/hooks/useRecentTokens.d.ts +3 -3
- package/dist/widget/hooks/useRecentTokens.d.ts.map +1 -1
- package/dist/widget/hooks/useRecipients.d.ts +1 -1
- package/dist/widget/hooks/useRecipients.d.ts.map +1 -1
- package/dist/widget/hooks/useSelectedFeeOption.d.ts +2 -2
- package/dist/widget/hooks/useSelectedFeeOption.d.ts.map +1 -1
- package/dist/widget/hooks/useSelectedFundMethod.d.ts +1 -1
- package/dist/widget/hooks/useSelectedFundMethod.d.ts.map +1 -1
- package/dist/widget/hooks/useSelectedRecipient.d.ts +1 -1
- package/dist/widget/hooks/useSelectedRecipient.d.ts.map +1 -1
- package/dist/widget/hooks/useSendForm.d.ts +9 -31
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
- package/dist/widget/hooks/useSwapAmount.d.ts +1 -1
- package/dist/widget/hooks/useSwapAmount.d.ts.map +1 -1
- package/dist/widget/hooks/useTheme.d.ts +1 -1
- package/dist/widget/hooks/useTheme.d.ts.map +1 -1
- package/dist/widget/hooks/useTokenList.d.ts +7 -31
- package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
- package/dist/widget/hooks/useTrailsSendTransaction.d.ts +83 -0
- package/dist/widget/hooks/useTrailsSendTransaction.d.ts.map +1 -0
- package/dist/widget/hooks/useWalletConnectUri.d.ts +11 -0
- package/dist/widget/hooks/useWalletConnectUri.d.ts.map +1 -0
- package/dist/widget/hooks/useWidgetProps.d.ts +5 -0
- package/dist/widget/hooks/useWidgetProps.d.ts.map +1 -1
- package/dist/widget/index.d.ts +2 -0
- package/dist/widget/index.d.ts.map +1 -1
- package/dist/widget/index.js +8 -5
- package/dist/widget/providers/TrailsModalProvider.d.ts +65 -0
- package/dist/widget/providers/TrailsModalProvider.d.ts.map +1 -0
- package/dist/widget/providers/TrailsProvider.d.ts +1 -1
- package/dist/widget/providers/TrailsProvider.d.ts.map +1 -1
- package/dist/widget/types.d.ts +11 -18
- package/dist/widget/types.d.ts.map +1 -1
- package/dist/widget/widget.d.ts +20 -11
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +45 -49
- package/src/aave.ts +387 -138
- package/src/analytics.ts +208 -2
- package/src/chains.ts +65 -64
- package/src/constants.ts +18 -14
- package/src/customTokens.ts +151 -0
- package/src/decoders.ts +4 -7
- package/src/error.ts +7 -3
- package/src/fees.ts +239 -125
- package/src/gasless.ts +54 -108
- package/src/index.ts +29 -9
- package/src/indexerClient.ts +2 -0
- package/src/intentReceiptMonitor.ts +1 -4
- package/src/intentReceiptPoller.ts +2 -2
- package/src/intents.ts +16 -5
- package/src/mode.ts +1 -1
- package/src/mutations.ts +7 -3
- package/src/prepareSend.ts +19 -14
- package/src/prices.ts +1 -1
- package/src/sequenceWallet.ts +2 -2
- package/src/time.ts +28 -0
- package/src/tokenBalances.ts +348 -153
- package/src/tokens.ts +393 -142
- package/src/trailsClient.ts +1 -1
- package/src/trailsRouter.ts +4 -5
- package/src/transactionIntent/deposits/depositOrchestrator.ts +6 -2
- package/src/transactionIntent/deposits/gaslessDeposit.ts +13 -7
- package/src/transactionIntent/deposits/standardDeposit.ts +1 -1
- package/src/transactionIntent/execution/transactionState.ts +1 -1
- package/src/transactionIntent/handlers/crossChain.ts +75 -37
- package/src/transactionIntent/handlers/sameChainSameToken.ts +66 -20
- package/src/transactionIntent/quote/feeExtractors.ts +1 -29
- package/src/transactionIntent/quote/normalizeQuote.ts +99 -7
- package/src/transactionIntent/quote/quoteHelpers.ts +1 -1
- package/src/transactionIntent/types.ts +31 -6
- package/src/transactionIntent/utils/testnetHelpers.ts +0 -5
- package/src/transactionIntent/validators.ts +0 -30
- package/src/transactions.ts +3 -3
- package/src/utils.ts +18 -0
- package/src/wallets.ts +32 -10
- package/src/widget/compiled.css +1 -1
- package/src/widget/components/AccountIntentTransactionHistory.tsx +2 -1
- package/src/widget/components/AccountIntentTransactionHistoryButton.tsx +2 -2
- package/src/widget/components/AddressWalletIcon.tsx +29 -0
- package/src/widget/components/ChainFilterDropdown.tsx +2 -8
- package/src/widget/components/ChainImage.tsx +8 -5
- package/src/widget/components/ChainList.tsx +6 -8
- package/src/widget/components/ClassicSwap.tsx +93 -85
- package/src/widget/components/ConnectWallet.tsx +1 -2
- package/src/widget/components/ConnectedWallets.tsx +17 -4
- package/src/widget/components/DebugMenu.tsx +2 -2
- package/src/widget/components/DebugScreensList.tsx +0 -1
- package/src/widget/components/DepositTracker.tsx +20 -34
- package/src/widget/components/Earn.tsx +7 -6
- package/src/widget/components/FeeOption.tsx +4 -4
- package/src/widget/components/FeeOptions.tsx +19 -39
- package/src/widget/components/Footer.tsx +1 -1
- package/src/widget/components/Fund.tsx +23 -119
- package/src/widget/components/FundMethods.tsx +9 -6
- package/src/widget/components/FundSwap.tsx +6 -5
- package/src/widget/components/FundingMethodSelectorButton.tsx +2 -2
- package/src/widget/components/HookModalContent.tsx +306 -0
- package/src/widget/components/Modal.tsx +1 -1
- package/src/widget/components/OriginSelectionAmount.tsx +135 -0
- package/src/widget/components/Pay.tsx +66 -124
- package/src/widget/components/PoolDeposit.tsx +11 -55
- package/src/widget/components/PoolWithdraw.tsx +3 -3
- package/src/widget/components/QuoteDetails.tsx +473 -728
- package/src/widget/components/Receipt.tsx +74 -7
- package/src/widget/components/RecentTokens.tsx +8 -8
- package/src/widget/components/RecipientSelectorButton.tsx +4 -2
- package/src/widget/components/ScreenHeader.tsx +2 -2
- package/src/widget/components/SearchInputField.tsx +1 -1
- package/src/widget/components/ShadowPortal.tsx +58 -0
- package/src/widget/components/Swap.tsx +6 -5
- package/src/widget/components/ThemeProvider.tsx +1 -1
- package/src/widget/components/TokenList.tsx +3 -4
- package/src/widget/components/TokenSelector.tsx +211 -80
- package/src/widget/components/Tooltip.tsx +18 -7
- package/src/widget/components/TrailsHookModal.tsx +118 -0
- package/src/widget/components/WaasFeeOptions.tsx +333 -138
- package/src/widget/components/WalletConfirmation.tsx +7 -2
- package/src/widget/components/WalletConnect.tsx +197 -235
- package/src/widget/components/WidgetProviders.tsx +75 -0
- package/src/widget/hooks/useAddressWalletIcon.ts +53 -0
- package/src/widget/hooks/useBalanceVisible.tsx +1 -1
- package/src/widget/hooks/useChainFilter.tsx +1 -1
- package/src/widget/hooks/useCheckout.ts +13 -1
- package/src/widget/hooks/useConnector.tsx +18 -0
- package/src/widget/hooks/useCurrentScreen.tsx +3 -3
- package/src/widget/hooks/useCustomTokenFetch.tsx +72 -0
- package/src/widget/hooks/useCustomTokenSearch.tsx +402 -0
- package/src/widget/hooks/useDebounce.ts +25 -0
- package/src/widget/hooks/useDebugScreens.ts +26 -10
- package/src/widget/hooks/useDefaultTokenSelection.tsx +99 -143
- package/src/widget/hooks/useDestinationSelectedToken.tsx +1 -14
- package/src/widget/hooks/useEarnPool.tsx +1 -1
- package/src/widget/hooks/useIntentTransactionHistory.ts +20 -11
- package/src/widget/hooks/useIsMobile.tsx +50 -0
- package/src/widget/hooks/useMode.ts +2 -3
- package/src/widget/hooks/useOriginSelectedToken.tsx +2 -15
- package/src/widget/hooks/usePayMessage.tsx +31 -11
- package/src/widget/hooks/usePriceImpactWarning.ts +1 -1
- package/src/widget/hooks/useQuote.ts +189 -6
- package/src/widget/hooks/useRecentTokens.ts +6 -6
- package/src/widget/hooks/useRecipients.ts +1 -1
- package/src/widget/hooks/useSelectedFeeOption.tsx +2 -2
- package/src/widget/hooks/useSelectedFundMethod.tsx +1 -1
- package/src/widget/hooks/useSelectedRecipient.tsx +1 -1
- package/src/widget/hooks/useSendForm.ts +328 -152
- package/src/widget/hooks/useSwapAmount.tsx +1 -1
- package/src/widget/hooks/useTheme.tsx +1 -1
- package/src/widget/hooks/useTokenList.ts +672 -400
- package/src/widget/hooks/useTrailsSendTransaction.ts +949 -0
- package/src/widget/hooks/useWalletConnectUri.tsx +228 -0
- package/src/widget/hooks/useWidgetProps.tsx +3 -1
- package/src/widget/index.tsx +12 -0
- package/src/widget/providers/TrailsModalProvider.tsx +195 -0
- package/src/widget/providers/TrailsProvider.tsx +9 -3
- package/src/widget/types.ts +12 -20
- package/src/widget/widget.tsx +598 -385
- package/dist/cctp.d.ts +0 -3
- package/dist/cctp.d.ts.map +0 -1
- package/dist/lifi.d.ts +0 -4
- package/dist/lifi.d.ts.map +0 -1
- package/dist/meshconnect.d.ts +0 -171
- package/dist/meshconnect.d.ts.map +0 -1
- package/dist/relaySdk.d.ts +0 -87
- package/dist/relaySdk.d.ts.map +0 -1
- package/dist/widget/components/MeshConnectExchanges.d.ts +0 -7
- package/dist/widget/components/MeshConnectExchanges.d.ts.map +0 -1
- package/dist/widget/components/MeshConnectFlow.d.ts +0 -13
- package/dist/widget/components/MeshConnectFlow.d.ts.map +0 -1
- package/dist/widget/components/MeshConnectIframe.d.ts +0 -15
- package/dist/widget/components/MeshConnectIframe.d.ts.map +0 -1
- package/dist/widget/components/Receive.d.ts +0 -12
- package/dist/widget/components/Receive.d.ts.map +0 -1
- package/dist/widget/hooks/useSelectedMeshExchange.d.ts +0 -14
- package/dist/widget/hooks/useSelectedMeshExchange.d.ts.map +0 -1
- package/src/cctp.ts +0 -54
- package/src/lifi.ts +0 -108
- package/src/meshconnect.ts +0 -531
- package/src/relaySdk.ts +0 -703
- package/src/widget/components/MeshConnectExchanges.tsx +0 -290
- package/src/widget/components/MeshConnectFlow.tsx +0 -90
- package/src/widget/components/MeshConnectIframe.tsx +0 -500
- package/src/widget/components/Receive.tsx +0 -175
- package/src/widget/hooks/useSelectedMeshExchange.tsx +0 -46
package/src/relaySdk.ts
DELETED
|
@@ -1,703 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
convertViemChainToRelayChain,
|
|
3
|
-
createClient,
|
|
4
|
-
getClient,
|
|
5
|
-
MAINNET_RELAY_API,
|
|
6
|
-
} from "@reservoir0x/relay-sdk"
|
|
7
|
-
import type { WalletClient } from "viem"
|
|
8
|
-
import {
|
|
9
|
-
arbitrum,
|
|
10
|
-
avalanche,
|
|
11
|
-
base,
|
|
12
|
-
berachain,
|
|
13
|
-
blast,
|
|
14
|
-
opBNB,
|
|
15
|
-
bsc,
|
|
16
|
-
bob,
|
|
17
|
-
boba,
|
|
18
|
-
celo,
|
|
19
|
-
corn,
|
|
20
|
-
cronos,
|
|
21
|
-
cyber,
|
|
22
|
-
degen,
|
|
23
|
-
mainnet,
|
|
24
|
-
flowMainnet,
|
|
25
|
-
forma,
|
|
26
|
-
funkiMainnet,
|
|
27
|
-
gnosis,
|
|
28
|
-
gravity,
|
|
29
|
-
hemi,
|
|
30
|
-
hychain,
|
|
31
|
-
ink,
|
|
32
|
-
linea,
|
|
33
|
-
lisk,
|
|
34
|
-
manta,
|
|
35
|
-
mantle,
|
|
36
|
-
metis,
|
|
37
|
-
mint,
|
|
38
|
-
mode,
|
|
39
|
-
morph,
|
|
40
|
-
optimism,
|
|
41
|
-
plume,
|
|
42
|
-
polygon,
|
|
43
|
-
polygonZkEvm,
|
|
44
|
-
ronin,
|
|
45
|
-
redstone,
|
|
46
|
-
sanko,
|
|
47
|
-
scroll,
|
|
48
|
-
sei,
|
|
49
|
-
shape,
|
|
50
|
-
soneium,
|
|
51
|
-
sonic,
|
|
52
|
-
story,
|
|
53
|
-
superposition,
|
|
54
|
-
superseed,
|
|
55
|
-
swellchain,
|
|
56
|
-
taiko,
|
|
57
|
-
tron,
|
|
58
|
-
unichain,
|
|
59
|
-
worldchain,
|
|
60
|
-
xai,
|
|
61
|
-
zeroG,
|
|
62
|
-
zircuit,
|
|
63
|
-
zksync,
|
|
64
|
-
zora,
|
|
65
|
-
katana,
|
|
66
|
-
abstract,
|
|
67
|
-
ancient8,
|
|
68
|
-
apeChain,
|
|
69
|
-
arbitrumNova,
|
|
70
|
-
arenaz,
|
|
71
|
-
b3,
|
|
72
|
-
} from "viem/chains"
|
|
73
|
-
import { somnia } from "./customChains.js"
|
|
74
|
-
import { logger } from "./logger.js"
|
|
75
|
-
|
|
76
|
-
export type Chain = any
|
|
77
|
-
export type RelayQuote = any
|
|
78
|
-
export type RelayExecuteResult = any
|
|
79
|
-
export type RelayProgressData = any
|
|
80
|
-
|
|
81
|
-
// Source: https://docs.relay.link/resources/supported-chains
|
|
82
|
-
export const relaySupportedChains: Record<number, Chain> = {
|
|
83
|
-
[abstract.id]: abstract,
|
|
84
|
-
[ancient8.id]: ancient8,
|
|
85
|
-
[apeChain.id]: apeChain,
|
|
86
|
-
[arbitrum.id]: arbitrum,
|
|
87
|
-
[arbitrumNova.id]: arbitrumNova,
|
|
88
|
-
[arenaz.id]: arenaz,
|
|
89
|
-
[avalanche.id]: avalanche,
|
|
90
|
-
[b3.id]: b3,
|
|
91
|
-
[base.id]: base,
|
|
92
|
-
[berachain.id]: berachain,
|
|
93
|
-
[blast.id]: blast,
|
|
94
|
-
[bsc.id]: bsc,
|
|
95
|
-
[opBNB.id]: opBNB,
|
|
96
|
-
[bob.id]: bob,
|
|
97
|
-
[boba.id]: boba,
|
|
98
|
-
[celo.id]: celo,
|
|
99
|
-
[corn.id]: corn,
|
|
100
|
-
[cronos.id]: cronos,
|
|
101
|
-
[cyber.id]: cyber,
|
|
102
|
-
[degen.id]: degen,
|
|
103
|
-
[mainnet.id]: mainnet,
|
|
104
|
-
[flowMainnet.id]: flowMainnet,
|
|
105
|
-
[forma.id]: forma,
|
|
106
|
-
[funkiMainnet.id]: funkiMainnet,
|
|
107
|
-
[gnosis.id]: gnosis,
|
|
108
|
-
[gravity.id]: gravity,
|
|
109
|
-
[hemi.id]: hemi,
|
|
110
|
-
[hychain.id]: hychain,
|
|
111
|
-
[ink.id]: ink,
|
|
112
|
-
[linea.id]: linea,
|
|
113
|
-
[lisk.id]: lisk,
|
|
114
|
-
[manta.id]: manta,
|
|
115
|
-
[mantle.id]: mantle,
|
|
116
|
-
[metis.id]: metis,
|
|
117
|
-
[mint.id]: mint,
|
|
118
|
-
[mode.id]: mode,
|
|
119
|
-
[morph.id]: morph,
|
|
120
|
-
[optimism.id]: optimism,
|
|
121
|
-
[plume.id]: plume,
|
|
122
|
-
[polygon.id]: polygon,
|
|
123
|
-
[polygonZkEvm.id]: polygonZkEvm,
|
|
124
|
-
[ronin.id]: ronin,
|
|
125
|
-
[redstone.id]: redstone,
|
|
126
|
-
[sanko.id]: sanko,
|
|
127
|
-
[scroll.id]: scroll,
|
|
128
|
-
[sei.id]: sei,
|
|
129
|
-
[shape.id]: shape,
|
|
130
|
-
[soneium.id]: soneium,
|
|
131
|
-
[sonic.id]: sonic,
|
|
132
|
-
[story.id]: story,
|
|
133
|
-
[superposition.id]: superposition,
|
|
134
|
-
[superseed.id]: superseed,
|
|
135
|
-
[swellchain.id]: swellchain,
|
|
136
|
-
[taiko.id]: taiko,
|
|
137
|
-
[tron.id]: tron,
|
|
138
|
-
[unichain.id]: unichain,
|
|
139
|
-
[worldchain.id]: worldchain,
|
|
140
|
-
[xai.id]: xai,
|
|
141
|
-
[zeroG.id]: zeroG,
|
|
142
|
-
[zircuit.id]: zircuit,
|
|
143
|
-
[zksync.id]: zksync,
|
|
144
|
-
[zora.id]: zora,
|
|
145
|
-
[katana.id]: katana,
|
|
146
|
-
[somnia.id]: somnia,
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
getRelaySupportedChains().then((relayChains) => {
|
|
150
|
-
createClient({
|
|
151
|
-
baseApiUrl: MAINNET_RELAY_API,
|
|
152
|
-
source: "Trails",
|
|
153
|
-
chains: relayChains.map((chain: Chain) =>
|
|
154
|
-
convertViemChainToRelayChain(chain),
|
|
155
|
-
),
|
|
156
|
-
})
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
export enum RelayTradeType {
|
|
160
|
-
EXACT_INPUT = "EXACT_INPUT",
|
|
161
|
-
EXACT_OUTPUT = "EXACT_OUTPUT",
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export interface RelayQuoteOptions {
|
|
165
|
-
wallet: WalletClient
|
|
166
|
-
chainId: number
|
|
167
|
-
toChainId?: number
|
|
168
|
-
amount: string
|
|
169
|
-
currency: string
|
|
170
|
-
toCurrency?: string
|
|
171
|
-
tradeType?: RelayTradeType
|
|
172
|
-
txs: Array<{
|
|
173
|
-
to: string
|
|
174
|
-
value: string
|
|
175
|
-
data: string
|
|
176
|
-
}>
|
|
177
|
-
recipient?: string
|
|
178
|
-
slippageTolerance?: string
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export interface RelayExecuteOptions {
|
|
182
|
-
quote: RelayQuote
|
|
183
|
-
wallet: WalletClient
|
|
184
|
-
onProgress?: (data: RelayProgressData) => void
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Get a quote for a relay transaction
|
|
189
|
-
*/
|
|
190
|
-
export async function getRelaySDKQuote(
|
|
191
|
-
options: RelayQuoteOptions,
|
|
192
|
-
): Promise<RelayQuote> {
|
|
193
|
-
try {
|
|
194
|
-
const client = getClient()
|
|
195
|
-
if (!client) {
|
|
196
|
-
throw new Error("Relay client not available")
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
logger.console.log("[trails-sdk] getRelaySDKQuote", options)
|
|
200
|
-
|
|
201
|
-
const quote = await client.actions.getQuote({
|
|
202
|
-
wallet: options.wallet,
|
|
203
|
-
chainId: options.chainId,
|
|
204
|
-
toChainId: options.toChainId || options.chainId,
|
|
205
|
-
amount: options.amount,
|
|
206
|
-
currency: options.currency,
|
|
207
|
-
toCurrency: options.toCurrency || options.currency,
|
|
208
|
-
tradeType: options.tradeType || RelayTradeType.EXACT_OUTPUT,
|
|
209
|
-
txs: options.txs,
|
|
210
|
-
user: options.wallet.account!.address,
|
|
211
|
-
recipient: options.recipient || options.wallet.account!.address,
|
|
212
|
-
options: {
|
|
213
|
-
slippageTolerance: options.slippageTolerance
|
|
214
|
-
? Math.round(Number(options.slippageTolerance) * 100 * 100).toString()
|
|
215
|
-
: undefined,
|
|
216
|
-
},
|
|
217
|
-
})
|
|
218
|
-
|
|
219
|
-
return quote
|
|
220
|
-
} catch (error) {
|
|
221
|
-
logger.console.error("[trails-sdk] Error getting relay quote:", error)
|
|
222
|
-
throw error
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Execute a relay transaction
|
|
228
|
-
*/
|
|
229
|
-
export async function relaySDKExecute(
|
|
230
|
-
options: RelayExecuteOptions,
|
|
231
|
-
): Promise<RelayExecuteResult> {
|
|
232
|
-
try {
|
|
233
|
-
const client = getClient()
|
|
234
|
-
if (!client) {
|
|
235
|
-
throw new Error("Relay client not available")
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
logger.console.log(
|
|
239
|
-
"[trails-sdk] relaysdkclient",
|
|
240
|
-
client.chains,
|
|
241
|
-
options.quote,
|
|
242
|
-
)
|
|
243
|
-
|
|
244
|
-
const result = await client.actions.execute({
|
|
245
|
-
quote: options.quote,
|
|
246
|
-
wallet: options.wallet,
|
|
247
|
-
onProgress:
|
|
248
|
-
options.onProgress ||
|
|
249
|
-
((data) => {
|
|
250
|
-
logger.console.log("[trails-sdk] Relay progress:", data)
|
|
251
|
-
}),
|
|
252
|
-
})
|
|
253
|
-
|
|
254
|
-
return result
|
|
255
|
-
} catch (error) {
|
|
256
|
-
logger.console.error(
|
|
257
|
-
"[trails-sdk] Error executing relay transaction:",
|
|
258
|
-
error,
|
|
259
|
-
)
|
|
260
|
-
throw error
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Helper function to create a simple relay transaction for a contract call
|
|
266
|
-
*/
|
|
267
|
-
export async function createSimpleRelayTransaction(
|
|
268
|
-
wallet: WalletClient,
|
|
269
|
-
contractAddress: string,
|
|
270
|
-
callData: string,
|
|
271
|
-
value: string,
|
|
272
|
-
chainId: number,
|
|
273
|
-
currency: string = "0x0000000000000000000000000000000000000000", // ETH
|
|
274
|
-
): Promise<RelayQuote> {
|
|
275
|
-
const options: RelayQuoteOptions = {
|
|
276
|
-
wallet,
|
|
277
|
-
chainId,
|
|
278
|
-
amount: value,
|
|
279
|
-
currency,
|
|
280
|
-
txs: [
|
|
281
|
-
{
|
|
282
|
-
to: contractAddress,
|
|
283
|
-
value,
|
|
284
|
-
data: callData,
|
|
285
|
-
},
|
|
286
|
-
],
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
return await getRelaySDKQuote(options)
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Helper function to execute a simple relay transaction
|
|
294
|
-
*/
|
|
295
|
-
export async function executeSimpleRelayTransaction(
|
|
296
|
-
quote: RelayQuote,
|
|
297
|
-
wallet: WalletClient,
|
|
298
|
-
onProgress?: RelayExecuteOptions["onProgress"],
|
|
299
|
-
): Promise<RelayExecuteResult> {
|
|
300
|
-
return await relaySDKExecute({
|
|
301
|
-
quote,
|
|
302
|
-
wallet,
|
|
303
|
-
onProgress,
|
|
304
|
-
})
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
export function getTxHashFromRelayResult(result: RelayExecuteResult): string {
|
|
308
|
-
let txHash =
|
|
309
|
-
result?.data?.steps?.[result?.data?.steps?.length - 1]?.items?.[0]
|
|
310
|
-
?.txHashes?.[0]?.txHash
|
|
311
|
-
|
|
312
|
-
if (!txHash) {
|
|
313
|
-
txHash =
|
|
314
|
-
result?.data?.steps?.[result?.data?.steps?.length - 1]?.items?.[0]
|
|
315
|
-
?.internalTxHashes?.[0]?.txHash
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
if (!txHash) {
|
|
319
|
-
throw new Error("No transaction hash found in relay result")
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
return txHash
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
export async function getRelaySupportedChains(): Promise<Chain[]> {
|
|
326
|
-
return Object.values(relaySupportedChains)
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
export async function isChainSupported(chainId: number): Promise<boolean> {
|
|
330
|
-
return Object.keys(relaySupportedChains).includes(chainId.toString())
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
export interface RelayToken {
|
|
334
|
-
id: string
|
|
335
|
-
symbol: string
|
|
336
|
-
name: string
|
|
337
|
-
contractAddress: string
|
|
338
|
-
decimals: number
|
|
339
|
-
chainId: number
|
|
340
|
-
chainName: string
|
|
341
|
-
imageUrl: string
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
export async function getRelaySupportedTokens(): Promise<RelayToken[]> {
|
|
345
|
-
try {
|
|
346
|
-
const relayChains = await fetchRelayChains()
|
|
347
|
-
|
|
348
|
-
const tokens: RelayToken[] = []
|
|
349
|
-
|
|
350
|
-
relayChains.forEach((chain) => {
|
|
351
|
-
if (!chain.disabled) {
|
|
352
|
-
// Add native currency
|
|
353
|
-
tokens.push({
|
|
354
|
-
id: chain.currency.id || `${chain.currency.symbol}-${chain.name}`,
|
|
355
|
-
symbol: chain.currency.symbol,
|
|
356
|
-
name: chain.currency.name,
|
|
357
|
-
contractAddress: chain.currency.address,
|
|
358
|
-
decimals: chain.currency.decimals,
|
|
359
|
-
chainId: chain.id,
|
|
360
|
-
chainName: chain.displayName || chain.name,
|
|
361
|
-
imageUrl: "", // Native currencies typically don't have logoURI
|
|
362
|
-
})
|
|
363
|
-
|
|
364
|
-
// Add featured tokens
|
|
365
|
-
chain.featuredTokens.forEach((token) => {
|
|
366
|
-
tokens.push({
|
|
367
|
-
id: token.id || `${token.symbol}-${chain.name}`,
|
|
368
|
-
symbol: token.symbol,
|
|
369
|
-
name: token.name,
|
|
370
|
-
contractAddress: token.address,
|
|
371
|
-
decimals: token.decimals,
|
|
372
|
-
chainId: chain.id,
|
|
373
|
-
chainName: chain.displayName || chain.name,
|
|
374
|
-
imageUrl: token.metadata?.logoURI || "",
|
|
375
|
-
})
|
|
376
|
-
})
|
|
377
|
-
|
|
378
|
-
// Add ERC20 currencies
|
|
379
|
-
chain.erc20Currencies.forEach((token) => {
|
|
380
|
-
tokens.push({
|
|
381
|
-
id: token.id || `${token.symbol}-${chain.name}`,
|
|
382
|
-
symbol: token.symbol,
|
|
383
|
-
name: token.name,
|
|
384
|
-
contractAddress: token.address,
|
|
385
|
-
decimals: token.decimals,
|
|
386
|
-
chainId: chain.id,
|
|
387
|
-
chainName: chain.displayName || chain.name,
|
|
388
|
-
imageUrl: token.metadata?.logoURI || "",
|
|
389
|
-
})
|
|
390
|
-
})
|
|
391
|
-
|
|
392
|
-
// Add solver currencies (fallback for chains that might not have featuredTokens/erc20Currencies)
|
|
393
|
-
chain.solverCurrencies.forEach((token) => {
|
|
394
|
-
tokens.push({
|
|
395
|
-
id: token.id || `${token.symbol}-${chain.name}`,
|
|
396
|
-
symbol: token.symbol,
|
|
397
|
-
name: token.name,
|
|
398
|
-
contractAddress: token.address,
|
|
399
|
-
decimals: token.decimals,
|
|
400
|
-
chainId: chain.id,
|
|
401
|
-
chainName: chain.displayName || chain.name,
|
|
402
|
-
imageUrl: token.metadata?.logoURI || "",
|
|
403
|
-
})
|
|
404
|
-
})
|
|
405
|
-
}
|
|
406
|
-
})
|
|
407
|
-
|
|
408
|
-
// Remove duplicates by chainId and contractAddress
|
|
409
|
-
const uniqueTokens = tokens.filter(
|
|
410
|
-
(token, index, self) =>
|
|
411
|
-
index ===
|
|
412
|
-
self.findIndex(
|
|
413
|
-
(t) =>
|
|
414
|
-
t.chainId === token.chainId &&
|
|
415
|
-
t.contractAddress.toLowerCase() ===
|
|
416
|
-
token.contractAddress.toLowerCase(),
|
|
417
|
-
),
|
|
418
|
-
)
|
|
419
|
-
|
|
420
|
-
logger.console.log(
|
|
421
|
-
`[trails-sdk] Fetched ${uniqueTokens.length} unique tokens from Relay API`,
|
|
422
|
-
)
|
|
423
|
-
|
|
424
|
-
return uniqueTokens
|
|
425
|
-
} catch (error) {
|
|
426
|
-
logger.console.error(
|
|
427
|
-
"[trails-sdk] Error fetching Relay supported tokens:",
|
|
428
|
-
error,
|
|
429
|
-
)
|
|
430
|
-
return []
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
// Types for Relay API response
|
|
435
|
-
interface RelayApiToken {
|
|
436
|
-
id: string
|
|
437
|
-
symbol: string
|
|
438
|
-
name: string
|
|
439
|
-
address: string
|
|
440
|
-
decimals: number
|
|
441
|
-
metadata?: {
|
|
442
|
-
logoURI?: string
|
|
443
|
-
}
|
|
444
|
-
supportsBridging?: boolean
|
|
445
|
-
withdrawalFee?: number
|
|
446
|
-
depositFee?: number
|
|
447
|
-
surgeEnabled?: boolean
|
|
448
|
-
supportsPermit?: boolean
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
interface RelayChain {
|
|
452
|
-
id: number
|
|
453
|
-
name: string
|
|
454
|
-
displayName: string
|
|
455
|
-
disabled: boolean
|
|
456
|
-
currency: {
|
|
457
|
-
id: string
|
|
458
|
-
symbol: string
|
|
459
|
-
name: string
|
|
460
|
-
address: string
|
|
461
|
-
decimals: number
|
|
462
|
-
supportsBridging: boolean
|
|
463
|
-
}
|
|
464
|
-
featuredTokens: RelayApiToken[]
|
|
465
|
-
erc20Currencies: RelayApiToken[]
|
|
466
|
-
solverCurrencies: RelayApiToken[]
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
interface RelayChainsResponse {
|
|
470
|
-
chains: RelayChain[]
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
// Cache for chains data
|
|
474
|
-
let cachedChains: RelayChain[] | null = null
|
|
475
|
-
let cacheTimestamp: number = 0
|
|
476
|
-
const CACHE_DURATION = 5 * 60 * 1000 // 5 minutes
|
|
477
|
-
|
|
478
|
-
async function fetchRelayChains(): Promise<RelayChain[]> {
|
|
479
|
-
const now = Date.now()
|
|
480
|
-
|
|
481
|
-
// Return cached data if still valid
|
|
482
|
-
if (cachedChains && now - cacheTimestamp < CACHE_DURATION) {
|
|
483
|
-
return cachedChains
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
try {
|
|
487
|
-
const response = await fetch("https://api.relay.link/chains")
|
|
488
|
-
if (!response.ok) {
|
|
489
|
-
throw new Error(`Failed to fetch chains: ${response.status}`)
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
const data: RelayChainsResponse = await response.json()
|
|
493
|
-
cachedChains = data.chains
|
|
494
|
-
cacheTimestamp = now
|
|
495
|
-
|
|
496
|
-
return data.chains
|
|
497
|
-
} catch (error) {
|
|
498
|
-
logger.console.error("[trails-sdk] Error fetching Relay chains:", error)
|
|
499
|
-
// Return cached data if available, even if expired
|
|
500
|
-
if (cachedChains) {
|
|
501
|
-
return cachedChains
|
|
502
|
-
}
|
|
503
|
-
throw error
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
export type GetIsRouteSupportedOptions = {
|
|
508
|
-
originChainId: number
|
|
509
|
-
destinationChainId: number
|
|
510
|
-
amount: string
|
|
511
|
-
originToken: string
|
|
512
|
-
destinationToken: string
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
export async function getIsRouteSupported({
|
|
516
|
-
originChainId,
|
|
517
|
-
destinationChainId,
|
|
518
|
-
amount,
|
|
519
|
-
originToken,
|
|
520
|
-
destinationToken,
|
|
521
|
-
}: GetIsRouteSupportedOptions): Promise<boolean> {
|
|
522
|
-
try {
|
|
523
|
-
// Fetch supported chains from Relay API
|
|
524
|
-
const chains = await fetchRelayChains()
|
|
525
|
-
|
|
526
|
-
// Check if both chains are supported and not disabled
|
|
527
|
-
const originChain = chains.find((chain) => chain.id === originChainId)
|
|
528
|
-
const destinationChain = chains.find(
|
|
529
|
-
(chain) => chain.id === destinationChainId,
|
|
530
|
-
)
|
|
531
|
-
|
|
532
|
-
if (
|
|
533
|
-
!originChain ||
|
|
534
|
-
!destinationChain ||
|
|
535
|
-
originChain.disabled ||
|
|
536
|
-
destinationChain.disabled
|
|
537
|
-
) {
|
|
538
|
-
return false
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
// Check if destination token is supported on destination chain
|
|
542
|
-
const isDestinationTokenSupported = destinationChain.solverCurrencies.some(
|
|
543
|
-
(currency) =>
|
|
544
|
-
currency.address.toLowerCase() === destinationToken.toLowerCase(),
|
|
545
|
-
)
|
|
546
|
-
|
|
547
|
-
if (!isDestinationTokenSupported) {
|
|
548
|
-
return false
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
// If we have a client available, try to get a quote to verify the route
|
|
552
|
-
const client = getClient()
|
|
553
|
-
if (client) {
|
|
554
|
-
try {
|
|
555
|
-
const sender = "0x1111111111111111111111111111111111111111"
|
|
556
|
-
|
|
557
|
-
const quote = await client.actions.getQuote({
|
|
558
|
-
chainId: originChainId,
|
|
559
|
-
toChainId: destinationChainId,
|
|
560
|
-
amount: amount,
|
|
561
|
-
currency: originToken,
|
|
562
|
-
toCurrency: destinationToken,
|
|
563
|
-
tradeType: "EXACT_OUTPUT",
|
|
564
|
-
txs: [],
|
|
565
|
-
user: sender,
|
|
566
|
-
recipient: sender,
|
|
567
|
-
})
|
|
568
|
-
|
|
569
|
-
return quote.steps.length > 0
|
|
570
|
-
} catch (error) {
|
|
571
|
-
logger.console.warn(
|
|
572
|
-
"[trails-sdk] Quote check failed, falling back to chain/token validation:",
|
|
573
|
-
error,
|
|
574
|
-
)
|
|
575
|
-
// If quote fails, we still return true if chains and tokens are supported
|
|
576
|
-
return true
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
// If no client available, return true if chains and tokens are supported
|
|
581
|
-
return true
|
|
582
|
-
} catch (error) {
|
|
583
|
-
logger.console.error("[trails-sdk] Error checking route support:", error)
|
|
584
|
-
return false
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
interface RelayStatusResponse {
|
|
589
|
-
status: string
|
|
590
|
-
inTxHashes: string[]
|
|
591
|
-
txHashes: string[]
|
|
592
|
-
time: number
|
|
593
|
-
originChainId: number
|
|
594
|
-
destinationChainId: number
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
/**
|
|
598
|
-
* Fetch the status of a relay request by request ID
|
|
599
|
-
*/
|
|
600
|
-
export async function fetchRelayRequestStatus(
|
|
601
|
-
requestId: string,
|
|
602
|
-
): Promise<RelayStatusResponse> {
|
|
603
|
-
try {
|
|
604
|
-
const response = await fetch(
|
|
605
|
-
`https://api.relay.link/intents/status/v2?requestId=${requestId}`,
|
|
606
|
-
)
|
|
607
|
-
|
|
608
|
-
if (!response.ok) {
|
|
609
|
-
throw new Error(
|
|
610
|
-
`Failed to fetch relay status: ${response.status} ${response.statusText}`,
|
|
611
|
-
)
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
const data = await response.json()
|
|
615
|
-
return data as RelayStatusResponse
|
|
616
|
-
} catch (error) {
|
|
617
|
-
logger.console.error(
|
|
618
|
-
"[trails-sdk] Error fetching relay request status:",
|
|
619
|
-
error,
|
|
620
|
-
)
|
|
621
|
-
throw error
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
/**
|
|
626
|
-
* Wait for relay destination transaction to complete and return the last transaction hash
|
|
627
|
-
*/
|
|
628
|
-
export async function waitForRelayDestinationTx(
|
|
629
|
-
quoteProviderRequestId: string,
|
|
630
|
-
): Promise<string> {
|
|
631
|
-
const maxWaitTime = 5 * 60 * 1000 // 5 minutes
|
|
632
|
-
const pollInterval = 5000 // 5 seconds
|
|
633
|
-
const startTime = Date.now()
|
|
634
|
-
|
|
635
|
-
const sleep = (ms: number): Promise<void> =>
|
|
636
|
-
new Promise((resolve) => setTimeout(resolve, ms))
|
|
637
|
-
|
|
638
|
-
while (Date.now() - startTime < maxWaitTime) {
|
|
639
|
-
try {
|
|
640
|
-
const status = await fetchRelayRequestStatus(quoteProviderRequestId)
|
|
641
|
-
if (!status) {
|
|
642
|
-
throw new Error("No status found")
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
if (
|
|
646
|
-
status.inTxHashes &&
|
|
647
|
-
status.inTxHashes.length > 0 &&
|
|
648
|
-
status.originChainId === status.destinationChainId
|
|
649
|
-
) {
|
|
650
|
-
return status.inTxHashes[status.inTxHashes.length - 1]!
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
logger.console.log("[trails-sdk] Relay status check:", {
|
|
654
|
-
requestId: quoteProviderRequestId,
|
|
655
|
-
status: status.status,
|
|
656
|
-
txHashesCount: status.txHashes?.length || 0,
|
|
657
|
-
})
|
|
658
|
-
|
|
659
|
-
// Check if we have transaction hashes
|
|
660
|
-
if (status.txHashes && status.txHashes.length > 0) {
|
|
661
|
-
// Return the last transaction hash in the array
|
|
662
|
-
const lastTxHash = status.txHashes[status.txHashes.length - 1]
|
|
663
|
-
if (lastTxHash) {
|
|
664
|
-
logger.console.log(
|
|
665
|
-
"[trails-sdk] Relay transaction completed:",
|
|
666
|
-
lastTxHash,
|
|
667
|
-
)
|
|
668
|
-
return lastTxHash
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
// If status is failed or error, throw an error
|
|
673
|
-
if (status.status === "failed" || status.status === "error") {
|
|
674
|
-
throw new Error(
|
|
675
|
-
`Relay transaction failed with status: ${status.status}`,
|
|
676
|
-
)
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
// Wait before next poll
|
|
680
|
-
await sleep(pollInterval)
|
|
681
|
-
} catch (error) {
|
|
682
|
-
// If it's a fetch error (like 404), continue polling as the request might not be indexed yet
|
|
683
|
-
if (
|
|
684
|
-
error instanceof Error &&
|
|
685
|
-
(error.message.includes("Failed to fetch relay status") ||
|
|
686
|
-
error.message.includes("No status found"))
|
|
687
|
-
) {
|
|
688
|
-
logger.console.warn(
|
|
689
|
-
"[trails-sdk] Relay status not yet available, continuing to poll...",
|
|
690
|
-
)
|
|
691
|
-
await sleep(pollInterval)
|
|
692
|
-
continue
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
// For other errors, rethrow
|
|
696
|
-
throw error
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
throw new Error(
|
|
701
|
-
`Timeout waiting for relay transaction after ${maxWaitTime / 1000} seconds`,
|
|
702
|
-
)
|
|
703
|
-
}
|