Skip to content

Commit

Permalink
AUTO fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Jun 10, 2024
1 parent a5380a4 commit d6b9909
Showing 1 changed file with 51 additions and 47 deletions.
98 changes: 51 additions & 47 deletions src/bin/sys-lend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.required(true)
.help("The amount of tokens to withdraw; accepts keyword ALL"),
)
.arg(
Arg::with_name("minimum_ui_amount")
.long("minimum-amount")
.value_name("AMOUNT")
.takes_value(true)
.validator(is_parsable::<f64>)
.default_value("0.0")
.help("Do not withdraw if AMOUNT is less than this value")
)
.arg(
Arg::with_name("token")
.value_name("TOKEN")
Expand Down Expand Up @@ -853,7 +862,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let minimum_apy_bps = value_t!(matches, "minimum_apy", u16).unwrap_or(0);
let minimum_amount = {
let minimum_amount =
maybe_token.amount(value_t!(matches, "minimum_ui_amount", f64).unwrap_or(0.));
maybe_token.amount(value_t_or_exit!(matches, "minimum_ui_amount", f64));
if minimum_amount == 0 {
1
} else {
Expand All @@ -880,16 +889,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
None
}
ui_amount => {
let requested_amount = token.amount(ui_amount.parse::<f64>().unwrap());
if requested_amount < minimum_amount {
return Err(format!(
"Requested amount of {} is too small. Minimum amount is {}",
maybe_token.format_amount(requested_amount),
maybe_token.format_amount(minimum_amount),
)
.into());
}
Some(requested_amount)
Some(token.amount(ui_amount.parse::<f64>().unwrap()))
}
};

Expand Down Expand Up @@ -957,38 +957,30 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let (ops, minimum_op_amount, maximum_op_amount) = match cmd {
Command::Deposit => {
let (minimum_op_amount, maximum_op_amount) = match requested_amount {
None => (minimum_amount, address_token_balance),
Some(u64::MAX) => (address_token_balance, address_token_balance),
Some(requested_amount) => (requested_amount, requested_amount),
};

if maximum_op_amount > address_token_balance {
println!(
"Requested deposit amount of {} is greater than current wallet balance of {}",
maybe_token.format_amount(maximum_op_amount),
maybe_token.format_amount(address_token_balance),
);
return Ok(());
}

if minimum_op_amount > address_token_balance {
if address_token_balance < minimum_amount {
println!(
"Minimum deposit amount of {} is greater than current wallet balance of {}",
maybe_token.format_amount(minimum_op_amount),
maybe_token.format_amount(minimum_amount),
maybe_token.format_amount(address_token_balance),
);
return Ok(());
}

if minimum_op_amount > maximum_op_amount {
println!(
"Minimum deposit amount of {} is greater than requested deposit amount of {}",
maybe_token.format_amount(minimum_op_amount),
maybe_token.format_amount(maximum_op_amount),
);
return Ok(());
}
let (minimum_op_amount, maximum_op_amount) = match requested_amount {
None => (minimum_amount, address_token_balance),
Some(u64::MAX) => (address_token_balance, address_token_balance),
Some(requested_amount) => {
if address_token_balance < requested_amount {
println!(
"Requested deposit amount of {} is greater than current wallet balance of {}",
maybe_token.format_amount(requested_amount),
maybe_token.format_amount(address_token_balance),
);
return Ok(());
}
(requested_amount, requested_amount)
},
};

(
vec![(Operation::Deposit, deposit_pool)],
Expand All @@ -999,23 +991,35 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Command::Withdraw | Command::Rebalance => {
let withdraw_pool_supply_balance = *supply_balance.get(withdraw_pool).unwrap();

let (minimum_op_amount, maximum_op_amount) = match requested_amount {
None => (minimum_amount, withdraw_pool_supply_balance),
Some(u64::MAX) => {
(withdraw_pool_supply_balance, withdraw_pool_supply_balance)
}
Some(requested_amount) => (requested_amount, requested_amount),
};

if maximum_op_amount > withdraw_pool_supply_balance {
if withdraw_pool_supply_balance < minimum_amount {
println!(
"Withdraw amount of {} is greater than current {withdraw_pool} supply balance of {}",
maybe_token.format_amount(maximum_op_amount),
"The supply balance of {withdraw_pool}, {}, is less than minimum withdraw amount of {}",
maybe_token.format_amount(withdraw_pool_supply_balance),
maybe_token.format_amount(minimum_amount),
);
return Ok(());
}

let (minimum_op_amount, maximum_op_amount) = match requested_amount {
None => {
(minimum_amount, withdraw_pool_supply_balance)
},
Some(u64::MAX) => {
(withdraw_pool_supply_balance, withdraw_pool_supply_balance)
}
Some(requested_amount) => {
if withdraw_pool_supply_balance < requested_amount {
println!(
"The supply balance of {withdraw_pool}, {}, is less than requested amount of {}",
maybe_token.format_amount(withdraw_pool_supply_balance),
maybe_token.format_amount(requested_amount),
);
return Ok(());
}
(requested_amount, requested_amount)
},
};

(
if cmd == Command::Withdraw {
vec![(Operation::Withdraw, withdraw_pool)]
Expand Down

0 comments on commit d6b9909

Please sign in to comment.