Skip to content
This repository has been archived by the owner on Apr 22, 2022. It is now read-only.

Commit

Permalink
feat: set all permissions at once
Browse files Browse the repository at this point in the history
  • Loading branch information
kengoldfarb committed Jan 7, 2022
1 parent d0dbe9c commit e635190
Show file tree
Hide file tree
Showing 8 changed files with 463 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
"name": "InvalidTotalChildren",
"type": "error"
},
{
"inputs": [],
"name": "MissingRequiredPermissions",
"type": "error"
},
{
"inputs": [
{
Expand Down Expand Up @@ -320,6 +325,56 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
},
{
"internalType": "enum PropertyType",
"name": "propertyType",
"type": "uint8"
},
{
"internalType": "enum PermissionType",
"name": "permissionType",
"type": "uint8"
},
{
"components": [
{
"internalType": "enum Permission",
"name": "permission",
"type": "uint8"
},
{
"internalType": "address[]",
"name": "addresses",
"type": "address[]"
},
{
"internalType": "uint256",
"name": "numTokens",
"type": "uint256"
},
{
"internalType": "address",
"name": "lockedBy",
"type": "address"
}
],
"internalType": "struct MeemPermission[]",
"name": "permissions",
"type": "tuple[]"
}
],
"name": "setPermissions",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,56 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
},
{
"internalType": "enum PropertyType",
"name": "propertyType",
"type": "uint8"
},
{
"internalType": "enum PermissionType",
"name": "permissionType",
"type": "uint8"
},
{
"components": [
{
"internalType": "enum Permission",
"name": "permission",
"type": "uint8"
},
{
"internalType": "address[]",
"name": "addresses",
"type": "address[]"
},
{
"internalType": "uint256",
"name": "numTokens",
"type": "uint256"
},
{
"internalType": "address",
"name": "lockedBy",
"type": "address"
}
],
"internalType": "struct MeemPermission[]",
"name": "permissions",
"type": "tuple[]"
}
],
"name": "setPermissions",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down
14 changes: 14 additions & 0 deletions contracts/Meem/facets/MeemPermissionsFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ contract MeemPermissionsFacet is IMeemPermissionsStandard {
LibMeem.lockChildrenPerWallet(tokenId);
}

function setPermissions(
uint256 tokenId,
PropertyType propertyType,
PermissionType permissionType,
MeemPermission[] memory permissions
) external override {
LibMeem.setPermissions(
tokenId,
propertyType,
permissionType,
permissions
);
}

function addPermission(
uint256 tokenId,
PropertyType propertyType,
Expand Down
7 changes: 7 additions & 0 deletions contracts/Meem/interfaces/MeemStandard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ interface IMeemPermissionsStandard {
MeemPermission[] permission
);

function setPermissions(
uint256 tokenId,
PropertyType propertyType,
PermissionType permissionType,
MeemPermission[] memory permissions
) external;

function addPermission(
uint256 tokenId,
PropertyType propertyType,
Expand Down
30 changes: 30 additions & 0 deletions contracts/Meem/libraries/LibMeem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,36 @@ library LibMeem {
return tokenId;
}

function setPermissions(
uint256 tokenId,
PropertyType propertyType,
PermissionType permissionType,
MeemPermission[] memory permissions
) internal {
LibERC721.requireOwnsToken(tokenId);
MeemProperties storage props = getProperties(tokenId, propertyType);
permissionNotLocked(props, permissionType);

MeemPermission[] storage perms = getPermissions(props, permissionType);

// Check if there are any existing locked permissions and if so, verify they're the same as the new permissions
validatePermissions(permissions, perms);

if (permissionType == PermissionType.Copy) {
delete props.copyPermissions;
} else if (permissionType == PermissionType.Remix) {
delete props.remixPermissions;
} else if (permissionType == PermissionType.Read) {
delete props.readPermissions;
} else {
revert InvalidPermissionType();
}

for (uint256 i = 0; i < permissions.length; i++) {
perms.push(permissions[i]);
}
}

function addPermission(
uint256 tokenId,
PropertyType propertyType,
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/meemStandard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export enum Permission {
}

export enum PropertyType {
Meem = 1,
Child = 2
Meem = 0,
Child = 1
}
Loading

0 comments on commit e635190

Please sign in to comment.