Skip to content

Commit

Permalink
feat(connector): allow to set default fees (#2181)
Browse files Browse the repository at this point in the history
  • Loading branch information
justprosh committed Mar 18, 2024
1 parent 1bbc0d7 commit 83f4346
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
12 changes: 11 additions & 1 deletion crates/chain-connector/src/connector.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -106,6 +106,10 @@ impl ChainConnector {
}

async fn get_base_fee_per_gas(&self) -> Result<U256, ConnectorError> {
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])
Expand Down Expand Up @@ -138,6 +142,10 @@ impl ChainConnector {
}

async fn max_priority_fee_per_gas(&self) -> Result<U256, ConnectorError> {
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![])
Expand Down Expand Up @@ -568,6 +576,8 @@ mod tests {
"0x97a2456e78c4894c62eef6031972d1ca296ed40bf311ab54c231f13db59fc428",
)
.unwrap(),
default_base_fee: None,
default_priority_fee: None,
},
peer_id_from_hex("0x6497db93b32e4cdd979ada46a23249f444da1efb186cd74b9666bd03f710028b")
.unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion crates/chain-listener/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion crates/cid-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
4 changes: 4 additions & 0 deletions crates/server-config/src/node_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>,
/// If none, comes from the chain
pub default_priority_fee: Option<u64>,
}

#[derive(Clone, Deserialize, Serialize, Derivative)]
Expand Down

0 comments on commit 83f4346

Please sign in to comment.