Skip to content

Commit

Permalink
Add config for native price estimator
Browse files Browse the repository at this point in the history
  • Loading branch information
sunce86 committed Mar 7, 2025
1 parent 7bb3594 commit c804bc8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
25 changes: 20 additions & 5 deletions crates/driver/src/infra/blockchain/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use {
infra::{config::file::GasEstimatorType, mempool},
},
ethcontract::dyns::DynWeb3,
gas_estimation::{GasPriceEstimating, nativegasestimator::NativeGasEstimator},
gas_estimation::{
GasPriceEstimating,
nativegasestimator::{NativeGasEstimator, Params},
},
std::sync::Arc,
};

Expand All @@ -32,10 +35,22 @@ impl GasPriceEstimator {
mempools: &[mempool::Config],
) -> Result<Self, Error> {
let gas: Arc<dyn GasPriceEstimating> = match gas_estimator_type {
GasEstimatorType::Native => Arc::new(
NativeGasEstimator::new(web3.transport().clone(), None)
.await
.map_err(Error::GasPrice)?,
GasEstimatorType::Native {
max_reward_percentile,
max_block_percentile,
min_block_percentile,
} => Arc::new(
NativeGasEstimator::new(
web3.transport().clone(),
Some(Params {
max_reward_percentile: *max_reward_percentile,
max_block_percentile: *max_block_percentile,
min_block_percentile: *min_block_percentile,
..Default::default()
}),
)
.await
.map_err(Error::GasPrice)?,
),
GasEstimatorType::Web3 => Arc::new(web3.clone()),
};
Expand Down
25 changes: 22 additions & 3 deletions crates/driver/src/infra/config/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,14 +627,33 @@ fn default_response_size_limit_max_bytes() -> usize {
30_000_000
}

#[derive(Clone, Debug, Deserialize, Default)]
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
pub enum GasEstimatorType {
#[default]
Native,
Native {
// effective reward value to be selected from each individual block
// Example: 20 means 20% of the transactions with the lowest gas price will be analyzed
max_reward_percentile: usize,
// economical priority fee to be selected from sorted individual block reward percentiles
// This constitutes the part of priority fee that doesn't depend on the time_limit
min_block_percentile: f64,
// urgent priority fee to be selected from sorted individual block reward percentiles
// This constitutes the part of priority fee that depends on the time_limit
max_block_percentile: f64,
},
Web3,
}

impl Default for GasEstimatorType {
fn default() -> Self {
GasEstimatorType::Native {
max_reward_percentile: 20,
min_block_percentile: 30.,
max_block_percentile: 60.,
}
}
}

/// Defines various strategies to prioritize orders.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "kebab-case", tag = "strategy")]
Expand Down

0 comments on commit c804bc8

Please sign in to comment.