-
Notifications
You must be signed in to change notification settings - Fork 45
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
Add support for hardhat
and hardhat-deploy
artifacts and deployments.
#512
Comments
I want to look into this during Ecosystem Fridays maybe? |
I'll start with adding this to |
So, hardhat artefacts are structured differently from truffle artefacts. In hardhat, you get a list of contracts for each network, while in truffle it's a list of networks for each contract. This difference has two major impacts. First, in hardhat it's possible that a contract will have different ABIs on different networks. Second, we have a single json file containing all info about all contracts. So, potentially, we can generate multiple contracts with a single macro invocation. As for generating multiple contracts from a single macro invocation, I think this could be useful; we won't have to load and parse the same file multiple times. However, that will require changing the interface of both builder and macro. I'm thinking about what a good interface will look like. |
I also agree. I think having multiple contracts with different ABIs is a huge can of worms that I don't want to open. Also, as long as we can have a way to specify a single deployment, we can techincally still support different ABIs on different networks by having multiple
Just to make sure I understood correctly, would the suggestion be that we can specify multiple paths to JSON artifacts and then the network information would just be merged (erroring if non-mergable differences - such as different ABIs are encountered)? |
My line of thought was the following. One artifact (that is, one JSON file) may now export multiple contracts. Thus, we should be able to generate all of them in one go. Merging data form different JSONs sounds interesting, I'll look into it. |
So, we have several formats for artifacts. Truffle and Waffle:
HardHat:
With these in mind, I propose the following API. In
In
Then let artifact = HardhatDeployments::new("deployments/")
.unwrap();
Builder::new(artifact.contract("ContractName"))
.generate()
.unwrap()
.write_to_file(Path::new(&dest).join("rust_coin.rs"))
.unwrap();
Builder::new(artifact.contract("AnotherContractName"))
.generate()
.unwrap()
.write_to_file(Path::new(&dest).join("rust_coin.rs"))
.unwrap(); As for macros, I have a few ideas, but none that I'm satisfied with. |
In preparation for #512, we're separating artifacts (that is, JSON files that contain contracts) from actual contracts data.
I like the proposed abstractions, as it will make it easier to extend it and add new formats in the future. |
In preparation for #512, we're separating artifacts (that is, JSON files that contain contracts) from actual contracts data.
I want to move code that loads contracts from etherscan and other places from |
The issue with that is that it means that we would need to pull in It also allows some of the JSON parsing code to move out of |
I was thinking that we may enable curl support conditionally, via a feature flag (i.e. I'm not sure about |
The idea would be that Then, hopefully, we could even make it so we can create a |
I see. Then I'll continue with the current structure for now, and we can implement this proposal later. |
Part of #512. We're adding the Artifact trait that will provide a uniform interface for working with different artifact sources.
Part of #512. Implements artifact loader for hardhat export (hardhat export command).
So I still don't have any nice API for a macro that could yield multiple contracts at once. So for now, I propose that we live the current macro API, just slightly modify it:
Example: contract!(
pub "build/export.json",
format = hardhat_multi,
contract = WETH9,
contract_rename = Weth,
); |
Would it be possible to try and autodetect this as well? Otherwise I like the format setting.
We can also use contract!(
pub "build/export.json",
format = hardhat_multi,
contract = WETH9 as Weth,
); |
It's possible, but there are corner cases, and it will require parsing JSON into a
Love it! |
For sure, just another improvement idea to make the macro as ergonomic as possible. |
Maybe |
Fix #196, part of #512, merge after #554. Refactor builder interface to separate code that loads artifacts, parses them and generates bindings into independent modules. Now code generation takes a reference to `Contract`, loading contracts from source is no longer builder's job. Additionally, `Builder` was renamed to `ContractBuilder` in anticipation that we will have `ArtifactBuilder` in the future. Also `ethcontract_generate::contract` was renamed to `ethcontract_generate::generate`. I can move these changes into separate pullrequests if anyone things it's necessary. Procedural macro will be updated later in #512.
Fix #196, part of #512, merge after #554. Refactor builder interface to separate code that loads artifacts, parses them and generates bindings into independent modules. Now code generation takes a reference to `Contract`, loading contracts from source is no longer builder's job. Additionally, `Builder` was renamed to `ContractBuilder` in anticipation that we will have `ArtifactBuilder` in the future. Also `ethcontract_generate::contract` was renamed to `ethcontract_generate::generate`. I can move these changes into separate pullrequests if anyone things it's necessary. Procedural macro will be updated later in #512.
Fix #196, part of #512, merge after #554. Refactor builder interface to separate code that loads artifacts, parses them and generates bindings into independent modules. Now code generation takes a reference to `Contract`, loading contracts from source is no longer builder's job. Additionally, `Builder` was renamed to `ContractBuilder` in anticipation that we will have `ArtifactBuilder` in the future. Also `ethcontract_generate::contract` was renamed to `ethcontract_generate::generate`. I can move these changes into separate pullrequests if anyone things it's necessary. Procedural macro will be updated later in #512.
Since we are migrating more and more of our repositories to
hardhat
andhardhat-deploy
, it would be nice to support this natively.Artifact
toContract
.struct Artifact
.Artifact
without needing the source json #170Builder
to work withContract
, implementContractBuilder
.ethabi
.main
.The text was updated successfully, but these errors were encountered: