Supply Vault Shares as Collateral
MidnightSupplyVaultSharesCallback wraps the loan-token proceeds of a fixed-rate borrow into ERC-4626 vault shares and supplies them as collateral on Morpho Midnight, atomically in the same take.
Description
The borrower posts a sell (borrow) offer on Morpho Midnight with this callback set as receiverIfMakerIsSeller. When the offer is filled, the loan tokens received from the lender are deposited into an ERC-4626 vault and the resulting shares are supplied as collateral on the borrower's behalf. The borrower never holds the shares directly between transactions.
This is the supply side of the vault-as-collateral pattern. The withdraw side, used on early exit, is the MidnightWithdrawVaultSharesCallback.
Step-by-step callback execution
The borrower posts a sell (borrow) offer on Morpho Midnight with receiverIfMakerIsSeller set to this callback. The offer carries the callback wiring; the take triggers it.
- Take: A taker fills the borrower's sell (borrow) offer on Morpho Midnight by calling
MORPHO_MIDNIGHT.take(). The loan-token proceeds (sellerAssets) land on the callback because the offer'sreceiverIfMakerIsSellerpoints at it, and Morpho Midnight invokesonSellon the callback. - Validate that the vault is listed at
collateralIndexand thatasset() == loanToken. - Optional top-up: If
additionalDepositPercent > 0, pull additional loan tokens from the borrower, priced from the offer's tick. The borrower can over-collateralize the position this way (for example, deposit 130% of the position's value into the vault even though only 100% came from the lender). - Deposit all loan tokens held by the callback (
sellerAssets + top-up) into the vault. Shares are minted to the callback. - Supply collateral: Call
supplyCollateralon Morpho Midnight to supply those shares to the market on the borrower's behalf atcollateralIndex.
Prerequisites
- The offer's
receiverIfMakerIsSellermust be this callback so thatsellerAssetslands here beforeonSellfires. - If
additionalDepositPercent > 0, the borrower must have approved the callback for the loan token.
The callback holds no state and never refunds. Any loan tokens sent to it outside an active take get swept into the next supply call as if they were part of the fill, and end up in another borrower's position. Always route through Morpho Midnight's take().