Skip to content

Commit

Permalink
sys-lend: add --skip-if-only-one-pool-remains flag to withdraw
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Apr 29, 2024
1 parent f3eb7e4 commit dc42a08
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/bin/sys-lend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.possible_values(&pools)
.help("Lending pool to withdraw from. If multiple pools are provided, the pool with the lowest APY is selected"),
)
.arg(
Arg::with_name("skip_withdraw_if_only_one_pool_remains")
.long("skip-if-only-one-pool-remains")
.takes_value(false)
.help("Do not withdraw if only one lending pool remains"),
)
.arg(
Arg::with_name("signer")
.value_name("KEYPAIR")
Expand Down Expand Up @@ -303,6 +309,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (signer, address) = signer_of(matches, "signer", &mut wallet_manager)?;
let address = address.expect("address");
let signer = signer.expect("signer");
let skip_withdraw_if_only_one_pool_remains = matches.is_present("skip_withdraw_if_only_one_pool_remains");

let token = MaybeToken::from(value_t!(matches, "token", Token).ok());
let pools = values_t_or_exit!(matches, "pool", String);
Expand Down Expand Up @@ -360,6 +367,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
return Err("No available pools".into());
}

if skip_withdraw_if_only_one_pool_remains && pools.len() == 1 {
println!("Taking no action due to --skip-if-only-one-pool-remains flag");
return Ok(());
}

let ordering = if op == Operation::Deposit {
std::cmp::Ordering::Less
} else {
Expand Down

0 comments on commit dc42a08

Please sign in to comment.