Skip to content

Commit

Permalink
fix: print backtrace and handle zero assets
Browse files Browse the repository at this point in the history
  • Loading branch information
jkbpvsc committed Jul 24, 2024
1 parent 9ce2d03 commit a26cf16
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/liquidator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ impl Liquidator {
loop {
let start = std::time::Instant::now();
while let Ok(mut msg) = self.geyser_receiver.recv() {
debug!("Received message {:?}", msg);
match msg.account_type {
AccountType::OracleAccount => {
if let Some(bank_to_update_pk) = self.oracle_to_bank.get(&msg.address) {
Expand Down
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use env_logger::Builder;
use std::error::Error;
use std::{backtrace::Backtrace, error::Error};

/// Geyser service
mod geyser;
Expand Down Expand Up @@ -41,7 +41,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();

std::panic::set_hook(Box::new(|panic_info| {
eprintln!("Panic occurred: {:?}", panic_info);
eprintln!("Panic occurred: {:#?}", panic_info);

eprintln!("Backtrace: {}", Backtrace::capture());

std::process::exit(1);
}));

Expand Down
14 changes: 13 additions & 1 deletion src/rebalancer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use jupiter_swap_api_client::{
transaction_config::{ComputeUnitPriceMicroLamports, TransactionConfig},
JupiterSwapApiClient,
};
use log::info;
use log::{debug, info, warn};
use marginfi::{
constants::EXP_10_I80F48,
state::{
Expand Down Expand Up @@ -180,6 +180,7 @@ impl Rebalancer {
loop {
let start = std::time::Instant::now();
while let Ok(mut msg) = self.geyser_receiver.recv() {
debug!("Received message {:?}", msg);
match msg.account_type {
AccountType::OracleAccount => {
if let Some(bank_to_update_pk) = self.oracle_to_bank.get(&msg.address) {
Expand Down Expand Up @@ -233,6 +234,7 @@ impl Rebalancer {
}

async fn rebalance_accounts(&mut self) -> anyhow::Result<()> {
debug!("Rebalancing accounts");
self.sell_non_preferred_deposits().await?;
self.repay_liabilities().await?;
self.handle_tokens_in_token_accounts().await?;
Expand All @@ -248,6 +250,16 @@ impl Rebalancer {
&self.liquidator_account.account_wrapper,
RequirementType::Initial,
);

if assets.is_zero() {
warn!("Assets are zero, stopping liquidations");

self.stop_liquidations
.store(true, std::sync::atomic::Ordering::Relaxed);

return Ok(());
}

if (assets - liabs) / assets <= 0.5 {
self.stop_liquidations
.store(true, std::sync::atomic::Ordering::Relaxed);
Expand Down

0 comments on commit a26cf16

Please sign in to comment.