# 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](/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.


---

# Agent Instructions: 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:

```
GET https://docs.dahlia.xyz/key-concepts/oracles.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
