File size: 2,008 Bytes
cc183a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import {ERC2981} from "@openzeppelin/contracts/token/common/ERC2981.sol";
import {IERC5192} from "./interfaces/IERC5192.sol";

contract RoyaltyCollection is ERC721, ERC2981, IERC5192 {
    address public immutable issuer;
    mapping(uint256 => bool) private _locked;

    constructor(address royaltyReceiver, uint96 royaltyBps) ERC721("Royalty Collection", "ROYAL") {
        issuer = msg.sender;
        if (royaltyReceiver != address(0)) {
            _setDefaultRoyalty(royaltyReceiver, royaltyBps);
        }
    }

    function mint(address to, uint256 tokenId) external {
        require(msg.sender == issuer, "only issuer");
        _mint(to, tokenId);
    }

    function setDefaultRoyalty(address receiver, uint96 feeNumerator) external {
        require(msg.sender == issuer, "only issuer");
        if (receiver == address(0) && feeNumerator == 0) {
            _deleteDefaultRoyalty();
        } else {
            _setDefaultRoyalty(receiver, feeNumerator);
        }
    }

    function setLocked(uint256 tokenId, bool value) public virtual {
        require(msg.sender == _requireOwned(tokenId), "only owner");
        _locked[tokenId] = value;
        if (value) emit Locked(tokenId);
        else emit Unlocked(tokenId);
    }

    function locked(uint256 tokenId) public view returns (bool) {
        _requireOwned(tokenId);
        return _locked[tokenId];
    }

    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, ERC2981) returns (bool) {
        return interfaceId == type(IERC5192).interfaceId || super.supportsInterface(interfaceId);
    }

    function _update(address to, uint256 tokenId, address auth) internal virtual override returns (address from) {
        from = super._update(to, tokenId, auth);
        if (from != address(0)) {
            require(!_locked[tokenId], "token is locked");
        }
    }
}