pub async fn fetch_positions_in_whirlpool(
    rpc: &RpcClient,
    whirlpool: Pubkey,
) -> Result<Vec<DecodedAccount<Position>>, Box<dyn Error>>
Expand description

Fetches all positions associated with a specific Whirlpool.

This function retrieves all positions linked to the given Whirlpool address using program filters. The positions are decoded and returned as a vector of hydrated position objects.

§Arguments

  • rpc - A reference to the Solana RPC client.
  • whirlpool - The public key of the Whirlpool whose positions should be fetched.

§Returns

A Result containing a vector of DecodedAccount<Position> objects, representing the positions associated with the given Whirlpool.

§Errors

This function will return an error if:

  • RPC calls fail while fetching filtered accounts.
  • Decoding the position data fails.

§Example

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

#[tokio::main]
async fn main() {
    set_whirlpools_config_address(WhirlpoolsConfigInput::SolanaDevnet).unwrap();
    let rpc = RpcClient::new("https://api.devnet.solana.com".to_string());
    let whirlpool_address =
        Pubkey::from_str("3KBZiL2g8C7tiJ32hTv5v3KM7aK9htpqTw4cTXz1HvPt").unwrap();

    let positions = fetch_positions_in_whirlpool(&rpc, whirlpool_address)
        .await
        .unwrap();

    println!("Positions: {:?}", positions);
}