Options
All
  • Public
  • Public/Protected
  • All
Menu

The state account defines program-level parameters, and tracks listed markets and supported collaterals.

Hierarchy

  • default<Schema>
    • State

Index

Constructors

  • new State(program: Program<Zo>, pubkey: PublicKey, data: Readonly<Schema>, signer: PublicKey, cache: Cache, commitment?: Commitment): State
  • Parameters

    • program: Program<Zo>
    • pubkey: PublicKey
    • data: Readonly<Schema>
    • signer: PublicKey
    • cache: Cache
    • Optional commitment: Commitment

    Returns State

Properties

_eqEmitters: {} = {}

Event Queue listeners

Type declaration

  • [key: string]: EventEmitter<string, any>
_eqEmittersKeys: {} = {}

Type declaration

  • [key: string]: number
_eqEmittersLocks: {} = {}

Type declaration

_obEmitters: {} = {}

OB listeners

Type declaration

  • [key: string]: EventEmitter<string, any>
_obEmittersKeys: {} = {}

Type declaration

  • [key: string]: number
_obEmittersLocks: {} = {}

Type declaration

assets: {} = {}

Type declaration

backupSubscriberChannel: undefined | number
cache: Cache
commitment: Commitment = "processed"
data: Readonly<Schema>
eventEmitter: null | EventEmitter<UpdateEvents, ChangeEvent<any>> = null

Subscriptions

lastAccountSnapshotTime: number = ...
mainSubscriberChannel: undefined | number
markets: {} = {}

Type declaration

pubkey: PublicKey
signer: PublicKey
slot: number = -1
subLock: AsyncLock = ...
subscribeLastUpdate: number = ...
subscribeTimeLimit: number = 0
zoMarketAccounts: {} = {}

zo market infos

Type declaration

Accessors

  • get connection(): Connection
  • get indexToAssetKey(): string[]
  • get indexToMarketKey(): string[]
  • get program(): Program<Zo>
  • get provider(): default
  • get publicKey(): PublicKey

