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.

realizeLoss

function realizeLoss(address adapter, bytes memory data) external

Realizes a loss reported by an adapter. This function is permissionless and updates the vault's totalAssets to reflect the loss. New deposits are blocked for the remainder of the transaction to prevent flashloan-based manipulation.

Parameters:

NameTypeDescription
adapteraddressThe adapter reporting the loss.
databytesThe protocol-specific data to identify the position with the loss.

accrueInterest

function accrueInterest() public

Accrues interest for the vault by querying the Vault Interest Controller (VIC) and updates totalAssets. This function is called by most state-changing functions.

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.

Curator Functions

The following functions are only callable by the Curator and are subject to a timelock. The 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.

Timelocked Actions

  • setIsAllocator(address, bool): Grants or revokes the Allocator role.
  • setVic(address): Sets the Vault Interest Controller (VIC).
  • setIsAdapter(address, bool): Enables or disables a protocol Adapter.
  • setSharesGate(address), setReceiveAssetsGate(address), setSendAssetsGate(address): Sets contracts for onchain compliance.
  • increaseAbsoluteCap(bytes, uint256), increaseRelativeCap(bytes, uint256): Increases risk limits for an id.
  • setPerformanceFee(uint256), setManagementFee(uint256): Sets the vault's fees.
  • setPerformanceFeeRecipient(address), setManagementFeeRecipient(address): Sets the fee recipients.
  • setForceDeallocatePenalty(address, uint256): Sets the penalty for using forceDeallocate.
  • abdicateSubmit(bytes4): Irreversibly disables the ability to submit a specific type of action.
  • decreaseTimelock(bytes4, uint256): Decreases a function's timelock duration (this action itself has a 2-week timelock).

Instant Actions

  • increaseTimelock(bytes4, uint256): Instantly increases a function's timelock duration.
  • decreaseAbsoluteCap(bytes, uint256), decreaseRelativeCap(bytes, uint256): Instantly decreases risk limits. Also callable by a Sentinel.
  • revoke(bytes): Revokes a pending timelocked action. Also callable by a Sentinel.

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.

setLiquidityMarket

function setLiquidityMarket(address newLiquidityAdapter, bytes memory newLiquidityData) external

Sets the default adapter for handling user deposits and withdrawals.