Percolator Rust SDK
A high-performance, type-safe Rust SDK for building on top of Percolator — the formally verified risk engine for perpetual DEXs on Solana.
Overview
Percolator handles the core "math" of a perpetual exchange: margin requirements, funding accruals, liquidations, and PnL socialization.
This SDK allows developers to build:
- Wrapper Programs: Call into the Percolator engine using CPI.
- Trading Bots: Execute trades and manage positions via RPC.
- Keepers: Run maintenance cranks to keep the system healthy.
- Frontends: Fetch and decode complex engine state with zero-overhead casting.
Installation
Add this to your Cargo.toml:
[]
= { = "../percolator-sdk" }
= "1.18"
= "1.18"
Quick Start
1. Initialize the Client
use ;
let rpc_url = "https://api.mainnet-beta.solana.com";
let program_id = from_str?;
let engine_state = from_str?;
let client = new;
2. Fetch Protocol State
let engine = client.get_engine_state?;
println!;
println!;
// Fetch a specific user's metrics
if let Some = client.get_account?
3. Build and Send Instructions
use Keypair;
let payer = from_bytes?;
let tx_sig = client.send_deposit?;
println!;
Architecture
Percolator is designed as a no_std logic library. The SDK interacts with a Wrapper Program on-chain which forwards commands to the engine after validating signatures and oracle inputs.
Instruction Layout
The SDK follows the standard Percolator wire format (Borsh-compatible):
0x00: Deposit0x01: Withdraw0x02: ExecuteTrade0x03: KeeperCrank
High-Performance Decoding
Unlike many Solana SDKs that rely on heavy serialization, the Percolator Rust SDK uses raw memory casting for #[repr(C)] engine state. This provides instantaneous decoding of the 4096-account slab, essential for high-frequency trading bots and real-time dashboards.
License
Apache-2.0