Docs

Rolling loans into Morpho Blue

How fallback rolling can move Midnight debt to a Morpho Blue market.

Rolling moves a Midnight position's debt and collateral to another market, so the loan continues after maturity. Fallback rolling lets any caller move a borrower's position to a Morpho Blue market the borrower chose in advance, during a time window the borrower configured.

Fallback rolling contracts (BlueFallbackRolling) are listed on the Addresses page and contract specs are available here.

Why rolling matters

After maturity, a Midnight position with debt can be liquidated. Collateral, Health, Liquidations explains how liquidation works.

Liquidation has a cost. Fallback rolling lets a borrower keep a loan open past maturity, as a Morpho Blue position, without having to repay and borrow again themselves. Someone still has to call roll during the window: the borrower, the integrator, or any other caller.

ApproachWho takes actionDestinationWhat it needs
Manual rollingThe borrower or an integrator acting for themA market selected for the new positionSomeone to submit the repay and new borrow transactions
Fallback rollingAny caller during an enabled windowA Morpho Blue market selected in advanceBorrower authorization on Midnight and Morpho Blue, an enabled configuration, and destination liquidity

The fallback contract does not schedule a transaction. A borrower enables a configuration, and a caller can submit roll while its window is open. See Requirements for fallback rolling.

What a roll does

  1. The contract supplies collateral to Morpho Blue for the borrower. Morpho Blue records the collateral first and collects the tokens at the end of the call, handing control back to the contract in between (the onMorphoSupplyCollateral callback).
  2. During that callback, the contract borrows on Morpho Blue, for the borrower, the debt being rolled plus the incentive. This is possible because the collateral is already recorded.
  3. It repays that debt on Midnight and withdraws the matching collateral from Midnight. Morpho Blue then collects this collateral.
  4. It sends the incentive to the caller of roll.

All steps run in one transaction, without a flash loan. If any step fails, the whole roll reverts and nothing moves.

Example: a borrower owes 10,000 USDC on Midnight against 0.2 cbBTC, and a caller rolls the full debt when the incentive is 1%. The added debt is 100 USDC:

StepAmount
Borrowed on Morpho Blue for the borrower10,100 USDC
Used to repay Midnight debt10,000 USDC
Paid to the caller100 USDC
Collateral moved from Midnight to Morpho Blue0.2 cbBTC

After the roll, the borrower owes 10,100 USDC on Morpho Blue at the market's variable rate, against the same 0.2 cbBTC. The incentive is added to the debt; no collateral is paid to the caller.

A roll can move part of the debt or all of it. A partial roll must meet minRollableAssets; a roll of the full remaining debt is allowed even when it is below that minimum. For a partial roll, the collateral moved is the Midnight collateral multiplied by the rolled debt divided by the total debt, rounded down.

How the incentive changes

The incentive starts at incentiveAtStart and rises linearly to incentiveAtEnd over the window.

incentive(t) = incentiveAtStart
  + (incentiveAtEnd - incentiveAtStart) * (t - start) / (end - start)

The contract calculates the incentive from the configured start and end values and the current time, rounding the result down. The incentive rises until rolling becomes worth it for someone. The contract does not check the Morpho Blue market's liquidity before a caller submits roll. If the market cannot supply the required amount, that roll cannot complete.

Requirements for fallback rolling

  • A Morpho Blue market matches the Midnight position's loan token and single active collateral token. See Match the market parameters.
  • The market has enough available liquidity when roll runs. See How much liquidity is enough.
  • The borrower accepts that the loan continues on Morpho Blue at a variable rate.

A borrower who wants another fixed-rate term can arrange a manual roll to a later-maturity Midnight market instead.

How much liquidity is enough

  • Size for the combined debt of all configured positions that could roll into the same Morpho Blue market during overlapping windows, plus their incentives.
  • Compare expected debt with available liquidity over time, not only a single reading. Supply and borrow activity can change what is available before a roll is submitted.
  • Leave room for other borrowers and for liquidity withdrawals. A market that only just fits the expected roll amount can have no capacity when the call runs.

The contract borrows directly from the Morpho Blue market and does not call the Public Allocator. Only liquidity already in that market when the roll runs counts. A roller can reallocate liquidity into the market through the Public Allocator before calling the contract, within the flow caps the vaults set.

Match the market parameters

The contract checks that the Morpho Blue market has the same loan token and the same single active collateral token as the Midnight position. The integrator chooses the other Morpho Blue market parameters:

  • LLTV: select an LLTV appropriate for the position after the incentive is added.
  • Oracle: select an oracle appropriate for the collateral and consistent with the health assumptions used for the Midnight position.

Limitations and risks

  • Fallback rolling is not guaranteed. A caller must call roll during an enabled window, and the Morpho Blue market must have enough liquidity to supply the required assets.
  • A roll happens in a single transaction. If the new Morpho Blue position, or for a partial roll the remaining Midnight position, would be unhealthy, the whole roll reverts and nothing moves.
  • After the roll, Morpho Blue interest accrues on the debt and can affect the position's health.
  • The Midnight position can change before the roll (for example after a repayment or a new borrow). The contract uses the debt and collateral at the time of the roll.
  • A roll window can extend past maturity, but a matured position with debt can also be liquidated.

To set up fallback rolling, see Set up fallback rolling.