diff --git a/cli/src/cmd/cast/run.rs b/cli/src/cmd/cast/run.rs index 45836f6f0040b..bf99e276cbf52 100644 --- a/cli/src/cmd/cast/run.rs +++ b/cli/src/cmd/cast/run.rs @@ -71,6 +71,21 @@ pub struct RunArgs { /// Overrides the version specified in the config. #[clap(long, short)] evm_version: Option, + /// Sets the number of assumed available compute units per second for this provider + /// + /// default value: 330 + /// + /// See also, https://github.com/alchemyplatform/alchemy-docs/blob/master/documentation/compute-units.md#rate-limits-cups + #[clap(long, alias = "cups", value_name = "CUPS")] + pub compute_units_per_second: Option, + + /// Disables rate limiting for this node's provider. + /// + /// default value: false + /// + /// See also, https://github.com/alchemyplatform/alchemy-docs/blob/master/documentation/compute-units.md#rate-limits-cups + #[clap(long, value_name = "NO_RATE_LIMITS", visible_alias = "no-rpc-rate-limit")] + pub no_rate_limit: bool, } impl RunArgs { @@ -84,7 +99,13 @@ impl RunArgs { Config::figment_with_root(find_project_root_path(None).unwrap()).merge(self.rpc); let mut evm_opts = figment.extract::()?; let config = Config::from_provider(figment).sanitized(); - let provider = utils::get_provider(&config)?; + + let compute_units_per_second = + if self.no_rate_limit { Some(u64::MAX) } else { self.compute_units_per_second }; + + let provider = utils::get_provider_builder(&config)? + .compute_units_per_second_opt(compute_units_per_second) + .build()?; let tx_hash = self.tx_hash.parse().wrap_err("invalid tx hash")?; let tx = provider diff --git a/cli/src/utils.rs b/cli/src/utils.rs index bbc973f55d7c4..e84c6e84e8d34 100644 --- a/cli/src/utils.rs +++ b/cli/src/utils.rs @@ -93,9 +93,16 @@ pub fn parse_u256(s: &str) -> Result { /// /// Defaults to `http://localhost:8545` and `Mainnet`. pub fn get_provider(config: &Config) -> Result { + get_provider_builder(config)?.build() +} +/// Returns a [ProviderBuilder](foundry_common::ProviderBuilder) instantiated using [Config]'s RPC +/// URL and chain. +/// +/// Defaults to `http://localhost:8545` and `Mainnet`. +pub fn get_provider_builder(config: &Config) -> Result { let url = config.get_rpc_url_or_localhost_http()?; let chain = config.chain_id.unwrap_or_default(); - foundry_common::ProviderBuilder::new(url.as_ref()).chain(chain).build() + Ok(foundry_common::ProviderBuilder::new(url.as_ref()).chain(chain)) } pub async fn get_chain(chain: Option, provider: M) -> Result diff --git a/common/src/provider.rs b/common/src/provider.rs index 2db74e6f70057..f0322722cf6bf 100644 --- a/common/src/provider.rs +++ b/common/src/provider.rs @@ -124,6 +124,16 @@ impl ProviderBuilder { self } + /// Sets the number of assumed available compute units per second + /// + /// See also, + pub fn compute_units_per_second_opt(mut self, compute_units_per_second: Option) -> Self { + if let Some(cups) = compute_units_per_second { + self.compute_units_per_second = cups; + } + self + } + /// Sets aggressive `max_retry` and `initial_backoff` values /// /// This is only recommend for local dev nodes