Skip to content

Commit ce3b589

Browse files
committed
Add --raw and --bps flags to supply-apy subcommand
1 parent 70d76ae commit ce3b589

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/bin/sys-lend.rs

+27-2
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,18 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
219219
.validator(is_valid_token_or_sol)
220220
.default_value("USDC")
221221
.help("Token to deposit"),
222+
)
223+
.arg(
224+
Arg::with_name("raw")
225+
.long("raw")
226+
.takes_value(false)
227+
.help("Only output raw numerical value"),
228+
)
229+
.arg(
230+
Arg::with_name("bps")
231+
.long("bps")
232+
.takes_value(false)
233+
.help("Display in Basis Points instead of Percent"),
222234
),
223235
);
224236

@@ -276,9 +288,22 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
276288
("supply-apy", Some(matches)) => {
277289
let pool = value_t_or_exit!(matches, "pool", String);
278290
let token = MaybeToken::from(value_t!(matches, "token", Token).ok());
291+
let raw = matches.is_present("raw");
292+
let bps = matches.is_present("bps");
279293

280-
let apr = pool_supply_apr(&rpc_client, &pool, token)?;
281-
let msg = format!("{} {} {:.2}%", pool, token, apr_to_apy(apr) * 100.);
294+
let apy = apr_to_apy(pool_supply_apr(&rpc_client, &pool, token)?) * 100.;
295+
296+
let value = if bps {
297+
format!("{:.0}", apy * 100.)
298+
} else {
299+
format!("{:.2}", apy)
300+
};
301+
302+
let msg = if raw {
303+
value.to_string()
304+
} else {
305+
format!("{pool} {token} {value}{}", if bps { "bps" } else { "%" })
306+
};
282307
notifier.send(&msg).await;
283308
println!("{msg}");
284309
}

0 commit comments

Comments
 (0)