diff --git a/orchestrator/web30/src/client.rs b/orchestrator/web30/src/client.rs index d6617e7..d39e635 100644 --- a/orchestrator/web30/src/client.rs +++ b/orchestrator/web30/src/client.rs @@ -15,6 +15,7 @@ use clarity::utils::bytes_to_hex_str; use clarity::{Address, PrivateKey, Transaction}; use num::ToPrimitive; use num256::Uint256; +use std::cmp::max; use std::{cmp::min, time::Duration}; use std::{sync::Arc, time::Instant}; use tokio::time::sleep as delay_for; @@ -44,6 +45,10 @@ impl Web3 { self.url.clone() } + pub async fn get_base_fee_per_gas(&self) -> Result, Web3Error> { + Ok(self.eth_get_latest_block().await?.base_fee_per_gas) + } + pub async fn eth_accounts(&self) -> Result, Web3Error> { self.jsonrpc_client .request_method("eth_accounts", Vec::::new(), self.timeout, None) @@ -117,10 +122,19 @@ impl Web3 { ) .await } + /// Get the median gas price over the last 10 blocks. This function does not + /// simply wrap eth_gasPrice, in post London chains it also requests the base + /// gas from the previous block and prevents the use of a lower value pub async fn eth_gas_price(&self) -> Result { - self.jsonrpc_client + let median_gas = self + .jsonrpc_client .request_method("eth_gasPrice", Vec::::new(), self.timeout, None) - .await + .await?; + let base_gas = self.get_base_fee_per_gas().await?; + Ok(match base_gas { + Some(base_gas) => max(base_gas, median_gas), + None => median_gas, + }) } pub async fn eth_estimate_gas(