-2
pub fn burn_liquidity(ctx: Context<BurnLiquidity>, _to: Pubkey) -> ProgramResult {
        let pool_account = &ctx.accounts.pool_account;
        let token1_account = &ctx.accounts.pool_token1_account;
        let token2_account = &ctx.accounts.pool_token2_account;
        let source = &ctx.accounts.source;
        let (reserve1, reserve2) = (pool_account.token1_balance, pool_account.token2_balance);
        let balance1: u64 = token1_account.amount;
        let balance2: u64 = token2_account.amount;
        let liquidity = source.amount;
        let total_supply = ctx.accounts.mint.supply;
        let amount1 = liquidity as f64 * balance1 as f64 / total_supply as f64;
        let amount2 = liquidity as f64 * balance2 as f64 / total_supply as f64;
        {
            let cpi_program = ctx.accounts.system_program.to_account_info();
            let mut cpi_accounts = UpdatePool {
                pool_account: pool_account.clone(),
            };

            let update_ctx = Context::new(
                cpi_program.key,
                &mut cpi_accounts,
                &[pool_account.to_account_info()],
            );
            let update_data = UpdateData {
                token1: pool_account.token1.to_string(),
                token2: pool_account.token2.to_string(),
                token1_amount: amount1 as u64,
                token2_amount: amount2 as u64,
            };
            update_pool(update_ctx, update_data);
        }

        
        Ok(())
    }

1.i have tried almost all possible way to eliminate this error does someone have any idea how to solve this 2.And this a smart contract on solana blockchain and i have used anchor in this the error i get is: enter image description here

mohan A
  • 65
  • 2
  • 10
  • 1
    Please share any relevant code [instead of a screenshot](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question) by editing your Question. Fewer people are likely to reproduce your issue without having your code in a copyable form. – tjheslin1 Nov 28 '21 at 13:18
  • [Please do not upload images of code/errors when asking a question.](//meta.stackoverflow.com/q/285551) – Jmb Nov 28 '21 at 13:20
  • When asking a question, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This is referred to by community members as creating a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – tjheslin1 Nov 28 '21 at 13:21

1 Answers1

1
            let update_ctx = Context::new(
                cpi_program.key,
                &mut cpi_accounts,
                &[pool_account.to_account_info()],
            );

update_ctx references the temporary array, thus Context cannot outlive yout temporary array. Binding your array to a variable beforehand will solve the error.

            let acc_info = [pool_account.to_account_info()];
            let update_ctx = Context::new(
                cpi_program.key,
                &mut cpi_accounts,
                &acc_info,
            );
susitsm
  • 465
  • 2
  • 6