Skip to main content

mega_evme/common/
hardfork.rs

1use mega_evm::{
2    alloy_hardforks::{EthereumHardfork, ForkCondition},
3    alloy_op_hardforks::{EthereumHardforks, OpHardfork, OpHardforks},
4    MegaHardfork, MegaHardforks, MegaSpecId,
5};
6
7/// Fixed hardfork configuration for replay
8#[derive(Debug, Clone, Copy)]
9pub struct FixedHardfork {
10    spec: MegaSpecId,
11}
12
13impl FixedHardfork {
14    /// Create a new [`FixedHardfork`] with the given `spec`
15    pub fn new(spec: MegaSpecId) -> Self {
16        Self { spec }
17    }
18}
19
20impl EthereumHardforks for FixedHardfork {
21    fn ethereum_fork_activation(&self, fork: EthereumHardfork) -> ForkCondition {
22        if fork <= EthereumHardfork::Prague {
23            ForkCondition::Timestamp(0)
24        } else {
25            ForkCondition::Never
26        }
27    }
28}
29
30impl OpHardforks for FixedHardfork {
31    fn op_fork_activation(&self, fork: OpHardfork) -> ForkCondition {
32        if fork <= OpHardfork::Isthmus {
33            ForkCondition::Timestamp(0)
34        } else {
35            ForkCondition::Never
36        }
37    }
38}
39
40impl MegaHardforks for FixedHardfork {
41    fn mega_fork_activation(&self, fork: MegaHardfork) -> ForkCondition {
42        let mapped_spec = fork.spec_id();
43        if mapped_spec <= self.spec {
44            ForkCondition::Timestamp(0)
45        } else {
46            ForkCondition::Never
47        }
48    }
49}