Skip to content

Commit 57ad84b

Browse files
committed
feat: support lido modules
Added new types in `crates/common/src/types.rs` to model the different Lido modules we'll encounter depending on the Chain. Also added a `HashMap` that introduces a new dimension to the pseudo-map that previously always returned the registry address for the Lido curated module in `crates/common/src/config/mux.rs`, with the goal of being able to return the corresponding address based on the Chain and Lido Module id. To specify the required Lido module, a new optional field was added to `examples/configs/pbs_mux.toml` for lido loader, called `lido_module_id` which always defaults to 1.
1 parent b9201ce commit 57ad84b

File tree

4 files changed

+75
-15
lines changed

4 files changed

+75
-15
lines changed

config.example.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ validator_pubkeys = [
135135
# OPTIONAL
136136
loader = "./tests/data/mux_keys.example.json"
137137
# loader = { url = "http://localhost:8000/keys" }
138-
# loader = { registry = "lido", node_operator_id = 8 }
138+
# loader = { registry = "lido", node_operator_id = 8, lido_module_id = 1 }
139139
# loader = { registry = "ssv", node_operator_id = 8 }
140140
late_in_slot_time_ms = 1500
141141
timeout_get_header_ms = 900

crates/common/src/config/mux.rs

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use super::{MUX_PATH_ENV, PbsConfig, RelayConfig, load_optional_env_var};
2222
use crate::{
2323
config::{remove_duplicate_keys, safe_read_http_response},
2424
pbs::RelayClient,
25-
types::{BlsPublicKey, Chain},
25+
types::{BlsPublicKey, Chain, HoleskyModules, HoodiModules, MainnetModules},
2626
};
2727

2828
#[derive(Debug, Deserialize, Serialize)]
@@ -167,6 +167,8 @@ pub enum MuxKeysLoader {
167167
Registry {
168168
registry: NORegistry,
169169
node_operator_id: u64,
170+
#[serde(default)]
171+
lido_module_id: Option<u8>
170172
},
171173
}
172174

@@ -210,7 +212,7 @@ impl MuxKeysLoader {
210212
.wrap_err("failed to fetch mux keys from HTTP endpoint")
211213
}
212214

213-
Self::Registry { registry, node_operator_id } => match registry {
215+
Self::Registry { registry, node_operator_id, lido_module_id } => match registry {
214216
NORegistry::Lido => {
215217
let Some(rpc_url) = rpc_url else {
216218
bail!("Lido registry requires RPC URL to be set in the PBS config");
@@ -220,6 +222,7 @@ impl MuxKeysLoader {
220222
rpc_url,
221223
chain,
222224
U256::from(*node_operator_id),
225+
*lido_module_id,
223226
http_timeout,
224227
)
225228
.await
@@ -257,21 +260,58 @@ sol! {
257260
"src/abi/LidoNORegistry.json"
258261
}
259262

260-
// Fetching Lido Curated Module
261-
fn lido_registry_address(chain: Chain) -> eyre::Result<Address> {
262-
match chain {
263-
Chain::Mainnet => Ok(address!("55032650b14df07b85bF18A3a3eC8E0Af2e028d5")),
264-
Chain::Holesky => Ok(address!("595F64Ddc3856a3b5Ff4f4CC1d1fb4B46cFd2bAC")),
265-
Chain::Hoodi => Ok(address!("5cDbE1590c083b5A2A64427fAA63A7cfDB91FbB5")),
266-
Chain::Sepolia => Ok(address!("33d6E15047E8644F8DDf5CD05d202dfE587DA6E3")),
267-
_ => bail!("Lido registry not supported for chain: {chain:?}"),
268-
}
263+
fn lido_registry_addresses_by_module() -> HashMap<Chain, HashMap<u8, Address>> {
264+
let mut map: HashMap<Chain, HashMap<u8, Address>> = HashMap::new();
265+
266+
// --- Mainnet ---
267+
let mut mainnet = HashMap::new();
268+
mainnet.insert(MainnetModules::Curated as u8, address!("55032650b14df07b85bF18A3a3eC8E0Af2e028d5"));
269+
mainnet.insert(MainnetModules::SimpleDVT as u8, address!("aE7B191A31f627b4eB1d4DaC64eaB9976995b433"));
270+
mainnet.insert(MainnetModules::CommunityStaking as u8, address!("dA7dE2ECdDfccC6c3AF10108Db212ACBBf9EA83F"));
271+
map.insert(Chain::Mainnet, mainnet);
272+
273+
// --- Holesky ---
274+
let mut holesky = HashMap::new();
275+
holesky.insert(HoleskyModules::Curated as u8, address!("595F64Ddc3856a3b5Ff4f4CC1d1fb4B46cFd2bAC"));
276+
holesky.insert(HoleskyModules::SimpleDVT as u8, address!("11a93807078f8BB880c1BD0ee4C387537de4b4b6"));
277+
holesky.insert(HoleskyModules::Sandbox as u8, address!("D6C2ce3BB8bea2832496Ac8b5144819719f343AC"));
278+
holesky.insert(HoleskyModules::CommunityStaking as u8, address!("4562c3e63c2e586cD1651B958C22F88135aCAd4f"));
279+
map.insert(Chain::Holesky, holesky);
280+
281+
// --- Hoodi ---
282+
let mut hoodi = HashMap::new();
283+
hoodi.insert(HoodiModules::Curated as u8, address!("5cDbE1590c083b5A2A64427fAA63A7cfDB91FbB5"));
284+
hoodi.insert(HoodiModules::SimpleDVT as u8, address!("0B5236BECA68004DB89434462DfC3BB074d2c830"));
285+
hoodi.insert(HoodiModules::Sandbox as u8, address!("682E94d2630846a503BDeE8b6810DF71C9806891"));
286+
hoodi.insert(HoodiModules::CommunityStaking as u8, address!("79CEf36D84743222f37765204Bec41E92a93E59d"));
287+
map.insert(Chain::Hoodi, hoodi);
288+
289+
// --- Sepolia --
290+
let mut sepolia = HashMap::new();
291+
sepolia.insert(1, address!("33d6E15047E8644F8DDf5CD05d202dfE587DA6E3"));
292+
map.insert(Chain::Sepolia, sepolia);
293+
294+
map
295+
}
296+
297+
// Fetching appropiate registry address
298+
fn lido_registry_address(chain: Chain, maybe_module: Option<u8>) -> eyre::Result<Address> {
299+
lido_registry_addresses_by_module()
300+
.get(&chain)
301+
.ok_or_else(|| eyre::eyre!("Lido registry not supported for chain: {chain:?}"))?
302+
.get(&maybe_module.unwrap_or(1))
303+
.copied()
304+
.ok_or_else(|| eyre::eyre!(
305+
"Lido module id {:?} not found for chain: {chain:?}",
306+
maybe_module.unwrap_or(1)
307+
))
269308
}
270309

271310
async fn fetch_lido_registry_keys(
272311
rpc_url: Url,
273312
chain: Chain,
274313
node_operator_id: U256,
314+
lido_module_id: Option<u8>,
275315
http_timeout: Duration,
276316
) -> eyre::Result<Vec<BlsPublicKey>> {
277317
debug!(?chain, %node_operator_id, "loading operator keys from Lido registry");
@@ -283,7 +323,7 @@ async fn fetch_lido_registry_keys(
283323
let rpc_client = RpcClient::new(http, is_local);
284324
let provider = ProviderBuilder::new().connect_client(rpc_client);
285325

286-
let registry_address = lido_registry_address(chain)?;
326+
let registry_address = lido_registry_address(chain, lido_module_id)?;
287327
let registry = LidoRegistry::new(registry_address, provider);
288328

289329
let total_keys = registry.getTotalSigningKeyCount(node_operator_id).call().await?.try_into()?;

crates/common/src/types.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub struct JwtClaims {
2929
pub module: String,
3030
}
3131

32-
#[derive(Clone, Copy, PartialEq, Eq)]
32+
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
3333
pub enum Chain {
3434
Mainnet,
3535
Holesky,
@@ -44,6 +44,26 @@ pub enum Chain {
4444
},
4545
}
4646

47+
pub enum MainnetModules {
48+
Curated = 1,
49+
SimpleDVT = 2,
50+
CommunityStaking = 3
51+
}
52+
53+
pub enum HoleskyModules {
54+
Curated = 1,
55+
SimpleDVT = 2,
56+
Sandbox = 3,
57+
CommunityStaking = 4
58+
}
59+
60+
pub enum HoodiModules {
61+
Curated = 1,
62+
SimpleDVT = 2,
63+
Sandbox = 3,
64+
CommunityStaking = 4
65+
}
66+
4767
pub type ForkVersion = [u8; 4];
4868

4969
impl std::fmt::Display for Chain {

examples/configs/pbs_mux.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ target_first_request_ms = 200
3333

3434
[[mux]]
3535
id = "lido-mux"
36-
loader = { registry = "lido", node_operator_id = 8 }
36+
loader = { registry = "lido", node_operator_id = 8, lido_module_id = 1 }
3737

3838
[[mux.relays]]
3939
id = "relay-3"

0 commit comments

Comments
 (0)