pub fn add_liquidity_pool(
        &self,
        signer: &dyn Signer,
        pool_name: &str,
        max_token_a_ui_amount: f64,
        max_token_b_ui_amount: f64,
    ) -> Result<Signature, FarmClientError> {
        if max_token_a_ui_amount < 0.0
            || max_token_b_ui_amount < 0.0
            || (max_token_a_ui_amount == 0.0 && max_token_b_ui_amount == 0.0)
        {
            return Err(FarmClientError::ValueError(format!(
                "Invalid add liquidity amounts {} and {} specified for Pool {}: Must be greater or equal to zero and at least one non-zero.",
                max_token_a_ui_amount, max_token_b_ui_amount, pool_name
            )));
        }
        // if one of the tokens is SOL and amount is zero, we need to estimate that
        // amount to get it transfered to WSOL
        let is_saber_pool = pool_name.starts_with("SBR.");
        let (is_token_a_sol, is_token_b_sol) = self.pool_has_sol_tokens(pool_name)?;
        let token_a_ui_amount = if max_token_a_ui_amount == 0.0 && is_token_a_sol && !is_saber_pool
        {
            let pool_price = self.get_pool_price(pool_name)?;
            if pool_price > 0.0 {
                max_token_b_ui_amount * 1.03 / pool_price
            } else {
                0.0
            }
        } else {
            max_token_a_ui_amount
        };
        let token_b_ui_amount = if max_token_b_ui_amount == 0.0 && is_token_b_sol && !is_saber_pool
        {
            max_token_a_ui_amount * self.get_pool_price(pool_name)? * 1.03
        } else {
            max_token_b_ui_amount
        };

        let mut inst = Vec::<Instruction>::new();
        let _ = self.check_pool_accounts(
            signer,
            pool_name,
            token_a_ui_amount,
            token_b_ui_amount,
            0.0,
            true,
            &mut inst,
        )?;

        // check if tokens need to be wrapped to a Saber decimal token
        if is_saber_pool {
            let (is_token_a_wrapped, is_token_b_wrapped) =
                self.pool_has_saber_wrapped_tokens(pool_name)?;
            if is_token_a_wrapped && max_token_a_ui_amount > 0.0 {
                inst.push(self.new_instruction_wrap_token(
                    &signer.pubkey(),
                    pool_name,
                    TokenSelector::TokenA,
                    max_token_a_ui_amount,
                )?);
            }
            if is_token_b_wrapped && max_token_b_ui_amount > 0.0 {
                inst.push(self.new_instruction_wrap_token(
                    &signer.pubkey(),
                    pool_name,
                    TokenSelector::TokenB,
                    max_token_b_ui_amount,
                )?);
            }
        }

        // create and send instruction
        inst.push(self.new_instruction_add_liquidity_pool(
            &signer.pubkey(),
            pool_name,
            max_token_a_ui_amount,
            max_token_b_ui_amount,
        )?);
        if is_token_a_sol || is_token_b_sol {
            inst.push(self.new_instruction_close_token_account(&signer.pubkey(), "SOL")?);
        }
        self.sign_and_send_instructions(&[signer], inst.as_slice())
    }
/// Adds liquidity to the Pool.
/// If one of token amounts is set to zero it will be determined based on the pool
/// price and the specified amount of another token.
Adds liquidity to the Pool.
If one of token amounts is set to zero it will be determined based on the pool
price and the specified amount of another token.
Adds liquidity to the Pool . If one of token amounts is set to zero it will be determined based on the pool price and the specified amount of another token .
pub fn add_liquidity_pool(
        &self,
        signer: &dyn Signer,
        pool_name: &str,
        max_token_a_ui_amount: f64,
        max_token_b_ui_amount: f64,
    ) -> Result<Signature, FarmClientError> {
        if max_token_a_ui_amount < 0.0
            || max_token_b_ui_amount < 0.0
            || (max_token_a_ui_amount == 0.0 && max_token_b_ui_amount == 0.0)
        {
            return Err(FarmClientError::ValueError(format!(
                "Invalid add liquidity amounts {} and {} specified for Pool {}: Must be greater or equal to zero and at least one non-zero.",
                max_token_a_ui_amount, max_token_b_ui_amount, pool_name
            )));
        }
        // if one of the tokens is SOL and amount is zero, we need to estimate that
        // amount to get it transfered to WSOL
        let is_saber_pool = pool_name.starts_with("SBR.");
        let (is_token_a_sol, is_token_b_sol) = self.pool_has_sol_tokens(pool_name)?;
        let token_a_ui_amount = if max_token_a_ui_amount == 0.0 && is_token_a_sol && !is_saber_pool
        {
            let pool_price = self.get_pool_price(pool_name)?;
            if pool_price > 0.0 {
                max_token_b_ui_amount * 1.03 / pool_price
            } else {
                0.0
            }
        } else {
            max_token_a_ui_amount
        };
        let token_b_ui_amount = if max_token_b_ui_amount == 0.0 && is_token_b_sol && !is_saber_pool
        {
            max_token_a_ui_amount * self.get_pool_price(pool_name)? * 1.03
        } else {
            max_token_b_ui_amount
        };
        let mut inst = Vec::<Instruction>::new();
        let _ = self.check_pool_accounts(
            signer,
            pool_name,
            token_a_ui_amount,
            token_b_ui_amount,
            0.0,
            true,
            &mut inst,
        )?;
        // check if tokens need to be wrapped to a Saber decimal token
        if is_saber_pool {
            let (is_token_a_wrapped, is_token_b_wrapped) =
                self.pool_has_saber_wrapped_tokens(pool_name)?;
            if is_token_a_wrapped && max_token_a_ui_amount > 0.0 {
                inst.push(self.new_instruction_wrap_token(
                    &signer.pubkey(),
                    pool_name,
                    TokenSelector::TokenA,
                    max_token_a_ui_amount,
                )?);
            }
            if is_token_b_wrapped && max_token_b_ui_amount > 0.0 {
                inst.push(self.new_instruction_wrap_token(
                    &signer.pubkey(),
                    pool_name,
                    TokenSelector::TokenB,
                    max_token_b_ui_amount,
                )?);
            }
        }
        // create and send instruction
        inst.push(self.new_instruction_add_liquidity_pool(
            &signer.pubkey(),
            pool_name,
            max_token_a_ui_amount,
            max_token_b_ui_amount,
        )?);
        if is_token_a_sol || is_token_b_sol {
            inst.push(self.new_instruction_close_token_account(&signer.pubkey(), "SOL")?);
        }
        self.sign_and_send_instructions(&[signer], inst.as_slice())
    }
