Foundry-Hardhat plugins: Use Foundry for Hardhat projects

Overview

This repo contains hardhat plugins to use foundry tools in hardhat environments.

Installation

See in each plugin

Documentation

Releases

The develop branch

Adapted from Optimism's release process

Our primary development branch is develop.

Developers can release new versions of the software by adding changesets to their pull requests using yarn changeset. Changesets will persist over time on the develop branch without triggering new version bumps to be proposed by the Changesets bot. Once changesets are merged into master, the bot will create a new pull request called "Version Packages" which bumps the versions of packages. The correct flow for triggering releases is to update the base branch of these pull requests onto develop and merge them, and then create a new pull request to merge develop into master. Then, the release workflow will trigger the actual publishing to npm and Docker hub.

Be sure to not merge other pull requests into develop if partially through the release process. This can cause problems with Changesets doing releases and will require manual intervention to fix it.

Contributing

See contributing guidelines

Comments
  • hardhat-forge: multiple contracts same name

    hardhat-forge: multiple contracts same name

    Properly handle building artifacts when multiple contracts have the same name. Previously this would fail as fully qualified names were not being used and it would become ambiguous which contract was being referenced. Now paths are converted into fully qualified names such that it is no longer ambiguous what contract is being referenced.

    opened by tynes 2
  • hardhat-forge: parse string metadata

    hardhat-forge: parse string metadata

    The build info compiler output metadata is serialized as a string and hardhat tooling that reads these files expects the string to be an object. This PR looks to see if the metadata is a string and then parses the json string into an object.

    The first commit includes a failing test to show that this is a problem.

    Perhaps another way to fix this would be to serialize the metadata as a json object in ethers-solc.

    opened by tynes 2
  • feat: configurable runSuper (#73)

    feat: configurable runSuper (#73)

    Starts the release process by merging develop into master. After merge, we should base the changesets PR that gets opened automatically on develop then merge and merge develop into master again to finally trigger the release


    Allow the user to configure runSuper in the build task. Allowing the user to run this will allow for more composability with other hardhat based tooling but will slow down the build.

    It was previously defaulted to true, but I found in practice that its generally not necessary to be true for just compilation. Things like typechain will not automatically run afterwards, but typechain doesn't currently work exactly the same as the foundry Artifacts doesn't have the concept of validArtifacts populated after building. We run typechain on its own after compilation to get around this difference, so always calling runSuper just slows down the build.

    opened by tynes 2
  • fix: rebase develop on master

    fix: rebase develop on master

    This PR rebases develop on top of master. I'd like to fix the git history in this repo so that we can do a release soon, because until a release happens the plugin breaks if build_info = true in the foundry.toml. Unblocks https://github.com/foundry-rs/hardhat/pull/60

    opened by tynes 2
  • feat: better `BuildInfo` support

    feat: better `BuildInfo` support

    This PR is a companion to https://github.com/foundry-rs/foundry/pull/2012

    It adds better support for hre.artifacts.getBuildInfo. The hardhat plugin doesn't currently have access to the values that make up the hash for the filename, so it simply searches through each BuildInfo to find the correct one. Not super ideal, but works for now.

    It will generate the debug files in the same way that hardhat does, so hardhat plugins that rely on the debug files should just work.

    To be able to optimize this, the hardhat plugin needs to be able to compute md5(_format,solcVersion,solcLongVersion,input)

    opened by tynes 2
  • feat: allow other plugins to be composed with `build`

    feat: allow other plugins to be composed with `build`

    Call runSuper after compiling so that other plugins that hook into the compile task are still called. I discovered that hardhat/typechain was not being ran with this plugin and I believe that this is the solution. Need to test locally to be sure. Note that calling runSuper here does not invoke the hardhat compiler toolchain. Two additional functions are added that I believe should be part of the IArtifacts interface but are not. Both of them are noops here, attempting to implement them would require a much larger change. Without them, there is a function is not defined error.

    Also delete some dead code in the constructor of ForgeArtifacts

    opened by tynes 2
  • Tests Pass with Panic

    Tests Pass with Panic

    See https://github.com/foundry-rs/hardhat/runs/6646586678?check_suite_focus=true

    @foundry-rs/hardhat
     | thread 'main' panicked at 'error binding to 127.0.0.1:8545: error creating server listener: Address already in use (os error 98)', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.18/src/server/server.rs:87:17
     | note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    @foundry-rs/hardhat-anvil
     |     ✔ can send transaction (386ms)
     |     ✔ can send transaction with env provider
     | 
    

    It looks like anvil has already started and its trying to be started again?

    opened by tynes 2
  • feat: write hardhat style artifacts to disk

    feat: write hardhat style artifacts to disk

    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 https://github.com/gakonst/ethers-rs/commit/54f1b9dee8f2317f0805ea5021f3d38a6118a459 ?).

    This errors if 2 contracts have the same name, see: https://github.com/foundry-rs/hardhat/blob/736941e266c22e7db6c95a379d1ec2f8cb2e0347/packages/hardhat-forge/src/forge/artifacts.ts#L419

    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

    opened by tynes 2
  • Bug: installed from npm and have

    Bug: installed from npm and have "valid main entry" error

    summary

    • after installing the deps, cannot do npx hardhat actions because of valid main entry error
    • for hardhat-anvil can work around that error by changing node_modules/@foundry-rs/hardhat-anvil/package.json and change main from dist/index.js to dist/src/index.js

    Steps to reproduce

    install in sample hardhat project / existing project

    npm i --save-dev @foundry-rs/hardhat
    

    using @foundry-rs/hardhat

    hardhat.config.js

    require("@foundry-rs/hardhat");
    // require("@foundry-rs/hardhat-anvil");
    // require("@foundry-rs/hardhat-forge");
    // require("@foundry-rs/easy-foundryup");
    
    
    /**
     * @type import('hardhat/config').HardhatUserConfig
     */
    module.exports = {
      defaultNetwork: "anvil",
      anvil: {
        url: "http://127.0.0.1:8545/",
        launch: false,
      },
      solidity: "0.8.4",
    };
    

    try to run node with anvil

    ➜  integration git:(master) ✗ npx hardhat node
    An unexpected error occurred:
    
    Error: Cannot find module '/Users/m1/Desktop/integration/node_modules/@foundry-rs/hardhat/dist/index.js'. Please verify that the package.json has a valid "main" entry
    
    

    try just hardhat

    ➜  integration git:(master) ✗ npx hardhat
    An unexpected error occurred:
    
    Error: Cannot find module '/Users/m1/Desktop/integration/node_modules/@foundry-rs/hardhat/dist/index.js'. Please verify that the package.json has a valid "main" entry
    
    

    using @foundry-rs/hardhat-anvil

    try using anvil

    //hardhat.config.js
    // require("@foundry-rs/hardhat");
    require("@foundry-rs/hardhat-anvil");
    // require("@foundry-rs/hardhat-forge");
    // require("@foundry-rs/easy-foundryup");
    
    
    /**
     * @type import('hardhat/config').HardhatUserConfig
     */
    module.exports = {
      defaultNetwork: "anvil",
      anvil: {
        url: "http://127.0.0.1:8545/",
        launch: false,
      },
      solidity: "0.8.4",
    };
    
    
    npm i --save-dev @foundry-rs/hardhat-anvil
    ➜  integration git:(master) ✗ npx hardhat node                          
    An unexpected error occurred:
    
    Error: Cannot find module '/Users/m1/Desktop/integration/node_modules/@foundry-rs/hardhat-anvil/dist/index.js'. Please verify that the package.json has a valid "main" entry
    
    

    go to node_modules/@foundry-rs/hardhat-anvil/package.json and change main from dist/index.js to dist/src/index.js

    {
      "name": "@foundry-rs/hardhat-anvil",
      "version": "0.1.2",
      "description": "Hardhat plugin for managing Anvil",
      "homepage": "https://github.com/foundry-rs/hardhat",
      "repository": "github:foundry-rs/hardhat",
      "license": "MIT",
      "main": "dist/src/index.js",
    

    and get the value.url is missing error

    ➜  integration git:(master) ✗ npx hardhat node
    Error in plugin @nomiclabs/hardhat-anvil: Anvil network config is invalid: value.url is missing
    
    For more info run Hardhat with --show-stack-traces
    
    
    opened by shawnharmsen 2
  • hardhat-forge: ignore metadata files

    hardhat-forge: ignore metadata files

    When getting contract artifacts, json files are pulled out of the artifacts directory. Since metadata files are now emitted by default as of https://github.com/foundry-rs/foundry/commit/ad91a4a962ddf2f3c3e340c018482851a5080f01, extra files were being passed through the hh artifact generation pipeline which broke things because the hardhat artifacts need the fully qualified name which is currently pulled from the ast in the compiler out. It could be possible to brute force the fully qualified name but that would fail when 2 contracts have a matching name. This filters out the metadata files when getting the contract artifacts.

    This fixes our broken CI

    opened by tynes 1
  • hardhat-forge: handle case insensitive filesystem (#97)

    hardhat-forge: handle case insensitive filesystem (#97)

    The artifact paths and filenames are based on the names of the files containing the smart contracts and the names of the contracts inside of the files.

    The npm package true-case-path has a bug that causes it to ignore directories that are spelled the same but have alternate casing.

    You can see here that it eagerly returns if the case insensitive regex hits: https://github.com/Profiscience/true-case-path/blob/8a016e6a8be64c873aba414fbcdb4748e24dc796/index.js#L31

    The problem is that it could hit multiple files and we need to check each, not just the first one that it hits.

    The problem is with DSTest and forge-std, where DSTest has a test.sol and forge-std has a Test.sol. The regex hits incorrectly and downstream consumers get passed the wrong data.

    The fix simply looks to see if true-case-path has an error (returns null) and then uses fsExtra to look directly at the filesystem. If directly looking at the filesystem works, then we know that the file is there and don't need to error.

    opened by tynes 1
  • Access default hardhat `compile` and `test` while still using this plugin

    Access default hardhat `compile` and `test` while still using this plugin

    Is there some way to still access the native hardhat calls using this plugin?

    I really like how this cleanly integrates into hardhat and replaces the compilation pipeline with forge and hardhat node with anvil as it gives a huge performance boost. And because it generates hardhat artifacts, all the hardhat scripts work well with foundry under the hood.

    However, it would still be useful to do the default hardhat compile from time to time to be able to generate typechain artifacts that I can pass to the front-end. And similarly, I can't seem to figure out a way to run the native hardhat tests, as hardhat test only looks for forge tests.

    opened by dino-rodriguez 2
  • wip docs

    wip docs

    WIP docs that I will continue filling out once the companion to https://github.com/foundry-rs/foundry/pull/2223 is implemented and merged into this repo

    opened by tynes 1
  • Error HH108: Cannot connect to the network anvil

    Error HH108: Cannot connect to the network anvil

    I am importing hardhat-anvil, but the additional params (ex: launch) aren't recognized by typescript. It also is not using the accounts I specify (I've tried accounts: { mnemonic: ... } as well as the array of private keys).

    image image

    Stripped-down version of my config:

    import '@nomiclabs/hardhat-ethers';
    import '@nomiclabs/hardhat-etherscan';
    import '@nomiclabs/hardhat-solhint';
    import '@nomiclabs/hardhat-waffle';
    import '@openzeppelin/hardhat-upgrades';
    import '@typechain/hardhat';
    import '@foundry-rs/hardhat-anvil';
    import 'hardhat-deploy';
    
    import * as dotenv from 'dotenv';
    import { HardhatUserConfig } from 'hardhat/config';
    
    const config: HardhatUserConfig = {
      networks: {
        anvil: {
          url: 'http://localhost:8545',
          chainId: 1337,
          accounts: [process.env.ADMIN_PRIVATE_KEY!],
          launch: true,
        },
      },
    };
    
    export default config;
    

    I can get it to connect if I start anvil in a separate terminal, but I still need to be able to deploy from the ADMIN_PRIVATE_KEY account. Any ideas?

    bug 
    opened by gigamesh 0
  • Unable to resolve import:

    Unable to resolve import: "INSERT_CONTRACT" with remappings when using NPM workspaces

    The situation

    I have Turborepo + pnpm project setup; a workspaces monorepo with a symlink dependency graph.

    When running hardhat compile with the foundry-rs/hardhat-* plugins installed I get the following mapping errors.

    [⠊] Compiling...
    [⠒] Unable to resolve import: "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol" with remappings:
            contracts/=/Users/kames/workspace/kames/code/turbo-eth/contracts/
    [⠢] Unable to resolve import: "@openzeppelin/contracts/access/Ownable.sol" with remappings:
            contracts/=/Users/kames/workspace/kames/code/turbo-eth/contracts/
    [⠆] Unable to resolve import: "@openzeppelin/contracts/token/ERC20/IERC20.sol" with remappings:
            contracts/=/Users/kames/workspace/kames/code/turbo-eth/contracts/
    ...
    ...
    ...
    [⠊] Unable to resolve import: "../../node_modules/zeppelin-solidity/contracts//math/SafeMath.sol" with remappings:
            contracts/=/Users/kames/workspace/kames/code/turbo-eth/contracts/
    

    This is obviously a problem with my monorepo build system, but just wanted to flag this issue.

    Maybe someone has an idea for a good work-around to get foundry-rs to work nicely in an NPM workspaces build setup?

    opened by kamescg 2
  • Failed to install solc 0.8.15: Checksum mismatch for version 0.8.15

    Failed to install solc 0.8.15: Checksum mismatch for version 0.8.15

    The Situation

    Just finished installing foundryup and adding the hardhat plugins to an existing project.

    When running hadhat compile I have gotten 2 different CLI outputs; only run 3 times.

    However, the main issue I am reporting is the checksum mismatch for v0.8.15

    1st and 3rd time

    [⠘] installing solc version "0.5.8"
    [⠃] Successfully installed solc 0.5.8
    [⠊] installing solc version "0.8.15"
    [⠒] Failed to install solc 0.8.15: Checksum mismatch for version 0.8.15
    
    Error: 
       0: Checksum mismatch for version 0.8.15
    
    Location:
       cli/src/compile.rs:100
    

    2nd time

    [⠢] installing solc version "0.7.6"
    [⠔] Successfully installed solc 0.7.6
    [⠒] installing solc version "0.4.26"
    [⠆] Successfully installed solc 0.4.26
    [⠆] installing solc version "0.7.3"
    [⠰] Successfully installed solc 0.7.3
    [⠰] installing solc version "0.5.17"
    [⠆] Successfully installed solc 0.5.17
    [⠢] installing solc version "0.6.12"
    [⠢] Successfully installed solc 0.6.12
    [⠆] installing solc version "0.8.15"
    [⠔] Failed to install solc 0.8.15: Checksum mismatch for version 0.8.15
    
    opened by kamescg 4
  • Error Message when `forge` not installed

    Error Message when `forge` not installed

    The error message for hardhat compile when forge is not installed does not tell users this fact. This could help users debug the build process more easily. The following error is produced:

    An unexpected error occurred:
    
    TypeError: Cannot read properties of null (reading 'code')
        at analyzeModuleNotFoundError (/home/circleci/project/node_modules/hardhat/src/internal/core/config/config-loading.ts:161:13)
        at Environment.run (/home/circleci/project/node_modules/hardhat/src/internal/core/runtime-environment.ts:136:33)
        at async main (/home/circleci/project/node_modules/hardhat/src/internal/cli/cli.ts:218:5)
    error Command failed with exit code 1.
    
    opened by tynes 1
Releases(@foundry-rs/[email protected])
Owner
Foundry
Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
Foundry
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Solidity starter combining foundry and hardhat because both are great and I can't live without either...

Combination Pizza Hut & Taco Bell Foundry && HardHat starter template. Motivation I like them both. With this set-up we get: Unit tests written in sol

Cache Monet 32 Aug 23, 2022
Minimal template to get started with Foundry + Hardhat

Hardhat x Foundry Template Template repository for getting started quickly with Hardhat and Foundry in one project Getting Started Use Foundry: forge

Foundry 158 Jan 3, 2023
Manually curated collection of resources, plugins, utilities, and other assortments for the Sapphire Community projects.

Awesome Sapphire Manually curated collection of resources, plugins, utilities, and other assortments for the Sapphire Community projects. Has your pro

Sapphire 20 Dec 17, 2022
WIP: Hevm based debugger for hardhat-huff projects

Huff Debug An easy hevm debug integration for hardhat-huff projects What does it do: Speed up your development experience by gaining rich feedback in

Huff 6 Jul 15, 2022
GitHub action to install Foundry

foundry-toolchain Action This GitHub action installs Foundry. Example workflow on: [push] name: test jobs: check: name: Foundry project ru

Bjerg 128 Jan 5, 2023
Library for Foundry VTT which provides easy access to dark comedy fantasy setting created by Richard Zadmar Woolcock

Library for Foundry VTT which provides easy access to dark comedy fantasy setting created by Richard Zadmar Woolcock. Current inclusions are a bestiary, edges, hindrances, and a journal with setting information, character creation, and more. The Savage Worlds Adventurers Edition Game System is the system this setting is designed for.

KevDog 2 Mar 18, 2022
A module to integrate World Anvil with Foundry Virtual Tabletop.

Foundry Virtual Tabletop - World Anvil Integration This module provides an integration with World Anvil for Foundry Virtual Tabletop, allowing you to

Foundry Virtual Tabletop 5 Sep 7, 2022
An implementation of the Dungeons & Dragons 5th Edition game system for Foundry Virtual Tabletop

An implementation of the Dungeons & Dragons 5th Edition game system for Foundry Virtual Tabletop.

Foundry Virtual Tabletop 103 Jan 2, 2023
🛠️ Easily track & compare gas costs estimated by Foundry on each of your Pull Requests!

?? ??️ Foundry Gas Diff Reporter Easily compare gas reports generated by Foundry automatically on each of your Pull Requests! How it works Everytime s

Romain Milon 133 Dec 28, 2022
A module for modifying sheet rolling functions on Foundry VTT Character sheets for D&D 5th Edition.

Ready Set Roll for 5e - FoundryVTT Module Ready Set Roll is a Foundry VTT module that accelerates the built in rolling system of the Foundry DnD5e sys

Mangó 17 Dec 12, 2022
tools and plugins for logseq

logtools tools and plugins for logseq logtools-css-productivitypack my css mods for Kanban/columns view (#.v-kanban), Einsihower Matrix (#.v-einsenhow

null 126 Jan 2, 2023
Foxpage portal, server apis and plugins

Low-code, made simple and fast Try live demo Foxpage is a lightweight front-end low-code framework. Features ??️ Visualization. Provides visual page e

Foxpage 165 Dec 31, 2022
Shared eslint configuration for Strapi v4 plugins & applications.

This package is currently under development and should be consider ALPHA in terms of state. I/We are currently accepting contributions and/or dedicated contributors to help develop and maintain this package.

Strapi Community 6 Oct 28, 2022
Load LiteXLoader JS plugins in BDSX!

BDSX-LXL: Load LiteXLoader JS plugins in BDSX! Background Both LiteXLoader (LXL) and Bedrock Dedicated Server eXtended (BDSX) are popular options of l

PneuJai 8 Oct 30, 2022
It's a repository to studies. Its idea is to learn about Nx and its plugins.

StudyingNx This project was generated using Nx. ?? Smart, Fast and Extensible Build System Adding capabilities to your workspace Nx supports many plug

Open-ish 4 May 13, 2022
An interactive list of plugins for hex-rays' IDA Pro

Interactive IDA Plugin List This is a comprehensive list of plugins for IDA Pro that is more interactive, that is, it can be sorted and filtered to he

Vincent Mallet 106 Dec 26, 2022