pub fn new_instruction_add_liquidity_pool(
        &self,
        wallet_address: &Pubkey,
        pool_name: &str,
        max_token_a_ui_amount: f64,
        max_token_b_ui_amount: f64,
    ) -> Result<Instruction, FarmClientError> {
        // get pool info
        let pool = self.get_pool(pool_name)?;

        // get tokens info
        let token_a = self.get_token_by_ref_from_cache(&pool.token_a_ref)?;
        let token_b = self.get_token_by_ref_from_cache(&pool.token_b_ref)?;

        // convert amounts if wrapped tokens are used
        let mut max_token_a_amount =
            self.to_token_amount_option(max_token_a_ui_amount, &token_a)?;
        let mut max_token_b_amount =
            self.to_token_amount_option(max_token_b_ui_amount, &token_b)?;
        if let PoolRoute::Saber {
            wrapped_token_a_ref,
            wrapped_token_b_ref,
            ..
        } = pool.route
        {
            if let Some(token_ref) = wrapped_token_a_ref {
                let underlying_decimals =
                    token_a.ok_or(ProgramError::UninitializedAccount)?.decimals;
                let wrapped_decimals = self.get_token_by_ref(&token_ref)?.decimals;
                max_token_a_amount = account::to_amount_with_new_decimals(
                    max_token_a_amount,
                    underlying_decimals,
                    wrapped_decimals,
                )?;
            }
            if let Some(token_ref) = wrapped_token_b_ref {
                let underlying_decimals =
                    token_b.ok_or(ProgramError::UninitializedAccount)?.decimals;
                let wrapped_decimals = self.get_token_by_ref(&token_ref)?.decimals;
                max_token_b_amount = account::to_amount_with_new_decimals(
                    max_token_b_amount,
                    underlying_decimals,
                    wrapped_decimals,
                )?;
            }
        }

        // fill in instruction data
        let data = AmmInstruction::AddLiquidity {
            max_token_a_amount,
            max_token_b_amount,
        }
        .to_vec()?;

        let accounts = match pool.route {
            PoolRoute::Raydium { .. } => {
                self.get_add_liquidity_accounts_raydium(wallet_address, pool_name)?
            }
            PoolRoute::Saber { .. } => {
                self.get_add_liquidity_accounts_saber(wallet_address, pool_name)?
            }
            PoolRoute::Orca { .. } => {
                self.get_add_liquidity_accounts_orca(wallet_address, pool_name)?
            }
        };

        Ok(Instruction {
            program_id: pool.router_program_id,
            data,
            accounts,
        })
    }
/// Creates a new Instruction for adding liquidity to the Pool.
/// If one of the token amounts is 0 and pool requires both tokens,
/// amount will be autocalculated based on the current pool price.
Creates a new Instruction for adding liquidity to the Pool.
If one of the token amounts is 0 and pool requires both tokens,
amount will be autocalculated based on the current pool price.
Creates a new Instruction for adding liquidity to the Pool . If one of the token amounts is 0 and pool requires both tokens amount will be autocalculated based on the current pool price .
pub fn new_instruction_add_liquidity_pool(
        &self,
        wallet_address: &Pubkey,
        pool_name: &str,
        max_token_a_ui_amount: f64,
        max_token_b_ui_amount: f64,
    ) -> Result<Instruction, FarmClientError> {
        // get pool info
        let pool = self.get_pool(pool_name)?;
        // get tokens info
        let token_a = self.get_token_by_ref_from_cache(&pool.token_a_ref)?;
        let token_b = self.get_token_by_ref_from_cache(&pool.token_b_ref)?;
        // convert amounts if wrapped tokens are used
        let mut max_token_a_amount =
            self.to_token_amount_option(max_token_a_ui_amount, &token_a)?;
        let mut max_token_b_amount =
            self.to_token_amount_option(max_token_b_ui_amount, &token_b)?;
        if let PoolRoute::Saber {
            wrapped_token_a_ref,
            wrapped_token_b_ref,
            ..
        } = pool.route
        {
            if let Some(token_ref) = wrapped_token_a_ref {
                let underlying_decimals =
                    token_a.ok_or(ProgramError::UninitializedAccount)?.decimals;
                let wrapped_decimals = self.get_token_by_ref(&token_ref)?.decimals;
                max_token_a_amount = account::to_amount_with_new_decimals(
                    max_token_a_amount,
                    underlying_decimals,
                    wrapped_decimals,
                )?;
            }
            if let Some(token_ref) = wrapped_token_b_ref {
                let underlying_decimals =
                    token_b.ok_or(ProgramError::UninitializedAccount)?.decimals;
                let wrapped_decimals = self.get_token_by_ref(&token_ref)?.decimals;
                max_token_b_amount = account::to_amount_with_new_decimals(
                    max_token_b_amount,
                    underlying_decimals,
                    wrapped_decimals,
                )?;
            }
        }
        // fill in instruction data
        let data = AmmInstruction::AddLiquidity {
            max_token_a_amount,
            max_token_b_amount,
        }
        .to_vec()?;
        let accounts = match pool.route {
            PoolRoute::Raydium { .. } => {
                self.get_add_liquidity_accounts_raydium(wallet_address, pool_name)?
            }
            PoolRoute::Saber { .. } => {
                self.get_add_liquidity_accounts_saber(wallet_address, pool_name)?
            }
            PoolRoute::Orca { .. } => {
                self.get_add_liquidity_accounts_orca(wallet_address, pool_name)?
            }
        };
        Ok(Instruction {
            program_id: pool.router_program_id,
            data,
            accounts,
        })
    }
