Borrow Blue to Midnight
BorrowBlueToMidnightCallback migrates a borrower from a variable-rate position on Morpho Blue into a fixed-rate position on Morpho Midnight in a single take.
Description
The borrower has a variable-rate position on Blue and posts a sell (borrow) offer on Midnight with this callback as the receiver. When the sell (borrow) offer is taken, the Midnight proceeds (sellerAssets) land on the callback. The callback uses them to repay the Blue debt, withdraws the Blue collateral, and supplies it to Midnight on the borrower's behalf, so the borrower exits the take with a fixed-rate borrow position on Midnight.
Blue has no maturity, so the renewal window is anchored to the user's renewalCadence (for example, FourWeekCadence) rather than a source maturity timestamp.
Step-by-step callback execution
The borrower posts a sell (borrow) offer on the Midnight target market 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 the Midnight target market by calling
MORPHO_MIDNIGHT.take(). The Midnight proceeds (sellerAssets) land on the callback because the offer'sreceiverIfMakerIsSellerpoints at it, and Morpho Midnight invokesonSellon the callback. - Validate: The Blue source market and the Midnight target market must share the same
loanToken. The Blue market's single collateral token must appear somewhere in the Midnight market's collateral set; the matching slot is resolved automatically by the callback. - Calculate and transfer fees: An effective-price fee is derived from the offer's tick and applied to the interest portion only, then transferred to the protocol fee recipient.
- Repay Blue: The callback repays the borrower's variable-rate debt with
sellerAssets - fee. On the final fill the position is closed in shares (exactly zero); on partial fills the debt is repaid pro-rata in assets. - Withdraw collateral: The matching amount of collateral is withdrawn from Blue (pro-rata on partial fills, in full on the final fill).
- Supply collateral: The withdrawn collateral is supplied to the matching slot on the Midnight market on the borrower's behalf.
Prerequisites
- The borrower must authorize the callback on Morpho Blue. Blue's authorization surface is distinct from Midnight's, so granting Midnight authorization is not sufficient.
- The offer's
receiverIfMakerIsSellermust point at this callback sosellerAssetslands here beforeonSellruns.
Only the Blue market's single collateral token is migrated. If the Midnight target lists additional collateral slots, the borrower must supply those separately (for example, via Supply Collateral). They are not pulled by this callback.