// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import {ERC1155Upgradeable} from "openzeppelin-contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.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 ExampleERC1155Upgradeable * @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 ExampleERC1155Upgradeable is ERC1155Upgradeable, OperatorFilterer, OwnableUpgradeable, ERC2981Upgradeable { bool public operatorFilteringEnabled; function initialize() public initializer { __ERC1155_init(""); __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 safeTransferFrom( address from, address to, uint256 tokenId, uint256 amount, bytes memory data ) public override onlyAllowedOperator(from) { super.safeTransferFrom(from, to, tokenId, amount, data); } function safeBatchTransferFrom( address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) public override onlyAllowedOperator(from) { super.safeBatchTransferFrom(from, to, ids, amounts, data); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC1155Upgradeable, ERC2981Upgradeable) returns (bool) { // Supports the following `interfaceId`s: // - IERC165: 0x01ffc9a7 // - IERC1155: 0xd9b67a26 // - IERC1155MetadataURI: 0x0e89341c // - IERC2981: 0x2a55205a return ERC1155Upgradeable.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); } }