Function fetch_whirlpools_by_token_pair
pub async fn fetch_whirlpools_by_token_pair(
rpc: &RpcClient,
token_1: Address,
token_2: Address,
whirlpool_deployment: Option<WhirlpoolDeployment>,
) -> 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.whirlpool_deployment- The whirlpool program and config to query against. Defaults to the mutable whirlpool program and mainnet config ifNone.
§Returns
A Result containing a Vec<PoolInfo>:
PoolInfo::Initializedfor initialized pools, including pool state and price.PoolInfo::Uninitializedfor 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 orca_whirlpools::{fetch_whirlpools_by_token_pair, PoolInfo, WhirlpoolDeployment};
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_pubkey::Pubkey;
use std::str::FromStr;
#[tokio::main]
async fn main() {
let rpc = RpcClient::new("https://api.devnet.solana.com".to_string());
let token_a = Pubkey::from_str("So11111111111111111111111111111111111111112").unwrap();
let token_b = Pubkey::from_str("BRjpCHtyQLNCo8gqRUr8jtdAj5AjPYQaoqbvcZiHok1k").unwrap(); // devUSDC
let pool_infos = fetch_whirlpools_by_token_pair(&rpc, token_a, token_b, Some(WhirlpoolDeployment::devnet()))
.await
.unwrap();
for pool_info in pool_infos {
match pool_info {
PoolInfo::Initialized(pool) => println!("Pool is initialized: {:?}", pool),
PoolInfo::Uninitialized(pool) => println!("Pool is not initialized: {:?}", pool),
}
}
}