Overview
ThePerpMarket 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
The public key address of this perp market account
Unique identifier index for this perp market
Human-readable name of the market (32-byte array)
AMM (Automated Market Maker)
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
PnL Pool
Pool for settling trader profit and loss. Contains:
scaled_balance- The scaled pool balancemarket_index- Associated market index
Insurance Claim
Insurance fund claim information for this market
Maximum allowed imbalance in unrealized PnL before triggering risk measures
Margin and Risk Parameters
Initial margin ratio requirement (in basis points, e.g., 2000 = 20%)
Maintenance margin ratio requirement (in basis points)
Initial margin ratio for high leverage mode
Maintenance margin ratio for high leverage mode
Initial margin fraction factor for position size scaling
IMF factor applied to unrealized PnL
Initial asset weight for positive unrealized PnL
Maintenance asset weight for positive unrealized PnL
Liquidation Fees
Fee paid to liquidators (in basis points)
Insurance fund liquidation fee (in basis points)
Market Status
Current operational status (Active, FundingPaused, AmmPaused, FillPaused, etc.)
Type of contract (Perpetual or Future)
Risk tier classification (A, B, C, Speculative, HighlySpeculative, Isolated)
Bitfield of currently paused operations
Expiry (for Futures)
Unix timestamp when the market expires (0 for perpetuals)
Settlement price at expiry
User Statistics
Total number of users with positions or orders in this market
Number of users with non-zero base asset positions
Quote Market
Index of the spot market used for quote asset (usually USDC, index 0)
Protected Maker Mode
Divisor for protected maker limit price calculations
Dynamic divisor for protected maker mode
Liquidity Pool
Scalar for LP fee transfers
Status of the liquidity pool
Bitfield of paused LP operations
Scalar for LP exchange fee exclusions
Associated LP pool identifier
General pool identifier
Record IDs
Next sequential fill record ID
Next sequential funding rate record ID
Next sequential AMM curve update record ID
Fuel Boost
Fuel boost multiplier for position holdings
Fuel boost multiplier for taker trades
Fuel boost multiplier for maker trades
Miscellaneous
Fee adjustment factor for this market
Price of the most recent fill
AMM Fields
Theamm field is an AMM struct containing comprehensive automated market maker data:
Oracle
oracle: Pubkey- Oracle account providing price feedsoracle_source: OracleSource- Type of oracle (Pyth, Switchboard, etc.)historical_oracle_data: HistoricalOracleData- Historical price datalast_oracle_normalised_price: i64- Last normalized oracle pricelast_oracle_conf_pct: u64- Last oracle confidence percentagelast_oracle_valid: bool- Whether last oracle update was valid
AMM Reserves
base_asset_reserve: u128- Base asset reservesquote_asset_reserve: u128- Quote asset reservessqrt_k: u128- Square root of invariant kpeg_multiplier: u128- Peg multiplier for price calculationterminal_quote_asset_reserve: u128- Terminal quote reservesmin_base_asset_reserve: u128- Minimum base reservesmax_base_asset_reserve: u128- Maximum base reservesconcentration_coef: u128- Concentration coefficient
Position Tracking
base_asset_amount_long: i128- Total long base asset amountbase_asset_amount_short: i128- Total short base asset amountbase_asset_amount_with_amm: i128- Net position with AMMbase_asset_amount_with_unsettled_lp: i128- Amount with unsettled LPmax_open_interest: u128- Maximum allowed open interest
Quote Amounts
quote_asset_amount: i128- Net quote asset amountquote_entry_amount_long: i128- Entry quote amount for longsquote_entry_amount_short: i128- Entry quote amount for shortsquote_break_even_amount_long: i128- Break-even quote for longsquote_break_even_amount_short: i128- Break-even quote for shorts
Funding Rates
last_funding_rate: i64- Most recent funding ratelast_funding_rate_long: i64- Funding rate for long positionslast_funding_rate_short: i64- Funding rate for short positionslast24h_avg_funding_rate: i64- 24-hour average funding ratecumulative_funding_rate_long: i128- Cumulative funding for longscumulative_funding_rate_short: i128- Cumulative funding for shortslast_funding_rate_ts: i64- Timestamp of last funding updatefunding_period: i64- Funding period durationnet_revenue_since_last_funding: i64- Net revenue accumulation
Fees
fee_pool: PoolBalance- Fee pool balancetotal_fee: i128- Total fees collectedtotal_mm_fee: i128- Total market maker feestotal_exchange_fee: u128- Total exchange feestotal_fee_minus_distributions: i128- Fees after distributionstotal_fee_withdrawn: u128- Total withdrawn feestotal_liquidation_fee: u128- Total liquidation fees
Liquidity Provider Data
user_lp_shares: u128- Total LP shares issued to usersbase_asset_amount_per_lp: i128- Base asset per LP sharequote_asset_amount_per_lp: i128- Quote asset per LP sharetarget_base_asset_amount_per_lp: i32- Target base asset per LPper_lp_base: i8- Base amount per LP unit
Spreads and Pricing
base_spread: u32- Base spread in basis pointsmax_spread: u32- Maximum spread in basis pointslong_spread: u32- Spread for long positionsshort_spread: u32- Spread for short positionsamm_spread_adjustment: i8- AMM spread adjustment factoramm_inventory_spread_adjustment: i8- Inventory-based spread adjustment
Price Tracking
ask_base_asset_reserve: u128- Ask side base reservesask_quote_asset_reserve: u128- Ask side quote reservesbid_base_asset_reserve: u128- Bid side base reservesbid_quote_asset_reserve: u128- Bid side quote reserveslast_bid_price_twap: u64- TWAP of bid pricelast_ask_price_twap: u64- TWAP of ask pricelast_mark_price_twap: u64- TWAP of mark pricelast_mark_price_twap5min: u64- 5-minute mark price TWAPlast_mark_price_twap_ts: i64- Timestamp of last mark TWAP
Order Configuration
order_step_size: u64- Minimum order size incrementorder_tick_size: u64- Minimum price incrementmin_order_size: u64- Minimum order size allowed
Volume and Volatility
volume24h: u64- 24-hour trading volumelong_intensity_volume: u64- Long-side intensity volumeshort_intensity_volume: u64- Short-side intensity volumemark_std: u64- Mark price standard deviationoracle_std: u64- Oracle price standard deviation
Trade Data
last_trade_ts: i64- Timestamp of last tradelast_update_slot: u64- Slot of last update
Risk Controls
max_fill_reserve_fraction: u16- Maximum fraction of reserves per fillmax_slippage_ratio: u16- Maximum allowed slippage ratiocurve_update_intensity: u8- Intensity of curve updatesamm_jit_intensity: u8- Just-in-time AMM adjustment intensity
Reference Price
reference_price_offset: i32- Reference price offsetreference_price_offset_deadband_pct: u8- Deadband percentage for offset
Market Maker Oracle
mm_oracle_price: i64- Market maker oracle pricemm_oracle_slot: u64- Slot of MM oracle updatemm_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 reservesnet_unsettled_funding_pnl: i64- Net unsettled funding PnLquote_asset_amount_with_unsettled_lp: i64- Quote amount with unsettled LPoracle_low_risk_slot_delay_override: i8- Override for low-risk slot delayoracle_slot_delay_override: i8- General oracle slot delay overridelast_funding_oracle_twap: i64- Last funding oracle TWAP
Methods
ThePerpMarket struct implements the Market trait from marketmap.rs:
market_index()
oracle_info()
MarketId- The perp market IDPubkey- The oracle account address fromamm.oracleOracleSource- The oracle source type fromamm.oracle_source
Usage Example
See Also
- SpotMarket - Spot market structure
- MarketMap - Market subscription and management