pub async fn increase_liquidity_instructions(
    rpc: &RpcClient,
    position_mint_address: Pubkey,
    param: IncreaseLiquidityParam,
    slippage_tolerance_bps: Option<u16>,
    authority: Option<Pubkey>,
) -> Result<IncreaseLiquidityInstruction, Box<dyn Error>>
Expand description

Generates instructions to increase liquidity for an existing position.

This function computes the necessary quote and creates instructions to add liquidity to 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 IncreaseLiquidityParam specifying the liquidity addition 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 addition. Defaults to the global funder if not provided.

§Returns

A Result containing IncreaseLiquidityInstruction on success:

  • quote - The computed quote for increasing liquidity, including liquidity delta, token estimates, and maximum tokens based on slippage tolerance.
  • instructions - A vector of Instruction objects required to execute the liquidity addition.
  • 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 solana_client::rpc_client::RpcClient;
use solana_sdk::pubkey::Pubkey;
use orca_whirlpools::{
    increase_liquidity_instructions, WhirlpoolsConfigInput, set_whirlpools_config_address, IncreaseLiquidityParam
};
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_PUBKEY").unwrap();
let param = IncreaseLiquidityParam::TokenA(1_000_000);
let slippage_tolerance_bps = Some(100);

let result = increase_liquidity_instructions(
    &rpc,
    position_mint_address,
    param,
    slippage_tolerance_bps,
    None, // SET GLOBAL FUNDER
).unwrap();

println!("Liquidity Increase Quote: {:?}", result.quote);
println!("Number of Instructions: {}", result.instructions.len());