@@ -2,6 +2,7 @@ use crate::eth::{
2
2
backend:: { info:: StorageInfo , notifications:: NewBlockNotifications } ,
3
3
error:: BlockchainError ,
4
4
} ;
5
+ use alloy_eips:: { calc_next_block_base_fee, eip1559:: BaseFeeParams } ;
5
6
use alloy_primitives:: B256 ;
6
7
use anvil_core:: eth:: transaction:: TypedTransaction ;
7
8
use foundry_evm:: revm:: primitives:: SpecId ;
@@ -28,11 +29,8 @@ pub const INITIAL_GAS_PRICE: u128 = 1_875_000_000;
28
29
/// Bounds the amount the base fee can change between blocks.
29
30
pub const BASE_FEE_CHANGE_DENOMINATOR : u128 = 8 ;
30
31
31
- /// Elasticity multiplier as defined in [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559)
32
- pub const EIP1559_ELASTICITY_MULTIPLIER : u128 = 2 ;
33
-
34
32
pub fn default_elasticity ( ) -> f64 {
35
- 1f64 / BASE_FEE_CHANGE_DENOMINATOR as f64
33
+ 1f64 / BaseFeeParams :: ethereum ( ) . elasticity_multiplier as f64
36
34
}
37
35
38
36
/// Stores the fee related information
@@ -127,28 +125,7 @@ impl FeeManager {
127
125
if self . base_fee ( ) == 0 {
128
126
return 0
129
127
}
130
- calculate_next_block_base_fee ( gas_used, gas_limit, last_fee_per_gas)
131
- }
132
- }
133
-
134
- /// Calculate base fee for next block. [EIP-1559](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md) spec
135
- pub fn calculate_next_block_base_fee ( gas_used : u128 , gas_limit : u128 , base_fee : u128 ) -> u128 {
136
- let gas_target = gas_limit / EIP1559_ELASTICITY_MULTIPLIER ;
137
-
138
- if gas_used == gas_target {
139
- return base_fee
140
- }
141
- if gas_used > gas_target {
142
- let gas_used_delta = gas_used - gas_target;
143
- let base_fee_delta =
144
- std:: cmp:: max ( 1 , base_fee * gas_used_delta / gas_target / BASE_FEE_CHANGE_DENOMINATOR ) ;
145
- base_fee + base_fee_delta
146
- } else {
147
- let gas_used_delta = gas_target - gas_used;
148
- let base_fee_per_gas_delta =
149
- base_fee * gas_used_delta / gas_target / BASE_FEE_CHANGE_DENOMINATOR ;
150
-
151
- base_fee. saturating_sub ( base_fee_per_gas_delta)
128
+ calc_next_block_base_fee ( gas_used, gas_limit, last_fee_per_gas, BaseFeeParams :: ethereum ( ) )
152
129
}
153
130
}
154
131
0 commit comments