migrate to hardhat 3#1
Open
kanej wants to merge 13 commits into
Open
Conversation
The latest `solidity-utils` uses package exports for the contracts, which is necessary with Hardhat 3 as it complies with npm resolution rules.
87ddfd1 to
480d706
Compare
Pull in Hardhat 3 as a dev dependency. Add type `module` to the package.json so that the project is treated as ESM.
5ad9846 to
9fa4cca
Compare
Hardhat 3 resolution honours npm transient dependency resolution, hence to ensure the same version of OpenZeppelin Contracts is used throughout contract compilation we add an explicit resolution.
46ccee2 to
a76bed1
Compare
Based on `foundry.toml` create an equivalent `hardhat.config.ts` file. The identical `[profile.default]` and `[profile.ci]` have been collapsed down into the single compilers setting. The `solx` profile has been left out as experimental rather than required for day to day development. Other Foundry-only settings that have been left out: 1. `[fmt]` - formatting will be replaced by prettier in a subsequent commit. 2. libs - npm dependencies will be used for dependency resolution in a subsequent commit.
Hardhat 3 Solidity import resolution can access npm modules directly, hence does not require remappings for forge/openzeppelin/solidity-utils. However, one remapping has been added `src/=src` to allow absolute imports. This is to avoid changing the imports in the Solidity files. It would be a small change to remove this remapping and update the Solidity imports with a small number of relative imports.
Update the package.json to change the test script to run Hardhat. There are no TS/JS tests so invoke Solidity test directly.
Hardhat supports recording a gas snapshot to `./.gas-snapshot`. It uses a slightly different format to Foundry, so the snapshot file has been updated. The `snapshot` script in the `package.json` has been updated to allow writing or updating the snapshot file by running: ```shell npm run snapshot ```
The core CI checks have been ported to using the Hardhat variants, so tests and the gas check. This required installing Node 24 to support running Hardhat. The snapshot check has been encoded as a script in the package.json for local running. The target branch was updated to `main`.
To replace `forge fmt` we add prettier with `prettier-plugin-solidity`. The configuration includes rules for ts, json and solidity. The Solidity file rules are aimed to reduce the number of formatting changes. Format and lint scripts have been added to the `package.json`, and swapped into the makefile.
Based on the config a run of `yarn run format` has updated the formatting.
Ignore solc warnings for code size when coming from tests and for transient storage from the 1inch/solidity-utils npm package.
This is a sketch of an Ignition based deployment for the AquaRouter, retaining the owner lookup from config via a wrapping script, but gaining the advantage of Ignition handling the deployment. Instead of passing in env variables, the `hardhat-keystore` plugin has been included.
a76bed1 to
d674935
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Migrate
aquato Hardhat 3.Building
The build settings have been ported from
foundry.tomlinto a newhardhat.config.ts, and can be run with:Hardhat 3 is able to resolve imports from node modules without further config. A single
src/=src/remapping has been kept to support absolute imports. We would recommend updating the tests to relative imports, and removing theremappings.txtfile.The
hardhat-ignore-warningsplugin has been added to exclude warnings about test contract sizes.Testing
The Solidity Test suite (50 tests) is passing
yarn testCoverage
A coverage report (including an html report) can be generated with:
Gas Report
The gas snapshot file
.gas-snapshothas been updated to Hardhat's format.To update the snapshot:
To check against the snapshot:
Formatting
Formatting is now managed with
prettierandprettier-plugin-solidity. The settings were chosen to minimize code level changes. The Solidity files have had the new formatting applied.To format all files:
To check the formatting:
Deployment
A sketch of a deployment setup using Hardhat Ignition has been added. The
DEPLOY.mdhas been partially updated to reflect this.The owner continues to be set based on the config. The owner for the development network (31337) has been set to the first built-in Hardhat account.
To run against an in-memory Hardhat network:
To run against a local development node:
yarn hardhat node # In another tab yarn hardhat run ./script/deployAquaRouter.ts --network localhostReview
Note
Reviewing this PR a commit at a time is the easiest approach