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

issue: yarn deploy fails in case of multiple contracts in the same file in the Foundry version #947

Closed
1 task done
nzmpi opened this issue Sep 19, 2024 · 1 comment
Closed
1 task done

Comments

@nzmpi
Copy link

nzmpi commented Sep 19, 2024

Is there an existing issue for this?

Which method was used to setup Scaffold-ETH 2 ?

npx create-eth@latest

Current Behavior

In the Foundry version if you have a contract A in the same sol-file as the contract B that inherits it, running yarn deploy will throw Error: ENOENT: no such file or directory, open '/[path]/packages/foundry/out/A.sol/A.json'.
Even though json-file is generated, but it's in /[path]/packages/foundry/out/B.sol/A.json.

Expected Behavior

yarn deploy should look for contract's ABI file in every folder of /foundry/out and not only in folders with the same name

Steps To Reproduce

In foundry/contracts create B.sol file with this code:

//SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;

contract A {
  uint256 x;

  constructor() payable {
    x = 1;
  }

  function update(uint256 y) external virtual {
    x = y;
  }
}

contract B is A {
  function update(uint256 y) external override {
    x = y * 2;
  }
}

Then in foundry/script/Deploy.s.sol in the run function add

    B b = new B();
    console.logString(
      string.concat(
        "B deployed at: ", vm.toString(address(b))
      )
    );

Run yarn deploy

Anything else?

Some projects have multiple contracts (especially abstract contracts) in the same sol-file. They won't work with SE-2 (Foundry). Developers either will need to create every contract in their own sol-file or move json-files to their own folders in the foundry/out folder.

This problem only exists in the Foundry version. The Hardhat version works properly.

@technophile-04
Copy link
Collaborator

Thanks @nzmpi for raising, we have tweaked the deployment in #1011

And just tried reproducing and it seems to work now 🙌 To try :

In foundry/contracts create B.sol file with this code:

//SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;

contract A {
  uint256 x;

  constructor() payable {
    x = 1;
  }

  function update(uint256 y) external virtual {
    x = y;
  }
}

contract B is A {
  function update(uint256 y) external override {
    x = y * 2;
  }
}

And in DeployYourContract.s.sol and this deployment of B line:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "./DeployHelpers.s.sol";
import "../contracts/YourContract.sol";
import "../contracts/B.sol";

/**
 * @notice Deploy script for YourContract contract
 * @dev Inherits ScaffoldETHDeploy which:
 *      - Includes forge-std/Script.sol for deployment
 *      - Includes ScaffoldEthDeployerRunner modifier
 *      - Provides `deployer` variable
 * Example:
 * yarn deploy --file DeployYourContract.s.sol  # local anvil chain
 * yarn deploy --file DeployYourContract.s.sol --network optimism # live network (requires keystore)
 */
contract DeployYourContract is ScaffoldETHDeploy {
    /**
     * @dev Deployer setup based on `ETH_KEYSTORE_ACCOUNT` in `.env`:
     *      - "scaffold-eth-default": Uses Anvil's account #9 (0xa0Ee7A142d267C1f36714E4a8F75612F20a79720), no password prompt
     *      - "scaffold-eth-custom": requires password used while creating keystore
     *
     * Note: Must use ScaffoldEthDeployerRunner modifier to:
     *      - Setup correct `deployer` account and fund it
     *      - Export contract addresses & ABIs to `nextjs` packages
     */
    function run() external ScaffoldEthDeployerRunner {
      // Deploy B contract
        B b = new B();
        console.logString(
          string.concat(
            "B deployed at: ", vm.toString(address(b))
          )
        );
      // Deploy B contract
      new YourContract(deployer);
    }
}

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

No branches or pull requests

2 participants