# Midnight Liquidations

Understand Midnight liquidation rules for unhealthy positions and unpaid debt at maturity, including incentives, post-maturity cases, and bad debt.

Source: https://docs.morpho.org/learn/concepts/midnight/liquidation



A lender's position depends on borrowers repaying their debt. Two situations can put that at risk:

* A position becomes undercollateralized. If a borrower's collateral loses enough value, it may no longer cover their debt. Left unaddressed, this can lead to bad debt - a shortfall that lenders ultimately bear.
* Debt remains unpaid at maturity. A market matures on a fixed date, at which point lenders expect to redeem. A borrower who has not repaid - even one whose position is otherwise healthy - leaves lenders unable to withdraw the loan tokens they are owed.

Liquidation is the mechanism that addresses both. A liquidator repays borrower's debt and receives collateral in return; the repaid loan tokens become withdrawable liquidity for lenders in that market. Midnight has two liquidation paths, one for each situation:

* **Health-based liquidation** applies when a position is no longer safely backed by its collateral. It can be triggered at any time, before or after maturity, and protects lenders against solvency deterioration.
* **Post-maturity liquidation** applies when debt is still outstanding after the market's maturity, regardless of the position's health. It lets lenders redeem even when a borrower fails to repay on time.

## Borrower health and maximum debt [#borrower-health-and-maximum-debt]

A Midnight market can accept multiple collateral assets. Each collateral asset has its own oracle and **LLTV** (liquidation loan-to-value). LLTV is the percentage of a collateral's oracle value that contributes to a borrower's maximum debt (`maxDebt`).

Any borrower in a market can back their single debt with any mix of those listed collaterals. A borrower's maximum debt, called `maxDebt`, is the sum of these contributions across all collateral assets used by the borrower:

$$
\text{maxDebt} = \sum_i \left( \text{collateral value}_i \times \text{LLTV}_i \right)
$$

<Callout type="info" title="Example">
  Suppose a USDC market accepts WETH and cbBTC as collateral.

  A borrower deposits:

  * 2 WETH worth 3,000 USDC each, with 86% LLTV
  * 0.1 cbBTC worth 90,000 USDC, with 77% LLTV

  Their `maxDebt` is:

  * WETH contribution: 2 × 3,000 × 86% = 5,160 USDC
  * cbBTC contribution: 0.1 × 90,000 × 77% = 6,930 USDC

  Total `maxDebt` = 12,090 USDC.
</Callout>

A borrower is healthy as long as their `debt` is less than or equal to `maxDebt`.

<Callout type="info">
  Healthy and liquidatable are not the same thing. Before maturity, liquidation is based on borrower health. After maturity, a borrower with outstanding debt can also be liquidated through the post-maturity liquidation path, even if the position is still healthy.
</Callout>

## Liquidation incentive [#liquidation-incentive]

The **LIF** (liquidation incentive factor) determines how much collateral a liquidator receives for repaying debt.

A LIF of 1.05 means the liquidator receives collateral worth 1.05 loan tokens for each 1 loan token repaid. A LIF of 1.0 means there is no liquidation bonus.

Each collateral's **liquidation cursor** is fixed at market creation. Together with its LLTV, it determines the maximum LIF, called `maxLif`:

$$
\text{maxLif} = \frac{1}{1 - \text{liquidation cursor} \times (1 - \text{LLTV})}
$$

