From 59dd3aa66e8b05df431437383bf7aa39dd7f473e Mon Sep 17 00:00:00 2001 From: microwavedcola1 Date: Wed, 3 Aug 2022 10:37:35 +0200 Subject: [PATCH] insurance fund for trustless vs not trustful Signed-off-by: microwavedcola1 --- .../mango-v4/src/instructions/liq_token_bankruptcy.rs | 1 + programs/mango-v4/src/instructions/token_register.rs | 3 ++- .../src/instructions/token_register_trustless.rs | 3 ++- programs/mango-v4/src/state/mint_info.rs | 9 +++++++-- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/programs/mango-v4/src/instructions/liq_token_bankruptcy.rs b/programs/mango-v4/src/instructions/liq_token_bankruptcy.rs index f5f541da3..13d8a14fa 100644 --- a/programs/mango-v4/src/instructions/liq_token_bankruptcy.rs +++ b/programs/mango-v4/src/instructions/liq_token_bankruptcy.rs @@ -31,6 +31,7 @@ pub struct LiqTokenBankruptcy<'info> { #[account( has_one = group, constraint = liab_mint_info.load()?.token_index == liab_token_index, + constraint = liab_mint_info.load()?.elligible_for_group_insurance_fund() )] pub liab_mint_info: AccountLoader<'info, MintInfo>, diff --git a/programs/mango-v4/src/instructions/token_register.rs b/programs/mango-v4/src/instructions/token_register.rs index 80619e70b..6315e9d84 100644 --- a/programs/mango-v4/src/instructions/token_register.rs +++ b/programs/mango-v4/src/instructions/token_register.rs @@ -153,7 +153,8 @@ pub fn token_register( vaults: Default::default(), oracle: ctx.accounts.oracle.key(), registration_time: Clock::get()?.unix_timestamp, - reserved: [0; 256], + group_insurance_fund: 1, + reserved: [0; 255], }; mint_info.banks[0] = ctx.accounts.bank.key(); diff --git a/programs/mango-v4/src/instructions/token_register_trustless.rs b/programs/mango-v4/src/instructions/token_register_trustless.rs index 78b683db1..74a06a748 100644 --- a/programs/mango-v4/src/instructions/token_register_trustless.rs +++ b/programs/mango-v4/src/instructions/token_register_trustless.rs @@ -123,7 +123,8 @@ pub fn token_register_trustless( vaults: Default::default(), oracle: ctx.accounts.oracle.key(), registration_time: Clock::get()?.unix_timestamp, - reserved: [0; 256], + group_insurance_fund: 0, + reserved: [0; 255], }; mint_info.banks[0] = ctx.accounts.bank.key(); diff --git a/programs/mango-v4/src/state/mint_info.rs b/programs/mango-v4/src/state/mint_info.rs index f16d63584..4552f8e65 100644 --- a/programs/mango-v4/src/state/mint_info.rs +++ b/programs/mango-v4/src/state/mint_info.rs @@ -28,12 +28,13 @@ pub struct MintInfo { pub oracle: Pubkey, pub registration_time: i64, + pub group_insurance_fund: u8, - pub reserved: [u8; 256], + pub reserved: [u8; 255], } const_assert_eq!( size_of::(), - MAX_BANKS * 2 * 32 + 3 * 32 + 2 + 8 + 6 + 256 + MAX_BANKS * 2 * 32 + 3 * 32 + 2 + 8 + 6 + 1 + 255 ); const_assert_eq!(size_of::() % 8, 0); @@ -67,4 +68,8 @@ impl MintInfo { ); Ok(()) } + + pub fn elligible_for_group_insurance_fund(&self) -> bool { + self.group_insurance_fund == 1 + } }