> For the complete documentation index, see [llms.txt](https://help.defisaver.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.defisaver.com/protocols/morpho-midnight.md).

# Morpho Midnight

Morpho Midnight introduces a different approach to lending and borrowing in DeFi.

Instead of supplying assets into a traditional lending pool with variable interest rates and open-ended loans, Midnight introduces **fixed-rate, fixed-term lending markets**. Borrowers know how much their debt will cost, lenders know how much they can earn, and both sides know exactly when the loan reaches maturity.

However, simply creating fixed-term loans introduces a problem of its own.

What happens if a lender wants their money back before maturity? Does the borrower have to repay first? What if a borrower wants to repay early, but the lender wants to stay?

This is where Morpho Midnight's orderbook and fungible unit system come into play.

### Fixed rate, fixed term

Midnight markets have a predetermined maturity.

Instead of borrowing indefinitely at a variable rate, a borrower can know how much borrowing will cost over a specific period - The same applies to lenders.

Rather than supplying assets without knowing what rates might look like several months from now, a lender knows the value their position is expected to reach at maturity.

This creates much greater predictability for both sides of the market.

Midnight markets are separated based on factors including:

* the loan asset
* maturity
* collateral configuration

Within the same market, however, lenders and borrowers can submit offers at different rates.

### The Morpho Midnight orderbook

If you've ever traded through an exchange, you're probably familiar with an orderbook.

One side wants to buy at a particular price. Another wants to sell.

Midnight applies a similar concept to lending.

A lender might effectively say:

*"I'm willing to lend this amount at this rate."*

Another lender might be willing to lend at a slightly higher rate.

Borrowers can similarly express the terms at which they're willing to borrow.

> When compatible liquidity is available, an offer can be filled and a lending position is created.
>
> Orders can also be partially filled.
>
> Imagine you're looking to borrow $2 million, but only $1 million is available at a 4% rate. Another $1 million might be available at 4.1%.
>
> Your position can consume liquidity across those different offers rather than requiring the entire $2 million to be available at exactly the same rate.

There is another important difference compared to simply locking money into an orderbook.

**Capital doesn't necessarily have to sit idle while an offer waits to be filled.**

A lender's assets can remain deployed elsewhere, such as through Morpho Vaults, and continue earning yield. When the other side of the offer is found, a callback can source the required funds and complete the transaction.

This makes it possible to offer liquidity without necessarily leaving that capital sitting unused while waiting for a borrower.

### Understanding rates and maturity

Imagine paying **950 USDC today for something that will be worth 1,000 USDC at maturity**.

Your return over that remaining period is approximately:

***1,000 / 950 - 1 = 5.26%***

That **5.26% is the simple return over the remaining term, and not necessarily the APR shown in the interface.**

In other words, if maturity is several months away, the position still moves from 950 USDC to 1,000 USDC over those several months. That return is then **annualized into an APR** to make positions with different maturities easier to compare.

### Credit and debt units

Midnight performs its accounting using **fungible units of credit and debt**.

The easiest way to understand them is through a simple example:

> Imagine a lender is willing to provide **950 USDC today** in exchange for receiving **1,000 USDC at maturity**.
>
> The lender effectively buys:
>
> * **1,000 credit units**
>
> Each unit represents a claim on **1 USDC at maturity**.
>
> Since the lender paid 950 USDC for 1,000 units, each unit initially cost:
>
> * **0.95 USDC**
>
> Now we need someone on the other side.
>
> A borrower wants to receive 950 USDC today.
>
> They therefore effectively sell 1,000 units for 950 USDC.

The end result looks like this:

**Lender**

* Provides 950 USDC
* Receives 1,000 credit units
* Those units represent a claim on 1,000 USDC at maturity

**Borrower**

* Receives 950 USDC
* Receives 1,000 debt units
* Owes 1,000 USDC at maturity

The lender therefore holds **credit units**, while the borrower holds **debt units**.

This might initially seem like additional accounting for the sake of accounting, but in reality, these fungible units are what make Midnight's early exits possible.

### Why do fungible units matter?

Imagine a simpler fixed-term lending system that directly connects one lender with one borrower.

Lender A lends money to Borrower A for six months.

*What happens if Lender A suddenly wants their money back after three months?*

If their claim is directly tied to Borrower A, there isn't much they can do unless Borrower A agrees to repay early.

Midnight avoids this problem because positions aren't treated as permanent one-to-one relationships between specific lenders and borrowers.

Credit and debt are fungible within the market, which means new lenders and borrowers can enter while existing lenders and borrowers exit.

Let's look at how this works.

<details>

<summary>Scenario 1: A lender and borrower both want to exit</summary>

Let's continue with our original example.

Lender A holds 1,000 credit units.

Borrower A holds 1,000 debt units.

Some time has passed, and those units can now be exchanged at around **0.97 USDC each**, meaning 1,000 units cost 970 USDC.

Lender A wants their money back.

* They can sell their 1,000 credit units for 970 USDC.

Borrower A also wants to repay early.

* They spend 970 USDC to acquire 1,000 units, which offsets their 1,000 debt units.

The result is simple:

**Lender A exits.**

**Borrower A exits.**

{% hint style="info" %}
*From the user's perspective, these actions can simply look like withdrawing and repaying debt. The buy and sell terminology describes what is happening through Midnight's underlying unit accounting.*
{% endhint %}

</details>

<details>

<summary>Scenario 2: The lender wants to exit, but the borrower wants to stay</summary>

Now imagine Lender A wants their liquidity back, but Borrower A is perfectly happy keeping their loan until maturity.

Does Lender A have to wait for Borrower A? Not at all.

Lender A can offer their 1,000 credit units for 970 USDC.

A new lender, Lender B, can purchase those units.

* Lender A receives their 970 USDC and exits.
* Lender B now holds the 1,000 credit units representing the claim against the market.

Borrower A's position doesn't need to change.

There's another possibility as well:<br>

* Instead of a new lender purchasing those units, an existing borrower looking to repay debt can provide the liquidity on the other side.\
  \
  Their debt is reduced while Lender A gets to exit.

</details>

<details>

<summary>Scenario 3: The borrower wants to exit, but the lender wants to stay</summary>

Let's reverse the situation.

Borrower A wants to repay their position early, while Lender A wants to continue holding their credit.

* Borrower A can look to acquire 1,000 units for 970 USDC.
* An existing lender who wants to exit can sell their credit units into that liquidity.

Borrower A reduces their debt, and the exiting lender receives their USDC.

*The original lender can remain in the market.*

But there's another interesting possibility.

A **new borrower** might want to enter.

* Borrower A provides 970 USDC to exit their position, while Borrower B wants to borrow 970 USDC.
* Borrower B can take the other side, effectively selling the units that Borrower A needs to offset their debt.

Borrower A exits.

Borrower B enters.

And the lending side of the market doesn't need to change.

</details>

### Positions settle at the market level

This is the key concept tying all of these examples together.

It can be useful to talk about "Lender A" and "Borrower A" when explaining Midnight, but there isn't necessarily a permanent relationship between those two users.

> Positions settle at the market level rather than as individual peer-to-peer loans. So, a lender's credit units represent their position within that market - and a borrower's debt units represent their obligation within that market.
>
> Because those units are fungible, different participants can enter and exit without requiring the specific counterparty that originally helped create the position to do anything.

That's what allows a fixed-term lending market to retain considerably more flexibility than a simple system where one lender is locked to one borrower until maturity.

### What does this look like for the user?

After going through units, buy orders and sell orders, Midnight might sound considerably more complicated than a traditional lending protocol.

From the user's perspective, it doesn't necessarily have to be.

* A borrower who wants to exit is essentially **repaying their debt**.
* A lender who wants to exit is essentially **withdrawing their liquidity**.

The orderbook and fungible unit accounting are what allow those actions to happen in the background.

Understanding the units is useful because it explains *how* Midnight can offer fixed terms without necessarily locking every participant into their position until maturity.

### What about liquidations on Morpho Midnight?

Borrowers still need to maintain sufficient collateral.

Just like with a traditional lending protocol, if a position becomes undercollateralized, it can become eligible for liquidation.

A liquidator repays debt and receives collateral according to the protocol's liquidation mechanics.

The unique aspect of Midnight is that maturity introduces another important consideration.

Once maturity passes, the borrower's debt is due. Any outstanding debt can become eligible for post-maturity liquidation, even if the position would otherwise be sufficiently collateralized.

Borrowers therefore need to account for the maturity of their position rather than treating the loan as open-ended.

### Can a borrower repay before maturity?

Yes.

A borrower doesn't necessarily have to wait until the maturity date.

*Circling back on our previous example:*

The borrower received 950 USDC but ultimately owes 1,000 USDC.

If the relevant units can later be acquired for 970 USDC, the borrower may be able to close the position through the secondary market before maturity.

As maturity approaches, however, the economic value of a unit would generally be expected to move closer toward its final value of 1 USDC, assuming normal market conditions.

That means the potential discount available from exiting through secondary liquidity becomes smaller.

A borrower can also directly repay their debt at the full value of one loan token per debt unit rather than relying on secondary liquidity.

***

## Related Articles:
