Function harvest_position_instructions
pub async fn harvest_position_instructions(
rpc: &RpcClient,
position_mint_address: Address,
config: HarvestPositionConfig,
) -> 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.config- The parameters to build the harvest position instruction.
§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 ofInstructionobjects required to execute the harvesting process.additional_signers- A vector ofKeypairobjects representing additional signers required for the instructions.
§Errors
This function will return an error if:
- The
authorityaccount 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, HarvestPositionConfig, WhirlpoolDeployment};
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_pubkey::Pubkey;
use std::str::FromStr;
use crate::utils::load_wallet;
#[tokio::main]
async fn main() {
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 config = HarvestPositionConfig {
authority: Some(wallet.pubkey()),
whirlpool_deployment: Some(WhirlpoolDeployment::devnet()),
};
let result = harvest_position_instructions(&rpc, position_mint_address, config)
.await
.unwrap();
println!("Fees Quote: {:?}", result.fees_quote);
println!("Rewards Quote: {:?}", result.rewards_quote);
println!("Number of Instructions: {}", result.instructions.len());
}