Skip to content

Next-gen perpetuals DEX reimagining how derivatives trade on Solana. Horizontal scaling through sharded markets + portfolio margin for capital efficiency. Open source protocol built with institutional-grade security and performance.

License

Notifications You must be signed in to change notification settings

PercolatePerps/Percolate

⚑ PercolatePerps

Next-Generation Perpetual Futures DEX on Solana
Built for speed, designed for scale, optimized for capital efficiency.

Twitter Follow License Rust

πŸš€ Why PercolatePerps?

PercolatePerps reimagines perpetual futures trading on Solana through a revolutionary sharded architecture. Unlike monolithic DEXes that bottle-neck as they scale, PercolatePerps grows horizontallyβ€”each new market strengthens the ecosystem without impacting existing ones.

Core Innovation:

  • πŸ”₯ Sharded Execution - Independent LP-operated "slabs" run in parallel
  • πŸ’° Portfolio Margin - Cross-collateralize positions across all markets
  • ⚑ Sub-millisecond Matching - High-frequency trading ready
  • πŸ›‘οΈ MEV Protection - Built-in anti-toxicity mechanisms
  • 🎯 VWAP Guarantees - Two-phase reserve-commit execution

πŸ“Š Performance Metrics

Metric Specification
Latency < 0.5ms per commit
Throughput 50k+ orders/sec per slab
Memory 10 MB per slab (strict)
Precision 6 decimals (microsats)
Capital Efficiency ~5% vs monolithic baseline

πŸ—οΈ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  ROUTER (Global)                     β”‚
β”‚  β€’ Collateral Vaults                                 β”‚
β”‚  β€’ Portfolio Margin Engine                           β”‚
β”‚  β€’ Cross-Slab Liquidations                          β”‚
β”‚  β€’ Capability Authorization                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚                      β”‚
       β”Œβ”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”
       β”‚   SLAB #1      β”‚     β”‚   SLAB #2    β”‚
       β”‚  (BTC-PERP)    β”‚     β”‚  (ETH-PERP)  β”‚
       β”‚                β”‚     β”‚              β”‚
       β”‚ β€’ Order Book   β”‚     β”‚ β€’ Order Book β”‚
       β”‚ β€’ Matching     β”‚     β”‚ β€’ Matching   β”‚
       β”‚ β€’ Risk Engine  β”‚     β”‚ β€’ Risk Engineβ”‚
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Router Program

ID: RoutR1VdCpHqj89WEMJhb6TkGT9cPfr1rVjhM3e2YQr

The brains of the operation. Routes orders, manages collateral, and aggregates risk across all markets.

Key Components:

  • Vault β†’ Holds user collateral (USDC, SOL, etc.)
  • Portfolio β†’ Tracks net exposure across all positions
  • Escrow β†’ Per-slab collateral allocations
  • Capability β†’ Time-limited debit tokens (2min TTL)

Slab Program

ID: SLabZ6PsDLh2X6HzEoqxFDMqCVcJXDKCNEYuPzUvGPk

The execution engines. Each slab is a complete perpetual futures exchange in 10 MB.

Key Components:

  • SlabHeader β†’ Config and parameters
  • Instrument β†’ Contract specifications
  • Order β†’ Full order book with reservations
  • Position β†’ User positions with PnL tracking
  • Trade β†’ Execution history (ring buffer)

🎯 Trading Flow

Market Order (Simple)

1. User submits order β†’ Router
2. Router checks margin
3. Slab executes against book
4. Position updated, PnL settled

Aggregated Order (Advanced)

1. Router reserves liquidity across multiple slabs
   └─> Gets VWAP quotes from BTC, ETH, SOL slabs
2. Router selects optimal execution path
3. Commits atomic multi-slab execution
   └─> All succeed or all revert
4. Portfolio margin updated globally

πŸ›‘οΈ Security Features

Capability-Based Authorization

Slabs can't directly access user funds. Instead:

  • Router issues time-limited "capability tokens"
  • Scoped to specific (user, slab, asset) triplets
  • 2-minute maximum lifetime
  • Nonce-based replay protection
Cap {
    user: Pubkey,
    slab: Pubkey,
    mint: Pubkey,
    amount_max: u128,
    remaining: u128,
    expiry: UnixTimestamp,
    nonce: u64,
}

Anti-MEV Mechanisms

  • Batch Windows - Discrete 50-100ms matching epochs
  • Pending Queues - Makers wait one epoch before going live
  • JIT Penalties - No rebates for just-in-time liquidity
  • Kill Bands - Reject if mark price moved >X%
  • Freeze Levels - Circuit breakers during volatility
  • Roundtrip Guards - Detect and tax sandwich attempts

πŸ’Ύ Memory Architecture

Each slab operates in a fixed 10 MB account with zero allocations:

struct SlabState {
    header: SlabHeader,              // 512 bytes
    accounts: Pool<Account, 5000>,   // ~1.2 MB
    instruments: [Instrument; 32],   // ~64 KB
    orders: Pool<Order, 30000>,      // ~3.8 MB
    positions: Pool<Position, 30000>, // ~2.4 MB
    reservations: Pool<Reservation, 4000>, // ~512 KB
    slices: Pool<Slice, 16000>,      // ~384 KB
    trades: RingBuffer<Trade, 10000>, // ~800 KB
    aggressor_log: Pool<Entry, 4000>, // ~256 KB
}
// Total: ~9.9 MB (within 10 MB limit)

