Hardhat-deploy: feature request: allow deployments from mainnet on hardhat in forking mode

Created on 19 Nov 2020  ·  10Comments  ·  Source: wighawag/hardhat-deploy

It would be cool if await ethers.getContract("Bar") when run in hardhat forking mode would let hardhat-deploy know that --network hardhat can actually also take into consideration the deployments/ from whatever network is configured in forking

Referencing this issue https://github.com/wighawag/hardhat-deploy-ethers/issues/6

enhancement

All 10 comments

implemented in 0.7.0-beta.29
via hardhat node --fork ... --fork-deployments <networkName>

Copying from our chat for reference:

Is it exclusive to the network you pass with --fork-deployments ? Ideally for me it would do this:

  1. Look into —fork-deployments deployments folder first - if contract not in there
  2. Look into —network deployments folder second

This way tests can mix forked contract instances from mainnet + mocked ones that you might only wanna deploy to hardhat network

it works by copying the deployments from the chain into localhost
so then your deploy script can decide to override the deployment if they wish

  1. ah ok cool. how does it know which network to copy the deployments over from? Does it parse the forking.url ?

  2. I am using hardhat network in-memory forking and I don't have an instance of hardhat node running during my tests. Does this also work for tests using forking on in-memory hardhat network?

ha no, good point, this is only a param for the node task.
I should be able to add it to the test task. reopenning

re 1. : the argument to the param is the name of the network to copy from

Actually @gitpusha do you have a repo example on how this is setup because thinking of it might need some changes on how things are handled.
currently with in memory network, there is no facility to have pre-deployed contract info
I might be able to add a similar param but need to think more

actually you should be able to use the external deployments config :

something like :

hardhat.config.js

module.exports = {
 ...
  external: {
    deployments: {
      hardhat: ['deployments/mainnet'],
    },
  },
}

actually you should be able to use the external deployments config

That would be sweet.

hardhat: ['deployments/mainnet']

Does the tool understand that on hardhat in should then look both into deployments/mainnet as well as deployments/hardhat ? If so, which deployments take precedence? I would want the deployments/mainnet take precedence if there are overlaps between contracts, since I configured it explicitly.

Also, will the deployments/hardhat directory be taken into account by default ?

Here is an example repo.

I am not sure how useful this feature is though, since you can always just use

await hre.ethers.getContractAt(abi, address)

in forkmode instead to access deployed instances from a specific network.

So it's really just a nice-to-have.

I tried the suggestion I posted above and it seems to work fine.
The deployments specified in external will not take precedence but that should not be an issue as node by default reset contract in deployments/hardhat and so unless you force redeployment of already deployed contract, you ll get the one from deployments/mainnet

I ll close the issue but if you have issue feel free to reopen

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jsidorenko picture jsidorenko  ·  3Comments

tennox picture tennox  ·  4Comments

lepidotteri picture lepidotteri  ·  5Comments

jaypaik picture jaypaik  ·  13Comments

freebyte picture freebyte  ·  9Comments