@@ -217,3 +217,72 @@ func GetBaseFisFromAPI(agentAddr common.Address, eventsURL string) (miners []add
217
217
218
218
return miners , baseFis , nil
219
219
}
220
+
221
+ func GetPoolMetricsFromAPI (eventsURL string ) (* PoolMetrics , error ) {
222
+ url := fmt .Sprintf ("%s/metrics" , eventsURL )
223
+
224
+ resp , err := http .Get (url )
225
+ if err != nil {
226
+ return nil , err
227
+ }
228
+ defer resp .Body .Close ()
229
+
230
+ if resp .StatusCode != http .StatusOK {
231
+ // if the server can't find the agent we're asking for, it will return a 404
232
+ // we treat it as 0 baseFis
233
+ if resp .StatusCode == http .StatusNotFound {
234
+ return nil , nil
235
+ }
236
+
237
+ return nil , fmt .Errorf ("error fetching collateral stats. Status code: %d" , resp .StatusCode )
238
+ }
239
+
240
+ body , err := io .ReadAll (resp .Body )
241
+ if err != nil {
242
+ return nil , err
243
+ }
244
+
245
+ var response PoolsMetricsJSON
246
+ if err := json .Unmarshal (body , & response ); err != nil {
247
+ return nil , err
248
+ }
249
+
250
+ poolTotalAssets := big .NewInt (0 )
251
+ poolTotalAssets .SetString (response .PoolTotalAssets , 10 )
252
+ poolTotalBorrowed := big .NewInt (0 )
253
+ poolTotalBorrowed .SetString (response .PoolTotalBorrowed , 10 )
254
+ poolTotalBorrowableAssets := big .NewInt (0 )
255
+ poolTotalBorrowableAssets .SetString (response .PoolTotalBorrowableAssets , 10 )
256
+ poolExitReserve := big .NewInt (0 )
257
+ poolExitReserve .SetString (response .PoolExitReserve , 10 )
258
+ totalMinerCollaterals := big .NewInt (0 )
259
+ totalMinerCollaterals .SetString (response .TotalMinerCollaterals , 10 )
260
+ totalValueLocked := big .NewInt (0 )
261
+ totalValueLocked .SetString (response .TotalValueLocked , 10 )
262
+ totalMinersSectors := big .NewInt (0 )
263
+ totalMinersSectors .SetString (response .TotalMinersSectors , 10 )
264
+ totalMinerQAP := big .NewInt (0 )
265
+ totalMinerQAP .SetString (response .TotalMinerQAP , 10 )
266
+ totalMinerRBP := big .NewInt (0 )
267
+ totalMinerRBP .SetString (response .TotalMinerRBP , 10 )
268
+ totalMinerEDR := big .NewInt (0 )
269
+ totalMinerEDR .SetString (response .TotalMinerEDR , 10 )
270
+
271
+ result := PoolMetrics {
272
+ Height : response .Height ,
273
+ Timestamp : response .Timestamp ,
274
+ PoolTotalAssets : poolTotalAssets ,
275
+ PoolTotalBorrowed : poolTotalBorrowed ,
276
+ PoolTotalBorrowableAssets : poolTotalBorrowableAssets ,
277
+ PoolExitReserve : poolExitReserve ,
278
+ TotalAgentCount : response .TotalAgentCount ,
279
+ TotalMinerCollaterals : totalMinerCollaterals ,
280
+ TotalMinersCount : response .TotalMinersCount ,
281
+ TotalValueLocked : totalValueLocked ,
282
+ TotalMinersSectors : totalMinersSectors ,
283
+ TotalMinerQAP : totalMinerQAP ,
284
+ TotalMinerRBP : totalMinerRBP ,
285
+ TotalMinerEDR : totalMinerEDR ,
286
+ }
287
+ return & result , nil
288
+ }
0 commit comments