# Hybrid Orderbook System

Polynomial Trade features the world's first hybrid orderbook + AMM system, combining the best of both execution models.

## System Overview

### Dual Execution Paths

* **Orderbook (CLOB)**: 200ms latency, built in Rust, fully audited
* **AMM**: Oracle-based for guaranteed liquidity and zero slippage on large trades
* **Intelligent routing**: System automatically chooses the best execution path

### Execution Logic

* **Limit orders** → Orderbook (for precision and price control)
* **Market orders** → AMM (for guaranteed liquidity)
* **Large trades** → AMM (zero slippage on big positions)

## Technical Specifications

### Central Limit Order Book (CLOB)

* **Latency**: 200ms (faster than a blink)
* **Technology**: Built in Rust for maximum performance
* **Security**: Fully audited by Macro Security and Octane Security
* **Capacity**: Handles high-frequency trading like a pro

### AMM Integration

* **Oracle-based**: Uses Pyth Network for price feeds
* **Guaranteed liquidity**: Always available for market orders
* **Zero slippage**: Large trades execute without price impact
* **Dynamic pricing**: Adjusts based on market conditions

## Pyth Lazer Integration

### Performance Improvements

* **1ms price updates** (vs. 400ms+ elsewhere)
* **\~70ms end-to-end latency** vs Binance
* **Negative latency possible** at times

### Benefits

* **Eliminates toxic flow**: No more arbitrageurs exploiting stale prices
* **Tight spreads**: AMMs can run with minimal spreads
* **Low fees**: Reduced fees due to better price accuracy
* **CEX-quality execution**: DeFi transparency with centralized exchange performance

## Market Evolution

### Early Markets

* **AMM dominates**: Provides liquidity bootstrapping
* **Higher spreads**: Necessary for initial liquidity provision

### Mature Markets

* **Orderbook dominates**: More efficient price discovery
* **Tighter spreads**: Better execution for all users

### Adaptive System

* **Real-time optimization**: System adapts to market conditions
* **Automatic routing**: No user intervention required
* **Best execution**: Always delivers optimal fills

## Fast Execution Architecture

### The Speed Problem in Traditional AMMs

Traditional AMM trades are notoriously slow, taking 7-11 seconds to execute a single trade:

* **User confirms order on-chain**: \~500ms-7s
* **Chain confirmation**: 2-3s
* **Keeper execution**: 2-3s
* **Total**: Up to 11 seconds per trade

In volatile markets, this delay is an eternity for traders trying to close positions quickly.

### Polynomial's Solution: Optimized Order Flow

Polynomial's architecture cuts execution time down to 2-4 seconds - a 3-5x improvement over traditional AMMs.

#### **How It Works**

Instead of sending orders on-chain first, our optimized flow works differently:

1. **Direct Keeper Routing**: Orders go straight to the keeper
2. **Price Fetching**: Keeper fetches current market price
3. **On-chain Execution**: Keeper executes the trade on-chain
4. **Instant Confirmation**: User receives immediate confirmation

#### **Key Benefits**

* **Lightning-fast executions**: 2-4 second execution times
* **Better user experience**: No more waiting for slow confirmations
* **Reduced slippage**: Faster execution means less price movement
* **More competitive with CEXs**: Closing the gap with centralized exchanges
* **Higher capital efficiency**: Faster position management
* **Lower risk during volatile markets**: Quick exits when needed

### Future Optimizations

With upcoming optimizations like flash blocks, Polynomial could potentially reduce execution times to under 200ms - faster than some centralized exchanges.

This represents a key moment in DeFi's evolution, where fast execution - traditionally CEX's killer advantage over DEXs - is becoming a reality in decentralized trading.

## Future Enhancements

### Dynamic Routing (Coming Soon)

Market orders will intelligently split between orderbook and AMM based on:

* **Current liquidity depth**: Real-time assessment of available liquidity
* **Trade size**: Optimal routing based on position size
* **Spread analysis**: Real-time spread comparison
* **Market conditions**: Adaptive routing based on volatility

### Benefits

* **Maximum efficiency**: Optimal execution for every trade
* **Zero thinking required**: System handles all optimization
* **Better fills**: Improved execution quality across all market conditions
