Add explicit self-liquidation checks (#427)
Just for safety, the other conditions and borrowing pattern would already make it impossible.
This commit is contained in:
parent
50c820ddce
commit
bac15698e6
|
@ -45,6 +45,7 @@ pub fn perp_liq_base_position(
|
|||
) -> Result<()> {
|
||||
let group_pk = &ctx.accounts.group.key();
|
||||
|
||||
require_keys_neq!(ctx.accounts.liqor.key(), ctx.accounts.liqee.key());
|
||||
let mut liqor = ctx.accounts.liqor.load_full_mut()?;
|
||||
// account constraint #1
|
||||
require!(
|
||||
|
|
|
@ -84,12 +84,6 @@ pub fn perp_liq_quote_and_bankruptcy(
|
|||
) -> Result<()> {
|
||||
let mango_group = ctx.accounts.group.key();
|
||||
|
||||
// Cannot settle with yourself
|
||||
require!(
|
||||
ctx.accounts.liqor.key() != ctx.accounts.liqee.key(),
|
||||
MangoError::SomeError
|
||||
);
|
||||
|
||||
let (perp_market_index, settle_token_index) = {
|
||||
let perp_market = ctx.accounts.perp_market.load()?;
|
||||
(
|
||||
|
@ -98,6 +92,7 @@ pub fn perp_liq_quote_and_bankruptcy(
|
|||
)
|
||||
};
|
||||
|
||||
require_keys_neq!(ctx.accounts.liqor.key(), ctx.accounts.liqee.key());
|
||||
let mut liqee = ctx.accounts.liqee.load_full_mut()?;
|
||||
let mut liqor = ctx.accounts.liqor.load_full_mut()?;
|
||||
// account constraint #1
|
||||
|
|
|
@ -57,8 +57,9 @@ pub struct PerpSettlePnl<'info> {
|
|||
|
||||
pub fn perp_settle_pnl(ctx: Context<PerpSettlePnl>) -> Result<()> {
|
||||
// Cannot settle with yourself
|
||||
require!(
|
||||
ctx.accounts.account_a.key() != ctx.accounts.account_b.key(),
|
||||
require_keys_neq!(
|
||||
ctx.accounts.account_a.key(),
|
||||
ctx.accounts.account_b.key(),
|
||||
MangoError::CannotSettleWithSelf
|
||||
);
|
||||
|
||||
|
|
|
@ -84,6 +84,8 @@ pub fn token_liq_bankruptcy(
|
|||
let (bank_ais, health_ais) = &ctx.remaining_accounts.split_at(liab_mint_info.num_banks());
|
||||
liab_mint_info.verify_banks_ais(bank_ais)?;
|
||||
|
||||
require_keys_neq!(ctx.accounts.liqor.key(), ctx.accounts.liqee.key());
|
||||
|
||||
let mut liqor = ctx.accounts.liqor.load_full_mut()?;
|
||||
// account constraint #1
|
||||
require!(
|
||||
|
|
|
@ -47,6 +47,7 @@ pub fn token_liq_with_token(
|
|||
let mut account_retriever = ScanningAccountRetriever::new(ctx.remaining_accounts, group_pk)
|
||||
.context("create account retriever")?;
|
||||
|
||||
require_keys_neq!(ctx.accounts.liqor.key(), ctx.accounts.liqee.key());
|
||||
let mut liqor = ctx.accounts.liqor.load_full_mut()?;
|
||||
// account constraint #1
|
||||
require!(
|
||||
|
|
Loading…
Reference in New Issue