Review fixes
This commit is contained in:
parent
b25f6d5f4f
commit
35517bdb75
|
@ -24,9 +24,9 @@ pub struct LiqTokenBankruptcy<'info> {
|
|||
#[account(
|
||||
mut,
|
||||
has_one = group,
|
||||
constraint = liqor.load()?.is_owner_or_delegate(liqor_owner.key()),
|
||||
)]
|
||||
pub liqor: AccountLoader<'info, MangoAccount>,
|
||||
#[account(address = liqor.load()?.owner)]
|
||||
pub liqor_owner: Signer<'info>,
|
||||
|
||||
#[account(
|
||||
|
@ -160,8 +160,9 @@ pub fn liq_token_bankruptcy(
|
|||
liqor.tokens.deactivate(liqor_liab_raw_token_index);
|
||||
}
|
||||
} else {
|
||||
// This happens when asset_token_index == liab_token_index: the insurance fund
|
||||
// deposits directly into liqee, without a fee or the liqor indirection
|
||||
// For liab_token_index == QUOTE_TOKEN_INDEX: the insurance fund deposits directly into liqee,
|
||||
// without a fee or the liqor being involved
|
||||
require_eq!(liab_token_index, QUOTE_TOKEN_INDEX);
|
||||
require_eq!(liab_price_adjusted, I80F48::ONE);
|
||||
require_eq!(insurance_transfer_i80f48, liab_transfer);
|
||||
}
|
||||
|
@ -177,8 +178,10 @@ pub fn liq_token_bankruptcy(
|
|||
indexed_total_deposits = cm!(indexed_total_deposits + bank.indexed_deposits);
|
||||
}
|
||||
|
||||
// TODO: what if loss is greater than entire deposits?
|
||||
// total_indexed_deposits * (deposit_index - new_deposit_index) = remaining_liab_loss
|
||||
// This is the solution to:
|
||||
// total_indexed_deposits * (deposit_index - new_deposit_index) = remaining_liab_loss
|
||||
// AUDIT: Could it happen that remaining_liab_loss > total_indexed_deposits * deposit_index?
|
||||
// Probably not.
|
||||
let new_deposit_index =
|
||||
cm!(liab_deposit_index - remaining_liab_loss / indexed_total_deposits);
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ pub struct LiqTokenWithToken<'info> {
|
|||
#[account(
|
||||
mut,
|
||||
has_one = group,
|
||||
constraint = liqor.load()?.owner == liqor_owner.key() || liqor.load()?.delegate == liqor_owner.key(),
|
||||
constraint = liqor.load()?.is_owner_or_delegate(liqor_owner.key()),
|
||||
)]
|
||||
pub liqor: AccountLoader<'info, MangoAccount>,
|
||||
pub liqor_owner: Signer<'info>,
|
||||
|
|
|
@ -518,10 +518,9 @@ impl HealthCache {
|
|||
}
|
||||
|
||||
pub fn has_borrows(&self) -> bool {
|
||||
let spot_borrows = self
|
||||
.token_infos
|
||||
.iter()
|
||||
.any(|ti| ti.balance < -BANKRUPTCY_DUST_THRESHOLD);
|
||||
// AUDIT: Can we really guarantee that liquidation/bankruptcy resolution always leaves
|
||||
// non-negative balances?
|
||||
let spot_borrows = self.token_infos.iter().any(|ti| ti.balance.is_negative());
|
||||
let perp_borrows = self
|
||||
.perp_infos
|
||||
.iter()
|
||||
|
|
|
@ -59,7 +59,10 @@ impl MintInfo {
|
|||
}
|
||||
|
||||
pub fn verify_banks_ais(&self, all_bank_ais: &[AccountInfo]) -> Result<()> {
|
||||
require!(all_bank_ais.iter().map(|ai| ai.key).eq(self.banks().iter()), MangoError::SomeError);
|
||||
require!(
|
||||
all_bank_ais.iter().map(|ai| ai.key).eq(self.banks().iter()),
|
||||
MangoError::SomeError
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ async fn test_delegate() -> Result<(), TransportError> {
|
|||
// SETUP: Create a group, register a token (mint0), create an account
|
||||
//
|
||||
|
||||
let mango_setup::GroupWithTokens { group, tokens } = mango_setup::GroupWithTokensConfig {
|
||||
let mango_setup::GroupWithTokens { group, tokens, .. } = mango_setup::GroupWithTokensConfig {
|
||||
admin,
|
||||
payer,
|
||||
mints,
|
||||
|
|
Loading…
Reference in New Issue