19
19
} ,
20
20
std:: collections:: { HashMap , HashSet } ,
21
21
sys:: {
22
- app_version,
22
+ app_version, metrics ,
23
23
notifier:: * ,
24
24
priority_fee:: { apply_priority_fee, PriorityFee } ,
25
25
send_transaction_until_expired,
@@ -43,6 +43,32 @@ enum Operation {
43
43
Withdraw ,
44
44
}
45
45
46
+ mod dp {
47
+ use super :: * ;
48
+
49
+ pub fn supply_balance (
50
+ pool : & str ,
51
+ address : & Pubkey ,
52
+ maybe_token : MaybeToken ,
53
+ ui_amount : f64 ,
54
+ ) -> metrics:: Point {
55
+ metrics:: Point :: new ( "sys_lend::supply_balance" )
56
+ . tag ( "pool" , pool)
57
+ . tag ( "address" , metrics:: dp:: pubkey_to_value ( address) )
58
+ . tag ( "token" , maybe_token. name ( ) )
59
+ . field ( "amount" , ui_amount)
60
+ . timestamp ( metrics:: dp:: now ( ) )
61
+ }
62
+
63
+ pub fn supply_apy ( pool : & str , maybe_token : MaybeToken , apy_bps : u64 ) -> metrics:: Point {
64
+ metrics:: Point :: new ( "sys_lend::supply_apy" )
65
+ . tag ( "pool" , pool)
66
+ . tag ( "token" , maybe_token. name ( ) )
67
+ . field ( "apy_bps" , apy_bps as f64 )
68
+ . timestamp ( metrics:: dp:: now ( ) )
69
+ }
70
+ }
71
+
46
72
#[ tokio:: main]
47
73
async fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
48
74
solana_logger:: setup_with_default ( "solana=info" ) ;
@@ -292,9 +318,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
292
318
let bps = matches. is_present ( "bps" ) ;
293
319
294
320
let apy = apr_to_apy ( pool_supply_apr ( & rpc_client, & pool, token) ?) * 100. ;
321
+ let apy_as_bps = ( apy * 100. ) as u64 ;
295
322
296
323
let value = if bps {
297
- format ! ( "{:.0 }" , apy * 100. )
324
+ format ! ( "{}" , apy_as_bps )
298
325
} else {
299
326
format ! ( "{:.2}" , apy)
300
327
} ;
@@ -307,23 +334,31 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
307
334
if !raw {
308
335
notifier. send ( & msg) . await ;
309
336
}
337
+ metrics:: push ( dp:: supply_apy ( & pool, token, apy_as_bps) ) . await ;
310
338
println ! ( "{msg}" ) ;
311
339
}
312
340
( "supply-balance" , Some ( matches) ) => {
313
341
let pool = value_t_or_exit ! ( matches, "pool" , String ) ;
314
342
let address = pubkey_of ( matches, "address" ) . unwrap ( ) ;
315
343
let token = MaybeToken :: from ( value_t ! ( matches, "token" , Token ) . ok ( ) ) ;
316
344
317
- let supply_balance = pool_supply_balance ( & rpc_client, & pool, token, address) ?;
345
+ let amount = pool_supply_balance ( & rpc_client, & pool, token, address) ?;
318
346
let apr = pool_supply_apr ( & rpc_client, & pool, token) ?;
319
347
320
348
let msg = format ! (
321
349
"{}: {} supplied at {:.2}%" ,
322
350
pool,
323
- token. format_amount( supply_balance ) ,
351
+ token. format_amount( amount ) ,
324
352
apr_to_apy( apr) * 100.
325
353
) ;
326
354
notifier. send ( & msg) . await ;
355
+ metrics:: push ( dp:: supply_balance (
356
+ & pool,
357
+ & address,
358
+ token,
359
+ token. ui_amount ( amount) ,
360
+ ) )
361
+ . await ;
327
362
println ! ( "{msg}" ) ;
328
363
}
329
364
( "deposit" | "withdraw" , Some ( matches) ) => {
@@ -504,6 +539,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
504
539
_ => unreachable ! ( ) ,
505
540
}
506
541
542
+ metrics:: send ( metrics:: env_config ( ) ) . await ;
507
543
Ok ( ( ) )
508
544
}
509
545
0 commit comments