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/aave.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { encodeFunctionData, type WalletClient } from "viem"
|
|
1
|
+
import { useMemo, useState, useEffect } from "react"
|
|
2
|
+
import { encodeFunctionData, type WalletClient, type PublicClient } from "viem"
|
|
4
3
|
import { logger } from "./logger.js"
|
|
5
4
|
|
|
6
5
|
// Chain ID to Aave market name mapping
|
|
@@ -29,6 +28,8 @@ export function getAaveV3WrappedTokenGatewayAddress(
|
|
|
29
28
|
return WRAPPED_TOKEN_GATEWAY_ADDRESS[chainId] ?? null
|
|
30
29
|
}
|
|
31
30
|
|
|
31
|
+
const AAVE_API_ENDPOINT = "https://api.v3.aave.com/graphql"
|
|
32
|
+
|
|
32
33
|
// Pool data interface
|
|
33
34
|
export interface Pool {
|
|
34
35
|
id: string
|
|
@@ -51,131 +52,237 @@ export interface Pool {
|
|
|
51
52
|
wrappedTokenGatewayAddress?: string
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Fetch all markets from Aave GraphQL API
|
|
57
|
+
*/
|
|
58
|
+
async function fetchAllMarkets(): Promise<any[]> {
|
|
59
|
+
const marketsQuery = {
|
|
60
|
+
query: `
|
|
61
|
+
query Markets {
|
|
62
|
+
markets(request: {
|
|
63
|
+
chainIds: [1, 8453, 42161, 137, 10, 100]
|
|
64
|
+
}) {
|
|
65
|
+
__typename
|
|
66
|
+
name
|
|
67
|
+
address
|
|
68
|
+
icon
|
|
69
|
+
chain {
|
|
70
|
+
__typename
|
|
71
|
+
name
|
|
72
|
+
chainId
|
|
73
|
+
icon
|
|
74
|
+
}
|
|
75
|
+
reserves {
|
|
76
|
+
__typename
|
|
77
|
+
underlyingToken {
|
|
78
|
+
__typename
|
|
79
|
+
address
|
|
80
|
+
chainId
|
|
81
|
+
name
|
|
82
|
+
symbol
|
|
83
|
+
decimals
|
|
84
|
+
imageUrl
|
|
85
|
+
}
|
|
86
|
+
aToken {
|
|
87
|
+
__typename
|
|
88
|
+
address
|
|
89
|
+
}
|
|
90
|
+
size {
|
|
91
|
+
__typename
|
|
92
|
+
amount {
|
|
93
|
+
__typename
|
|
94
|
+
value
|
|
95
|
+
}
|
|
96
|
+
usd
|
|
97
|
+
}
|
|
98
|
+
isFrozen
|
|
99
|
+
isPaused
|
|
100
|
+
supplyInfo {
|
|
101
|
+
__typename
|
|
102
|
+
apy {
|
|
103
|
+
__typename
|
|
104
|
+
value
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
`,
|
|
111
|
+
}
|
|
80
112
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
logger.console.log(
|
|
90
|
-
"[trails-sdk] Supply reserves type:",
|
|
91
|
-
typeof market.supplyReserves,
|
|
92
|
-
)
|
|
93
|
-
logger.console.log(
|
|
94
|
-
"[trails-sdk] Supply reserves length:",
|
|
95
|
-
market.supplyReserves?.length,
|
|
96
|
-
)
|
|
113
|
+
try {
|
|
114
|
+
const response = await fetch(AAVE_API_ENDPOINT, {
|
|
115
|
+
method: "POST",
|
|
116
|
+
headers: {
|
|
117
|
+
"Content-Type": "application/json",
|
|
118
|
+
},
|
|
119
|
+
body: JSON.stringify(marketsQuery),
|
|
120
|
+
})
|
|
97
121
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
122
|
+
if (!response.ok) {
|
|
123
|
+
const errorText = await response.text().catch(() => "Unknown error")
|
|
124
|
+
logger.console.error(
|
|
125
|
+
`Failed to fetch markets from GraphQL API: HTTP ${response.status} - ${errorText}`,
|
|
126
|
+
)
|
|
127
|
+
return []
|
|
128
|
+
}
|
|
105
129
|
|
|
106
|
-
|
|
107
|
-
market.supplyReserves
|
|
108
|
-
?.filter((reserve: any) => {
|
|
109
|
-
// Check if reserve has supply info and is not frozen/paused
|
|
110
|
-
const hasSupplyInfo =
|
|
111
|
-
reserve.supplyInfo && !reserve.isFrozen && !reserve.isPaused
|
|
112
|
-
const hasLiquidity = parseFloat(reserve.size?.usd || "0") > 0
|
|
113
|
-
// logger.console.log(
|
|
114
|
-
// `[trails-sdk] Reserve ${reserve.underlyingToken?.symbol}: hasSupplyInfo=${hasSupplyInfo}, hasLiquidity=${hasLiquidity}, sizeUSD=${reserve.size?.usd}`,
|
|
115
|
-
// )
|
|
116
|
-
return hasSupplyInfo && hasLiquidity
|
|
117
|
-
})
|
|
118
|
-
.map((reserve: any) => {
|
|
119
|
-
const decimals = reserve.underlyingToken?.decimals
|
|
120
|
-
if (!decimals) {
|
|
121
|
-
logger.console.warn(
|
|
122
|
-
"[trails-sdk] Missing decimals for reserve:",
|
|
123
|
-
{
|
|
124
|
-
reserve: reserve.underlyingToken,
|
|
125
|
-
market: market.chain.chainId,
|
|
126
|
-
},
|
|
127
|
-
)
|
|
128
|
-
return null // Return null instead of throwing
|
|
129
|
-
}
|
|
130
|
+
const marketsData = (await response.json()) as any
|
|
130
131
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
132
|
+
// Check for GraphQL errors
|
|
133
|
+
if (marketsData.errors && marketsData.errors.length > 0) {
|
|
134
|
+
logger.console.error(
|
|
135
|
+
"GraphQL errors in markets query:",
|
|
136
|
+
marketsData.errors,
|
|
137
|
+
)
|
|
138
|
+
return []
|
|
139
|
+
}
|
|
136
140
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
symbol: tokenMetadata.symbol,
|
|
146
|
-
name: tokenMetadata.name,
|
|
147
|
-
address: reserve.underlyingToken?.address,
|
|
148
|
-
decimals: tokenMetadata.decimals,
|
|
149
|
-
logoUrl:
|
|
150
|
-
"logoUrl" in tokenMetadata
|
|
151
|
-
? tokenMetadata.logoUrl
|
|
152
|
-
: reserve.underlyingToken?.imageUrl,
|
|
153
|
-
},
|
|
154
|
-
depositAddress: market.address,
|
|
155
|
-
isActive: !reserve.isFrozen && !reserve.isPaused,
|
|
156
|
-
protocolUrl: "https://app.aave.com/",
|
|
157
|
-
poolUrl: `https://app.aave.com/reserve-overview/?underlyingAsset=${reserve.underlyingToken?.address?.toLowerCase()}&marketName=${CHAIN_TO_MARKET_NAME[market.chain.chainId] || "proto_mainnet_v3"}`,
|
|
158
|
-
wrappedTokenGatewayAddress:
|
|
159
|
-
getAaveV3WrappedTokenGatewayAddress(market.chain.chainId) ||
|
|
160
|
-
undefined,
|
|
161
|
-
}
|
|
141
|
+
// Validate response structure
|
|
142
|
+
if (!marketsData.data || !Array.isArray(marketsData.data.markets)) {
|
|
143
|
+
logger.console.warn(
|
|
144
|
+
"Invalid response structure from Aave API:",
|
|
145
|
+
marketsData,
|
|
146
|
+
)
|
|
147
|
+
return []
|
|
148
|
+
}
|
|
162
149
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
150
|
+
return marketsData.data.markets
|
|
151
|
+
} catch (apiError) {
|
|
152
|
+
logger.console.error("Failed to fetch markets from GraphQL API:", apiError)
|
|
153
|
+
return []
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Transform API market data to Pool interface
|
|
159
|
+
*/
|
|
160
|
+
function transformReserveToPool(market: any, reserve: any): Pool | null {
|
|
161
|
+
try {
|
|
162
|
+
if (!market || !reserve || !reserve.underlyingToken) {
|
|
163
|
+
return null
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const chainId = market.chain?.chainId
|
|
167
|
+
if (!chainId) {
|
|
168
|
+
return null
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const decimals = reserve.underlyingToken?.decimals
|
|
172
|
+
if (!decimals) {
|
|
173
|
+
logger.console.warn("[trails-sdk] Missing decimals for reserve:", {
|
|
174
|
+
reserve: reserve.underlyingToken,
|
|
175
|
+
market: chainId,
|
|
176
|
+
})
|
|
177
|
+
return null
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Validate required fields
|
|
181
|
+
if (!reserve.underlyingToken?.address || !market.address) {
|
|
182
|
+
logger.console.warn(
|
|
183
|
+
"[trails-sdk] Missing required addresses for reserve:",
|
|
184
|
+
{
|
|
185
|
+
underlyingTokenAddress: reserve.underlyingToken?.address,
|
|
186
|
+
marketAddress: market.address,
|
|
187
|
+
chainId,
|
|
188
|
+
},
|
|
189
|
+
)
|
|
190
|
+
return null
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Check if reserve has supply info and is not frozen/paused
|
|
194
|
+
const hasSupplyInfo =
|
|
195
|
+
reserve.supplyInfo && !reserve.isFrozen && !reserve.isPaused
|
|
196
|
+
const usdValue = reserve.size?.usd || "0"
|
|
197
|
+
const usdValueNum = parseFloat(usdValue)
|
|
198
|
+
const hasLiquidity = !Number.isNaN(usdValueNum) && usdValueNum > 0
|
|
199
|
+
|
|
200
|
+
if (!hasSupplyInfo || !hasLiquidity) {
|
|
201
|
+
return null
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Parse APY value safely
|
|
205
|
+
const apyValue = reserve.supplyInfo?.apy?.value || "0"
|
|
206
|
+
const apyNum = parseFloat(apyValue)
|
|
207
|
+
if (Number.isNaN(apyNum)) {
|
|
208
|
+
logger.console.warn("[trails-sdk] Invalid APY value for reserve:", {
|
|
209
|
+
symbol: reserve.underlyingToken?.symbol,
|
|
210
|
+
apyValue,
|
|
211
|
+
chainId,
|
|
168
212
|
})
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
213
|
+
return null
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const tokenMetadata = {
|
|
217
|
+
symbol: reserve.underlyingToken?.symbol || "UNKNOWN",
|
|
218
|
+
name: reserve.underlyingToken?.name || "Unknown Token",
|
|
219
|
+
decimals,
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const pool: Pool = {
|
|
223
|
+
id: `${reserve.underlyingToken.address}-${chainId}-${reserve.aToken?.address || ""}`,
|
|
224
|
+
name: `${tokenMetadata.symbol} Market`,
|
|
225
|
+
protocol: "Aave",
|
|
226
|
+
chainId: chainId,
|
|
227
|
+
apy: apyNum * 100, // Convert to percentage
|
|
228
|
+
tvl: usdValueNum,
|
|
229
|
+
token: {
|
|
230
|
+
symbol: tokenMetadata.symbol,
|
|
231
|
+
name: tokenMetadata.name,
|
|
232
|
+
address: reserve.underlyingToken.address,
|
|
233
|
+
decimals: tokenMetadata.decimals,
|
|
234
|
+
logoUrl: reserve.underlyingToken?.imageUrl,
|
|
235
|
+
},
|
|
236
|
+
depositAddress: market.address,
|
|
237
|
+
isActive: !reserve.isFrozen && !reserve.isPaused,
|
|
238
|
+
protocolUrl: "https://app.aave.com/",
|
|
239
|
+
poolUrl: `https://app.aave.com/reserve-overview/?underlyingAsset=${reserve.underlyingToken.address.toLowerCase()}&marketName=${CHAIN_TO_MARKET_NAME[chainId] || "proto_mainnet_v3"}`,
|
|
240
|
+
wrappedTokenGatewayAddress:
|
|
241
|
+
getAaveV3WrappedTokenGatewayAddress(chainId) || undefined,
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return pool
|
|
245
|
+
} catch (error) {
|
|
246
|
+
logger.console.error(`Failed to transform reserve data:`, error)
|
|
247
|
+
return null
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export function useAavePools() {
|
|
252
|
+
const [pools, setPools] = useState<Pool[]>([])
|
|
253
|
+
const [loading, setLoading] = useState(true)
|
|
254
|
+
const [error, setError] = useState<Error | null>(null)
|
|
255
|
+
|
|
256
|
+
useEffect(() => {
|
|
257
|
+
async function fetchPools() {
|
|
258
|
+
try {
|
|
259
|
+
setLoading(true)
|
|
260
|
+
setError(null)
|
|
261
|
+
|
|
262
|
+
const marketsData = await fetchAllMarkets()
|
|
263
|
+
const transformedPools = marketsData.flatMap((market) => {
|
|
264
|
+
if (!market.reserves || market.reserves.length === 0) {
|
|
265
|
+
return []
|
|
266
|
+
}
|
|
267
|
+
return market.reserves
|
|
268
|
+
.map((reserve: any) => transformReserveToPool(market, reserve))
|
|
269
|
+
.filter((pool: Pool | null): pool is Pool => pool !== null)
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
setPools(transformedPools)
|
|
273
|
+
} catch (err) {
|
|
274
|
+
setError(
|
|
275
|
+
err instanceof Error ? err : new Error("Failed to fetch Aave pools"),
|
|
276
|
+
)
|
|
277
|
+
} finally {
|
|
278
|
+
setLoading(false)
|
|
279
|
+
}
|
|
172
280
|
}
|
|
173
|
-
}, [markets])
|
|
174
281
|
|
|
175
|
-
|
|
176
|
-
|
|
282
|
+
fetchPools()
|
|
283
|
+
}, [])
|
|
177
284
|
|
|
178
|
-
// Sort by APY descending
|
|
285
|
+
// Sort by APY descending
|
|
179
286
|
const sortedPools = useMemo(() => {
|
|
180
287
|
return pools.sort((a: Pool, b: Pool) => b.apy - a.apy)
|
|
181
288
|
}, [pools])
|
|
@@ -187,6 +294,88 @@ export function useAavePools() {
|
|
|
187
294
|
}
|
|
188
295
|
}
|
|
189
296
|
|
|
297
|
+
/**
|
|
298
|
+
* Get all pools for a specific chain
|
|
299
|
+
*/
|
|
300
|
+
export async function getAavePoolsForChain(
|
|
301
|
+
chainId: number,
|
|
302
|
+
_publicClient: PublicClient,
|
|
303
|
+
): Promise<Pool[]> {
|
|
304
|
+
try {
|
|
305
|
+
if (!chainId || chainId <= 0) {
|
|
306
|
+
logger.console.warn(
|
|
307
|
+
"[trails-sdk] Invalid chainId provided to getAavePoolsForChain:",
|
|
308
|
+
chainId,
|
|
309
|
+
)
|
|
310
|
+
return []
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const marketsData = await fetchAllMarkets()
|
|
314
|
+
if (!marketsData || marketsData.length === 0) {
|
|
315
|
+
logger.console.warn(
|
|
316
|
+
"[trails-sdk] No markets data returned for chain:",
|
|
317
|
+
chainId,
|
|
318
|
+
)
|
|
319
|
+
return []
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const chainMarkets = marketsData.filter(
|
|
323
|
+
(market) => market.chain?.chainId === chainId,
|
|
324
|
+
)
|
|
325
|
+
|
|
326
|
+
if (chainMarkets.length === 0) {
|
|
327
|
+
logger.console.warn("[trails-sdk] No markets found for chain:", chainId)
|
|
328
|
+
return []
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const transformedPools = chainMarkets.flatMap((market) => {
|
|
332
|
+
if (!market.reserves || market.reserves.length === 0) {
|
|
333
|
+
return []
|
|
334
|
+
}
|
|
335
|
+
return market.reserves
|
|
336
|
+
.map((reserve: any) => transformReserveToPool(market, reserve))
|
|
337
|
+
.filter((pool: Pool | null): pool is Pool => pool !== null)
|
|
338
|
+
})
|
|
339
|
+
|
|
340
|
+
return transformedPools
|
|
341
|
+
} catch (error) {
|
|
342
|
+
logger.console.error(
|
|
343
|
+
`Failed to get Aave pools for chain ${chainId}:`,
|
|
344
|
+
error,
|
|
345
|
+
)
|
|
346
|
+
return []
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Get all pools across all chains
|
|
352
|
+
*/
|
|
353
|
+
export async function getAllAavePools(
|
|
354
|
+
_publicClient: PublicClient,
|
|
355
|
+
): Promise<Pool[]> {
|
|
356
|
+
try {
|
|
357
|
+
const marketsData = await fetchAllMarkets()
|
|
358
|
+
if (!marketsData || marketsData.length === 0) {
|
|
359
|
+
logger.console.warn("[trails-sdk] No markets data returned")
|
|
360
|
+
return []
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const transformedPools = marketsData.flatMap((market) => {
|
|
364
|
+
if (!market.reserves || market.reserves.length === 0) {
|
|
365
|
+
return []
|
|
366
|
+
}
|
|
367
|
+
return market.reserves
|
|
368
|
+
.map((reserve: any) => transformReserveToPool(market, reserve))
|
|
369
|
+
.filter((pool: Pool | null): pool is Pool => pool !== null)
|
|
370
|
+
})
|
|
371
|
+
|
|
372
|
+
return transformedPools
|
|
373
|
+
} catch (error) {
|
|
374
|
+
logger.console.error("Failed to get all Aave pools:", error)
|
|
375
|
+
return []
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
190
379
|
/**
|
|
191
380
|
* Generate Aave withdraw calldata
|
|
192
381
|
* @param asset - The address of the underlying asset to withdraw
|
|
@@ -199,23 +388,45 @@ export function generateAaveWithdrawCalldata(
|
|
|
199
388
|
amount: bigint,
|
|
200
389
|
to: string,
|
|
201
390
|
): `0x${string}` {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
391
|
+
try {
|
|
392
|
+
if (!asset || !to) {
|
|
393
|
+
throw new Error("Asset and recipient addresses are required")
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (amount <= 0n) {
|
|
397
|
+
throw new Error("Amount must be greater than 0")
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// Basic address validation (should start with 0x and be 42 chars)
|
|
401
|
+
if (!asset.startsWith("0x") || asset.length !== 42) {
|
|
402
|
+
throw new Error(`Invalid asset address: ${asset}`)
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (!to.startsWith("0x") || to.length !== 42) {
|
|
406
|
+
throw new Error(`Invalid recipient address: ${to}`)
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
return encodeFunctionData({
|
|
410
|
+
abi: [
|
|
411
|
+
{
|
|
412
|
+
name: "withdraw",
|
|
413
|
+
type: "function",
|
|
414
|
+
stateMutability: "nonpayable",
|
|
415
|
+
inputs: [
|
|
416
|
+
{ name: "asset", type: "address" },
|
|
417
|
+
{ name: "amount", type: "uint256" },
|
|
418
|
+
{ name: "to", type: "address" },
|
|
419
|
+
],
|
|
420
|
+
outputs: [{ type: "uint256" }],
|
|
421
|
+
},
|
|
422
|
+
],
|
|
423
|
+
functionName: "withdraw",
|
|
424
|
+
args: [asset as `0x${string}`, amount, to as `0x${string}`],
|
|
425
|
+
})
|
|
426
|
+
} catch (error) {
|
|
427
|
+
logger.console.error("Error generating Aave withdraw calldata:", error)
|
|
428
|
+
throw error
|
|
429
|
+
}
|
|
219
430
|
}
|
|
220
431
|
|
|
221
432
|
// Generate deposit calldata for Aave pool
|
|
@@ -225,11 +436,38 @@ export const generateAaveDepositCalldata = (
|
|
|
225
436
|
amount: string,
|
|
226
437
|
) => {
|
|
227
438
|
try {
|
|
439
|
+
if (!walletClient) {
|
|
440
|
+
throw new Error("Wallet client is required")
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (!pool) {
|
|
444
|
+
throw new Error("Pool is required")
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
if (!pool.token || !pool.token.address) {
|
|
448
|
+
throw new Error("Pool token address is required")
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// Validate pool token address
|
|
452
|
+
if (
|
|
453
|
+
!pool.token.address.startsWith("0x") ||
|
|
454
|
+
pool.token.address.length !== 42
|
|
455
|
+
) {
|
|
456
|
+
throw new Error(`Invalid pool token address: ${pool.token.address}`)
|
|
457
|
+
}
|
|
458
|
+
|
|
228
459
|
const userAddress = walletClient?.account?.address || walletClient?.account
|
|
229
460
|
if (!userAddress) {
|
|
230
461
|
throw new Error("User address not found")
|
|
231
462
|
}
|
|
232
463
|
|
|
464
|
+
// Validate user address format
|
|
465
|
+
const addressStr =
|
|
466
|
+
typeof userAddress === "string" ? userAddress : String(userAddress)
|
|
467
|
+
if (!addressStr.startsWith("0x") || addressStr.length !== 42) {
|
|
468
|
+
throw new Error(`Invalid user address: ${addressStr}`)
|
|
469
|
+
}
|
|
470
|
+
|
|
233
471
|
// Validate amount
|
|
234
472
|
if (
|
|
235
473
|
!amount ||
|
|
@@ -237,7 +475,18 @@ export const generateAaveDepositCalldata = (
|
|
|
237
475
|
Number.isNaN(Number(amount)) ||
|
|
238
476
|
Number(amount) <= 0
|
|
239
477
|
) {
|
|
240
|
-
throw new Error(
|
|
478
|
+
throw new Error(`Invalid amount: ${amount}`)
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// Validate amount can be converted to BigInt
|
|
482
|
+
let amountBigInt: bigint
|
|
483
|
+
try {
|
|
484
|
+
amountBigInt = BigInt(amount)
|
|
485
|
+
if (amountBigInt <= 0n) {
|
|
486
|
+
throw new Error("Amount must be greater than 0")
|
|
487
|
+
}
|
|
488
|
+
} catch {
|
|
489
|
+
throw new Error(`Invalid amount format: ${amount}`)
|
|
241
490
|
}
|
|
242
491
|
|
|
243
492
|
// Aave V3 Pool contract deposit function
|
|
@@ -259,8 +508,8 @@ export const generateAaveDepositCalldata = (
|
|
|
259
508
|
],
|
|
260
509
|
args: [
|
|
261
510
|
pool.token.address as `0x${string}`, // asset address
|
|
262
|
-
|
|
263
|
-
|
|
511
|
+
amountBigInt, // amount to deposit
|
|
512
|
+
addressStr as `0x${string}`, // onBehalfOf (user's address)
|
|
264
513
|
0, // referralCode (0 for no referral)
|
|
265
514
|
],
|
|
266
515
|
})
|