pub trait AccountRetriever {
    // Required methods
    fn available_banks(&self) -> Result<Vec<TokenIndex>>;
    fn bank_and_oracle(
        &self,
        group: &Pubkey,
        active_token_position_index: usize,
        token_index: TokenIndex
    ) -> Result<(&Bank, I80F48)>;
    fn serum_oo(
        &self,
        active_serum_oo_index: usize,
        key: &Pubkey
    ) -> Result<&OpenOrders>;
    fn openbook_oo(
        &self,
        active_openbook_oo_index: usize,
        key: &Pubkey
    ) -> Result<&OpenOrdersAccount>;
    fn perp_market_and_oracle_price(
        &self,
        group: &Pubkey,
        active_perp_position_index: usize,
        perp_market_index: PerpMarketIndex
    ) -> Result<(&PerpMarket, I80F48)>;
}
Expand description

This trait abstracts how to find accounts needed for the health computation.

There are different ways they are retrieved from remainingAccounts, based on the instruction:

  • FixedOrderAccountRetriever requires the remainingAccounts to be in a well defined order and is the fastest. It’s used where possible.
  • ScanningAccountRetriever does a linear scan for each account it needs. It needs more compute, but works when a union of bank/oracle/market accounts are passed because health needs to be computed for different baskets in one instruction (such as for liquidation instructions).

Required Methods§

source

fn available_banks(&self) -> Result<Vec<TokenIndex>>

Returns the token indexes of the available banks. Unordered and may have duplicates.

source

fn bank_and_oracle( &self, group: &Pubkey, active_token_position_index: usize, token_index: TokenIndex ) -> Result<(&Bank, I80F48)>

source

fn serum_oo( &self, active_serum_oo_index: usize, key: &Pubkey ) -> Result<&OpenOrders>

source

fn openbook_oo( &self, active_openbook_oo_index: usize, key: &Pubkey ) -> Result<&OpenOrdersAccount>

source

fn perp_market_and_oracle_price( &self, group: &Pubkey, active_perp_position_index: usize, perp_market_index: PerpMarketIndex ) -> Result<(&PerpMarket, I80F48)>

Implementors§