Skip to main content

MidnightSupplyVaultSharesCallback

Git Source - Generated with forge doc

Inherits: IMidnightSupplyVaultSharesCallback

Title: MidnightSupplyVaultSharesCallback

Callback that deposits loan tokens into an ERC-4626 vault and supplies the resulting shares as collateral when a SELL offer is taken on Midnight.

The offer's receiverIfMakerIsSeller (or receiverIfTakerIsSeller when the taker sells) must be this contract so sellerAssets are transferred here before onSell; onSell reverts InvalidReceiver unless receiver is this contract.

The borrower must approve this contract for the loan token and authorize it on Morpho Midnight (collateral supply).

The vault must be listed in the market's collaterals.

Any balance left on this contract is forfeited.

On Morpho Vault-v2, deposits can revert if a liquidity-adapter cap is reached, blocking otherwise valid fills. VAULT SAFETY REQUIREMENTS

List of assumptions on the collateral vault that guarantee this callback behaves as expected:

  • deposit(assets) returns exactly the number of shares it mints to this callback. ERC-4626 does not require the return value to equal the shares minted, so a vault that under-reports supplies less collateral than it minted and strands the remainder here.
  • Its share price must not move adversely between offer creation and fill: the deposit accepts whatever rate the vault reports, with no minimum-shares bound. The vault must be resistant to atomic share-price manipulation (e.g. sandwiched via donation).
  • Its shares should carry high decimals (e.g. 18 via a virtual-shares offset) so per-fill rounding is negligible; shares that match a low-decimal underlying let dust-sized fills socialize per-fill rounding loss to other depositors over many takes (takeUnits has no minimum).
  • It must not re-enter Midnight nor this callback on deposit.

Constants

MORPHO_MIDNIGHT

IMidnight public immutable MORPHO_MIDNIGHT

Functions

constructor

constructor(address morphoMidnight) ;

onSell

function onSell(
bytes32 marketId,
Market memory market,
uint256 sellerAssets,
uint256 units,
uint256, /* pendingFeeDecrease */
address seller,
address receiver,
bytes memory data
) external override returns (bytes32);