File size: 13,165 Bytes
f998fcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{
  "language": "Solidity",
  "sources": {
    "contracts/Manager/royalty/RoyaltyFeeRegistry.sol": {
      "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"
    },
    "contracts/Manager/royalty/interface/IRoyaltyFeeRegistry.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.9;\n\ninterface IRoyaltyFeeRegistry {\n  \n    function updateRoyaltyFeeLimit(uint256 _royaltyFeeLimit) external;\n\n    function royaltyInfo(address collection, uint256 amount) external view returns (address, uint256);\n\n    function royaltyFeeInfoCollection(address collection)\n        external\n        view\n        returns (\n            address,\n            address,\n            uint256\n        );\n}\n"
    },
    "contracts/Manager/interface/IOwnable.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.9;\n\ninterface IOwnable {\n    function transferOwnership(address newOwner) external;\n\n    function owner() external view returns (address);\n\n    function admin() external view returns (address);\n}\n"
    },
    "@openzeppelin/contracts/access/Ownable.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    constructor() {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions anymore. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby removing any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/introspection/IERC165.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n    /**\n     * @dev Returns true if this contract implements the interface defined by\n     * `interfaceId`. See the corresponding\n     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n     * to learn more about how these ids are created.\n     *\n     * This function call must use less than 30 000 gas.\n     */\n    function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n"
    },
    "@openzeppelin/contracts/utils/Context.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n}\n"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 99999
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    }
  }
}