Skip to main content

Overview

The PerpMarket struct represents a Drift perpetual futures market account. It contains the market’s AMM (Automated Market Maker) configuration, funding rates, PnL pools, risk parameters, and all operational state for the perpetual market.

Account Structure

Core Fields

pubkey
Pubkey
The public key address of this perp market account
market_index
u16
Unique identifier index for this perp market
name
[u8; 32]
Human-readable name of the market (32-byte array)

AMM (Automated Market Maker)

amm
AMM
The AMM struct containing all automated market maker parameters and state. This includes:
  • Oracle data: Oracle address, historical data, and price information
  • Reserves: Base and quote asset reserves for the AMM
  • Liquidity: LP shares and liquidity pool balances
  • Funding: Funding rates and cumulative funding data
  • Fees: Fee pools and total fee accumulation
  • Spreads: Base spread, max spread, and dynamic spread adjustments
  • Trade data: Last trade prices, volumes, and timestamps
  • Order parameters: Step size, tick size, minimum order size
See the AMM Fields section below for detailed field descriptions.

PnL Pool

pnl_pool
PoolBalance
Pool for settling trader profit and loss. Contains:
  • scaled_balance - The scaled pool balance
  • market_index - Associated market index

Insurance Claim

insurance_claim
InsuranceClaim
Insurance fund claim information for this market
unrealized_pnl_max_imbalance
u64
Maximum allowed imbalance in unrealized PnL before triggering risk measures

Margin and Risk Parameters

margin_ratio_initial
u32
Initial margin ratio requirement (in basis points, e.g., 2000 = 20%)
margin_ratio_maintenance
u32
Maintenance margin ratio requirement (in basis points)
high_leverage_margin_ratio_initial
u16
Initial margin ratio for high leverage mode
high_leverage_margin_ratio_maintenance
u16
Maintenance margin ratio for high leverage mode
imf_factor
u32
Initial margin fraction factor for position size scaling
unrealized_pnl_imf_factor
u32
IMF factor applied to unrealized PnL
unrealized_pnl_initial_asset_weight
u32
Initial asset weight for positive unrealized PnL
unrealized_pnl_maintenance_asset_weight
u32
Maintenance asset weight for positive unrealized PnL

Liquidation Fees

liquidator_fee
u32
Fee paid to liquidators (in basis points)
if_liquidation_fee
u32
Insurance fund liquidation fee (in basis points)

Market Status

status
MarketStatus
Current operational status (Active, FundingPaused, AmmPaused, FillPaused, etc.)
contract_type
ContractType
Type of contract (Perpetual or Future)
contract_tier
ContractTier
Risk tier classification (A, B, C, Speculative, HighlySpeculative, Isolated)
paused_operations
u8
Bitfield of currently paused operations

Expiry (for Futures)

expiry_ts
i64
Unix timestamp when the market expires (0 for perpetuals)
expiry_price
i64
Settlement price at expiry

User Statistics

number_of_users
u32
Total number of users with positions or orders in this market
number_of_users_with_base
u32
Number of users with non-zero base asset positions

Quote Market

quote_spot_market_index
u16
Index of the spot market used for quote asset (usually USDC, index 0)

Protected Maker Mode

protected_maker_limit_price_divisor
u8
Divisor for protected maker limit price calculations
protected_maker_dynamic_divisor
u8
Dynamic divisor for protected maker mode

Liquidity Pool

lp_fee_transfer_scalar
u8
Scalar for LP fee transfers
lp_status
u8
Status of the liquidity pool
lp_paused_operations
u8
Bitfield of paused LP operations
lp_exchange_fee_excluscion_scalar
u8
Scalar for LP exchange fee exclusions
lp_pool_id
u8
Associated LP pool identifier
pool_id
u8
General pool identifier

Record IDs

next_fill_record_id
u64
Next sequential fill record ID
next_funding_rate_record_id
u64
Next sequential funding rate record ID
next_curve_record_id
u64
Next sequential AMM curve update record ID

