Skip to main content

evm_oracle_state/
config.rs

1use alloy_primitives::Address;
2
3use crate::FeedId;
4
5/// Feed registration configuration.
6#[derive(Clone, Debug)]
7pub struct FeedConfig {
8    /// User-facing proxy address.
9    pub proxy: Address,
10    /// Optional stable id. If omitted, one is derived from the label or proxy.
11    pub id: Option<FeedId>,
12    /// Optional human-readable label.
13    pub label: Option<String>,
14    /// Optional base symbol.
15    pub base: Option<String>,
16    /// Optional quote symbol.
17    pub quote: Option<String>,
18    /// Staleness and answer validity policy.
19    pub staleness: StalenessPolicy,
20}
21
22impl Default for FeedConfig {
23    fn default() -> Self {
24        Self {
25            proxy: Address::ZERO,
26            id: None,
27            label: None,
28            base: None,
29            quote: None,
30            staleness: StalenessPolicy::default(),
31        }
32    }
33}
34
35/// Policy used to classify round freshness and answer validity.
36#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
37pub struct StalenessPolicy {
38    max_age_secs: Option<u64>,
39    allow_zero_or_negative_answer: bool,
40}
41
42impl StalenessPolicy {
43    /// Create a policy with a max age.
44    pub fn max_age(max_age_secs: u64) -> Self {
45        Self {
46            max_age_secs: Some(max_age_secs),
47            allow_zero_or_negative_answer: false,
48        }
49    }
50
51    /// Allow zero or negative answers for generic signed numeric feeds.
52    pub fn allow_zero_or_negative_answer(mut self, allow: bool) -> Self {
53        self.allow_zero_or_negative_answer = allow;
54        self
55    }
56
57    pub(crate) fn max_age_secs(&self) -> Option<u64> {
58        self.max_age_secs
59    }
60
61    pub(crate) fn allows_zero_or_negative_answer(&self) -> bool {
62        self.allow_zero_or_negative_answer
63    }
64}