|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.9;\nimport {IERC165} from \"@openzeppelin/contracts/utils/introspection/IERC165.sol\";\nimport {Ownable} from \"@openzeppelin/contracts/access/Ownable.sol\";\nimport {IOwnable} from \"../interface/IOwnable.sol\";\n\nimport {IRoyaltyFeeRegistry} from \"./interface/IRoyaltyFeeRegistry.sol\";\n\n// register royalty fee\ncontract RoyaltyFeeRegistry is IRoyaltyFeeRegistry, Ownable {\n struct FeeInfo {\n address setter;\n address receiver;\n uint256 fee;\n }\n // ERC721 interfaceID\n bytes4 public constant INTERFACE_ID_ERC721 = 0x80ac58cd;\n\n // ERC1155 interfaceID\n bytes4 public constant INTERFACE_ID_ERC1155 = 0xd9b67a26;\n\n // ERC2981 interfaceID\n bytes4 public constant INTERFACE_ID_ERC2981 = 0x2a55205a;\n\n // limit max royalty fee(10,000 = 100%)\n uint256 public royaltyFeeLimit;\n\n //compile royalty information mapping \n mapping(address => FeeInfo) private _royaltyFeeInfoCollection;\n\n event NewRoyaltyFeeLimit(uint256 royaltyFeeLimit);\n event RoyaltyFeeUpdate(address indexed collection, address indexed setter, address indexed receiver, uint256 fee);\n\n // initialize royalty fee\n constructor(uint256 _royaltyFeeLimit) {\n // no higher than the upper limit\n require(_royaltyFeeLimit <= 9500, \"Royalty fee limit too high\");\n royaltyFeeLimit = _royaltyFeeLimit;\n }\n\n // Update a collection's upper limit of royalty fee\n function updateRoyaltyFeeLimit(uint256 _royaltyFeeLimit) external override onlyOwner {\n // no higher than the upper limit\n require(_royaltyFeeLimit <= 9500, \"Royalty fee limit too high\");\n royaltyFeeLimit = _royaltyFeeLimit;\n\n emit NewRoyaltyFeeLimit(_royaltyFeeLimit);\n }\n\n function updateRoyaltyInfoForCollection(\n address collection,\n address setter,\n address receiver,\n uint256 fee\n ) internal{\n require(fee <= royaltyFeeLimit, \"Registry: Royalty fee too high\");\n\n _royaltyFeeInfoCollection[collection] = FeeInfo({setter: setter, receiver: receiver, fee: fee});\n\n emit RoyaltyFeeUpdate(collection, setter, receiver, fee);\n }\n\n //\n // function royaltyInfo\n // @Description: calculate royalty fee\n // @param address\n // @param uint256\n // @return external\n //\n function royaltyInfo(address collection, uint256 amount) external view override returns (address, uint256) {\n return (\n _royaltyFeeInfoCollection[collection].receiver,\n (amount * _royaltyFeeInfoCollection[collection].fee) / 10000\n );\n }\n /*Check collection information*/\n function royaltyFeeInfoCollection(address collection)\n external\n view\n override\n returns (\n address,\n address,\n uint256\n )\n {\n return (\n _royaltyFeeInfoCollection[collection].setter,\n _royaltyFeeInfoCollection[collection].receiver,\n _royaltyFeeInfoCollection[collection].fee\n );\n }\n\n\n function updateRoyaltyInfoForCollectionIfSetter(\n address collection,\n address setter,\n address receiver,\n uint256 fee\n ) external {\n address currentSetter = _royaltyFeeInfoCollection[collection].setter;\n require(msg.sender == currentSetter, \"Setter: Not the setter\");\n\n updateRoyaltyInfoForCollection(collection, setter, receiver, fee);\n }\n\n\n //\n // function checkForCollectionSetter\n // @Description: Confirm royalty fee seeting information\n // @param address\n // @return external Return editor, regarless of admin or owner\n //\n function checkForCollectionSetter(address collection) external view returns (address, uint8) {\n address currentSetter = _royaltyFeeInfoCollection[collection].setter;\n if (currentSetter != address(0)){\n return (currentSetter,0);\n }\n try IERC165(collection).supportsInterface(INTERFACE_ID_ERC2981) returns (bool interfaceSupport) {\n if (interfaceSupport) {\n return (address(0), 1);\n }\n } catch {}\n\n try IOwnable(collection).owner() returns (address setter) {\n return (setter, 2);\n } catch {\n try IOwnable(collection).admin() returns (address setter) {\n return (setter, 3);\n } catch {\n return (address(0), 4);\n }\n }\n }\n\n //\n // function updateRoyaltyInfoForCollectionIfAdmin\n // @Description: Update royalty info if this is the admin of the collection\n // @param address collection address\n // @param address Editor address\n // @param address Wallet address receiving royalty fee\n // @param uint256 royalty fee 500=5%\n // @return external\n //\n function updateRoyaltyInfoForCollectionIfAdmin(\n address collection,\n address setter,\n address receiver,\n uint256 fee\n ) external {\n //https://eips.ethereum.org/EIPS/eip-2981\n require(!IERC165(collection).supportsInterface(INTERFACE_ID_ERC2981), \" Must not be ERC2981\");\n require(msg.sender == IOwnable(collection).admin(), \" Not the admin\");\n\n _updateRoyaltyInfoForCollectionIfOwnerOrAdmin(collection, setter, receiver, fee);\n }\n\n //\n // tion updateRoyaltyInfoForCollectionIfOwner\n // @Description: Update royalty info if this is the owner of the collection\n // @param address\n // @param address\n // @param address\n // @param uint256\n // @return external\n //\n function updateRoyaltyInfoForCollectionIfOwner(\n address collection,\n address setter,\n address receiver,\n uint256 fee\n ) external {\n require(!IERC165(collection).supportsInterface(INTERFACE_ID_ERC2981), \" Must not be ERC2981\");\n require(msg.sender == IOwnable(collection).owner(), \" Not the owner\");\n\n _updateRoyaltyInfoForCollectionIfOwnerOrAdmin(collection, setter, receiver, fee);\n }\n\n //\n // function _updateRoyaltyInfoForCollectionIfOwnerOrAdmin\n // @Description: Update royalty fee information\n // @param address\n // @param address\n // @param address\n // @param uint256\n // @return internal\n //\n function _updateRoyaltyInfoForCollectionIfOwnerOrAdmin(\n address collection,\n address setter,\n address receiver,\n uint256 fee\n ) internal {\n address currentSetter = _royaltyFeeInfoCollection[collection].setter;\n require(currentSetter == address(0), \"Already set\");\n\n require(\n (IERC165(collection).supportsInterface(INTERFACE_ID_ERC721) ||\n IERC165(collection).supportsInterface(INTERFACE_ID_ERC1155)),\n \" Not Set of ERC721/ERC1155\"\n );\n\n updateRoyaltyInfoForCollection(collection, setter, receiver, fee);\n }\n}\n"
|