Methods

  • _subscribe(accountName: string, withBackup?: boolean, programPassed?: Program<any>): Promise<EventEmitter<string | symbol, any>>
  • Parameters

    • accountName: string
    • withBackup: boolean = false
    • Optional programPassed: Program<any>

    Returns Promise<EventEmitter<string | symbol, any>>

  • _unsubscribe(): Promise<void>
  • cacheInterestRates(start: number, end: number): Promise<string>
  • Called by the keepers to update the borrow and supply multipliers.

    Parameters

    • start: number

      The inclusive start index of the collateral array.

    • end: number

      The exclusive end index of the collateral array.

    Returns Promise<string>

  • cacheOracle(mockPrices?: BN[]): Promise<string>
  • Called by the keepers regularly to cache the oracle prices.

    Parameters

    • Optional mockPrices: BN[]

      Only used for testing purposes. An array of user-set prices.

    Returns Promise<string>

  • eqEmitter(symbol: string): undefined | EventEmitter<string, any>
  • getBestAsk(marketKey: string): number
  • getBestBid(marketKey: string): number
  • getCollateralIndex(mint: PublicKey): number
  • Get the index of the collateral in the State's collaterals list using the mint public key.

    Parameters

    • mint: PublicKey

      The mint's public key.

    Returns number

  • getDexProgram(): PublicKey
  • Gets the funding info object for a given market. Funding will be undefined in the first minute of the hour. Make sure to handle that case!

    Parameters

    • symbol: string

    Returns FundingInfo

  • getMarketBySymbol(sym: string, withOrderbooks?: boolean, withEventQueues?: boolean): Promise<ZoMarket>
  • getMarketImf(marketKey: string): Decimal
  • getMarketIndexBySymbol(sym: string): number
  • Get the index of a market in the State's PerpMarkets list using the market symbol.

    Parameters

    • sym: string

      The market symbol. Ex:("BTC-PERP")

    Returns number

  • getMarketKeyBySymbol(sym: string): PublicKey
  • getMarketMmf(marketKey: string): Decimal
  • getMintBySymbol(symbol: string): PublicKey
  • getVaultCollateralByMint(mint: PublicKey): [PublicKey, CollateralInfo]
  • Get the vault public key and the CollateralInfo object for a collateral using the mint public key.

    Parameters

    • mint: PublicKey

      The mint's public key.

    Returns [PublicKey, CollateralInfo]

    The vault public key and the CollateralInfo object.

  • getZoMarketAccounts(__namedParameters: { market: MarketInfo; withEventQueues?: boolean; withOrderbooks?: boolean }): Promise<{ asks: Orderbook; bids: Orderbook; dexMarket: ZoMarket; eventQueue: Event[] }>
  • Get the ZoMarket DEX accounts for a market using the market object ( { dexMarket: ZoMarket; bids: Orderbook; asks: Orderbook } )

    Parameters

    • __namedParameters: { market: MarketInfo; withEventQueues?: boolean; withOrderbooks?: boolean }
      • market: MarketInfo
      • Optional withEventQueues?: boolean
      • Optional withOrderbooks?: boolean

    Returns Promise<{ asks: Orderbook; bids: Orderbook; dexMarket: ZoMarket; eventQueue: Event[] }>

  • loadZoMarkets(withOrderbooks?: boolean, withEventQueues?: boolean): Promise<void>
  • Load all ZoMarket DEX Accounts

    Parameters

    • Optional withOrderbooks: boolean
    • Optional withEventQueues: boolean

    Returns Promise<void>

  • obEmitter(symbol: string): undefined | EventEmitter<string, any>
  • refresh(): Promise<void>
  • subscribe(withBackup?: boolean, subscribeLimit?: number, cacheLimit?: number): Promise<void>
  • Parameters

    • withBackup: boolean = false

      use a backup confirmed listener

    • subscribeLimit: number = 1000

      minimum time difference between state updates, to prevent constant reloads

    • cacheLimit: number = 5000

      minimum time difference between cache updates, to prevent constant reloads

    Returns Promise<void>

  • subscribeToAllOrderbooks(): Promise<void>
  • subscribeToEventQueue(symbol: string): Promise<void>
  • subscribeToOrderbook(symbol: string): Promise<void>
  • unsubscribe(): Promise<void>
  • unsubscribeFromAllOrderbooks(): Promise<void>
  • unsubscribeFromEventQueue(symbol: string): Promise<void>
  • unsubscribeFromOrderbook(symbol: string): Promise<void>
  • updateAccountOnChange(processUpdate: any, that: default<T>): (account: any, snapshotTime?: any) => void
  • Parameters

    • processUpdate: any
    • that: default<T>

    Returns (account: any, snapshotTime?: any) => void

      • (account: any, snapshotTime?: any): void
      • Parameters

        • account: any
        • Optional snapshotTime: any

        Returns void

  • updatePerpFunding(symbol: string): Promise<string>
  • Called by the keepers every hour to update the funding on each market.

    Parameters

    • symbol: string

      The market symbol. Ex:("BTC-PERP")

    Returns Promise<string>

  • computeSupplyAndBorrowApys(utilization: Decimal, optimalUtility: Decimal, maxRate: Decimal, optimalRate: Decimal): { borrowApy: any; supplyApy: any }
  • computes supply and borrow apys

    Parameters

    • utilization: Decimal
    • optimalUtility: Decimal
    • maxRate: Decimal
    • optimalRate: Decimal

    Returns { borrowApy: any; supplyApy: any }

    • borrowApy: any
    • supplyApy: any
  • fetch(program: Program<Zo>, k: PublicKey, commitment: Commitment): Promise<Schema>
  • getEventQueueUpdateEventName(symbol: string): string
  • getOrderbookUpdateEventName(symbol: string): string
  • getSigner(stateKey: PublicKey, programId: PublicKey): Promise<[PublicKey, number]>
  • Gets the state signer's pda account and bump.

    Parameters

    • stateKey: PublicKey
    • programId: PublicKey

    Returns Promise<[PublicKey, number]>

    An array consisting of the state signer pda and bump.

  • load(program: Program<Zo>, k: PublicKey, commitment?: Commitment): Promise<State>

Generated using TypeDoc