Skip to main content

Lend Midnight Renewal Callback

Rolls a lender's fixed-rate lending position from one Morpho Midnight market into a longer-dated Midnight fixed-rate market.

Description

The lender posts a buy (lend) offer on the target market with this callback set as the receiver. When the offer fills, Midnight invokes onBuy on the callback. The callback withdraws principal from the lender's source position and uses it to fund the new lend on the target market.

Step-by-step callback execution

The lender posts a buy (lend) offer on the target market with receiverIfMakerIsBuyer set to this callback. The callback will withdraw the lender's funds from the source market and fund the offer in the target market. The offer carries the callback wiring; the take triggers it.

LendMidnightRenewalCallback flow: a taker calls take() on the target market, which invokes onBuy on the callback; the callback withdraws principal from the source market and approves it to the target market to settle the new lend.
  1. Take: A taker fills the lender's renewal buy (lend) offer on the target market by calling MORPHO_MIDNIGHT.take(). Morpho Midnight invokes onBuy on the callback. Only Morpho Midnight may call; buyerAssets and obligationUnits must both be non-zero.
  2. Validation: The source and target obligations must share the same loanToken, otherwise TokenMismatch. The callback also reads the source position with slashing and continuous accrual applied and reverts with ZeroAmount if the post-update credit is zero.
  3. Fee: A fee is derived from the offer tick using the buyer-side effective price and applies to the interest portion of the offer only. When routed through the Migration Intent Ratifier, the ratifier sets the fee rate; used directly, the offer creator encodes it themselves. If fee > 0, it is sent to the fee recipient encoded in the callback data.
  4. Withdraw principal: The callback withdraws buyerAssets + fee from the source market on the lender's behalf.
  5. Transfer principal: The withdrawn buyerAssets funds the new lend on the target market.

Prerequisites

  • The lender must authorize the callback. The callback withdraws from the source position on the lender's behalf.
  • The target buy (lend) offer's receiver field must point at this callback.
  • The source position must be withdrawable at execution time. See Routing for the two cases.
Source must be withdrawable at take time

The source market must already permit withdrawal at execution time. This withdrawable can be created just in time by the keeper rolling the lender's position forward.

Routing

The natural taker of a lender's target buy (lend) renewal offer is a borrower, since taking that offer means borrowing at the offered rate. A keeper can also match the offer against an existing target borrow offer in the RFQ if that results in a positive spread (MEV profit).

The callback needs the lender's source position to be withdrawable when the take fires:

  • Source already withdrawable (matured, or a prior borrower repay at par). The take fills with no source-side action.
  • Source not yet withdrawable: Someone (the taker or a keeper) must bundle a source-side borrow + repay in the same transaction to create withdrawable.

Taker net rate (borrower)

When a borrower takes the lender's target buy (lend) renewal offer, they borrow at the offered rate X%. If the lender's source position isn't already withdrawable, the borrower also bears the cost of the source-side bundle (borrow + repay) needed to unlock it. That source-side interest accrues to the lender, so it raises the borrower's effective cost above X%.

Example. Lender's target buy (lend) offer at X% = 2%. A borrower takes the offer and borrows at 2% on the target. If the borrower also bundles a source-side borrow at the source market rate and repays at par to unlock the lender, the accrued source interest is added on top of their 2% target borrow.

Keeper

A third party keeper doesn't want to hold borrow exposure; they match existing offers when a positive spread exists.

  1. Read the lender's target buy (lend) offer at X%.
  2. Find a target sell (borrow) offer at Y% with Y − X > 0.
  3. If the source isn't already withdrawable, bundle a source-side borrow + repay to unlock the lender's position.
  4. Match the two target offers whenever the Y − X spread covers the source-side cost plus the keeper's transaction cost (gas).

In the Migration Intent Ratifier context, the keeper can take on behalf of the lender against a sell (borrow) offer in the RFQ, executing as soon as the spread exceeds the source-side cost and gas.

Example. Lender's target buy (lend) offer at X% = 2% and a matching target sell (borrow) offer at Y% = 6%. The 4% gross spread is the keeper's profit headroom. The keeper bundles a source-side borrow + repay to unlock the lender; the source-side interest accrues to the lender. The renewal goes through as long as the 4% target spread exceeds the source-side cost plus gas. The lender closes the source position early, rolls into the 2% target lend, and collects the keeper's source-side interest on top, netting a return above 2%.