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

ignition: port hardhat-ignition-viem to Hardhat 3 #6260

Merged
merged 34 commits into from
Feb 14, 2025
Merged

Conversation

kanej
Copy link
Member

@kanej kanej commented Feb 11, 2025

Migrate hardhat-ignition-viem to Hardhat 3.

Preview

image

Review Questions

  • I removed Node 18 from the ./packages build matrix to allow prebuild scripts to use Hardhat 3. Those scripts are used for generating types in the fixture projects.
  • The check for ethers plugin has been kept and now throws a HardhatError from the Ignition namespace
  • I migrated HardhatPluginError exceptions directly to HardhatError exceptions using the Ignition namespace
  • Addition of a ViemIgnitionHelper interface with the impl moved to internal
  • The minimal change to ToContractType bringing through the new ContractAbis type from hardhat-viem
  • Are we happy with the peerdeps of ignition/ignition-core/hardhat-viem

Manual run through

The hardhat-ignition-viem plugin has been added to the ./v-next/example-project. There is a script showing the usage, much the preview above. To run the script:

cd v-next/example-project
pnpm clean
pnpm build # this to ensure all deps are built
pnpm hardhat run ./scripts/deploy-rocket-from-script.ts

# Compiling your Solidity contracts
# Compiled 1 Solidity file with solc 0.7.1 (evm target: istanbul)
# Compiled 10 Solidity files with solc 0.8.22 (evm target: shanghai)

# Deployed rocket with Ignition from a Hardhat Script 🚀

#   address: 0x5FbDB2315678afecb367f032d93F642f64180aa3
#   name: Saturn V
#   status: lift-off

# We have Viem type support for the contracts Ignition deployed!

# Calling a non-existent function shows as a type error.
# It causes Viem to throw:

# Function "nonexistant" not found on ABI.
# Make sure you are using the correct ABI and that the function exists on it.

TODO

  • ESmify the code
  • Format the code based up updated prettier
  • Apply latest eslint rules
  • Add in new plugin structures from HH3
  • Re-enable the tests
  • Add connection.ignition based on Hook system
  • Deal with other plugin check
  • Review HH3 todos
    • Error handling - which errors do we throw?
    • Bring back missing tests
  • Move code to internal
  • Check exported types - should we expose an interface
  • Add plugin into example project

Follow up tasks

  • Convert tests to Node Test Runner
  • Remove exemptions from eslint rules
  • Look again at type checks in tests - can this be made more comprehensible in terms of build steps
  • Remove npm scripts comparison exemption

Copy link

changeset-bot bot commented Feb 11, 2025

⚠️ No Changeset found

Latest commit: 84cc6cd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

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

💥 An error occurred when fetching the changed packages and changesets in this PR
Some errors occurred when validating the changesets config:
The package or glob expression "@nomicfoundation/hardhat-ethers-chai-matchers" is specified in the `ignore` option but it is not found in the project. You may have misspelled the package name or provided an invalid glob expression. Note that glob expressions must be defined according to https://www.npmjs.com/package/micromatch.
The package "@nomicfoundation/hardhat-chai-matchers" depends on the ignored package "hardhat", but "@nomicfoundation/hardhat-chai-matchers" is not being ignored. Please add "@nomicfoundation/hardhat-chai-matchers" to the `ignore` option.
The package "@nomicfoundation/hardhat-chai-matchers" depends on the ignored package "@nomicfoundation/hardhat-ethers", but "@nomicfoundation/hardhat-chai-matchers" is not being ignored. Please add "@nomicfoundation/hardhat-chai-matchers" to the `ignore` option.
The package "@nomicfoundation/hardhat-chai-matchers" depends on the ignored package "@nomicfoundation/eslint-plugin-hardhat-internal-rules", but "@nomicfoundation/hardhat-chai-matchers" is not being ignored. Please add "@nomicfoundation/hardhat-chai-matchers" to the `ignore` option.
The package "@nomicfoundation/hardhat-chai-matchers" depends on the ignored package "@nomicfoundation/eslint-plugin-slow-imports", but "@nomicfoundation/hardhat-chai-matchers" is not being ignored. Please add "@nomicfoundation/hardhat-chai-matchers" to the `ignore` option.

Copy link

vercel bot commented Feb 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hardhat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 14, 2025 5:03pm

@github-actions github-actions bot added the status:ready This issue is ready to be worked on label Feb 11, 2025
@kanej kanej linked an issue Feb 11, 2025 that may be closed by this pull request
Copy link
Contributor

github-actions bot commented Feb 11, 2025

hardhat

Total size of the bundle: 214M
Total number of dependencies (including transitive): 54

