@@ -110,6 +110,19 @@ mod dp {
110
110
. field ( "apy_bps" , apy_bps as f64 )
111
111
}
112
112
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
+
113
126
pub fn principal_balance_change (
114
127
pool : & str ,
115
128
address : & Pubkey ,
@@ -534,8 +547,12 @@ async fn build_instructions_for_ops<'a>(
534
547
& address_lookup_table_accounts,
535
548
) ?;
536
549
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
+ ) ?) ;
539
556
540
557
let simulation_total_apy =
541
558
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>> {
1057
1074
}
1058
1075
1059
1076
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 ;
1060
1086
1061
1087
if raw && total_only {
1062
1088
println ! ( "{}" , token. ui_amount( total_balance) ) ;
@@ -1066,7 +1092,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
1066
1092
println ! (
1067
1093
"Total supply: {} at {:.2}%" ,
1068
1094
token. format_amount( total_balance) ,
1069
- apr_to_apy ( total_apr ) * 100.
1095
+ total_apy ,
1070
1096
) ;
1071
1097
1072
1098
let wallet_balance = maybe_token. balance ( rpc_client, & address) ?;
@@ -1143,8 +1169,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
1143
1169
ui_amount => token. amount ( ui_amount. parse :: < f64 > ( ) . unwrap ( ) ) ,
1144
1170
} ;
1145
1171
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
+ ) ?) ;
1148
1178
let total_apy = apr_to_apy ( pools_supply_balance_apr ( & supply_balance) . 0 ) * 100. ;
1149
1179
1150
1180
assert_eq ! (
@@ -1316,9 +1346,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
1316
1346
) ;
1317
1347
}
1318
1348
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 ( ) ;
1322
1353
1323
1354
let max_requested_amount = match requested_amount {
1324
1355
u64:: MAX => {
@@ -1335,6 +1366,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
1335
1366
} else {
1336
1367
max_requested_amount
1337
1368
} ;
1369
+ println ! ( "{withdraw_pool} {:.2}%" , apr_to_apy( apr) * 100. ) ;
1338
1370
1339
1371
if max_requested_amount > withdraw_pool_available_balance {
1340
1372
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>> {
1496
1528
notifier
1497
1529
. send ( & format ! ( "{} via via {signature}" , operation_info. op_msg) )
1498
1530
. await ;
1499
-
1500
- return Ok ( ( ) ) ;
1501
1531
}
1502
1532
_ => unreachable ! ( ) ,
1503
1533
}
0 commit comments