Skip to content

acegikmoo/perp-dex

Repository files navigation

perp-dex

A non-custodial perpetual futures DEX on Solana, built with Anchor. Supports hybrid order matching, trades fill against an on-chain AMM or a live order book, whichever offers a better price.


Fill routing- when a taker order arrives, the engine:

  1. Collects book-side makers sorted by best price
  2. For each maker that beats the AMM, routes to order matching first
  3. Falls back to the AMM for any remaining quantity

On-chain accounts

Account Seeds Description
State drift_state Global config
PerpMarket perp_market Per-market params + embedded AMM state
perp_market_vault perp_market_vault SPL token vault for a market
User user / <authority> / <account_id> Orders array (max 8) + positions (max 16)
Oracle oracle / <market_index> Custom price feed with staleness & deviation checks

Getting started

Prerequisites

Tool Version
Rust 1.89.0 (see rust-toolchain.toml)
Solana CLI ≥ 2.x
Anchor CLI 0.32.1
Node.js ≥ 18
Yarn any

Install dependencies

yarn install

Build

anchor build

Run tests (local validator)

anchor test

Deploy via Surfpool (localnet)

# Start a local validator
surfpool start

# Deploy
surfpool run deployment

See runbooks/ for devnet and mainnet deployment.


AMM

The AMM uses a constant-product curve (k = base × quote). Price impact is computed off-chain by the filler and passed as limit_price.

bid_price = quote_reserve / base_reserve
ask_price = base_reserve / quote_reserve

weighted_price = (oracle_price × oracle_weight + amm_price × (10000 − oracle_weight)) / 10000

oracle_price_weight (0–10000 bps) controls how strongly the oracle anchors the displayed price.


License

ISC

About

a non-custodial perpetual futures DEX on Solana

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors