hardhat icon indicating copy to clipboard operation
hardhat copied to clipboard

Allow plugins to provide more artifacts

Open wighawag opened this issue 5 years ago • 22 comments

Currently hardhat offer a function hre.artifacts.readArtifact (as well as other method in hre.artifacts) Unfortunately such artifacts field is hardwired at runtime creation with a specific folder and as a read-only field it is not supposed to be modified.

hardhat-deploy (and even builder-deploy before) offer a mechanism for external import of artifacts, it support different format like truffle too. It does so with its own custom function so user can deploy these artifacts.

But since hardhat, as mentioned do not allow plugin to override the canonical way to get artifacts, other plugin that offer new features to artifacts are not aware of hardhat-deploy artifacts, even if they are compatible.

There are different approches to solve this. One approach is to allow plugin to hook into the getArtifact process so plugins can import artifact from other sources, even transforming it to fit hardhat expected format.

This way any plugin that add features to artifacts can access them via a standard mechanism

wighawag avatar Nov 19 '20 19:11 wighawag

If I'm understanding correctly, you would like to add extra fields to the JSON artifacts, and then be able to consume them, is that correct?

One thing to keep in mind is that if you add fields, the current type of Artifact won't have those extra fields, but that's an easy problem to circumvent.

fvictorio avatar Nov 20 '20 13:11 fvictorio

It is not about adding extra field to artifacts, but being able for a plugin to add more artifacts, from different sources. And having that reachable to other plugin

hardhat-deploy already offer that feature but these artifacts are not seen by other plugins

wighawag avatar Nov 20 '20 14:11 wighawag

Any plan to support that somehow?

It has resurfaced with my update of hardhat-deploy-ethers (wip) that is now an extension of hardhat-ethers

hardhat-deploy-ethers used to re-write the function of hardhat-ethers but now this is not easily possible, nor recommended (would need to guess any future addition of function)

One of the reason for the re-write was to ensure ethers.getContractFactoryByName would still consider the extra artifacts that hardhat-deploy allow user to provide.

It would be a lot better if somehow plugin could override hre.artifacts directly, this wwould make any plugin using artifacts.readArtifact support the extra artifacts provided.

wighawag avatar Feb 12 '21 08:02 wighawag

I would very much like this feature to be able to use external libraries in my Hardhat project!

rhlsthrm avatar Feb 17 '21 15:02 rhlsthrm

I started to look at implementating it but I am not sure what is the best way forward