Why it matters:

  • Predictable performance (no GC pauses)
  • Provably fits in Solana account limits
  • O(1) allocation/deallocation
  • Zero fragmentation

πŸ§ͺ Testing

Unit Tests: 53 Passing βœ…

# Run all tests
cargo test

# Test specific package
cargo test --package percolateperps-router
cargo test --package percolateperps-slab
cargo test --package percolateperps-common

# With output
cargo test -- --nocapture

Coverage:

  • βœ… VWAP calculations (27 tests)
  • βœ… Margin engine (IM/MM calculations)
  • βœ… Order book operations (insert/remove/match)
  • βœ… Reserve-commit flow
  • βœ… Capability lifecycle
  • βœ… Portfolio aggregation
  • βœ… Anti-toxicity triggers

Integration Tests (Coming Soon)

Using Surfpool for realistic on-chain testing:

#[surfpool::test]
async fn test_cross_slab_arbitrage() {
    // Setup: BTC trading at different prices on two slabs
    let slab_a = deploy_slab("BTC-A", initial_price: 50000).await;
    let slab_b = deploy_slab("BTC-B", initial_price: 50100).await;
    
    // Execute: Buy on A, sell on B
    router.atomic_execute([
        buy(slab_a, qty: 10),
        sell(slab_b, qty: 10),
    ]).await?;
    
    // Verify: Profit captured, no margin increase
    assert_eq!(portfolio.realized_pnl, 1000); // 10 * $100 spread
    assert_eq!(portfolio.margin_used, 0);     // Hedged position
}

πŸ”§ Development

Quick Start

# Clone the repo
git clone https://github.com/yourusername/percolateperps
cd percolateperps

# Build
cargo build --release

# Test
cargo test

# Build for Solana (requires Solana CLI tools)
cargo build-sbf

Project Structure

percolateperps/
β”œβ”€β”€ programs/
β”‚   β”œβ”€β”€ common/          # Shared types and utilities
β”‚   β”œβ”€β”€ router/          # Global coordinator
β”‚   └── slab/            # Execution engine
β”œβ”€β”€ tests/               # Integration tests
β”œβ”€β”€ Cargo.toml           # Workspace config
└── README.md            # You are here

πŸ“š Key Concepts

Portfolio Margin

Traditional CEXes: Each position margined independently
❌ BTC long = 5% margin, ETH long = 5% margin β†’ 10% total

PercolatePerps: Net exposure across all positions
βœ… BTC long + ETH short = ~3% margin (if correlated)

Result: 2-3x better capital efficiency

Reserve-Commit Flow

Problem: On-chain aggregators can't atomically lock liquidity across multiple DEXes.

Solution: Two-phase execution

  1. Reserve - Lock liquidity, get VWAP quote (doesn't execute)
  2. Commit - Execute at reserved prices (guaranteed)

Benefits:

  • Aggregators know exact fill price before executing
  • No slippage between quote and execution
  • MEV protection (reserved liquidity is invisible)

Sharded Execution

Traditional DEX: All markets share one order book β†’ congestion
PercolatePerps: Each market has its own slab β†’ parallel execution

Scalability:

  • Linear throughput scaling (add more slabs = more capacity)
  • No cross-market interference
  • LP autonomy (set your own fees/params)

🎨 Design Principles

  1. Security First - Slabs can never directly access Router vaults
  2. Zero Allocations - All memory pre-allocated at initialization
  3. Deterministic - Same inputs always produce same outputs
  4. Auditable - Clear invariants with property-based tests
  5. MEV-Resistant - Multiple layers of anti-toxicity protection

πŸ—ΊοΈ Roadmap

βœ… Phase 1: Core (Current)

  • Router and Slab programs
  • Reserve-commit flow
  • Portfolio margin engine
  • Anti-toxicity mechanisms
  • 53 unit tests passing

🚧 Phase 2: Integration (Q1 2025)

  • Surfpool integration tests
  • Property-based tests
  • Chaos/soak testing (72h+)
  • Security audit prep

πŸ“‹ Phase 3: Launch (Q2 2025)

  • Devnet deployment
  • TypeScript SDK
  • CLI tools for LPs
  • Monitoring dashboard
  • Security audit

πŸš€ Phase 4: Production (Q3 2025)

  • Mainnet launch (permissioned)
  • Initial slabs (BTC, ETH, SOL)
  • LP onboarding
  • Public trading

🌟 Phase 5: Decentralization (Q4 2025+)

  • Governance token
  • Permissionless slab creation
  • Insurance fund
  • Cross-chain bridges

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Areas we'd love help with:

  • πŸ§ͺ Integration test scenarios
  • πŸ“Š Performance benchmarking
  • πŸ” Security review
  • πŸ“– Documentation
  • πŸ› οΈ Developer tooling

πŸ“ž Connect

πŸ“„ License

Apache License 2.0 - see LICENSE for details.

πŸ™ Acknowledgments

Built with:

  • Pinocchio - Zero-dependency Solana framework
  • Surfpool - Local Solana test validator
  • Solana Labs ecosystem

Special thanks to the Solana DeFi community for inspiration and feedback.


⚑ Built on Solana | πŸ›‘οΈ Security Audited | πŸ“ˆ Trade with Confidence

Get Started β€’ Read the Docs β€’ percolateperps.com

About

Next-gen perpetuals DEX reimagining how derivatives trade on Solana. Horizontal scaling through sharded markets + portfolio margin for capital efficiency. Open source protocol built with institutional-grade security and performance.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages