> For the complete documentation index, see [llms.txt](https://docs.moonwell.fi/moonwell/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.moonwell.fi/moonwell/developers/protocol/oev.md).

# OEV

Moonwell's OEV system captures value from liquidation MEV at the protocol level, splitting profits between liquidators and the protocol. Instead of block builders capturing all liquidation surplus, Moonwell delays Chainlink price updates by a short window and allows liquidators to access fresh prices early by routing liquidations through OEV wrapper contracts.

## How It Works

1. Each Chainlink price feed is wrapped in an OEV wrapper contract
2. The wrapper **delays price updates** by `maxRoundDelay` seconds (default: 10s)
3. Liquidators call `updatePriceEarlyAndLiquidate()` to access the fresh price and execute the liquidation in one transaction
4. Liquidation profits are split between the liquidator and the protocol based on `liquidatorFeeBps`
5. After the delay window expires, the fresh price becomes publicly available to everyone

There are two OEV wrapper variants - one for Moonwell Core markets (mToken-based) and one for Morpho Blue isolated markets.

## Configuration

These are the current deployed values. They are set at deployment and can be updated by the contract owner - do not hardcode them.

| Parameter          | Current Value | Description                                  |
| ------------------ | ------------- | -------------------------------------------- |
| `liquidatorFeeBps` | 4000          | Liquidator keeps 40% of profit               |
| `maxRoundDelay`    | 10            | Seconds before price becomes public          |
| `maxDecrements`    | 10            | Max previous rounds to search for valid data |

## Price Delay Mechanism

Both OEV wrappers implement the same delay logic in `latestRoundData()`:

```solidity
// Pseudo-code
if (roundId != cachedRoundId && block.timestamp < updatedAt + maxRoundDelay) {
    // Return PREVIOUS round data (delayed price)
    return getPreviousRoundData();
} else {
    // Return current round data (fresh price available to everyone)
    return currentRoundData;
}
```

After `maxRoundDelay` seconds, the fresh price becomes available to everyone. The OEV window is only valuable during this delay period.

{% content-ref url="/pages/QEcsZJlElyg2kox8VNJH" %}
[Core Markets](/moonwell/developers/protocol/oev/core-markets.md)
{% endcontent-ref %}

{% content-ref url="/pages/CaAuaageZRkQE4XmiOr7" %}
[Morpho Markets](/moonwell/developers/protocol/oev/morpho-markets.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.moonwell.fi/moonwell/developers/protocol/oev.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
