pub async fn get_positions_for_owner(
    rpc: &RpcClient,
    owner: Pubkey,
) -> Result<Vec<PositionOrBundle>, Box<dyn Error>>
Expand description

Fetches all positions owned by a given wallet in the Orca Whirlpools.

This function retrieves token accounts owned by the wallet, using both the SPL Token Program and Token 2022 Program. It identifies accounts holding exactly one token, which represent either a position or a position bundle. For each of these accounts, it fetches the corresponding position or bundle data, including any bundled positions, and returns them.

§Arguments

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

§Returns

A Result containing a vector of PositionOrBundle objects, representing the decoded positions or position bundles owned by the given wallet.

§Errors

This function will return an error if:

  • Token accounts cannot be fetched.
  • Position or position bundle addresses cannot be derived.
  • RPC calls fail when fetching account data.

§Example

use solana_client::rpc_client::RpcClient;
use solana_sdk::pubkey::Pubkey;
use orca_whirlpools::get_positions_for_owner;
use std::str::FromStr;

let rpc = RpcClient::new("https://api.devnet.solana.com");
let owner = Pubkey::from_str("OWNER_PUBLIC_KEY").unwrap();

let positions = get_positions_for_owner(&rpc, owner).unwrap();
println!("{:?}", positions);