Skip to main content
Repository: purpletrade/percolator-match · License: Apache 2.0 · Language: Rust

What It Does

percolator-match is a Solana program that provides passive market making for Percolator markets. When a user submits a TradeCpi instruction, the Percolator program calls this matcher via CPI to determine the execution price and size. The matcher quotes prices around the oracle with a configurable spread. Deployed on mainnet at MTCPqs6RWWUPMHhvZnnB6BLAXS86TDpTaxQW7Pa3aDh.

How It Works

The matcher writes its response into a context account that Percolator reads after the CPI returns.

Two Matching Modes

Passive Mode (kind=0)

Fixed spread around the oracle price. Simple and predictable:
bid = floor(oracle_price * 9950 / 10000)   // -50bps
ask = ceil(oracle_price * 10050 / 10000)    // +50bps
All integer math, no floating point. Rounding is always passive-favorable (bid rounds down, ask rounds up).

vAMM Mode (kind=1)

Dynamic pricing with configurable parameters:
ParameterDescriptionExample
trading_fee_bpsFee on every fill5 (0.05%)
base_spread_bpsMinimum spread10 (0.10%)
impact_k_bpsPrice impact at full utilization100 (1%)
max_total_bpsCap on total cost500 (5%)
liquidity_notional_e6Quoting depth for impact calculation10B
max_fill_absMaximum fill per tradeu128::MAX
max_inventory_absInventory limit (0 = unlimited)0
Price impact increases with trade size relative to liquidity_notional_e6, creating a virtual AMM curve.

Context Account Layout

Each LP gets a 320-byte context account owned by the matcher program:
OffsetSizeFieldDescription
064Return dataABI response written on each CPI call
648Magic0x504552434d415443 (“PERCMATC”)
724Version3
761Kind0=Passive, 1=vAMM
8032LP PDAStored on init, verified on every call
1124Trading fee bps
(config fields)

Security

  • LP PDA binding — The matcher verifies the CPI signer matches the stored LP PDA on every call. Prevents unauthorized programs from using the matcher.
  • One-time init — Context can only be initialized once (no rebinding).
  • Program ownership — Context account must be owned by the matcher program.
  • Atomic setup required — Context creation + LP initialization must be in a single transaction to prevent race conditions.

Instructions

TagInstructionDescription
0MatchCalled by Percolator via CPI. Calculates execution price/size.
1Init (legacy)Initialize context with LP PDA.
2Init vAMMInitialize context with LP PDA and full vAMM configuration.

Build

cargo-build-sbf --sbf-out-dir target/deploy -- --locked
cargo test

Verified Build

Built deterministically using solanafoundation/solana-verifiable-build:2.3.0. See the Source Verification page for the SHA-256 hash and reproduction instructions.

View Repository

Source code, context layout, vAMM implementation

Verified Build

Latest SBF build artifact with SHA-256 hash