-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat: Allow renaming exported ABIs #25
Conversation
Specific use case for this? Would it be more useful to pass the entire |
Never mind the second question, I misread the code. |
Alone, this doesn't do much. But I plan to submit a couple more PRs:
|
I'm trying to replace a bunch of custom logic in Dark Forest with this plugin, as we migrate to the Diamond pattern: https://github.com/darkforest-eth/eth/blob/master/tasks/compile.ts#L14-L88 |
f61cc57
to
50d3d40
Compare
@ItsNickBarry what do you think of this new approach? I'm a fan! I've also marked this as breaking since the |
I still don't see much use for the I also think I might want to keep the So right now I'm thinking that As for the subgraph issue, it's very disappointing to see a multi-billion-dollar project leave something like that unaddressed for so long. No excuse, really. I am in favor of providing a workaround here, but it should be kept on the periphery and its implementation should not affect core functionality of the plugin. |
Hm, so you want me to back out these changes? As for overriding tasks, I'm trending towards being very much against them. What happens with task overrides is a cascading effect where multiple other projects do it and then you have to import them in a very specific order. This is a design flaw in hardhat and stops them from every supporting ESM without a rework. Ideally, the plugins will provide common functionality as configuration and then anything exceptionally specialized will use an override. I don't believe Dark Forest is doing anything too far out of the ordinary (I've seen other projects doing much the same things). |
As for your contract-sizer plugin, I don't think the |
How would you feel if I implement the rest of my changes on top of this PR so you can see my plans for this |
Not saying that these changes are not acceptable, just that I need more time and information to make an informed decision. Don't want to rush it, particularly with respect to breaking changes (also, it's been a long couple of weeks, so I'm not necessarily thinking as clearly as I would like). I do see your point about subtasks, and have encountered issues with import ordering in the past. However, I think that in 95% of cases, that only applies to built-in Hardhat subtasks. If
Yes, I'd like to see either an explanation or an implementation, whichever you feel is easier.
Both plugins should probably throw an error if the final output includes name conflicts (I'll look into it). Ultimately, confusion is in itself destructive. So if |
I can try to describe it! I'm in the process of migrating the Dark Forest contracts to the Diamond pattern, and in that process we combine all our Facet ABIs into a single ABI named This is simple enough, with both plugins, we can write a const config = {
solidity: '0.8.10',
diamondAbi: {
// This plugin will combine all ABIs from any Smart Contract with `Facet` in the name or path and output it as `DarkForest.json`
name: 'DarkForest',
include: ['Facet'],
},
abiExporter: {
// This plugin will copy the ABI from the DarkForest artifact into our `@darkforest_eth/contracts` package as `abis/DarkForest.json`
path: path.join(packageDirs['@darkforest_eth/contracts'], 'abis'),
runOnCompile: true,
// We don't want additional directories created, so we explicitly set the `flat` option to `true`
flat: true,
// We **only** want to copy the DarkForest ABI (which is the Diamond ABI we generate) to this folder, so we limit the matched files with the `only` option
only: [':DarkForest$'],
},
};
export default config; We want this entire ABI available for the game's dApp, but we also need to generate and export a version of that same ABI that is valid for the Dark Forest Subgraph (which is heavily used by the playerbase). So my goal is to allow separate "abi exporters", like such: const config = {
solidity: '0.8.10',
diamondAbi: {
// This plugin will combine all ABIs from any Smart Contract with `Facet` in the name or path and output it as `DarkForest.json`
name: 'DarkForest',
include: ['Facet'],
},
// This plugin config will copy the ABI from the DarkForest artifact into our `@darkforest_eth/contracts` package
abiExporter: [
// Generates the `abis/DarkForest.json` file for use in the game client
{
path: path.join(packageDirs['@darkforest_eth/contracts'], 'abis'),
runOnCompile: true,
// We are only generating one file so set the name to "DarkForest" explicitly
rename: () => 'DarkForest",
// We **only** want to copy the DarkForest ABI (which is the Diamond ABI we generate) to this folder, so we limit the matched files with the `only` option
only: [':DarkForest$'],
},
// Generates the `abis/DarkForest_stripped.json` file
{
path: path.join(packageDirs['@darkforest_eth/contracts'], 'abis'),
runOnCompile: true,
// We are only generating one file so set the name to "DarkForest_stripped" explicitly
rename: () => "DarkForest_stripped"
only: [':DarkForest$'],
filter: (abi) => subgraphAbiFilter(abi),
},
]
};
export default config; This will allow us to turn the same ABI into multiple exported ABIs and support both the game client and the subgraph. So far we've just been doing this sort of logic by hooking the compile and generating the artifacts ourselves; however, integrating the Diamond ABI with TypeChain has run into the task hook ordering problem we were discussing. While trying to solve those issues, I thought it'd be helpful to combine efforts with already-released community plugins (Dark Forest has waaaaaay too much bespoke code). Does this make sense? What do you think? |
This part is really interesting. As long as the I'm still not completely sure about this implementation of |
It seems like |
The |
I think that's fair. Putting things in different directories makes things a little weird for our published packages. I wonder if |
@ItsNickBarry I dug into the |
Let's keep both |
The rename configuration is mutually exclusive with `flat` so validations were added to verify.
@ItsNickBarry I finally had a chance to update this as we discussed. Can you take a look? I'd like to get this feature released so I can update the Dark Forest codebase. |
Will review as soon as possible. |
@phated Fixed the case where neither |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one question about the validation, but otherwise looks great
index.js
Outdated
@@ -36,12 +38,25 @@ extendConfig(function (config, userConfig) { | |||
validate(conf, 'path', 'string'); | |||
validate(conf, 'runOnCompile', 'boolean'); | |||
validate(conf, 'clear', 'boolean'); | |||
validate(conf, 'flat', 'boolean'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to re-add this boolean validation then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Released as |
This allows users to rename their exported ABIs without any additional task hooks or filesystem reads. They can specify a
rename
function that receives the fully qualified name and returns a new name.