# Price Oracle

The Price Oracle is a smart contract based on Uniswap’s TWAP (Time Weighted Average Price). It has been designed with attention to simplicity and gas costs. While numerous alternative price oracle solutions are available, this TWAP solution allows the platform to remain highly automated and permissionless.

Anyone can create a new Lending Pool containing an arbitrary combination of assets, so traditional oracles that require manual set-up of new pairs won't work. The best way to guarantee support for all pairs on Uniswap and similar AMMs is to draw the prices from Uniswap itself.

For each LP token pair, Uniswap V2 stores the cumulative price that is the sum of the spot price at each second in the history of the contract. By sampling the cumulative price at two points in time it is possible to calculate the TWAP between those two points by dividing the difference of the accumulators by the time elapsed.

The Price Oracle uses a minimum period of 30 minutes to calculate the TWAP. This prevents accidental liquidation due to high market volatility or attempts of market manipulation through flash loans. The TWAP protects borrowers. Their position won't be liquidated unless the price exits the liquidation boundaries for at least 30 minutes.


---

# 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.impermax.finance/protocol/price-oracle.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.
