diff --git a/src/tokens/ERC6160Ext1155.sol b/src/tokens/ERC6160Ext1155.sol index ca61aaf..6a1d3a1 100644 --- a/src/tokens/ERC6160Ext1155.sol +++ b/src/tokens/ERC6160Ext1155.sol @@ -40,21 +40,21 @@ contract ERC6160Ext1155 is ERC1155, ERC165Storage, IERC6160Ext1155 { } /// @notice Mints token to the specified account `_to` - function safeMint(address _to, uint256 _id, uint256 _amount, bytes calldata _data) external { + function safeMint(address _to, uint256 _id, uint256 _amount, bytes calldata _data) public { if (!isRoleAdmin(MINTER_ROLE) && !hasRole(MINTER_ROLE, _msgSender())) revert PermissionDenied(); super._mint(_to, _id, _amount, _data); } /// @notice Mints token in batch to the specified account `_to` function safeMintBatch(address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data) - external + public { if (!isRoleAdmin(MINTER_ROLE) && !hasRole(MINTER_ROLE, _msgSender())) revert PermissionDenied(); super._mintBatch(to, ids, amounts, data); } /// @notice Burns token associated with the specified account `_from` - function burn(address _from, uint256 _id, uint256 _amount, bytes[] calldata) external { + function burn(address _from, uint256 _id, uint256 _amount, bytes[] calldata) public { bool isApproved = isApprovedForAll(_msgSender(), _from); bool hasBurnRole = isRoleAdmin(BURNER_ROLE) || hasRole(BURNER_ROLE, _msgSender()); if (!isApproved && !hasBurnRole) revert PermissionDenied(); @@ -62,7 +62,7 @@ contract ERC6160Ext1155 is ERC1155, ERC165Storage, IERC6160Ext1155 { } /// @notice Burns token in batch associated with the specified account `_from` - function burnBatch(address _from, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata) external { + function burnBatch(address _from, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata) public { bool isApproved = isApprovedForAll(_msgSender(), _from); bool hasBurnRole = isRoleAdmin(BURNER_ROLE) || hasRole(BURNER_ROLE, _msgSender()); if (!isApproved && !hasBurnRole) revert PermissionDenied(); @@ -80,7 +80,7 @@ contract ERC6160Ext1155 is ERC1155, ERC165Storage, IERC6160Ext1155 { /// @dev This method can only be called from an admin of the given role /// @param _role The role to set for the account /// @param _account The account to be granted the specified role - function grantRole(bytes32 _role, address _account) external { + function grantRole(bytes32 _role, address _account) public { if (!isRoleAdmin(_role)) revert NotRoleAdmin(); _roles[_role][_account] = true; } @@ -89,7 +89,7 @@ contract ERC6160Ext1155 is ERC1155, ERC165Storage, IERC6160Ext1155 { /// @dev This method can only be called from an admin of the given role /// @param _role The role to revoke for the account /// @param _account The account whose role is to be revoked - function revokeRole(bytes32 _role, address _account) external { + function revokeRole(bytes32 _role, address _account) public { if (!isRoleAdmin(_role)) revert NotRoleAdmin(); _roles[_role][_account] = false; } @@ -107,12 +107,12 @@ contract ERC6160Ext1155 is ERC1155, ERC165Storage, IERC6160Ext1155 { } /// @notice Get the Minter-Role ID - function getMinterRole() external pure returns (bytes32) { + function getMinterRole() public pure returns (bytes32) { return MINTER_ROLE; } /// @notice Get the Burner-Role ID - function getBurnerRole() external pure returns (bytes32) { + function getBurnerRole() public pure returns (bytes32) { return BURNER_ROLE; } diff --git a/src/tokens/ERC6160Ext20.sol b/src/tokens/ERC6160Ext20.sol index f3fce05..de2fcd0 100644 --- a/src/tokens/ERC6160Ext20.sol +++ b/src/tokens/ERC6160Ext20.sol @@ -13,57 +13,50 @@ error PermissionDenied(); contract ERC6160Ext20 is ERC165Storage, ERC20, IERC6160Ext20 { /// @notice InterfaceId for ERC6160Ext20 - bytes4 constant _IERC6160Ext20_ID_ = 0xbbb8b47e; + bytes4 private constant IERC6160Ext20_ID = 0xbbb8b47e; /// @notice The Id of Role required to mint token - bytes32 constant MINTER_ROLE = keccak256("MINTER ROLE"); + bytes32 public constant MINTER_ROLE = keccak256("MINTER ROLE"); /// @notice The Id of Role required to burn token - bytes32 constant BURNER_ROLE = keccak256("BURNER ROLE"); + bytes32 public constant BURNER_ROLE = keccak256("BURNER ROLE"); /// @notice mapping of defined roles in the contract - mapping(bytes32 => mapping(address => bool)) _roles; + mapping(bytes32 => mapping(address => bool)) internal _roles; /// @notice mapping of admins of defined roles - mapping(bytes32 => mapping(address => bool)) _rolesAdmin; + mapping(bytes32 => mapping(address => bool)) internal _rolesAdmin; constructor(address admin, string memory name, string memory symbol) ERC20(name, symbol) { - _registerInterface(_IERC6160Ext20_ID_); + _registerInterface(IERC6160Ext20_ID); _registerInterface(type(IERC5679Ext20).interfaceId); _registerInterface(type(IERC_ACL_CORE).interfaceId); _rolesAdmin[MINTER_ROLE][admin] = true; - _roles[MINTER_ROLE][admin] = true; - _rolesAdmin[BURNER_ROLE][admin] = true; + + _roles[MINTER_ROLE][admin] = true; _roles[BURNER_ROLE][admin] = true; } /// @notice Mints token to the specified account `_to` - function mint(address _to, uint256 _amount, bytes calldata) external { - if (!isRoleAdmin(MINTER_ROLE) && !hasRole(MINTER_ROLE, _msgSender())) revert PermissionDenied(); + function mint(address _to, uint256 _amount, bytes calldata) public { + if (!_isRoleAdmin(MINTER_ROLE) && !hasRole(MINTER_ROLE, _msgSender())) revert PermissionDenied(); super._mint(_to, _amount); } /// @notice Burns token associated with the specified account `_from` - function burn(address _from, uint256 _amount, bytes calldata) external { - if (!isRoleAdmin(BURNER_ROLE) && !hasRole(BURNER_ROLE, _msgSender())) revert PermissionDenied(); + function burn(address _from, uint256 _amount, bytes calldata) public { + if (!_isRoleAdmin(BURNER_ROLE) && !hasRole(BURNER_ROLE, _msgSender())) revert PermissionDenied(); super._burn(_from, _amount); } - /// @notice Checks that an account has a specified role - /// @param _role The role to query - /// @param _account The account to query for the given role - function hasRole(bytes32 _role, address _account) public view returns (bool) { - return _roles[_role][_account]; - } - /// @notice Grants a given role to the specified account /// @dev This method can only be called from an admin of the given role /// @param _role The role to set for the account /// @param _account The account to be granted the specified role - function grantRole(bytes32 _role, address _account) external { - if (!isRoleAdmin(_role)) revert NotRoleAdmin(); + function grantRole(bytes32 _role, address _account) public { + if (!_isRoleAdmin(_role)) revert NotRoleAdmin(); _roles[_role][_account] = true; } @@ -71,8 +64,8 @@ contract ERC6160Ext20 is ERC165Storage, ERC20, IERC6160Ext20 { /// @dev This method can only be called from an admin of the given role /// @param _role The role to revoke for the account /// @param _account The account whose role is to be revoked - function revokeRole(bytes32 _role, address _account) external { - if (!isRoleAdmin(_role)) revert NotRoleAdmin(); + function revokeRole(bytes32 _role, address _account) public { + if (!_isRoleAdmin(_role)) revert NotRoleAdmin(); _roles[_role][_account] = false; } @@ -82,20 +75,27 @@ contract ERC6160Ext20 is ERC165Storage, ERC20, IERC6160Ext20 { return super.supportsInterface(_interfaceId); } + /// @notice Checks that an account has a specified role + /// @param _role The role to query + /// @param _account The account to query for the given role + function hasRole(bytes32 _role, address _account) public view returns (bool) { + return _roles[_role][_account]; + } + /// @notice Get the Minter-Role ID - function getMinterRole() external pure returns (bytes32) { + function getMinterRole() public pure returns (bytes32) { return MINTER_ROLE; } /// @notice Get the Burner-Role ID - function getBurnerRole() external pure returns (bytes32) { + function getBurnerRole() public pure returns (bytes32) { return BURNER_ROLE; } /** * INTERNAL FUNCTIONS * */ - function isRoleAdmin(bytes32 role) internal view returns (bool) { + function _isRoleAdmin(bytes32 role) internal view returns (bool) { return _rolesAdmin[role][_msgSender()]; } } diff --git a/src/tokens/ERC6160Ext721.sol b/src/tokens/ERC6160Ext721.sol index e58a8d8..50adffc 100644 --- a/src/tokens/ERC6160Ext721.sol +++ b/src/tokens/ERC6160Ext721.sol @@ -40,13 +40,13 @@ contract ERC6160Ext721 is ERC721, ERC165Storage, IERC6160Ext721 { } /// @notice Mints token with ID of `_tokenId` to the specified account `_to` - function safeMint(address _to, uint256 _tokenId, bytes calldata _data) external { + function safeMint(address _to, uint256 _tokenId, bytes calldata _data) public { if (!isRoleAdmin(MINTER_ROLE) && !hasRole(MINTER_ROLE, _msgSender())) revert PermissionDenied(); super._safeMint(_to, _tokenId, _data); } /// @notice Burns token with ID of `_tokenId` - function burn(address, uint256 _tokenId, bytes calldata) external { + function burn(address, uint256 _tokenId, bytes calldata) public { bool isApproved = _isApprovedOrOwner(_msgSender(), _tokenId); bool hasBurnRole = isRoleAdmin(BURNER_ROLE) || hasRole(BURNER_ROLE, _msgSender()); if (!isApproved && !hasBurnRole) revert PermissionDenied(); @@ -64,7 +64,7 @@ contract ERC6160Ext721 is ERC721, ERC165Storage, IERC6160Ext721 { /// @dev This method can only be called from an admin of the given role /// @param _role The role to set for the account /// @param _account The account to be granted the specified role - function grantRole(bytes32 _role, address _account) external { + function grantRole(bytes32 _role, address _account) public { if (!isRoleAdmin(_role)) revert NotRoleAdmin(); _roles[_role][_account] = true; } @@ -73,7 +73,7 @@ contract ERC6160Ext721 is ERC721, ERC165Storage, IERC6160Ext721 { /// @dev This method can only be called from an admin of the given role /// @param _role The role to revoke for the account /// @param _account The account whose role is to be revoked - function revokeRole(bytes32 _role, address _account) external { + function revokeRole(bytes32 _role, address _account) public { if (!isRoleAdmin(_role)) revert NotRoleAdmin(); _roles[_role][_account] = false; } @@ -96,17 +96,17 @@ contract ERC6160Ext721 is ERC721, ERC165Storage, IERC6160Ext721 { } /// @notice Checks that token of ID `_tokenID` exists - function exists(uint256 _tokenID) external view returns (bool) { + function exists(uint256 _tokenID) public view returns (bool) { return super._exists(_tokenID); } /// @notice Get the Minter-Role ID - function getMinterRole() external pure returns (bytes32) { + function getMinterRole() public pure returns (bytes32) { return MINTER_ROLE; } /// @notice Get the Burner-Role ID - function getBurnerRole() external pure returns (bytes32) { + function getBurnerRole() public pure returns (bytes32) { return BURNER_ROLE; }