diff --git a/contracts/RolesRegistry/SftRolesRegistrySingleRole.sol b/contracts/RolesRegistry/SftRolesRegistrySingleRole.sol index 280b16d..4a72024 100644 --- a/contracts/RolesRegistry/SftRolesRegistrySingleRole.sol +++ b/contracts/RolesRegistry/SftRolesRegistrySingleRole.sol @@ -2,7 +2,7 @@ pragma solidity 0.8.9; -import { IERCXXXX } from './interfaces/IERCXXXX.sol'; +import { ISftRolesRegistry } from './interfaces/ISftRolesRegistry.sol'; import { IERC165 } from '@openzeppelin/contracts/utils/introspection/IERC165.sol'; import { IERC1155 } from '@openzeppelin/contracts/token/ERC1155/IERC1155.sol'; import { IERC1155Receiver } from '@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol'; @@ -10,7 +10,7 @@ import { ERC1155Holder, ERC1155Receiver } from '@openzeppelin/contracts/token/ER import { ERC165Checker } from '@openzeppelin/contracts/utils/introspection/ERC165Checker.sol'; // Semi-fungible token (SFT) registry with only one role (UNIQUE_ROLE) -contract SftRolesRegistrySingleRole is IERCXXXX, ERC1155Holder { +contract SftRolesRegistrySingleRole is ISftRolesRegistry, ERC1155Holder { bytes32 public constant UNIQUE_ROLE = keccak256('UNIQUE_ROLE'); // grantor => tokenAddress => operator => isApproved @@ -216,7 +216,7 @@ contract SftRolesRegistrySingleRole is IERCXXXX, ERC1155Holder { function supportsInterface( bytes4 interfaceId ) public view virtual override(ERC1155Receiver, IERC165) returns (bool) { - return interfaceId == type(IERCXXXX).interfaceId || interfaceId == type(IERC1155Receiver).interfaceId; + return interfaceId == type(ISftRolesRegistry).interfaceId || interfaceId == type(IERC1155Receiver).interfaceId; } /** Helper Functions **/ diff --git a/contracts/RolesRegistry/interfaces/ISftRolesRegistry.sol b/contracts/RolesRegistry/interfaces/ISftRolesRegistry.sol new file mode 100644 index 0000000..4e8c84a --- /dev/null +++ b/contracts/RolesRegistry/interfaces/ISftRolesRegistry.sol @@ -0,0 +1,133 @@ +// SPDX-License-Identifier: CC0-1.0 + +pragma solidity 0.8.9; + +import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol"; + +/// @title ERC-XXXX Semi-Fungible Token Roles +/// @dev See https://eips.ethereum.org/EIPS/eip-XXXX +/// Note: the ERC-165 identifier for this interface is 0xTBD +interface ISftRolesRegistry is IERC165 { + struct RoleData { + address grantee; + uint64 expirationDate; + bool revocable; + bytes data; + } + + struct DepositInfo { + address grantor; + address tokenAddress; + uint256 tokenId; + uint256 tokenAmount; + } + + struct RoleAssignment { + uint256 nonce; + bytes32 role; + address tokenAddress; + uint256 tokenId; + uint256 tokenAmount; + address grantor; + address grantee; + uint64 expirationDate; + bool revocable; + bytes data; + } + + /** Events **/ + + /// @notice Emitted when a role is granted. + /// @param _nonce The identifier of the role assignment. + /// @param _role The role identifier. + /// @param _tokenAddress The token address. + /// @param _tokenId The token identifier. + /// @param _tokenAmount The token amount. + /// @param _grantor The user assigning the role. + /// @param _grantee The user receiving the role. + /// @param _expirationDate The expiration date of the role. + /// @param _revocable Whether the role is revocable or not. + /// @param _data Any additional data about the role. + event RoleGranted( + uint256 indexed _nonce, + bytes32 indexed _role, + address _tokenAddress, + uint256 _tokenId, + uint256 _tokenAmount, + address _grantor, + address _grantee, + uint64 _expirationDate, + bool _revocable, + bytes _data + ); + + /// @notice Emitted when a role is revoked. + /// @param _nonce The identifier of the role assignment. + /// @param _role The role identifier. + /// @param _tokenAddress The token address. + /// @param _tokenId The token identifier. + /// @param _tokenAmount The token amount. + /// @param _revoker The user revoking the role. + /// @param _grantee The user that receives the role revocation. + event RoleRevoked( + uint256 indexed _nonce, + bytes32 indexed _role, + address _tokenAddress, + uint256 _tokenId, + uint256 _tokenAmount, + address _revoker, + address _grantee + ); + + /// @notice Emitted when a user is approved to manage roles on behalf of another user. + /// @param _tokenAddress The token address. + /// @param _operator The user approved to grant and revoke roles. + /// @param _isApproved The approval status. + event RoleApprovalForAll(address indexed _tokenAddress, address indexed _operator, bool _isApproved); + + /// @notice Emitted when a user withdraws tokens from a role assignment. + /// @param _nonce The identifier of the role assignment. + /// @param _grantor The user withdrawing the tokens. + /// @param _tokenAddress The token address. + /// @param _tokenId The token identifier. + /// @param _tokenAmount The token amount withdrawn. + event Withdrew(uint256 indexed _nonce, address indexed _grantor, address _tokenAddress, uint256 _tokenId, uint256 _tokenAmount); + + /** External Functions **/ + + /// @notice Grants a role on behalf of a user. + /// @param _roleAssignment The role assignment data. + function grantRoleFrom(RoleAssignment calldata _roleAssignment) external; + + /// @notice Revokes a role on behalf of a user. + /// @param _nonce The identifier of the role assignment. + /// @param _role The role identifier. + /// @param _grantee The user that gets their role revoked. + function revokeRoleFrom(uint256 _nonce, bytes32 _role, address _grantee) external; + + /// @notice Approves operator to grant and revoke any roles on behalf of another user. + /// @param _tokenAddress The token address. + /// @param _operator The user approved to grant and revoke roles. + /// @param _approved The approval status. + function setRoleApprovalForAll(address _tokenAddress, address _operator, bool _approved) external; + + /** View Functions **/ + + /// @notice Returns the custom data of a role assignment. + /// @param _nonce The identifier of the role assignment. + /// @param _role The role identifier. + /// @param _grantee The user that gets their role revoked. + function roleData(uint256 _nonce, bytes32 _role, address _grantee) external view returns (RoleData memory data_); + + /// @notice Returns the expiration date of a role assignment. + /// @param _nonce The identifier of the role assignment. + /// @param _role The role identifier. + /// @param _grantee The user that gets their role revoked. + function roleExpirationDate(uint256 _nonce, bytes32 _role, address _grantee) external view returns (uint64 expirationDate_); + + /// @notice Checks if the grantor approved the operator for all NFTs. + /// @param _tokenAddress The token address. + /// @param _grantor The user that approved the operator. + /// @param _operator The user that can grant and revoke roles. + function isRoleApprovedForAll(address _tokenAddress, address _grantor, address _operator) external view returns (bool); +}