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

Help With New diamondCut Functions #7

Open
mudgen opened this issue Aug 13, 2020 · 2 comments
Open

Help With New diamondCut Functions #7

mudgen opened this issue Aug 13, 2020 · 2 comments

Comments

@mudgen
Copy link
Owner

mudgen commented Aug 13, 2020

If you want to contribute to this project, here's an opportunity to do so.

Make pull requests to implement the versions of diamondCut listed below or discuss new possible versions in the comments.

The implementations must be gas efficient.

Rational

Something that is currently missing from the Diamond Standard is a way to add/replace/remove functions and execute arbitrary code in the same transaction. This is needed for example to initialize/setup storage data after adding functions to a diamond.

It is possible to have different versions of the diamondCut function that take different arguments and work in different ways. However all versions are used to add/replace/remove functions from diamonds.

But before adding more versions of diamondCut to the Diamond Standard I want them implemented in this project. In addition, versions of diamondCut can exist and be used that are not defined in the Diamond Standard. The ones defined in the Diamond Standard are for compatibility between tools.

Just because a version of diamondCut doesn't exist in the Diamond Standard doesn't mean it can't exist and be used. I'd like this project to include a library of different versions of diamondCut that are useful in different circumstances.

What to Implement

Implement the following functions in DiamondFacet.sol or other file. All these functions can be private/internal/public/external.

  • diamondCut(bytes[] memory _diamondCut, address _initializer, bytes memory _data)

This version of diamondCut is used to execute arbitrary code after adding/replacing/removing functions and passing in _data as an argument to the arbitrary code.

_initializer is a contract with a function initialize(bytes memory _data) that is called using delegatecall. Obviously the parameter _data is passed from diamondCut to initialize.

  • diamondCut(bytes memory _diamondCut)

First 20 bytes is the facet address and the rest of the bytes are 4-byte function selectors.

  • diamondCut(address _facet, bytes memory _data)

This function is used to allow a new facet to add its functions to a diamond and execute arbitrary code, passing _data as an argument.

_facet should execute the initialize(bytes memory _data) using delegatecode. For example: _facet.delegatecall(abi.encodeWithSignature("initialize(bytes)", _data).

From within initialize(bytes memory _data) a facet should add its function selectors.

Other Versions

I am interested in suggestions and adding other versions of diamondCut to the project. Feel free to discuss ideas in the comments or in the Diamond Standard Discord: https://discord.gg/kQewPw2

@jerryji
Copy link

jerryji commented Aug 14, 2020

"From within initialize(bytes memory _data) a facet should add its function selectors." -- what does this mean?

@mudgen
Copy link
Owner Author

mudgen commented Aug 16, 2020

@jerryji It means that a facet can add its own functions to a diamond.

A facet can implement the initialize(bytes memory _data) function. And that function can call a version of diamondCut to add its functions to the diamond.

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

No branches or pull requests

2 participants