> For the complete documentation index, see [llms.txt](https://docs.dahlia.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.dahlia.xyz/key-concepts/oracles.md).

# Oracles

Accurate asset pricing is fundamental to the safety and efficiency of lending and borrowing operations. To address this, lending protocols use Oracle contracts to aggregate and process price feeds. Dahlia’s approach to oracles is designed to provide flexibility, scalability, and robust data integrity — critical for long-tail assets that often face liquidity challenges.

### Oracle-Agnostic Design

Dahlia markets are **oracle agnostic**, meaning any oracle can be used as long as it implements the **IDahliaOracle** interface. This allows for seamless integration with existing price feeds while supporting custom oracle implementations.

Dahlia’s **Oracle Factory** enhances this flexibility, enabling market deployers to choose from pre-built oracle types or deploy their own custom oracles.

### Pre-Built Oracles

1. **Chainlink Oracle**
   * Relies on Chainlink’s decentralized oracle network for accurate and reliable price feeds.
   * Dahlia uses a **maximum delay check** to ensure the data remains fresh and hasn’t been delayed beyond an acceptable threshold.
2. **Pyth Oracle**
   * Works with [Pyth Network](https://www.pyth.network/price-feeds) price feeds.
3. **Dual Oracle (Chainlink with Uniswap Fallback)**
   * The **Chainlink Oracle** serves as the primary price feed.
   * If the Chainlink Oracle returns `badData` — indicating stale or invalid pricing — the system falls back to the **Uniswap V3 TWAP Oracle** as a secondary source.
   * This fallback mechanism ensures continued price reliability and system safety while minimizing exposure to oracle failures.

The Oracle Factory allows anyone to deploy a new oracle using one of the pre-built oracle types. For further customization, developers can implement their own oracles, provided they:

* Adhere to the IDahliaOracle interface.
* Include a properly defined `getPrice()` function.

### Oracle Malfunction

If an oracle that implements the **delay sanity check** fails (e.g., returns `badData`), Dahlia activates safeguards to protect users.

When an oracle malfunction occurs:

* Actions requiring fresh price data, such as liquidations, borrowing, or withdrawing collateral, are **halted**.
* The **Oracle Stalled Mode**, detailed on the [Market Modes page](https://docs.dahlia.xyz/key-concepts/market-modes.md#oracle-stalled-mode), outlines the resolution process. This includes a `REPAY_PERIOD` during which borrowers can repay debts and reclaim collateral, ensuring fair liquidity distribution even without a functioning price feed.
