You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
The text was updated successfully, but these errors were encountered:
@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.
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 ofdiamondCut
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 ofdiamondCut
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 functioninitialize(bytes memory _data)
that is called usingdelegatecall
. Obviously the parameter_data
is passed fromdiamondCut
toinitialize
.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 theinitialize(bytes memory _data)
usingdelegatecode
. 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/kQewPw2The text was updated successfully, but these errors were encountered: