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. |
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:
Name | Type | Description |
---|---|---|
adapter | address | The adapter reporting the loss. |
data | bytes | The 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:
Curator
callssubmit(bytes calldata data)
with the ABI-encoded function call.- 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.