MidnightVaultExecutor
Git Source - Generated with forge doc
Inherits: IMidnightVaultExecutor, IRepayCallback, ILiquidateCallback
Title: MidnightVaultExecutor
Facilitates deposit, withdraw and liquidation of ERC-4626 vault shares used as Midnight collateral.
Supports multiple vaults: the vault is derived from market.collateralParams[collateralIndex].
The executor is pass-through, not custody.
Funds must be supplied within the same call; a balance parked across calls is neither usable nor recoverable.
VaultV2 deposits can revert if a liquidity-adapter cap of the vault is reached, blocking otherwise valid deposit-and-add-collateral flows.
Uses the Midnight contract as authorization authority (caller must be onBehalf or authorized by it on
Midnight).
VAULT SAFETY REQUIREMENTS
List of assumptions on the vault that guarantee this executor behaves as expected:
deposit,mintandredeemmove exactly the assets/shares they report. The executor pullspreviewMint(shares)on the mint path, which equals whatmintconsumes in the same transaction, so no dust is left behind.- It must be resistant to atomic share-price manipulation (donation/sandwich): no per-share-price/slippage bound is enforced by the executor, so deposit/mint/redeem settle at whatever rate the vault reports at execution time.
- It must not re-enter Midnight nor this executor on
deposit,mint,previewMintnorredeem.
Constants
MORPHO_MIDNIGHT
IMidnight public immutable MORPHO_MIDNIGHT
Functions
constructor
constructor(address morphoMidnight) ;
depositAndAddCollateral
Deposits into the market's vault-share collateral and supplies the resulting shares for onBehalf.
Provide either assets (and shares == 0) or shares (and assets == 0), not both.
function depositAndAddCollateral(
Market memory market,
uint256 collateralIndex,
uint256 assets,
uint256 shares,
address onBehalf
) external returns (uint256 depositedShares, uint256 usedAssets);
Parameters
| Name | Type | Description |
|---|---|---|
market | Market | The target market. |
collateralIndex | uint256 | The index in market.collateralParams whose token is the ERC-4626 vault deposited into. |
assets | uint256 | The deposit amount in vault assets. Set to 0 if supplying shares. |
shares | uint256 | The target share output. Set to 0 if supplying assets. |
onBehalf | address | The account credited with the collateral on Midnight. |
Returns
| Name | Type | Description |
|---|---|---|
depositedShares | uint256 | The vault shares supplied as collateral. |
usedAssets | uint256 | The vault assets consumed by the deposit. |
withdrawCollateralAndRedeem
Withdraws vault-share collateral from Midnight and redeems it into vault assets for receiver.
function withdrawCollateralAndRedeem(
Market memory market,
uint256 collateralIndex,
uint256 shares,
address onBehalf,
address receiver
) external returns (uint256 assets);
Parameters
| Name | Type | Description |
|---|---|---|
market | Market | The source market. |
collateralIndex | uint256 | The index in market.collateralParams whose token is the ERC-4626 vault redeemed from. |
shares | uint256 | The vault shares to withdraw and redeem. |
onBehalf | address | The account whose collateral is withdrawn. |
receiver | address | The address that receives the redeemed assets. |
Returns
| Name | Type | Description |
|---|---|---|
assets | uint256 | The vault assets transferred to receiver. |
onRepay
function onRepay(bytes32, Market memory market, uint256 units, address onBehalf, bytes memory data)
external
override
returns (bytes32);
onLiquidate
function onLiquidate(
address liquidator,
bytes32,
Market memory market,
uint256 collateralIndex,
uint256 seizedShares,
uint256 repaidUnits,
address,
address receiver,
bytes memory,
uint256
) external override returns (bytes32);
_withdrawAndRedeem
Shared by withdrawCollateralAndRedeem and onRepay: derives the vault from the market's collateral
and checks its asset matches the loan token, withdraws shares of vault-share collateral from onBehalf on
Midnight, and redeems them to redeemReceiver.
withdrawCollateralAndRedeem redeems to the external receiver;
onRepay redeems to the executor, which then funds the repay.
function _withdrawAndRedeem(
Market memory market,
uint256 collateralIndex,
uint256 shares,
address onBehalf,
address redeemReceiver
) internal returns (uint256 assets);
_fundRepay
function _fundRepay(address loanToken, uint256 redeemed, uint256 repaidUnits, address surplusReceiver) internal;
_checkAuthorized
function _checkAuthorized(address onBehalf) internal view;