pub async fn harvest_position_instructions(
    rpc: &RpcClient,
    position_mint_address: Pubkey,
    authority: Option<Pubkey>,
) -> Result<HarvestPositionInstruction, Box<dyn Error>>
Expand description

Generates instructions to harvest a position.

Harvesting a position involves collecting any accumulated fees and rewards from the position. The position remains open, and liquidity is not removed.

§Arguments

  • rpc - A reference to a Solana RPC client for fetching accounts and pool data.
  • position_mint_address - The public key of the NFT mint address representing the pool position.
  • authority - An optional public key of the account authorizing the harvesting process. Defaults to the global funder if not provided.

§Returns

A Result containing HarvestPositionInstruction on success:

  • fees_quote - A breakdown of the fees owed to the position owner, including the amounts for Token A and Token B.
  • rewards_quote - A breakdown of the rewards owed, including up to three reward tokens.
  • instructions - A vector of Instruction objects required to execute the harvesting process.
  • additional_signers - A vector of Keypair objects representing additional signers required for the instructions.

§Errors

This function will return an error if:

  • The authority account is invalid or missing.
  • The position or token mint accounts are not found or have invalid data.
  • Any RPC request to the blockchain fails.

§Example

use orca_whirlpools::{
    harvest_position_instructions, set_whirlpools_config_address, WhirlpoolsConfigInput,
};
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::pubkey::Pubkey;
use std::str::FromStr;
use crate::utils::load_wallet;

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

    let position_mint_address =
        Pubkey::from_str("HqoV7Qv27REUtmd9UKSJGGmCRNx3531t33bDG1BUfo9K").unwrap();

    let result = harvest_position_instructions(&rpc, position_mint_address, Some(wallet.pubkey()))
        .await
        .unwrap();

    println!("Fees Quote: {:?}", result.fees_quote);
    println!("Rewards Quote: {:?}", result.rewards_quote);
    println!("Number of Instructions: {}", result.instructions.len());
}