User instructions handle account creation, collateral management, and user settings.
Core Instructions
initialize_user
Creates a new user trading account.
pub fn initialize_user(
ctx: Context<InitializeUser>,
sub_account_id: u16,
name: [u8; 32],
) -> Result<()>
Sub-account ID (0-9999) for portfolio segregation
User account name (32 bytes)
deposit
Deposits collateral into user account.
pub fn deposit(
ctx: Context<Deposit>,
market_index: u16,
amount: u64,
reduce_only: bool,
) -> Result<()>
withdraw
Withdraws collateral from user account.
pub fn withdraw(
ctx: Context<Withdraw>,
market_index: u16,
amount: u64,
reduce_only: bool,
) -> Result<()>
SDK Usage
See the SDK guides for TypeScript usage:
Account Management
Create and manage accounts
DriftClient API
Client methods