@eth-optimism/actions-sdk 0.1.0 → 0.2.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/LICENSE +1 -1
- package/dist/__mocks__/MockAssets.d.ts.map +1 -0
- package/dist/__mocks__/MockAssets.js.map +1 -0
- package/dist/__mocks__/MockPrivyClient.d.ts.map +1 -0
- package/dist/__mocks__/MockPrivyClient.js.map +1 -0
- package/dist/__mocks__/utils.d.ts.map +1 -0
- package/dist/__mocks__/utils.js.map +1 -0
- package/dist/__tests__/actions.test.d.ts.map +1 -0
- package/dist/{actions.test.js → __tests__/actions.test.js} +5 -5
- package/dist/__tests__/actions.test.js.map +1 -0
- package/dist/constants/assets.d.ts +19 -0
- package/dist/constants/assets.d.ts.map +1 -1
- package/dist/constants/assets.js +84 -6
- package/dist/constants/assets.js.map +1 -1
- package/dist/constants/supportedChains.d.ts +1 -1
- package/dist/constants/supportedChains.d.ts.map +1 -1
- package/dist/constants/supportedChains.js +7 -3
- package/dist/constants/supportedChains.js.map +1 -1
- package/dist/core/asset/__mocks__/mockAsset.js +1 -1
- package/dist/core/asset/__mocks__/mockAsset.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/{test → lend/__mocks__}/MockLendProvider.d.ts +7 -6
- package/dist/lend/__mocks__/MockLendProvider.d.ts.map +1 -0
- package/dist/{test → lend/__mocks__}/MockLendProvider.js +20 -21
- package/dist/lend/__mocks__/MockLendProvider.js.map +1 -0
- package/dist/{test → lend/__mocks__}/MockMarkets.d.ts +1 -1
- package/dist/lend/__mocks__/MockMarkets.d.ts.map +1 -0
- package/dist/{test → lend/__mocks__}/MockMarkets.js +1 -1
- package/dist/lend/__mocks__/MockMarkets.js.map +1 -0
- package/dist/lend/__mocks__/mockLendTransaction.d.ts +3 -12
- package/dist/lend/__mocks__/mockLendTransaction.d.ts.map +1 -1
- package/dist/lend/__mocks__/mockLendTransaction.js +3 -19
- package/dist/lend/__mocks__/mockLendTransaction.js.map +1 -1
- package/dist/lend/core/LendProvider.d.ts +14 -2
- package/dist/lend/core/LendProvider.d.ts.map +1 -1
- package/dist/lend/core/LendProvider.js +23 -2
- package/dist/lend/core/LendProvider.js.map +1 -1
- package/dist/lend/core/__tests__/LendProvider.test.js +2 -2
- package/dist/lend/core/__tests__/LendProvider.test.js.map +1 -1
- package/dist/lend/namespaces/ActionsLendNamespace.d.ts +2 -36
- package/dist/lend/namespaces/ActionsLendNamespace.d.ts.map +1 -1
- package/dist/lend/namespaces/ActionsLendNamespace.js +2 -48
- package/dist/lend/namespaces/ActionsLendNamespace.js.map +1 -1
- package/dist/lend/namespaces/BaseLendNamespace.d.ts +47 -0
- package/dist/lend/namespaces/BaseLendNamespace.d.ts.map +1 -0
- package/dist/lend/namespaces/BaseLendNamespace.js +58 -0
- package/dist/lend/namespaces/BaseLendNamespace.js.map +1 -0
- package/dist/lend/namespaces/WalletLendNamespace.d.ts +8 -36
- package/dist/lend/namespaces/WalletLendNamespace.d.ts.map +1 -1
- package/dist/lend/namespaces/WalletLendNamespace.js +14 -69
- package/dist/lend/namespaces/WalletLendNamespace.js.map +1 -1
- package/dist/lend/namespaces/__tests__/ActionsLendNamespace.spec.js +2 -2
- package/dist/lend/namespaces/__tests__/ActionsLendNamespace.spec.js.map +1 -1
- package/dist/lend/namespaces/__tests__/BaseLendNamespace.spec.d.ts +2 -0
- package/dist/lend/namespaces/__tests__/BaseLendNamespace.spec.d.ts.map +1 -0
- package/dist/lend/namespaces/__tests__/BaseLendNamespace.spec.js +110 -0
- package/dist/lend/namespaces/__tests__/BaseLendNamespace.spec.js.map +1 -0
- package/dist/lend/namespaces/__tests__/WalletLendNamespace.spec.js +8 -10
- package/dist/lend/namespaces/__tests__/WalletLendNamespace.spec.js.map +1 -1
- package/dist/lend/providers/aave/AaveLendProvider.d.ts +19 -27
- package/dist/lend/providers/aave/AaveLendProvider.d.ts.map +1 -1
- package/dist/lend/providers/aave/AaveLendProvider.js +124 -180
- package/dist/lend/providers/aave/AaveLendProvider.js.map +1 -1
- package/dist/lend/providers/aave/__mocks__/mockReserve.d.ts +11 -0
- package/dist/lend/providers/aave/__mocks__/mockReserve.d.ts.map +1 -0
- package/dist/lend/providers/aave/__mocks__/mockReserve.js +80 -0
- package/dist/lend/providers/aave/__mocks__/mockReserve.js.map +1 -0
- package/dist/lend/providers/aave/__tests__/AaveLendProvider.test.d.ts +2 -0
- package/dist/lend/providers/aave/__tests__/AaveLendProvider.test.d.ts.map +1 -0
- package/dist/lend/providers/aave/__tests__/AaveLendProvider.test.js +315 -0
- package/dist/lend/providers/aave/__tests__/AaveLendProvider.test.js.map +1 -0
- package/dist/lend/providers/aave/abis/pool.d.ts +153 -0
- package/dist/lend/providers/aave/abis/pool.d.ts.map +1 -0
- package/dist/lend/providers/aave/abis/pool.js +79 -0
- package/dist/lend/providers/aave/abis/pool.js.map +1 -0
- package/dist/lend/providers/aave/sdk.d.ts.map +1 -1
- package/dist/lend/providers/aave/sdk.js +6 -65
- package/dist/lend/providers/aave/sdk.js.map +1 -1
- package/dist/lend/providers/morpho/MorphoLendProvider.d.ts +0 -1
- package/dist/lend/providers/morpho/MorphoLendProvider.d.ts.map +1 -1
- package/dist/lend/providers/morpho/MorphoLendProvider.js +13 -28
- package/dist/lend/providers/morpho/MorphoLendProvider.js.map +1 -1
- package/dist/lend/providers/morpho/__tests__/MorphoLendProvider.test.js +5 -24
- package/dist/lend/providers/morpho/__tests__/MorphoLendProvider.test.js.map +1 -1
- package/dist/lend/providers/morpho/__tests__/api.test.js +248 -54
- package/dist/lend/providers/morpho/__tests__/api.test.js.map +1 -1
- package/dist/lend/providers/morpho/contracts.d.ts +19 -0
- package/dist/lend/providers/morpho/contracts.d.ts.map +1 -0
- package/dist/lend/providers/morpho/contracts.js +32 -0
- package/dist/lend/providers/morpho/contracts.js.map +1 -0
- package/dist/lend/providers/morpho/sdk.d.ts.map +1 -1
- package/dist/lend/providers/morpho/sdk.js +168 -71
- package/dist/lend/providers/morpho/sdk.js.map +1 -1
- package/dist/services/ChainManager.d.ts +1 -1
- package/dist/{test → services/__mocks__}/MockChainManager.d.ts +1 -1
- package/dist/services/__mocks__/MockChainManager.d.ts.map +1 -0
- package/dist/services/__mocks__/MockChainManager.js.map +1 -0
- package/dist/services/tokenBalance.d.ts.map +1 -1
- package/dist/services/tokenBalance.js +4 -5
- package/dist/services/tokenBalance.js.map +1 -1
- package/dist/services/tokenBalance.spec.js +2 -2
- package/dist/services/tokenBalance.spec.js.map +1 -1
- package/dist/supported/tokens.d.ts +4 -4
- package/dist/supported/tokens.d.ts.map +1 -1
- package/dist/supported/tokens.js +5 -72
- package/dist/supported/tokens.js.map +1 -1
- package/dist/types/asset.d.ts +3 -3
- package/dist/types/asset.d.ts.map +1 -1
- package/dist/types/lend/base.d.ts +4 -9
- package/dist/types/lend/base.d.ts.map +1 -1
- package/dist/types/lend/contracts.d.ts +17 -0
- package/dist/types/lend/contracts.d.ts.map +1 -0
- package/dist/types/lend/contracts.js +2 -0
- package/dist/types/lend/contracts.js.map +1 -0
- package/dist/types/lend/index.d.ts +1 -0
- package/dist/types/lend/index.d.ts.map +1 -1
- package/dist/types/lend/index.js +1 -0
- package/dist/types/lend/index.js.map +1 -1
- package/dist/utils/assets.d.ts +7 -1
- package/dist/utils/assets.d.ts.map +1 -1
- package/dist/utils/assets.js +12 -1
- package/dist/utils/assets.js.map +1 -1
- package/dist/utils/assets.test.js +1 -1
- package/dist/utils/assets.test.js.map +1 -1
- package/dist/utils/constants.d.ts +5 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +5 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/wallet/core/namespace/WalletNamespace.d.ts.map +1 -1
- package/dist/wallet/core/namespace/WalletNamespace.js.map +1 -1
- package/dist/wallet/core/namespace/__tests__/WalletNamespace.spec.js +4 -4
- package/dist/wallet/core/namespace/__tests__/WalletNamespace.spec.js.map +1 -1
- package/dist/wallet/core/providers/__tests__/WalletProvider.spec.js +4 -4
- package/dist/wallet/core/providers/__tests__/WalletProvider.spec.js.map +1 -1
- package/dist/wallet/core/providers/hosted/registry/__tests__/HostedWalletProviderRegistry.spec.js +2 -2
- package/dist/wallet/core/providers/hosted/registry/__tests__/HostedWalletProviderRegistry.spec.js.map +1 -1
- package/dist/wallet/core/providers/smart/default/__tests__/DefaultSmartWalletProvider.spec.js +3 -3
- package/dist/wallet/core/providers/smart/default/__tests__/DefaultSmartWalletProvider.spec.js.map +1 -1
- package/dist/wallet/core/wallets/abstract/__tests__/Wallet.spec.js +2 -2
- package/dist/wallet/core/wallets/abstract/__tests__/Wallet.spec.js.map +1 -1
- package/dist/wallet/core/wallets/eoa/__tests__/EOAWallet.spec.js +2 -2
- package/dist/wallet/core/wallets/eoa/__tests__/EOAWallet.spec.js.map +1 -1
- package/dist/wallet/core/wallets/smart/default/__tests__/DefaultSmartWallet.spec.js +3 -3
- package/dist/wallet/core/wallets/smart/default/__tests__/DefaultSmartWallet.spec.js.map +1 -1
- package/dist/wallet/core/wallets/smart/default/utils/__tests__/findSignerInArray.spec.js +1 -1
- package/dist/wallet/core/wallets/smart/default/utils/__tests__/findSignerInArray.spec.js.map +1 -1
- package/dist/wallet/core/wallets/smart/default/utils/__tests__/getSignerPublicKey.spec.js +1 -1
- package/dist/wallet/core/wallets/smart/default/utils/__tests__/getSignerPublicKey.spec.js.map +1 -1
- package/dist/wallet/node/providers/hosted/privy/__tests__/PrivyHostedWalletProvider.spec.js +4 -4
- package/dist/wallet/node/providers/hosted/privy/__tests__/PrivyHostedWalletProvider.spec.js.map +1 -1
- package/dist/wallet/node/providers/hosted/registry/__tests__/NodeHostedWalletProviderRegistry.spec.js +2 -2
- package/dist/wallet/node/providers/hosted/registry/__tests__/NodeHostedWalletProviderRegistry.spec.js.map +1 -1
- package/dist/wallet/node/providers/hosted/turnkey/__tests__/TurnkeyHostedWalletProvider.spec.js +2 -2
- package/dist/wallet/node/providers/hosted/turnkey/__tests__/TurnkeyHostedWalletProvider.spec.js.map +1 -1
- package/dist/wallet/node/wallets/hosted/privy/__tests__/PrivyWallet.spec.js +3 -3
- package/dist/wallet/node/wallets/hosted/privy/__tests__/PrivyWallet.spec.js.map +1 -1
- package/dist/wallet/node/wallets/hosted/privy/utils/__tests__/createSigner.spec.js +2 -2
- package/dist/wallet/node/wallets/hosted/privy/utils/__tests__/createSigner.spec.js.map +1 -1
- package/dist/wallet/node/wallets/hosted/turnkey/__tests__/TurnkeyWallet.spec.js +2 -2
- package/dist/wallet/node/wallets/hosted/turnkey/__tests__/TurnkeyWallet.spec.js.map +1 -1
- package/dist/wallet/node/wallets/hosted/turnkey/utils/__tests__/createSigner.spec.js +1 -1
- package/dist/wallet/node/wallets/hosted/turnkey/utils/__tests__/createSigner.spec.js.map +1 -1
- package/dist/wallet/react/providers/hosted/dynamic/__mocks__/DynamicHostedWalletProviderMock.d.ts.map +1 -1
- package/dist/wallet/react/providers/hosted/dynamic/__mocks__/DynamicHostedWalletProviderMock.js +1 -1
- package/dist/wallet/react/providers/hosted/dynamic/__mocks__/DynamicHostedWalletProviderMock.js.map +1 -1
- package/dist/wallet/react/providers/hosted/dynamic/__tests__/DynamicHostedWalletProvider.spec.js +5 -2
- package/dist/wallet/react/providers/hosted/dynamic/__tests__/DynamicHostedWalletProvider.spec.js.map +1 -1
- package/dist/wallet/react/providers/hosted/privy/__mocks__/PrivyHostedWalletProviderMock.d.ts.map +1 -1
- package/dist/wallet/react/providers/hosted/privy/__mocks__/PrivyHostedWalletProviderMock.js +1 -1
- package/dist/wallet/react/providers/hosted/privy/__mocks__/PrivyHostedWalletProviderMock.js.map +1 -1
- package/dist/wallet/react/providers/hosted/privy/__tests__/PrivyHostedWalletProvider.spec.js +2 -2
- package/dist/wallet/react/providers/hosted/privy/__tests__/PrivyHostedWalletProvider.spec.js.map +1 -1
- package/dist/wallet/react/providers/hosted/turnkey/__tests__/TurnkeyHostedWalletProvider.spec.js +2 -2
- package/dist/wallet/react/providers/hosted/turnkey/__tests__/TurnkeyHostedWalletProvider.spec.js.map +1 -1
- package/dist/wallet/react/providers/registry/__tests__/ReactHostedWalletProviderRegistry.spec.js +1 -1
- package/dist/wallet/react/providers/registry/__tests__/ReactHostedWalletProviderRegistry.spec.js.map +1 -1
- package/dist/wallet/react/wallets/hosted/dynamic/__tests__/DynamicWallet.spec.js +2 -2
- package/dist/wallet/react/wallets/hosted/dynamic/__tests__/DynamicWallet.spec.js.map +1 -1
- package/dist/wallet/react/wallets/hosted/dynamic/utils/__tests__/createSigner.spec.js +1 -1
- package/dist/wallet/react/wallets/hosted/dynamic/utils/__tests__/createSigner.spec.js.map +1 -1
- package/dist/wallet/react/wallets/hosted/privy/__tests__/PrivyWallet.spec.js +2 -2
- package/dist/wallet/react/wallets/hosted/privy/__tests__/PrivyWallet.spec.js.map +1 -1
- package/dist/wallet/react/wallets/hosted/privy/utils/__tests__/createSigner.spec.js +1 -1
- package/dist/wallet/react/wallets/hosted/privy/utils/__tests__/createSigner.spec.js.map +1 -1
- package/dist/wallet/react/wallets/hosted/turnkey/__tests__/TurnkeyWallet.spec.js +2 -2
- package/dist/wallet/react/wallets/hosted/turnkey/__tests__/TurnkeyWallet.spec.js.map +1 -1
- package/dist/wallet/react/wallets/hosted/turnkey/utils/__tests__/createSigner.spec.js +1 -1
- package/dist/wallet/react/wallets/hosted/turnkey/utils/__tests__/createSigner.spec.js.map +1 -1
- package/package.json +1 -1
- package/src/{test → __mocks__}/MockPrivyClient.ts +1 -1
- package/src/{actions.test.ts → __tests__/actions.test.ts} +2 -2
- package/src/constants/assets.ts +92 -8
- package/src/constants/supportedChains.ts +10 -2
- package/src/core/asset/__mocks__/mockAsset.ts +1 -1
- package/src/index.ts +1 -1
- package/src/{test → lend/__mocks__}/MockLendProvider.ts +20 -23
- package/src/{test → lend/__mocks__}/MockMarkets.ts +1 -1
- package/src/lend/__mocks__/mockLendTransaction.ts +4 -26
- package/src/lend/core/LendProvider.ts +34 -2
- package/src/lend/core/__tests__/LendProvider.test.ts +2 -2
- package/src/lend/namespaces/ActionsLendNamespace.ts +2 -85
- package/src/lend/namespaces/BaseLendNamespace.ts +89 -0
- package/src/lend/namespaces/WalletLendNamespace.ts +25 -121
- package/src/lend/namespaces/__tests__/ActionsLendNamespace.spec.ts +10 -9
- package/src/lend/namespaces/__tests__/BaseLendNamespace.spec.ts +137 -0
- package/src/lend/namespaces/__tests__/WalletLendNamespace.spec.ts +19 -22
- package/src/lend/providers/aave/AaveLendProvider.ts +163 -231
- package/src/lend/providers/aave/__mocks__/mockReserve.ts +84 -0
- package/src/lend/providers/aave/__tests__/AaveLendProvider.test.ts +419 -0
- package/src/lend/providers/aave/abis/pool.ts +81 -0
- package/src/lend/providers/aave/sdk.ts +7 -69
- package/src/lend/providers/morpho/MorphoLendProvider.ts +20 -41
- package/src/lend/providers/morpho/__tests__/MorphoLendProvider.test.ts +8 -32
- package/src/lend/providers/morpho/__tests__/api.test.ts +277 -51
- package/src/lend/providers/morpho/contracts.ts +37 -0
- package/src/lend/providers/morpho/sdk.ts +232 -84
- package/src/services/tokenBalance.spec.ts +2 -2
- package/src/services/tokenBalance.ts +6 -7
- package/src/supported/tokens.ts +6 -79
- package/src/types/asset.ts +3 -3
- package/src/types/lend/base.ts +8 -11
- package/src/types/lend/contracts.ts +18 -0
- package/src/types/lend/index.ts +1 -0
- package/src/utils/assets.test.ts +1 -1
- package/src/utils/assets.ts +15 -1
- package/src/utils/constants.ts +4 -0
- package/src/wallet/core/namespace/WalletNamespace.ts +2 -4
- package/src/wallet/core/namespace/__tests__/WalletNamespace.spec.ts +6 -6
- package/src/wallet/core/providers/__tests__/WalletProvider.spec.ts +6 -6
- package/src/wallet/core/providers/hosted/registry/__tests__/HostedWalletProviderRegistry.spec.ts +3 -3
- package/src/wallet/core/providers/smart/default/__tests__/DefaultSmartWalletProvider.spec.ts +7 -9
- package/src/wallet/core/wallets/abstract/__tests__/Wallet.spec.ts +2 -2
- package/src/wallet/core/wallets/eoa/__tests__/EOAWallet.spec.ts +2 -2
- package/src/wallet/core/wallets/smart/default/__tests__/DefaultSmartWallet.spec.ts +3 -3
- package/src/wallet/core/wallets/smart/default/utils/__tests__/findSignerInArray.spec.ts +1 -1
- package/src/wallet/core/wallets/smart/default/utils/__tests__/getSignerPublicKey.spec.ts +1 -1
- package/src/wallet/node/providers/hosted/privy/__tests__/PrivyHostedWalletProvider.spec.ts +5 -5
- package/src/wallet/node/providers/hosted/registry/__tests__/NodeHostedWalletProviderRegistry.spec.ts +3 -3
- package/src/wallet/node/providers/hosted/turnkey/__tests__/TurnkeyHostedWalletProvider.spec.ts +2 -2
- package/src/wallet/node/wallets/hosted/privy/__tests__/PrivyWallet.spec.ts +4 -4
- package/src/wallet/node/wallets/hosted/privy/utils/__tests__/createSigner.spec.ts +2 -2
- package/src/wallet/node/wallets/hosted/turnkey/__tests__/TurnkeyWallet.spec.ts +2 -2
- package/src/wallet/node/wallets/hosted/turnkey/utils/__tests__/createSigner.spec.ts +1 -1
- package/src/wallet/react/providers/hosted/dynamic/__mocks__/DynamicHostedWalletProviderMock.ts +1 -1
- package/src/wallet/react/providers/hosted/dynamic/__tests__/DynamicHostedWalletProvider.spec.ts +8 -5
- package/src/wallet/react/providers/hosted/privy/__mocks__/PrivyHostedWalletProviderMock.ts +1 -1
- package/src/wallet/react/providers/hosted/privy/__tests__/PrivyHostedWalletProvider.spec.ts +4 -5
- package/src/wallet/react/providers/hosted/turnkey/__tests__/TurnkeyHostedWalletProvider.spec.ts +2 -2
- package/src/wallet/react/providers/registry/__tests__/ReactHostedWalletProviderRegistry.spec.ts +5 -7
- package/src/wallet/react/wallets/hosted/dynamic/__tests__/DynamicWallet.spec.ts +2 -2
- package/src/wallet/react/wallets/hosted/dynamic/utils/__tests__/createSigner.spec.ts +1 -1
- package/src/wallet/react/wallets/hosted/privy/__tests__/PrivyWallet.spec.ts +2 -2
- package/src/wallet/react/wallets/hosted/privy/utils/__tests__/createSigner.spec.ts +1 -1
- package/src/wallet/react/wallets/hosted/turnkey/__tests__/TurnkeyWallet.spec.ts +2 -2
- package/src/wallet/react/wallets/hosted/turnkey/utils/__tests__/createSigner.spec.ts +1 -1
- package/dist/actions.test.d.ts.map +0 -1
- package/dist/actions.test.js.map +0 -1
- package/dist/test/MockAssets.d.ts.map +0 -1
- package/dist/test/MockAssets.js.map +0 -1
- package/dist/test/MockChainManager.d.ts.map +0 -1
- package/dist/test/MockChainManager.js.map +0 -1
- package/dist/test/MockLendProvider.d.ts.map +0 -1
- package/dist/test/MockLendProvider.js.map +0 -1
- package/dist/test/MockMarkets.d.ts.map +0 -1
- package/dist/test/MockMarkets.js.map +0 -1
- package/dist/test/MockPrivyClient.d.ts.map +0 -1
- package/dist/test/MockPrivyClient.js.map +0 -1
- package/dist/test/utils.d.ts.map +0 -1
- package/dist/test/utils.js.map +0 -1
- /package/dist/{test → __mocks__}/MockAssets.d.ts +0 -0
- /package/dist/{test → __mocks__}/MockAssets.js +0 -0
- /package/dist/{test → __mocks__}/MockPrivyClient.d.ts +0 -0
- /package/dist/{test → __mocks__}/MockPrivyClient.js +0 -0
- /package/dist/{test → __mocks__}/utils.d.ts +0 -0
- /package/dist/{test → __mocks__}/utils.js +0 -0
- /package/dist/{actions.test.d.ts → __tests__/actions.test.d.ts} +0 -0
- /package/dist/{test → services/__mocks__}/MockChainManager.js +0 -0
- /package/src/{test → __mocks__}/MockAssets.ts +0 -0
- /package/src/{test → __mocks__}/utils.ts +0 -0
- /package/src/{test → services/__mocks__}/MockChainManager.ts +0 -0
|
@@ -1,18 +1,20 @@
|
|
|
1
|
+
import type { Address } from 'viem'
|
|
1
2
|
import type { WaitForUserOperationReceiptReturnType } from 'viem/account-abstraction'
|
|
2
3
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
4
|
|
|
5
|
+
import { getRandomAddress } from '@/__mocks__/utils.js'
|
|
6
|
+
import type { MockLendProvider } from '@/lend/__mocks__/MockLendProvider.js'
|
|
7
|
+
import { createMockLendProvider } from '@/lend/__mocks__/MockLendProvider.js'
|
|
4
8
|
import { WalletLendNamespace } from '@/lend/namespaces/WalletLendNamespace.js'
|
|
5
|
-
import {
|
|
6
|
-
import { getRandomAddress } from '@/test/utils.js'
|
|
7
|
-
import type { LendProvider, TransactionData } from '@/types/lend/index.js'
|
|
9
|
+
import type { TransactionData } from '@/types/lend/index.js'
|
|
8
10
|
import { createMock as createSmartWalletMock } from '@/wallet/core/wallets/smart/abstract/__mocks__/SmartWallet.js'
|
|
9
11
|
import type { SmartWallet } from '@/wallet/core/wallets/smart/abstract/SmartWallet.js'
|
|
10
12
|
|
|
11
13
|
describe('WalletLendNamespace', () => {
|
|
12
14
|
const mockWalletAddress = getRandomAddress()
|
|
13
|
-
let mockProvider:
|
|
15
|
+
let mockProvider: MockLendProvider
|
|
14
16
|
let mockWallet: SmartWallet
|
|
15
|
-
let mockMarketId: { address:
|
|
17
|
+
let mockMarketId: { address: Address; chainId: 130 }
|
|
16
18
|
|
|
17
19
|
beforeEach(() => {
|
|
18
20
|
// Create a consistent market ID for all tests
|
|
@@ -53,7 +55,7 @@ describe('WalletLendNamespace', () => {
|
|
|
53
55
|
|
|
54
56
|
it('should create an instance with a lend provider and wallet', () => {
|
|
55
57
|
const namespace = new WalletLendNamespace(
|
|
56
|
-
{ morpho: mockProvider
|
|
58
|
+
{ morpho: mockProvider },
|
|
57
59
|
mockWallet,
|
|
58
60
|
)
|
|
59
61
|
|
|
@@ -62,7 +64,7 @@ describe('WalletLendNamespace', () => {
|
|
|
62
64
|
|
|
63
65
|
it('should inherit read operations from ActionsLendNamespace', async () => {
|
|
64
66
|
const namespace = new WalletLendNamespace(
|
|
65
|
-
{ morpho: mockProvider
|
|
67
|
+
{ morpho: mockProvider },
|
|
66
68
|
mockWallet,
|
|
67
69
|
)
|
|
68
70
|
const mockMarkets = [
|
|
@@ -107,7 +109,7 @@ describe('WalletLendNamespace', () => {
|
|
|
107
109
|
describe('openPosition', () => {
|
|
108
110
|
it('should call provider openPosition with wallet address as receiver', async () => {
|
|
109
111
|
const namespace = new WalletLendNamespace(
|
|
110
|
-
{ morpho: mockProvider
|
|
112
|
+
{ morpho: mockProvider },
|
|
111
113
|
mockWallet,
|
|
112
114
|
)
|
|
113
115
|
const mockAsset = {
|
|
@@ -123,13 +125,12 @@ describe('WalletLendNamespace', () => {
|
|
|
123
125
|
marketId: marketId.address,
|
|
124
126
|
apy: 0.05,
|
|
125
127
|
transactionData: {
|
|
126
|
-
|
|
128
|
+
position: {
|
|
127
129
|
to: marketId.address,
|
|
128
130
|
value: 0n,
|
|
129
131
|
data: '0x' as const,
|
|
130
132
|
},
|
|
131
133
|
},
|
|
132
|
-
slippage: 50,
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
vi.mocked(mockProvider.openPosition).mockResolvedValue(mockTransaction)
|
|
@@ -158,7 +159,7 @@ describe('WalletLendNamespace', () => {
|
|
|
158
159
|
describe('closePosition', () => {
|
|
159
160
|
it('should call provider closePosition and execute transaction for SmartWallet', async () => {
|
|
160
161
|
const namespace = new WalletLendNamespace(
|
|
161
|
-
{ morpho: mockProvider
|
|
162
|
+
{ morpho: mockProvider },
|
|
162
163
|
mockWallet,
|
|
163
164
|
)
|
|
164
165
|
const closeParams = {
|
|
@@ -172,7 +173,7 @@ describe('WalletLendNamespace', () => {
|
|
|
172
173
|
marketId: closeParams.marketId.address,
|
|
173
174
|
apy: 0.05,
|
|
174
175
|
transactionData: {
|
|
175
|
-
|
|
176
|
+
position: {
|
|
176
177
|
to: closeParams.marketId.address,
|
|
177
178
|
value: 0n,
|
|
178
179
|
data: '0x' as const,
|
|
@@ -190,7 +191,7 @@ describe('WalletLendNamespace', () => {
|
|
|
190
191
|
options: undefined,
|
|
191
192
|
})
|
|
192
193
|
expect(mockWallet.send).toHaveBeenCalledWith(
|
|
193
|
-
mockTransaction.transactionData.
|
|
194
|
+
mockTransaction.transactionData.position,
|
|
194
195
|
130,
|
|
195
196
|
)
|
|
196
197
|
expect(result).toEqual({
|
|
@@ -202,7 +203,7 @@ describe('WalletLendNamespace', () => {
|
|
|
202
203
|
|
|
203
204
|
it('should store the wallet reference', () => {
|
|
204
205
|
const namespace = new WalletLendNamespace(
|
|
205
|
-
{ morpho: mockProvider
|
|
206
|
+
{ morpho: mockProvider },
|
|
206
207
|
mockWallet,
|
|
207
208
|
)
|
|
208
209
|
|
|
@@ -212,7 +213,7 @@ describe('WalletLendNamespace', () => {
|
|
|
212
213
|
|
|
213
214
|
it('should execute transaction with approval when present', async () => {
|
|
214
215
|
const namespace = new WalletLendNamespace(
|
|
215
|
-
{ morpho: mockProvider
|
|
216
|
+
{ morpho: mockProvider },
|
|
216
217
|
mockWallet,
|
|
217
218
|
)
|
|
218
219
|
const mockAsset = {
|
|
@@ -226,7 +227,7 @@ describe('WalletLendNamespace', () => {
|
|
|
226
227
|
value: 0n,
|
|
227
228
|
data: '0xapproval' as const,
|
|
228
229
|
}
|
|
229
|
-
const
|
|
230
|
+
const position: TransactionData = {
|
|
230
231
|
to: marketId.address,
|
|
231
232
|
value: 0n,
|
|
232
233
|
data: '0xdeposit' as const,
|
|
@@ -237,8 +238,7 @@ describe('WalletLendNamespace', () => {
|
|
|
237
238
|
marketId: marketId.address,
|
|
238
239
|
apy: 0.05,
|
|
239
240
|
timestamp: Date.now(),
|
|
240
|
-
transactionData: { approval,
|
|
241
|
-
slippage: 50,
|
|
241
|
+
transactionData: { approval, position },
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
vi.mocked(mockProvider.openPosition).mockResolvedValue(mockTransaction)
|
|
@@ -249,10 +249,7 @@ describe('WalletLendNamespace', () => {
|
|
|
249
249
|
marketId,
|
|
250
250
|
})
|
|
251
251
|
|
|
252
|
-
expect(mockWallet.sendBatch).toHaveBeenCalledWith(
|
|
253
|
-
[approval, openPosition],
|
|
254
|
-
130,
|
|
255
|
-
)
|
|
252
|
+
expect(mockWallet.sendBatch).toHaveBeenCalledWith([approval, position], 130)
|
|
256
253
|
expect(result).toEqual({
|
|
257
254
|
receipt: { success: true },
|
|
258
255
|
userOpHash: '0xmockbatchhash',
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Address } from 'viem'
|
|
2
|
-
import { encodeFunctionData, erc20Abi, formatUnits
|
|
2
|
+
import { encodeFunctionData, erc20Abi, formatUnits } from 'viem'
|
|
3
3
|
|
|
4
|
+
import { WETH } from '@/constants/assets.js'
|
|
4
5
|
import { LendProvider } from '@/lend/core/LendProvider.js'
|
|
5
6
|
import type { ChainManager } from '@/services/ChainManager.js'
|
|
6
7
|
import type { LendProviderConfig } from '@/types/actions.js'
|
|
@@ -14,36 +15,15 @@ import type {
|
|
|
14
15
|
LendOpenPositionInternalParams,
|
|
15
16
|
LendTransaction,
|
|
16
17
|
} from '@/types/lend/index.js'
|
|
17
|
-
import { getAssetAddress } from '@/utils/assets.js'
|
|
18
|
+
import { getAssetAddress, isNativeAsset } from '@/utils/assets.js'
|
|
18
19
|
|
|
20
|
+
import { POOL_ABI, WETH_GATEWAY_ABI } from './abis/pool.js'
|
|
19
21
|
import {
|
|
20
22
|
getPoolAddress,
|
|
21
23
|
getSupportedChainIds,
|
|
22
24
|
getWETHGatewayAddress,
|
|
23
25
|
} from './addresses.js'
|
|
24
|
-
import { getReserve, getReserves } from './sdk.js'
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* WETH predeploy address on OP Stack chains
|
|
28
|
-
* @description WETH is deployed at the same address on all OP Stack chains (Optimism, Base, etc.)
|
|
29
|
-
*/
|
|
30
|
-
const WETH_ADDRESS = '0x4200000000000000000000000000000000000006'
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Aave Pool ABI - only the functions we need
|
|
34
|
-
*/
|
|
35
|
-
const POOL_ABI = parseAbi([
|
|
36
|
-
'function supply(address asset, uint256 amount, address onBehalfOf, uint16 referralCode)',
|
|
37
|
-
'function withdraw(address asset, uint256 amount, address to) returns (uint256)',
|
|
38
|
-
])
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Aave WETHGateway ABI - for native ETH deposits/withdrawals
|
|
42
|
-
*/
|
|
43
|
-
const WETH_GATEWAY_ABI = parseAbi([
|
|
44
|
-
'function depositETH(address pool, address onBehalfOf, uint16 referralCode) payable',
|
|
45
|
-
'function withdrawETH(address pool, uint256 amount, address to)',
|
|
46
|
-
])
|
|
26
|
+
import { getATokenAddress, getReserve, getReserves } from './sdk.js'
|
|
47
27
|
|
|
48
28
|
/**
|
|
49
29
|
* Supported chain IDs for Aave lending
|
|
@@ -58,26 +38,13 @@ export const SUPPORTED_CHAIN_IDS = getSupportedChainIds() as readonly number[]
|
|
|
58
38
|
export class AaveLendProvider extends LendProvider<LendProviderConfig> {
|
|
59
39
|
protected readonly SUPPORTED_CHAIN_IDS = SUPPORTED_CHAIN_IDS
|
|
60
40
|
|
|
61
|
-
private chainManager: ChainManager
|
|
62
|
-
|
|
63
41
|
/**
|
|
64
42
|
* Create a new Aave lending provider
|
|
65
43
|
* @param config - Aave lending configuration
|
|
66
44
|
* @param chainManager - Chain manager for blockchain interactions
|
|
67
45
|
*/
|
|
68
46
|
constructor(config: LendProviderConfig, chainManager: ChainManager) {
|
|
69
|
-
super(config)
|
|
70
|
-
this.chainManager = chainManager
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Check if market is a WETH market
|
|
75
|
-
* @param marketId - Market identifier
|
|
76
|
-
* @returns true if market is for WETH
|
|
77
|
-
* @description WETH is a predeploy at the same address on all OP Stack chains
|
|
78
|
-
*/
|
|
79
|
-
private isWETHMarket(marketId: LendMarketId): boolean {
|
|
80
|
-
return marketId.address.toLowerCase() === WETH_ADDRESS.toLowerCase()
|
|
47
|
+
super(config, chainManager)
|
|
81
48
|
}
|
|
82
49
|
|
|
83
50
|
/**
|
|
@@ -104,27 +71,149 @@ export class AaveLendProvider extends LendProvider<LendProviderConfig> {
|
|
|
104
71
|
chainId: params.marketId.chainId,
|
|
105
72
|
})
|
|
106
73
|
|
|
107
|
-
// Check if this is a
|
|
108
|
-
if (
|
|
109
|
-
return this.
|
|
74
|
+
// Check if this is a native ETH market
|
|
75
|
+
if (isNativeAsset(params.asset)) {
|
|
76
|
+
return this._openETHPosition(params, poolAddress, marketInfo)
|
|
110
77
|
}
|
|
111
78
|
|
|
112
79
|
// Standard ERC-20 flow
|
|
113
80
|
return this._openERC20Position(params, poolAddress, marketInfo)
|
|
114
|
-
} catch
|
|
81
|
+
} catch {
|
|
115
82
|
throw new Error(
|
|
116
|
-
`Failed to open position with ${params.amountWei} of ${params.asset.metadata.symbol}
|
|
117
|
-
error instanceof Error ? error.message : 'Unknown error'
|
|
118
|
-
}`,
|
|
83
|
+
`Failed to open position with ${params.amountWei} of ${params.asset.metadata.symbol}`,
|
|
119
84
|
)
|
|
120
85
|
}
|
|
121
86
|
}
|
|
122
87
|
|
|
123
88
|
/**
|
|
124
|
-
*
|
|
89
|
+
* Close a position in an Aave market
|
|
90
|
+
* @description Withdraws assets from an Aave reserve
|
|
91
|
+
* @param params - Position closing operation parameters
|
|
92
|
+
* @returns Promise resolving to withdrawal transaction details
|
|
93
|
+
*/
|
|
94
|
+
protected async _closePosition(
|
|
95
|
+
params: LendClosePositionParams,
|
|
96
|
+
): Promise<LendTransaction> {
|
|
97
|
+
try {
|
|
98
|
+
// Get Pool address for this chain
|
|
99
|
+
const poolAddress = getPoolAddress(params.marketId.chainId)
|
|
100
|
+
if (!poolAddress) {
|
|
101
|
+
throw new Error(
|
|
102
|
+
`Aave V3 not deployed on chain ${params.marketId.chainId}`,
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const marketInfo = await this.getMarket({
|
|
107
|
+
address: params.marketId.address,
|
|
108
|
+
chainId: params.marketId.chainId,
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
// Check if this is a native ETH market
|
|
112
|
+
if (isNativeAsset(marketInfo.asset)) {
|
|
113
|
+
return this._closeETHPosition(params, poolAddress, marketInfo)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Standard ERC-20 flow
|
|
117
|
+
return this._closeERC20Position(params, poolAddress, marketInfo)
|
|
118
|
+
} catch {
|
|
119
|
+
throw new Error('Failed to close position')
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Get detailed market information
|
|
125
|
+
* @param marketId - Market identifier containing address and chainId
|
|
126
|
+
* @returns Promise resolving to market information
|
|
127
|
+
*/
|
|
128
|
+
protected async _getMarket(marketId: LendMarketId): Promise<LendMarket> {
|
|
129
|
+
return getReserve({
|
|
130
|
+
marketId,
|
|
131
|
+
chainManager: this.chainManager,
|
|
132
|
+
lendConfig: this._config,
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Get list of available lending markets
|
|
138
|
+
* @param params - Filtering parameters
|
|
139
|
+
* @returns Promise resolving to array of market information
|
|
140
|
+
*/
|
|
141
|
+
protected async _getMarkets(
|
|
142
|
+
params: GetLendMarketsParams,
|
|
143
|
+
): Promise<LendMarket[]> {
|
|
144
|
+
const marketConfigs = params.markets || []
|
|
145
|
+
|
|
146
|
+
return getReserves({
|
|
147
|
+
chainManager: this.chainManager,
|
|
148
|
+
lendConfig: this._config,
|
|
149
|
+
markets: marketConfigs,
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Get position for a specific wallet address
|
|
155
|
+
* @param params - Parameters for fetching position
|
|
156
|
+
* @returns Promise resolving to position information
|
|
157
|
+
*/
|
|
158
|
+
protected async _getPosition(
|
|
159
|
+
params: GetMarketBalanceParams,
|
|
160
|
+
): Promise<LendMarketPosition> {
|
|
161
|
+
try {
|
|
162
|
+
const publicClient = this.chainManager.getPublicClient(
|
|
163
|
+
params.marketId.chainId,
|
|
164
|
+
)
|
|
165
|
+
const market = await this._getMarket(params.marketId)
|
|
166
|
+
const poolAddress = getPoolAddress(params.marketId.chainId)
|
|
167
|
+
|
|
168
|
+
if (!poolAddress) {
|
|
169
|
+
throw new Error(
|
|
170
|
+
`Aave V3 not deployed on chain ${params.marketId.chainId}`,
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Get the aToken address from Pool.getReserveData
|
|
175
|
+
// For native assets, use WETH address since Aave uses WETH internally
|
|
176
|
+
const assetAddress = isNativeAsset(market.asset)
|
|
177
|
+
? getAssetAddress(WETH, params.marketId.chainId)
|
|
178
|
+
: getAssetAddress(market.asset, params.marketId.chainId)
|
|
179
|
+
|
|
180
|
+
const aTokenAddress = await getATokenAddress({
|
|
181
|
+
underlyingAsset: assetAddress,
|
|
182
|
+
chainId: params.marketId.chainId,
|
|
183
|
+
chainManager: this.chainManager,
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
const balance = await publicClient.readContract({
|
|
187
|
+
address: aTokenAddress,
|
|
188
|
+
abi: erc20Abi,
|
|
189
|
+
functionName: 'balanceOf',
|
|
190
|
+
args: [params.walletAddress],
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
const balanceFormatted = formatUnits(
|
|
194
|
+
balance,
|
|
195
|
+
market.asset.metadata.decimals,
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
return {
|
|
199
|
+
balance,
|
|
200
|
+
balanceFormatted,
|
|
201
|
+
shares: balance, // In Aave, aTokens are 1:1 with underlying
|
|
202
|
+
sharesFormatted: balanceFormatted,
|
|
203
|
+
marketId: params.marketId,
|
|
204
|
+
}
|
|
205
|
+
} catch {
|
|
206
|
+
throw new Error(
|
|
207
|
+
`Failed to get market balance for ${params.walletAddress} in market ${params.marketId.address}`,
|
|
208
|
+
)
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Open position for native ETH using WETHGateway
|
|
125
214
|
* @description Deposits native ETH via WETHGateway which wraps and deposits in one tx
|
|
126
215
|
*/
|
|
127
|
-
private async
|
|
216
|
+
private async _openETHPosition(
|
|
128
217
|
params: LendOpenPositionInternalParams,
|
|
129
218
|
poolAddress: Address,
|
|
130
219
|
marketInfo: LendMarket,
|
|
@@ -147,19 +236,20 @@ export class AaveLendProvider extends LendProvider<LendProviderConfig> {
|
|
|
147
236
|
],
|
|
148
237
|
})
|
|
149
238
|
|
|
239
|
+
const wethAddress = getAssetAddress(WETH, params.marketId.chainId)
|
|
240
|
+
|
|
150
241
|
return {
|
|
151
242
|
amount: params.amountWei,
|
|
152
|
-
asset:
|
|
243
|
+
asset: wethAddress,
|
|
153
244
|
marketId: params.marketId.address,
|
|
154
245
|
apy: marketInfo.apy.total,
|
|
155
246
|
transactionData: {
|
|
156
|
-
|
|
247
|
+
position: {
|
|
157
248
|
to: gatewayAddress,
|
|
158
249
|
data: depositCallData,
|
|
159
250
|
value: params.amountWei, // Send ETH as msg.value
|
|
160
251
|
},
|
|
161
252
|
},
|
|
162
|
-
slippage: params.options?.slippage ?? 50,
|
|
163
253
|
}
|
|
164
254
|
}
|
|
165
255
|
|
|
@@ -172,18 +262,8 @@ export class AaveLendProvider extends LendProvider<LendProviderConfig> {
|
|
|
172
262
|
poolAddress: Address,
|
|
173
263
|
marketInfo: LendMarket,
|
|
174
264
|
): Promise<LendTransaction> {
|
|
175
|
-
// Get asset address for the chain
|
|
176
|
-
const assetAddress = params.asset
|
|
177
|
-
if (!assetAddress) {
|
|
178
|
-
throw new Error(`Asset not supported on chain ${params.marketId.chainId}`)
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Generate approval transaction
|
|
182
|
-
const approvalCallData = encodeFunctionData({
|
|
183
|
-
abi: erc20Abi,
|
|
184
|
-
functionName: 'approve',
|
|
185
|
-
args: [poolAddress, params.amountWei],
|
|
186
|
-
})
|
|
265
|
+
// Get asset address for the chain (throws for native assets)
|
|
266
|
+
const assetAddress = getAssetAddress(params.asset, params.marketId.chainId)
|
|
187
267
|
|
|
188
268
|
// Generate supply transaction
|
|
189
269
|
const supplyCallData = encodeFunctionData({
|
|
@@ -203,65 +283,25 @@ export class AaveLendProvider extends LendProvider<LendProviderConfig> {
|
|
|
203
283
|
marketId: params.marketId.address,
|
|
204
284
|
apy: marketInfo.apy.total,
|
|
205
285
|
transactionData: {
|
|
206
|
-
approval:
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
286
|
+
approval: this.buildApprovalTx(
|
|
287
|
+
assetAddress,
|
|
288
|
+
poolAddress,
|
|
289
|
+
params.amountWei,
|
|
290
|
+
),
|
|
291
|
+
position: {
|
|
212
292
|
to: poolAddress,
|
|
213
293
|
data: supplyCallData,
|
|
214
294
|
value: 0n,
|
|
215
295
|
},
|
|
216
296
|
},
|
|
217
|
-
slippage: params.options?.slippage ?? 50,
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Close a position in an Aave market
|
|
223
|
-
* @description Withdraws assets from an Aave reserve
|
|
224
|
-
* @param params - Position closing operation parameters
|
|
225
|
-
* @returns Promise resolving to withdrawal transaction details
|
|
226
|
-
*/
|
|
227
|
-
protected async _closePosition(
|
|
228
|
-
params: LendClosePositionParams,
|
|
229
|
-
): Promise<LendTransaction> {
|
|
230
|
-
try {
|
|
231
|
-
// Get Pool address for this chain
|
|
232
|
-
const poolAddress = getPoolAddress(params.marketId.chainId)
|
|
233
|
-
if (!poolAddress) {
|
|
234
|
-
throw new Error(
|
|
235
|
-
`Aave V3 not deployed on chain ${params.marketId.chainId}`,
|
|
236
|
-
)
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const marketInfo = await this.getMarket({
|
|
240
|
-
address: params.marketId.address,
|
|
241
|
-
chainId: params.marketId.chainId,
|
|
242
|
-
})
|
|
243
|
-
|
|
244
|
-
// Check if this is a WETH market
|
|
245
|
-
if (this.isWETHMarket(params.marketId)) {
|
|
246
|
-
return this._closeWETHPosition(params, poolAddress, marketInfo)
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// Standard ERC-20 flow
|
|
250
|
-
return this._closeERC20Position(params, poolAddress, marketInfo)
|
|
251
|
-
} catch (error) {
|
|
252
|
-
throw new Error(
|
|
253
|
-
`Failed to close position: ${
|
|
254
|
-
error instanceof Error ? error.message : 'Unknown error'
|
|
255
|
-
}`,
|
|
256
|
-
)
|
|
257
297
|
}
|
|
258
298
|
}
|
|
259
299
|
|
|
260
300
|
/**
|
|
261
|
-
* Close position for
|
|
301
|
+
* Close position for native ETH using WETHGateway
|
|
262
302
|
* @description Withdraws aWETH, unwraps to ETH, and sends to user
|
|
263
303
|
*/
|
|
264
|
-
private async
|
|
304
|
+
private async _closeETHPosition(
|
|
265
305
|
params: LendClosePositionParams,
|
|
266
306
|
poolAddress: Address,
|
|
267
307
|
marketInfo: LendMarket,
|
|
@@ -273,23 +313,16 @@ export class AaveLendProvider extends LendProvider<LendProviderConfig> {
|
|
|
273
313
|
)
|
|
274
314
|
}
|
|
275
315
|
|
|
316
|
+
const wethAddress = getAssetAddress(WETH, params.marketId.chainId)
|
|
317
|
+
|
|
276
318
|
// Get the aToken address for the underlying WETH asset
|
|
277
|
-
// Note: params.marketId.address is the underlying WETH address, not the aToken
|
|
278
|
-
const { getATokenAddress } = await import('./sdk.js')
|
|
279
319
|
const aWETHAddress = await getATokenAddress({
|
|
280
|
-
underlyingAsset:
|
|
320
|
+
underlyingAsset: wethAddress,
|
|
281
321
|
chainId: params.marketId.chainId,
|
|
282
322
|
chainManager: this.chainManager,
|
|
283
323
|
})
|
|
284
324
|
|
|
285
|
-
//
|
|
286
|
-
const approvalCallData = encodeFunctionData({
|
|
287
|
-
abi: erc20Abi,
|
|
288
|
-
functionName: 'approve',
|
|
289
|
-
args: [gatewayAddress, params.amount],
|
|
290
|
-
})
|
|
291
|
-
|
|
292
|
-
// Second: Call withdrawETH on gateway
|
|
325
|
+
// Call withdrawETH on gateway
|
|
293
326
|
const withdrawCallData = encodeFunctionData({
|
|
294
327
|
abi: WETH_GATEWAY_ABI,
|
|
295
328
|
functionName: 'withdrawETH',
|
|
@@ -302,22 +335,21 @@ export class AaveLendProvider extends LendProvider<LendProviderConfig> {
|
|
|
302
335
|
|
|
303
336
|
return {
|
|
304
337
|
amount: params.amount,
|
|
305
|
-
asset:
|
|
338
|
+
asset: wethAddress,
|
|
306
339
|
marketId: params.marketId.address,
|
|
307
340
|
apy: marketInfo.apy.total,
|
|
308
341
|
transactionData: {
|
|
309
|
-
approval:
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
342
|
+
approval: this.buildApprovalTx(
|
|
343
|
+
aWETHAddress,
|
|
344
|
+
gatewayAddress,
|
|
345
|
+
params.amount,
|
|
346
|
+
),
|
|
347
|
+
position: {
|
|
315
348
|
to: gatewayAddress,
|
|
316
349
|
data: withdrawCallData,
|
|
317
350
|
value: 0n,
|
|
318
351
|
},
|
|
319
352
|
},
|
|
320
|
-
slippage: params.options?.slippage ?? 50,
|
|
321
353
|
}
|
|
322
354
|
}
|
|
323
355
|
|
|
@@ -352,112 +384,12 @@ export class AaveLendProvider extends LendProvider<LendProviderConfig> {
|
|
|
352
384
|
marketId: params.marketId.address,
|
|
353
385
|
apy: marketInfo.apy.total,
|
|
354
386
|
transactionData: {
|
|
355
|
-
|
|
387
|
+
position: {
|
|
356
388
|
to: poolAddress,
|
|
357
389
|
data: withdrawCallData,
|
|
358
390
|
value: 0n,
|
|
359
391
|
},
|
|
360
392
|
},
|
|
361
|
-
slippage: params.options?.slippage ?? 50,
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* Get detailed market information
|
|
367
|
-
* @param marketId - Market identifier containing address and chainId
|
|
368
|
-
* @returns Promise resolving to market information
|
|
369
|
-
*/
|
|
370
|
-
protected async _getMarket(marketId: LendMarketId): Promise<LendMarket> {
|
|
371
|
-
return getReserve({
|
|
372
|
-
marketId,
|
|
373
|
-
chainManager: this.chainManager,
|
|
374
|
-
lendConfig: this._config,
|
|
375
|
-
})
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* Get list of available lending markets
|
|
380
|
-
* @param params - Filtering parameters
|
|
381
|
-
* @returns Promise resolving to array of market information
|
|
382
|
-
*/
|
|
383
|
-
protected async _getMarkets(
|
|
384
|
-
params: GetLendMarketsParams,
|
|
385
|
-
): Promise<LendMarket[]> {
|
|
386
|
-
const marketConfigs = params.markets || []
|
|
387
|
-
|
|
388
|
-
return getReserves({
|
|
389
|
-
chainManager: this.chainManager,
|
|
390
|
-
lendConfig: this._config,
|
|
391
|
-
markets: marketConfigs,
|
|
392
|
-
})
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
/**
|
|
396
|
-
* Get position for a specific wallet address
|
|
397
|
-
* @param params - Parameters for fetching position
|
|
398
|
-
* @returns Promise resolving to position information
|
|
399
|
-
*/
|
|
400
|
-
protected async _getPosition(
|
|
401
|
-
params: GetMarketBalanceParams,
|
|
402
|
-
): Promise<LendMarketPosition> {
|
|
403
|
-
try {
|
|
404
|
-
const publicClient = this.chainManager.getPublicClient(
|
|
405
|
-
params.marketId.chainId,
|
|
406
|
-
)
|
|
407
|
-
const market = await this._getMarket(params.marketId)
|
|
408
|
-
const poolAddress = getPoolAddress(params.marketId.chainId)
|
|
409
|
-
|
|
410
|
-
if (!poolAddress) {
|
|
411
|
-
throw new Error(
|
|
412
|
-
`Aave V3 not deployed on chain ${params.marketId.chainId}`,
|
|
413
|
-
)
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
// Get the aToken address from Pool.getReserveData
|
|
417
|
-
const assetAddress = getAssetAddress(
|
|
418
|
-
market.asset,
|
|
419
|
-
params.marketId.chainId,
|
|
420
|
-
)
|
|
421
|
-
|
|
422
|
-
const reserveData = (await publicClient.readContract({
|
|
423
|
-
address: poolAddress,
|
|
424
|
-
abi: parseAbi([
|
|
425
|
-
'struct ReserveData { uint256 configuration; uint128 liquidityIndex; uint128 currentLiquidityRate; uint128 variableBorrowIndex; uint128 currentVariableBorrowRate; uint128 currentStableBorrowRate; uint40 lastUpdateTimestamp; uint16 id; address aTokenAddress; address stableDebtTokenAddress; address variableDebtTokenAddress; address interestRateStrategyAddress; uint128 accruedToTreasury; uint128 unbacked; uint128 isolationModeTotalDebt; }',
|
|
426
|
-
'function getReserveData(address asset) view returns (ReserveData)',
|
|
427
|
-
]),
|
|
428
|
-
functionName: 'getReserveData',
|
|
429
|
-
args: [assetAddress],
|
|
430
|
-
})) as {
|
|
431
|
-
aTokenAddress: Address
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
const aTokenAddress = reserveData.aTokenAddress
|
|
435
|
-
|
|
436
|
-
const balance = await publicClient.readContract({
|
|
437
|
-
address: aTokenAddress,
|
|
438
|
-
abi: erc20Abi,
|
|
439
|
-
functionName: 'balanceOf',
|
|
440
|
-
args: [params.walletAddress],
|
|
441
|
-
})
|
|
442
|
-
|
|
443
|
-
const balanceFormatted = formatUnits(
|
|
444
|
-
balance,
|
|
445
|
-
market.asset.metadata.decimals,
|
|
446
|
-
)
|
|
447
|
-
|
|
448
|
-
return {
|
|
449
|
-
balance,
|
|
450
|
-
balanceFormatted,
|
|
451
|
-
shares: balance, // In Aave, aTokens are 1:1 with underlying
|
|
452
|
-
sharesFormatted: balanceFormatted,
|
|
453
|
-
marketId: params.marketId,
|
|
454
|
-
}
|
|
455
|
-
} catch (error) {
|
|
456
|
-
throw new Error(
|
|
457
|
-
`Failed to get market balance for ${params.walletAddress} in market ${params.marketId.address}: ${
|
|
458
|
-
error instanceof Error ? error.message : 'Unknown error'
|
|
459
|
-
}`,
|
|
460
|
-
)
|
|
461
393
|
}
|
|
462
394
|
}
|
|
463
395
|
}
|