pub async fn close_position_instructions(
rpc: &RpcClient,
position_mint_address: Pubkey,
slippage_tolerance_bps: Option<u16>,
authority: Option<Pubkey>,
) -> Result<ClosePositionInstruction, Box<dyn Error>>
Expand description
Generates instructions to close a liquidity position.
This function collects all fees and rewards, removes any remaining liquidity, and closes the position. It returns the necessary instructions, quotes for fees and rewards, and the liquidity quote for the closed position.
§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 position to be closed.slippage_tolerance_bps
- An optional slippage tolerance in basis points. Defaults to the global slippage tolerance if not provided.authority
- An optional public key of the account authorizing the transaction. Defaults to the global funder if not provided.
§Returns
A Result
containing ClosePositionInstruction
on success:
instructions
- A vector ofInstruction
objects required to execute the position closure.additional_signers
- A vector ofKeypair
objects representing additional signers required for the instructions.quote
- The computed quote for decreasing liquidity, including liquidity delta, token estimates, and minimum tokens.fees_quote
- Details of the fees available to collect from the position:fee_owed_a
- The amount of fees available to collect in token A.fee_owed_b
- The amount of fees available to collect in token B.
rewards_quote
- Details of the rewards available to collect from the position:rewards
- An array containing up to threeCollectRewardQuote
entries, one for each reward token.- Each entry includes
rewards_owed
, the amount of the respective reward token available to collect.
- Each entry includes
§Errors
This function will return an error if:
- The
authority
account is invalid or missing. - The position, token mint, or reward accounts are not found or have invalid data.
- Any RPC request to the blockchain fails.
§Example
use solana_client::rpc_client::RpcClient;
use solana_sdk::pubkey::Pubkey;
use orca_whirlpools::{
close_position_instructions, WhirlpoolsConfigInput, set_whirlpools_config_address
};
use std::str::FromStr;
set_whirlpools_config_address(WhirlpoolsConfigInput::SolanaDevnet).unwrap();
let rpc = RpcClient::new("https://api.devnet.solana.com");
let position_mint_address = Pubkey::from_str("POSITION_NFT_MINT_ADDRESS").unwrap();
let slippage_tolerance_bps = Some(100);
let result = close_position_instructions(
&rpc,
position_mint_address,
slippage_tolerance_bps,
None, // SET GLOBAL FUNDER
).unwrap();
println!("Instructions: {:?}", result.instructions);
println!("Fees Quote: {:?}", result.fees_quote);
println!("Rewards Quote: {:?}", result.rewards_quote);
println!("Liquidity Decrease Quote: {:?}", result.quote);