Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(forge): clone verified contracts as a foundry project #7576

Merged
merged 60 commits into from
Apr 18, 2024

Conversation

Troublor
Copy link
Contributor

@Troublor Troublor commented Apr 5, 2024

This PR is the first step of integrating on-chain contract tweak feature into foundry, as mentioned in #7575.

We introduce forge clone command, which takes the address of an on-chain verified contract and creates a corresponding foundry project in the local filesystem.

The foundry configuration foundry.toml is well generated so that the project is compilation-ready and guaranteed to generate exactly the same code as the on-chain contract.

We also generate a metadata file, .clone.meta, which contains the original address of the contract, constructor arguments, storage layout, etc, which may be useful for downstream tasks.

ZhangZhuoSJTU and others added 30 commits March 26, 2024 21:47
Test: fix rate limit issue for forge clone tests
Add `clone.toml` metadata to forge clone
Add constructor arguments in the clone metadata
crates/config/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following the practice of RPC endpoints in testing, I also added a list of mainnet Etherscan API keys to facilitate integrated tests that require fetching Etherscan data, e.g., forge clone. The rate limit of Etherscan API with keys should be sufficient to allow tests pass.

@Troublor
Copy link
Contributor Author

Thanks for your effort @mattsse! We have future addressed some issues in tests. Could you trigger the CI test and see if this PR works?

@mattsse
Copy link
Member

mattsse commented Apr 17, 2024

ty @Troublor

I'll give this a final review tmrw

@ZhangZhuoSJTU
Copy link
Contributor

There's an unusual CI test failure here, although the CI appears correctly in our repo.

@mattsse
Copy link
Member

mattsse commented Apr 18, 2024

nice work!

I'm unable to push directly to this branch for some reason,
could you please include my last commit from https://github.com/foundry-rs/foundry/compare/master...mattsse:foundry:matt/forge-clone?expand=1

then this is g2m

@Troublor
Copy link
Contributor Author

@mattsse I just merged the latest commit on master branch. Sorry to interrupt the CI that you just triggered. Could you please trigger again?

@mattsse mattsse merged commit 1c59fcc into foundry-rs:master Apr 18, 2024
20 checks passed
@mattsse
Copy link
Member

mattsse commented Apr 18, 2024

tysm for this!

klkvr pushed a commit that referenced this pull request Apr 20, 2024
* 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>
@ZhangZhuoSJTU ZhangZhuoSJTU deleted the forge_clone branch April 20, 2024 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants