# MegaTAO Core

MegaTAO is a perpetual futures DEX for Bittensor subnet Alpha tokens. You can deposit TAO as collateral and take leveraged positions on Alpha tokens.

## What is MegaTAO?

MegaTAO is a perpetual futures DEX on Bittensor EVM. You deposit TAO as collateral and take leveraged long or short positions on Alpha token prices. All profit and loss is settled in TAO.

Key properties:

* **Synthetic positions:** Positions track Alpha token price movements through perpetual contracts. All settlement is in TAO.
* **Perpetual futures:** Contracts never expire. Hold a position as long as you want, subject to funding costs and margin requirements.
* **TAO collateral:** All margin, fees, and settlement are in native TAO. A single-currency system simplifies operations and concentrates liquidity.
* **Hybrid liquidity:** Orders are first matched against the order book. The protocol vault fills any remaining size, providing instant execution.
* **On-chain oracle pricing:** Alpha token prices are derived directly from on-chain pool reserves, with no off-chain price feeds.

## How it works

### Vault model

Instead of matching buyers and sellers through an order book, MegaTAO uses a vault model. The protocol vault acts as the counterparty to every trade:

* **Instant execution:** Orders fill immediately. No waiting for a matching counterparty.
* **Guaranteed liquidity:** The vault is always available to take the other side of your trade.
* **Simplified trading:** One counterparty system eliminates complex order book interactions.

When order book liquidity is available, the protocol matches against it first. The vault fills any remaining size.

### Trading flow

1. Fund your wallet with TAO
2. Deposit TAO as margin
3. Open a position (long or short) on an Alpha token with your chosen leverage (up to 3x)
4. The protocol fills your order instantly via vault or order book matching
5. Funding payments accrue every 8 hours based on market imbalance between longs and shorts
6. Interest fees accrue based on vault utilization (charged to both sides)
7. Close the position when ready and realize your P\&L in TAO

### Margin and liquidation

The protocol continuously monitors your margin ratio. If it falls below the maintenance margin (currently 10%), the position is automatically liquidated to prevent negative balances and protect the system.

## Architecture

{% @mermaid/diagram content="graph LR
subgraph BP\["Bittensor Protocol"]
POOLS\[Alpha Token Pools] -->|reserve data| ORACLE

```
    subgraph EVM["Bittensor EVM"]
        ORACLE[Price Oracle] -->|price feed| FUTURES[Futures Contract]
        VAULT[Protocol Vault] <-->|liquidity| FUTURES
    end
end

KEEPER[Keeper] -->|liquidate| FUTURES
USER[Trader] -->|deposit / trade| FUTURES
FUTURES -->|P&L settlement| USER[Trader]
```

" %}

| Component        | Role                                                        |
| ---------------- | ----------------------------------------------------------- |
| Futures Contract | Core trading logic: positions, margin, orders, liquidations |
| Price Oracle     | Reads Alpha token prices from on-chain pool reserves        |
| Protocol Vault   | Provides liquidity and acts as counterparty                 |
| Keeper           | Monitors and executes liquidations of unhealthy positions   |

All contracts run on Bittensor EVM (Chain ID: 964) and are upgradeable to support future improvements without disrupting existing positions.

## Why Bittensor EVM?

MegaTAO is built on Bittensor's native EVM chain. This gives the protocol direct access to the Bittensor ecosystem:

* **Native TAO integration:** TAO is the chain's native currency, so collateral deposits and settlements require no token wrapping or bridging.
* **Alpha token precompile:** Bittensor EVM includes a precompile contract that exposes Alpha token pool reserves at the chain level. The oracle reads prices directly from this precompile, giving MegaTAO a trustless source of truth for pricing without relying on external oracle networks.
* **EVM compatibility:** Developers and traders can use standard Ethereum tooling (MetaMask, Viem, ethers.js) while operating within the Bittensor ecosystem.

## In this section

* [Alpha Tokens](/core/alpha-tokens.md): Supported markets and how Alpha tokens work
* [Oracle](/core/oracle.md): On-chain pricing via the Alpha precompile
* [Vault](/core/vault.md): How the protocol vault provides liquidity
* [Keepers](/core/keepers.md): Automated liquidation and protocol maintenance
* [Funding and Interest](/core/funding-and-interest.md): How the protocol stays balanced


---

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