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 of DecreaseLiquidityParam 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 of Instruction objects required to execute the decrease liquidity operation.
  • 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::{
    decrease_liquidity_instructions, set_whirlpools_config_address, DecreaseLiquidityParam, 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 param = DecreaseLiquidityParam::TokenA(1_000_000);
    let result = decrease_liquidity_instructions(
        &rpc,
        position_mint_address,
        param,
        Some(100),
        Some(wallet.pubkey()),
    )
    .await.unwrap();
    println!("Liquidity Increase Quote: {:?}", result.quote);
    println!("Number of Instructions: {}", result.instructions.len());
}