在 solana 智能合约中借入时临时价值下降
getttting temporary value dropped while borrow in solana smart contract
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 已经尝试了几乎所有可能的方法来消除这个错误 有人知道如何解决这个问题吗
2.And 这是 solana 区块链上的智能合约,我在其中使用了锚点
我得到的错误是:
let update_ctx = Context::new(
cpi_program.key,
&mut cpi_accounts,
&[pool_account.to_account_info()],
);
update_ctx
引用临时数组,因此 Context
不能比临时数组长。预先将数组绑定到变量将解决错误。
let acc_info = [pool_account.to_account_info()];
let update_ctx = Context::new(
cpi_program.key,
&mut cpi_accounts,
&acc_info,
);
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 已经尝试了几乎所有可能的方法来消除这个错误 有人知道如何解决这个问题吗
2.And 这是 solana 区块链上的智能合约,我在其中使用了锚点
我得到的错误是:
let update_ctx = Context::new(
cpi_program.key,
&mut cpi_accounts,
&[pool_account.to_account_info()],
);
update_ctx
引用临时数组,因此 Context
不能比临时数组长。预先将数组绑定到变量将解决错误。
let acc_info = [pool_account.to_account_info()];
let update_ctx = Context::new(
cpi_program.key,
&mut cpi_accounts,
&acc_info,
);