pub async fn decrease_liquidity_instructions(
rpc: &RpcClient,
position_mint_address: Pubkey,
param: DecreaseLiquidityParam,
slippage_tolerance_bps: Option<u16>,
authority: Option<Pubkey>,
) -> Result<DecreaseLiquidityInstruction, Box<dyn Error>>
Expand description
Generates instructions to decrease liquidity from an existing position.
This function computes the necessary quote and creates Solana instructions to reduce liquidity from an existing pool position, specified by the position’s mint address.
§Arguments
rpc
- A reference to a Solana RPC client for fetching necessary accounts and pool data.position_mint_address
- The public key of the NFT mint address representing the pool position.param
- A variant ofDecreaseLiquidityParam
specifying the liquidity reduction method (by Token A, Token B, or liquidity amount).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 liquidity removal. Defaults to the global funder if not provided.
§Returns
A Result
containing DecreaseLiquidityInstruction
on success:
quote
- The computed quote for decreasing liquidity, including liquidity delta, token estimates, and minimum tokens.instructions
- A vector ofInstruction
objects required to execute the decrease liquidity operation.additional_signers
- A vector ofKeypair
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 solana_client::rpc_client::RpcClient;
use solana_sdk::pubkey::Pubkey;
use orca_whirlpools::{
decrease_liquidity_instructions, WhirlpoolsConfigInput, set_whirlpools_config_address, DecreaseLiquidityParam
};
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 param = DecreaseLiquidityParam::Liquidity(500_000);
let slippage_tolerance_bps = Some(100);
let result = decrease_liquidity_instructions(
&rpc,
position_mint_address,
param,
slippage_tolerance_bps,
None, // SET GLOBAL FUNDER
).unwrap();
println!("Liquidity Decrease Quote: {:?}", result.quote);
println!("Number of Instructions: {}", result.instructions.len());