ethers_flashbots/
user.rs

1use crate::utils::deserialize_u256;
2use ethers::core::types::U256;
3use serde::Deserialize;
4
5/// Represents stats for a searcher.
6#[derive(Deserialize, Debug)]
7#[serde(rename_all = "camelCase")]
8pub struct UserStats {
9    /// Whether the searcher is high priority or not.
10    pub is_high_priority: bool,
11    /// The total amount of payments made to validators.
12    #[serde(deserialize_with = "deserialize_u256")]
13    pub all_time_validator_payments: U256,
14    /// The total amount of gas simulated in bundles.
15    #[serde(deserialize_with = "deserialize_u256")]
16    pub all_time_gas_simulated: U256,
17    /// The total amount of payments made to validators in the last 7 days.
18    #[serde(deserialize_with = "deserialize_u256")]
19    pub last_7d_validator_payments: U256,
20    /// The total amount of gas simulated in bundles the last 7 days.
21    #[serde(deserialize_with = "deserialize_u256")]
22    pub last_7d_gas_simulated: U256,
23    /// The total amount of payments made to validators in the last day.
24    #[serde(deserialize_with = "deserialize_u256")]
25    pub last_1d_validator_payments: U256,
26    /// The total amount of gas simulated in bundles in the last day.
27    #[serde(deserialize_with = "deserialize_u256")]
28    pub last_1d_gas_simulated: U256,
29}
30
31#[cfg(test)]
32mod tests {
33    use super::*;
34
35    #[test]
36    fn user_stats_deserialize() {
37        let user_stats: UserStats = serde_json::from_str(
38            r#"{
39                "isHighPriority": true,
40                "allTimeValidatorPayments": "1280749594841588639",
41                "allTimeGasSimulated": "30049470846",
42                "last7dValidatorPayments": "1280749594841588639",
43                "last7dGasSimulated": "30049470846",
44                "last1dValidatorPayments": "142305510537954293",
45                "last1dGasSimulated": "2731770076"
46            }"#,
47        )
48        .unwrap();
49
50        assert!(user_stats.is_high_priority);
51        assert_eq!(
52            user_stats.all_time_validator_payments,
53            U256::from_dec_str("1280749594841588639").unwrap()
54        );
55        assert_eq!(
56            user_stats.all_time_gas_simulated,
57            U256::from_dec_str("30049470846").unwrap()
58        );
59        assert_eq!(
60            user_stats.last_7d_validator_payments,
61            U256::from_dec_str("1280749594841588639").unwrap()
62        );
63        assert_eq!(
64            user_stats.last_7d_gas_simulated,
65            U256::from_dec_str("30049470846").unwrap()
66        );
67        assert_eq!(
68            user_stats.last_1d_validator_payments,
69            U256::from_dec_str("142305510537954293").unwrap()
70        );
71        assert_eq!(
72            user_stats.last_1d_gas_simulated,
73            U256::from_dec_str("2731770076").unwrap()
74        );
75    }
76}