program: optimize cu usage in token deposit, by computing health only… (#786)
* program: optimize cu usage in token deposit, by computing health only if user is being liquidated Signed-off-by: microwavedcola1 <microwavedcola@gmail.com> * Fixes from review Signed-off-by: microwavedcola1 <microwavedcola@gmail.com> * Fixes from review Signed-off-by: microwavedcola1 <microwavedcola@gmail.com> --------- Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
8129cf45b4
commit
236aee99d8
|
@ -124,16 +124,14 @@ impl<'a, 'info> DepositCommon<'a, 'info> {
|
|||
// Since depositing can only increase health, we can skip the usual pre-health computation.
|
||||
// Also, TokenDeposit is one of the rare instructions that is allowed even during being_liquidated.
|
||||
// Being in a health region always means being_liquidated is false, so it's safe to gate the check.
|
||||
if !account.fixed.is_in_health_region() {
|
||||
let was_being_liquidated = account.being_liquidated();
|
||||
if !account.fixed.is_in_health_region() && was_being_liquidated {
|
||||
let health = cache.health(HealthType::LiquidationEnd);
|
||||
msg!("health: {}", health);
|
||||
// Only compute health and check for recovery if not already being liquidated
|
||||
|
||||
let was_being_liquidated = account.being_liquidated();
|
||||
let recovered = account.fixed.maybe_recover_from_being_liquidated(health);
|
||||
require!(
|
||||
!was_being_liquidated || recovered,
|
||||
MangoError::DepositsIntoLiquidatingMustRecover
|
||||
);
|
||||
require!(recovered, MangoError::DepositsIntoLiquidatingMustRecover);
|
||||
}
|
||||
|
||||
// Group level deposit limit on account
|
||||
|
|
Loading…
Reference in New Issue