Skip to main content
Account types represent the on-chain data structures used by Drift Protocol.

UserAccount

The main account type for user positions, orders, and balances.
authority
PublicKey
required
The public key of the user’s wallet that owns this account
delegate
PublicKey
required
The public key of the delegate authorized to trade on behalf of the user
name
number[]
required
Array representing the account name (max 32 bytes)
subAccountId
number
required
The sub-account identifier (0-255)
spotPositions
SpotPosition[]
required
Array of spot market positions held by the user
perpPositions
PerpPosition[]
required
Array of perpetual market positions held by the user
orders
Order[]
required
Array of open orders for this user
status
number
required
User status flags (see UserStatus enum)
nextLiquidationId
number
required
The next liquidation identifier to be used
nextOrderId
number
required
The next order identifier to be used
maxMarginRatio
number
required
Maximum margin ratio for the account
settledPerpPnl
BN
required
Settled perpetual profit and loss
totalDeposits
BN
required
Total deposits made to this account
totalWithdraws
BN
required
Total withdrawals made from this account
isMarginTradingEnabled
boolean
required
Whether margin trading is enabled for this account
idle
boolean
required
Whether the account is idle (no positions or orders)
openOrders
number
required
Number of open orders
hasOpenOrder
boolean
required
Whether the account has any open orders
marginMode
MarginMode
required
The margin mode for this account (DEFAULT, HIGH_LEVERAGE, etc.)
export type UserAccount = {
  authority: PublicKey;
  delegate: PublicKey;
  name: number[];
  subAccountId: number;
  spotPositions: SpotPosition[];
  perpPositions: PerpPosition[];
  orders: Order[];
  status: number;
  nextLiquidationId: number;
  nextOrderId: number;
  maxMarginRatio: number;
  lastAddPerpLpSharesTs: BN;
  settledPerpPnl: BN;
  totalDeposits: BN;
  totalWithdraws: BN;
  totalSocialLoss: BN;
  cumulativePerpFunding: BN;
  cumulativeSpotFees: BN;
  liquidationMarginFreed: BN;
  lastActiveSlot: BN;
  isMarginTradingEnabled: boolean;
  idle: boolean;
  openOrders: number;
  hasOpenOrder: boolean;
  openAuctions: number;
  hasOpenAuction: boolean;
  lastFuelBonusUpdateTs: number;
  marginMode: MarginMode;
  poolId: number;
};

PerpMarketAccount

Represents a perpetual futures market.
status
MarketStatus
required
Current market status (ACTIVE, PAUSED, etc.)
contractType
ContractType
required
Type of contract (PERPETUAL, FUTURE, PREDICTION)
contractTier
ContractTier
required
Risk tier of the contract (A, B, C, SPECULATIVE, etc.)
marketIndex
number
required
Unique identifier for this market
pubkey
PublicKey
required
The public key of this market account
name
number[]
required
Market name (max 32 bytes)
amm
AMM
required
Automated Market Maker configuration and state
numberOfUsers
number
required
Total number of users with positions in this market
marginRatioInitial
number
required
Initial margin requirement ratio
marginRatioMaintenance
number
required
Maintenance margin requirement ratio
liquidatorFee
number
required
Fee paid to liquidators
ifLiquidationFee
number
required
Fee paid to insurance fund on liquidation
export type PerpMarketAccount = {
  status: MarketStatus;
  contractType: ContractType;
  contractTier: ContractTier;
  expiryTs: BN;
  expiryPrice: BN;
  marketIndex: number;
  pubkey: PublicKey;
  name: number[];
  amm: AMM;
  numberOfUsersWithBase: number;
  numberOfUsers: number;
  marginRatioInitial: number;
  marginRatioMaintenance: number;
  nextFillRecordId: BN;
  nextFundingRateRecordId: BN;
  nextCurveRecordId: BN;
  pnlPool: PoolBalance;
  liquidatorFee: number;
  ifLiquidationFee: number;
  imfFactor: number;
  unrealizedPnlImfFactor: number;
  // ... additional fields
};

SpotMarketAccount

