Function open_position_instructions

pub async fn open_position_instructions(
    rpc: &RpcClient,
    pool_address: Address,
    lower_price: f64,
    upper_price: f64,
    param: IncreaseLiquidityParam,
    config: OpenPositionConfig,
) -> Result<OpenPositionInstruction, Box<dyn Error>>
Expand description

Opens a position in a liquidity pool within a specific price range.

This function creates a new position in the specified price range for a given pool. It allows for providing liquidity in a targeted range, optimizing capital efficiency.

§Arguments

  • rpc - A reference to the Solana RPC client.
  • pool_address - The public key of the liquidity pool.
  • lower_price - The lower bound of the price range for the position. Must be greater than 0.0.
  • upper_price - The upper bound of the price range for the position. Must be greater than 0.0.
  • param - Maximum amounts of token A and B to deposit.
  • config - The parameters to build the open position instruction.

§Returns

Returns a Result containing an OpenPositionInstruction on success, which includes:

  • position_mint - The mint address of the position NFT.
  • instructions - A vector of Instruction objects required for creating the position.
  • additional_signers - A vector of Keypair objects for additional transaction signers.
  • initialization_cost - The cost of initializing the position, in lamports.

§Errors

Returns an error if:

  • The funder account is invalid.
  • The pool or token mint accounts are not found or invalid.
  • Any RPC request fails.
  • The pool is a Splash Pool, as they only support full-range positions.
  • The lower price is less or equal to 0.0.
  • The upper price is less or equal to 0.0.

§Example

use solana_client::rpc_client::RpcClient;
use solana_keypair::Keypair;
use solana_pubkey::Pubkey;
use orca_whirlpools::{open_position_instructions, IncreaseLiquidityParam, OpenPositionConfig, WhirlpoolDeployment};
use std::str::FromStr;

let rpc = RpcClient::new("https://api.devnet.solana.com");

let whirlpool_pubkey = Pubkey::from_str("WHIRLPOOL_ADDRESS").unwrap();
let param = IncreaseLiquidityParam { token_max_a: 1_000_000, token_max_b: 1_000_000 };

let wallet = Keypair::new();

let config = OpenPositionConfig {
    slippage_tolerance_bps: Some(100),
    funder: Some(wallet.pubkey()),
    whirlpool_deployment: Some(WhirlpoolDeployment::devnet()),
};
let result = open_position_instructions(&rpc, whirlpool_pubkey, 0.00005, 0.00015, param, config).unwrap();

println!("Position Mint: {:?}", result.position_mint);
println!("Initialization Cost: {} lamports", result.initialization_cost);