diff --git a/crates/driver/src/infra/blockchain/gas.rs b/crates/driver/src/infra/blockchain/gas.rs index 203b6af5fd..a2e1b21a28 100644 --- a/crates/driver/src/infra/blockchain/gas.rs +++ b/crates/driver/src/infra/blockchain/gas.rs @@ -20,7 +20,7 @@ type AdditionalTip = (MaxAdditionalTip, AdditionalTipPercentage); pub struct GasPriceEstimator { //TODO: remove visibility once boundary is removed pub(super) gas: Arc, - additional_tip: Option, + additional_tip: AdditionalTip, max_fee_per_gas: eth::U256, min_priority_fee: eth::U256, } @@ -53,7 +53,8 @@ impl GasPriceEstimator { .. } => (max_additional_tip, additional_tip_percentage), }) - .next(); + .next() + .unwrap_or((eth::U256::zero(), 0.)); // Use the lowest max_fee_per_gas of all mempools as the max_fee_per_gas let max_fee_per_gas = mempools .iter() @@ -84,24 +85,19 @@ impl GasPriceEstimator { .estimate() .await .map(|estimate| { - let additional_tip = self - .additional_tip - .map(|(max_additional_tip, additional_tip_percentage)| { - max_additional_tip - .to_f64_lossy() - .min(estimate.max_fee_per_gas * additional_tip_percentage) - }) - .map(eth::U256::from_f64_lossy) - .unwrap_or(eth::U256::zero()); + let (max, percentage) = self.additional_tip; + let additional_tip = max + .to_f64_lossy() + .min(estimate.max_fee_per_gas * percentage); let tip = std::cmp::max( - self.min_priority_fee, - eth::U256::from_f64_lossy(estimate.max_priority_fee_per_gas), + self.min_priority_fee + eth::U256::from_f64_lossy(additional_tip), + eth::U256::from_f64_lossy(estimate.max_priority_fee_per_gas + additional_tip), ); eth::GasPrice::new( self.max_fee_per_gas.into(), - (tip + additional_tip).into(), + tip.into(), eth::U256::from_f64_lossy(estimate.base_fee_per_gas).into(), ) })