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 8f10b62
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 45 deletions.
2 changes: 1 addition & 1 deletion observability/indexer/src/utils/transactions_crawler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::Result;
use chrono::{Local, TimeZone};
use concurrent_queue::ConcurrentQueue;
use futures::{future::join_all, stream, Future, StreamExt};
use log::{error, info, warn};
use solana_client::{
nonblocking::rpc_client::RpcClient, rpc_client::GetConfirmedSignaturesForAddress2Config,
rpc_config::RpcTransactionConfig,
Expand All @@ -22,7 +23,6 @@ use std::{
};
use std::{str::FromStr, time::Duration};
use tokio::{join, runtime::Builder};
use tracing::{error, info, warn};

use crate::common::{
Target, DEFAULT_MAX_PENDING_SIGNATURES, DEFAULT_MONITOR_INTERVAL, DEFAULT_RPC_ENDPOINT,
Expand Down
5 changes: 2 additions & 3 deletions programs/marginfi/src/instructions/marginfi_account/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub fn lending_account_borrow(ctx: Context<LendingAccountBorrow>, amount: u64) -
..
} = ctx.accounts;

let current_time = Clock::get()?.unix_timestamp;
let mut marginfi_account = marginfi_account_loader.load_mut()?;

check!(
Expand All @@ -42,7 +41,7 @@ pub fn lending_account_borrow(ctx: Context<LendingAccountBorrow>, amount: u64) -
);

bank_loader.load_mut()?.accrue_interest(
current_time,
Clock::get()?.unix_timestamp,
#[cfg(not(feature = "client"))]
bank_loader.key(),
)?;
Expand Down Expand Up @@ -89,7 +88,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
10 changes: 2 additions & 8 deletions programs/marginfi/src/instructions/marginfi_account/liquidate.rs
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 All @@ -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##
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;

Expand All @@ -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(),
)?;
Expand Down Expand Up @@ -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(())
}
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
44 changes: 19 additions & 25 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 @@ -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!())?
Expand Down Expand Up @@ -330,11 +336,10 @@ impl<'a, 'b> RiskEngine<'a, 'b> {
marginfi_account: &'a MarginfiAccount,
remaining_ais: &[AccountInfo<'b>],
) -> MarginfiResult<Self> {
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,
})
}

Expand All @@ -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;
Expand All @@ -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| {
Expand All @@ -402,23 +403,18 @@ impl<'a, 'b> RiskEngine<'a, 'b> {
pub fn get_account_health(
&self,
requirement_type: RiskRequirementType,
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 All @@ -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<I80F48> {
let liability_bank_balance = self
.bank_accounts_with_price
Expand All @@ -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!())?;

Expand Down Expand Up @@ -496,7 +491,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 +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!())?;

Expand Down

0 comments on commit 8f10b62

Please sign in to comment.