Overview
The liquidity adapter mechanism in Morpho Vault V2 enables automated allocation and deallocation of assets during user deposits and withdrawals. This ensures efficient capital deployment while maintaining sufficient liquidity for redemptions.Liquidity adapter concept
The liquidity adapter is a designated adapter used automatically during:- Deposits/Mints: Assets are allocated to the liquidity adapter after user deposits
- Withdrawals/Redeems: Assets are deallocated from the liquidity adapter when idle assets are insufficient
The same adapter and data are used for both entry and exit. This ensures that supply-withdraw or withdraw-supply loops don’t change the overall allocation pattern.
VaultV2.sol:104-112
Setting the liquidity adapter
Allocators can configure the liquidity adapter and its data:Example configuration
VaultV2.sol:628-633
Deposit flow with liquidity adapter
When users deposit or mint shares, the vault automatically allocates assets:Deposit code flow
VaultV2.sol:776-786
Withdrawal flow with liquidity adapter
When users withdraw or redeem shares, the vault deallocates if needed:Deallocate if needed
If idle assets are insufficient and
liquidityAdapter is set, assets are deallocated from it.Withdrawal code flow
VaultV2.sol:805-823
Liquidity adapter considerations
Cap implications
Relative cap with low TVL
When the vault has very low total assets, the relative cap mechanism can make deposits difficult:To allow deposits when the vault is nearly empty, consider:
- Setting relative caps to WAD (100%) for liquidity adapter IDs
- Using only absolute caps for liquidity adapters
- Temporarily removing the liquidity adapter during initial deposits
VaultV2.sol:110-112
Disabling automatic allocation
To disable automatic allocation and deallocation:- Deposits remain in the vault as idle assets
- Withdrawals can only use idle assets (no automatic deallocation)
- Allocators must manually manage all allocations
Liquidity adapter data
TheliquidityData parameter is adapter-specific encoded data:
liquidityData is indexed in the event so it cannot be read from logs. To retrieve current liquidity data, call vault.liquidityData().VaultV2.sol:236-239
Access control
Only allocators can set the liquidity adapter and data:VaultV2.sol:629
Best practices
Choose liquid markets
Select adapters pointing to highly liquid markets to ensure withdrawals don’t fail.
Monitor adapter health
Regularly check that the liquidity adapter can handle expected deposit/withdrawal volumes.
In-kind redemptions
Even if the liquidity adapter cannot deallocate (market is illiquid), users can still exit using force deallocate to withdraw directly from any market at the cost of a penalty. Source:VaultV2.sol:76