|
1 | 1 | // SPDX-License-Identifier: Apache 2.0 |
2 | | -// Credits: OpenSea |
| 2 | +// Credit: OpenSea |
3 | 3 | pragma solidity ^0.8.0; |
4 | 4 |
|
5 | 5 | import { IOperatorFilterRegistry } from "./interface/IOperatorFilterRegistry.sol"; |
6 | 6 |
|
7 | | -contract OperatorFilterer { |
| 7 | +abstract contract OperatorFilterer { |
8 | 8 | error OperatorNotAllowed(address operator); |
9 | 9 |
|
10 | | - IOperatorFilterRegistry constant OPERATOR_FILTERER_REGISTRY = |
| 10 | + // solhint-disable-next-line |
| 11 | + IOperatorFilterRegistry constant operatorFilterRegistry = |
11 | 12 | IOperatorFilterRegistry(0x000000000000AAeB6D7670E522A718067333cd4E); |
12 | 13 |
|
13 | 14 | constructor(address subscriptionOrRegistrantToCopy, bool subscribe) { |
14 | 15 | // If an inheriting token contract is deployed to a network without the registry deployed, the modifier |
15 | 16 | // will not revert, but the contract will need to be registered with the registry once it is deployed in |
16 | 17 | // order for the modifier to filter addresses. |
17 | | - if (address(OPERATOR_FILTERER_REGISTRY).code.length > 0) { |
| 18 | + if (address(operatorFilterRegistry).code.length > 0) { |
18 | 19 | if (subscribe) { |
19 | | - OPERATOR_FILTERER_REGISTRY.registerAndSubscribe(address(this), subscriptionOrRegistrantToCopy); |
| 20 | + operatorFilterRegistry.registerAndSubscribe(address(this), subscriptionOrRegistrantToCopy); |
20 | 21 | } else { |
21 | 22 | if (subscriptionOrRegistrantToCopy != address(0)) { |
22 | | - OPERATOR_FILTERER_REGISTRY.registerAndCopyEntries(address(this), subscriptionOrRegistrantToCopy); |
| 23 | + operatorFilterRegistry.registerAndCopyEntries(address(this), subscriptionOrRegistrantToCopy); |
23 | 24 | } else { |
24 | | - OPERATOR_FILTERER_REGISTRY.register(address(this)); |
| 25 | + operatorFilterRegistry.register(address(this)); |
25 | 26 | } |
26 | 27 | } |
27 | 28 | } |
28 | 29 | } |
29 | 30 |
|
30 | | - modifier onlyAllowedOperator() virtual { |
| 31 | + modifier onlyAllowedOperator(address from) virtual { |
31 | 32 | // Check registry code length to facilitate testing in environments without a deployed registry. |
32 | | - if (address(OPERATOR_FILTERER_REGISTRY).code.length > 0) { |
33 | | - if (!OPERATOR_FILTERER_REGISTRY.isOperatorAllowed(address(this), msg.sender)) { |
| 33 | + if (address(operatorFilterRegistry).code.length > 0) { |
| 34 | + // Allow spending tokens from addresses with balance |
| 35 | + // Note that this still allows listings and marketplaces with escrow to transfer tokens if transferred |
| 36 | + // from an EOA. |
| 37 | + if (from == msg.sender) { |
| 38 | + _; |
| 39 | + return; |
| 40 | + } |
| 41 | + if ( |
| 42 | + !(operatorFilterRegistry.isOperatorAllowed(address(this), msg.sender) && |
| 43 | + operatorFilterRegistry.isOperatorAllowed(address(this), from)) |
| 44 | + ) { |
34 | 45 | revert OperatorNotAllowed(msg.sender); |
35 | 46 | } |
36 | 47 | } |
|
0 commit comments