Fuel Boost

fuel_boost_position
u8
Fuel boost multiplier for position holdings
fuel_boost_taker
u8
Fuel boost multiplier for taker trades
fuel_boost_maker
u8
Fuel boost multiplier for maker trades

Miscellaneous

fee_adjustment
i16
Fee adjustment factor for this market
last_fill_price
u64
Price of the most recent fill

AMM Fields

The amm field is an AMM struct containing comprehensive automated market maker data:

Oracle

  • oracle: Pubkey - Oracle account providing price feeds
  • oracle_source: OracleSource - Type of oracle (Pyth, Switchboard, etc.)
  • historical_oracle_data: HistoricalOracleData - Historical price data
  • last_oracle_normalised_price: i64 - Last normalized oracle price
  • last_oracle_conf_pct: u64 - Last oracle confidence percentage
  • last_oracle_valid: bool - Whether last oracle update was valid

AMM Reserves

  • base_asset_reserve: u128 - Base asset reserves
  • quote_asset_reserve: u128 - Quote asset reserves
  • sqrt_k: u128 - Square root of invariant k
  • peg_multiplier: u128 - Peg multiplier for price calculation
  • terminal_quote_asset_reserve: u128 - Terminal quote reserves
  • min_base_asset_reserve: u128 - Minimum base reserves
  • max_base_asset_reserve: u128 - Maximum base reserves
  • concentration_coef: u128 - Concentration coefficient

Position Tracking

  • base_asset_amount_long: i128 - Total long base asset amount
  • base_asset_amount_short: i128 - Total short base asset amount
  • base_asset_amount_with_amm: i128 - Net position with AMM
  • base_asset_amount_with_unsettled_lp: i128 - Amount with unsettled LP
  • max_open_interest: u128 - Maximum allowed open interest

Quote Amounts

  • quote_asset_amount: i128 - Net quote asset amount
  • quote_entry_amount_long: i128 - Entry quote amount for longs
  • quote_entry_amount_short: i128 - Entry quote amount for shorts
  • quote_break_even_amount_long: i128 - Break-even quote for longs
  • quote_break_even_amount_short: i128 - Break-even quote for shorts

Funding Rates

  • last_funding_rate: i64 - Most recent funding rate
  • last_funding_rate_long: i64 - Funding rate for long positions
  • last_funding_rate_short: i64 - Funding rate for short positions
  • last24h_avg_funding_rate: i64 - 24-hour average funding rate
  • cumulative_funding_rate_long: i128 - Cumulative funding for longs
  • cumulative_funding_rate_short: i128 - Cumulative funding for shorts
  • last_funding_rate_ts: i64 - Timestamp of last funding update
  • funding_period: i64 - Funding period duration
  • net_revenue_since_last_funding: i64 - Net revenue accumulation

Fees

  • fee_pool: PoolBalance - Fee pool balance
  • total_fee: i128 - Total fees collected
  • total_mm_fee: i128 - Total market maker fees
  • total_exchange_fee: u128 - Total exchange fees
  • total_fee_minus_distributions: i128 - Fees after distributions
  • total_fee_withdrawn: u128 - Total withdrawn fees
  • total_liquidation_fee: u128 - Total liquidation fees

Liquidity Provider Data

  • user_lp_shares: u128 - Total LP shares issued to users
  • base_asset_amount_per_lp: i128 - Base asset per LP share
  • quote_asset_amount_per_lp: i128 - Quote asset per LP share
  • target_base_asset_amount_per_lp: i32 - Target base asset per LP
  • per_lp_base: i8 - Base amount per LP unit

Spreads and Pricing

  • base_spread: u32 - Base spread in basis points
  • max_spread: u32 - Maximum spread in basis points
  • long_spread: u32 - Spread for long positions
  • short_spread: u32 - Spread for short positions
  • amm_spread_adjustment: i8 - AMM spread adjustment factor
  • amm_inventory_spread_adjustment: i8 - Inventory-based spread adjustment

