Skip to content

Commit

Permalink
chore: remove obsolete arg
Browse files Browse the repository at this point in the history
  • Loading branch information
losman0s committed Nov 20, 2023
1 parent ba1f392 commit 4cc88f3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn lending_account_borrow(ctx: Context<LendingAccountBorrow>, 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(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -348,12 +346,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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,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(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@ pub fn lending_pool_handle_bankruptcy(ctx: Context<LendingPoolHandleBankruptcy>)

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(),
)?;
Expand Down
28 changes: 9 additions & 19 deletions programs/marginfi/src/state/marginfi_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ impl<'a, 'b> BankAccountWithPriceFeed<'a, 'b> {
pub fn calc_assets_and_liabilities_values(
&self,
weight_type: Option<WeightType>,
current_timestamp: i64,
) -> MarginfiResult<(I80F48, I80F48)> {
let (worst_price, best_price) = self.price_feed.get_price_range()?;
let bank_al = AccountLoader::<Bank>::try_from(&self.bank)?;
Expand Down Expand Up @@ -357,7 +356,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;
Expand All @@ -376,14 +374,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| {
Expand All @@ -405,20 +400,16 @@ impl<'a, 'b> RiskEngine<'a, 'b> {
current_timestamp: i64,
) -> MarginfiResult<I80F48> {
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: {}",
Expand Down Expand Up @@ -462,8 +453,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!())?;

Expand Down Expand Up @@ -496,7 +487,6 @@ impl<'a, 'b> RiskEngine<'a, 'b> {
&self,
bank_pk: &Pubkey,
pre_liquidation_health: I80F48,
current_timestamp: i64,
) -> MarginfiResult<I80F48> {
let liability_bank_balance = self
.bank_accounts_with_price
Expand All @@ -518,8 +508,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!())?;

Expand Down

0 comments on commit 4cc88f3

Please sign in to comment.