Architecture
Morpho Vault V2 is built on a modular, role-based architecture that separates concerns between asset management, risk configuration, and market interactions. This design enables flexible yield strategies while maintaining strong security guarantees.System overview
The architecture consists of several key components working together:Core components
VaultV2 contract
The main vault contract handles:- Asset management: Deposits, withdrawals, and share accounting (ERC-4626)
- Allocation coordination: Routes assets to/from adapters
- Interest accrual: Tracks performance and realizes gains/losses
- Risk enforcement: Validates operations against caps and constraints
- Fee collection: Manages performance and management fees
The vault uses transient storage and accrues interest/loss only once per transaction to optimize gas and prevent manipulation.
VaultV2Factory
The factory contract deploys new vault instances using CREATE2 for deterministic addresses:Adapters
Adapters are separate contracts that hold positions on behalf of the vault and provide a standardized interface:- Enforce that only the vault can call allocate/deallocate
- Enter/exit markets only during allocate/deallocate calls
- Return correct risk IDs for cap enforcement
- Provide accurate real-time asset valuations
- Maintain approvals for the vault to transfer assets
Morpho Market V1 Adapter V2
Connects to Morpho Blue markets with adaptive curve IRM support
Morpho Vault V1 Adapter
Connects to MetaMorpho V1 vaults for nested strategies
Adapter registry
An optional registry can restrict which adapters a vault can use:The adapter registry is useful when the curator role is abdicated, ensuring the vault will forever only use authorized adapter types.
Data flow
Deposit flow
- User calls
deposit()ormint()with assets - Vault accrues interest (first call in transaction only)
- Assets transferred from user to vault
- Gates checked (if configured)
- Assets forwarded to liquidity adapter (if configured)
- Shares minted to user
Withdrawal flow
- User calls
withdraw()orredeem()with shares - Vault accrues interest (first call in transaction only)
- Gates checked (if configured)
- Idle assets used first
- Liquidity adapter deallocated if needed
- Assets transferred to user
- Shares burned
Allocation flow
- Allocator calls
allocate()with adapter, data, and amount - Vault checks adapter is enabled
- Assets transferred to adapter
- Adapter allocates to underlying market
- Adapter returns risk IDs and asset change
- Vault updates allocations and checks caps
- Event emitted for tracking
Interest accrual flow
- First interaction in a transaction triggers
accrueInterest() - Vault loops through all adapters calling
realAssets() - Gains and losses calculated
- Losses realized immediately (share price decreases)
- Gains limited by
maxRateto prevent manipulation - Performance fees calculated on interest
- Management fees calculated on principal
- Fee shares minted to recipients
- Total assets and last update timestamp recorded
Storage architecture
Immutable storage
Mutable storage
The vault maintains several categories of state: Roles:owner: Single address controlling curator and sentinelscurator: Single address managing configurationisAllocator: Mapping of allocator addressesisSentinel: Mapping of sentinel addresses
_totalAssets: Last recorded total assets (uint128)lastUpdate: Timestamp of last interest accrualfirstTotalAssets: Assets after first accrual in transaction- Standard ERC20 balances and allowances
adapters: Array of enabled adapter addressesisAdapter: Mapping for quick lookupsadapterRegistry: Optional registry address
allocation: Mapping from ID to current allocationabsoluteCap: Mapping from ID to absolute caprelativeCap: Mapping from ID to relative cap (WAD)forceDeallocatePenalty: Mapping from adapter to penalty (WAD)
liquidityAdapter: Address of liquidity adapterliquidityData: Encoded data for liquidity adaptermaxRate: Maximum rate of share price increase
timelock: Mapping from function selector to delayabdicated: Mapping from selector to abdication statusexecutableAt: Mapping from call data to execution timestamp
performanceFee: Fee on interest (WAD, max 50%)performanceFeeRecipient: Recipient addressmanagementFee: Fee on principal (WAD, max 5%/year)managementFeeRecipient: Recipient address
receiveSharesGate: Controls receiving sharessendSharesGate: Controls sending sharesreceiveAssetsGate: Controls withdrawing assetssendAssetsGate: Controls depositing assets
Security design
Immutability
All vault contracts are immutable with no upgrade mechanisms. This provides:- Predictable behavior forever
- No governance risk from upgrades
- Simplified auditing and verification
Role separation
Different roles have carefully scoped permissions:- Owner: Cannot directly hurt depositors, but sets curator
- Curator: Cannot directly hurt depositors without timelocks
- Allocators: Can move funds within caps, set liquidity adapter
- Sentinels: Can only decrease risk (revoke, deallocate, decrease caps)
Timelock protection
Critical curator actions are timelockable:- Submission creates pending action
- Execution only possible after timelock expires
- Users can exit before changes take effect
- Functions can be abdicated (permanently disabled)
Caps enforcement
Multi-layered risk limits:- ID-based system: Group related risks
- Absolute caps: Hard limits per ID
- Relative caps: Proportional limits (soft on exit)
- Checked on allocation: Prevents exceeding limits
Inflation attack protection
The vault uses virtual shares and decimal offset:Gas optimization
Single accrual per transaction
Interest and losses are accounted only once per transaction using transient storage:- First interaction triggers
accrueInterest() firstTotalAssetstracks if already accrued- Subsequent calls skip accrual
- Prevents flashloan manipulation
Efficient allocation tracking
Allocations are updated incrementally:- Only changed during allocate/deallocate
- Not updated on every interest accrual
- IDs removed when allocation reaches zero
Design considerations
Token requirements
The vault assumes the underlying asset:- Is ERC-20 compliant (may omit return values)
- Doesn’t re-enter on transfer
- Doesn’t have transfer fees
- Balance changes match transfer amounts exactly
Liveness requirements
For proper operation:- Adapters must not revert on
realAssets() - Token must not revert on transfers with valid approvals
- Total assets and supply must stay below ~10^35
- Vault pinged at least every 10 years
- Adapters must not revert on deallocate if markets are liquid
Next steps
Key features
Learn about timelocks, gates, fees, and other features
Adapters
Explore available adapters and integration patterns