From 529adb58eeea54ce40ec2d469ee9be60096a1295 Mon Sep 17 00:00:00 2001 From: Francesco Date: Mon, 19 May 2025 12:06:48 +0200 Subject: [PATCH 1/3] Add missing methods to evm client --- src/evm-canister-client/src/client.rs | 72 ++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/src/evm-canister-client/src/client.rs b/src/evm-canister-client/src/client.rs index 49f10a8a..4f94c64a 100644 --- a/src/evm-canister-client/src/client.rs +++ b/src/evm-canister-client/src/client.rs @@ -11,8 +11,8 @@ use did::transaction::StorableExecutionResult; use did::unsafe_blocks::ValidateUnsafeBlockArgs; use did::{ Block, BlockConfirmationData, BlockConfirmationResult, BlockConfirmationStrategy, BlockNumber, - BlockchainBlockInfo, BlockchainStorageLimits, Bytes, EstimateGasRequest, EvmStats, H160, H256, - Transaction, TransactionReceipt, U64, U256, + BlockchainBlockInfo, BlockchainStorageLimits, Bytes, EstimateGasRequest, EvmStats, FeeHistory, + H160, H256, Transaction, TransactionReceipt, U64, U256, }; use ic_canister_client::{CanisterClient, CanisterClientResult}; pub use ic_log::writer::{Log, Logs}; @@ -317,6 +317,55 @@ impl EvmCanisterClient { .await } + /// Returns the maximum priority fee per gas that should be paid by a transaction + /// to be included in the next block. + /// + /// It uses a default gas ratio threshold of 75% to determine if a block is nearly empty. + /// + /// Returns error variant only if there's no block data available. + /// + /// See . + pub async fn eth_max_priority_fee_per_gas(&self) -> CanisterClientResult> { + self.client.query("eth_max_priority_fee_per_gas", ()).await + } + + /// Reports the fee history, for the given amount of blocks, up until the + /// newest block provided. + /// + /// # JSON RPC + /// + /// This method can also be called through PRC method [`eth_feeHistory`](evm_core::rpc::EthRpc::eth_fee_history). + /// + /// # Ethereum spec + /// + /// See . + pub async fn eth_fee_history( + &self, + block_count: u64, + newest_block: BlockNumber, + reward_percentiles: Option>, + ) -> CanisterClientResult> { + self.client + .query( + "eth_fee_history", + (block_count, newest_block, reward_percentiles), + ) + .await + } + + /// Returns an estimate of the current price per gas in wei. + /// + /// # JSON RPC + /// + /// This method can also be called by [`eth_gasPrice`](evm_core::rpc::EthRpc::eth_gas_price) JSON RPC method. + /// + /// # Ethereum spec + /// + /// See . + pub async fn eth_gas_price(&self) -> CanisterClientResult> { + self.client.query("eth_gas_price", ()).await + } + /// Execute a call on the EVM without modifying the state /// See [eth_call](https://eth.wiki/json-rpc/API#eth_call) /// @@ -431,6 +480,12 @@ impl EvmCanisterClient { self.client.query("get_evm_global_state", ()).await } + /// Returns the max pool size. This is the maximum amount of transactions + /// that can be in the pool. + pub async fn get_max_tx_pool_size(&self) -> CanisterClientResult { + self.client.query("get_max_tx_pool_size", ()).await + } + /// Sets the global state of the EVM. pub async fn admin_set_evm_global_state( &self, @@ -493,6 +548,19 @@ impl EvmCanisterClient { .await } + /// Sets the coinbase address. + pub async fn admin_set_coinbase( + &mut self, + coinbase: H160, + ) -> CanisterClientResult> { + self.client.update("admin_set_coinbase", (coinbase,)).await + } + + /// Removes all transactions from the transaction pool. + pub async fn admin_clear_pool(&mut self) -> CanisterClientResult> { + self.client.update("admin_clear_pool", ()).await + } + /// Returns whether unsafe blocks are enabled pub async fn is_unsafe_blocks_enabled(&self) -> CanisterClientResult { self.client.query("is_unsafe_blocks_enabled", ()).await From b6de72ca03ebaef80345681f7e3988f646865c99 Mon Sep 17 00:00:00 2001 From: Francesco Date: Mon, 19 May 2025 12:08:32 +0200 Subject: [PATCH 2/3] Fix_self --- src/evm-canister-client/src/client.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/evm-canister-client/src/client.rs b/src/evm-canister-client/src/client.rs index 4f94c64a..4bb8ad7b 100644 --- a/src/evm-canister-client/src/client.rs +++ b/src/evm-canister-client/src/client.rs @@ -550,14 +550,14 @@ impl EvmCanisterClient { /// Sets the coinbase address. pub async fn admin_set_coinbase( - &mut self, + &self, coinbase: H160, ) -> CanisterClientResult> { self.client.update("admin_set_coinbase", (coinbase,)).await } /// Removes all transactions from the transaction pool. - pub async fn admin_clear_pool(&mut self) -> CanisterClientResult> { + pub async fn admin_clear_pool(&self) -> CanisterClientResult> { self.client.update("admin_clear_pool", ()).await } From 78ef78f44d10a42a14b9f8dcf4927227a52651d3 Mon Sep 17 00:00:00 2001 From: Francesco Date: Mon, 19 May 2025 12:08:46 +0200 Subject: [PATCH 3/3] fmt --- src/evm-canister-client/src/client.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/evm-canister-client/src/client.rs b/src/evm-canister-client/src/client.rs index 4bb8ad7b..8e9b2eb6 100644 --- a/src/evm-canister-client/src/client.rs +++ b/src/evm-canister-client/src/client.rs @@ -549,10 +549,7 @@ impl EvmCanisterClient { } /// Sets the coinbase address. - pub async fn admin_set_coinbase( - &self, - coinbase: H160, - ) -> CanisterClientResult> { + pub async fn admin_set_coinbase(&self, coinbase: H160) -> CanisterClientResult> { self.client.update("admin_set_coinbase", (coinbase,)).await }