Skip to content

Commit

Permalink
Generalize error message
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed May 27, 2024
1 parent 47099ae commit 7dfdc41
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/bin/sys-lend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,26 +512,37 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.unwrap_or_else(|| supported_pools_for_token(token));

is_token_supported(&token, &pools)?;
for pool in pools {
let amount = pool_supply_balance(&rpc_client, &pool, token, address)?;
let apr = pool_supply_apr(&rpc_client, &pool, token)?;

let mut total_amount = 0;
let mut non_empty_pools_count = 0;
for pool in &pools {
let amount = pool_supply_balance(&rpc_client, pool, token, address)?;
let apr = pool_supply_apr(&rpc_client, pool, token)?;

let msg = format!(
"{:>15}: {} supplied at {:.2}%",
pool,
token.format_amount(amount),
apr_to_apy(apr) * 100.
);
if amount > 0 {
non_empty_pools_count += 1;
total_amount += amount;
}
notifier.send(&msg).await;
metrics::push(dp::supply_balance(
&pool,
pool,
&address,
token,
token.ui_amount(amount),
))
.await;
println!("{msg}");
}

if non_empty_pools_count > 1 {
println!("\nTotal supply: {}", token.format_amount(total_amount));
}
}
("deposit" | "withdraw" | "rebalance", Some(matches)) => {
#[derive(PartialEq, Clone, Copy)]
Expand Down Expand Up @@ -780,7 +791,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("{msg}");

if !send_transaction_until_expired(&rpc_client, &transaction, last_valid_block_height) {
let msg = format!("Deposit failed: {signature}");
let msg = format!("Transaction failed: {signature}");
notifier.send(&msg).await;
return Err(msg.into());
}
Expand Down

0 comments on commit 7dfdc41

Please sign in to comment.