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

# Oracle

The oracle is MegaTAO's pricing engine. It provides real-time Alpha token prices to the protocol by reading directly from on-chain data, with no reliance on off-chain price feeds.

## How pricing works

Each Bittensor subnet has an Alpha token that trades in an on-chain liquidity pool against TAO. These pools hold reserves of both TAO and the Alpha token. The ratio of these reserves determines the token's price.

MegaTAO's price oracle reads these reserves through the **Alpha precompile contract** on Bittensor EVM. The precompile is a native contract built into the chain itself, giving the oracle a direct source of truth for pricing from the Alpha pools.

The price derivation:

1. The oracle calls `get_alpha_price(netUid)` for a given subnet
2. The precompile returns the current pool reserves (TAO and Alpha token amounts)
3. The price is calculated from the TAO/Alpha ratio in the pool
4. This price is used for position entry, exit, P\&L calculation, and liquidation checks

Because the precompile is part of the Bittensor EVM itself, the oracle accesses pool state at the block level. There is no delay, no relay, and no intermediary. The price you see is the price on-chain at that moment.

## Why on-chain pricing matters

Most derivatives protocols rely on external oracle networks (like Chainlink) to relay off-chain exchange prices on-chain. This introduces latency, trust assumptions, and potential manipulation vectors.

MegaTAO takes a different approach:

* **No off-chain feeds.** Prices come directly from on-chain pool reserves via the precompile. There is no external data provider to trust or wait for.
* **No relay delay.** The oracle reads pool state in the same block as the trade. Prices are always current.
* **Transparent and verifiable.** Anyone can independently verify prices by reading the same pool reserves on-chain.
* **Manipulation resistant.** Manipulating prices would require moving actual liquidity in the Alpha token pools, which has a real capital cost.

## Price validation

The oracle includes safeguards to reject invalid price data:

* Zero or negative prices are rejected
* Price impact is calculated dynamically based on position size relative to pool liquidity
* The protocol enforces a maximum slippage parameter on each trade, reverting the transaction if actual execution price deviates too far from the oracle price

## Role in the protocol

Oracle prices feed into every part of the trading system:

| Function           | How oracle price is used                                     |
| ------------------ | ------------------------------------------------------------ |
| Opening a position | Determines entry price and notional value                    |
| Closing a position | Determines exit price and realized P\&L                      |
| Margin ratio       | Calculates unrealized P\&L against current price             |
| Liquidation        | Triggers when margin ratio falls below maintenance threshold |
| Funding rates      | Combined with open interest to determine funding payments    |


---

# 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.megatao.com/core/oracle.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.
