-
Notifications
You must be signed in to change notification settings - Fork 27
/
ExampleERC721Upgradeable.sol
119 lines (103 loc) · 3.79 KB
/
ExampleERC721Upgradeable.sol
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import {ERC721Upgradeable} from
"openzeppelin-contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import {OperatorFilterer} from "../../OperatorFilterer.sol";
import {OwnableUpgradeable} from "openzeppelin-contracts-upgradeable/access/OwnableUpgradeable.sol";
import {
IERC2981Upgradeable,
ERC2981Upgradeable
} from "openzeppelin-contracts-upgradeable/token/common/ERC2981Upgradeable.sol";
/**
* @title ExampleERC721Upgradeable
* @notice This example contract is configured to use the DefaultOperatorFilterer, which automatically registers the
* token and subscribes it to OpenSea's curated filters.
* Adding the onlyAllowedOperator modifier to the transferFrom and both safeTransferFrom methods ensures that
* the msg.sender (operator) is allowed by the OperatorFilterRegistry.
*/
abstract contract ExampleERC721Upgradeable is
ERC721Upgradeable,
OperatorFilterer,
OwnableUpgradeable,
ERC2981Upgradeable
{
bool public operatorFilteringEnabled;
function initialize() public initializer {
__ERC721_init("Example", "EXAMPLE");
__Ownable_init();
__ERC2981_init();
_registerForOperatorFiltering();
operatorFilteringEnabled = true;
// Set royalty receiver to the contract creator,
// at 5% (default denominator is 10000).
_setDefaultRoyalty(msg.sender, 500);
}
function setApprovalForAll(address operator, bool approved)
public
override
onlyAllowedOperatorApproval(operator)
{
super.setApprovalForAll(operator, approved);
}
function approve(address operator, uint256 tokenId)
public
override
onlyAllowedOperatorApproval(operator)
{
super.approve(operator, tokenId);
}
function transferFrom(address from, address to, uint256 tokenId)
public
override
onlyAllowedOperator(from)
{
super.transferFrom(from, to, tokenId);
}
function safeTransferFrom(address from, address to, uint256 tokenId)
public
override
onlyAllowedOperator(from)
{
super.safeTransferFrom(from, to, tokenId);
}
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data)
public
override
onlyAllowedOperator(from)
{
super.safeTransferFrom(from, to, tokenId, data);
}
function tokenURI(uint256) public pure override returns (string memory) {
return "";
}
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC721Upgradeable, ERC2981Upgradeable)
returns (bool)
{
// Supports the following `interfaceId`s:
// - IERC165: 0x01ffc9a7
// - IERC721: 0x80ac58cd
// - IERC721Metadata: 0x5b5e139f
// - IERC2981: 0x2a55205a
return ERC721Upgradeable.supportsInterface(interfaceId)
|| ERC2981Upgradeable.supportsInterface(interfaceId);
}
function setDefaultRoyalty(address receiver, uint96 feeNumerator) public onlyOwner {
_setDefaultRoyalty(receiver, feeNumerator);
}
function setOperatorFilteringEnabled(bool value) public onlyOwner {
operatorFilteringEnabled = value;
}
function _operatorFilteringEnabled() internal view override returns (bool) {
return operatorFilteringEnabled;
}
function _isPriorityOperator(address operator) internal pure override returns (bool) {
// OpenSea Seaport Conduit:
// https://etherscan.io/address/0x1E0049783F008A0085193E00003D00cd54003c71
// https://goerli.etherscan.io/address/0x1E0049783F008A0085193E00003D00cd54003c71
return operator == address(0x1E0049783F008A0085193E00003D00cd54003c71);
}
}