Skip to content

Commit 5d2ef61

Browse files
devin-ai-integration[bot]Jayant Krishnamurthy
andauthored
feat(fortuna): add metric to track accrued pyth fees (#2448)
* feat(fortuna): add metric to track accrued pyth fees Co-Authored-By: Jayant Krishnamurthy <[email protected]> * refactor(fortuna): use ChainIdLabel as key for accrued_pyth_fees metric Co-Authored-By: Jayant Krishnamurthy <[email protected]> * chore(fortuna): bump patch version to 7.4.4 Co-Authored-By: Jayant Krishnamurthy <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Jayant Krishnamurthy <[email protected]>
1 parent 3646e91 commit 5d2ef61

File tree

5 files changed

+63
-3
lines changed

5 files changed

+63
-3
lines changed

apps/fortuna/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/fortuna/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fortuna"
3-
version = "7.4.3"
3+
version = "7.4.4"
44
edition = "2021"
55

66
[lib]

apps/fortuna/src/keeper.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use {
1111
keeper::commitment::update_commitments_loop,
1212
keeper::fee::adjust_fee_wrapper,
1313
keeper::fee::withdraw_fees_wrapper,
14+
keeper::track::track_accrued_pyth_fees,
1415
keeper::track::track_balance,
1516
keeper::track::track_provider,
1617
},
@@ -208,6 +209,14 @@ pub async fn run_keeper_threads(
208209
)
209210
.in_current_span(),
210211
);
212+
spawn(
213+
track_accrued_pyth_fees(
214+
chain_id.clone(),
215+
contract.clone(),
216+
keeper_metrics.clone(),
217+
)
218+
.in_current_span(),
219+
);
211220

212221
time::sleep(TRACK_INTERVAL).await;
213222
}

apps/fortuna/src/keeper/keeper_metrics.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ pub struct AccountLabel {
1616
pub address: String,
1717
}
1818

19+
#[derive(Clone, Debug, Hash, PartialEq, Eq, EncodeLabelSet)]
20+
pub struct ChainIdLabel {
21+
pub chain_id: String,
22+
}
23+
1924
pub struct KeeperMetrics {
2025
pub current_sequence_number: Family<AccountLabel, Gauge>,
2126
pub end_sequence_number: Family<AccountLabel, Gauge>,
@@ -36,6 +41,7 @@ pub struct KeeperMetrics {
3641
pub final_gas_multiplier: Family<AccountLabel, Histogram>,
3742
pub final_fee_multiplier: Family<AccountLabel, Histogram>,
3843
pub gas_price_estimate: Family<AccountLabel, Gauge<f64, AtomicU64>>,
44+
pub accrued_pyth_fees: Family<ChainIdLabel, Gauge<f64, AtomicU64>>,
3945
}
4046

4147
impl Default for KeeperMetrics {
@@ -76,6 +82,7 @@ impl Default for KeeperMetrics {
7682
Histogram::new(vec![100.0, 110.0, 120.0, 140.0, 160.0, 180.0, 200.0].into_iter())
7783
}),
7884
gas_price_estimate: Family::default(),
85+
accrued_pyth_fees: Family::default(),
7986
}
8087
}
8188
}
@@ -202,9 +209,25 @@ impl KeeperMetrics {
202209
keeper_metrics.gas_price_estimate.clone(),
203210
);
204211

212+
writable_registry.register(
213+
"accrued_pyth_fees",
214+
"Accrued Pyth fees on the contract",
215+
keeper_metrics.accrued_pyth_fees.clone(),
216+
);
217+
205218
// *Important*: When adding a new metric:
206219
// 1. Register it above using `writable_registry.register(...)`
207220
// 2. Add a get_or_create call in the loop below to initialize it for each chain/provider pair
221+
222+
// Initialize accrued_pyth_fees for each chain_id
223+
for (chain_id, _) in chain_labels.iter() {
224+
let _ = keeper_metrics
225+
.accrued_pyth_fees
226+
.get_or_create(&ChainIdLabel {
227+
chain_id: chain_id.clone(),
228+
});
229+
}
230+
208231
for (chain_id, provider_address) in chain_labels {
209232
let account_label = AccountLabel {
210233
chain_id,

apps/fortuna/src/keeper/track.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use {
2-
super::keeper_metrics::{AccountLabel, KeeperMetrics},
2+
super::keeper_metrics::{AccountLabel, ChainIdLabel, KeeperMetrics},
33
crate::{
44
api::ChainId, chain::ethereum::InstrumentedPythContract,
55
eth_utils::traced_client::TracedClient,
@@ -100,3 +100,31 @@ pub async fn track_provider(
100100
})
101101
.set(end_sequence_number as i64);
102102
}
103+
104+
/// tracks the accrued pyth fees on the given chain
105+
/// if there is an error the function will just return
106+
#[tracing::instrument(skip_all)]
107+
pub async fn track_accrued_pyth_fees(
108+
chain_id: ChainId,
109+
contract: InstrumentedPythContract,
110+
metrics: Arc<KeeperMetrics>,
111+
) {
112+
let accrued_pyth_fees = match contract.get_accrued_pyth_fees().call().await {
113+
Ok(fees) => fees,
114+
Err(e) => {
115+
tracing::error!("Error while getting accrued pyth fees. error: {:?}", e);
116+
return;
117+
}
118+
};
119+
120+
// The f64 conversion is made to be able to serve metrics with the constraints of Prometheus.
121+
// The fee is in wei, so we divide by 1e18 to convert it to eth.
122+
let accrued_pyth_fees = accrued_pyth_fees as f64 / 1e18;
123+
124+
metrics
125+
.accrued_pyth_fees
126+
.get_or_create(&ChainIdLabel {
127+
chain_id: chain_id.clone(),
128+
})
129+
.set(accrued_pyth_fees);
130+
}

0 commit comments

Comments
 (0)