Skip to Content
DevelopersDrift TS SDKDeposits & Withdrawals

Deposits & Withdrawals

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
import { SPOT_MARKET_RATE_PRECISION } from "@drift-labs/sdk";
Variable SPOT_MARKET_RATE_PRECISIONReference ↗
TypeScript docs unavailable for SPOT_MARKET_RATE_PRECISION.
Last updated on