# Overview

## Trading on Drake Exchange

Drake implements **perpetual futures contracts** (perpetual swaps) that track underlying asset prices without expiration dates. Key characteristics:

**Leverage Trading**: Open positions larger than your collateral through leverage up to 50x (configurable per position)

**Funding Payments**: Periodic payments between longs and shorts that keep perpetual prices anchored to spot prices

**Mark Price**: Oracle-based fair value used for margin calculations and liquidations (protects against manipulation)

**Borrowing Fees**: Continuous interest charged on leveraged positions that scales with vault utilization

***

## Hybrid CLOB + AMM Architecture

### Dual-Venue Liquidity Model

Drake's perpetual exchange combines two complementary liquidity sources to optimize execution quality while ensuring continuous market availability:

**Order Book (CLOB)**

A Red-Black tree-indexed structure stores limit orders with strict price-time priority. Professional market makers and active traders place resting orders at specified price levels, creating tight spreads and deep liquidity in active markets. Orders remain on the book until market conditions trigger execution or they're manually canceled.

**Dynamic AMM Vaults**

Oracle-aligned liquidity pools provide guaranteed fills without bonding curve mechanics. Instead of algorithmic pricing, vaults quote prices based on aggregated oracle feeds, ensuring external market alignment. Retail LPs can passively deposit capital into vaults, earning yield while the system taps this liquidity for executions the order book cannot fully satisfy.

***

### Intelligent Order Routing

Every market order passes through Drake's hybrid routing engine, which dynamically allocates execution across venues based on real-time market conditions:

#### Routing Decision Framework

The router evaluates six critical parameters in sequence:

1. **Vault Utilization Analysis** — Current percentage of vault capacity deployed in open positions
2. **Open Interest Imbalance** — Directional skew between long and short positions
3. **Order Size Context** — Trade size relative to 24-hour market volume
4. **Order Book Depth** — Available liquidity at current price levels
5. **Optimal Venue Split** — Calculated allocation between CLOB and AMM
6. **Atomic Cross-Venue Execution** — Simultaneous settlement across both liquidity sources

#### Hierarchical Execution Rules

The router applies decision logic in strict priority order:

**Emergency Mode** (>95% vault utilization)

Redirects all flow to order book to prevent vault depletion. AMM becomes unavailable until utilization drops below threshold.

**High Utilization Bias** (85-95% vault utilization)

Strongly favors order book execution, only tapping vaults for unfillable remainder or when book depth is insufficient.

**Balanced Routing** (<85% vault utilization)

Dynamically splits orders based on:

* Open interest imbalance correction (routes against prevailing skew to balance vault exposure)
* Size optimization (large orders get CLOB priority to minimize AMM slippage)
* Price improvement (fills best price levels from book first, remainder from vaults)

**Venue Availability Verification**

Confirms both venues are operational before routing. Falls back to single-venue execution if one source is unavailable.

**Best Execution Default**

When all parameters are neutral, router defaults to the venue offering superior pricing at that moment.

### Execution Flow

#### Standard Market Order

1. Order arrives → Router calculates optimal split
2. CLOB matching engine attempts fill against resting orders
3. If partial fill or no match → Remainder routes to AMM vault
4. Vault quotes price from oracle feed and executes instantly
5. Both fills settle atomically in single transaction

#### Large Order Optimization

* Optimal % fills against order book at tight spreads
* Remaining % settles against vault at oracle price
* Combined execution achieves better average price than either venue alone

#### Thin Market Protection

* Long-tail assets with sparse order books default to AMM-first routing
* Vaults provide predictable pricing when CLOB depth is insufficient
* Prevents failed trades in illiquid conditions

***

### System Benefits

**Price Efficiency**

CLOB market makers compete to provide tight spreads in liquid markets, while oracle-aligned vaults prevent manipulation in thin markets.

**Execution Certainty**

AMM vaults guarantee every valid order executes, eliminating failed transactions even during volatile periods or for large sizes.

**Capital Flexibility**

Professional market makers access the order book for active management, while passive retail LPs contribute to vaults without monitoring positions.

**Market Scalability**

High-volume assets leverage deep order books, while emerging markets rely on vault liquidity until natural CLOB depth develops.

**Risk Management**

Vault utilization limits and imbalance-aware routing prevent asymmetric exposure accumulation that could destabilize the AMM component.

***

## Underlying System

**Hybrid Order Router**

* Inputs: vault utilization, OI imbalance, oracle mid, and book depth.
* Venue priority: book fills first; vault backstops or shares flow.
* Output: deterministic split executed atomically.

**Orderbook**

* Per-market on-chain order book using balanced trees.
* Supports Limit, Stop, Take-Profit, OCO orders.
* Price-time priority maintained; fills loop until no cross remains.
* Queries provide real-time best bid/ask and depth.

**Oracle Aggregator**

* Sources: multiple networks; keepers update on-chain.
* Aggregation: normalize, discard stale values, compute mid.
* Consumers: AMM pricing, margin checks, liquidation triggers, funding rates.

**Vault System (ERC-4626)**

* Deposits mint dUSDC; share value tracks vault assets and unrealized PnL.
* Redemptions: two-step request → redeem with time delay.
* Locked deposits: NFT lockups with discounted entry or boosted returns.

***

### Glossary

* AMM (dynamic): Oracle-quoted vault with spreads; no impermanent loss.
* dUSDC: ERC-4626 share token for AMM strategy vaults.
* frUSDC: Funding Rate Strategy Vault token.
* OI: Open Interest.
* MR: Margin Ratio.
* OCO: One-Cancels-the-Other order.
* Venue split: Allocation of taker flow between AMM and Order Book.


---

# 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.drake.exchange/trading/overview.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.