<Callout type="info">
  Use decimal values in this formula, with [the currently enabled cursor of **0.3**](/learn/concepts/midnight/#liquidation-cursor). For the same cursor of 0.3, a lower LLTV gives a higher maximum incentive.
</Callout>

The liquidation bonus is the borrower's liquidation penalty. The same amount can be stated against two bases:

* as a share of the debt repaid: `LIF - 1`;
* as a share of the collateral seized: `1 - 1 / LIF`, which at `maxLif` equals `liquidation cursor × (1 - LLTV)`.

<Callout type="info" title="Example">
  With a cursor of 0.3 and an LLTV of &#x2A;*86%** (0.86), `maxLif` is approximately **1.044** (a 4.4% bonus). A liquidator who repays 1,000 USDC of debt receives about 1,044 USDC worth of collateral. The 44 USDC penalty is:

  \- about 4.4% of the debt repaid (44 / 1,000);

  \- about 4.2% of the collateral seized (44 / 1,044, or 0.3 × 0.14).
</Callout>

The LIF used in a liquidation depends on the liquidation path:

* in health-based liquidation, the LIF is `maxLif`;
* in post-maturity liquidation, the LIF starts at 1.0 at maturity and rises linearly to `maxLif` over the next 60 minutes.

<Callout type="info">
  With a `maxLif` of 1.044, the penalty is about 1.1% of the debt repaid after 15 minutes, about 2.2% after 30 minutes, and about 4.4% from 60 minutes on.
</Callout>

## Health-based liquidation [#health-based-liquidation]

Health-based liquidation is available when a borrower is unhealthy, meaning `debt > maxDebt`.

In this path:

1. The liquidator repays part of the borrower's debt.
2. The liquidator receives collateral using the collateral's `maxLif`.
3. The repaid loan tokens become withdrawable liquidity for lenders.

Health-based liquidation is usually limited by the **RCF** (Recovery Close Factor). It prevents liquidating entire positions as soon as they become unhealthy - protecting borrowers from being over-liquidated for a small health breach - whilst still incentivizing liquidators to restore the position to health.

<Callout type="info">
  The RCF has two exceptions:

  * When `LLTV = 1`, repaying can never restore health, so the RCF is inactive and there is no cap on the liquidation amount.
  * When the collateral remaining after a partial liquidation would be too small to liquidate efficiently, the RCF is deactivated to avoid leaving dust positions.
</Callout>

## Post-maturity liquidation [#post-maturity-liquidation]

Post-maturity liquidation is available strictly after maturity when a borrower still has outstanding debt.

In this path:

1. The liquidator repays outstanding debt.
2. The liquidator receives collateral.
3. The LIF starts at 1.0 and rises linearly to `maxLif` over 60 minutes.
4. No RCF applies.

If a borrower is both post-maturity and unhealthy, the liquidator can choose either path:

* health-based liquidation: immediate `maxLif`, but RCF may apply;
* post-maturity liquidation: ramping LIF, with no RCF.

## Summary by case [#summary-by-case]

| Case                                   | Liquidatable?                                            | Liquidation mode              | LIF                                                                | RCF                       |
| -------------------------------------- | -------------------------------------------------------- | ----------------------------- | ------------------------------------------------------------------ | ------------------------- |
| **Pre-maturity and at exact maturity** |                                                          |                               |                                                                    |                           |
| Healthy                                | <DocsStatusBadge status="positive">No</DocsStatusBadge>  | -                             | -                                                                  | -                         |
| Unhealthy                              | <DocsStatusBadge status="negative">Yes</DocsStatusBadge> | Health-based                  | `maxLif`                                                           | RCF if `LLTV < 1`         |
| **Post-maturity - within 60 min ramp** |                                                          |                               |                                                                    |                           |
| Healthy                                | <DocsStatusBadge status="negative">Yes</DocsStatusBadge> | Post-maturity                 | 1.0 → `maxLif` (linear)                                            | No RCF                    |
| Unhealthy                              | <DocsStatusBadge status="negative">Yes</DocsStatusBadge> | Health-based or post-maturity | Health-based: `maxLif`<br />Post-maturity: 1.0 → `maxLif` (linear) | Only on health-based mode |
| **Post-maturity - after 60 min ramp**  |                                                          |                               |                                                                    |                           |
| Healthy                                | <DocsStatusBadge status="negative">Yes</DocsStatusBadge> | Post-maturity                 | `maxLif`                                                           | No RCF                    |
| Unhealthy                              | <DocsStatusBadge status="negative">Yes</DocsStatusBadge> | Health-based or post-maturity | `maxLif`                                                           | Only on health-based mode |

<Callout type="info" title="Liquidator gates">
  A market can use a liquidator gate to restrict who may liquidate.

  Restricting liquidators can change how quickly bad debt is realized and how quickly lenders receive recovered liquidity.

  More on liquidator gates in [the Gates section](/learn/concepts/midnight/gates/).
</Callout>

## Bad debt [#bad-debt]

Bad debt arises during liquidation when, even after seizing all the borrower's collateral at the maximum liquidation incentive, some debt still cannot be repaid. The protocol immediately records the excess as a loss.

This bad debt is distributed proportionally across lenders: each lender's credit is reduced by the share of total market credit that could not be recovered. The corresponding loan tokens are gone - they will never become withdrawable. Bad debt in one market does not affect lenders in other markets.

<Callout type="info" title="For developers">
  For the technical details on collateral, position health, and liquidation mechanics, see [Collateral, Health, Liquidations](/developers/midnight/concepts/collateral-health-liquidations/).
</Callout>