Overview
Morpho Vault V2 allows allocators to move assets between markets within boundaries set by caps. Allocation operations enable efficient capital deployment while maintaining risk controls through absolute and relative caps.Allocation mechanism
Allocators can distribute vault assets to different markets through adapters. Each market is identified by one or more IDs that track allocations and enforce caps.Only accounts with the allocator role can call
allocate() and deallocate() functions. Sentinels can also deallocate assets.Allocating assets
Theallocate() function moves assets from the vault to an adapter representing a market:
Allocation process
Accrue interest
The vault first accrues any pending interest to update total assets and allocations.
Update allocations
The adapter returns IDs and the change in allocation, which updates tracked allocations.
Example allocation
Cap enforcement
Allocations are subject to two types of caps:- Absolute cap: Maximum total assets that can be allocated to an ID (in asset units)
- Relative cap: Maximum allocation as a fraction of total vault assets (in WAD, where 1e18 = 100%)
VaultV2.sol:575-600
Deallocating assets
Thedeallocate() function withdraws assets from an adapter back to the vault:
Deallocation process
Call adapter
The adapter’s
deallocate() function is called with the specified data and asset amount.Example deallocation
VaultV2.sol:602-624
Allocation tracking
Allocations are tracked per ID using theCaps struct:
Viewing allocations
Interest and losses
Allocations are updated when interacting with markets to account for accrued interest or realized losses. The change value returned by adapters includes both the intended allocation change and any interest or losses.
Allocation with interest
When allocating to a market that has accrued interest, the allocation increases by both the new assets and the interest:AllocateTest.sol:225-269
Relative cap protection
Relative caps usefirstTotalAssets rather than real-time total assets to prevent flashloan-based cap manipulation:
AllocateTest.sol:120-149
Access control
- Allocators: Can call both
allocate()anddeallocate() - Sentinels: Can only call
deallocate()(emergency withdrawals) - Others: Cannot call these functions
VaultV2.sol:575, 602