use serde::{Deserialize, Serialize};
#[must_use]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PriceGuardConfig {
lower_tolerance_bps: u32,
upper_tolerance_bps: u32,
fail_on_provider_error: bool,
fail_on_token_price_not_found: bool,
enabled: bool,
}
impl Default for PriceGuardConfig {
fn default() -> Self {
Self {
lower_tolerance_bps: 300,
upper_tolerance_bps: 10_000,
fail_on_provider_error: false,
fail_on_token_price_not_found: false,
enabled: false,
}
}
}
impl PriceGuardConfig {
pub fn lower_tolerance_bps(&self) -> u32 {
self.lower_tolerance_bps
}
pub fn upper_tolerance_bps(&self) -> u32 {
self.upper_tolerance_bps
}
pub fn fail_on_provider_error(&self) -> bool {
self.fail_on_provider_error
}
pub fn fail_on_token_price_not_found(&self) -> bool {
self.fail_on_token_price_not_found
}
pub fn enabled(&self) -> bool {
self.enabled
}
pub fn with_lower_tolerance_bps(mut self, bps: u32) -> Self {
self.lower_tolerance_bps = bps;
self
}
pub fn with_upper_tolerance_bps(mut self, bps: u32) -> Self {
self.upper_tolerance_bps = bps;
self
}
pub fn with_fail_on_provider_error(mut self, fail: bool) -> Self {
self.fail_on_provider_error = fail;
self
}
pub fn with_fail_on_token_price_not_found(mut self, fail: bool) -> Self {
self.fail_on_token_price_not_found = fail;
self
}
pub fn with_enabled(mut self, enabled: bool) -> Self {
self.enabled = enabled;
self
}
}