diff --git a/contracts/OriumRentalProtocol.sol b/contracts/OriumRentalProtocol.sol index cfab12c..a1963e5 100644 --- a/contracts/OriumRentalProtocol.sol +++ b/contracts/OriumRentalProtocol.sol @@ -4,20 +4,17 @@ pragma solidity 0.8.9; import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import { AccessControlUpgradeable } from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; +import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; -contract OriumRentalProtocol is Initializable, AccessControlUpgradeable, PausableUpgradeable { - bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); +contract OriumRentalProtocol is Initializable, OwnableUpgradeable, PausableUpgradeable { uint256 public constant MAX_PERCENTAGE = 100 ether; // 100% uint256 public constant DEFAULT_FEE_PERCENTAGE = 2.5 ether; // 2.5% address public rolesRegistry; uint256 public maxDeadline; - /// @dev nonce => isPresigned - mapping(bytes32 => bool) public preSignedOffer; /// @dev tokenAddress => feePercentageInWei mapping(address => uint256) public feesPerCollection; @@ -31,23 +28,14 @@ contract OriumRentalProtocol is Initializable, AccessControlUpgradeable, Pausabl address treasury; } - modifier onlyTokenOwner(address _tokenAddress, uint256 _tokenId) { - require( - msg.sender == IERC721(_tokenAddress).ownerOf(_tokenId), - "OriumRentalProtocol: Caller does not have the required permission" - ); - _; - } - function initialize(address _owner, address _rolesRegistry, uint256 _maxDeadline) public initializer { - __AccessControl_init(); __Pausable_init(); + __Ownable_init(); rolesRegistry = _rolesRegistry; maxDeadline = _maxDeadline; - _setupRole(DEFAULT_ADMIN_ROLE, _owner); - _setupRole(PAUSER_ROLE, _owner); + transferOwnership(_owner); } function _chargeFee(address _tokenAddress, address _lender, address _feeToken, uint256 _feeAmount) internal { @@ -86,18 +74,18 @@ contract OriumRentalProtocol is Initializable, AccessControlUpgradeable, Pausabl return (_amount * _percentage) / MAX_PERCENTAGE; } - function pause() external onlyRole(PAUSER_ROLE) { + function pause() external onlyOwner { _pause(); } - function unpause() external onlyRole(PAUSER_ROLE) { + function unpause() external onlyOwner { _unpause(); } function setMarketplaceFeeForCollection( address _tokenAddress, uint256 _feePercentageInWei - ) external onlyRole(DEFAULT_ADMIN_ROLE) { + ) external onlyOwner { require( _feePercentageInWei <= MAX_PERCENTAGE, "OriumRentalProtocol: Fee percentage cannot be greater than 100%" @@ -105,10 +93,10 @@ contract OriumRentalProtocol is Initializable, AccessControlUpgradeable, Pausabl feesPerCollection[_tokenAddress] = _feePercentageInWei; } - function setCollectionFeeInfo(address _tokenAddress, uint256 _feePercentageInWei, address _treasury) external { + function setCollectionFeeInfo(address _creator, address _tokenAddress, uint256 _feePercentageInWei, address _treasury) external { require( - msg.sender == collectionFeeInfo[_tokenAddress].creator || hasRole(DEFAULT_ADMIN_ROLE, msg.sender), - "OriumRentalProtocol: Only creator or operator can set collection fee" + msg.sender == collectionFeeInfo[_tokenAddress].creator || msg.sender == owner(), + "OriumRentalProtocol: Only creator or operator can set collection fee info" ); require( _feePercentageInWei <= MAX_PERCENTAGE, @@ -116,13 +104,13 @@ contract OriumRentalProtocol is Initializable, AccessControlUpgradeable, Pausabl ); collectionFeeInfo[_tokenAddress] = CollectionFeeInfo({ - creator: collectionFeeInfo[_tokenAddress].creator, + creator: _creator, feePercentageInWei: _feePercentageInWei, treasury: _treasury }); } - function setMaxDeadline(uint256 _maxDeadline) external onlyRole(DEFAULT_ADMIN_ROLE) { + function setMaxDeadline(uint256 _maxDeadline) external onlyOwner { maxDeadline = _maxDeadline; } } diff --git a/contracts/interfaces/IRolesRegistry.sol b/contracts/interfaces/IRolesRegistry.sol deleted file mode 100644 index 287f177..0000000 --- a/contracts/interfaces/IRolesRegistry.sol +++ /dev/null @@ -1,237 +0,0 @@ -// SPDX-License-Identifier: CC0-1.0 - -pragma solidity 0.8.9; - -import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol"; - - -/// @title ERC-7432 Non-Fungible Token Roles -/// @dev See https://eips.ethereum.org/EIPS/eip-7432 -/// Note: the ERC-165 identifier for this interface is 0xd7e151ef. -interface IRolesRegistry is IERC165 { - struct RoleData { - uint64 expirationDate; - bytes data; - } - - /** Events **/ - - /// @notice Emitted when a role is granted. - /// @param _role The role identifier. - /// @param _tokenAddress The token address. - /// @param _tokenId The token identifier. - /// @param _grantor The user assigning the role. - /// @param _grantee The user receiving the role. - /// @param _expirationDate The expiration date of the role. - /// @param _data Any additional data about the role. - event RoleGranted( - bytes32 indexed _role, - address indexed _tokenAddress, - uint256 indexed _tokenId, - address _grantor, - address _grantee, - uint64 _expirationDate, - bytes _data - ); - - /// @notice Emitted when a role is revoked. - /// @param _role The role identifier. - /// @param _tokenAddress The token address. - /// @param _tokenId The token identifier. - /// @param _revoker The user revoking the role. - /// @param _grantee The user that receives the role revocation. - event RoleRevoked( - bytes32 indexed _role, - address indexed _tokenAddress, - uint256 indexed _tokenId, - address _revoker, - address _grantee - ); - - /// @notice Emitted when a user is approved to manage any role 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 is approved to manage the roles of an NFT on behalf of another user. - /// @param _tokenAddress The token address. - /// @param _tokenId The token identifier. - /// @param _operator The user approved to grant and revoke roles. - /// @param _isApproved The approval status. - event RoleApproval( - address indexed _tokenAddress, - uint256 indexed _tokenId, - address _operator, - bool _isApproved - ); - - /** External Functions **/ - - /// @notice Grants a role to a user. - /// @param _role The role identifier. - /// @param _tokenAddress The token address. - /// @param _tokenId The token identifier. - /// @param _grantee The user receiving the role. - /// @param _expirationDate The expiration date of the role. - /// @param _data Any additional data about the role. - function grantRole( - bytes32 _role, - address _tokenAddress, - uint256 _tokenId, - address _grantee, - uint64 _expirationDate, - bytes calldata _data - ) external; - - /// @notice Revokes a role from a user. - /// @param _role The role identifier. - /// @param _tokenAddress The token address. - /// @param _tokenId The token identifier. - /// @param _grantee The user that receives the role revocation. - function revokeRole( - bytes32 _role, - address _tokenAddress, - uint256 _tokenId, - address _grantee - ) external; - - /// @notice Grants a role on behalf of a user. - /// @param _role The role identifier. - /// @param _tokenAddress The token address. - /// @param _tokenId The token identifier. - /// @param _grantor The user assigning the role. - /// @param _grantee The user that receives the role. - /// @param _expirationDate The expiration date of the role. - /// @param _data Any additional data about the role. - function grantRoleFrom( - bytes32 _role, - address _tokenAddress, - uint256 _tokenId, - address _grantor, - address _grantee, - uint64 _expirationDate, - bytes calldata _data - ) external; - - /// @notice Revokes a role on behalf of a user. - /// @param _role The role identifier. - /// @param _tokenAddress The token address. - /// @param _tokenId The token identifier. - /// @param _revoker The user revoking the role. - /// @param _grantee The user that receives the role revocation. - function revokeRoleFrom( - bytes32 _role, - address _tokenAddress, - uint256 _tokenId, - address _revoker, - 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; - - /// @notice Approves operator to grant and revoke roles of an NFT on behalf of another user. - /// @param _tokenAddress The token address. - /// @param _tokenId The token identifier. - /// @param _operator The user approved to grant and revoke roles. - /// @param _approved The approval status. - function approveRole( - address _tokenAddress, - uint256 _tokenId, - address _operator, - bool _approved - ) external; - - /** View Functions **/ - - /// @notice Checks if a user has a role. - /// @param _role The role identifier. - /// @param _tokenAddress The token address. - /// @param _tokenId The token identifier. - /// @param _grantor The user that assigned the role. - /// @param _grantee The user that received the role. - function hasRole( - bytes32 _role, - address _tokenAddress, - uint256 _tokenId, - address _grantor, - address _grantee - ) external view returns (bool); - - /// @notice Checks if a user has a unique role. - /// @param _role The role identifier. - /// @param _tokenAddress The token address. - /// @param _tokenId The token identifier. - /// @param _grantor The user that assigned the role. - /// @param _grantee The user that received the role. - function hasUniqueRole( - bytes32 _role, - address _tokenAddress, - uint256 _tokenId, - address _grantor, - address _grantee - ) external view returns (bool); - - /// @notice Returns the custom data of a role assignment. - /// @param _role The role identifier. - /// @param _tokenAddress The token address. - /// @param _tokenId The token identifier. - /// @param _grantor The user that assigned the role. - /// @param _grantee The user that received the role. - function roleData( - bytes32 _role, - address _tokenAddress, - uint256 _tokenId, - address _grantor, - address _grantee - ) external view returns (bytes memory data_); - - /// @notice Returns the expiration date of a role assignment. - /// @param _role The role identifier. - /// @param _tokenAddress The token address. - /// @param _tokenId The token identifier. - /// @param _grantor The user that assigned the role. - /// @param _grantee The user that received the role. - function roleExpirationDate( - bytes32 _role, - address _tokenAddress, - uint256 _tokenId, - address _grantor, - 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); - - /// @notice Checks if the grantor approved the operator for a specific NFT. - /// @param _tokenAddress The token address. - /// @param _tokenId The token identifier. - /// @param _grantor The user that approved the operator. - /// @param _operator The user approved to grant and revoke roles. - function getApprovedRole( - address _tokenAddress, - uint256 _tokenId, - address _grantor, - address _operator - ) external view returns (bool); - -} \ No newline at end of file diff --git a/contracts/mocks/MockERC721.sol b/contracts/mocks/MockERC721.sol deleted file mode 100644 index e8e7a7a..0000000 --- a/contracts/mocks/MockERC721.sol +++ /dev/null @@ -1,13 +0,0 @@ -// SPDX-License-Identifier: CC0-1.0 - -pragma solidity 0.8.9; - -import { ERC721 } from "@openzeppelin/contracts/token/ERC721/ERC721.sol"; - -contract MockERC721 is ERC721 { - constructor(string memory name_, string memory symbol_) ERC721(name_, symbol_) {} - - function mint(address to, uint256 tokenId) external { - _mint(to, tokenId); - } -} \ No newline at end of file