From 54222c5b3fcf10d8258b10b82c48db3dbe8ad37e Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Tue, 16 Aug 2022 09:51:01 +0200 Subject: [PATCH] liq_token_bankruptcy: don't pass redundant index --- CHANGELOG.md | 2 +- client/src/client.rs | 5 +---- .../src/instructions/liq_token_bankruptcy.rs | 14 ++++---------- programs/mango-v4/src/lib.rs | 3 +-- .../mango-v4/tests/program_test/mango_client.rs | 4 +--- programs/mango-v4/tests/test_bankrupt_tokens.rs | 5 ----- ts/client/src/mango_v4.ts | 8 -------- 7 files changed, 8 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28b488cf3..3d049b6bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Update this for each mainnet deployment. ## not on mainnet -- +- liq_token_bankruptcy: removed liab_token_index argument ## mainnet diff --git a/client/src/client.rs b/client/src/client.rs index e286d34f1..cd032e948 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -873,10 +873,7 @@ impl MangoClient { ams }, data: anchor_lang::InstructionData::data( - &mango_v4::instruction::LiqTokenBankruptcy { - liab_token_index, - max_liab_transfer, - }, + &mango_v4::instruction::LiqTokenBankruptcy { max_liab_transfer }, ), }) .signer(&self.owner) diff --git a/programs/mango-v4/src/instructions/liq_token_bankruptcy.rs b/programs/mango-v4/src/instructions/liq_token_bankruptcy.rs index d3c848af6..7622ff7cc 100644 --- a/programs/mango-v4/src/instructions/liq_token_bankruptcy.rs +++ b/programs/mango-v4/src/instructions/liq_token_bankruptcy.rs @@ -11,10 +11,9 @@ use crate::state::*; use crate::util::checked_math as cm; // Remaining accounts: -// - all banks for liab_token_index (writable) +// - all banks for liab_mint_info (writable) // - merged health accounts for liqor+liqee #[derive(Accounts)] -#[instruction(liab_token_index: TokenIndex)] pub struct LiqTokenBankruptcy<'info> { #[account( has_one = insurance_vault, @@ -37,7 +36,6 @@ pub struct LiqTokenBankruptcy<'info> { #[account( has_one = group, - constraint = liab_mint_info.load()?.token_index == liab_token_index, )] pub liab_mint_info: AccountLoader<'info, MintInfo>, @@ -67,7 +65,6 @@ impl<'info> LiqTokenBankruptcy<'info> { pub fn liq_token_bankruptcy( ctx: Context, - liab_token_index: TokenIndex, max_liab_transfer: I80F48, ) -> Result<()> { let group = ctx.accounts.group.load()?; @@ -75,12 +72,9 @@ pub fn liq_token_bankruptcy( // split remaining accounts into banks and health let liab_mint_info = ctx.accounts.liab_mint_info.load()?; - let bank_pks = liab_mint_info.banks(); - let (bank_ais, health_ais) = &ctx.remaining_accounts.split_at(bank_pks.len()); - require!( - bank_ais.iter().map(|ai| ai.key).eq(bank_pks.iter()), - MangoError::SomeError - ); + let liab_token_index = liab_mint_info.token_index; + let (bank_ais, health_ais) = &ctx.remaining_accounts.split_at(liab_mint_info.num_banks()); + liab_mint_info.verify_banks_ais(bank_ais)?; let mut liqor = ctx.accounts.liqor.load_mut()?; // account constraint #1 diff --git a/programs/mango-v4/src/lib.rs b/programs/mango-v4/src/lib.rs index 2f7082231..5a384200f 100644 --- a/programs/mango-v4/src/lib.rs +++ b/programs/mango-v4/src/lib.rs @@ -337,10 +337,9 @@ pub mod mango_v4 { pub fn liq_token_bankruptcy( ctx: Context, - liab_token_index: TokenIndex, max_liab_transfer: I80F48, ) -> Result<()> { - instructions::liq_token_bankruptcy(ctx, liab_token_index, max_liab_transfer) + instructions::liq_token_bankruptcy(ctx, max_liab_transfer) } /// diff --git a/programs/mango-v4/tests/program_test/mango_client.rs b/programs/mango-v4/tests/program_test/mango_client.rs index 949499b43..1eb122d64 100644 --- a/programs/mango-v4/tests/program_test/mango_client.rs +++ b/programs/mango-v4/tests/program_test/mango_client.rs @@ -1953,7 +1953,6 @@ pub struct LiqTokenBankruptcyInstruction<'keypair> { pub liqor: Pubkey, pub liqor_owner: &'keypair Keypair, - pub liab_token_index: TokenIndex, pub max_liab_transfer: I80F48, pub liab_mint_info: Pubkey, } @@ -1967,7 +1966,6 @@ impl<'keypair> ClientInstruction for LiqTokenBankruptcyInstruction<'keypair> { ) -> (Self::Accounts, instruction::Instruction) { let program_id = mango_v4::id(); let instruction = Self::Instruction { - liab_token_index: self.liab_token_index, max_liab_transfer: self.max_liab_transfer, }; @@ -1986,7 +1984,7 @@ impl<'keypair> ClientInstruction for LiqTokenBankruptcyInstruction<'keypair> { &liqor, QUOTE_TOKEN_INDEX, 0, - self.liab_token_index, + liab_mint_info.token_index, 0, ) .await; diff --git a/programs/mango-v4/tests/test_bankrupt_tokens.rs b/programs/mango-v4/tests/test_bankrupt_tokens.rs index 01b54c4b8..69cff8a1f 100644 --- a/programs/mango-v4/tests/test_bankrupt_tokens.rs +++ b/programs/mango-v4/tests/test_bankrupt_tokens.rs @@ -257,7 +257,6 @@ async fn test_bankrupt_tokens_socialize_loss() -> Result<(), TransportError> { liqee: account, liqor: vault_account, liqor_owner: owner, - liab_token_index: borrow_token1.index, liab_mint_info: borrow_token1.mint_info, max_liab_transfer: I80F48::from_num(100000.0), }, @@ -283,7 +282,6 @@ async fn test_bankrupt_tokens_socialize_loss() -> Result<(), TransportError> { liqee: account, liqor: vault_account, liqor_owner: owner, - liab_token_index: borrow_token2.index, liab_mint_info: borrow_token2.mint_info, max_liab_transfer: I80F48::from_num(100000.0), }, @@ -562,7 +560,6 @@ async fn test_bankrupt_tokens_insurance_fund() -> Result<(), TransportError> { liqee: account, liqor: vault_account, liqor_owner: owner, - liab_token_index: borrow_token1.index, liab_mint_info: borrow_token1.mint_info, max_liab_transfer: I80F48::from_num(100000.0), }, @@ -594,7 +591,6 @@ async fn test_bankrupt_tokens_insurance_fund() -> Result<(), TransportError> { liqee: account, liqor: vault_account, liqor_owner: owner, - liab_token_index: borrow_token2.index, liab_mint_info: borrow_token2.mint_info, max_liab_transfer: I80F48::from_num(liab_transfer), }, @@ -628,7 +624,6 @@ async fn test_bankrupt_tokens_insurance_fund() -> Result<(), TransportError> { liqee: account, liqor: vault_account, liqor_owner: owner, - liab_token_index: borrow_token2.index, liab_mint_info: borrow_token2.mint_info, max_liab_transfer: I80F48::from_num(1000000.0), }, diff --git a/ts/client/src/mango_v4.ts b/ts/client/src/mango_v4.ts index a14e1a704..16383d1a6 100644 --- a/ts/client/src/mango_v4.ts +++ b/ts/client/src/mango_v4.ts @@ -2004,10 +2004,6 @@ export type MangoV4 = { } ], "args": [ - { - "name": "liabTokenIndex", - "type": "u16" - }, { "name": "maxLiabTransfer", "type": { @@ -7040,10 +7036,6 @@ export const IDL: MangoV4 = { } ], "args": [ - { - "name": "liabTokenIndex", - "type": "u16" - }, { "name": "maxLiabTransfer", "type": {