Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/morpho-org/vault-v2/llms.txt

Use this file to discover all available pages before exploring further.

Overview

The MorphoVaultV1Adapter contract enables Morpho Vault V2 to allocate assets to Morpho Vaults V1 (also known as MetaMorpho). This adapter provides a simple interface for depositing into and withdrawing from V1 vaults while managing rewards through a skim mechanism.
This adapter is designed and audited specifically for Morpho Vaults V1 (versions V1.0 and V1.1). Integration with other vaults must be carefully assessed from a security standpoint.
  • Must only be used with Morpho Vaults V1 protected against inflation attacks with an initial deposit
  • Must not be used with a Morpho Vault V1 that has a market with an IRM that can re-enter the parent vault or adapter
  • Morpho Vaults V1.1 do not realize bad debt, so Morpho Vaults V2 supplying to them will not realize corresponding bad debt
  • Losses corresponding to rounding errors are realizable
  • Shares of the Morpho Vault V1 cannot be skimmed (only other tokens)

Contract details

License: GPL-2.0-or-later
Solidity version: 0.8.28

State variables

Immutable variables

factory

address public immutable factory
The address of the factory contract that deployed this adapter.

parentVault

address public immutable parentVault
The address of the parent Morpho Vault V2 that uses this adapter.

morphoVaultV1

address public immutable morphoVaultV1
The address of the Morpho Vault V1 (MetaMorpho) that this adapter interacts with.

adapterId

bytes32 public immutable adapterId
Unique identifier for this adapter instance, computed as keccak256(abi.encode("this", address(this))).

Storage variables

skimRecipient

address public skimRecipient
The address that receives skimmed tokens (rewards). Set by the vault owner.

Constructor

constructor(address _parentVault, address _morphoVaultV1)
Initializes the adapter with the parent vault and target Morpho Vault V1.
_parentVault
address
The address of the parent Morpho Vault V2
_morphoVaultV1
address
The address of the Morpho Vault V1 to integrate with
The constructor verifies that the asset of the parent vault matches the asset of the Morpho Vault V1.

View functions

ids

function ids() public view returns (bytes32[] memory)
Returns the adapter’s allocation IDs.
ids
bytes32[]
Array containing a single element: the adapter ID

allocation

function allocation() public view returns (uint256)
Returns the current allocation amount in the parent vault.
allocation
uint256
The allocation amount from the parent vault

realAssets

function realAssets() external view returns (uint256)
Returns the real assets held in the Morpho Vault V1, based on the adapter’s share balance.
assets
uint256
The preview redemption value of the adapter’s shares, or 0 if allocation is 0

Functions

setSkimRecipient

function setSkimRecipient(address newSkimRecipient) external
Sets the recipient address for skimmed tokens. Only callable by the vault owner.
newSkimRecipient
address
The new skim recipient address

skim

function skim(address token) external
Skims the adapter’s balance of a token and sends it to the skim recipient. Only callable by the skim recipient.
token
address
The token address to skim (cannot be Morpho Vault V1 shares)
Cannot skim Morpho Vault V1 shares. Attempting to do so will revert with CannotSkimMorphoVaultV1Shares().

allocate

function allocate(
    bytes memory data,
    uint256 assets,
    bytes4,
    address
) external returns (bytes32[] memory, int256)
Allocates assets to the Morpho Vault V1 by depositing. Only callable by the parent vault.
data
bytes
Must be empty (length 0)
assets
uint256
Amount of assets to allocate (deposit)
ids
bytes32[]
The adapter’s allocation IDs
change
int256
The change in allocation amount (new allocation - old allocation)
This function does not emit any events because the IDs logged in the parent vault are sufficient.

deallocate

function deallocate(
    bytes memory data,
    uint256 assets,
    bytes4,
    address
) external returns (bytes32[] memory, int256)
Deallocates assets from the Morpho Vault V1 by withdrawing. Only callable by the parent vault.
data
bytes
Must be empty (length 0)
assets
uint256
Amount of assets to deallocate (withdraw)
ids
bytes32[]
The adapter’s allocation IDs
change
int256
The change in allocation amount (new allocation - old allocation)
This function does not emit any events because the IDs logged in the parent vault are sufficient.

Events

SetSkimRecipient

event SetSkimRecipient(address indexed newSkimRecipient)
Emitted when the skim recipient address is updated.

Skim

event Skim(address indexed token, uint256 assets)
Emitted when tokens are skimmed from the adapter.
token
address
The address of the token that was skimmed
assets
uint256
The amount of tokens skimmed

Errors

AssetMismatch

error AssetMismatch()
Thrown during construction if the parent vault’s asset does not match the Morpho Vault V1’s asset.

CannotSkimMorphoVaultV1Shares

error CannotSkimMorphoVaultV1Shares()
Thrown when attempting to skim the Morpho Vault V1 share tokens.

InvalidData

error InvalidData()
Thrown when non-empty data is provided to allocate or deallocate functions.

NotAuthorized

error NotAuthorized()
Thrown when the caller is not authorized to perform the operation.

Build docs developers (and LLMs) love