@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,8 +1,8 @@
|
|
|
1
1
|
import type { Address } from 'viem'
|
|
2
2
|
import { describe, expect, it } from 'vitest'
|
|
3
3
|
|
|
4
|
-
import { MockUSDCAsset } from '@/
|
|
5
|
-
import { MockLendProvider } from '@/
|
|
4
|
+
import { MockUSDCAsset } from '@/__mocks__/MockAssets.js'
|
|
5
|
+
import { MockLendProvider } from '@/lend/__mocks__/MockLendProvider.js'
|
|
6
6
|
import type { LendMarketConfig, LendMarketId } from '@/types/lend/index.js'
|
|
7
7
|
|
|
8
8
|
// Test helper class that exposes protected validation methods as public
|
|
@@ -1,90 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { AaveLendProvider } from '@/lend/providers/aave/AaveLendProvider.js'
|
|
3
|
-
import type { MorphoLendProvider } from '@/lend/providers/morpho/MorphoLendProvider.js'
|
|
4
|
-
import type { LendProviderConfig } from '@/types/actions.js'
|
|
5
|
-
import type {
|
|
6
|
-
GetLendMarketParams,
|
|
7
|
-
GetLendMarketsParams,
|
|
8
|
-
LendMarket,
|
|
9
|
-
LendMarketId,
|
|
10
|
-
} from '@/types/lend/index.js'
|
|
1
|
+
import { BaseLendNamespace } from './BaseLendNamespace.js'
|
|
11
2
|
|
|
12
3
|
/**
|
|
13
4
|
* Actions Lend Namespace
|
|
14
5
|
* @description Read-only lending operations available on actions.lend
|
|
15
6
|
*/
|
|
16
|
-
export class ActionsLendNamespace {
|
|
17
|
-
constructor(
|
|
18
|
-
protected readonly providers: {
|
|
19
|
-
morpho?: LendProvider<LendProviderConfig>
|
|
20
|
-
aave?: LendProvider<LendProviderConfig>
|
|
21
|
-
},
|
|
22
|
-
) {}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Route a market to the correct provider
|
|
26
|
-
* @param marketId - Market identifier to route
|
|
27
|
-
* @returns The provider that handles this market
|
|
28
|
-
* @throws Error if no provider is found for the market
|
|
29
|
-
*/
|
|
30
|
-
private getProviderForMarket(
|
|
31
|
-
marketId: LendMarketId,
|
|
32
|
-
): MorphoLendProvider | AaveLendProvider {
|
|
33
|
-
const allProviders = [this.providers.morpho, this.providers.aave].filter(
|
|
34
|
-
Boolean,
|
|
35
|
-
) as Array<MorphoLendProvider | AaveLendProvider>
|
|
36
|
-
|
|
37
|
-
for (const provider of allProviders) {
|
|
38
|
-
const market = provider.config.marketAllowlist?.find(
|
|
39
|
-
(m: LendMarketId) =>
|
|
40
|
-
m.address.toLowerCase() === marketId.address.toLowerCase() &&
|
|
41
|
-
m.chainId === marketId.chainId,
|
|
42
|
-
)
|
|
43
|
-
if (market) return provider
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
throw new Error(
|
|
47
|
-
`No provider configured for market ${marketId.address} on chain ${marketId.chainId}`,
|
|
48
|
-
)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Get all markets across all configured providers
|
|
53
|
-
* @param params - Optional filtering parameters
|
|
54
|
-
* @returns Promise resolving to array of markets from all providers
|
|
55
|
-
*/
|
|
56
|
-
async getMarkets(params: GetLendMarketsParams = {}): Promise<LendMarket[]> {
|
|
57
|
-
const allProviders = [this.providers.morpho, this.providers.aave].filter(
|
|
58
|
-
Boolean,
|
|
59
|
-
) as Array<MorphoLendProvider | AaveLendProvider>
|
|
60
|
-
|
|
61
|
-
const results = await Promise.all(
|
|
62
|
-
allProviders.map((p) => p.getMarkets(params)),
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
return results.flat()
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Get a specific market by routing to the correct provider
|
|
70
|
-
* @param params - Market identifier
|
|
71
|
-
* @returns Promise resolving to market information
|
|
72
|
-
*/
|
|
73
|
-
async getMarket(params: GetLendMarketParams): Promise<LendMarket> {
|
|
74
|
-
const provider = this.getProviderForMarket(params)
|
|
75
|
-
return provider.getMarket(params)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Get supported chain IDs across all providers
|
|
80
|
-
* @returns Array of unique chain IDs supported by any provider
|
|
81
|
-
*/
|
|
82
|
-
supportedChainIds(): number[] {
|
|
83
|
-
const allProviders = [this.providers.morpho, this.providers.aave].filter(
|
|
84
|
-
Boolean,
|
|
85
|
-
) as Array<MorphoLendProvider | AaveLendProvider>
|
|
86
|
-
|
|
87
|
-
const allChains = allProviders.flatMap((p) => p.supportedChainIds())
|
|
88
|
-
return [...new Set(allChains)]
|
|
89
|
-
}
|
|
90
|
-
}
|
|
7
|
+
export class ActionsLendNamespace extends BaseLendNamespace {}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { LendProvider } from '@/lend/core/LendProvider.js'
|
|
2
|
+
import type { AaveLendProvider } from '@/lend/providers/aave/AaveLendProvider.js'
|
|
3
|
+
import type { MorphoLendProvider } from '@/lend/providers/morpho/MorphoLendProvider.js'
|
|
4
|
+
import type { LendProviderConfig } from '@/types/actions.js'
|
|
5
|
+
import type {
|
|
6
|
+
GetLendMarketParams,
|
|
7
|
+
GetLendMarketsParams,
|
|
8
|
+
LendMarket,
|
|
9
|
+
LendMarketId,
|
|
10
|
+
} from '@/types/lend/index.js'
|
|
11
|
+
|
|
12
|
+
export type LendProviders = {
|
|
13
|
+
morpho?: LendProvider<LendProviderConfig>
|
|
14
|
+
aave?: LendProvider<LendProviderConfig>
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Base Lend Namespace
|
|
19
|
+
* @description Shared lending operations for Actions and Wallet namespaces
|
|
20
|
+
*/
|
|
21
|
+
export abstract class BaseLendNamespace {
|
|
22
|
+
constructor(protected readonly providers: LendProviders) {}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Get all markets across all configured providers
|
|
26
|
+
* @param params - Optional filtering parameters
|
|
27
|
+
* @returns Promise resolving to array of markets from all providers
|
|
28
|
+
*/
|
|
29
|
+
async getMarkets(params: GetLendMarketsParams = {}): Promise<LendMarket[]> {
|
|
30
|
+
const results = await Promise.all(
|
|
31
|
+
this.getAllProviders().map((p) => p.getMarkets(params)),
|
|
32
|
+
)
|
|
33
|
+
return results.flat()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Get a specific market by routing to the correct provider
|
|
38
|
+
* @param params - Market identifier
|
|
39
|
+
* @returns Promise resolving to market information
|
|
40
|
+
*/
|
|
41
|
+
async getMarket(params: GetLendMarketParams): Promise<LendMarket> {
|
|
42
|
+
const provider = this.getProviderForMarket(params)
|
|
43
|
+
return provider.getMarket(params)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get supported chain IDs across all providers
|
|
48
|
+
* @returns Array of unique chain IDs supported by any provider
|
|
49
|
+
*/
|
|
50
|
+
supportedChainIds(): number[] {
|
|
51
|
+
const allChains = this.getAllProviders().flatMap((p) =>
|
|
52
|
+
p.supportedChainIds(),
|
|
53
|
+
)
|
|
54
|
+
return [...new Set(allChains)]
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Get all configured providers
|
|
59
|
+
* @returns Array of configured providers
|
|
60
|
+
*/
|
|
61
|
+
protected getAllProviders(): Array<MorphoLendProvider | AaveLendProvider> {
|
|
62
|
+
return [this.providers.morpho, this.providers.aave].filter(
|
|
63
|
+
Boolean,
|
|
64
|
+
) as Array<MorphoLendProvider | AaveLendProvider>
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Route a market to the correct provider
|
|
69
|
+
* @param marketId - Market identifier to route
|
|
70
|
+
* @returns The provider that handles this market
|
|
71
|
+
* @throws Error if no provider is found for the market
|
|
72
|
+
*/
|
|
73
|
+
protected getProviderForMarket(
|
|
74
|
+
marketId: LendMarketId,
|
|
75
|
+
): MorphoLendProvider | AaveLendProvider {
|
|
76
|
+
for (const provider of this.getAllProviders()) {
|
|
77
|
+
const market = provider.config.marketAllowlist?.find(
|
|
78
|
+
(m: LendMarketId) =>
|
|
79
|
+
m.address.toLowerCase() === marketId.address.toLowerCase() &&
|
|
80
|
+
m.chainId === marketId.chainId,
|
|
81
|
+
)
|
|
82
|
+
if (market) return provider
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
throw new Error(
|
|
86
|
+
`No provider configured for market ${marketId.address} on chain ${marketId.chainId}`,
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -1,101 +1,26 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { AaveLendProvider } from '@/lend/providers/aave/AaveLendProvider.js'
|
|
3
|
-
import type { MorphoLendProvider } from '@/lend/providers/morpho/MorphoLendProvider.js'
|
|
4
|
-
import type { LendProviderConfig } from '@/types/actions.js'
|
|
1
|
+
import type { SupportedChainId } from '@/constants/supportedChains.js'
|
|
5
2
|
import type {
|
|
6
3
|
ClosePositionParams,
|
|
7
|
-
GetLendMarketParams,
|
|
8
|
-
GetLendMarketsParams,
|
|
9
4
|
GetPositionParams,
|
|
10
|
-
LendMarket,
|
|
11
|
-
LendMarketId,
|
|
12
5
|
LendMarketPosition,
|
|
13
6
|
LendOpenPositionParams,
|
|
7
|
+
LendTransaction,
|
|
14
8
|
LendTransactionReceipt,
|
|
15
9
|
} from '@/types/lend/index.js'
|
|
16
10
|
import type { Wallet } from '@/wallet/core/wallets/abstract/Wallet.js'
|
|
17
11
|
|
|
12
|
+
import { BaseLendNamespace, type LendProviders } from './BaseLendNamespace.js'
|
|
13
|
+
|
|
18
14
|
/**
|
|
19
15
|
* Wallet Lend Namespace
|
|
20
16
|
* @description Full lending operations available on wallet.lend
|
|
21
17
|
*/
|
|
22
|
-
export class WalletLendNamespace {
|
|
18
|
+
export class WalletLendNamespace extends BaseLendNamespace {
|
|
23
19
|
constructor(
|
|
24
|
-
|
|
25
|
-
morpho?: LendProvider<LendProviderConfig>
|
|
26
|
-
aave?: LendProvider<LendProviderConfig>
|
|
27
|
-
},
|
|
20
|
+
providers: LendProviders,
|
|
28
21
|
private readonly wallet: Wallet,
|
|
29
|
-
) {
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Route a market to the correct provider
|
|
33
|
-
* @param marketId - Market identifier to route
|
|
34
|
-
* @returns The provider that handles this market
|
|
35
|
-
* @throws Error if no provider is found for the market
|
|
36
|
-
*/
|
|
37
|
-
private getProviderForMarket(
|
|
38
|
-
marketId: LendMarketId,
|
|
39
|
-
): MorphoLendProvider | AaveLendProvider {
|
|
40
|
-
const allProviders = [this.providers.morpho, this.providers.aave].filter(
|
|
41
|
-
Boolean,
|
|
42
|
-
) as Array<MorphoLendProvider | AaveLendProvider>
|
|
43
|
-
|
|
44
|
-
for (const provider of allProviders) {
|
|
45
|
-
const market = provider.config.marketAllowlist?.find(
|
|
46
|
-
(m: LendMarketId) =>
|
|
47
|
-
m.address.toLowerCase() === marketId.address.toLowerCase() &&
|
|
48
|
-
m.chainId === marketId.chainId,
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
if (market) {
|
|
52
|
-
return provider
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
throw new Error(
|
|
57
|
-
`No provider configured for market ${marketId.address} on chain ${marketId.chainId}`,
|
|
58
|
-
)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Get all markets across all configured providers
|
|
63
|
-
* @param params - Optional filtering parameters
|
|
64
|
-
* @returns Promise resolving to array of markets from all providers
|
|
65
|
-
*/
|
|
66
|
-
async getMarkets(params: GetLendMarketsParams = {}): Promise<LendMarket[]> {
|
|
67
|
-
const allProviders = [this.providers.morpho, this.providers.aave].filter(
|
|
68
|
-
Boolean,
|
|
69
|
-
) as Array<MorphoLendProvider | AaveLendProvider>
|
|
70
|
-
|
|
71
|
-
const results = await Promise.all(
|
|
72
|
-
allProviders.map((p) => p.getMarkets(params)),
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
return results.flat()
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Get a specific market by routing to the correct provider
|
|
80
|
-
* @param params - Market identifier
|
|
81
|
-
* @returns Promise resolving to market information
|
|
82
|
-
*/
|
|
83
|
-
async getMarket(params: GetLendMarketParams): Promise<LendMarket> {
|
|
84
|
-
const provider = this.getProviderForMarket(params)
|
|
85
|
-
return provider.getMarket(params)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Get supported chain IDs across all providers
|
|
90
|
-
* @returns Array of unique chain IDs supported by any provider
|
|
91
|
-
*/
|
|
92
|
-
supportedChainIds(): number[] {
|
|
93
|
-
const allProviders = [this.providers.morpho, this.providers.aave].filter(
|
|
94
|
-
Boolean,
|
|
95
|
-
) as Array<MorphoLendProvider | AaveLendProvider>
|
|
96
|
-
|
|
97
|
-
const allChains = allProviders.flatMap((p) => p.supportedChainIds())
|
|
98
|
-
return [...new Set(allChains)]
|
|
22
|
+
) {
|
|
23
|
+
super(providers)
|
|
99
24
|
}
|
|
100
25
|
|
|
101
26
|
/**
|
|
@@ -116,25 +41,7 @@ export class WalletLendNamespace {
|
|
|
116
41
|
walletAddress: this.wallet.address,
|
|
117
42
|
})
|
|
118
43
|
|
|
119
|
-
|
|
120
|
-
if (!transactionData) {
|
|
121
|
-
throw new Error('No transaction data returned from lend provider')
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (transactionData.approval && transactionData.openPosition) {
|
|
125
|
-
return await this.wallet.sendBatch(
|
|
126
|
-
[transactionData.approval, transactionData.openPosition],
|
|
127
|
-
params.marketId.chainId,
|
|
128
|
-
)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (!transactionData.openPosition) {
|
|
132
|
-
throw new Error('No openPosition transaction data returned')
|
|
133
|
-
}
|
|
134
|
-
return await this.wallet.send(
|
|
135
|
-
transactionData.openPosition,
|
|
136
|
-
params.marketId.chainId,
|
|
137
|
-
)
|
|
44
|
+
return this.executeTransaction(lendTransaction, params.marketId.chainId)
|
|
138
45
|
}
|
|
139
46
|
|
|
140
47
|
/**
|
|
@@ -175,28 +82,25 @@ export class WalletLendNamespace {
|
|
|
175
82
|
walletAddress: this.wallet.address,
|
|
176
83
|
})
|
|
177
84
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
throw new Error(
|
|
181
|
-
'No transaction data returned from close position provider',
|
|
182
|
-
)
|
|
183
|
-
}
|
|
85
|
+
return this.executeTransaction(closeTransaction, params.marketId.chainId)
|
|
86
|
+
}
|
|
184
87
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Execute a lend transaction with optional approval batching
|
|
90
|
+
*/
|
|
91
|
+
private async executeTransaction(
|
|
92
|
+
transaction: LendTransaction,
|
|
93
|
+
chainId: SupportedChainId,
|
|
94
|
+
): Promise<LendTransactionReceipt> {
|
|
95
|
+
const { transactionData } = transaction
|
|
192
96
|
|
|
193
|
-
if (
|
|
194
|
-
|
|
97
|
+
if (transactionData.approval) {
|
|
98
|
+
return this.wallet.sendBatch(
|
|
99
|
+
[transactionData.approval, transactionData.position],
|
|
100
|
+
chainId,
|
|
101
|
+
)
|
|
195
102
|
}
|
|
196
103
|
|
|
197
|
-
return
|
|
198
|
-
transactionData.closePosition,
|
|
199
|
-
params.marketId.chainId,
|
|
200
|
-
)
|
|
104
|
+
return this.wallet.send(transactionData.position, chainId)
|
|
201
105
|
}
|
|
202
106
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import type { Address } from 'viem'
|
|
1
2
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
3
|
|
|
4
|
+
import { getRandomAddress } from '@/__mocks__/utils.js'
|
|
5
|
+
import type { MockLendProvider } from '@/lend/__mocks__/MockLendProvider.js'
|
|
6
|
+
import { createMockLendProvider } from '@/lend/__mocks__/MockLendProvider.js'
|
|
3
7
|
import { ActionsLendNamespace } from '@/lend/namespaces/ActionsLendNamespace.js'
|
|
4
|
-
import { createMockLendProvider } from '@/test/MockLendProvider.js'
|
|
5
|
-
import { getRandomAddress } from '@/test/utils.js'
|
|
6
|
-
import type { LendProvider } from '@/types/lend/index.js'
|
|
7
8
|
|
|
8
9
|
describe('ActionsLendNamespace', () => {
|
|
9
|
-
let mockProvider:
|
|
10
|
-
let mockMarketId: { address:
|
|
10
|
+
let mockProvider: MockLendProvider
|
|
11
|
+
let mockMarketId: { address: Address; chainId: 130 }
|
|
11
12
|
|
|
12
13
|
beforeEach(() => {
|
|
13
14
|
mockMarketId = { address: getRandomAddress(), chainId: 130 as const }
|
|
@@ -30,13 +31,13 @@ describe('ActionsLendNamespace', () => {
|
|
|
30
31
|
})
|
|
31
32
|
|
|
32
33
|
it('should create an instance with a lend provider', () => {
|
|
33
|
-
const namespace = new ActionsLendNamespace({ morpho: mockProvider
|
|
34
|
+
const namespace = new ActionsLendNamespace({ morpho: mockProvider })
|
|
34
35
|
|
|
35
36
|
expect(namespace).toBeInstanceOf(ActionsLendNamespace)
|
|
36
37
|
})
|
|
37
38
|
|
|
38
39
|
it('should delegate getMarkets to provider', async () => {
|
|
39
|
-
const namespace = new ActionsLendNamespace({ morpho: mockProvider
|
|
40
|
+
const namespace = new ActionsLendNamespace({ morpho: mockProvider })
|
|
40
41
|
const spy = vi.spyOn(mockProvider, 'getMarkets')
|
|
41
42
|
|
|
42
43
|
await namespace.getMarkets()
|
|
@@ -45,7 +46,7 @@ describe('ActionsLendNamespace', () => {
|
|
|
45
46
|
})
|
|
46
47
|
|
|
47
48
|
it('should delegate getMarket to provider with correct parameters', async () => {
|
|
48
|
-
const namespace = new ActionsLendNamespace({ morpho: mockProvider
|
|
49
|
+
const namespace = new ActionsLendNamespace({ morpho: mockProvider })
|
|
49
50
|
const spy = vi.spyOn(mockProvider, 'getMarket')
|
|
50
51
|
|
|
51
52
|
await namespace.getMarket(mockMarketId)
|
|
@@ -54,7 +55,7 @@ describe('ActionsLendNamespace', () => {
|
|
|
54
55
|
})
|
|
55
56
|
|
|
56
57
|
it('should delegate supportedChainIds to provider', () => {
|
|
57
|
-
const namespace = new ActionsLendNamespace({ morpho: mockProvider
|
|
58
|
+
const namespace = new ActionsLendNamespace({ morpho: mockProvider })
|
|
58
59
|
const spy = vi.spyOn(mockProvider, 'supportedChainIds')
|
|
59
60
|
|
|
60
61
|
namespace.supportedChainIds()
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { Address } from 'viem'
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import { getRandomAddress } from '@/__mocks__/utils.js'
|
|
5
|
+
import type { MockLendProvider } from '@/lend/__mocks__/MockLendProvider.js'
|
|
6
|
+
import { createMockLendProvider } from '@/lend/__mocks__/MockLendProvider.js'
|
|
7
|
+
import { BaseLendNamespace } from '@/lend/namespaces/BaseLendNamespace.js'
|
|
8
|
+
|
|
9
|
+
// Concrete implementation for testing
|
|
10
|
+
class TestLendNamespace extends BaseLendNamespace {}
|
|
11
|
+
|
|
12
|
+
describe('BaseLendNamespace', () => {
|
|
13
|
+
let mockMorphoProvider: MockLendProvider
|
|
14
|
+
let mockAaveProvider: MockLendProvider
|
|
15
|
+
let mockMarketId: { address: Address; chainId: 130 }
|
|
16
|
+
let aaveMarketId: { address: Address; chainId: 130 }
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
mockMarketId = { address: getRandomAddress(), chainId: 130 as const }
|
|
20
|
+
aaveMarketId = { address: getRandomAddress(), chainId: 130 as const }
|
|
21
|
+
|
|
22
|
+
mockMorphoProvider = createMockLendProvider({
|
|
23
|
+
marketAllowlist: [
|
|
24
|
+
{
|
|
25
|
+
address: mockMarketId.address,
|
|
26
|
+
chainId: mockMarketId.chainId,
|
|
27
|
+
name: 'Morpho Market',
|
|
28
|
+
asset: {
|
|
29
|
+
address: { 130: getRandomAddress() },
|
|
30
|
+
metadata: { symbol: 'USDC', name: 'USD Coin', decimals: 6 },
|
|
31
|
+
type: 'erc20' as const,
|
|
32
|
+
},
|
|
33
|
+
lendProvider: 'morpho',
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
mockAaveProvider = createMockLendProvider({
|
|
39
|
+
marketAllowlist: [
|
|
40
|
+
{
|
|
41
|
+
address: aaveMarketId.address,
|
|
42
|
+
chainId: aaveMarketId.chainId,
|
|
43
|
+
name: 'Aave Market',
|
|
44
|
+
asset: {
|
|
45
|
+
address: { 130: getRandomAddress() },
|
|
46
|
+
metadata: { symbol: 'USDC', name: 'USD Coin', decimals: 6 },
|
|
47
|
+
type: 'erc20' as const,
|
|
48
|
+
},
|
|
49
|
+
lendProvider: 'aave',
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
describe('getMarkets', () => {
|
|
56
|
+
it('should aggregate markets from all providers', async () => {
|
|
57
|
+
const namespace = new TestLendNamespace({
|
|
58
|
+
morpho: mockMorphoProvider,
|
|
59
|
+
aave: mockAaveProvider,
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const markets = await namespace.getMarkets()
|
|
63
|
+
|
|
64
|
+
expect(markets).toHaveLength(2)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('should work with single provider', async () => {
|
|
68
|
+
const namespace = new TestLendNamespace({
|
|
69
|
+
morpho: mockMorphoProvider,
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
const markets = await namespace.getMarkets()
|
|
73
|
+
|
|
74
|
+
expect(markets).toHaveLength(1)
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
describe('getMarket', () => {
|
|
79
|
+
it('should route to correct provider based on market', async () => {
|
|
80
|
+
const namespace = new TestLendNamespace({
|
|
81
|
+
morpho: mockMorphoProvider,
|
|
82
|
+
aave: mockAaveProvider,
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
const morphoSpy = vi.spyOn(mockMorphoProvider, 'getMarket')
|
|
86
|
+
const aaveSpy = vi.spyOn(mockAaveProvider, 'getMarket')
|
|
87
|
+
|
|
88
|
+
await namespace.getMarket(mockMarketId)
|
|
89
|
+
|
|
90
|
+
expect(morphoSpy).toHaveBeenCalledWith(mockMarketId)
|
|
91
|
+
expect(aaveSpy).not.toHaveBeenCalled()
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('should throw if no provider found for market', async () => {
|
|
95
|
+
const namespace = new TestLendNamespace({
|
|
96
|
+
morpho: mockMorphoProvider,
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
const unknownMarket = {
|
|
100
|
+
address: getRandomAddress(),
|
|
101
|
+
chainId: 130 as const,
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
await expect(namespace.getMarket(unknownMarket)).rejects.toThrow(
|
|
105
|
+
'No provider configured for market',
|
|
106
|
+
)
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
describe('supportedChainIds', () => {
|
|
111
|
+
it('should return unique chain IDs from all providers', () => {
|
|
112
|
+
const namespace = new TestLendNamespace({
|
|
113
|
+
morpho: mockMorphoProvider,
|
|
114
|
+
aave: mockAaveProvider,
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
const chainIds = namespace.supportedChainIds()
|
|
118
|
+
|
|
119
|
+
expect(chainIds).toContain(1)
|
|
120
|
+
expect(chainIds).toContain(130)
|
|
121
|
+
expect(chainIds).toContain(8453)
|
|
122
|
+
expect(chainIds).toContain(84532)
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
it('should deduplicate chain IDs', () => {
|
|
126
|
+
const namespace = new TestLendNamespace({
|
|
127
|
+
morpho: mockMorphoProvider,
|
|
128
|
+
aave: mockAaveProvider,
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
const chainIds = namespace.supportedChainIds()
|
|
132
|
+
const uniqueChainIds = [...new Set(chainIds)]
|
|
133
|
+
|
|
134
|
+
expect(chainIds).toEqual(uniqueChainIds)
|
|
135
|
+
})
|
|
136
|
+
})
|
|
137
|
+
})
|