Fix account borrow issue in perp_liq_force_cancel_orders (#557)

This commit is contained in:
Christian Kamm 2023-04-24 09:52:33 +02:00 committed by GitHub
parent 10113443df
commit 898788909e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 18 deletions

View File

@ -10,29 +10,25 @@ pub fn perp_liq_force_cancel_orders(
limit: u8,
) -> Result<()> {
let mut account = ctx.accounts.account.load_full_mut()?;
let mut health_cache = {
let retriever =
new_fixed_order_account_retriever(ctx.remaining_accounts, &account.borrow())?;
new_health_cache(&account.borrow(), &retriever).context("create health cache")?
};
let mut perp_market = ctx.accounts.perp_market.load_mut()?;
//
// Early return if if liquidation is not allowed or if market is not in force close
//
let mut health_cache = {
let retriever =
new_fixed_order_account_retriever(ctx.remaining_accounts, &account.borrow())?;
let health_cache =
new_health_cache(&account.borrow(), &retriever).context("create health cache")?;
{
let liquidatable = account.check_liquidatable(&health_cache)?;
if account.fixed.is_operational()
&& liquidatable != CheckLiquidatable::Liquidatable
&& !perp_market.is_force_close()
{
return Ok(());
}
}
health_cache
};
let liquidatable = account.check_liquidatable(&health_cache)?;
if account.fixed.is_operational()
&& liquidatable != CheckLiquidatable::Liquidatable
&& !perp_market.is_force_close()
{
return Ok(());
}
//
// Cancel orders