From bb7ee03cc755db53d4a069b10573b99b02f48155 Mon Sep 17 00:00:00 2001 From: man0s <95379755+losman0s@users.noreply.github.com> Date: Mon, 20 Nov 2023 15:11:59 +0800 Subject: [PATCH] chore: remove obsolete arg --- .../instructions/marginfi_account/borrow.rs | 5 +-- .../marginfi_account/liquidate.rs | 10 +---- .../instructions/marginfi_account/withdraw.rs | 6 +-- .../marginfi_group/handle_bankruptcy.rs | 6 +-- .../marginfi/src/state/marginfi_account.rs | 44 ++++++++----------- 5 files changed, 27 insertions(+), 44 deletions(-) diff --git a/programs/marginfi/src/instructions/marginfi_account/borrow.rs b/programs/marginfi/src/instructions/marginfi_account/borrow.rs index 08f8bce1..bc7eca85 100644 --- a/programs/marginfi/src/instructions/marginfi_account/borrow.rs +++ b/programs/marginfi/src/instructions/marginfi_account/borrow.rs @@ -33,7 +33,6 @@ pub fn lending_account_borrow(ctx: Context, amount: u64) - .. } = ctx.accounts; - let current_time = Clock::get()?.unix_timestamp; let mut marginfi_account = marginfi_account_loader.load_mut()?; check!( @@ -42,7 +41,7 @@ pub fn lending_account_borrow(ctx: Context, amount: u64) - ); bank_loader.load_mut()?.accrue_interest( - current_time, + Clock::get()?.unix_timestamp, #[cfg(not(feature = "client"))] bank_loader.key(), )?; @@ -89,7 +88,7 @@ pub fn lending_account_borrow(ctx: Context, amount: u64) - // Check account health, if below threshold fail transaction // Assuming `ctx.remaining_accounts` holds only oracle accounts RiskEngine::new(&marginfi_account, ctx.remaining_accounts)? - .check_account_health(RiskRequirementType::Initial, current_time)?; + .check_account_health(RiskRequirementType::Initial)?; Ok(()) } diff --git a/programs/marginfi/src/instructions/marginfi_account/liquidate.rs b/programs/marginfi/src/instructions/marginfi_account/liquidate.rs index 05127480..ee6f4704 100644 --- a/programs/marginfi/src/instructions/marginfi_account/liquidate.rs +++ b/programs/marginfi/src/instructions/marginfi_account/liquidate.rs @@ -89,8 +89,6 @@ pub fn lending_account_liquidate( .. } = ctx.accounts; - let current_timestamp = Clock::get()?.unix_timestamp; - let mut liquidator_marginfi_account = liquidator_marginfi_account_loader.load_mut()?; let mut liquidatee_marginfi_account = liquidatee_marginfi_account_loader.load_mut()?; let current_timestamp = Clock::get()?.unix_timestamp; @@ -115,10 +113,7 @@ pub fn lending_account_liquidate( &ctx.remaining_accounts[liquidatee_accounts_starting_pos..]; RiskEngine::new(&liquidatee_marginfi_account, liquidatee_remaining_accounts)? - .check_pre_liquidation_condition_and_get_account_health( - &ctx.accounts.liab_bank.key(), - current_timestamp, - )? + .check_pre_liquidation_condition_and_get_account_health(&ctx.accounts.liab_bank.key())? }; // ##Accounting changes## @@ -348,12 +343,11 @@ pub fn lending_account_liquidate( .check_post_liquidation_condition_and_get_account_health( &ctx.accounts.liab_bank.key(), pre_liquidation_health, - current_timestamp, )?; // Verify liquidator account health RiskEngine::new(&liquidator_marginfi_account, liquidator_remaining_accounts)? - .check_account_health(RiskRequirementType::Initial, current_timestamp)?; + .check_account_health(RiskRequirementType::Initial)?; emit!(LendingAccountLiquidateEvent { header: AccountEventHeader { diff --git a/programs/marginfi/src/instructions/marginfi_account/withdraw.rs b/programs/marginfi/src/instructions/marginfi_account/withdraw.rs index 2412b7f0..afae7864 100644 --- a/programs/marginfi/src/instructions/marginfi_account/withdraw.rs +++ b/programs/marginfi/src/instructions/marginfi_account/withdraw.rs @@ -37,8 +37,6 @@ pub fn lending_account_withdraw( .. } = ctx.accounts; - let current_timestamp = Clock::get()?.unix_timestamp; - let withdraw_all = withdraw_all.unwrap_or(false); let mut marginfi_account = marginfi_account_loader.load_mut()?; @@ -48,7 +46,7 @@ pub fn lending_account_withdraw( ); bank_loader.load_mut()?.accrue_interest( - current_timestamp, + Clock::get()?.unix_timestamp, #[cfg(not(feature = "client"))] bank_loader.key(), )?; @@ -103,7 +101,7 @@ pub fn lending_account_withdraw( // Check account health, if below threshold fail transaction // Assuming `ctx.remaining_accounts` holds only oracle accounts RiskEngine::new(&marginfi_account, ctx.remaining_accounts)? - .check_account_health(RiskRequirementType::Initial, current_timestamp)?; + .check_account_health(RiskRequirementType::Initial)?; Ok(()) } diff --git a/programs/marginfi/src/instructions/marginfi_group/handle_bankruptcy.rs b/programs/marginfi/src/instructions/marginfi_group/handle_bankruptcy.rs index d71979c0..315a3fd1 100644 --- a/programs/marginfi/src/instructions/marginfi_group/handle_bankruptcy.rs +++ b/programs/marginfi/src/instructions/marginfi_group/handle_bankruptcy.rs @@ -34,14 +34,12 @@ pub fn lending_pool_handle_bankruptcy(ctx: Context) let mut marginfi_account = marginfi_account_loader.load_mut()?; - let current_time = Clock::get()?.unix_timestamp; - RiskEngine::new(&marginfi_account, ctx.remaining_accounts)? - .check_account_bankrupt(current_time)?; + RiskEngine::new(&marginfi_account, ctx.remaining_accounts)?.check_account_bankrupt()?; let mut bank = bank_loader.load_mut()?; bank.accrue_interest( - current_time, + Clock::get()?.unix_timestamp, #[cfg(not(feature = "client"))] bank_loader.key(), )?; diff --git a/programs/marginfi/src/state/marginfi_account.rs b/programs/marginfi/src/state/marginfi_account.rs index 09124f96..9453ef74 100644 --- a/programs/marginfi/src/state/marginfi_account.rs +++ b/programs/marginfi/src/state/marginfi_account.rs @@ -189,7 +189,6 @@ impl<'a, 'b> BankAccountWithPriceFeed<'a, 'b> { pub fn calc_assets_and_liabilities_values( &self, weight_type: Option, - current_timestamp: i64, ) -> MarginfiResult<(I80F48, I80F48)> { let (worst_price, best_price) = self.price_feed.get_price_range()?; let bank_al = AccountLoader::::try_from(&self.bank)?; @@ -279,6 +278,13 @@ pub fn calc_asset_value( asset_amount }; + msg!( + "weighted_asset_qt: {}, price: {}, expo: {}", + weighted_asset_amount, + price, + mint_decimals + ); + let asset_value = weighted_asset_amount .checked_mul(price) .ok_or_else(math_error!())? @@ -330,11 +336,10 @@ impl<'a, 'b> RiskEngine<'a, 'b> { marginfi_account: &'a MarginfiAccount, remaining_ais: &[AccountInfo<'b>], ) -> MarginfiResult { + let bank_accounts_with_price = + BankAccountWithPriceFeed::load(&marginfi_account.lending_account, remaining_ais)?; Ok(Self { - bank_accounts_with_price: BankAccountWithPriceFeed::load( - &marginfi_account.lending_account, - remaining_ais, - )?, + bank_accounts_with_price, }) } @@ -357,7 +362,6 @@ impl<'a, 'b> RiskEngine<'a, 'b> { pub fn get_account_health_components( &self, requirement_type: RiskRequirementType, - current_timestamp: i64, ) -> MarginfiResult<(I80F48, I80F48)> { let mut total_assets = I80F48::ZERO; let mut total_liabilities = I80F48::ZERO; @@ -376,14 +380,11 @@ impl<'a, 'b> RiskEngine<'a, 'b> { } #[cfg(feature = "client")] - pub fn get_equity_components( - &self, - current_timestamp: i64, - ) -> MarginfiResult<(I80F48, I80F48)> { + pub fn get_equity_components(&self) -> MarginfiResult<(I80F48, I80F48)> { Ok(self .bank_accounts_with_price .iter() - .map(|a| a.calc_assets_and_liabilities_values(None, current_timestamp)) + .map(|a| a.calc_assets_and_liabilities_values(None)) .try_fold( (I80F48::ZERO, I80F48::ZERO), |(total_assets, total_liabilities), res| { @@ -402,23 +403,18 @@ impl<'a, 'b> RiskEngine<'a, 'b> { pub fn get_account_health( &self, requirement_type: RiskRequirementType, - current_timestamp: i64, ) -> MarginfiResult { let (total_weighted_assets, total_weighted_liabilities) = - self.get_account_health_components(requirement_type, current_timestamp)?; + self.get_account_health_components(requirement_type)?; Ok(total_weighted_assets .checked_sub(total_weighted_liabilities) .ok_or_else(math_error!())?) } - pub fn check_account_health( - &self, - requirement_type: RiskRequirementType, - current_timestamp: i64, - ) -> MarginfiResult { + pub fn check_account_health(&self, requirement_type: RiskRequirementType) -> MarginfiResult { let (total_weighted_assets, total_weighted_liabilities) = - self.get_account_health_components(requirement_type, current_timestamp)?; + self.get_account_health_components(requirement_type)?; msg!( "check_health: assets {} - liabs: {}", @@ -442,7 +438,6 @@ impl<'a, 'b> RiskEngine<'a, 'b> { pub fn check_pre_liquidation_condition_and_get_account_health( &self, bank_pk: &Pubkey, - current_timestamp: i64, ) -> MarginfiResult { let liability_bank_balance = self .bank_accounts_with_price @@ -462,8 +457,8 @@ impl<'a, 'b> RiskEngine<'a, 'b> { MarginfiError::IllegalLiquidation ); - let (assets, liabs) = self - .get_account_health_components(RiskRequirementType::Maintenance, current_timestamp)?; + let (assets, liabs) = + self.get_account_health_components(RiskRequirementType::Maintenance)?; let account_health = assets.checked_sub(liabs).ok_or_else(math_error!())?; @@ -496,7 +491,6 @@ impl<'a, 'b> RiskEngine<'a, 'b> { &self, bank_pk: &Pubkey, pre_liquidation_health: I80F48, - current_timestamp: i64, ) -> MarginfiResult { let liability_bank_balance = self .bank_accounts_with_price @@ -518,8 +512,8 @@ impl<'a, 'b> RiskEngine<'a, 'b> { "Liability payoff too severe" ); - let (assets, liabs) = self - .get_account_health_components(RiskRequirementType::Maintenance, current_timestamp)?; + let (assets, liabs) = + self.get_account_health_components(RiskRequirementType::Maintenance)?; let account_health = assets.checked_sub(liabs).ok_or_else(math_error!())?;