Skip to main content

Overview

The SpotMarket struct represents a Drift spot market account. It contains all configuration parameters, balance information, and state for a spot market including oracle data, interest rates, fees, and collateral weights.

Account Structure

Core Fields

pubkey
Pubkey
The public key address of this spot market account
oracle
Pubkey
The oracle account address providing price data for this market
mint
Pubkey
The SPL token mint address for this market’s asset
vault
Pubkey
The token account holding deposited assets for this market
name
[u8; 32]
Human-readable name of the market (32-byte array)
market_index
u16
Unique identifier index for this spot market

Oracle and Price Data

historical_oracle_data
HistoricalOracleData
Historical oracle price information and statistics
oracle_source
OracleSource
The type of oracle being used (e.g., Pyth, Switchboard)
historical_index_data
HistoricalIndexData
Historical interest rate index data

Balance Information

deposit_balance
u128
Total deposited balance in the market (in token’s base units)
borrow_balance
u128
Total borrowed balance in the market (in token’s base units)
cumulative_deposit_interest
u128
Cumulative interest earned by depositors since market inception
cumulative_borrow_interest
u128
Cumulative interest paid by borrowers since market inception
max_token_deposits
u64
Maximum allowed deposit amount for this market

TWAP (Time-Weighted Average Price) Data

deposit_token_twap
u64
Time-weighted average of total deposits
borrow_token_twap
u64
Time-weighted average of total borrows
utilization_twap
u64
Time-weighted average utilization rate
last_twap_ts
u64
Unix timestamp of last TWAP update

Interest Rate Parameters

optimal_utilization
u32
Target utilization rate for optimal interest rates (in basis points)
optimal_borrow_rate
u32
Interest rate at optimal utilization (in basis points per year)
max_borrow_rate
u32
Maximum borrow interest rate (in basis points per year)
min_borrow_rate
u8
Minimum borrow interest rate
last_interest_ts
u64
Unix timestamp of last interest rate update

Risk Parameters

initial_asset_weight
u32
Initial collateral weight for deposits (in basis points, e.g., 8000 = 80%)
maintenance_asset_weight
u32
Maintenance collateral weight for deposits (in basis points)
initial_liability_weight
u32
Initial weight for borrows when calculating collateral requirements
maintenance_liability_weight
u32
Maintenance weight for borrows when calculating collateral requirements
imf_factor
u32
Initial margin fraction factor for position size scaling
liquidator_fee
u32
Fee paid to liquidators (in basis points)
if_liquidation_fee
u32
Insurance fund liquidation fee (in basis points)
scale_initial_asset_weight_start
u64
Deposit size at which initial asset weight scaling begins

Order Configuration

order_step_size
u64
Minimum order quantity increment (order sizes must be multiples of this)
order_tick_size
u64
Minimum price increment (prices must be multiples of this)
min_order_size
u64
Minimum allowed order size
max_position_size
u64
Maximum position size allowed
orders_enabled
bool
Whether trading is enabled for this market

Fee Pools

revenue_pool
PoolBalance
Protocol revenue pool balance
spot_fee_pool
PoolBalance
Spot trading fee pool balance
total_spot_fee
u128
Total spot fees collected
total_swap_fee
u64
Total swap fees collected

Insurance Fund

insurance_fund
InsuranceFund
Insurance fund configuration and balance

Social Loss

total_social_loss
u128
Total socialized loss in base asset
total_quote_social_loss
u128
Total socialized loss in quote asset

Market Status

status
MarketStatus
Current operational status of the market (Active, ReduceOnly, etc.)
asset_tier
AssetTier
Risk classification of the asset (Collateral, Protected, Cross, Isolated)
paused_operations
u8
Bitfield of paused operations
if_paused_operations
u8
Bitfield of insurance fund paused operations

Flash Loans

flash_loan_amount
u64
Current outstanding flash loan amount
flash_loan_initial_token_amount
u64
Initial token amount for flash loan tracking

Token Program

token_program_flag
u8
Flags indicating token program type (SPL Token vs Token-2022)
decimals
u32
Number of decimal places for the token

Record IDs

next_fill_record_id
u64
Next fill record identifier
next_deposit_record_id
u64
Next deposit record identifier

Miscellaneous

withdraw_guard_threshold
u64
Threshold for withdrawal guards
expiry_ts
i64
Unix timestamp when market expires (0 if no expiry)
fee_adjustment
i16
Fee adjustment factor
max_token_borrows_fraction
u16
Maximum fraction of deposits that can be borrowed
pool_id
u8
Associated pool identifier
fuel_boost_deposits
u8
Fuel boost multiplier for deposits
fuel_boost_borrows
u8
Fuel boost multiplier for borrows
fuel_boost_taker
u8
Fuel boost multiplier for taker fees
fuel_boost_maker
u8
Fuel boost multiplier for maker fees
fuel_boost_insurance
u8
Fuel boost multiplier for insurance fund contributions

Methods

The SpotMarket 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 spot market ID
  • Pubkey - The oracle account address
  • OracleSource - The oracle source type

token_program()

pub fn token_program(&self) -> Pubkey
Returns the token program address (either SPL Token or Token-2022). Returns: The appropriate token program Pubkey based on token_program_flag.

is_token_2022_program()

pub fn is_token_2022_program(&self) -> bool
Checks if this market uses the Token-2022 program. Returns: true if using Token-2022, false otherwise.

has_transfer_hook()

pub fn has_transfer_hook(&self) -> bool
Checks if the token has a transfer hook extension (Token-2022 feature). Returns: true if transfer hook is enabled.

Usage Example

use drift::accounts::SpotMarket;
use drift::MarketMap;

// Get a spot market from the market map
let spot_market_data = market_map.get(&market_index)?;
let spot_market = &spot_market_data.data;

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

println!("Market: {}", market_index);
println!("Oracle: {}", oracle);
println!("Deposit Balance: {}", spot_market.deposit_balance);
println!("Borrow Balance: {}", spot_market.borrow_balance);

See Also

  • PerpMarket - Perpetual futures market structure
  • MarketMap - Market subscription and management

Build docs developers (and LLMs) love