From 83f434652938cc888cbde1198466eb13a39646cf Mon Sep 17 00:00:00 2001 From: Aleksey Proshutinskiy Date: Mon, 18 Mar 2024 14:26:02 +0200 Subject: [PATCH] feat(connector): allow to set default fees (#2181) --- crates/chain-connector/src/connector.rs | 12 +++++++++++- crates/chain-listener/Cargo.toml | 2 +- crates/cid-utils/Cargo.toml | 2 +- crates/server-config/src/node_config.rs | 4 ++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/crates/chain-connector/src/connector.rs b/crates/chain-connector/src/connector.rs index 6000a409d3..45307f9ff7 100644 --- a/crates/chain-connector/src/connector.rs +++ b/crates/chain-connector/src/connector.rs @@ -1,5 +1,5 @@ use alloy_primitives::hex::ToHexExt; -use alloy_primitives::{uint, FixedBytes, U256}; +use alloy_primitives::{uint, FixedBytes, Uint, U256}; use alloy_sol_types::sol_data::Array; use alloy_sol_types::{SolCall, SolType}; use std::collections::HashMap; @@ -106,6 +106,10 @@ impl ChainConnector { } async fn get_base_fee_per_gas(&self) -> Result { + if let Some(fee) = self.config.default_base_fee { + return Ok(Uint::from(fee)); + } + let block: Value = process_response( self.client .request("eth_getBlockByNumber", rpc_params!["pending", false]) @@ -138,6 +142,10 @@ impl ChainConnector { } async fn max_priority_fee_per_gas(&self) -> Result { + if let Some(fee) = self.config.default_priority_fee { + return Ok(Uint::from(fee)); + } + let resp: String = process_response( self.client .request("eth_maxPriorityFeePerGas", rpc_params![]) @@ -568,6 +576,8 @@ mod tests { "0x97a2456e78c4894c62eef6031972d1ca296ed40bf311ab54c231f13db59fc428", ) .unwrap(), + default_base_fee: None, + default_priority_fee: None, }, peer_id_from_hex("0x6497db93b32e4cdd979ada46a23249f444da1efb186cd74b9666bd03f710028b") .unwrap(), diff --git a/crates/chain-listener/Cargo.toml b/crates/chain-listener/Cargo.toml index 10ec32b1fb..a6efe1ebbb 100644 --- a/crates/chain-listener/Cargo.toml +++ b/crates/chain-listener/Cargo.toml @@ -23,7 +23,7 @@ serde_json = { workspace = true } tokio = { workspace = true, features = ["rt"] } server-config = { workspace = true } types = { workspace = true } -libipld = "0.16.0" +libipld = { workspace = true } alloy-sol-types = { workspace = true } alloy-primitives = { workspace = true } diff --git a/crates/cid-utils/Cargo.toml b/crates/cid-utils/Cargo.toml index 37ee9de776..8cbdf65721 100644 --- a/crates/cid-utils/Cargo.toml +++ b/crates/cid-utils/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] serde = { workspace = true } -libipld = "0.16.0" +libipld = { workspace = true } bytes = "1.5.0" quick-protobuf = "0.8.1" eyre = { workspace = true } diff --git a/crates/server-config/src/node_config.rs b/crates/server-config/src/node_config.rs index 2f684dbd12..0c162d4004 100644 --- a/crates/server-config/src/node_config.rs +++ b/crates/server-config/src/node_config.rs @@ -567,6 +567,10 @@ pub struct ChainConfig { pub market_contract_address: String, pub network_id: u64, pub wallet_key: PrivateKey, + /// If none, comes from the chain + pub default_base_fee: Option, + /// If none, comes from the chain + pub default_priority_fee: Option, } #[derive(Clone, Deserialize, Serialize, Derivative)]