Skip to content

migrate to hardhat 3#1

Open
kanej wants to merge 13 commits into
mainfrom
chore/migrate-to-hardhat
Open

migrate to hardhat 3#1
kanej wants to merge 13 commits into
mainfrom
chore/migrate-to-hardhat

Conversation

@kanej

@kanej kanej commented Jun 1, 2026

Copy link
Copy Markdown
Member

Migrate aqua to Hardhat 3.

Building

The build settings have been ported from foundry.toml into a new hardhat.config.ts, and can be run with:

yarn build # or npx hardhat build

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 the remappings.txt file.

The hardhat-ignore-warnings plugin has been added to exclude warnings about test contract sizes.

Testing

The Solidity Test suite (50 tests) is passing

yarn test

Coverage

A coverage report (including an html report) can be generated with:

npx hardhat test --coverage

Gas Report

The gas snapshot file .gas-snapshot has been updated to Hardhat's format.

To update the snapshot:

yarn snapshot # or npx hardhat test solidity --snapshot

To check against the snapshot:

snapshot:check # npx hardhat test solidity --snapshot-check

Formatting

Formatting is now managed with prettier and prettier-plugin-solidity. The settings were chosen to minimize code level changes. The Solidity files have had the new formatting applied.

To format all files:

yarn format

To check the formatting:

yarn lint

Deployment

A sketch of a deployment setup using Hardhat Ignition has been added. The DEPLOY.md has 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:

yarn hardhat run ./script/deployAquaRouter.ts

To run against a local development node:

yarn hardhat node 

# In another tab
yarn hardhat run ./script/deployAquaRouter.ts --network localhost

Review

Note

Reviewing this PR a commit at a time is the easiest approach

The latest `solidity-utils` uses package exports for the contracts,
which is necessary with Hardhat 3 as it complies with npm resolution
rules.
@kanej kanej force-pushed the chore/migrate-to-hardhat branch from 87ddfd1 to 480d706 Compare June 2, 2026 14:44
Pull in Hardhat 3 as a dev dependency. Add type `module` to the
package.json so that the project is treated as ESM.
@kanej kanej force-pushed the chore/migrate-to-hardhat branch 2 times, most recently from 5ad9846 to 9fa4cca Compare June 2, 2026 15:38
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.
@kanej kanej force-pushed the chore/migrate-to-hardhat branch 9 times, most recently from 46ccee2 to a76bed1 Compare June 4, 2026 17:28
@kanej kanej marked this pull request as ready for review June 4, 2026 17:29
kanej added 10 commits June 8, 2026 16:37
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.
@kanej kanej force-pushed the chore/migrate-to-hardhat branch from a76bed1 to d674935 Compare June 8, 2026 16:38
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.

1 participant