Class DriftClient

DriftClient

This class is the main way to interact with Drift Protocol. It allows you to subscribe to the various accounts where the Market's state is stored, as well as: opening positions, liquidating, settling funding, depositing & withdrawing, and more.

Hierarchy

Constructors

Properties

Accessors

Methods

addAndSubscribeToUsers addInsuranceFundStake addOpenbookRemainingAccounts addPerpLpShares addPerpMarketToRemainingAccountMaps addPhoenixRemainingAccounts addSerumRemainingAccounts addSpotFulfillmentAccounts addSpotMarketToRemainingAccountMaps addTokenMintToRemainingAccounts addUser buildAndSignTransactionsMap buildBulkTransactions buildTransaction buildTransactionsMap cancelAndPlaceOrders cancelOrder cancelOrderByUserId cancelOrders cancelOrdersByIds cancelRequestRemoveInsuranceFundStake checkIfAccountExists closePosition convertToPerpPrecision convertToPricePrecision convertToSpotPrecision createAssociatedTokenAccountIdempotentInstruction createDepositTxn createInitializeUserAccountAndDepositCollateral createInitializeUserAccountAndDepositCollateralIxs createUser decodeSwiftOrderParamsMessage decodeSwiftServerMessage deleteUser deposit depositIntoSpotMarketRevenuePool emulateAccount encodeSwiftOrderParamsMessage encodeSwiftServerMessage fetchAccounts fetchAllUserAccounts fetchMarketLookupTableAccount fetchReferrerNameAccount fillPerpOrder fillSpotOrder forceCancelOrders forceGetPerpMarketAccount forceGetSpotMarketAccount forceGetStateAccount forceGetUserAccount getAddInsuranceFundStakeIx getAddPerpLpSharesIx getAssociatedTokenAccount getAssociatedTokenAccountCreationIx getBuildEncodedVaaIxs getCancelOrderByUserIdIx getCancelOrderIx getCancelOrdersByIdsIx getCancelOrdersIx getDepositInstruction getDepositIntoSpotMarketRevenuePoolIx getDepositTxnIx getFillPerpOrderIx getFillSpotOrderIx getForceCancelOrdersIx getInitializeInsuranceFundStakeIx getInitializeUserInstructions getInitializeUserStatsIx getJupiterSwapIx getJupiterSwapIxV6 getLiquidateBorrowForPerpPnlIx getLiquidatePerpIx getLiquidatePerpPnlForDepositIx getLiquidatePerpWithFillIx getLiquidateSpotIx getMarketFees getMarketIndexAndType getModifyOrderByUserIdIx getModifyOrderIx getNextSubAccountId getOpenbookV2FulfillmentConfig getOpenbookV2FulfillmentConfigs getOracleDataForPerpMarket getOracleDataForSpotMarket getOraclePriceDataAndSlot getOrder getOrderByUserId getPerpMarketAccount getPerpMarketAccounts getPerpMarketExtendedInfo getPhoenixV1FulfillmentConfig getPhoenixV1FulfillmentConfigs getPlaceAndMakePerpOrderIx getPlaceAndMakeSpotOrderIx getPlaceAndMakeSwiftPerpOrderIxs getPlaceAndTakePerpOrderIx getPlaceAndTakeSpotOrderIx getPlaceOrdersIx getPlacePerpOrderIx getPlaceSpotOrderIx getPlaceSwiftTakerPerpOrderIxs getPostPythPullOracleUpdateAtomicIxs getPostSwitchboardOnDemandUpdateAtomicIx getQuoteAssetTokenAmount getQuoteSpotMarketAccount getQuoteValuePerLpShare getReceiverProgram getReclaimRentIx getReferredUserStatsAccountsByReferrer getReferrerNameAccountsForAuthority getRemainingAccountMapsForUsers getRemainingAccounts getRemovePerpLpSharesInExpiringMarket getRemovePerpLpSharesIx getResolvePerpBankruptcyIx getResolvePerpPnlDeficitIx getResolveSpotBankruptcyIx getRevertFillIx getSerumV3FulfillmentConfig getSerumV3FulfillmentConfigs getSetUserStatusToBeingLiquidatedIx getSettleExpiredMarketIx getSettleFundingPaymentIx getSettlePNLsIxs getSettleRevenueToInsuranceFundIx getSignerPublicKey getSinglePostPythPullOracleAtomicIx getSpotMarketAccount getSpotMarketAccounts getSpotPosition getStakeForMSOLIx getStateAccount getStatePublicKey getSwapIx getSwitchboardOnDemandProgram getTokenAmount getTokenProgramForSpotMarket getTransferDepositIx getTriggerOrderIx getUpdateAMMsIx getUpdateAdvancedDlpIx getUpdateFundingRateIx getUpdatePerpBidAskTwapIx getUpdatePrelaunchOracleIx getUpdatePythPullOracleIxs getUpdateUserCustomMarginRatioIx getUpdateUserGovTokenInsuranceStakeIx getUpdateUserIdleIx getUpdateUserMarginTradingEnabledIx getUpdateUserOpenOrdersCountIx getUpdateUserQuoteAssetInsuranceStakeIx getUpdateUserReduceOnlyIx getUser getUserAccount getUserAccountAndSlot getUserAccountPublicKey getUserAccountsAndAddressesForAuthority getUserAccountsForAuthority getUserAccountsForDelegate getUserDeletionIx getUserMapKey getUserStats getUserStatsAccountPublicKey getUsers getWithdrawIx getWithdrawalIxs getWrappedSolAccountCreationIxs handlePreSignedTransaction handleSignedTransaction hasUser initializeInsuranceFundStake initializeReferrerName initializeUserAccount initializeUserAccountAndDepositCollateral initializeUserAccountForDevnet isVersionedTransaction liquidateBorrowForPerpPnl liquidatePerp liquidatePerpPnlForDeposit liquidatePerpWithFill liquidateSpot modifyOrder modifyOrderByUserOrderId modifyPerpOrder modifyPerpOrderByUserOrderId mustIncludeMarketsInIx openPosition placeAndMakePerpOrder placeAndMakeSpotOrder placeAndMakeSwiftPerpOrder placeAndTakePerpOrder placeAndTakePerpWithAdditionalOrders placeAndTakeSpotOrder placeOrders placePerpOrder placeSpotOrder placeSwiftTakerOrder postMultiPythPullOracleUpdatesAtomic postPythPullOracleUpdateAtomic postSwitchboardOnDemandUpdate prepareMarketOrderTxs preparePlaceAndTakePerpOrderWithAdditionalOrders preparePlaceAndTakeSpotOrder preparePlaceOrdersTx preparePlaceSpotOrderTx reclaimRent removeInsuranceFundStake removePerpLpShares removePerpLpSharesInExpiringMarket requestRemoveInsuranceFundStake resolvePerpBankruptcy resolvePerpPnlDeficit resolveSpotBankruptcy sendMarketOrderAndGetSignedFillTx sendSignedTx sendTransaction setUserStatusToBeingLiquidated settleExpiredMarket settleExpiredMarketPoolsToRevenuePool settleFundingPayment settleLP settleLPIx settleMultiplePNLs settleMultiplePNLsIx settlePNL settlePNLIx settlePNLs settleRevenueToInsuranceFund signMessage signSwiftOrderParamsMessage signSwiftServerMessage stakeForMSOL subscribe subscribeUsers swap switchActiveUser transferDeposit triggerEvent triggerOrder unsubscribe unsubscribeUsers updateAMMs updateFundingRate updatePerpBidAskTwap updatePrelaunchOracle updatePythPullOracle updateSpotMarketCumulativeInterest updateSpotMarketCumulativeInterestIx updateUserAdvancedLp updateUserCustomMarginRatio updateUserDelegate updateUserGovTokenInsuranceStake updateUserIdle updateUserMarginTradingEnabled updateUserName updateUserOpenOrdersCount updateUserQuoteAssetInsuranceStake updateUserReduceOnly updateWallet withdraw withdrawAllDustPositions