Represents a spot market for trading tokens.
status
MarketStatus
required
Current market status
assetTier
AssetTier
required
Asset tier classification (COLLATERAL, PROTECTED, CROSS, ISOLATED)
marketIndex
number
required
Unique identifier for this spot market
pubkey
PublicKey
required
The public key of this market account
mint
PublicKey
required
The SPL token mint for this market
vault
PublicKey
required
The vault account holding tokens for this market
oracle
PublicKey
required
The oracle account providing price data
oracleSource
OracleSource
required
The type of oracle being used (PYTH, SWITCHBOARD, etc.)
decimals
number
required
Number of decimals for the token
depositBalance
BN
required
Total deposits in this market
borrowBalance
BN
required
Total borrows in this market
initialAssetWeight
number
required
Initial collateral weight for this asset
maintenanceAssetWeight
number
required
Maintenance collateral weight for this asset
export type SpotMarketAccount = {
  status: MarketStatus;
  assetTier: AssetTier;
  name: number[];
  marketIndex: number;
  pubkey: PublicKey;
  mint: PublicKey;
  vault: PublicKey;
  oracle: PublicKey;
  oracleSource: OracleSource;
  historicalOracleData: HistoricalOracleData;
  historicalIndexData: HistoricalIndexData;
  insuranceFund: {
    vault: PublicKey;
    totalShares: BN;
    userShares: BN;
    sharesBase: BN;
    unstakingPeriod: BN;
    lastRevenueSettleTs: BN;
    revenueSettlePeriod: BN;
    totalFactor: number;
    userFactor: number;
  };
  decimals: number;
  optimalUtilization: number;
  optimalBorrowRate: number;
  maxBorrowRate: number;
  cumulativeDepositInterest: BN;
  cumulativeBorrowInterest: BN;
  depositBalance: BN;
  borrowBalance: BN;
  initialAssetWeight: number;
  maintenanceAssetWeight: number;
  initialLiabilityWeight: number;
  maintenanceLiabilityWeight: number;
  liquidatorFee: number;
  // ... additional fields
};

UserStatsAccount

Tracks user statistics and fee information.
authority
PublicKey
required
The user’s authority public key
referrer
PublicKey
required
The referrer’s public key
numberOfSubAccounts
number
required
Number of sub-accounts currently active
numberOfSubAccountsCreated
number
required
Total number of sub-accounts ever created
makerVolume30D
BN
required
Maker volume over the last 30 days
takerVolume30D
BN
required
Taker volume over the last 30 days
fees
object
required
Fee statistics for this user
export type UserStatsAccount = {
  numberOfSubAccounts: number;
  numberOfSubAccountsCreated: number;
  makerVolume30D: BN;
  takerVolume30D: BN;
  fillerVolume30D: BN;
  lastMakerVolume30DTs: BN;
  lastTakerVolume30DTs: BN;
  lastFillerVolume30DTs: BN;
  fees: {
    totalFeePaid: BN;
    totalFeeRebate: BN;
    totalTokenDiscount: BN;
    totalRefereeDiscount: BN;
    totalReferrerReward: BN;
    current_epoch_referrer_reward: BN;
  };
  referrer: PublicKey;
  referrerStatus: number;
  authority: PublicKey;
  ifStakedQuoteAssetAmount: BN;
  // ... additional fields
};

StateAccount

The global state account for the Drift Protocol.
admin
PublicKey
required
The admin authority for the protocol
exchangeStatus
number
required
Global exchange status flags
numberOfMarkets
number
required
Total number of perpetual markets
numberOfSpotMarkets
number
required
Total number of spot markets
perpFeeStructure
FeeStructure
required
Fee structure for perpetual markets
spotFeeStructure
FeeStructure
required
Fee structure for spot markets
export type StateAccount = {
  admin: PublicKey;
  exchangeStatus: number;
  whitelistMint: PublicKey;
  discountMint: PublicKey;
  oracleGuardRails: OracleGuardRails;
  numberOfAuthorities: BN;
  numberOfSubAccounts: BN;
  numberOfMarkets: number;
  numberOfSpotMarkets: number;
  minPerpAuctionDuration: number;
  defaultMarketOrderTimeInForce: number;
  defaultSpotAuctionDuration: number;
  liquidationMarginBufferRatio: number;
  settlementDuration: number;
  maxNumberOfSubAccounts: number;
  signer: PublicKey;
  signerNonce: number;
  srmVault: PublicKey;
  perpFeeStructure: FeeStructure;
  spotFeeStructure: FeeStructure;
  lpCooldownTime: BN;
  initialPctToLiquidate: number;
  liquidationDuration: number;
  maxInitializeUserFee: number;
  featureBitFlags: number;
};

Build docs developers (and LLMs) love