Price Tracking

  • ask_base_asset_reserve: u128 - Ask side base reserves
  • ask_quote_asset_reserve: u128 - Ask side quote reserves
  • bid_base_asset_reserve: u128 - Bid side base reserves
  • bid_quote_asset_reserve: u128 - Bid side quote reserves
  • last_bid_price_twap: u64 - TWAP of bid price
  • last_ask_price_twap: u64 - TWAP of ask price
  • last_mark_price_twap: u64 - TWAP of mark price
  • last_mark_price_twap5min: u64 - 5-minute mark price TWAP
  • last_mark_price_twap_ts: i64 - Timestamp of last mark TWAP

Order Configuration

  • order_step_size: u64 - Minimum order size increment
  • order_tick_size: u64 - Minimum price increment
  • min_order_size: u64 - Minimum order size allowed

Volume and Volatility

  • volume24h: u64 - 24-hour trading volume
  • long_intensity_volume: u64 - Long-side intensity volume
  • short_intensity_volume: u64 - Short-side intensity volume
  • mark_std: u64 - Mark price standard deviation
  • oracle_std: u64 - Oracle price standard deviation

Trade Data

  • last_trade_ts: i64 - Timestamp of last trade
  • last_update_slot: u64 - Slot of last update

Risk Controls

  • max_fill_reserve_fraction: u16 - Maximum fraction of reserves per fill
  • max_slippage_ratio: u16 - Maximum allowed slippage ratio
  • curve_update_intensity: u8 - Intensity of curve updates
  • amm_jit_intensity: u8 - Just-in-time AMM adjustment intensity

Reference Price

  • reference_price_offset: i32 - Reference price offset
  • reference_price_offset_deadband_pct: u8 - Deadband percentage for offset

Market Maker Oracle

  • mm_oracle_price: i64 - Market maker oracle price
  • mm_oracle_slot: u64 - Slot of MM oracle update
  • mm_oracle_sequence_id: u64 - MM oracle sequence identifier

Social Loss

  • total_social_loss: u128 - Total socialized losses

Advanced

  • last_oracle_reserve_price_spread_pct: i64 - Last spread between oracle and reserves
  • net_unsettled_funding_pnl: i64 - Net unsettled funding PnL
  • quote_asset_amount_with_unsettled_lp: i64 - Quote amount with unsettled LP
  • oracle_low_risk_slot_delay_override: i8 - Override for low-risk slot delay
  • oracle_slot_delay_override: i8 - General oracle slot delay override
  • last_funding_oracle_twap: i64 - Last funding oracle TWAP

Methods

The PerpMarket struct implements the Market trait from marketmap.rs:

market_index()

fn market_index(&self) -> u16
Returns the market index identifier.

oracle_info()

fn oracle_info(&self) -> (MarketId, Pubkey, OracleSource)
Returns a tuple containing:
  • MarketId - The perp market ID
  • Pubkey - The oracle account address from amm.oracle
  • OracleSource - The oracle source type from amm.oracle_source

Usage Example

use drift::accounts::PerpMarket;
use drift::MarketMap;

// Get a perp market from the market map
let perp_market_data = market_map.get(&market_index)?;
let perp_market = &perp_market_data.data;

// Access market properties
let market_index = perp_market.market_index();
let (market_id, oracle, oracle_source) = perp_market.oracle_info();

println!("Market: {}", market_index);
println!("Oracle: {}", oracle);
println!("Mark Price TWAP: {}", perp_market.amm.last_mark_price_twap);
println!("Funding Rate: {}", perp_market.amm.last_funding_rate);
println!("Base Asset Reserve: {}", perp_market.amm.base_asset_reserve);
println!("Quote Asset Reserve: {}", perp_market.amm.quote_asset_reserve);

See Also

Build docs developers (and LLMs) love