Skip to Content
DevelopersDrift SDKDeposits & Withdrawals

Deposits & Withdrawals

How it works

Drift uses a cross-margin system where all your deposits serve as collateral for all your positions across perp and spot markets. When you deposit tokens (like USDC, SOL, or other supported assets), they’re added to your user account’s spot balances. These deposits can be used to back perp positions, and you can borrow against them to increase leverage.

Each deposit in a spot market earns interest from borrowers, while borrows accrue interest charges. Spot balances are tracked with precision (typically 1e6 for USDC, 1e9 for SOL) and can be positive (deposits) or negative (borrows). Your total collateral value is calculated by summing all deposits (weighted by asset weights) and subtracting borrows and unrealized perp losses.

Withdrawals require sufficient free collateral, you can’t withdraw funds that are backing open positions or would put your account below minimum margin requirements. The SDK handles token account derivation and precision conversion automatically.

SDK Usage

Deposits/withdrawals move tokens between your wallet token accounts and your Drift subaccount’s spot position.

Converting amounts and deriving the token account

// marketIndex 0 is commonly USDC const marketIndex = 0; const amount = driftClient.convertToSpotPrecision(marketIndex, 100); // 100 USDC (example)
Method DriftClient.convertToSpotPrecisionReference ↗
Parameters:
NameTypeDefault
marketIndexnumber
amountany
Returns:
BN
const marketIndex = 0; const ata = await driftClient.getAssociatedTokenAccount(marketIndex); console.log(ata.toBase58());
Method DriftClient.getAssociatedTokenAccountReference ↗
Parameters:
NameTypeDefault
marketIndexnumber
useNativeboolean
tokenProgramPublicKey
authorityPublicKey
allowOwnerOffCurveboolean
Returns:
Promise<PublicKey>

Deposit

const marketIndex = 0; const amount = driftClient.convertToSpotPrecision(marketIndex, 100); const associatedTokenAccount = await driftClient.getAssociatedTokenAccount(marketIndex); await driftClient.deposit(amount, marketIndex, associatedTokenAccount);
Method DriftClient.depositReference ↗
Parameters:
NameTypeDefault
amountany

to deposit

marketIndexnumber

spot market index to deposit into

associatedTokenAccountPublicKey

can be the wallet public key if using native sol

subAccountIdnumber

subaccountId to deposit

reduceOnlyboolean

if true, deposit must not increase account risk

txParamsTxParams

transaction parameters

initSwiftAccountboolean

if true, initialize a swift account for the user

overrides{ authority?: PublicKey; }

allows overriding authority for the deposit transaction

Returns:
Promise<string>

Withdraw

const marketIndex = 0; const amount = driftClient.convertToSpotPrecision(marketIndex, 100); const associatedTokenAccount = await driftClient.getAssociatedTokenAccount(marketIndex); await driftClient.withdraw(amount, marketIndex, associatedTokenAccount);
Method DriftClient.withdrawReference ↗
Parameters:
NameTypeDefault
amountany
marketIndexnumber
associatedTokenAddressPublicKey

the token account to withdraw to. can be the wallet public key if using native sol

reduceOnlyboolean
subAccountIdnumber
txParamsTxParams
updateFuelboolean
Returns:
Promise<string>

Spot rates (borrow / lend)

import { SPOT_MARKET_RATE_PRECISION, calculateDepositRate, convertToNumber } from "@drift-labs/sdk"; const spotMarket = driftClient.getSpotMarketAccount(0); const rate = calculateDepositRate(spotMarket); console.log(convertToNumber(rate, SPOT_MARKET_RATE_PRECISION));
Function calculateDepositRateReference ↗
Parameters:
NameTypeDefault
bankSpotMarketAccount
deltaany
currentUtilizationany
Returns:
BN
import { SPOT_MARKET_RATE_PRECISION, calculateBorrowRate, convertToNumber } from "@drift-labs/sdk"; const spotMarket = driftClient.getSpotMarketAccount(0); const rate = calculateBorrowRate(spotMarket); console.log(convertToNumber(rate, SPOT_MARKET_RATE_PRECISION));
Function calculateBorrowRateReference ↗
Parameters:
NameTypeDefault
bankSpotMarketAccount
deltaany
currentUtilizationany
Returns:
BN
Last updated on