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

FacetCut struct in IDiamondWriteableInternal doesn't follow the Spec naming conventions #193

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions abi/DiamondWritable.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"components": [
{
"internalType": "address",
"name": "target",
"name": "facetAddress",
"type": "address"
},
{
Expand All @@ -66,7 +66,7 @@
},
{
"internalType": "bytes4[]",
"name": "selectors",
"name": "functionSelectors",
"type": "bytes4[]"
}
],
Expand Down Expand Up @@ -116,7 +116,7 @@
"components": [
{
"internalType": "address",
"name": "target",
"name": "facetAddress",
"type": "address"
},
{
Expand All @@ -126,7 +126,7 @@
},
{
"internalType": "bytes4[]",
"name": "selectors",
"name": "functionSelectors",
"type": "bytes4[]"
}
],
Expand Down
4 changes: 2 additions & 2 deletions abi/DiamondWritableInternal.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"components": [
{
"internalType": "address",
"name": "target",
"name": "facetAddress",
"type": "address"
},
{
Expand All @@ -56,7 +56,7 @@
},
{
"internalType": "bytes4[]",
"name": "selectors",
"name": "functionSelectors",
"type": "bytes4[]"
}
],
Expand Down
8 changes: 4 additions & 4 deletions abi/IDiamondWritable.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"components": [
{
"internalType": "address",
"name": "target",
"name": "facetAddress",
"type": "address"
},
{
Expand All @@ -56,7 +56,7 @@
},
{
"internalType": "bytes4[]",
"name": "selectors",
"name": "functionSelectors",
"type": "bytes4[]"
}
],
Expand Down Expand Up @@ -87,7 +87,7 @@
"components": [
{
"internalType": "address",
"name": "target",
"name": "facetAddress",
"type": "address"
},
{
Expand All @@ -97,7 +97,7 @@
},
{
"internalType": "bytes4[]",
"name": "selectors",
"name": "functionSelectors",
"type": "bytes4[]"
}
],
Expand Down
4 changes: 2 additions & 2 deletions abi/IDiamondWritableInternal.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"components": [
{
"internalType": "address",
"name": "target",
"name": "facetAddress",
"type": "address"
},
{
Expand All @@ -56,7 +56,7 @@
},
{
"internalType": "bytes4[]",
"name": "selectors",
"name": "functionSelectors",
"type": "bytes4[]"
}
],
Expand Down
8 changes: 4 additions & 4 deletions abi/ISolidStateDiamond.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"components": [
{
"internalType": "address",
"name": "target",
"name": "facetAddress",
"type": "address"
},
{
Expand All @@ -61,7 +61,7 @@
},
{
"internalType": "bytes4[]",
"name": "selectors",
"name": "functionSelectors",
"type": "bytes4[]"
}
],
Expand Down Expand Up @@ -122,7 +122,7 @@
"components": [
{
"internalType": "address",
"name": "target",
"name": "facetAddress",
"type": "address"
},
{
Expand All @@ -132,7 +132,7 @@
},
{
"internalType": "bytes4[]",
"name": "selectors",
"name": "functionSelectors",
"type": "bytes4[]"
}
],
Expand Down
8 changes: 4 additions & 4 deletions abi/SolidStateDiamond.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"components": [
{
"internalType": "address",
"name": "target",
"name": "facetAddress",
"type": "address"
},
{
Expand All @@ -81,7 +81,7 @@
},
{
"internalType": "bytes4[]",
"name": "selectors",
"name": "functionSelectors",
"type": "bytes4[]"
}
],
Expand Down Expand Up @@ -142,7 +142,7 @@
"components": [
{
"internalType": "address",
"name": "target",
"name": "facetAddress",
"type": "address"
},
{
Expand All @@ -152,7 +152,7 @@
},
{
"internalType": "bytes4[]",
"name": "selectors",
"name": "functionSelectors",
"type": "bytes4[]"
}
],
Expand Down
4 changes: 2 additions & 2 deletions contracts/proxy/diamond/SolidStateDiamond.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ abstract contract SolidStateDiamond is
FacetCut[] memory facetCuts = new FacetCut[](1);

