From efb13f5f51dd26d3596ac5a066ea1fe594748887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernani=20S=C3=A3o=20Thiago?= Date: Wed, 20 Dec 2023 11:22:11 -0500 Subject: [PATCH] refactor SftRolesRegistrySingleRole.sol --- .../interfaces/ISftRolesRegistry.sol | 132 +++++++++--------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/contracts/RolesRegistry/interfaces/ISftRolesRegistry.sol b/contracts/RolesRegistry/interfaces/ISftRolesRegistry.sol index d0ca0eb..7c579b8 100644 --- a/contracts/RolesRegistry/interfaces/ISftRolesRegistry.sol +++ b/contracts/RolesRegistry/interfaces/ISftRolesRegistry.sol @@ -6,77 +6,63 @@ 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 0xd38a803e +/// Note: the ERC-165 identifier for this interface is 0xa4629326 interface ISftRolesRegistry is IERC165 { - struct RoleData { + struct RoleAssignment { address grantee; uint64 expirationDate; bool revocable; bytes data; } - struct DepositInfo { - address tokenAddress; - uint256 tokenId; - uint256 tokenAmount; - } - - struct RoleAssignment { + struct Record { address grantor; - uint256 nonce; - bytes32 role; address tokenAddress; uint256 tokenId; uint256 tokenAmount; - address grantee; - uint64 expirationDate; - bool revocable; - bytes data; } /** Events **/ - /// @notice Emitted when a role is granted. - /// @param _grantor The user assigning the role. - /// @param _nonce The identifier of the role assignment. - /// @param _role The role identifier. + /// @notice Emitted when a record is created. + /// @param _grantor The owner of the NFTs. + /// @param _recordId The identifier of the record created. /// @param _tokenAddress The token address. /// @param _tokenId The token identifier. /// @param _tokenAmount The token amount. + event RecordCreated( + address indexed _grantor, + uint256 indexed _recordId, + address indexed _tokenAddress, + uint256 _tokenId, + uint256 _tokenAmount + ); + + /// @notice Emitted when a role is granted. + /// @param _recordId The record identifier. + /// @param _role The role identifier. /// @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( - address indexed _grantor, - uint256 indexed _nonce, + uint256 indexed _recordId, bytes32 indexed _role, - address _tokenAddress, - uint256 _tokenId, - uint256 _tokenAmount, - address _grantee, + address indexed _grantee, uint64 _expirationDate, bool _revocable, bytes _data ); /// @notice Emitted when a role is revoked. - /// @param _grantor The user revoking the role. - /// @param _nonce The identifier of the role assignment. + /// @param _recordId The record identifier. /// @param _role The role identifier. - /// @param _tokenAddress The token address. - /// @param _tokenId The token identifier. - /// @param _tokenAmount The token amount. /// @param _grantee The user that receives the role revocation. - event RoleRevoked( - address indexed _grantor, - uint256 indexed _nonce, - bytes32 indexed _role, - address _tokenAddress, - uint256 _tokenId, - uint256 _tokenAmount, - address _grantee - ); + event RoleRevoked(uint256 indexed _recordId, bytes32 indexed _role, address indexed _grantee); + + /// @notice Emitted when a user withdraws tokens from a record. + /// @param _recordId The record identifier. + event Withdrew(uint256 indexed _recordId); /// @notice Emitted when a user is approved to manage roles on behalf of another user. /// @param _tokenAddress The token address. @@ -84,23 +70,46 @@ interface ISftRolesRegistry is IERC165 { /// @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 _grantor The user withdrawing the tokens. - /// @param _nonce The identifier of the role assignment. - event Withdrew(address indexed _grantor, uint256 indexed _nonce); - /** External Functions **/ - /// @notice Grants a role on behalf of a user. - /// @param _roleAssignment The role assignment data. - function grantRoleFrom(RoleAssignment calldata _roleAssignment) external; + /// @notice Creates a new record for on behalf of a user. + /// @param _grantor The owner of the NFTs. + /// @param _tokenAddress The token address. + /// @param _tokenId The token identifier. + /// @param _tokenAmount The token amount. + /// @return recordId_ The unique identifier of the record created. + function createRecordFrom( + address _grantor, + address _tokenAddress, + uint256 _tokenId, + uint256 _tokenAmount + ) external returns (uint256 recordId_); + + /// @notice Grants a role to `_grantee`. + /// @param _recordId The identifier of the record. + /// @param _role The role identifier. + /// @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. + function grantRole( + uint256 _recordId, + bytes32 _role, + address _grantee, + uint64 _expirationDate, + bool _revocable, + bytes calldata _data + ) external; /// @notice Revokes a role on behalf of a user. - /// @param _grantor The user revoking the role. - /// @param _nonce The identifier of the role assignment. + /// @param _recordId The record identifier. /// @param _role The role identifier. /// @param _grantee The user that gets their role revoked. - function revokeRoleFrom(address _grantor, uint256 _nonce, bytes32 _role, address _grantee) external; + function revokeRoleFrom(uint256 _recordId, bytes32 _role, address _grantee) external; + + /// @notice Withdraws tokens back to grantor. + /// @param _recordId The record identifier. + function withdrawFrom(uint256 _recordId) external; /// @notice Approves operator to grant and revoke roles on behalf of another user. /// @param _tokenAddress The token address. @@ -108,33 +117,24 @@ interface ISftRolesRegistry is IERC165 { /// @param _approved The approval status. function setRoleApprovalForAll(address _tokenAddress, address _operator, bool _approved) external; - /// @notice Withdraws tokens back to grantor. - /// @param _grantor The user withdrawing the tokens. - /// @param _nonce The identifier of the role assignment. - function withdrawFrom(address _grantor, uint256 _nonce) external; - /** View Functions **/ /// @notice Returns the custom data of a role assignment. - /// @param _grantor The user that assigned the role. + /// @param _recordId The record identifier. /// @param _role The role identifier. - /// @param _nonce The identifier of the role assignment. - /// @param _grantee The user that gets their role revoked. + /// @param _grantee The user that received the role. function roleData( - address _grantor, - uint256 _nonce, + uint256 _recordId, bytes32 _role, address _grantee - ) external view returns (RoleData memory data_); + ) external view returns (RoleAssignment memory data_); /// @notice Returns the expiration date of a role assignment. - /// @param _grantor The user that assigned the role. - /// @param _nonce The identifier of the role assignment. + /// @param _recordId The record identifier. /// @param _role The role identifier. - /// @param _grantee The user that gets their role revoked. + /// @param _grantee The user that received the role. function roleExpirationDate( - address _grantor, - uint256 _nonce, + uint256 _recordId, bytes32 _role, address _grantee ) external view returns (uint64 expirationDate_);