Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ClearingHouse

ClearingHouse

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.

The default way to construct a ClearingHouse instance is using the from method. This will create an instance using the static WebSocketClearingHouseAccountSubscriber, which will use a websocket for each state account subscription. Alternatively, if you want to implement your own method of subscribing to the state accounts on the blockchain, you can implement a ClearingHouseAccountSubscriber and use it in the ClearingHouse.constructor

Hierarchy

Index

Constructors

Properties

_isSubscribed: boolean = false
connection: Connection
eventEmitter: StrictEventEmitter<EventEmitter, ClearingHouseAccountEvents, ClearingHouseAccountEvents, "addEventListener" | "removeEventListener", "on" | "addListener" | "removeListener" | "once" | "emit">
opts?: ConfirmOptions
program: Program<Idl>
provider: default
statePublicKey?: PublicKey
txSender: TxSender
userAccount?: UserAccount
userAccountPublicKey?: PublicKey
wallet: IWallet

Accessors

  • get isSubscribed(): boolean
  • set isSubscribed(val: boolean): void

Methods

  • deleteUser(): Promise<string>
  • depositCollateral(amount: BN, collateralAccountPublicKey: PublicKey, userPositionsAccountPublicKey?: PublicKey): Promise<string>
  • fetchAccounts(): Promise<void>
  • getClosePositionIx(marketIndex: BN, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionInstruction>
  • getDepositCollateralInstruction(amount: BN, collateralAccountPublicKey: PublicKey, userPositionsAccountPublicKey?: PublicKey): Promise<TransactionInstruction>
  • getInitializeUserInstructions(): Promise<[Keypair, PublicKey, TransactionInstruction]>
  • getLiquidateIx(liquidateeUserAccountPublicKey: PublicKey): Promise<TransactionInstruction>
  • getMarket(marketIndex: number | BN): Market
  • getSettleFundingPaymentIx(userAccount: PublicKey, userPositionsAccount: PublicKey): Promise<TransactionInstruction>
  • getUpdateFundingRateIx(oracle: PublicKey, marketIndex: BN): Promise<TransactionInstruction>
  • getUserAccountPublicKey(): Promise<PublicKey>
  • getWithdrawCollateralIx(amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionInstruction>
  • initializeUserAccount(): Promise<[string, PublicKey]>
  • initializeUserAccountAndDepositCollateral(amount: BN, collateralAccountPublicKey: PublicKey): Promise<[string, PublicKey]>
  • liquidate(liquidateeUserAccountPublicKey: PublicKey): Promise<string>
  • settleFundingPayment(userAccount: PublicKey, userPositionsAccount: PublicKey): Promise<string>
  • Parameters

    • Optional optionalSubscriptions: ClearingHouseAccountTypes[]

      Optional extra accounts to subcribe to. Always subscribes to base clearing house state and market account state by default. You should only subscribe to optional extra accounts if required, to avoid overloading your RPC.

    Returns Promise<boolean>

    Promise : SubscriptionSuccess

  • subscribeToAll(): Promise<boolean>
  • Shorthand function to subscribe to all available Clearing House State Accounts

    Returns Promise<boolean>

    Promise : SubscriptionSuccess

  • unsubscribe(): Promise<void>
  • updateFundingRate(oracle: PublicKey, marketIndex: BN): Promise<string>
  • updateWallet(newWallet: IWallet): void
  • withdrawCollateral(amount: BN, collateralAccountPublicKey: PublicKey): Promise<string>

Generated using TypeDoc