pub fn new_instruction_add_liquidity_pool ( & self , wallet_address : & Pubkey , pool_name : & str , max_token_a_ui_amount : f64 , max_token_b_ui_amount : f64 , ) -> Result < Instruction , FarmClientError > { // get pool info let pool = self . get_pool ( pool_name ) ? ; // get tokens info let token_a = self . get_token_by_ref_from_cache ( & pool . token_a_ref ) ? ; let token_b = self . get_token_by_ref_from_cache ( & pool . token_b_ref ) ? ; // convert amounts if wrapped tokens are used let mut max_token_a_amount = self . to_token_amount_option ( max_token_a_ui_amount , & token_a ) ? ; let mut max_token_b_amount = self . to_token_amount_option ( max_token_b_ui_amount , & token_b ) ? ; if let PoolRoute :: Saber { wrapped_token_a_ref , wrapped_token_b_ref , .. } = pool . route { if let Some ( token_ref ) = wrapped_token_a_ref { let underlying_decimals = token_a . ok_or ( ProgramError :: UninitializedAccount ) ? . decimals ; let wrapped_decimals = self . get_token_by_ref ( & token_ref ) ? . decimals ; max_token_a_amount = account :: to_amount_with_new_decimals ( max_token_a_amount , underlying_decimals , wrapped_decimals , ) ? ; } if let Some ( token_ref ) = wrapped_token_b_ref { let underlying_decimals = token_b . ok_or ( ProgramError :: UninitializedAccount ) ? . decimals ; let wrapped_decimals = self . get_token_by_ref ( & token_ref ) ? . decimals ; max_token_b_amount = account :: to_amount_with_new_decimals ( max_token_b_amount , underlying_decimals , wrapped_decimals , ) ? ; } } // fill in instruction data let data = AmmInstruction :: AddLiquidity { max_token_a_amount , max_token_b_amount , } . to_vec ( ) ? ; let accounts = match pool . route { PoolRoute :: Raydium { .. } => { self . get_add_liquidity_accounts_raydium ( wallet_address , pool_name ) ? } PoolRoute :: Saber { .. } => { self . get_add_liquidity_accounts_saber ( wallet_address , pool_name ) ? } PoolRoute :: Orca { .. } => { self . get_add_liquidity_accounts_orca ( wallet_address , pool_name ) ? } } ; Ok ( Instruction { program_id : pool . router_program_id , data , accounts , } ) }
Creates a new Instruction for adding liquidity to the Pool.
Creates a new Instruction for adding liquidity to the Pool .
&self
wallet_address
&Pubkey
pool_name
&str
max_token_a_ui_amount
f64
max_token_b_ui_amount
f64
&self
wallet_address
&Pubkey
pool_name
&str
max_token_a_ui_amount
f64
max_token_b_ui_amount
f64