Skip to content

Commit

Permalink
chore: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
LevBeta committed Jul 3, 2024
1 parent c89df4c commit 30567ce
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
9 changes: 6 additions & 3 deletions src/cli/entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use crate::{
transaction_manager::{BatchTransactions, TransactionManager},
};
use log::{error, info};
use std::{collections::HashMap, sync::{atomic::AtomicBool, Arc}};
use std::{
collections::HashMap,
sync::{atomic::AtomicBool, Arc},
};

pub async fn run_liquidator(config: Eva01Config) -> anyhow::Result<()> {
info!("Starting eva01 liquidator! {:#?}", &config);
Expand Down Expand Up @@ -36,7 +39,7 @@ pub async fn run_liquidator(config: Eva01Config) -> anyhow::Result<()> {
config.liquidator_config.clone(),
liquidator_rx.clone(),
transaction_tx.clone(),
stop_liquidator.clone()
stop_liquidator.clone(),
)
.await;

Expand All @@ -46,7 +49,7 @@ pub async fn run_liquidator(config: Eva01Config) -> anyhow::Result<()> {
config.rebalancer_config.clone(),
transaction_tx.clone(),
rebalancer_rx.clone(),
stop_liquidator.clone()
stop_liquidator.clone(),
)
.await?;

Expand Down
21 changes: 15 additions & 6 deletions src/liquidator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use crate::{
};
use anchor_client::Program;
use anchor_lang::Discriminator;
use crossbeam::{channel::{Receiver, Sender}, epoch::Atomic};
use crossbeam::{
channel::{Receiver, Sender},
epoch::Atomic,
};
use fixed::types::I80F48;
use fixed_macro::types::I80F48;
use log::{debug, error, info};
Expand All @@ -31,7 +34,11 @@ use solana_client::{
};
use solana_program::pubkey::Pubkey;
use solana_sdk::{account_info::IntoAccountInfo, bs58, signature::Keypair};
use std::{cmp::min, collections::HashMap, sync::{atomic::AtomicBool, Arc}};
use std::{
cmp::min,
collections::HashMap,
sync::{atomic::AtomicBool, Arc},
};

/// Bank group private key offset
const BANK_GROUP_PK_OFFSET: usize = 32 + 1 + 8;
Expand Down Expand Up @@ -111,7 +118,7 @@ impl Liquidator {
banks: HashMap::new(),
liquidator_account,
oracle_to_bank: HashMap::new(),
stop_liquidation
stop_liquidation,
}
}

Expand Down Expand Up @@ -165,11 +172,13 @@ impl Liquidator {
};

if start.elapsed() > max_duration {
if self.stop_liquidation.load(std::sync::atomic::Ordering::Relaxed) {
if self
.stop_liquidation
.load(std::sync::atomic::Ordering::Relaxed)
{
break;
}
if let Ok(mut accounts) = self.process_all_accounts() {

if let Ok(mut accounts) = self.process_all_accounts() {
// Accounts are sorted from the highest profit to the lowest
accounts.sort_by(|a, b| a.profit.cmp(&b.profit));
accounts.reverse();
Expand Down
11 changes: 8 additions & 3 deletions src/rebalancer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,16 @@ impl Rebalancer {
// If our margin is at 50% or lower, we should stop liquidations and await until the account
// is fully rebalanced
pub async fn should_stop_liquidations(&self) -> anyhow::Result<()> {
let (assets, liabs) = self.calc_health(&self.liquidator_account.account_wrapper, RequirementType::Initial);
let (assets, liabs) = self.calc_health(
&self.liquidator_account.account_wrapper,
RequirementType::Initial,
);
if (assets - liabs) / assets <= 0.5 {
self.stop_liquidations.store(true, std::sync::atomic::Ordering::Relaxed);
self.stop_liquidations
.store(true, std::sync::atomic::Ordering::Relaxed);
} else {
self.stop_liquidations.store(false, std::sync::atomic::Ordering::Relaxed);
self.stop_liquidations
.store(false, std::sync::atomic::Ordering::Relaxed);
}
Ok(())
}
Expand Down

0 comments on commit 30567ce

Please sign in to comment.