Skip to content

← Back to contracts

Morpho Vaults V2

Code

v2.0 repository

Structs & Types

Caps

struct Caps {
    uint256 allocation;
    uint128 absoluteCap;
    uint128 relativeCap;
}
NameTypeDescription
allocationuint256The current amount of assets allocated to this id.
absoluteCapuint128The maximum amount of assets that can be allocated to this id.
relativeCapuint128The 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:

NameTypeDescription
assetsuint256The amount of the underlying asset to deposit.
onBehalfaddressThe recipient of the minted vault shares.

Return Values:

NameTypeDescription
sharesuint256The 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:

NameTypeDescription
sharesuint256The exact amount of shares to mint.
onBehalfaddressThe recipient of the minted vault shares.

Return Values:

NameTypeDescription
assetsuint256The 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:

NameTypeDescription
assetsuint256The amount of the underlying asset to withdraw.
receiveraddressThe recipient of the withdrawn assets.
onBehalfaddressThe owner of the shares to be burned. msg.sender must be approved.

Return Values:

NameTypeDescription
sharesuint256The 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:

NameTypeDescription
sharesuint256The exact amount of shares to burn.
receiveraddressThe recipient of the withdrawn assets.
onBehalfaddressThe owner of the shares to be burned. msg.sender must be approved.

Return Values:

NameTypeDescription
assetsuint256The 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:

NameTypeDescription
adapteraddressThe adapter to deallocate from.
databytesThe protocol-specific data for the deallocation.
assetsuint256The amount of assets to deallocate.
onBehalfaddressThe account from which the penalty shares will be burned.

Return Values:

NameTypeDescription
withdrawnSharesuint256The 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:

NameTypeDescription
newTotalAssetsuint256The updated total assets after interest accrual.
performanceFeeSharesuint256The amount of shares minted as performance fee.
managementFeeSharesuint256The 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:

NameTypeDescription
assetsuint256The amount of assets to preview deposit for.

Return Values:

NameTypeDescription
sharesuint256The 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:

NameTypeDescription
sharesuint256The amount of shares to preview mint for.

Return Values:

NameTypeDescription
assetsuint256The 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:

NameTypeDescription
assetsuint256The amount of assets to preview withdrawal for.

Return Values:

NameTypeDescription
sharesuint256The 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:

NameTypeDescription
sharesuint256The amount of shares to preview redemption for.

Return Values:

NameTypeDescription
assetsuint256The 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:

NameTypeDescription
assetsuint256The amount of assets to convert.

Return Values:

NameTypeDescription
sharesuint256The 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:

NameTypeDescription
sharesuint256The amount of shares to convert.

Return Values:

NameTypeDescription
assetsuint256The 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:

NameTypeDescription
databytes[]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:

  1. Curator calls submit(bytes calldata data) with the ABI-encoded function call.
  2. 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 Action

Parameters:

NameTypeDescription
selectorbytes4The function selector to abdicate.

addAdapter

function addAdapter(address account) external

Adds a new adapter to the vault.

Timelocked Action

Parameters:

NameTypeDescription
accountaddressThe 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:

NameTypeDescription
idDatabytesThe ID data to decrease cap for.
newAbsoluteCapuint256The 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:

NameTypeDescription
idDatabytesThe ID data to decrease cap for.
newRelativeCapuint256The 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 Action

Parameters:

NameTypeDescription
selectorbytes4The function selector.
newDurationuint256The new timelock duration.

increaseAbsoluteCap

function increaseAbsoluteCap(bytes memory idData, uint256 newAbsoluteCap) external

Increases the absolute cap for an id.

Timelocked Action

Parameters:

NameTypeDescription
idDatabytesThe ID data to increase cap for.
newAbsoluteCapuint256The new absolute cap value.

increaseRelativeCap

function increaseRelativeCap(bytes memory idData, uint256 newRelativeCap) external

Increases the relative cap for an id.

Timelocked Action

Parameters:

NameTypeDescription
idDatabytesThe ID data to increase cap for.
newRelativeCapuint256The new relative cap value (scaled by 1e18).

increaseTimelock

function increaseTimelock(bytes4 selector, uint256 newDuration) external