facetCuts[0] = FacetCut({
target: address(this),
facetAddress: address(this),
action: FacetCutAction.ADD,
selectors: selectors
functionSelectors: selectors
});

_diamondCut(facetCuts, address(0), '');
Expand Down
28 changes: 14 additions & 14 deletions contracts/proxy/diamond/writable/DiamondWritableInternal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ abstract contract DiamondWritableInternal is IDiamondWritableInternal {
FacetCut memory facetCut = facetCuts[i];
FacetCutAction action = facetCut.action;

if (facetCut.selectors.length == 0)
if (facetCut.functionSelectors.length == 0)
revert DiamondWritable__SelectorNotSpecified();

if (action == FacetCutAction.ADD) {
Expand Down Expand Up @@ -86,20 +86,20 @@ abstract contract DiamondWritableInternal is IDiamondWritableInternal {
) internal returns (uint256, bytes32) {
unchecked {
if (
facetCut.target != address(this) &&
!facetCut.target.isContract()
facetCut.facetAddress != address(this) &&
!facetCut.facetAddress.isContract()
) revert DiamondWritable__TargetHasNoCode();

for (uint256 i; i < facetCut.selectors.length; i++) {
bytes4 selector = facetCut.selectors[i];
for (uint256 i; i < facetCut.functionSelectors.length; i++) {
bytes4 selector = facetCut.functionSelectors[i];
bytes32 oldFacet = l.facets[selector];

if (address(bytes20(oldFacet)) != address(0))
revert DiamondWritable__SelectorAlreadyAdded();

// add facet for selector
l.facets[selector] =
bytes20(facetCut.target) |
bytes20(facetCut.facetAddress) |
bytes32(selectorCount);
uint256 selectorInSlotPosition = (selectorCount & 7) << 5;

Expand Down Expand Up @@ -129,14 +129,14 @@ abstract contract DiamondWritableInternal is IDiamondWritableInternal {
FacetCut memory facetCut
) internal returns (uint256, bytes32) {
unchecked {
if (facetCut.target != address(0))
if (facetCut.facetAddress != address(0))
revert DiamondWritable__RemoveTargetNotZeroAddress();

uint256 selectorSlotCount = selectorCount >> 3;
uint256 selectorInSlotIndex = selectorCount & 7;

for (uint256 i; i < facetCut.selectors.length; i++) {
bytes4 selector = facetCut.selectors[i];
for (uint256 i; i < facetCut.functionSelectors.length; i++) {
bytes4 selector = facetCut.functionSelectors[i];
bytes32 oldFacet = l.facets[selector];

if (address(bytes20(oldFacet)) == address(0))
Expand Down Expand Up @@ -217,25 +217,25 @@ abstract contract DiamondWritableInternal is IDiamondWritableInternal {
FacetCut memory facetCut
) internal {
unchecked {
if (!facetCut.target.isContract())
if (!facetCut.facetAddress.isContract())
revert DiamondWritable__TargetHasNoCode();

for (uint256 i; i < facetCut.selectors.length; i++) {
bytes4 selector = facetCut.selectors[i];
for (uint256 i; i < facetCut.functionSelectors.length; i++) {
bytes4 selector = facetCut.functionSelectors[i];
bytes32 oldFacet = l.facets[selector];
address oldFacetAddress = address(bytes20(oldFacet));

if (oldFacetAddress == address(0))
revert DiamondWritable__SelectorNotFound();
if (oldFacetAddress == address(this))
revert DiamondWritable__SelectorIsImmutable();
if (oldFacetAddress == facetCut.target)
if (oldFacetAddress == facetCut.facetAddress)
revert DiamondWritable__ReplaceTargetIsIdentical();

// replace old facet address
l.facets[selector] =
(oldFacet & CLEAR_ADDRESS_MASK) |
bytes20(facetCut.target);
bytes20(facetCut.facetAddress);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/proxy/diamond/writable/IDiamondWritableInternal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ interface IDiamondWritableInternal {
error DiamondWritable__TargetHasNoCode();

struct FacetCut {
address target;
address facetAddress;
FacetCutAction action;
bytes4[] selectors;
bytes4[] functionSelectors;
}
}
Loading