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

diamondCut utilities #65

Open
ItsNickBarry opened this issue Dec 31, 2021 · 4 comments · May be fixed by #158
Open

diamondCut utilities #65

ItsNickBarry opened this issue Dec 31, 2021 · 4 comments · May be fixed by #158

Comments

@ItsNickBarry
Copy link
Member

The diamondCut function is complex, and many users would benefit from a package to assist with adding/replacing/removing function selectors from diamond proxies.

@ItsNickBarry
Copy link
Member Author

Include a FacetCut TS interface.

@0xCourtney
Copy link
Contributor

0xCourtney commented Oct 14, 2022

Just to summarize the problem statement here. The Diamond proxy is becoming an increasingly popular standard but managing deployments and upgrades is a challenging task with limited developer tooling available. Some of the key issues underlying are as follows:

  1. The diamondCut is a complex function with many failure modes, this requires a user to have a deep understanding of the function logic.
  2. There is no standard practice for generating a FacetCut. Some users may choose to REPLACE all existing selectors when upgrading a Facet others may simply REPLACE only the selectors needed. A tool should not make this decision for the developer, but rather empower them to make the decision they choose.
  3. There are no tools available that provide the selectors needed or verify the FacetCut once it has been structured.

Some goals I believe are worthwhile pursuing here is to provide a package or plugin for developers to create a valid FacetCut. I have some ideas for implementation, however, I want to align on the problem statement and goals before proposing solutions.

@0xCourtney 0xCourtney linked a pull request Oct 30, 2022 that will close this issue
1 task
@jhubbardsf
Copy link
Contributor

jhubbardsf commented Nov 16, 2022

Awesome PR and definitely a useful thing to add. Just wanted to link to Nick Mudge's diamond util's that he puts in his hardhat template repos. They've been useful when writing update/deploy scripts. The sample deploy script uses the Util Functions. Although I think @0xCourtney's work is great.

Util Functions
Deploy Script

There are some cool features in the official sample utils, though. An example would be when I'm trying to implement solidstate libraries into my code. I'll often create a facet for a specific area, like an ERC1155Facet which isn't that different than the SolidStateERC1155Mock (but with no constructor). If I tried to add all selectors from that Facet it would error because DiamondLoupe's have to implement 165. So with the official sample tool you could do something like this in your deploy, using Nick's getSelectors method.

 cut.push({
      facetAddress: facet.address,
      action: FacetCutAction.Add,
      functionSelectors: getSelectors(facet).remove("supportsInterface(bytes4)"),
    })

@0xCourtney
Copy link
Contributor

0xCourtney commented Nov 16, 2022

Thanks for the feedback, I would agree that having the getSelector, get and remove functions are potential enhancements here. The getSelectors and getSignatures functions were actually copied from Nicks Diamond Util script which is similar to the ones you referenced.

Alternatively, you could also add the selector which you don't want into the exclude list when adding a facet.

// async function addUnregisteredSelectors(diamond: Diamond, contracts: Contract[], exclude: string[] = []): Promise<FacetCut[]>
let facetCut = await addUnregisteredSelectors(Diamond, [Test1Facet, Test2Facet], ["0x01234567"]);

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

Successfully merging a pull request may close this issue.

3 participants