diff --git a/Cargo.lock b/Cargo.lock index 72d3b80bd0a..b0ebac4b3c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11083,6 +11083,14 @@ dependencies = [ "url", ] +[[package]] +name = "starknet_l1_gas_price" +version = "0.0.0" +dependencies = [ + "starknet_api", + "thiserror 1.0.69", +] + [[package]] name = "starknet_l1_provider" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index 41bd6b00cf0..65d7f366534 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,7 @@ members = [ "crates/starknet_http_server", "crates/starknet_infra_utils", "crates/starknet_integration_tests", + "crates/starknet_l1_gas_price", "crates/starknet_l1_provider", "crates/starknet_l1_provider_types", "crates/starknet_mempool", diff --git a/crates/starknet_l1_gas_price/Cargo.toml b/crates/starknet_l1_gas_price/Cargo.toml new file mode 100644 index 00000000000..6f0b5f9e404 --- /dev/null +++ b/crates/starknet_l1_gas_price/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "starknet_l1_gas_price" +version.workspace = true +edition.workspace = true +repository.workspace = true +license.workspace = true + +[dependencies] +starknet_api.workspace = true +thiserror.workspace = true + +[lints] +workspace = true diff --git a/crates/starknet_l1_gas_price/src/l1_gas_price_provider.rs b/crates/starknet_l1_gas_price/src/l1_gas_price_provider.rs new file mode 100644 index 00000000000..d169582bd6d --- /dev/null +++ b/crates/starknet_l1_gas_price/src/l1_gas_price_provider.rs @@ -0,0 +1,31 @@ +use starknet_api::block::{BlockNumber, BlockTimestamp}; +use thiserror::Error; + +// TODO(guyn): both these constants need to go into VersionedConstants. +pub const MEAN_NUMBER_OF_BLOCKS: u64 = 300; +pub const LAG_MARGIN_SECONDS: u64 = 60; + +// TODO(guyn, Gilad): consider moving this to starknet_l1_provider_types/lib.rs? +// This is an interface that allows sharing the provider with the scraper across threads. +pub trait L1GasPriceProviderClient: Send + Sync { + fn add_price_info( + &self, + height: BlockNumber, + timestamp: BlockTimestamp, + gas_price: u128, + data_gas_price: u128, + ) -> Result<(), L1GasPriceProviderError>; + + fn get_price_info( + &self, + timestamp: BlockTimestamp, + ) -> Result<(u128, u128), L1GasPriceProviderError>; +} + +#[derive(Clone, Debug, Error)] +pub enum L1GasPriceProviderError { + #[error("Failed to add price info: {0}")] + AddPriceInfoError(String), + #[error("Failed to get price info: {0}")] + GetPriceInfoError(String), +} diff --git a/crates/starknet_l1_gas_price/src/lib.rs b/crates/starknet_l1_gas_price/src/lib.rs new file mode 100644 index 00000000000..3e6fbb983bb --- /dev/null +++ b/crates/starknet_l1_gas_price/src/lib.rs @@ -0,0 +1 @@ +pub mod l1_gas_price_provider;