Skip to content
This repository was archived by the owner on Apr 8, 2026. It is now read-only.

feat: write hardhat style artifacts to disk#38

Merged
gakonst merged 4 commits intofoundry-rs:developfrom
tynes:feat/write-hh-to-disk
May 30, 2022
Merged

feat: write hardhat style artifacts to disk#38
gakonst merged 4 commits intofoundry-rs:developfrom
tynes:feat/write-hh-to-disk

Conversation

@tynes
Copy link
Copy Markdown
Collaborator

@tynes tynes commented May 29, 2022

This will now write hardhat style artifacts to disk after running hardhat compile.

An example of how hardhat does this:

artifacts/
├── build-info
├── contracts
│   ├── chugsplash
│   ├── L1
│   ├── L2
│   ├── libraries
│   ├── standards
└── @openzeppelin
    ├── contracts
    └── contracts-upgradeable

The layout of the artifacts mirrors the layout of the contract source, unlike foundry which flattens all of the artifacts into a single top level directory

As of this PR, artifacts/build-info is not populated. I do not believe deps are compiled either unless they are used (the openzeppelin contracts in this example), hh seems to always compile them.

I do think that having the functionality to build hardhat style artifacts would be more suited for ethers-rs as the relative path to the source file is lost without looking at the forge artifact .ast.absolutePath (and having latest forge with gakonst/ethers-rs@54f1b9d ?).

This errors if 2 contracts have the same name, see:

throw new HardhatError(ERRORS.ARTIFACTS.MULTIPLE_FOUND, {

This is very helpful for making things just work with hardhat deploy and hardhat tasks.

A few thoughts on the design:

  • A config option to choose to write the files to disk or not? Unclear where in the hardhat config that would live, something like .forge.writeArtifacts? and default it to true?
  • Write the files to disk in the constructor instead of after constructing the ForgeArtifacts?

Right now in a project I am using an alternative and very hacky method to write the hh artifacts to disk and have confirmed that with having them written to disk, hardhat deploy works with anvil

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented May 29, 2022

🦋 Changeset detected

Latest commit: 35848b2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@foundry-rs/hardhat-forge Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@tynes
Copy link
Copy Markdown
Collaborator Author

tynes commented May 29, 2022

Will fix the tests, the version of nodejs used in ci doesn't have the fs/promises package.
Edit: tests are passing now

tynes added 4 commits May 29, 2022 16:35
Adds a function `writeArtifactsSync` that
accepts an output directory and will write
hardhat style artifacts to disk in that directory.
@tynes tynes force-pushed the feat/write-hh-to-disk branch from 965cd92 to 35848b2 Compare May 29, 2022 23:35
@gakonst gakonst merged commit b092fe5 into foundry-rs:develop May 30, 2022
@tynes tynes deleted the feat/write-hh-to-disk branch May 30, 2022 05:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants