Skip to content

xiaohkk/Precipitator

 
 

Repository files navigation

Precipitator

Solana's first leveraged prediction market protocol.

Built on Percolator by Anatoly Yakovenko -- a formally verified risk engine for perpetual futures. 152 projects forked it and built perps exchanges. We forked it and built prediction markets. The first mover in a direction nobody else went.

Status: Devnet-ready. Core protocol, matcher, and frontend are functional on Solana devnet. Next stage is mainnet deployment and audit.

Browse markets and filter by category


How to Use

  1. Connect your wallet -- Click the wallet button in the top right. Any Solana wallet (Phantom, Solflare, etc.) works. The app runs on devnet, so no real funds are needed.

  2. Get devnet SOL -- Click the "Faucet" button next to your wallet to receive 2 SOL on devnet for gas fees.

  3. Browse markets -- The Markets page shows all active prediction markets. Filter by category (Crypto, Politics, Sports, Culture, Other), sort by volume or deadline, or search by keyword.

  4. Place a trade -- Click any market card to open the trading view. You'll see a live probability chart, order book, and trade panel. Choose Buy YES or Buy NO, select your leverage (1x-5x), set your price and size, and submit.

  5. Track your positions -- The Portfolio page shows your open positions, P&L, leverage, and liquidation prices.

  6. Create a market -- Click "+ Create Market" to ask any yes/no question. Set a deadline, choose a resolution method (manual, Pyth oracle, multi-sig, or optimistic), and deposit initial liquidity.


The Idea

Percolator tracks long and short positions. In perps, "long" means you bet the price goes up. But what if "long" means YES? And "short" means NO?

The oracle price becomes probability. The margin system becomes leverage for predictions. The resolution mechanism becomes binary outcome settlement.

The math is identical. The product is completely different.


What We Built

Component Description
Engine (engine/) Toly's Percolator risk engine (4,796 lines of verified Rust) with our resolve_binary() extension for prediction market settlement
Solana Program (programs/precipitator/) 16-instruction Anchor program: trade, resolve, claim, liquidate, multi-sig resolution, optimistic resolution
Matcher (packages/matcher/) Off-chain order book + WebSocket server for real-time order matching and trade submission
Frontend (packages/frontend/) Next.js 14 trading terminal with live charts, leverage controls, order book visualization
Polymarket Mirror (packages/polymarket-mirror/) Mirrors Polymarket event catalog onto Solana via Gamma API
Resolver (packages/resolver/) Automated market resolution via Pyth oracle price feeds

Features

  • Leveraged prediction markets -- 1x to 5x leverage on any prediction. Buy YES at 34c with 5x leverage, win $100 if correct. Return: 1,371%.
  • Polymarket catalog on Solana -- Sports, politics, crypto, culture. Hundreds of events mirrored with real probabilities.
  • Permissionless market creation -- Ask any yes/no question, set a deadline, deposit liquidity. 0.1 SOL creation fee.
  • 4 resolution methods -- Admin manual, Pyth oracle automated, multi-sig panel vote, optimistic with challenge period.
  • Formally verified -- Every arithmetic path in the risk engine proven correct by the Kani model checker. No unsafe code.
  • Public leaderboard -- Top traders ranked by P&L across all markets.

Architecture

                    +------------------+
                    |   Next.js 14     |
                    |   Frontend       |
                    +--------+---------+
                             |
                    REST + WebSocket
                             |
                    +--------+---------+
                    |   Matcher        |
                    |   (off-chain     |
                    |    order book)   |
                    +--------+---------+
                             |
                    Anchor CPI
                             |
                    +--------+---------+
                    |   Precipitator   |
                    |   Solana Program |
                    +--------+---------+
                             |
                    +--------+---------+
                    |   Percolator     |
                    |   Risk Engine    |
                    |   (Kani-verified)|
                    +------------------+

Quick Start

Prerequisites

  • Rust + Cargo
  • Node.js 18+
  • Solana CLI + Anchor
  • Kani verifier (for proofs)

Run the Frontend

cd packages/frontend
npm install
npm run dev
# http://localhost:3000

Run the Matcher

cd packages/matcher
npm install
npx ts-node src/index.ts
# REST API on :3030, WebSocket on :8080

Run Kani Proofs

cd engine
cargo install --locked kani-verifier
cargo kani setup
cargo kani

Run Tests

# Engine unit tests
cd engine && cargo test

# Anchor program tests
anchor test

The Engine: Percolator

The risk engine is Toly's Percolator -- 4,796 lines of formally verified Rust that solves two fairness problems in leveraged trading:

  1. Exit fairness (H) -- When the vault is stressed, a single global haircut ratio determines how much profit is real. No queue priority, no first-come advantage.

  2. Overhang clearing (A/K) -- When positions go bankrupt, two global coefficients distribute the deficit across the opposing side. No account is singled out. O(1) per account.

We extended it with:

  • resolve_binary() for YES/NO outcome settlement
  • Bounded-loss margin parameters tuned for prediction markets (probability 0-100 range)
  • Warmup period as oracle-manipulation defense

Every arithmetic operation is proven correct by the Kani model checker. 243 tests passing (167 original + 24 prediction market + 52 integration). Zero failures.


Leverage Math

On Polymarket, you put up $34 to buy YES at 34c. If it resolves YES, you get $100.

On Precipitator, at 5x leverage, you put up $6.80 for the same $100 payout:

Leverage You Pay You Win Return
1x (Polymarket) $34.00 $100 194%
2x $17.00 $100 488%
3x $11.33 $100 782%
5x $6.80 $100 1,371%

Higher leverage means higher liquidation risk. The Percolator engine handles all margin math, liquidations, and deficit socialization with formal guarantees.


Project Structure

Precipitator/
  engine/              # Percolator risk engine (Rust, Kani-verified)
  programs/
    precipitator/      # Anchor Solana program (16 instructions)
  packages/
    frontend/          # Next.js 14 trading terminal
    matcher/           # Off-chain order book + WebSocket
    polymarket-mirror/ # Polymarket event catalog mirror
    resolver/          # Pyth oracle auto-resolution
  config/              # Market configs, mirror lists
  scripts/             # Demo and deployment scripts

Credits

  • Percolator by Anatoly Yakovenko -- the formally verified risk engine that makes this possible
  • Kani model checker for Rust verification
  • Polymarket for the event catalog
  • Pyth Network for oracle price feeds

License

Apache 2.0 -- same as the original Percolator.

Fork it, audit it, build on it.

About

Forked from Toly's Percolator. Formally verified. Leveraged predictions on Solana. Perpolator was built for this and nobody else saw it. CA: 8f1nLMD3muMahxA66WvMCU5edQCAExyEi6bhp5e7pump

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Rust 79.6%
  • TypeScript 18.1%
  • HTML 1.4%
  • Other 0.9%