Skip to content

Commit

Permalink
feat(forge): clone verified contracts as a foundry project (#7576)
Browse files Browse the repository at this point in the history
* feat:support forge clone

* feat: update configuration based on metadate from EtherScan 👷

* doc: update the documenation for

* add dump_sources function

* fix: add existing remapping into remappings.txt

* apply remapping on libraries

* add tests

* feat: update remappings in config file

* add two more test cases

* fix library remapping bug

* test: add e2e test cases for forge clone

* test: fix rate limit issue for forge clone tests

* feat: disable git by default for forge clone

* dump clone.toml metadata in cloned projects

* add storage layout to the clone metadata

* dump clone metadata in a hidden, readonly, compact json file

* add constructor arguments in clone metadata

* fix: typo field name

* fix: bug in remapping

* fix: remapping disorder for verified foundry contracts

* fix clippy and fmt warnings

* fmt in the foundry way

* chore: restore files to be consistent with foundry fmt style

* cherry pick bug fixes from tweak branch

* fix: remove the dependency of Etherscan in tests

* chore: move mockall to dev dependency, only mock in test build

* feat: use camelCase in .clone.meta

* doc: add comments to explain forge clone

* fix: import file not found error

* chore: remove uncessary dependency

fix: fix a foundry config bug regarding generating project_paths

* chore: refactor the test code a bit

* Update crates/forge/bin/cmd/clone.rs

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>

* Update crates/forge/bin/cmd/clone.rs

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>

* chore: change string as address in CloneArg

* test: add one basic forgetest for clone

* feat: dump remappings into remappings.txt by default

chore: break a large function into multiple small one to improve readability

* feat: improve UX and make --quiet true quiet

* test: add one more forgetest! for clone

* fix minor issues suggested in code review

* fix: incorrect assertion for project paths

* test: add default etherscan api keys and remove sleep in tests

* test: add more etherscan api keys

* fix: revoke the unnecessary changes in config.rs

* feat: bump foundry-compilers to 0.3.16

* chore: refactor code and clean some comments

* fix: path disorder on windows

* touchups

---------

Co-authored-by: Zhuo Zhang <zhan3299@purdue.edu>
Co-authored-by: Zhuo Zhang <14835483+ZhangZhuoSJTU@users.noreply.github.com>
Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
  • Loading branch information
5 people authored Apr 18, 2024
1 parent e5b8fc9 commit 1c59fcc
Show file tree
Hide file tree
Showing 24 changed files with 1,609 additions and 12 deletions.
74 changes: 74 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions crates/common/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ static ALCHEMY_MAINNET_KEYS: Lazy<Vec<&'static str>> = Lazy::new(|| {
keys
});

// List of etherscan keys for mainnet
static ETHERSCAN_MAINNET_KEYS: Lazy<Vec<&'static str>> = Lazy::new(|| {
let mut keys = vec![
"MCAUM7WPE9XP5UQMZPCKIBUJHPM1C24FP6",
"JW6RWCG2C5QF8TANH4KC7AYIF1CX7RB5D1",
"ZSMDY6BI2H55MBE3G9CUUQT4XYUDBB6ZSK",
"4FYHTY429IXYMJNS4TITKDMUKW5QRYDX61",
"QYKNT5RHASZ7PGQE68FNQWH99IXVTVVD2I",
"VXMQ117UN58Y4RHWUB8K1UGCEA7UQEWK55",
];

keys.shuffle(&mut rand::thread_rng());

keys
});

/// counts how many times a rpc endpoint was requested for _mainnet_
static NEXT_RPC_ENDPOINT: AtomicUsize = AtomicUsize::new(0);

Expand Down Expand Up @@ -111,6 +127,12 @@ pub fn next_ws_archive_rpc_endpoint() -> String {
format!("wss://eth-mainnet.alchemyapi.io/v2/{}", ALCHEMY_MAINNET_KEYS[idx])
}

/// Returns the next etherscan api key
pub fn next_etherscan_api_key() -> String {
let idx = next() % ETHERSCAN_MAINNET_KEYS.len();
ETHERSCAN_MAINNET_KEYS[idx].to_string()
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ impl Config {
self.rpc_storage_caching.enable_for_endpoint(endpoint)
}

/// Returns the `ProjectPathsConfig` sub set of the config.
/// Returns the `ProjectPathsConfig` sub set of the config.
///
/// **NOTE**: this uses the paths as they are and does __not__ modify them, see
/// `[Self::sanitized]`
Expand Down
3 changes: 3 additions & 0 deletions crates/forge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ solang-parser.workspace = true
strum = { workspace = true, features = ["derive"] }
thiserror = "1"
tokio = { version = "1", features = ["time"] }
toml = { version = "0.8", features = ["preserve_order"] }
toml_edit = "0.22.4"
watchexec = "2.3.2"
evm-disassembler.workspace = true
rustc-hash.workspace = true
Expand All @@ -96,6 +98,7 @@ tikv-jemallocator = { workspace = true, optional = true }
anvil.workspace = true
foundry-test-utils.workspace = true

mockall = "0.12"
criterion = "0.5"
globset = "0.4"
paste = "1.0"
Expand Down
Loading

0 comments on commit 1c59fcc

Please sign in to comment.