Skip to content

Commit

Permalink
chore: Add logging to liquidation-bot
Browse files Browse the repository at this point in the history
  • Loading branch information
kovipu committed Feb 11, 2025
1 parent b95eba2 commit 7f38ea3
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 7 deletions.
150 changes: 148 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions liquidation-bot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ edition = "2021"
[dependencies]
diesel = { version = "2.2.6", features = ["postgres"] }
dotenvy = "0.15"
log = "0.4.25"
env_logger = "0.11.6"
16 changes: 11 additions & 5 deletions liquidation-bot/src/bin/liquidation_bot.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::time;
use log::{error, info, warn};
use std::thread;

use self::models::*;
Expand All @@ -9,27 +10,32 @@ const SLEEP_TIME_SECONDS: u64 = 10;

fn main() {
let connection = &mut establish_connection();
env_logger::init();

info!("This is an info message");
warn!("This is a warning message");
error!("This is an error message");

loop {
get_new_loans();
get_prices();
find_liquidateable(connection);
attempt_liquidating();

println!("Sleeping for {SLEEP_TIME_SECONDS} seconds.");
info!("Sleeping for {SLEEP_TIME_SECONDS} seconds.");
thread::sleep(time::Duration::from_secs(SLEEP_TIME_SECONDS))
}
}

fn get_new_loans() {
// TODO: fetch loans from Loan Manager
// TODO: push new loans to the DB.
println!("Fetching new loans from Loan Manager.")
info!("Fetching new loans from Loan Manager.")
}

fn get_prices() {
// TODO: fetch and return token prices from CoinGecko
println!("Getting prices from CoinGecko.")
info!("Getting prices from CoinGecko.")
}

fn find_liquidateable(connection: &mut PgConnection /*prices: Prices*/) {
Expand All @@ -41,9 +47,9 @@ fn find_liquidateable(connection: &mut PgConnection /*prices: Prices*/) {
.load(connection)
.expect("Error loading loans");

println!("Displaying {} loans.", results.len());
info!("Displaying {} loans.", results.len());
for loan in results {
println!("{}", loan.id);
info!("{}", loan.id);
}

// TODO: calculate the health of each loan and return the unhealthy ones
Expand Down

0 comments on commit 7f38ea3

Please sign in to comment.