Skip to content

Commit 06c5f7b

Browse files
authored
chore: don't depend on config in common (#11756)
* chore: don't depend on config in common * feats
1 parent a70e6c0 commit 06c5f7b

File tree

13 files changed

+37
-42
lines changed

13 files changed

+37
-42
lines changed

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,10 @@ foundry-linking = { path = "crates/linking" }
208208

209209
# solc & compilation utilities
210210
foundry-block-explorers = { version = "0.22.0", default-features = false }
211-
foundry-compilers = { version = "0.19.1", default-features = false }
211+
foundry-compilers = { version = "0.19.1", default-features = false, features = [
212+
"rustls",
213+
"svm-solc",
214+
] }
212215
foundry-fork-db = "0.18"
213216
solang-parser = { version = "=0.3.9", package = "foundry-solang-parser" }
214217
solar = { package = "solar-compiler", version = "=0.1.7", default-features = false }

crates/cast/src/cmd/artifact.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use clap::{Parser, command};
88
use eyre::Result;
99
use foundry_cli::{
1010
opts::{EtherscanOpts, RpcOpts},
11-
utils::{self, LoadConfig},
11+
utils::{self, LoadConfig, fetch_abi_from_etherscan},
1212
};
13-
use foundry_common::{abi::fetch_abi_from_etherscan, fs};
13+
use foundry_common::fs;
1414
use serde_json::json;
1515
use std::path::PathBuf;
1616

crates/cast/src/cmd/constructor_args.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ use clap::{Parser, command};
66
use eyre::{OptionExt, Result, eyre};
77
use foundry_cli::{
88
opts::{EtherscanOpts, RpcOpts},
9-
utils::{self, LoadConfig},
9+
utils::{self, LoadConfig, fetch_abi_from_etherscan},
1010
};
11-
use foundry_common::abi::fetch_abi_from_etherscan;
1211
use foundry_config::Config;
1312

1413
foundry_config::impl_figment_convert!(ConstructorArgsArgs, etherscan, rpc);

crates/cast/src/cmd/creation_code.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use eyre::{OptionExt, Result, eyre};
99
use foundry_block_explorers::Client;
1010
use foundry_cli::{
1111
opts::{EtherscanOpts, RpcOpts},
12-
utils::{self, LoadConfig},
12+
utils::{self, LoadConfig, fetch_abi_from_etherscan},
1313
};
14-
use foundry_common::{abi::fetch_abi_from_etherscan, provider::RetryProvider};
14+
use foundry_common::provider::RetryProvider;
1515
use foundry_config::Config;
1616

1717
foundry_config::impl_figment_convert!(CreationCodeArgs, etherscan, rpc);

crates/cast/src/cmd/interface.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ use alloy_json_abi::{ContractObject, JsonAbi};
22
use alloy_primitives::Address;
33
use clap::Parser;
44
use eyre::{Context, Result};
5-
use foundry_cli::{opts::EtherscanOpts, utils::LoadConfig};
5+
use foundry_cli::{
6+
opts::EtherscanOpts,
7+
utils::{LoadConfig, fetch_abi_from_etherscan},
8+
};
69
use foundry_common::{
710
ContractsByArtifact,
8-
abi::fetch_abi_from_etherscan,
911
compile::{PathOrContractInfo, ProjectCompiler},
1012
find_target_path, fs, shell,
1113
};

crates/chisel/src/dispatcher.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::{
1010
use alloy_primitives::{Address, hex};
1111
use eyre::{Context, Result};
1212
use forge_fmt::FormatterConfig;
13+
use foundry_cli::utils::fetch_abi_from_etherscan;
1314
use foundry_config::RpcEndpointUrl;
1415
use foundry_evm::{
1516
decode::decode_console_logs,
@@ -466,12 +467,9 @@ impl ChiselDispatcher {
466467

467468
/// Fetches an interface from Etherscan
468469
pub(crate) async fn fetch_interface(&mut self, address: Address, name: String) -> Result<()> {
469-
let abis = foundry_common::abi::fetch_abi_from_etherscan(
470-
address,
471-
&self.source().config.foundry_config,
472-
)
473-
.await
474-
.wrap_err("Failed to fetch ABI from Etherscan")?;
470+
let abis = fetch_abi_from_etherscan(address, &self.source().config.foundry_config)
471+
.await
472+
.wrap_err("Failed to fetch ABI from Etherscan")?;
475473
let (abi, _) = abis
476474
.into_iter()
477475
.next()

crates/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ workspace = true
1414

1515
[dependencies]
1616
forge-fmt.workspace = true
17+
foundry-block-explorers.workspace = true
1718
foundry-common.workspace = true
1819
foundry-config.workspace = true
1920
foundry-debugger.workspace = true

crates/cli/src/utils/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use alloy_json_abi::JsonAbi;
2-
use alloy_primitives::{U256, map::HashMap};
2+
use alloy_primitives::{Address, U256, map::HashMap};
33
use alloy_provider::{Provider, network::AnyNetwork};
44
use eyre::{ContextCompat, Result};
55
use foundry_common::{
@@ -247,6 +247,18 @@ pub fn install_crypto_provider() {
247247
.expect("Failed to install default rustls crypto provider");
248248
}
249249

250+
/// Fetches the ABI of a contract from Etherscan.
251+
pub async fn fetch_abi_from_etherscan(
252+
address: Address,
253+
config: &foundry_config::Config,
254+
) -> Result<Vec<(JsonAbi, String)>> {
255+
let chain = config.chain.unwrap_or_default();
256+
let api_key = config.get_etherscan_api_key(Some(chain)).unwrap_or_default();
257+
let client = foundry_block_explorers::Client::new(chain, api_key)?;
258+
let source = client.contract_source_code(address).await?;
259+
source.items.into_iter().map(|item| Ok((item.abi()?, item.contract_name))).collect()
260+
}
261+
250262
/// Useful extensions to [`std::process::Command`].
251263
pub trait CommandUtils {
252264
/// Returns the command's output if execution is successful, otherwise, throws an error.

crates/common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ workspace = true
1616
foundry-block-explorers = { workspace = true, features = ["foundry-compilers"] }
1717
foundry-common-fmt.workspace = true
1818
foundry-compilers.workspace = true
19-
foundry-config.workspace = true
2019

20+
alloy-chains.workspace = true
2121
alloy-dyn-abi = { workspace = true, features = ["arbitrary", "eip712"] }
2222
alloy-eips.workspace = true
2323
alloy-json-abi.workspace = true

0 commit comments

Comments
 (0)