Skip to content

Commit 1e0b195

Browse files
committed
sys-lend: add --dry-run flag
1 parent 80bfd3b commit 1e0b195

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

src/bin/sys-lend.rs

+26-11
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
381381
.validator(is_parsable::<u16>)
382382
.help("Do not deposit if the current pool APY is less than this amount of BPS")
383383
)
384+
.arg(
385+
Arg::with_name("dry_run")
386+
.long("dry-run")
387+
.takes_value(false)
388+
)
384389
)
385390
.subcommand(
386391
SubCommand::with_name("withdraw")
@@ -421,6 +426,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
421426
.default_value("USDC")
422427
.help("Token to withdraw"),
423428
)
429+
.arg(
430+
Arg::with_name("dry_run")
431+
.long("dry-run")
432+
.takes_value(false)
433+
)
424434
)
425435
.subcommand(
426436
SubCommand::with_name("rebalance")
@@ -471,6 +481,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
471481
.default_value("250")
472482
.help("Skip rebalance if the APY improvement would be less than this amount of BPS")
473483
)
484+
.arg(
485+
Arg::with_name("dry_run")
486+
.long("dry-run")
487+
.takes_value(false)
488+
)
474489
)
475490
.subcommand(
476491
SubCommand::with_name("supply-balance")
@@ -769,6 +784,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
769784

770785
let maybe_token = MaybeToken::from(value_t!(matches, "token", Token).ok());
771786
let token = maybe_token.token().unwrap_or(Token::wSOL);
787+
let dry_run = matches.is_present("dry_run");
772788

773789
let pools = values_t!(matches, "pool", String)
774790
.ok()
@@ -1117,26 +1133,20 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
11171133
}
11181134

11191135
format!(
1120-
"Deposit {} from {} into {} at {simulation_deposit_pool_apy:.2}%",
1121-
maybe_token.format_amount(amount),
1122-
address,
1123-
deposit_pool
1136+
"Deposit {} from {address} into {deposit_pool} ({deposit_pool_apy:.2}% -> {simulation_deposit_pool_apy:.2}%)",
1137+
maybe_token.format_amount(amount)
11241138
)
11251139
}
11261140
Command::Withdraw => {
11271141
format!(
1128-
"Withdrew {} from {} into {}",
1129-
maybe_token.format_amount(amount),
1130-
withdraw_pool,
1131-
address
1142+
"Withdraw {} from {withdraw_pool} ({withdraw_pool_apy:.2}% -> {simulation_withdraw_pool_apy:.2}%) into {address}",
1143+
maybe_token.format_amount(amount)
11321144
)
11331145
}
11341146
Command::Rebalance => {
11351147
let msg_prefix = format!("Rebalance of {} from {withdraw_pool} ({withdraw_pool_apy:.2}% -> {simulation_withdraw_pool_apy:.2}%) \
11361148
to {deposit_pool} ({deposit_pool_apy:.2}% -> {simulation_deposit_pool_apy:.2}%)",
1137-
1138-
maybe_token.format_amount(amount),
1139-
1149+
maybe_token.format_amount(amount)
11401150
);
11411151

11421152
if simulation_apy_improvement_bps < minimum_apy_bps as isize {
@@ -1153,6 +1163,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
11531163

11541164
println!("{msg}");
11551165

1166+
if dry_run {
1167+
println!("Aborting due to --dry-run flag");
1168+
return Ok(());
1169+
}
1170+
11561171
if !send_transaction_until_expired(&rpc_clients, &transaction, last_valid_block_height)
11571172
{
11581173
let msg = format!("Transaction failed: {signature}");

0 commit comments

Comments
 (0)