Skip to content

Commit 8982ca7

Browse files
committed
add total_supply_balance_and_apy metric datapoint
1 parent 6cd67d8 commit 8982ca7

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

src/bin/sys-lend.rs

+40-10
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,19 @@ mod dp {
110110
.field("apy_bps", apy_bps as f64)
111111
}
112112

113+
pub fn total_supply_balance_and_apy(
114+
address: &Pubkey,
115+
maybe_token: MaybeToken,
116+
ui_amount: f64,
117+
apy_bps: u64,
118+
) -> metrics::Point {
119+
metrics::Point::new("sys_lend::total_supply_balance_and_apy")
120+
.tag("address", metrics::dp::pubkey_to_value(address))
121+
.tag("token", maybe_token.name())
122+
.field("amount", ui_amount)
123+
.field("apy", apy_bps as f64)
124+
}
125+
113126
pub fn principal_balance_change(
114127
pool: &str,
115128
address: &Pubkey,
@@ -534,8 +547,12 @@ async fn build_instructions_for_ops<'a>(
534547
&address_lookup_table_accounts,
535548
)?;
536549

537-
let simulation_supply_balance =
538-
pools_supply_balance(pools, token, address, &mut simulation_account_data_cache)?;
550+
let simulation_supply_balance = dbg!(pools_supply_balance(
551+
pools,
552+
token,
553+
address,
554+
&mut simulation_account_data_cache
555+
)?);
539556

540557
let simulation_total_apy =
541558
apr_to_apy(pools_supply_balance_apr(&simulation_supply_balance).0) * 100.;
@@ -1057,6 +1074,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
10571074
}
10581075

10591076
let (total_apr, total_balance) = pools_supply_balance_apr(&supply_balance);
1077+
let total_apy = apr_to_apy(total_apr) * 100.;
1078+
1079+
metrics::push(dp::total_supply_balance_and_apy(
1080+
&address,
1081+
maybe_token,
1082+
token.ui_amount(total_balance),
1083+
(total_apy * 100.) as u64,
1084+
))
1085+
.await;
10601086

10611087
if raw && total_only {
10621088
println!("{}", token.ui_amount(total_balance));
@@ -1066,7 +1092,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
10661092
println!(
10671093
"Total supply: {} at {:.2}%",
10681094
token.format_amount(total_balance),
1069-
apr_to_apy(total_apr) * 100.
1095+
total_apy,
10701096
);
10711097

10721098
let wallet_balance = maybe_token.balance(rpc_client, &address)?;
@@ -1143,8 +1169,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
11431169
ui_amount => token.amount(ui_amount.parse::<f64>().unwrap()),
11441170
};
11451171

1146-
let supply_balance =
1147-
pools_supply_balance(&pools, token, address, &mut account_data_cache)?;
1172+
let supply_balance = dbg!(pools_supply_balance(
1173+
&pools,
1174+
token,
1175+
address,
1176+
&mut account_data_cache
1177+
)?);
11481178
let total_apy = apr_to_apy(pools_supply_balance_apr(&supply_balance).0) * 100.;
11491179

11501180
assert_eq!(
@@ -1316,9 +1346,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
13161346
);
13171347
}
13181348

1319-
for withdraw_pool in &pools {
1320-
let withdraw_pool_available_balance =
1321-
supply_balance.get(withdraw_pool).unwrap().2;
1349+
//for withdraw_pool in &pools {
1350+
for withdraw_pool in &["solend-jlp".to_string()] {
1351+
let (apr, _, withdraw_pool_available_balance) =
1352+
*supply_balance.get(withdraw_pool).unwrap();
13221353

13231354
let max_requested_amount = match requested_amount {
13241355
u64::MAX => {
@@ -1335,6 +1366,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
13351366
} else {
13361367
max_requested_amount
13371368
};
1369+
println!("{withdraw_pool} {:.2}%", apr_to_apy(apr) * 100.);
13381370

13391371
if max_requested_amount > withdraw_pool_available_balance {
13401372
println!("Probing {withdraw_pool:<15} | FAIL | Rebalance {} failed due to an insufficient {withdraw_pool} supply balance of {}",
@@ -1496,8 +1528,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
14961528
notifier
14971529
.send(&format!("{} via via {signature}", operation_info.op_msg))
14981530
.await;
1499-
1500-
return Ok(());
15011531
}
15021532
_ => unreachable!(),
15031533
}

0 commit comments

Comments
 (0)