Solana-native perps and spot exchange combining a vAMM, a JIT (Just-In-Time) auction maker layer, and a DLOB orderbook. The TypeScript SDK exposes `DriftClient` and a Rust SDK is available for low-latency makers.
- 01Solana perps frontends
- 02JIT market making
- 03cross-margin trading bots
- 04spot + perps in one program
- 05high-throughput orderflow
- pnpm add @drift-labs/sdk @solana/web3.js @coral-xyz/anchor
| Variable | Scope | Description |
|---|---|---|
| NEXT_PUBLIC_SOLANA_RPC_URL | Client | Solana RPC URL (Helius / Triton / Quicknode recommended for production). |
| DRIFT_ENV | Client | `mainnet-beta` or `devnet` — passed to `initialize()` to pick the correct program ID and markets. |
| DRIFT_KEEPER_PRIVATE_KEY | Server | Optional: base58 keypair used by JIT maker / liquidator / settlement bots. Server-only. |
Use the Drift TypeScript SDK to interact with the on-chain program. Construct `new DriftClient({ connection, wallet, env: 'mainnet-beta' })`, call `subscribe()`, then place orders via `placePerpOrder({ orderType: OrderType.MARKET, marketIndex, direction, baseAssetAmount, auctionDuration, auctionStartPrice, auctionEndPrice })`. Drift program ID on mainnet is `dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH` and the JIT-proxy program is `J1TnP8zvVxbtF5KFp5xRmWuvG9McnhzmBd9XGfCyuxFP`. Read live book state from the DLOB HTTP endpoint at `https://dlob.drift.trade` or via the SDK's `DLOBClient`.
- ⚑Market orders go through a JIT auction first — set `auctionDuration` (slots) and start/end prices correctly. A zero-duration auction skips JIT and goes straight to vAMM/DLOB, paying worse fills.
- ⚑Oracle source matters: Drift uses Pyth and Switchboard depending on the market. Stale-oracle conditions pause taking; check `OracleGuardRails` before placing orders.
- ⚑Funding rates accrue per slot but are settled lazily — `settlePnL` and `settleFunding` may need to be cranked before withdrawing to avoid surprising balances.
- ⚑Liquidations are progressive (insurance fund + socialized loss tiers). A position can be partially liquidated while still margin-deficient; UIs must refresh `userAccount` post-tx, not assume full close.
- ⚑Devnet and mainnet have different program IDs and market indices — `initialize()` config must match the cluster you connect to or all account derivations will fail silently.
- ⚑Rate-limit aware: WebSocket subscriptions to `userAccount`/`perpMarketAccount` create one Solana account-listener each; subscribe only to the markets you actually display.