pub async fn fetch_whirlpools_by_token_pair(
    rpc: &RpcClient,
    token_1: Pubkey,
    token_2: Pubkey,
) -> Result<Vec<PoolInfo>, Box<dyn Error>>
Expand description

Fetches all possible liquidity pools between two token mints in Orca Whirlpools.

This function retrieves information about all pools between the specified token mints, including both initialized and uninitialized pools. If a pool does not exist, it creates a placeholder account for the uninitialized pool with default configuration details.

§Arguments

  • rpc - A reference to the Solana RPC client.
  • token_1 - The public key of the first token mint in the pool.
  • token_2 - The public key of the second token mint in the pool.

§Returns

A Result containing a Vec<PoolInfo>:

  • PoolInfo::Initialized for initialized pools, including pool state and price.
  • PoolInfo::Uninitialized for uninitialized pools, including configuration details.

§Errors

This function will return an error if:

  • Any required account or mint information cannot be fetched.
  • The pool or its configuration details are invalid.

§Example

use solana_client::rpc_client::RpcClient;
use solana_sdk::pubkey::Pubkey;
use orca_whirlpools::{
    fetch_whirlpools_by_token_pair, PoolInfo, set_whirlpools_config_address, WhirlpoolsConfigInput,
};
use std::str::FromStr;

set_whirlpools_config_address(WhirlpoolsConfigInput::SolanaDevnet).unwrap();
let rpc = RpcClient::new("https://api.devnet.solana.com");
let token_1 = Pubkey::from_str("TOKEN_MINT_ONE").unwrap();
let token_2 = Pubkey::from_str("TOKEN_MINT_TWO").unwrap();

let pools = fetch_whirlpools_by_token_pair(&rpc, token_1, token_2).unwrap();
for pool in pools {
    match pool {
        PoolInfo::Initialized(pool) => println!("Initialized Pool: {:?}", pool),
        PoolInfo::Uninitialized(pool) => println!("Uninitialized Pool: {:?}", pool),
    }
}