Skip to main content

krusty_kms_common/
validator.rs

1//! Staking validator metadata and presets.
2
3use crate::address::Address;
4use crate::chain::ChainId;
5
6/// A staking delegation pool validator.
7#[derive(Debug, Clone)]
8pub struct Validator {
9    pub address: Address,
10    pub name: String,
11}
12
13impl Validator {
14    pub fn new(address: Address, name: impl Into<String>) -> Self {
15        Self {
16            address,
17            name: name.into(),
18        }
19    }
20}
21
22/// Well-known validator presets.
23///
24/// Pool addresses change over time — verify against the staking explorer
25/// before relying on these in production.
26pub mod presets {
27    use super::*;
28
29    fn v(hex: &str, name: &str) -> Validator {
30        Validator::new(Address::from_hex(hex).unwrap(), name)
31    }
32
33    /// Mainnet delegation pool validators.
34    pub fn mainnet_validators() -> Vec<Validator> {
35        vec![
36            v(
37                "0x0219e985e87c0f14e5b7b1a59e05a2c1e7a248a9e18a20d665e0f16599b4e4b0",
38                "Braavos",
39            ),
40            v(
41                "0x0541dacadeb54d347a278cc5223f274e26ff916b09dd0ed87c817b47fdba1a32",
42                "Argent",
43            ),
44            v(
45                "0x06d5ee2006236e230809baa17bfe3b4ad2c663ecbf2bcab1e3a4e2d07bc35320",
46                "Nethermind",
47            ),
48            v(
49                "0x050e5d88de2b6b5d6a2e2e46e1bff55a17f6c96adead2c68d328abf99ee35b8f",
50                "Voyager",
51            ),
52            v(
53                "0x068f32ec40113e86e3c4cd7b93e46b05c4c0003beef09be4e9e3c3513fdc28de",
54                "Karnot",
55            ),
56            v(
57                "0x0478ee005a59c39d0f2cbb7fda3bb43c71a6c8ec258e82340d4eba8e35fcf434",
58                "Carbonable",
59            ),
60            v(
61                "0x01176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8",
62                "Starknet Foundation",
63            ),
64            v(
65                "0x0129a3e36e345f8a67e3e34dfb14de9f60c3f5d7b760920da73e38ce4cb2c55e",
66                "ZKX",
67            ),
68        ]
69    }
70
71    /// Sepolia testnet delegation pool validators.
72    ///
73    /// Sepolia pools rotate frequently. Query the staking contract
74    /// on-chain for current pools.
75    pub fn sepolia_validators() -> Vec<Validator> {
76        vec![]
77    }
78
79    /// Get validators for a given chain.
80    pub fn validators(chain_id: ChainId) -> Vec<Validator> {
81        match chain_id {
82            ChainId::Mainnet => mainnet_validators(),
83            ChainId::Sepolia => sepolia_validators(),
84        }
85    }
86}
87
88#[cfg(test)]
89mod tests {
90    use super::*;
91
92    #[test]
93    fn test_mainnet_validators_not_empty() {
94        let vals = presets::mainnet_validators();
95        assert!(!vals.is_empty());
96    }
97
98    #[test]
99    fn test_sepolia_validators_empty() {
100        let vals = presets::sepolia_validators();
101        assert!(vals.is_empty());
102    }
103
104    #[test]
105    fn test_validators_by_chain() {
106        let vals = presets::validators(ChainId::Mainnet);
107        assert!(!vals.is_empty());
108    }
109}