Skip to content

Chore/migrate to hardhat#131

Open
schaable wants to merge 14 commits into
1inch:release/1.1from
NomicFoundation:migrate-to-hh3
Open

Chore/migrate to hardhat#131
schaable wants to merge 14 commits into
1inch:release/1.1from
NomicFoundation:migrate-to-hh3

Conversation

@schaable

@schaable schaable commented Jun 8, 2026

Copy link
Copy Markdown

Makes Hardhat 3 the primary toolchain for swap-vm: compilation, Solidity tests, gas snapshots, CI, and deployment now run on Hardhat. The build configuration from foundry.toml was migrated into a new hardhat.config.ts.

Parity: all 706 Solidity tests pass under Hardhat 3, matching Forge exactly (706/706). No tests were disabled and no behavioral differences were found. When the gas snapshots were first regenerated under Hardhat, all non-fuzz values matched Forge exactly (705/705). A later bump to @1inch/solidity-utils@6.9.9 increased all entries by a small, uniform amount (≤0.032%).

Building

The via_ir and custom Yul optimizerSteps settings were translated directly into the solc configuration and applied to both the default and production profiles. This is required because Ignition builds use production, and the router contracts hit "stack too deep" errors without viaIR.

yarn build   # or npx hardhat compile

Added hardhat-ignore-warnings to suppress solc warnings from dependencies and test contracts.

Testing

The full Solidity test suite (706 tests) passes under Hardhat.

yarn test   # or npx hardhat test solidity

Coverage

Generate a coverage report (including HTML output) with:

npx hardhat test solidity --coverage

Produces coverage/lcov.info and an HTML report. Unlike Forge, no --ir-minimum flag is required for this via-IR project.

Gas Report

Gas snapshots were regenerated under Hardhat and integrated into yarn snapshot:check. Both .gas-snapshot and the snapshots/*.json files are covered.

To update the snapshot:

yarn snapshot   # or npx hardhat test solidity --snapshot

To check against the snapshot:

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

Compared to the original Forge baseline, the differences are:

  • Formatting (Contract#func() vs Contract:func())
  • The mean/median values of the single fuzz test (≤0.3%, expected because the fuzzing engines explore different inputs)
  • A small, uniform increase across all 605 non-fuzz entries (≤0.032%) introduced by the @1inch/solidity-utils@6.9.9 upgrade, which slightly increased the bytecode size of a hot-path library

The baselines (.gas-snapshot and snapshots/*.json) were regenerated after the dependency upgrade. All 706 tests continue to pass.

Deployment

Added Hardhat Ignition and hardhat-verify alongside the existing Foundry deployment flow. The modules in ignition/modules/ are generated from a shared _router.ts factory, and per-chain ignition/parameters/chain-<chainId>.json files replace the previous Config.sol JSON-loading mechanism. Verification uses Etherscan API v2, with constructor arguments provided automatically by Ignition.

npx hardhat ignition deploy ignition/modules/<Module>.ts \
  --network <network> \
  --parameters ignition/parameters/chain-<chainId>.json

Add --verify to verify during deployment. The full workflow is documented in DEPLOY.md.

CI

Tests and gas snapshot checks now run through Hardhat. Dependency installation was also switched from npm install to yarn install --frozen-lockfile so that resolutions are respected (see below).

Key decisions

  • Yarn resolutions: pinned @1inch/solidity-utils@6.9.9 and @openzeppelin/contracts@5.4.0. Without these pins, transitive dependencies can install multiple copies of the same Solidity packages, causing type mismatches between interfaces such as IERC20 and SafeERC20. The resolutions reproduce the flat dependency layout that Forge gets through remappings. Since npm ignores resolutions, CI was moved to Yarn as well.
  • splitTestsCompilation: true: without it, a cold ignition deploy compiles the entire via-IR project (~245s) and exceeds Node's default heap limit. Enabling it restricts deployment builds to the required contracts, reducing compilation time to ~11s. Tests and gas snapshots are unaffected.

Follow-ups

  • Formatting (forge fmt -> prettier-plugin-solidity): is handled in a follow-up PR in the fork: Replace forge fmt with prettier-plugin-solidity NomicFoundation/swap-vm#2
    I kept it separate to make this PR easier to review. Once this PR is merged, I'll open the formatting PR against 1inch.
  • Removing the remaining legacy Foundry deployment path (foundry.toml, remappings.txt, Forge-related Makefile targets, and script/*.s.sol).

Review

Note

Reviewing this PR one commit at a time is likely the easiest approach.

Comment thread .github/workflows/ci.yml

- name: Install node modules
run: npm install
run: yarn install --frozen-lockfile

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

CI now installs deps with yarn instead of npm because the repo already uses yarn and relies on resolutions in package.json to pin transitive dependencies.

Comment thread package.json
"@nomicfoundation/hardhat-ignition": "^3.1.6",
"@nomicfoundation/hardhat-keystore": "^3.0.11",
"@nomicfoundation/hardhat-verify": "^3.0.0",
"hardhat": "^3.8.0",

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

We're using a range, but this can also be pinned to a specific version depending on the repo needs.

Comment thread hardhat.config.ts
Comment on lines +36 to +37
default: { compilers: [swapVmCompiler] },
production: { compilers: [swapVmCompiler] },

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

default is used as the default profile for most tasks, except for deployment and verification which use production by default.

Comment thread Makefile
@@ -1 +1 @@
# SPDX-License-Identifier: LicenseRef-Degensoft-SwapVM-1.1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I wasn't sure how get / get-outputs are used on your side (same for .env.automation / the OPS_* env vars), so I didn't migrate them for now. We can migrate them as Hardhat scripts if needed.

@schaable schaable marked this pull request as ready for review June 8, 2026 22:08
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