pub fn add_liquidity_pool ( & self , signer : & dyn Signer , pool_name : & str , max_token_a_ui_amount : f64 , max_token_b_ui_amount : f64 , ) -> Result < Signature , FarmClientError > { if max_token_a_ui_amount < 0.0 || max_token_b_ui_amount < 0.0 || ( max_token_a_ui_amount == 0.0 && max_token_b_ui_amount == 0.0 ) { return Err ( FarmClientError :: ValueError ( format ! ( " " max_token_a_ui_amount max_token_b_ui_amount pool_name ) ) ) ; } // if one of the tokens is SOL and amount is zero, we need to estimate that // amount to get it transfered to WSOL let is_saber_pool = pool_name . starts_with ( " " ) ; let ( is_token_a_sol , is_token_b_sol ) = self . pool_has_sol_tokens ( pool_name ) ? ; let token_a_ui_amount = if max_token_a_ui_amount == 0.0 && is_token_a_sol && ! is_saber_pool { let pool_price = self . get_pool_price ( pool_name ) ? ; if pool_price > 0.0 { max_token_b_ui_amount * 1.03 / pool_price } else { 0.0 } } else { max_token_a_ui_amount } ; let token_b_ui_amount = if max_token_b_ui_amount == 0.0 && is_token_b_sol && ! is_saber_pool { max_token_a_ui_amount * self . get_pool_price ( pool_name ) ? * 1.03 } else { max_token_b_ui_amount } ; let mut inst = Vec :: < Instruction > :: new ( ) ; let _ = self . check_pool_accounts ( signer , pool_name , token_a_ui_amount , token_b_ui_amount , 0.0 , true , & mut inst , ) ? ; // check if tokens need to be wrapped to a Saber decimal token if is_saber_pool { let ( is_token_a_wrapped , is_token_b_wrapped ) = self . pool_has_saber_wrapped_tokens ( pool_name ) ? ; if is_token_a_wrapped && max_token_a_ui_amount > 0.0 { inst . push ( self . new_instruction_wrap_token ( & signer . pubkey ( ) , pool_name , TokenSelector :: TokenA , max_token_a_ui_amount , ) ? ) ; } if is_token_b_wrapped && max_token_b_ui_amount > 0.0 { inst . push ( self . new_instruction_wrap_token ( & signer . pubkey ( ) , pool_name , TokenSelector :: TokenB , max_token_b_ui_amount , ) ? ) ; } } // create and send instruction inst . push ( self . new_instruction_add_liquidity_pool ( & signer . pubkey ( ) , pool_name , max_token_a_ui_amount , max_token_b_ui_amount , ) ? ) ; if is_token_a_sol || is_token_b_sol { inst . push ( self . new_instruction_close_token_account ( & signer . pubkey ( ) , " " ) ? ) ; } self . sign_and_send_instructions ( & [ signer ] , inst . as_slice ( ) ) }
Adds liquidity to the Pool.
Adds liquidity to the Pool .
&self
signer
&dyn Signer
pool_name
&str
max_token_a_ui_amount
f64
max_token_b_ui_amount
f64
&self
signer
&dyn Signer
pool_name
&str
max_token_a_ui_amount
f64
max_token_b_ui_amount
f64