Skip to content

hoddukzoa12/stablerail

Repository files navigation

StableRail

StableRail: Orbital AMM on Solana

Paradigm's Orbital AMM — multi-asset stablecoin pool with concentrated liquidity & institutional settlement

Paper · Solana · Anchor · StableHacks 2026


What is Orbital?

Orbital is a next-generation multi-asset stablecoin AMM designed by Paradigm. It combines the best of Curve (multi-asset pools) and Uniswap V3 (concentrated liquidity) while adding a novel depeg isolation mechanism.

This repository is the first Solana-native implementation of the Orbital AMM, extended with a permissioned institutional settlement layer for regulated entities.

Key Innovations

Feature Description
Sphere Invariant ||r - x||² = r² — geometric invariant enabling N-asset pools on a hypersphere
Nested Ticks Spherical cap-based concentrated liquidity with per-tick reserves
Depeg Isolation When an asset depegs, its tick flips to Boundary — isolating risk from other LPs
Trade Segmentation Multi-tick swap execution with boundary detection and automatic tick crossing
Institutional Settlement Policy engine, allowlists, daily volume limits, and on-chain audit trails
KYC/AML Compliance On-chain KYC registry, risk scoring, jurisdiction filtering, FATF Travel Rule

Architecture

Single Anchor program with 4 bounded contexts as Rust modules:

orbital/
├── math/               # Core math engine
│   ├── sphere.rs       # Sphere invariant, price, equal-price point
│   ├── torus.rs        # Tick crossing detection, delta-to-boundary
│   ├── tick.rs         # k bounds, x_min/x_max, capital efficiency
│   ├── newton.rs       # Analytical swap solver (quadratic)
│   ├── fixed_point.rs  # Q64.64 fixed-point arithmetic (i128)
│   └── reserve_state.rs # O(1) invariant verification
│
├── domain/             # Business logic
│   ├── core/           # Pool operations, swap math
│   ├── liquidity/      # LP position management
│   ├── settlement/     # Institutional settlement orchestration
│   └── policy/         # Access control, compliance
│
├── instructions/       # On-chain instruction handlers
│   ├── initialize_pool     # Create N-asset pool with sphere invariant
│   ├── execute_swap        # Multi-segment swap with tick crossing
│   ├── create_tick         # Deploy concentrated liquidity tick
│   ├── add_liquidity       # Deposit to full-range or tick position
│   ├── remove_liquidity    # Withdraw with boundary-aware logic
│   ├── create_policy       # Define settlement policy
│   ├── update_policy       # Modify policy parameters
│   ├── manage_allowlist    # Add/remove institutional participants
│   ├── manage_kyc_entry    # KYC/KYT/AML registry per member
│   ├── execute_settlement  # Policy-checked institutional swap
│   └── close_pool          # Authority-only pool shutdown
│
├── state/              # Account definitions (PDA)
│   ├── pool, position, tick
│   ├── policy, allowlist, kyc_entry
│   └── settlement, audit_entry
│
├── errors.rs           # Program error codes
└── events.rs           # CPI event definitions

Math Reference

Based on the Paradigm Orbital paper:

Formula Description Implementation
Σ(r - xᵢ)² = r² Sphere invariant sphere.rs
(r - xⱼ) / (r - xᵢ) Marginal price sphere.rs
q = r(1 - 1/√n) Equal price point sphere.rs
α = Σxᵢ / √n Alpha (torus coordinate) torus.rs
k_min = r(√n - 1) Minimum tick bound tick.rs
k_max = r(n-1) / √n Maximum tick bound tick.rs
D = √(k²n - n((n-1)r - k√n)²) Tick discriminant tick.rs
x_min = (k√n - D) / n Lower reserve bound tick.rs
x_max = min(r, (k√n + D) / n) Upper reserve bound tick.rs
s(α) = √(r² - (α - r√n)²) Boundary sphere radius torus.rs
d_out = -b + √(b² + 2ad - d²) Analytical swap output newton.rs

Precision: Q64.64 fixed-point (i128 backing, 64 fractional bits) for all on-chain math.


Frontend

Next.js 16 app with real-time Solana devnet integration:

Page Features
Swap Token selection, real-time quote with tick-aware calculator, slippage settings
Dashboard Pool overview, reserve chart, LP positions, tick selector for concentrated liquidity
Settlement Policy-compliant institutional swap form, Travel Rule data input, compliance preview
Faucet Devnet SPL token faucet (USDC, USDT, PYUSD)
Admin Policy management (KYC toggle, risk score, Travel Rule threshold), KYC registry, allowlist

Getting Started

Prerequisites

Build & Test

# Install dependencies
npm install

