This is a quick implementation of the OpenSea OperatorFilter with a way to activate / deactivate it over time
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {WithOperatorFilter} from './WithOperatorFilter.sol';
import {ERC721A} from "erc721a/contracts/ERC721A.sol";
import {ERC2981} from '@openzeppelin/contracts/token/common/ERC2981.sol';
contract MyToken is ERC721A, WithOperatorFilter, Ownable {
constructor() ERC721A('Token', 'TOKEN') {}
/// @inheritdoc ERC721A
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC721A, ERC2981)
returns (bool)
{
return ERC721A.supportsInterface(interfaceId) || ERC2981.supportsInterface(interfaceId);
}
/// @inheritdoc ERC2981
function royaltyInfo(uint256 tokenId, uint256 amount) public view override returns (address recipient, uint256 amount) {
return (owner(), amount * 1000 / 10000);
}
/////////////////////////////////////////////////////////
// Interactions //
/////////////////////////////////////////////////////////
/// @inheritdoc ERC721A
/// @dev overrode to add the FilterOperator
function transferFrom(
address from,
address to,
uint256 tokenId
) public payable override onlyAllowedOperator(from) {
super.transferFrom(from, to, tokenId);
}
/// @inheritdoc ERC721A
/// @dev overrode to add the FilterOperator
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public payable override onlyAllowedOperator(from) {
super.safeTransferFrom(from, to, tokenId);
}
/// @inheritdoc ERC721A
/// @dev overrode to add the FilterOperator
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory data
) public payable override onlyAllowedOperator(from) {
super.safeTransferFrom(from, to, tokenId, data);
}
/// @inheritdoc ERC721A
/// @dev overrode to add the FilterOperator
function setApprovalForAll(address operator, bool _approved)
public
override
onlyAllowedOperatorForApproval(operator, _approved)
{
super.setApprovalForAll(operator, _approved);
}
/////////////////////////////////////////////////////////
// Gated Owner //
/////////////////////////////////////////////////////////
/// @notice Allows owner to switch on/off the OperatorFilter
/// @param newIsEnabled the new state
function setIsOperatorFilterEnabled(bool newIsEnabled) public onlyOwner {
isOperatorFilterEnabled = newIsEnabled;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {WithOperatorFilter} from './WithOperatorFilter.sol';
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import {ERC2981} from '@openzeppelin/contracts/token/common/ERC2981.sol';
contract MyToken is ERC721, WithOperatorFilter, Ownable {
constructor() ERC721('Token', 'TOKEN') {}
/// @inheritdoc ERC721
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC721, ERC2981)
returns (bool)
{
return ERC721.supportsInterface(interfaceId) || ERC2981.supportsInterface(interfaceId);
}
/// @inheritdoc ERC2981
function royaltyInfo(uint256 tokenId, uint256 amount) public view override returns (address, uint256) {
return (owner(), amount * 1000 / 10000);
}
/////////////////////////////////////////////////////////
// Interactions //
/////////////////////////////////////////////////////////
/// @inheritdoc ERC721
/// @dev overrode to add the FilterOperator
function transferFrom(
address from,
address to,
uint256 tokenId
) public override onlyAllowedOperator(from) {
super.transferFrom(from, to, tokenId);
}
/// @inheritdoc ERC721
/// @dev overrode to add the FilterOperator
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public override onlyAllowedOperator(from) {
super.safeTransferFrom(from, to, tokenId);
}
/// @inheritdoc ERC721
/// @dev overrode to add the FilterOperator
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory data
) public override onlyAllowedOperator(from) {
super.safeTransferFrom(from, to, tokenId, data);
}
/// @inheritdoc ERC721
/// @dev overrode to add the FilterOperator
function setApprovalForAll(address operator, bool _approved)
public
override
onlyAllowedOperatorForApproval(operator, _approved)
{
super.setApprovalForAll(operator, _approved);
}
/////////////////////////////////////////////////////////
// Gated Owner //
/////////////////////////////////////////////////////////
/// @notice Allows owner to switch on/off the OperatorFilter
/// @param newIsEnabled the new state
function setIsOperatorFilterEnabled(bool newIsEnabled) public onlyOwner {
isOperatorFilterEnabled = newIsEnabled;
}
}