Skip to main content

MidnightWithdrawVaultSharesCallback

Git Source - Generated with forge doc

Inherits: IMidnightWithdrawVaultSharesCallback

Title: MidnightWithdrawVaultSharesCallback

Callback that withdraws vault share collateral and redeems it to fund a borrower's BUY offer on Midnight.

The buyer must authorize this contract on Morpho Midnight to withdraw collateral on their behalf.

Only the shares needed to cover buyerAssets are withdrawn; the remaining collateral stays on Midnight.

Intended for reduceOnly offers: it does not check whether the fill crosses the buyer from debt into credit. VAULT SAFETY REQUIREMENTS

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

  • withdraw(assets) burns exactly previewWithdraw(assets) shares when both run in the same transaction. ERC-4626 only requires withdraw to burn no more shares than previewWithdraw, so a vault that accrues interest lazily returns a stale, inflated preview and the surplus shares pulled from the buyer's collateral are stranded here.
  • It must have immediate exit liquidity for buyerAssets, otherwise withdraw reverts and the fill fails.
  • 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 previewWithdraw nor withdraw.

Constants

MORPHO_MIDNIGHT

IMidnight public immutable MORPHO_MIDNIGHT

Functions

constructor

constructor(address morphoMidnight) ;

onBuy

function onBuy(
bytes32 marketId,
Market memory market,
uint256 buyerAssets,
uint256 units,
uint256,
address buyer,
bytes memory data
) external override returns (bytes32);