Morpho Vaults V2
Code
v2.0 repositoryStructs & Types
Caps
struct Caps {
uint256 allocation;
uint128 absoluteCap;
uint128 relativeCap;
}
Name | Type | Description |
---|---|---|
allocation | uint256 | The current amount of assets allocated to this id . |
absoluteCap | uint128 | The maximum amount of assets that can be allocated to this id . |
relativeCap | uint128 | The maximum percentage of total assets that can be allocated to this id , scaled by 1e18. |
External Functions
deposit
function deposit(uint256 assets, address onBehalf) external returns (uint256)
Deposits assets
of the underlying token to mint vault shares for onBehalf
.
Parameters:
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of the underlying asset to deposit. |
onBehalf | address | The recipient of the minted vault shares. |
Return Values:
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of vault shares minted. |
mint
function mint(uint256 shares, address onBehalf) external returns (uint256)
Mints exactly shares
vault shares for onBehalf
by depositing the required amount of the underlying token.
Parameters:
Name | Type | Description |
---|---|---|
shares | uint256 | The exact amount of shares to mint. |
onBehalf | address | The recipient of the minted vault shares. |
Return Values:
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of the underlying asset deposited. |
withdraw
function withdraw(uint256 assets, address receiver, address onBehalf) public returns (uint256)
Withdraws assets
of the underlying token by burning shares from onBehalf
and sends them to receiver
.
Parameters:
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of the underlying asset to withdraw. |
receiver | address | The recipient of the withdrawn assets. |
onBehalf | address | The owner of the shares to be burned. msg.sender must be approved. |
Return Values:
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of vault shares burned. |
redeem
function redeem(uint256 shares, address receiver, address onBehalf) external returns (uint256)
Burns exactly shares
vault shares from onBehalf
and sends the corresponding amount of underlying assets to receiver
.
Parameters:
Name | Type | Description |
---|---|---|
shares | uint256 | The exact amount of shares to burn. |
receiver | address | The recipient of the withdrawn assets. |
onBehalf | address | The owner of the shares to be burned. msg.sender must be approved. |
Return Values:
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of the underlying asset withdrawn. |
forceDeallocate
function forceDeallocate(address adapter, bytes memory data, uint256 assets, address onBehalf) external returns (uint256)
Forcibly deallocates assets
from a specific adapter
to the vault's idle pool. A penalty is taken from onBehalf
's shares to disincentivize misuse. This function is permissionless and serves as an in-kind redemption mechanism.
Parameters:
Name | Type | Description |
---|---|---|
adapter | address | The adapter to deallocate from. |
data | bytes | The protocol-specific data for the deallocation. |
assets | uint256 | The amount of assets to deallocate. |
onBehalf | address | The account from which the penalty shares will be burned. |
Return Values:
Name | Type | Description |
---|---|---|
withdrawnShares | uint256 | The amount of shares burned from onBehalf as a penalty. |
accrueInterest
function accrueInterest() public
Accrues interest for the vault by querying adapters for their current assets and updating totalAssets
. This function is called by most state-changing functions.
accrueInterestView
function accrueInterestView() public view returns (uint256, uint256, uint256)
Returns the view version of interest accrual without updating state.
Return Values:
Name | Type | Description |
---|---|---|
newTotalAssets | uint256 | The updated total assets after interest accrual. |
performanceFeeShares | uint256 | The amount of shares minted as performance fee. |
managementFeeShares | uint256 | The amount of shares minted as management fee. |
previewDeposit
function previewDeposit(uint256 assets) public view returns (uint256)
Returns previewed minted shares for a given asset amount.
Parameters:
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of assets to preview deposit for. |
Return Values:
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares that would be minted. |
previewMint
function previewMint(uint256 shares) public view returns (uint256)
Returns previewed deposited assets for a given share amount.
Parameters:
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares to preview mint for. |
Return Values:
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of assets that would be deposited. |
previewWithdraw
function previewWithdraw(uint256 assets) public view returns (uint256)
Returns previewed redeemed shares for a given asset amount.
Parameters:
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of assets to preview withdrawal for. |
Return Values:
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares that would be burned. |
previewRedeem
function previewRedeem(uint256 shares) public view returns (uint256)
Returns previewed withdrawn assets for a given share amount.
Parameters:
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares to preview redemption for. |
Return Values:
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of assets that would be withdrawn. |
convertToShares
function convertToShares(uint256 assets) external view returns (uint256)
Returns corresponding shares (rounded down) for a given asset amount. Takes into account performance and management fees.
Parameters:
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of assets to convert. |
Return Values:
Name | Type | Description |
---|---|---|
shares | uint256 | The corresponding amount of shares. |
convertToAssets
function convertToAssets(uint256 shares) external view returns (uint256)
Returns corresponding assets (rounded down) for a given share amount. Takes into account performance and management fees.
Parameters:
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares to convert. |
Return Values:
Name | Type | Description |
---|---|---|
assets | uint256 | The corresponding amount of assets. |
maxDeposit
function maxDeposit(address) external pure returns (uint256)
Returns the maximum amount of assets that can be deposited. Always returns 0 due to gate complexity.
maxMint
function maxMint(address) external pure returns (uint256)
Returns the maximum amount of shares that can be minted. Always returns 0 due to gate complexity.
maxWithdraw
function maxWithdraw(address) external pure returns (uint256)
Returns the maximum amount of assets that can be withdrawn. Always returns 0 due to gate complexity.
maxRedeem
function maxRedeem(address) external pure returns (uint256)
Returns the maximum amount of shares that can be redeemed. Always returns 0 due to gate complexity.
multicall
function multicall(bytes[] calldata data) external
Useful for EOAs to batch admin calls. Does not return anything, because accounts who would use the return data would be contracts, which can do the multicall themselves.
Parameters:
Name | Type | Description |
---|---|---|
data | bytes[] | Array of encoded function calls to execute. |
Owner Functions
setOwner
function setOwner(address newOwner) external
Transfers ownership of the vault to newOwner
. Only callable by the current owner
.
setCurator
function setCurator(address newCurator) external
Sets the vault's Curator
. Only callable by the owner
.
setIsSentinel
function setIsSentinel(address account, bool newIsSentinel) external
Grants or revokes the Sentinel
role for an account
. Only callable by the owner
.
setName
function setName(string memory newName) external
Sets the vault's name. Only callable by the owner
.
setSymbol
function setSymbol(string memory newSymbol) external
Sets the vault's symbol. Only callable by the owner
.
Curator Functions
The following functions are only callable by the Curator
. Some are subject to a timelock while others are instant. The timelock process is:
Curator
callssubmit(bytes calldata data)
with the ABI-encoded function call.- After the timelock expires, anyone can execute the function directly.
abdicate
function abdicate(bytes4 selector) external
Irreversibly disables the ability to submit a specific type of action.
Timelocked ActionParameters:
Name | Type | Description |
---|---|---|
selector | bytes4 | The function selector to abdicate. |
addAdapter
function addAdapter(address account) external
Adds a new adapter to the vault.
Timelocked ActionParameters:
Name | Type | Description |
---|---|---|
account | address | The adapter address to add. |
decreaseAbsoluteCap
function decreaseAbsoluteCap(bytes memory idData, uint256 newAbsoluteCap) external
Decreases the absolute cap for an id
.
Instant Action (also callable by a Sentinel
)
Parameters:
Name | Type | Description |
---|---|---|
idData | bytes | The ID data to decrease cap for. |
newAbsoluteCap | uint256 | The new absolute cap value. |
decreaseRelativeCap
function decreaseRelativeCap(bytes memory idData, uint256 newRelativeCap) external
Decreases the relative cap for an id
.
Instant Action (also callable by a Sentinel
)
Parameters:
Name | Type | Description |
---|---|---|
idData | bytes | The ID data to decrease cap for. |
newRelativeCap | uint256 | The new relative cap value (scaled by 1e18). |
decreaseTimelock
function decreaseTimelock(bytes4 selector, uint256 newDuration) external
Decreases a function's timelock duration (this action itself has a 3-week timelock).
Timelocked ActionParameters:
Name | Type | Description |
---|---|---|
selector | bytes4 | The function selector. |
newDuration | uint256 | The new timelock duration. |
increaseAbsoluteCap
function increaseAbsoluteCap(bytes memory idData, uint256 newAbsoluteCap) external
Increases the absolute cap for an id
.
Parameters:
Name | Type | Description |
---|---|---|
idData | bytes | The ID data to increase cap for. |
newAbsoluteCap | uint256 | The new absolute cap value. |
increaseRelativeCap
function increaseRelativeCap(bytes memory idData, uint256 newRelativeCap) external
Increases the relative cap for an id
.
Parameters:
Name | Type | Description |
---|---|---|
idData | bytes | The ID data to increase cap for. |
newRelativeCap | uint256 | The new relative cap value (scaled by 1e18). |
increaseTimelock
function increaseTimelock(bytes4 selector, uint256 newDuration) external
Increases a function's timelock duration.
Instant ActionParameters:
Name | Type | Description |
---|---|---|
selector | bytes4 | The function selector. |
newDuration | uint256 | The new timelock duration. |
removeAdapter
function removeAdapter(address account) external
Removes an adapter from the vault.
Timelocked ActionParameters:
Name | Type | Description |
---|---|---|
account | address | The adapter address to remove. |
revoke
function revoke(bytes calldata data) external
Revokes a pending timelocked action.
Instant Action (also callable by a Sentinel
)
Parameters:
Name | Type | Description |
---|---|---|
data | bytes | The ABI-encoded function call data to revoke. |
setAdapterRegistry
function setAdapterRegistry(address newAdapterRegistry) external
Sets the adapter registry contract. The no-op will revert if the registry now returns false for an already added adapter.
Timelocked ActionParameters:
Name | Type | Description |
---|---|---|
newAdapterRegistry | address | The new adapter registry contract. |
setForceDeallocatePenalty
function setForceDeallocatePenalty(address adapter, uint256 newForceDeallocatePenalty) external
Sets the penalty for using forceDeallocate
on a specific adapter.
Parameters:
Name | Type | Description |
---|---|---|
adapter | address | The adapter to set penalty for. |
newForceDeallocatePenalty | uint256 | The new penalty value (scaled by 1e18). |
setIsAllocator
function setIsAllocator(address account, bool newIsAllocator) external
Grants or revokes the Allocator
role for an account.
Parameters:
Name | Type | Description |
---|---|---|
account | address | The account to modify. |
newIsAllocator | bool | Whether the account should be an allocator. |
setManagementFee
function setManagementFee(uint256 newManagementFee) external
Sets the vault's management fee.
Timelocked ActionParameters:
Name | Type | Description |
---|---|---|
newManagementFee | uint256 | The new management fee (scaled by 1e18). |
setManagementFeeRecipient
function setManagementFeeRecipient(address newManagementFeeRecipient) external
Sets the management fee recipient.
Timelocked ActionParameters:
Name | Type | Description |
---|---|---|
newManagementFeeRecipient | address | The new management fee recipient. |
setPerformanceFee
function setPerformanceFee(uint256 newPerformanceFee) external
Sets the vault's performance fee.
Timelocked ActionParameters:
Name | Type | Description |
---|---|---|
newPerformanceFee | uint256 | The new performance fee (scaled by 1e18). |
setPerformanceFeeRecipient
function setPerformanceFeeRecipient(address newPerformanceFeeRecipient) external
Sets the performance fee recipient.
Timelocked ActionParameters:
Name | Type | Description |
---|---|---|
newPerformanceFeeRecipient | address | The new performance fee recipient. |
setReceiveAssetsGate
function setReceiveAssetsGate(address newReceiveAssetsGate) external
Sets the contract for gating asset receipts.
Timelocked ActionParameters:
Name | Type | Description |
---|---|---|
newReceiveAssetsGate | address | The new receive assets gate contract. |
setReceiveSharesGate
function setReceiveSharesGate(address newReceiveSharesGate) external
Sets the contract for gating share receipts.
Timelocked ActionParameters:
Name | Type | Description |
---|---|---|
newReceiveSharesGate | address | The new receive shares gate contract. |
setSendAssetsGate
function setSendAssetsGate(address newSendAssetsGate) external
Sets the contract for gating asset sends.
Timelocked ActionParameters:
Name | Type | Description |
---|---|---|
newSendAssetsGate | address | The new send assets gate contract. |
setSendSharesGate
function setSendSharesGate(address newSendSharesGate) external
Sets the contract for gating share sends.
Timelocked ActionParameters:
Name | Type | Description |
---|---|---|
newSendSharesGate | address | The new send shares gate contract. |
submit
function submit(bytes calldata data) external
Submits a timelocked action for execution after the timelock period expires.
Timelock Management FunctionParameters:
Name | Type | Description |
---|---|---|
data | bytes | The ABI-encoded function call data. |
Allocator Functions
allocate
function allocate(address adapter, bytes memory data, uint256 assets) external
Allocates assets
from the vault's idle pool to a specific adapter
.
deallocate
function deallocate(address adapter, bytes memory data, uint256 assets) external
Deallocates assets
from an adapter
back to the vault's idle pool. Also callable by a Sentinel
.
setLiquidityAdapterAndData
function setLiquidityAdapterAndData(address newLiquidityAdapter, bytes memory newLiquidityData) external
Sets the default adapter for handling user deposits and withdrawals.
Parameters:
Name | Type | Description |
---|---|---|
newLiquidityAdapter | address | The new liquidity adapter address. |
newLiquidityData | bytes | The new liquidity data for the adapter. |
setMaxRate
function setMaxRate(uint256 newMaxRate) external
Sets the maximum rate at which totalAssets
can grow.
Parameters:
Name | Type | Description |
---|---|---|
newMaxRate | uint256 | The new maximum rate (scaled by 1e18). |
Gating Functions
canReceiveShares
function canReceiveShares(address account) public view returns (bool)
Checks if an account can receive shares based on the receive shares gate.
Parameters:
Name | Type | Description |
---|---|---|
account | address | The account to check. |
Return Values:
Name | Type | Description |
---|---|---|
allowed | bool | Whether the account can receive shares. |
canSendShares
function canSendShares(address account) public view returns (bool)
Checks if an account can send shares based on the send shares gate.
Parameters:
Name | Type | Description |
---|---|---|
account | address | The account to check. |
Return Values:
Name | Type | Description |
---|---|---|
allowed | bool | Whether the account can send shares. |
canReceiveAssets
function canReceiveAssets(address account) public view returns (bool)
Checks if an account can receive assets based on the receive assets gate. The vault itself is always allowed.
Parameters:
Name | Type | Description |
---|---|---|
account | address | The account to check. |
Return Values:
Name | Type | Description |
---|---|---|
allowed | bool | Whether the account can receive assets. |
canSendAssets
function canSendAssets(address account) public view returns (bool)
Checks if an account can send assets based on the send assets gate.
Parameters:
Name | Type | Description |
---|---|---|
account | address | The account to check. |
Return Values:
Name | Type | Description |
---|---|---|
allowed | bool | Whether the account can send assets. |