Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config for native price estimator in driver #3316

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: all our comments usually start with capital letter

// 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
Loading