VaultV2Factory contract provides a deterministic deployment mechanism for creating Morpho Vault V2 instances. It uses CREATE2 for predictable vault addresses and maintains a registry of all deployed vaults.
Contract overview
The factory contract handles vault deployment and provides lookup functionality to verify vault authenticity and retrieve deployed vault addresses.Key features
- Deterministic deployment: Uses CREATE2 with salt for predictable vault addresses
- Vault registry: Tracks all deployed vaults with
isVaultV2mapping - Address lookup: Query deployed vault addresses by owner, asset, and salt
- Event emission: Emits
CreateVaultV2event for indexing and tracking
Factory deployment
TheVaultV2Factory contract is a simple, immutable factory with no constructor parameters:
VaultV2Factory.sol
Creating vaults
Use thecreateVaultV2 function to deploy new vault instances:
Parameters
The initial owner of the vault who will have administrative control
The ERC20 token address that the vault will accept as deposits
A unique salt value for CREATE2 deployment to generate deterministic addresses
Returns
The address of the newly deployedVaultV2 contract.
Verifying vaults
The factory provides methods to verify vault authenticity and lookup deployed addresses:Check if address is a factory-deployed vault
Lookup vault by parameters
address(0).
Computing vault addresses
You can predict the vault address before deployment using CREATE2 address calculation:The predicted address calculation must use the exact same parameters (owner, asset, salt) that will be passed to
createVaultV2.Events
The factory emits the following event when a vault is created:- Track all vault deployments
- Index vaults by owner or asset
- Monitor vault creation activity
- Build off-chain registries of vaults
Example usage
Next steps
Vault creation
Step-by-step guide to creating and initializing a vault
Configuration
Configure your vault with roles, fees, and parameters