Constructors

Properties

_isSubscribed: boolean = false
accountSubscriber: DriftClientAccountSubscriber
activeSubAccountId: number
authority: PublicKey
authoritySubAccountMap?: Map<string, number[]>
connection: Connection
enableMetricsEvents?: boolean
eventEmitter: StrictEventEmitter<EventEmitter<DefaultEventMap>, DriftClientAccountEvents, DriftClientAccountEvents, "addEventListener" | "removeEventListener", "on" | "addListener" | "removeListener" | "once" | "emit">
includeDelegates?: boolean
lookupTableAccount: AddressLookupTableAccount
marketLookupTable: PublicKey
metricsEventEmitter: StrictEventEmitter<EventEmitter<DefaultEventMap>, DriftClientMetricsEvents, DriftClientMetricsEvents, "addEventListener" | "removeEventListener", "on" | "addListener" | "removeListener" | "once" | "emit">
mustIncludePerpMarketIndexes: Set<number> = ...
mustIncludeSpotMarketIndexes: Set<number> = ...
opts?: ConfirmOptions
perpMarketLastSlotCache: Map<number, number> = ...
program: Program<Idl>
provider: AnchorProvider
receiverProgram?: Program<PythSolanaReceiver>
sbOnDemandProgram?: Program<Idl>
sbOnDemandProgramdId: PublicKey
sbProgramFeedConfigs?: Map<string, any>
signerPublicKey?: PublicKey
skipLoadUsers?: boolean
spotMarketLastSlotCache: Map<number, number> = ...
statePublicKey?: PublicKey
swiftID: PublicKey
txHandler: TxHandler
txParams: TxParams
txSender: TxSender
txVersion: TransactionVersion
userAccountSubscriptionConfig: UserSubscriptionConfig
userStats?: UserStats
userStatsAccountPublicKey: PublicKey
userStatsAccountSubscriptionConfig: UserStatsSubscriptionConfig
users: Map<string, User> = ...
wallet: IWallet
wormholeProgram?: Program<WormholeCoreBridgeSolana>

Accessors

