alloy_evm/eth/
spec.rs

1//! Abstraction over configuration object for [`super::EthBlockExecutor`].
2
3use alloy_eips::eip6110::MAINNET_DEPOSIT_CONTRACT_ADDRESS;
4use alloy_hardforks::{EthereumChainHardforks, EthereumHardfork, EthereumHardforks, ForkCondition};
5use alloy_primitives::{address, Address};
6
7/// A configuration object for [`super::EthBlockExecutor`]
8#[auto_impl::auto_impl(&, Arc)]
9pub trait EthExecutorSpec: EthereumHardforks {
10    /// Address of deposit contract emitting deposit events.
11    ///
12    /// Used by [`super::eip6110::parse_deposits_from_receipts`].
13    fn deposit_contract_address(&self) -> Option<Address>;
14}
15
16/// Basic Ethereum specification.
17#[derive(Debug, Clone)]
18pub struct EthSpec {
19    hardforks: EthereumChainHardforks,
20    deposit_contract_address: Option<Address>,
21}
22
23impl EthSpec {
24    /// Creates [`EthSpec`] for Ethereum mainnet.
25    pub fn mainnet() -> Self {
26        Self {
27            hardforks: EthereumChainHardforks::mainnet(),
28            deposit_contract_address: Some(MAINNET_DEPOSIT_CONTRACT_ADDRESS),
29        }
30    }
31
32    /// Creates [`EthSpec`] for Ethereum Sepolia.
33    pub fn sepolia() -> Self {
34        Self {
35            hardforks: EthereumChainHardforks::sepolia(),
36            deposit_contract_address: Some(address!("0x7f02c3e3c98b133055b8b348b2ac625669ed295d")),
37        }
38    }
39
40    /// Creates [`EthSpec`] for Ethereum Holesky.
41    pub fn holesky() -> Self {
42        Self {
43            hardforks: EthereumChainHardforks::holesky(),
44            deposit_contract_address: Some(address!("0x4242424242424242424242424242424242424242")),
45        }
46    }
47}
48
49impl EthereumHardforks for EthSpec {
50    fn ethereum_fork_activation(&self, fork: EthereumHardfork) -> ForkCondition {
51        self.hardforks.ethereum_fork_activation(fork)
52    }
53}
54
55impl EthExecutorSpec for EthSpec {
56    fn deposit_contract_address(&self) -> Option<Address> {
57        self.deposit_contract_address
58    }
59}