# Build Anchor program
npm run anchor-build

# Run on-chain tests
npm run anchor-test

# Start frontend dev server
npm run dev

Deploy to Devnet

# Deploy program
npm run deploy:devnet

# Bootstrap pool + ticks with demo liquidity
npm run bootstrap:devnet

Program ID

BZDXfJTBpH9ZMo2dz57BFKGNw4FYFCDr1KaUUkFtfRVD

Demo Configuration (Devnet)

3-asset pool: USDC · USDT · PYUSD

Parameter Value
Pool TVL $150M (demo tokens)
Fee 1 bps (0.01%)
Assets 3 (n = 3)
Ticks 5 concentrated ticks (3.5× – 18× concentration)
Tick TVL $49M/asset across ticks

Implementation Status

Comprehensive analysis against the Paradigm Orbital paper:

Paper Concept Status Notes
Sphere invariant ✅ Complete Both O(n) and O(1) verification paths
Multi-asset pools (n ≤ 8) ✅ Complete Parameterized n with Q64.64 precision
Price formula ✅ Complete Marginal price, equal-price point
Tick math (k bounds, x_min/x_max) ✅ Complete All formulas verified against paper
Trade segmentation loop ✅ Complete While loop with boundary detection and tick flip
Analytical swap solver ✅ Complete Closed-form quadratic (CU-optimized)
Depeg isolation (tick flip) ✅ Complete Interior → Boundary status transition
Torus tick-crossing detection ⚠️ Partial Alpha-based detection works; full torus consolidation deferred
Tick consolidation (r_c = Σrᵢ) ⚠️ Planned Individual tick tracking, no aggregation
Virtual reserve amplification ⚠️ Planned x_min computed but not used in swap math (#36)
Per-tick fee distribution ⚠️ Planned Fees tracked globally, no per-tick LP harvest
KYC/KYT/AML compliance ✅ Complete On-chain KYC registry, risk scoring, jurisdiction filter, Travel Rule

Note: The MVP prioritizes correctness of the sphere invariant, trade segmentation, and institutional compliance. Virtual reserve amplification (the mechanism that converts concentrated liquidity into reduced slippage) is tracked in issue #59. Per-tick fee distribution and LP fee claim are post-MVP (#48).


Project Structure

stablerail/
├── anchor/                 # Solana program (Rust/Anchor)
│   ├── programs/orbital/   # Main program source
│   └── Anchor.toml         # Anchor configuration
│
├── app/                    # Next.js frontend
│   ├── components/         # React components (swap, dashboard, settlement)
│   ├── hooks/              # Custom hooks (usePool, useSwapQuote, usePoolTicks, useKycEntries, useExecuteSettlement)
│   └── lib/                # Math library, config, deserializers
│
├── scripts/                # Deployment & bootstrap scripts
│   ├── deploy-devnet.sh    # Program deployment
│   ├── bootstrap-pool.ts   # Pool + tick + liquidity setup
│   └── create-demo-ticks.ts # Demo tick creation
│
└── docs/                   # Documentation
    ├── Orbital_Math_Reference.md
    ├── Orbital_DDD_Architecture.md
    ├── Orbital_Settlement_Protocol_PRD_v2.1.md
    └── DESIGN_SYSTEM.md

Tech Stack

Layer Technology
Smart Contract Rust, Anchor 0.31.1
Math Engine Custom Q64.64 fixed-point (i128)
Frontend Next.js 16, React 19, TypeScript
Styling Tailwind CSS 4
Charts Recharts
Wallet @solana/kit, Phantom
Network Solana Devnet

Roadmap

Remaining for Hackathon Submission

Issue Title Priority
#25 DoraHacks submission and final cleanup P0
#23 Demo video production (3-min format) P0
#24 README and project documentation P0
#21 E2E integration testing P1

Post-MVP

Issue Title Description
#59 Virtual reserve amplification Use x_min from concentrated ticks to amplify swap math, reducing slippage
#48 LP fee claim mechanism Per-tick fee distribution and claim_fees instruction
#47 close_pool guard fix Seed liquidity permanently locks pool closure
#43 i256 precision migration Upgrade from Q64.64 (i128) to unlimited precision
#42 Decimal normalization Production-scale deposit handling across different token decimals
#36 Depeg rebalance protection Prevent fee-free liquidity extraction during depeg events

Contributing

This project was built for StableHacks 2026. Contributions, issues, and discussions are welcome.


References


License

AGPL-3.0

About

Paradigm's Orbital AMM on Solana — multi-asset stablecoin pool with concentrated liquidity, institutional settlement, and KYC/AML compliance. Built for StableHacks 2026.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages