diff --git a/src/client/client.rs b/src/client/client.rs index 0252b08..a5bde12 100644 --- a/src/client/client.rs +++ b/src/client/client.rs @@ -78,6 +78,18 @@ impl Client { } } + pub async fn get_gas_price(&self) -> Result { + let payload = self.consensus.get_execution_payload().await?; + let base_fee = U256::from_little_endian(&payload.base_fee_per_gas.to_bytes_le()); + let tip = U256::from(10_u64.pow(9)); + Ok(base_fee + tip) + } + + pub async fn get_priority_fee(&self) -> Result { + let tip = U256::from(10_u64.pow(9)); + Ok(tip) + } + pub fn chain_id(&self) -> u64 { self.config.general.chain_id } diff --git a/src/client/rpc.rs b/src/client/rpc.rs index 8d9142c..71d27fd 100644 --- a/src/client/rpc.rs +++ b/src/client/rpc.rs @@ -53,6 +53,10 @@ trait EthRpc { async fn estimate_gas(&self, opts: CallOpts) -> Result; #[method(name = "chainId")] fn chain_id(&self) -> Result; + #[method(name = "gasPrice")] + async fn gas_price(&self) -> Result; + #[method(name = "maxPriorityFeePerGas")] + async fn max_priority_fee_per_gas(&self) -> Result; } struct RpcInner { @@ -130,6 +134,16 @@ impl EthRpcServer for RpcInner { let id = self.client.chain_id(); Ok(u64_to_hex_string(id)) } + + async fn gas_price(&self) -> Result { + let gas_price = convert_err(self.client.get_gas_price().await)?; + Ok(gas_price.encode_hex()) + } + + async fn max_priority_fee_per_gas(&self) -> Result { + let tip = convert_err(self.client.get_priority_fee().await)?; + Ok(tip.encode_hex()) + } } async fn start(rpc: RpcInner) -> Result<(HttpServerHandle, SocketAddr)> { diff --git a/src/consensus/types.rs b/src/consensus/types.rs index 450d906..09d7cd7 100644 --- a/src/consensus/types.rs +++ b/src/consensus/types.rs @@ -69,7 +69,7 @@ pub struct ExecutionPayload { #[serde(deserialize_with = "extra_data_deserialize")] extra_data: List, #[serde(deserialize_with = "u256_deserialize")] - base_fee_per_gas: U256, + pub base_fee_per_gas: U256, #[serde(deserialize_with = "bytes32_deserialize")] pub block_hash: Bytes32, #[serde(deserialize_with = "transactions_deserialize")]