liq_token_bankruptcy: don't pass redundant index

This commit is contained in:
Christian Kamm 2022-08-16 09:51:01 +02:00
parent e92561d32e
commit 54222c5b3f
7 changed files with 8 additions and 33 deletions

View File

@ -4,7 +4,7 @@ Update this for each mainnet deployment.
## not on mainnet
-
- liq_token_bankruptcy: removed liab_token_index argument
## mainnet

View File

@ -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)

View File

@ -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<LiqTokenBankruptcy>,
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

View File

@ -337,10 +337,9 @@ pub mod mango_v4 {
pub fn liq_token_bankruptcy(
ctx: Context<LiqTokenBankruptcy>,
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)
}
///

View File

@ -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;

View File

@ -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),
},

View File

@ -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": {