@@ -16,7 +16,7 @@ use prometheus::TextEncoder;
16
16
use reqwest:: StatusCode ;
17
17
use tower_http:: cors:: CorsLayer ;
18
18
19
- use crate :: box_kind:: PoolBox ;
19
+ use crate :: box_kind:: { OracleBox , PoolBox } ;
20
20
use crate :: monitor:: check_oracle_health;
21
21
use crate :: monitor:: check_pool_health;
22
22
use crate :: monitor:: OracleHealth ;
@@ -127,6 +127,21 @@ static MY_ORACLE_BOX_HEIGHT: Lazy<IntGaugeVec> = Lazy::new(|| {
127
127
m
128
128
} ) ;
129
129
130
+ static MY_ORACLE_CLAIMABLE_REWARDS : Lazy < IntGauge > = Lazy :: new ( || {
131
+ let m = IntGauge :: with_opts (
132
+ Opts :: new (
133
+ "oracle_claimable_rewards" ,
134
+ "The amount of claimable rewards for this oracle" ,
135
+ )
136
+ . namespace ( "ergo" )
137
+ . subsystem ( "oracle" ) ,
138
+ )
139
+ . unwrap ( ) ;
140
+
141
+ prometheus:: register ( Box :: new ( m. clone ( ) ) ) . expect ( "Failed to register" ) ;
142
+ m
143
+ } ) ;
144
+
130
145
static ALL_ORACLE_BOX_HEIGHT : Lazy < IntGaugeVec > = Lazy :: new ( || {
131
146
let m = IntGaugeVec :: new (
132
147
Opts :: new (
@@ -142,6 +157,21 @@ static ALL_ORACLE_BOX_HEIGHT: Lazy<IntGaugeVec> = Lazy::new(|| {
142
157
m
143
158
} ) ;
144
159
160
+ static ALL_ORACLE_CLAIMABLE_REWARDS : Lazy < IntGaugeVec > = Lazy :: new ( || {
161
+ let m = IntGaugeVec :: new (
162
+ Opts :: new (
163
+ "all_oracle_claimable_rewards" ,
164
+ "The amount of claimable rewards for all oracles" ,
165
+ )
166
+ . namespace ( "ergo" )
167
+ . subsystem ( "oracle" ) ,
168
+ & [ "oracle_address" ] ,
169
+ )
170
+ . unwrap ( ) ;
171
+ prometheus:: register ( Box :: new ( m. clone ( ) ) ) . expect ( "Failed to register" ) ;
172
+ m
173
+ } ) ;
174
+
145
175
static ACTIVE_ORACLE_BOX_HEIGHT : Lazy < IntGaugeVec > = Lazy :: new ( || {
146
176
let m = IntGaugeVec :: new (
147
177
Opts :: new (
@@ -270,6 +300,40 @@ fn update_reward_tokens_in_buyback_box(oracle_pool: Arc<OraclePool>) {
270
300
}
271
301
}
272
302
303
+ fn update_oracle_claimable_reward_tokens ( pool_health : & PoolHealth ) {
304
+ for oracle in & pool_health. details . all_oracle_boxes {
305
+ let reward_tokens = oracle. reward_tokens ;
306
+
307
+ if reward_tokens > 0 {
308
+ let claimable_tokens = reward_tokens - 1 ;
309
+ ALL_ORACLE_CLAIMABLE_REWARDS
310
+ . with_label_values ( & [ & oracle. address . to_base58 ( ) ] )
311
+ . set ( claimable_tokens as i64 ) ;
312
+ } else {
313
+ ALL_ORACLE_CLAIMABLE_REWARDS
314
+ . with_label_values ( & [ & oracle. address . to_base58 ( ) ] )
315
+ . set ( 0 ) ;
316
+ }
317
+ }
318
+ }
319
+
320
+ fn update_my_claimable_reward_tokens ( oracle_pool : Arc < OraclePool > ) {
321
+ if let Some ( oracle_box) = oracle_pool
322
+ . get_local_datapoint_box_source ( )
323
+ . get_local_oracle_datapoint_box ( )
324
+ . ok ( )
325
+ . flatten ( )
326
+ {
327
+ let num_tokens = * oracle_box. reward_token ( ) . amount . as_u64 ( ) ;
328
+ if num_tokens == 0 {
329
+ MY_ORACLE_CLAIMABLE_REWARDS . set ( num_tokens as i64 )
330
+ } else {
331
+ let claimable_tokens = num_tokens - 1 ;
332
+ MY_ORACLE_CLAIMABLE_REWARDS . set ( claimable_tokens as i64 )
333
+ }
334
+ }
335
+ }
336
+
273
337
pub fn update_metrics ( oracle_pool : Arc < OraclePool > ) -> Result < ( ) , anyhow:: Error > {
274
338
let node_api = NodeApi :: new (
275
339
ORACLE_SECRETS . node_api_key . clone ( ) ,
@@ -302,7 +366,9 @@ pub fn update_metrics(oracle_pool: Arc<OraclePool>) -> Result<(), anyhow::Error>
302
366
let wallet_balance: i64 = node_api. node . wallet_nano_ergs_balance ( ) ? as i64 ;
303
367
ORACLE_NODE_WALLET_BALANCE . set ( wallet_balance) ;
304
368
POOL_BOX_REWARD_TOKEN_AMOUNT . set ( pool_box. reward_token ( ) . amount . into ( ) ) ;
305
- update_reward_tokens_in_buyback_box ( oracle_pool) ;
369
+ update_reward_tokens_in_buyback_box ( oracle_pool. clone ( ) ) ;
370
+ update_my_claimable_reward_tokens ( oracle_pool) ;
371
+ update_oracle_claimable_reward_tokens ( & pool_health) ;
306
372
Ok ( ( ) )
307
373
}
308
374
0 commit comments