use crate::utils::load_wallet;
use orca_tx_sender::{build_and_send_transaction, get_rpc_client, set_rpc};
use orca_whirlpools::{harvest_position_instructions, HarvestPositionConfig, WhirlpoolDeployment};
use solana_commitment_config::CommitmentLevel;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, Signer};
use std::str::FromStr;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
set_rpc("https://api.devnet.solana.com").await?;
let rpc = get_rpc_client()?;
let wallet = load_wallet();
// SOL/devUSDC (8UJMatBoKTtA25PAYivhWDzNvTuksHUMeUxf5n1hhY7J)
let position_mint_address =
Pubkey::from_str("8UJMatBoKTtA25PAYivhWDzNvTuksHUMeUxf5n1hhY7J").unwrap();
let config = HarvestPositionConfig {
authority: Some(wallet.pubkey()),
whirlpool_deployment: Some(WhirlpoolDeployment::devnet()),
};
let result = harvest_position_instructions(&rpc, position_mint_address, config).await?;
// The instructions may include new token accounts that need to be created
// and signed for with their corresponding Keypair.
let mut signers: Vec<&Keypair> = vec![&wallet];
signers.extend(result.additional_signers.iter().map(|kp| kp));
println!("Fees Quote: {:?}", result.fees_quote);
println!("Rewards Quote: {:?}", result.rewards_quote);
println!("Number of Instructions: {}", result.instructions.len());
let signature = build_and_send_transaction(
result.instructions,
&signers,
Some(CommitmentLevel::Confirmed),
None, // No address lookup tables
)
.await?;
println!("Harvest transaction sent: {}", signature);
Ok(())
}