In the refund function, after the logic is executed, the contribution.amount has a hard reset to zero, but there is no logic ensuring the refunded sol is reflected in the fund.amount_raised.
This could lead to incorrect fund price updating when fund.amount_raised could be used for future logic like getting the price history of a fund to use for data archiving collections or just fund distribution
use crate::error::ErrorCode;
use crate::state::{Contribution, Fund};
use anchor_lang::prelude::*;
pub fn _refund(ctx: Context<FundRefund>) -> Result<()> {
let amount = ctx.accounts.contribution.amount;
let fund = &mut ctx.accounts.fund;
if ctx.accounts.fund.deadline != 0
&& ctx.accounts.fund.deadline > Clock::get().unwrap().unix_timestamp.try_into().unwrap()
{
return Err(ErrorCode::DeadlineNotReached.into());
}
**ctx
.accounts
.fund
.to_account_info()
.try_borrow_mut_lamports()? = ctx
.accounts
.fund
.to_account_info()
.lamports()
.checked_sub(amount)
.ok_or(ProgramError::InsufficientFunds)?;
**ctx
.accounts
.contributor
.to_account_info()
.try_borrow_mut_lamports()? = ctx
.accounts
.contributor
.to_account_info()
.lamports()
.checked_add(amount)
.ok_or(ErrorCode::CalculationOverflow)?;
fund.amount_raised -= ctx.accounts.contribution.amount;
ctx.accounts.contribution.amount = 0;
ctx.accounts.contribution.reload()?;
Ok(())
}