Currently the Artifacts object is instantiated synchrnously at the time the HRE is constructed (https://github.com/nomiclabs/hardhat/blob/e5b5041e15908fe81ee7ad5ec984f74f3fde253d/packages/hardhat-core/src/internal/core/runtime-environment.ts#L76). I think the change would probably be a breaking change as the way it is done now, do not allow for async hooks.

Did you start thinking how we could use the task api for that ?

This is to me the last piece needed to make my hardhat-deploy-ethers plugin an extension to hardhat-ethers. It would also open the api to new kind of plugins that can transform or add new artifacts.

On that note, it might be interesting to allow artifacts to belong to a specific network (Without overwriting other). THis would be useful for network like optimism which require a different compiler on their network

wighawag avatar Jun 13 '21 12:06 wighawag

Running into this again. Any progress?

Jack-ZooFiLabs avatar Oct 02 '21 23:10 Jack-ZooFiLabs

@fvictorio / @wighawag

Jack-ZooFiLabs avatar Oct 15 '21 06:10 Jack-ZooFiLabs

We've discussed this in private and decided that we are ok with adding an api like this one:


// This callback is only called if the built-in artifacts resolution fails, and no other extension was declared before and succeded
extendArtifactsResolution((name: string) => {
   return somehowGetTheArtifactAndAdaptItsFormatIfNecessaryOrUndefinedIfNotFound(name);
})

We'll probably add other ways of loading dependencies artifacts, but this is a good quick way to allow plugins to do it.

Unfortunately we can't prioritize this yet, but are willing to accept a PR implementing it.

alcuadrado avatar Oct 15 '21 14:10 alcuadrado

Hi, I think this should be higher priority. The hardhat ecosystem is missing something to manage deployments, and something like hardhat-deploy is desperately needed. However it's currently a non-starter because without this issue fixed hardhat-deploy is not compatible with other hardhat plugins like hardhat-ether and hardhat-waffle. Users and the hardhat-deploy maintainer @wighawag have to resort to dirty hacks to try and get it working, and it randomly breaks depending on different package managers, package versions and the phase of the moon.

Please consider prioritizing this higher, or at least taking an hour or two to sketch out "the right way" to do it in order for someone else to come in and help out.

KholdStare avatar Apr 01 '22 04:04 KholdStare

Somehow I only just discovered Hardhat Ignition yesterday, via https://github.com/NomicFoundation/hardhat/issues/381#issuecomment-1083303156. I'm not sure if I'm understanding correctly, but I get the impression that Nomic Foundation maybe don't want to spend extra effort supporting hardhat-deploy, since Ignition is the favoured strategic direction.

aspiers avatar Apr 01 '22 11:04 aspiers

@aspiers I took a look at https://github.com/NomicFoundation/hardhat-ignition , and there haven't been any commits since July 2021. There is only a single release on npm https://www.npmjs.com/package/hardhat-ignition from a year ago.

It seems to me that project is not maintained 🤔 Even if hardhat-ignition is the longterm solution, hardhat-deploy is available now and it would be nice to support the community/ecosystem.

Will comment in the other issue you linked to. Thanks.

KholdStare avatar Apr 01 '22 13:04 KholdStare

@KholdStare commented on April 1, 2022 2:57 PM:

It seems to me that project is not maintained :thinking:

Thanks, hadn't spotted that.

Even if hardhat-ignition is the longterm solution, hardhat-deploy is available now and it would be nice to support the community/ecosystem.

I totally agree. hardhat-deploy is incredibly useful.

aspiers avatar Apr 01 '22 14:04 aspiers

I agree this issue should have a higher priority. It will also enable a better integration between hardhat-deploy and hardhat-etherscan.

tuler avatar Apr 01 '22 14:04 tuler

Thanks for the comments folks. We'll discuss this internally and see if we can move this forward on our roadmap.

fvictorio avatar Apr 12 '22 17:04 fvictorio

Any update on that ?

There is more and more plugin that hardcode dependency on hardhat-ethers and until this issue is resolved this put hardhat-deploy-ethers in a difficult situation

While I do not think these library should hard code libraries like that (As this prevent user to provide their own implementation), it seems to be a trend and this cause typing issue on hardhat-deploy-ethers

see : https://github.com/wighawag/hardhat-deploy-ethers/issues/12 and https://github.com/wighawag/hardhat-deploy-ethers/issues/26

wighawag avatar Jul 04 '22 11:07 wighawag

Sorry @wighawag, we'll try to prioritize this.

fvictorio avatar Jul 11 '22 09:07 fvictorio

+1 running into this as well

douglasqian avatar Aug 08 '22 19:08 douglasqian

+1 me too. It's a pity, can't use hardhat toolbox like that... Hardhat-deploy is more important for me rn...

sharp2448 avatar Aug 24 '22 11:08 sharp2448

@sharp2448 you can use hardhat toolbox and hardhat-deploy (or any plugin not included in the toolbox) together

fvictorio avatar Aug 24 '22 14:08 fvictorio

@fvictorio the issue is that hardhat toolbox hardcode dependencies to hardhat-ethers and this prevent hardhat-deploy-ethers to be used.

hardhat-deploy-ethers could be used if that issue (1040) was solved though

wighawag avatar Aug 24 '22 15:08 wighawag

Would be really great to have documented support and compatibility between hardhat-toolbox and hardhat-deploy-ethers

I really wanna switch to using hardhat-toolbox by default but I dont wanna say good bye to hardhat-deploy-ethers `ethers.getContract("ContractName")" method, it's way too handy!

gitpusha avatar Sep 09 '22 15:09 gitpusha

First of all thanks for your hard work and commitment.

Any progress on this topic? Its pretty annoying not being able to use hardhat-deploy without hardhat-deploy-ethers due to that functionality.

KirchZ avatar Sep 12 '22 16:09 KirchZ

+1 on this

layinka avatar Sep 23 '22 09:09 layinka

Hope that all things go well. For anything stuck, we can discuss it publicly and work together.

noyyyy avatar Sep 26 '22 07:09 noyyyy

+1

akuter-bc avatar Sep 29 '22 11:09 akuter-bc