Increases a function's timelock duration.

Instant Action

Parameters:

NameTypeDescription
selectorbytes4The function selector.
newDurationuint256The new timelock duration.

removeAdapter

function removeAdapter(address account) external

Removes an adapter from the vault.

Timelocked Action

Parameters:

NameTypeDescription
accountaddressThe adapter address to remove.

revoke

function revoke(bytes calldata data) external

Revokes a pending timelocked action.

Instant Action (also callable by a Sentinel)

Parameters:

NameTypeDescription
databytesThe 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 Action

Parameters:

NameTypeDescription
newAdapterRegistryaddressThe new adapter registry contract.

setForceDeallocatePenalty

function setForceDeallocatePenalty(address adapter, uint256 newForceDeallocatePenalty) external

Sets the penalty for using forceDeallocate on a specific adapter.

Timelocked Action

Parameters:

NameTypeDescription
adapteraddressThe adapter to set penalty for.
newForceDeallocatePenaltyuint256The new penalty value (scaled by 1e18).

setIsAllocator

function setIsAllocator(address account, bool newIsAllocator) external

Grants or revokes the Allocator role for an account.

Timelocked Action

Parameters:

NameTypeDescription
accountaddressThe account to modify.
newIsAllocatorboolWhether the account should be an allocator.

setManagementFee

function setManagementFee(uint256 newManagementFee) external

Sets the vault's management fee.

Timelocked Action

Parameters:

NameTypeDescription
newManagementFeeuint256The new management fee (scaled by 1e18).

setManagementFeeRecipient

function setManagementFeeRecipient(address newManagementFeeRecipient) external

Sets the management fee recipient.

Timelocked Action

Parameters:

NameTypeDescription
newManagementFeeRecipientaddressThe new management fee recipient.

setPerformanceFee

function setPerformanceFee(uint256 newPerformanceFee) external

Sets the vault's performance fee.

Timelocked Action

Parameters:

NameTypeDescription
newPerformanceFeeuint256The new performance fee (scaled by 1e18).

setPerformanceFeeRecipient

function setPerformanceFeeRecipient(address newPerformanceFeeRecipient) external

Sets the performance fee recipient.

Timelocked Action

Parameters:

NameTypeDescription
newPerformanceFeeRecipientaddressThe new performance fee recipient.

setReceiveAssetsGate

function setReceiveAssetsGate(address newReceiveAssetsGate) external

Sets the contract for gating asset receipts.

Timelocked Action

Parameters:

NameTypeDescription
newReceiveAssetsGateaddressThe new receive assets gate contract.

setReceiveSharesGate

function setReceiveSharesGate(address newReceiveSharesGate) external

Sets the contract for gating share receipts.

Timelocked Action

Parameters:

NameTypeDescription
newReceiveSharesGateaddressThe new receive shares gate contract.

setSendAssetsGate

function setSendAssetsGate(address newSendAssetsGate) external

Sets the contract for gating asset sends.

Timelocked Action

Parameters:

NameTypeDescription
newSendAssetsGateaddressThe new send assets gate contract.

setSendSharesGate

function setSendSharesGate(address newSendSharesGate) external

Sets the contract for gating share sends.

Timelocked Action

Parameters:

NameTypeDescription
newSendSharesGateaddressThe 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 Function

Parameters:

NameTypeDescription
databytesThe 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:

NameTypeDescription
newLiquidityAdapteraddressThe new liquidity adapter address.
newLiquidityDatabytesThe new liquidity data for the adapter.

setMaxRate

function setMaxRate(uint256 newMaxRate) external

Sets the maximum rate at which totalAssets can grow.

Parameters:

NameTypeDescription
newMaxRateuint256The 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:

NameTypeDescription
accountaddressThe account to check.

Return Values:

NameTypeDescription
allowedboolWhether 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:

NameTypeDescription
accountaddressThe account to check.

Return Values:

NameTypeDescription
allowedboolWhether 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:

NameTypeDescription
accountaddressThe account to check.

Return Values:

NameTypeDescription
allowedboolWhether 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:

NameTypeDescription
accountaddressThe account to check.

Return Values:

NameTypeDescription
allowedboolWhether the account can send assets.