Methods

  • Adds and subscribes to users based on params set by the constructor or by updateWallet.

    Parameters

    Returns Promise<boolean>

  • Add to an insurance fund stake and optionally initialize the account

    Parameters

    • __namedParameters: {
          amount: BN;
          collateralAccountPublicKey: PublicKey;
          fromSubaccount?: boolean;
          initializeStakeAccount?: boolean;
          marketIndex: number;
          txParams?: TxParams;
      }
      • amount: BN
      • collateralAccountPublicKey: PublicKey

        The account where the funds to stake come from. Usually an associated token account

      • Optional fromSubaccount?: boolean

        Optional -- withdraw from current subaccount to fund stake amount, instead of wallet balance

      • Optional initializeStakeAccount?: boolean

        Add instructions to initialize the staking account -- required if its the first time the currrent authority has staked in this market

      • marketIndex: number

        Spot market index

      • Optional txParams?: TxParams

    Returns Promise<string>

  • Parameters

    • amount: BN
    • marketIndex: number
    • Optional txParams: TxParams
    • Optional subAccountId: number

    Returns Promise<string>

  • Parameters

    • marketIndex: number
    • writable: boolean
    • oracleAccountMap: Map<string, AccountMeta>
    • spotMarketAccountMap: Map<number, AccountMeta>
    • perpMarketAccountMap: Map<number, AccountMeta>

    Returns void

  • Parameters

    • marketIndex: number
    • writable: boolean
    • oracleAccountMap: Map<string, AccountMeta>
    • spotMarketAccountMap: Map<number, AccountMeta>

    Returns void

  • Parameters

    • instructionsMap: Record<string, TransactionInstruction | TransactionInstruction[]>
    • Optional txParams: TxParams
    • Optional txVersion: TransactionVersion
    • Optional lookupTables: AddressLookupTableAccount[]
    • Optional forceVersionedTransaction: boolean

    Returns Promise<{
        signedTxData: SignedTxData[];
        signedTxMap: Record<string, Transaction>;
    } | {
        signedTxData: SignedTxData[];
        signedTxMap: MappedRecord<Record<string, TransactionInstruction | TransactionInstruction[]>, Transaction | VersionedTransaction>;
    }>

  • Parameters

    • instructions: (TransactionInstruction | TransactionInstruction[])[]
    • Optional txParams: TxParams
    • Optional txVersion: TransactionVersion
    • Optional lookupTables: AddressLookupTableAccount[]
    • Optional forceVersionedTransaction: boolean

    Returns Promise<(Transaction | VersionedTransaction)[]>

  • Parameters

    • instructions: TransactionInstruction | TransactionInstruction[]
    • Optional txParams: TxParams
    • Optional txVersion: TransactionVersion
    • Optional lookupTables: AddressLookupTableAccount[]
    • Optional forceVersionedTransaction: boolean
    • Optional recentBlockhash: Readonly<{
          blockhash: string;
          lastValidBlockHeight: number;
      }>

    Returns Promise<Transaction | VersionedTransaction>

  • Parameters

    • instructionsMap: Record<string, TransactionInstruction | TransactionInstruction[]>
    • Optional txParams: TxParams
    • Optional txVersion: TransactionVersion
    • Optional lookupTables: AddressLookupTableAccount[]
    • Optional forceVersionedTransaction: boolean

    Returns Promise<MappedRecord<Record<string, TransactionInstruction | TransactionInstruction[]>, Transaction | VersionedTransaction>>

  • Parameters

    • Optional orderId: number
    • Optional txParams: TxParams
    • Optional subAccountId: number

    Returns Promise<string>

  • Parameters

    • userOrderId: number
    • Optional txParams: TxParams
    • Optional subAccountId: number

    Returns Promise<string>

  • Parameters

    • Optional orderIds: number[]
    • Optional txParams: TxParams
    • Optional subAccountId: number

    Returns Promise<string>

  • Parameters

    • marketIndex: number
    • Optional txParams: TxParams

    Returns Promise<string>

  • Converts an amount to the spot precision for a given market. The spot market precision is based on the token mint decimals.

    Parameters

    • marketIndex: number
    • amount: number | BN

    Returns BN

  • Parameters

    • amount: BN
    • marketIndex: number
    • associatedTokenAccount: PublicKey
    • Optional subAccountId: number
    • reduceOnly: boolean = false
    • Optional txParams: TxParams

    Returns Promise<Transaction | VersionedTransaction>

  • Parameters

    • amount: BN
    • userTokenAccount: PublicKey
    • marketIndex: number = 0
    • subAccountId: number = 0
    • Optional name: string
    • Optional fromSubAccountId: number
    • Optional referrerInfo: ReferrerInfo
    • Optional donateAmount: BN
    • Optional txParams: TxParams
    • Optional customMaxMarginRatio: number

    Returns Promise<[Transaction | VersionedTransaction, PublicKey]>

  • Parameters

    • amount: BN
    • userTokenAccount: PublicKey
    • marketIndex: number = 0
    • subAccountId: number = 0
    • Optional name: string
    • Optional fromSubAccountId: number
    • Optional referrerInfo: ReferrerInfo
    • Optional donateAmount: BN
    • Optional customMaxMarginRatio: number

    Returns Promise<{
        ixs: TransactionInstruction[];
        userAccountPublicKey: PublicKey;
    }>

  • Deposit funds into the given spot market

    Parameters

    • amount: BN

      to deposit

    • marketIndex: number

      spot market index to deposit into

    • associatedTokenAccount: PublicKey

      can be the wallet public key if using native sol

    • Optional subAccountId: number

      subaccountId to deposit

    • reduceOnly: boolean = false

      if true, deposit must not increase account risk

    • Optional txParams: TxParams

    Returns Promise<string>

  • Parameters

    • marketIndex: number
    • amount: BN
    • userTokenAccountPublicKey: PublicKey

    Returns Promise<string>

  • Update the subscribed accounts to a given authority, while leaving the connected wallet intact. This allows a user to emulate another user's account on the UI and sign permissionless transactions with their own wallet.

    Parameters

    Returns Promise<boolean>

  • Forces the accountSubscriber to fetch account updates from rpc

    Returns Promise<void>

  • Returns Promise<AddressLookupTableAccount>

  • Forces a fetch to rpc before returning accounts. Useful for anchor tests.

    Parameters

    • Optional subAccountId: number

    Returns Promise<UserAccount>

  • Parameters

    • marketIndex: number
    • amount: BN
    • collateralAccountPublicKey: PublicKey

    Returns Promise<TransactionInstruction>

  • Parameters

    • amount: BN
    • marketIndex: number
    • Optional subAccountId: number

    Returns Promise<TransactionInstruction>

  • Get the associated token address for the given spot market

    Parameters

    • marketIndex: number
    • useNative: boolean = true
    • tokenProgram: PublicKey = TOKEN_PROGRAM_ID

    Returns Promise<PublicKey>

  • Parameters

    Returns Promise<[TransactionInstruction[], Keypair]>

  • Parameters

    • userOrderId: number
    • Optional subAccountId: number

    Returns Promise<TransactionInstruction>

  • Parameters

    • Optional orderId: number
    • Optional subAccountId: number

    Returns Promise<TransactionInstruction>

  • Parameters

    • Optional orderIds: number[]
    • Optional subAccountId: number

    Returns Promise<TransactionInstruction>

  • Parameters

    • amount: BN
    • marketIndex: number
    • userTokenAccount: PublicKey
    • Optional subAccountId: number
    • reduceOnly: boolean = false
    • userInitialized: boolean = true

    Returns Promise<TransactionInstruction>

  • Parameters

    • marketIndex: number
    • amount: BN
    • userTokenAccountPublicKey: PublicKey

    Returns Promise<TransactionInstruction>

  • Parameters

    • amount: BN
    • marketIndex: number
    • associatedTokenAccount: PublicKey
    • Optional subAccountId: number
    • reduceOnly: boolean = false

    Returns Promise<TransactionInstruction[]>

  • Parameters

    • marketIndex: number

    Returns Promise<TransactionInstruction>

  • Returns Promise<TransactionInstruction>

  • Parameters

    • __namedParameters: {
          amount: BN;
          inAssociatedTokenAccount?: PublicKey;
          inMarketIndex: number;
          jupiterClient: JupiterClient;
          onlyDirectRoutes?: boolean;
          outAssociatedTokenAccount?: PublicKey;
          outMarketIndex: number;
          reduceOnly?: SwapReduceOnly;
          route?: Route;
          slippageBps?: number;
          swapMode?: SwapMode;
          userAccountPublicKey?: PublicKey;
      }
      • amount: BN
      • Optional inAssociatedTokenAccount?: PublicKey
      • inMarketIndex: number
      • jupiterClient: JupiterClient
      • Optional onlyDirectRoutes?: boolean
      • Optional outAssociatedTokenAccount?: PublicKey
      • outMarketIndex: number
      • Optional reduceOnly?: SwapReduceOnly
      • Optional route?: Route
      • Optional slippageBps?: number
      • Optional swapMode?: SwapMode
      • Optional userAccountPublicKey?: PublicKey

    Returns Promise<{
        ixs: TransactionInstruction[];
        lookupTables: AddressLookupTableAccount[];
    }>

  • Parameters

    • __namedParameters: {
          amount: BN;
          inAssociatedTokenAccount?: PublicKey;
          inMarketIndex: number;
          jupiterClient: JupiterClient;
          onlyDirectRoutes?: boolean;
          outAssociatedTokenAccount?: PublicKey;
          outMarketIndex: number;
          quote?: QuoteResponse;
          reduceOnly?: SwapReduceOnly;
          slippageBps?: number;
          swapMode?: SwapMode;
          userAccountPublicKey?: PublicKey;
      }

    Returns Promise<{
        ixs: TransactionInstruction[];
        lookupTables: AddressLookupTableAccount[];
    }>

  • Parameters

    • userAccountPublicKey: PublicKey
    • userAccount: UserAccount
    • perpMarketIndex: number
    • liabilityMarketIndex: number
    • maxLiabilityTransfer: BN
    • Optional limitPrice: BN
    • Optional liquidatorSubAccountId: number

    Returns Promise<TransactionInstruction>

  • Parameters

    • userAccountPublicKey: PublicKey
    • userAccount: UserAccount
    • marketIndex: number
    • maxBaseAssetAmount: BN
    • Optional limitPrice: BN
    • Optional liquidatorSubAccountId: number

    Returns Promise<TransactionInstruction>

  • Parameters

    • userAccountPublicKey: PublicKey
    • userAccount: UserAccount
    • perpMarketIndex: number
    • assetMarketIndex: number
    • maxPnlTransfer: BN
    • Optional limitPrice: BN
    • Optional liquidatorSubAccountId: number

    Returns Promise<TransactionInstruction>

  • Parameters

    Returns Promise<TransactionInstruction>

  • Parameters

    • userAccountPublicKey: PublicKey
    • userAccount: UserAccount
    • assetMarketIndex: number
    • liabilityMarketIndex: number
    • maxLiabilityTransfer: BN
    • Optional limitPrice: BN
    • Optional liquidatorSubAccountId: number

    Returns Promise<TransactionInstruction>

  • Calculates taker / maker fee (as a percentage, e.g. .001 = 10 basis points) for particular marketType

    Returns

    : {takerFee: number, makerFee: number} Precision None

    Parameters

    • marketType: MarketType
    • Optional marketIndex: number
    • Optional user: User

    Returns {
        makerFee: number;
        takerFee: number;
    }

    • makerFee: number
    • takerFee: number
  • Returns the market index and type for a given market name E.g. "SOL-PERP" -> { marketIndex: 0, marketType: MarketType.PERP }

    Parameters

    • name: string

    Returns {
        marketIndex: number;
        marketType: MarketType;
    }

  • Parameters

    • __namedParameters: {
          auctionDuration?: number;
          auctionEndPrice?: BN;
          auctionStartPrice?: BN;
          immediateOrCancel?: boolean;
          maxTs?: BN;
          newBaseAmount?: BN;
          newDirection?: PositionDirection;
          newLimitPrice?: BN;
          newOraclePriceOffset?: number;
          newTriggerCondition?: OrderTriggerCondition;
          newTriggerPrice?: BN;
          policy?: ModifyOrderPolicy;
          postOnly?: boolean;
          reduceOnly?: boolean;
          txParams?: TxParams;
          userOrderId: number;
      }
      • Optional auctionDuration?: number
      • Optional auctionEndPrice?: BN
      • Optional auctionStartPrice?: BN
      • Optional immediateOrCancel?: boolean
      • Optional maxTs?: BN
      • Optional newBaseAmount?: BN
      • Optional newDirection?: PositionDirection
      • Optional newLimitPrice?: BN
      • Optional newOraclePriceOffset?: number
      • Optional newTriggerCondition?: OrderTriggerCondition
      • Optional newTriggerPrice?: BN
      • Optional policy?: ModifyOrderPolicy
      • Optional postOnly?: boolean
      • Optional reduceOnly?: boolean
      • Optional txParams?: TxParams
      • userOrderId: number
    • Optional subAccountId: number

    Returns Promise<TransactionInstruction>

  • Parameters

    • __namedParameters: {
          auctionDuration?: number;
          auctionEndPrice?: BN;
          auctionStartPrice?: BN;
          immediateOrCancel?: boolean;
          maxTs?: BN;
          newBaseAmount?: BN;
          newDirection?: PositionDirection;
          newLimitPrice?: BN;
          newOraclePriceOffset?: number;
          newTriggerCondition?: OrderTriggerCondition;
          newTriggerPrice?: BN;
          orderId: number;
          policy?: ModifyOrderPolicy;
          postOnly?: boolean;
          reduceOnly?: boolean;
      }
      • Optional auctionDuration?: number
      • Optional auctionEndPrice?: BN
      • Optional auctionStartPrice?: BN
      • Optional immediateOrCancel?: boolean
      • Optional maxTs?: BN
      • Optional newBaseAmount?: BN
      • Optional newDirection?: PositionDirection
      • Optional newLimitPrice?: BN
      • Optional newOraclePriceOffset?: number
      • Optional newTriggerCondition?: OrderTriggerCondition
      • Optional newTriggerPrice?: BN
      • orderId: number
      • Optional policy?: ModifyOrderPolicy
      • Optional postOnly?: boolean
      • Optional reduceOnly?: boolean
    • Optional subAccountId: number

    Returns Promise<TransactionInstruction>

  • Parameters

    • encodedSwiftMessage: Buffer
    • swiftSignature: Buffer
    • encodedSwiftOrderParamsMessage: Buffer
    • swiftOrderParamsSignature: Buffer
    • takerExpectedOrderId: number
    • takerInfo: {
          taker: PublicKey;
          takerStats: PublicKey;
          takerUserAccount: UserAccount;
      }
    • orderParams: OptionalOrderParams
    • Optional referrerInfo: ReferrerInfo
    • Optional subAccountId: number

    Returns Promise<TransactionInstruction[]>

  • Parameters

    • orderParams: OptionalOrderParams
    • Optional subAccountId: number
    • Optional depositToTradeArgs: {
          depositMarketIndex: number;
          isMakingNewAccount: boolean;
      }
      • depositMarketIndex: number
      • isMakingNewAccount: boolean

    Returns Promise<TransactionInstruction>

  • Parameters

    • encodedSwiftServerMessage: Buffer
    • swiftSignature: Buffer
    • encodedSwiftOrderParamsMessage: Buffer
    • swiftOrderParamsSignature: Buffer
    • marketIndex: number
    • takerInfo: {
          taker: PublicKey;
          takerStats: PublicKey;
          takerUserAccount: UserAccount;
      }

    Returns Promise<TransactionInstruction[]>

  • Parameters

    • vaaString: string
    • feedIds: string | string[]
    • numSignatures: number = 2

    Returns Promise<TransactionInstruction[]>

  • Parameters

    Returns Promise<TransactionInstruction>

  • Parameters

    Returns {
        oracleAccountMap: Map<string, AccountMeta>;
        perpMarketAccountMap: Map<number, AccountMeta>;
        spotMarketAccountMap: Map<number, AccountMeta>;
    }

    • oracleAccountMap: Map<string, AccountMeta>
    • perpMarketAccountMap: Map<number, AccountMeta>
    • spotMarketAccountMap: Map<number, AccountMeta>
  • Parameters

    • params: RemainingAccountParams

    Returns AccountMeta[]

  • Parameters

    • marketIndex: number
    • userAccountPublicKey: PublicKey
    • Optional sharesToBurn: BN

    Returns Promise<TransactionInstruction>

  • Parameters

    • marketIndex: number
    • Optional sharesToBurn: BN
    • Optional subAccountId: number

    Returns Promise<TransactionInstruction>

  • Parameters

    • userAccountPublicKey: PublicKey
    • userAccount: UserAccount
    • marketIndex: number
    • Optional liquidatorSubAccountId: number

    Returns Promise<TransactionInstruction>

  • Parameters

    • spotMarketIndex: number
    • perpMarketIndex: number

    Returns Promise<TransactionInstruction>

  • Parameters

    • userAccountPublicKey: PublicKey
    • userAccount: UserAccount
    • marketIndex: number
    • Optional liquidatorSubAccountId: number

    Returns Promise<TransactionInstruction>

  • Parameters

    • marketIndex: number

    Returns Promise<TransactionInstruction>

  • Parameters

    • users: {
          settleeUserAccount: UserAccount;
          settleeUserAccountPublicKey: PublicKey;
      }[]
    • marketIndexes: number[]

    Returns Promise<TransactionInstruction[]>

  • Parameters

    • spotMarketIndex: number

    Returns Promise<TransactionInstruction>

  • Parameters

    • params: {
          merklePriceUpdate: {
              message: Buffer;
              proof: number[][];
          };
          vaa: Buffer;
      }
      • merklePriceUpdate: {
            message: Buffer;
            proof: number[][];
        }
        • message: Buffer
        • proof: number[][]
      • vaa: Buffer
    • feedId: string
    • guardianSet: PublicKey

    Returns Promise<TransactionInstruction>

  • Parameters

    • __namedParameters: {
          amount: BN;
          userAccountPublicKey?: PublicKey;
      }

    Returns Promise<TransactionInstruction[]>

  • Get the drift begin_swap and end_swap instructions

    Parameters

    • __namedParameters: {
          amountIn: BN;
          inMarketIndex: number;
          inTokenAccount: PublicKey;
          limitPrice?: BN;
          outMarketIndex: number;
          outTokenAccount: PublicKey;
          reduceOnly?: SwapReduceOnly;
          userAccountPublicKey?: PublicKey;
      }

    Returns Promise<{
        beginSwapIx: TransactionInstruction;
        endSwapIx: TransactionInstruction;
    }>

  • Returns the token amount for a given market. The spot market precision is based on the token mint decimals. Positive if it is a deposit, negative if it is a borrow.

    Parameters

    • marketIndex: number

    Returns BN

  • Parameters

    • amount: BN
    • marketIndex: number
    • fromSubAccountId: number
    • toSubAccountId: number

    Returns Promise<TransactionInstruction>

  • Parameters

    • marketIndexes: number[]

    Returns Promise<TransactionInstruction>

  • Parameters

    • advancedLp: boolean
    • subAccountId: number

    Returns Promise<TransactionInstruction>

  • Parameters

    Returns Promise<TransactionInstruction>

  • Parameters

    • perpMarketIndex: number

    Returns Promise<TransactionInstruction>

  • Parameters

    • params: {
          merklePriceUpdate: {
              message: Buffer;
              proof: number[][];
          };
      }
      • merklePriceUpdate: {
            message: Buffer;
            proof: number[][];
        }
        • message: Buffer
        • proof: number[][]
    • feedId: string
    • encodedVaaAddress: PublicKey

    Returns Promise<TransactionInstruction>

  • Parameters

    • marginRatio: number
    • subAccountId: number = 0

    Returns Promise<TransactionInstruction>

  • Parameters

    • marginTradingEnabled: boolean
    • subAccountId: number = 0
    • Optional userAccountPublicKey: PublicKey

    Returns Promise<TransactionInstruction>

  • Parameters

    • reduceOnly: boolean
    • subAccountId: number

    Returns Promise<TransactionInstruction>

  • Parameters

    • amount: BN
    • marketIndex: number
    • userTokenAccount: PublicKey
    • reduceOnly: boolean = false
    • Optional subAccountId: number

    Returns Promise<TransactionInstruction>

  • Parameters

    • amount: BN
    • marketIndex: number
    • associatedTokenAddress: PublicKey
    • reduceOnly: boolean = false
    • Optional subAccountId: number

    Returns Promise<TransactionInstruction[]>

  • Parameters

    • amount: BN
    • Optional includeRent: boolean

    Returns Promise<{
        ixs: TransactionInstruction[];
        pubkey: PublicKey;
        signers: Signer[];
    }>

  • Parameters

    • name: string

    Returns Promise<string>

  • Creates the User account for a user, and deposits some initial collateral

    Returns

    Parameters

    • amount: BN
    • userTokenAccount: PublicKey
    • marketIndex: number = 0
    • subAccountId: number = 0
    • Optional name: string
    • Optional fromSubAccountId: number
    • Optional referrerInfo: ReferrerInfo
    • Optional donateAmount: BN
    • Optional txParams: TxParams
    • Optional customMaxMarginRatio: number

    Returns Promise<[string, PublicKey]>

  • Parameters

    • tx: Transaction | VersionedTransaction

    Returns boolean

  • Parameters

    • userAccountPublicKey: PublicKey
    • userAccount: UserAccount
    • perpMarketIndex: number
    • liabilityMarketIndex: number
    • maxLiabilityTransfer: BN
    • Optional limitPrice: BN
    • Optional txParams: TxParams
    • Optional liquidatorSubAccountId: number

    Returns Promise<string>

  • Parameters

    • userAccountPublicKey: PublicKey
    • userAccount: UserAccount
    • marketIndex: number
    • maxBaseAssetAmount: BN
    • Optional limitPrice: BN
    • Optional txParams: TxParams
    • Optional liquidatorSubAccountId: number

    Returns Promise<string>

  • Parameters

    • userAccountPublicKey: PublicKey
    • userAccount: UserAccount
    • perpMarketIndex: number
    • assetMarketIndex: number
    • maxPnlTransfer: BN
    • Optional limitPrice: BN
    • Optional txParams: TxParams
    • Optional liquidatorSubAccountId: number

    Returns Promise<string>

  • Parameters

    • userAccountPublicKey: PublicKey
    • userAccount: UserAccount
    • assetMarketIndex: number
    • liabilityMarketIndex: number
    • maxLiabilityTransfer: BN
    • Optional limitPrice: BN
    • Optional txParams: TxParams
    • Optional liquidatorSubAccountId: number

    Returns Promise<string>

  • Modifies an open order (spot or perp) by closing it and replacing it with a new order.

    Returns

    Parameters

    • orderParams: {
          auctionDuration?: number;
          auctionEndPrice?: BN;
          auctionStartPrice?: BN;
          immediateOrCancel?: boolean;
          maxTs?: BN;
          newBaseAmount?: BN;
          newDirection?: PositionDirection;
          newLimitPrice?: BN;
          newOraclePriceOffset?: number;
          newTriggerCondition?: OrderTriggerCondition;
          newTriggerPrice?: BN;
          orderId: number;
          policy?: ModifyOrderPolicy;
          postOnly?: boolean;
          reduceOnly?: boolean;
      }
      • Optional auctionDuration?: number
      • Optional auctionEndPrice?: BN
      • Optional auctionStartPrice?: BN
      • Optional immediateOrCancel?: boolean
      • Optional maxTs?: BN
      • Optional newBaseAmount?: BN
      • Optional newDirection?: PositionDirection
      • Optional newLimitPrice?: BN
      • Optional newOraclePriceOffset?: number
      • Optional newTriggerCondition?: OrderTriggerCondition
      • Optional newTriggerPrice?: BN
      • orderId: number
      • Optional policy?: ModifyOrderPolicy
      • Optional postOnly?: boolean
      • Optional reduceOnly?: boolean
    • Optional txParams: TxParams
    • Optional subAccountId: number

    Returns Promise<string>

  • Modifies an open order by closing it and replacing it with a new order.

    Returns

    Parameters

    • orderParams: {
          auctionDuration?: number;
          auctionEndPrice?: BN;
          auctionStartPrice?: BN;
          immediateOrCancel?: boolean;
          maxTs?: BN;
          newBaseAmount?: BN;
          newDirection?: PositionDirection;
          newLimitPrice?: BN;
          newOraclePriceOffset?: number;
          newTriggerCondition?: OrderTriggerCondition;
          newTriggerPrice?: BN;
          policy?: ModifyOrderPolicy;
          postOnly?: boolean;
          reduceOnly?: boolean;
          userOrderId: number;
      }
      • Optional auctionDuration?: number
      • Optional auctionEndPrice?: BN
      • Optional auctionStartPrice?: BN
      • Optional immediateOrCancel?: boolean
      • Optional maxTs?: BN
      • Optional newBaseAmount?: BN
      • Optional newDirection?: PositionDirection
      • Optional newLimitPrice?: BN
      • Optional newOraclePriceOffset?: number
      • Optional newTriggerCondition?: OrderTriggerCondition
      • Optional newTriggerPrice?: BN
      • Optional policy?: ModifyOrderPolicy
      • Optional postOnly?: boolean
      • Optional reduceOnly?: boolean
      • userOrderId: number
    • Optional txParams: TxParams
    • Optional subAccountId: number

    Returns Promise<string>

  • Modifies an open order by closing it and replacing it with a new order.

    Deprecated

    use modifyOrder instead

    Returns

    Parameters

    • orderId: number
    • Optional newBaseAmount: BN
    • Optional newLimitPrice: BN
    • Optional newOraclePriceOffset: number

    Returns Promise<string>

  • Modifies an open order by closing it and replacing it with a new order.

    Deprecated

    use modifyOrderByUserOrderId instead

    Returns

    Parameters

    • userOrderId: number
    • Optional newBaseAmount: BN
    • Optional newLimitPrice: BN
    • Optional newOraclePriceOffset: number

    Returns Promise<string>

  • Each drift instruction must include perp and sport market accounts in the ix remaining accounts. Use this function to force a subset of markets to be included in the remaining accounts for every ix

    Parameters

    • __namedParameters: {
          perpMarketIndexes: number[];
          spotMarketIndexes: number[];
      }
      • perpMarketIndexes: number[]
      • spotMarketIndexes: number[]

    Returns void

  • Parameters

    Returns Promise<string>

  • Parameters

    Returns Promise<{
        signedCancelExistingOrdersTx?: Transaction;
        signedSettlePnlTx?: Transaction;
        txSig: string;
    }>

  • Parameters

    • swiftServerMessage: Buffer
    • swiftSignature: Buffer
    • swiftOrderParamsMessage: Buffer
    • swiftOrderParamsSignature: Buffer
    • marketIndex: number
    • takerInfo: {
          taker: PublicKey;
          takerStats: PublicKey;
          takerUserAccount: UserAccount;
      }
    • Optional txParams: TxParams

    Returns Promise<string>

  • Parameters

    • vaaString: string
    • feedIds: string[]

    Returns Promise<string>

  • Parameters

    • vaaString: string
    • feedId: string

    Returns Promise<string>

  • Parameters

    Returns Promise<{
        cancelExistingOrdersTx?: Transaction | VersionedTransaction;
        fillTx?: Transaction | VersionedTransaction;
        marketOrderTx: Transaction | VersionedTransaction;
        settlePnlTx?: Transaction | VersionedTransaction;
    }>

  • Parameters

    Returns Promise<{
        cancelExistingOrdersTx: Transaction | VersionedTransaction;
        placeAndTakeTx: Transaction | VersionedTransaction;
        settlePnlTx: Transaction | VersionedTransaction;
    }>

  • Parameters

    Returns Promise<{
        placeOrdersTx: Transaction | VersionedTransaction;
    }>

  • Parameters

    Returns Promise<{
        placeSpotOrderTx: Transaction | VersionedTransaction;
    }>

  • Parameters

    • marketIndex: number
    • Optional sharesToBurn: BN
    • Optional txParams: TxParams
    • Optional subAccountId: number

    Returns Promise<string>

  • Parameters

    • marketIndex: number
    • userAccountPublicKey: PublicKey
    • Optional sharesToBurn: BN
    • Optional txParams: TxParams

    Returns Promise<string>

  • Parameters

    • marketIndex: number
    • amount: BN
    • Optional txParams: TxParams

    Returns Promise<string>

  • Parameters

    • spotMarketIndex: number
    • perpMarketIndex: number
    • Optional txParams: TxParams

    Returns Promise<string>

  • Sends a market order and returns a signed tx which can fill the order against the vamm, which the caller can use to fill their own order if required.

    Returns

    Parameters

    • orderParams: OptionalOrderParams
    • userAccountPublicKey: PublicKey
    • userAccount: UserAccount
    • Optional makerInfo: MakerInfo | MakerInfo[]
    • Optional txParams: TxParams
    • bracketOrdersParams: OptionalOrderParams[] = ...
    • Optional referrerInfo: ReferrerInfo
    • Optional cancelExistingOrders: boolean

      Builds and returns an extra transaciton to cancel the existing orders in the same perp market. Intended use is to auto-cancel TP/SL orders when closing a position. Ignored if orderParams.marketType is not MarketType.PERP

    • Optional settlePnl: boolean

    Returns Promise<{
        signedCancelExistingOrdersTx?: Transaction;
        signedFillTx?: Transaction;
        signedSettlePnlTx?: Transaction;
        txSig: string;
    }>

  • Parameters

    • tx: Transaction | VersionedTransaction
    • Optional opts: ConfirmOptions

    Returns Promise<string>

  • Parameters

    • tx: Transaction | VersionedTransaction
    • Optional additionalSigners: Signer[]
    • Optional opts: ConfirmOptions
    • Optional preSigned: boolean

    Returns Promise<TxSigAndSlot>

  • Parameters

    • perpMarketIndex: number
    • Optional txParams: TxParams

    Returns Promise<string>

  • Parameters

    • settleeUserAccountPublicKey: PublicKey
    • marketIndex: number

    Returns Promise<TransactionInstruction>

  • Parameters

    • users: {
          settleeUserAccount: UserAccount;
          settleeUserAccountPublicKey: PublicKey;
      }[]
    • marketIndexes: number[]
    • Optional opts: {
          filterInvalidMarkets?: boolean;
      }
      • Optional filterInvalidMarkets?: boolean
    • Optional txParams: TxParams

    Returns Promise<string>

  • Parameters

    • spotMarketIndex: number
    • Optional txParams: TxParams

    Returns Promise<string>

  • Parameters

    • message: Uint8Array
    • keypair: Keypair = ...

    Returns Promise<Buffer>

  • Swap tokens in drift account using jupiter

    Parameters

    • __namedParameters: {
          amount: BN;
          inAssociatedTokenAccount?: PublicKey;
          inMarketIndex: number;
          jupiterClient: JupiterClient;
          onlyDirectRoutes?: boolean;
          outAssociatedTokenAccount?: PublicKey;
          outMarketIndex: number;
          reduceOnly?: SwapReduceOnly;
          route?: Route;
          slippageBps?: number;
          swapMode?: SwapMode;
          txParams?: TxParams;
          v6?: {
              quote?: QuoteResponse;
          };
      }

    Returns Promise<string>

  • Withdraws from the fromSubAccount and deposits into the toSubAccount

    Parameters

    • amount: BN
    • marketIndex: number
    • fromSubAccountId: number
    • toSubAccountId: number
    • Optional txParams: TxParams

    Returns Promise<string>

  • Parameters

    • vaaString: string
    • feedId: string

    Returns Promise<string>

  • Parameters

    • marketIndex: number
    • Optional txParams: TxParams

    Returns Promise<string>

  • Parameters

    • marketIndex: number

    Returns Promise<TransactionInstruction>

  • Parameters

    • updates: {
          advancedLp: boolean;
          subAccountId: number;
      }[]

    Returns Promise<string>

  • Parameters

    • updates: {
          marginRatio: number;
          subAccountId: number;
      }[]
    • Optional txParams: TxParams

    Returns Promise<string>

  • Parameters

    • updates: {
          marginTradingEnabled: boolean;
          subAccountId: number;
      }[]

    Returns Promise<string>

  • Parameters

    • name: string
    • subAccountId: number = 0

    Returns Promise<string>

  • Parameters

    • updates: {
          reduceOnly: boolean;
          subAccountId: number;
      }[]

    Returns Promise<string>

  • Update the wallet to use for drift transactions and linked user account

    Parameters

    • newWallet: IWallet
    • Optional subAccountIds: number[]
    • Optional activeSubAccountId: number
    • Optional includeDelegates: boolean
    • Optional authoritySubaccountMap: Map<string, number[]>

    Returns Promise<boolean>

  • Withdraws from a user account. If deposit doesn't already exist, creates a borrow

    Parameters

    • amount: BN
    • marketIndex: number
    • associatedTokenAddress: PublicKey

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

    • reduceOnly: boolean = false
    • Optional subAccountId: number
    • Optional txParams: TxParams

    Returns Promise<string>

  • Parameters

    • Optional subAccountId: number
    • Optional txParams: TxParams
    • Optional opts: {
          dustPositionCountCallback?: ((count: number) => void);
      }
      • Optional dustPositionCountCallback?: ((count: number) => void)
          • (count: number): void
          • Parameters

            • count: number

            Returns void

    Returns Promise<string>

Generated using TypeDoc