Account types represent the on-chain data structures used by Drift Protocol.
UserAccount
The main account type for user positions, orders, and balances.
The public key of the user’s wallet that owns this account
The public key of the delegate authorized to trade on behalf of the user
Array representing the account name (max 32 bytes)
The sub-account identifier (0-255)
Array of spot market positions held by the user
Array of perpetual market positions held by the user
Array of open orders for this user
User status flags (see UserStatus enum)
The next liquidation identifier to be used
The next order identifier to be used
Maximum margin ratio for the account
Settled perpetual profit and loss
Total deposits made to this account
Total withdrawals made from this account
Whether margin trading is enabled for this account
Whether the account is idle (no positions or orders)
Whether the account has any open orders
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.
Current market status (ACTIVE, PAUSED, etc.)
Type of contract (PERPETUAL, FUTURE, PREDICTION)
Risk tier of the contract (A, B, C, SPECULATIVE, etc.)
Unique identifier for this market
The public key of this market account
Market name (max 32 bytes)
Automated Market Maker configuration and state
Total number of users with positions in this market
Initial margin requirement ratio
Maintenance margin requirement ratio
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.
Asset tier classification (COLLATERAL, PROTECTED, CROSS, ISOLATED)
Unique identifier for this spot market
The public key of this market account
The SPL token mint for this market
The vault account holding tokens for this market
The oracle account providing price data
The type of oracle being used (PYTH, SWITCHBOARD, etc.)
Number of decimals for the token
Total deposits in this market
Total borrows in this market
Initial collateral weight for this asset
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.
The user’s authority public key
The referrer’s public key
Number of sub-accounts currently active
numberOfSubAccountsCreated
Total number of sub-accounts ever created
Maker volume over the last 30 days
Taker volume over the last 30 days
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.
The admin authority for the protocol
Global exchange status flags
Total number of perpetual markets
Total number of spot markets
Fee structure for perpetual markets
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;
};