From 30567cee48b2093928b23eae21eb55b5c0deae43 Mon Sep 17 00:00:00 2001 From: Beta <105949605+LevBeta@users.noreply.github.com> Date: Wed, 3 Jul 2024 22:41:34 +0100 Subject: [PATCH] chore: fmt --- src/cli/entrypoints.rs | 9 ++++++--- src/liquidator.rs | 21 +++++++++++++++------ src/rebalancer.rs | 11 ++++++++--- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/cli/entrypoints.rs b/src/cli/entrypoints.rs index d5599ea..e277642 100644 --- a/src/cli/entrypoints.rs +++ b/src/cli/entrypoints.rs @@ -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); @@ -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; @@ -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?; diff --git a/src/liquidator.rs b/src/liquidator.rs index a2dac3f..969f057 100644 --- a/src/liquidator.rs +++ b/src/liquidator.rs @@ -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}; @@ -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; @@ -111,7 +118,7 @@ impl Liquidator { banks: HashMap::new(), liquidator_account, oracle_to_bank: HashMap::new(), - stop_liquidation + stop_liquidation, } } @@ -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(); diff --git a/src/rebalancer.rs b/src/rebalancer.rs index 58b028d..38b811f 100644 --- a/src/rebalancer.rs +++ b/src/rebalancer.rs @@ -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(()) }