List of dependencies (sorted by size)
209M	total
29M	@ignored/edr-optimism-linux-x64-musl
29M	@ignored/edr-optimism-linux-x64-gnu
26M	@ignored/edr-optimism-linux-arm64-musl
26M	@ignored/edr-optimism-linux-arm64-gnu
22M	@ignored/edr-optimism-win32-x64-msvc
20M	esbuild
20M	@ignored/edr-optimism-darwin-x64
19M	@ignored/edr-optimism-darwin-arm64
2.8M	@sentry/tracing
2.5M	micro-eth-signer
1.9M	@noble/curves
1.7M	undici
1.2M	@sentry/types
1.2M	@noble/hashes
932K	@sentry/node
920K	@sentry/utils
856K	zod
844K	@ignored/hardhat-vnext-utils
624K	micro-packed
576K	tsx
548K	@sentry/core
544K	fast-equals
492K	@scure/bip39
368K	ethereum-cryptography
348K	@ignored/hardhat-vnext-errors
344K	@sentry/hub
336K	@ignored/edr
320K	enquirer
288K	semver
280K	@ignored/edr-optimism
192K	ws
168K	@scure/base
136K	get-tsconfig
136K	adm-zip
96K	@scure/bip32
92K	chalk
88K	tslib
88K	@sentry/minimal
76K	agent-base
72K	@nomicfoundation/solidity-analyzer
68K	debug
64K	lru_map
64K	https-proxy-agent
60K	@ignored/hardhat-vnext-zod-utils
56K	rfdc
48K	ansi-colors
44K	resolve.exports
40K	resolve-pkg-maps
36K	p-map
32K	cookie
24K	strip-ansi
24K	env-paths
24K	ansi-regex
20K	ms

@kanej kanej added the no changeset needed This PR doesn't require a changeset label Feb 11, 2025
@alcuadrado alcuadrado added the v-next A Hardhat v3 development task label Feb 11, 2025
@kanej kanej changed the title Feat/port ignition viem ignition: port hardhat-ignition-viem to Hardhat 3 Feb 12, 2025
@kanej kanej force-pushed the feat/port-ignition-viem branch from 82bb051 to c9a3934 Compare February 12, 2025 18:55
@kanej kanej force-pushed the feat/port-ignition-viem branch from c9a3934 to bddd229 Compare February 12, 2025 18:58
@kanej kanej force-pushed the feat/port-ignition-viem branch from bddd229 to c3ea8f9 Compare February 12, 2025 19:11
@kanej kanej force-pushed the feat/port-ignition-viem branch from c3ea8f9 to 8f8e9ba Compare February 12, 2025 20:40
@kanej kanej force-pushed the feat/port-ignition-viem branch from 0bb409c to 23ccc26 Compare February 12, 2025 21:27
@kanej kanej force-pushed the feat/port-ignition-plugin branch 4 times, most recently from f794457 to e5dd73f Compare February 13, 2025 22:36
@kanej kanej force-pushed the feat/port-ignition-viem branch from 23ccc26 to acafcce Compare February 13, 2025 23:13
kanej added 20 commits February 14, 2025 17:02
The v-next packages are built if a full Hardhat build is triggered.

`hardhat-ignition-viem` runs a prebuild step that compiles contracts in
fixture projects. This requires at least Node 20 as it involves Hardhat
3.

We are removing the old packages, so this change to the build should not
be an issue.
Before building `hardhat-ignition-viem` we need to build `hardhat-viem`
and through it `hardhat` itself. This is so we can leverage them in the
scripts that compile the contracts in the fixture projects. These
generate the types which are required to enforce type checks within the
tests that are part of the `hardhat-ignition-viem` build.
This package has now been released, hence the pre-release tag.
The issue is that the `useIgnitionProject` test helper for setting up
hre/connection was not reading the Hardhat config from file for the
project.

The pattern is being pulled from the `ignition-plugin` setup helpers.
Both companion plugins check to ensure there is only one companion
plugin installed.

If the other plugin has already been loaded, we throw a HardhatError.
For the general deployment failure exception, we now throw a specific
HardhatError that captures a deployment error.

As before the message is derived from the result object, then passed
into the exception.
Switch the Ignition object in the type extension of NetworkConnection to
the interface rather than the impl, so the impl can move to internal.
Add the plugin and a script to show deploying via
`connection.ignition.deploy(...)` and the type safety of the returned
contracts.
Somehow the Helper was in the middle of the complex type convertors.

It is now at the top, so the file can be read top to bottom.
`hardhat-ignition-viem` and now the `example-project` require prebuild
steps.

We should revisit this. The underlying issue is the type checks in the
`hardhat-ignition-viem` build which assumes a precompilation step on the
fixture projects contracts.
This is to meet the requirements of the script check in the CI.
Network config can be overriden at different points. We want to ensure
we are using the resolved config for that particular connection.
@kanej kanej added this pull request to the merge queue Feb 14, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 14, 2025
@kanej kanej added this pull request to the merge queue Feb 14, 2025
Merged via the queue into v-next with commit 8f1861b Feb 14, 2025
138 checks passed
@kanej kanej deleted the feat/port-ignition-viem branch February 14, 2025 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changeset needed This PR doesn't require a changeset status:ready This issue is ready to be worked on v-next A Hardhat v3 development task
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Migrate hardhat-ignition-viem to Hardhat 3
2 participants