agglayer_config/
l1.rs

1use std::{num::NonZeroU64, time::Duration};
2
3use agglayer_primitives::Address;
4use serde::{Deserialize, Serialize};
5use url::Url;
6
7/// The L1 configuration.
8#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
9#[serde(rename_all = "kebab-case")]
10pub struct L1 {
11    pub chain_id: u64,
12    pub node_url: Url,
13    #[serde(default = "default_ws_node_url")]
14    pub ws_node_url: Url,
15    #[serde(
16        default = "default_connect_attempt_timeout",
17        with = "crate::with::HumanDuration"
18    )]
19    pub connect_attempt_timeout: Duration,
20
21    #[serde(alias = "RollupManagerContract")]
22    pub rollup_manager_contract: Address,
23
24    #[serde(alias = "PolygonZkEVMGlobalExitRootV2Contract")]
25    pub polygon_zkevm_global_exit_root_v2_contract: Address,
26
27    #[serde(default = "L1::default_rpc_timeout")]
28    #[serde(with = "crate::with::HumanDuration")]
29    pub rpc_timeout: Duration,
30
31    #[serde(default = "L1::default_event_filter_block_range")]
32    pub event_filter_block_range: NonZeroU64,
33}
34
35impl L1 {
36    const fn default_rpc_timeout() -> Duration {
37        Duration::from_secs(45)
38    }
39
40    const fn default_event_filter_block_range() -> NonZeroU64 {
41        NonZeroU64::new(10000).unwrap()
42    }
43}
44
45impl Default for L1 {
46    fn default() -> Self {
47        // Values are coming from https://github.com/0xPolygon/agglayer/blob/main/config/default.go#L11
48        Self {
49            chain_id: 1337,
50            node_url: "http://zkevm-mock-l1-network:8545".parse().unwrap(),
51            connect_attempt_timeout: default_connect_attempt_timeout(),
52            ws_node_url: default_ws_node_url(),
53            rollup_manager_contract: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e"
54                .parse()
55                .unwrap(),
56            polygon_zkevm_global_exit_root_v2_contract:
57                "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e"
58                    .parse()
59                    .unwrap(),
60            rpc_timeout: Self::default_rpc_timeout(),
61            event_filter_block_range: Self::default_event_filter_block_range(),
62        }
63    }
64}
65
66fn default_ws_node_url() -> Url {
67    "ws://zkevm-mock-l1-network:8546".parse().unwrap()
68}
69
70const fn default_connect_attempt_timeout() -> Duration {
71    Duration::from_secs(3)
72}