forked from ProjectOpenSea/operator-filter-registry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExampleERC1155.sol
58 lines (53 loc) · 2.47 KB
/
ExampleERC1155.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {ERC1155} from "openzeppelin-contracts/token/ERC1155/ERC1155.sol";
import {ERC2981} from "openzeppelin-contracts/token/common/ERC2981.sol";
import {Ownable} from "openzeppelin-contracts/access/Ownable.sol";
import {DefaultOperatorFilterer} from "../DefaultOperatorFilterer.sol";
/**
* @title ExampleERC1155
* @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 safeTransferFrom methods ensures that
* the msg.sender (operator) is allowed by the OperatorFilterRegistry. Adding the onlyAllowedOperatorApproval
* modifier to the setApprovalForAll method ensures that owners do not approve operators that are not allowed.
*/
abstract contract ExampleERC1155 is ERC1155(""), ERC2981, DefaultOperatorFilterer, Ownable {
/**
* @dev See {IERC1155-setApprovalForAll}.
* In this example the added modifier ensures that the operator is allowed by the OperatorFilterRegistry.
*/
function setApprovalForAll(address operator, bool approved) public override onlyAllowedOperatorApproval(operator) {
super.setApprovalForAll(operator, approved);
}
/**
* @dev See {IERC1155-safeTransferFrom}.
* In this example the added modifier ensures that the operator is allowed by the OperatorFilterRegistry.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, uint256 amount, bytes memory data)
public
override
onlyAllowedOperator(from)
{
super.safeTransferFrom(from, to, tokenId, amount, data);
}
/**
* @dev See {IERC1155-safeBatchTransferFrom}.
* In this example the added modifier ensures that the operator is allowed by the OperatorFilterRegistry.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) public virtual override onlyAllowedOperator(from) {
super.safeBatchTransferFrom(from, to, ids, amounts, data);
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC1155, ERC2981) returns (bool) {
return ERC1155.supportsInterface(interfaceId) || ERC2981.supportsInterface(interfaceId);
}
}