Skip to content

Commit f7104e6

Browse files
committed
updated immutable modules to use the forked version
1 parent 2b005bb commit f7104e6

3 files changed

Lines changed: 56 additions & 113 deletions

File tree

dependecies/immutable/allowlist/OperatorAllowlistEnforced.sol

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@ import {IOperatorAllowlist} from "./IOperatorAllowlist.sol";
99
// Errors
1010
import {OperatorAllowlistEnforcementErrors} from "../errors/Errors.sol";
1111

12+
library OperatorAllowlistEnforcedStorage {
13+
14+
/// @custom:storage-location erc7201:operator.allowlist.enforced
15+
bytes32 public constant OPERATOR_ALLOWLIST_ENFORCED_STORAGE_POSITION =
16+
keccak256(abi.encode(uint256(keccak256("operator.allowlist.enforced")) - 1)) & ~bytes32(uint256(0xff));
17+
18+
struct Data {
19+
address operatorAllowlist;
20+
}
21+
22+
function data() internal pure returns (Data storage data_) {
23+
bytes32 position = OPERATOR_ALLOWLIST_ENFORCED_STORAGE_POSITION;
24+
assembly {
25+
data_.slot := position
26+
}
27+
}
28+
29+
}
30+
1231
interface IERC165 {
1332

1433
function supportsInterface(bytes4 interfaceId) external view returns (bool);
@@ -36,17 +55,19 @@ abstract contract OperatorAllowlistEnforced is OperatorAllowlistEnforcementError
3655
* @param targetApproval the address of the approval target to be validated
3756
*/
3857
modifier validateApproval(address targetApproval) {
58+
IOperatorAllowlist _operatorAllowlist = IOperatorAllowlist(_operatorAllowlistStorage().operatorAllowlist);
59+
3960
// Check for:
4061
// 1. approver is an EOA. Contract constructor is handled as transfers 'from' are blocked
4162
// 2. approver is address or bytecode is allowlisted
42-
if (msg.sender.code.length != 0 && !operatorAllowlist.isAllowlisted(msg.sender)) {
63+
if (msg.sender.code.length != 0 && !_operatorAllowlist.isAllowlisted(msg.sender)) {
4364
revert ApproverNotInAllowlist(msg.sender);
4465
}
4566

4667
// Check for:
4768
// 1. approval target is an EOA
4869
// 2. approval target address is Allowlisted or target address bytecode is Allowlisted
49-
if (targetApproval.code.length != 0 && !operatorAllowlist.isAllowlisted(targetApproval)) {
70+
if (targetApproval.code.length != 0 && !_operatorAllowlist.isAllowlisted(targetApproval)) {
5071
revert ApproveTargetNotInAllowlist(targetApproval);
5172
}
5273
_;
@@ -59,27 +80,29 @@ abstract contract OperatorAllowlistEnforced is OperatorAllowlistEnforcementError
5980
* @param to the address of the to target to be validated
6081
*/
6182
modifier validateTransfer(address from, address to) {
83+
IOperatorAllowlist _operatorAllowlist = IOperatorAllowlist(_operatorAllowlistStorage().operatorAllowlist);
84+
6285
// Check for:
6386
// 1. caller is an EOA
6487
// 2. caller is Allowlisted or is the calling address bytecode is Allowlisted
6588
if (
6689
msg.sender != tx.origin // solhint-disable-line avoid-tx-origin
67-
&& !operatorAllowlist.isAllowlisted(msg.sender)
90+
&& !_operatorAllowlist.isAllowlisted(msg.sender)
6891
) {
6992
revert CallerNotInAllowlist(msg.sender);
7093
}
7194

7295
// Check for:
7396
// 1. from is an EOA
7497
// 2. from is Allowlisted or from address bytecode is Allowlisted
75-
if (from.code.length != 0 && !operatorAllowlist.isAllowlisted(from)) {
98+
if (from.code.length != 0 && !_operatorAllowlist.isAllowlisted(from)) {
7699
revert TransferFromNotInAllowlist(from);
77100
}
78101

79102
// Check for:
80103
// 1. to is an EOA
81104
// 2. to is Allowlisted or to address bytecode is Allowlisted
82-
if (to.code.length != 0 && !operatorAllowlist.isAllowlisted(to)) {
105+
if (to.code.length != 0 && !_operatorAllowlist.isAllowlisted(to)) {
83106
revert TransferToNotInAllowlist(to);
84107
}
85108
_;
@@ -96,8 +119,17 @@ abstract contract OperatorAllowlistEnforced is OperatorAllowlistEnforcementError
96119
revert AllowlistDoesNotImplementIOperatorAllowlist();
97120
}
98121

99-
emit OperatorAllowlistRegistryUpdated(address(operatorAllowlist), _operatorAllowlist);
100-
operatorAllowlist = IOperatorAllowlist(_operatorAllowlist);
122+
emit OperatorAllowlistRegistryUpdated(_operatorAllowlistStorage().operatorAllowlist, _operatorAllowlist);
123+
_operatorAllowlistStorage().operatorAllowlist = _operatorAllowlist;
124+
}
125+
126+
/// @notice Get the current operator allowlist registry address
127+
function operatorAllowlist() external view returns (address) {
128+
return _operatorAllowlistStorage().operatorAllowlist;
129+
}
130+
131+
function _operatorAllowlistStorage() internal pure returns (OperatorAllowlistEnforcedStorage.Data storage) {
132+
return OperatorAllowlistEnforcedStorage.data();
101133
}
102134

103135
}

src/module/token/immutable/ImmutableAllowlistERC1155.sol

Lines changed: 10 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,13 @@ pragma solidity ^0.8.20;
44
import {Module} from "../../../Module.sol";
55
import {Role} from "../../../Role.sol";
66

7+
import {
8+
OperatorAllowlistEnforced,
9+
OperatorAllowlistEnforcedStorage
10+
} from "../../../../dependecies/immutable/allowlist/OperatorAllowlistEnforced.sol";
711
import {BeforeApproveForAllCallback} from "../../../callback/BeforeApproveForAllCallback.sol";
8-
912
import {BeforeBatchTransferCallbackERC1155} from "../../../callback/BeforeBatchTransferCallbackERC1155.sol";
1013
import {BeforeTransferCallbackERC1155} from "../../../callback/BeforeTransferCallbackERC1155.sol";
11-
import {OperatorAllowlistEnforced} from "@imtbl/contracts/allowlist/OperatorAllowlistEnforced.sol";
12-
13-
library ImmutableAllowlistStorage {
14-
15-
/// @custom:storage-location erc7201:token.immutableallowlist
16-
bytes32 public constant IMMUTABLE_ALLOWLIST_STORAGE_POSITION =
17-
keccak256(abi.encode(uint256(keccak256("token.immutableAllowlist.ERC1155")) - 1)) & ~bytes32(uint256(0xff));
18-
19-
struct Data {
20-
address operatorAllowlistRegistry;
21-
}
22-
23-
function data() internal pure returns (Data storage data_) {
24-
bytes32 position = IMMUTABLE_ALLOWLIST_STORAGE_POSITION;
25-
assembly {
26-
data_.slot := position
27-
}
28-
}
29-
30-
}
3114

3215
contract ImmutableAllowlistERC1155 is
3316
Module,
@@ -59,32 +42,20 @@ contract ImmutableAllowlistERC1155 is
5942
config.callbackFunctions = new CallbackFunction[](3);
6043
config.fallbackFunctions = new FallbackFunction[](2);
6144

62-
config.callbackFunctions[1] = CallbackFunction(this.beforeApproveForAll.selector);
63-
config.callbackFunctions[2] = CallbackFunction(this.beforeTransferERC1155.selector);
64-
config.callbackFunctions[3] = CallbackFunction(this.beforeBatchTransferERC1155.selector);
45+
config.callbackFunctions[0] = CallbackFunction(this.beforeApproveForAll.selector);
46+
config.callbackFunctions[1] = CallbackFunction(this.beforeTransferERC1155.selector);
47+
config.callbackFunctions[2] = CallbackFunction(this.beforeBatchTransferERC1155.selector);
6548

6649
config.fallbackFunctions[0] =
6750
FallbackFunction({selector: this.setOperatorAllowlistRegistry.selector, permissionBits: Role._MANAGER_ROLE});
68-
config.fallbackFunctions[1] =
69-
FallbackFunction({selector: this.getOperatorAllowlistRegistry.selector, permissionBits: 0});
51+
config.fallbackFunctions[1] = FallbackFunction({selector: this.operatorAllowlist.selector, permissionBits: 0});
7052

7153
config.requiredInterfaces = new bytes4[](1);
7254
config.requiredInterfaces[0] = 0x80ac58cd; // ERC1155
7355

7456
config.registerInstallationCallback = true;
7557
}
7658

77-
/*//////////////////////////////////////////////////////////////
78-
MODIFIERS
79-
//////////////////////////////////////////////////////////////*/
80-
81-
modifier isOperatorAllowlistSet() {
82-
if (_immutableAllowlistStorage().operatorAllowlistRegistry == address(0)) {
83-
revert OperatorAllowlistNotSet();
84-
}
85-
_;
86-
}
87-
8859
/*//////////////////////////////////////////////////////////////
8960
CALLBACK FUNCTIONS
9061
//////////////////////////////////////////////////////////////*/
@@ -93,7 +64,6 @@ contract ImmutableAllowlistERC1155 is
9364
function beforeApproveForAll(address _from, address _to, bool _approved)
9465
external
9566
override
96-
isOperatorAllowlistSet
9767
validateApproval(_to)
9868
returns (bytes memory)
9969
{}
@@ -102,7 +72,6 @@ contract ImmutableAllowlistERC1155 is
10272
function beforeTransferERC1155(address _from, address _to, uint256 _id, uint256 _value)
10373
external
10474
override
105-
isOperatorAllowlistSet
10675
validateTransfer(_from, _to)
10776
returns (bytes memory)
10877
{}
@@ -111,15 +80,14 @@ contract ImmutableAllowlistERC1155 is
11180
function beforeBatchTransferERC1155(address _from, address _to, uint256[] calldata _ids, uint256[] calldata _values)
11281
external
11382
override
114-
isOperatorAllowlistSet
11583
validateTransfer(_from, _to)
11684
returns (bytes memory)
11785
{}
11886

11987
/// @dev Called by a Core into an Module during the installation of the Module.
12088
function onInstall(bytes calldata data) external {
12189
address registry = abi.decode(data, (address));
122-
_immutableAllowlistStorage().operatorAllowlistRegistry = registry;
90+
_setOperatorAllowlistRegistry(registry);
12391
}
12492

12593
/// @dev Called by a Core into an Module during the uninstallation of the Module.
@@ -145,20 +113,7 @@ contract ImmutableAllowlistERC1155 is
145113

146114
/// @notice Set the operator allowlist registry address
147115
function setOperatorAllowlistRegistry(address newRegistry) external {
148-
_immutableAllowlistStorage().operatorAllowlistRegistry = newRegistry;
149-
}
150-
151-
/// @notice Get the current operator allowlist registry address
152-
function getOperatorAllowlistRegistry() external view returns (address) {
153-
return _immutableAllowlistStorage().operatorAllowlistRegistry;
154-
}
155-
156-
/*//////////////////////////////////////////////////////////////
157-
INTERNAL FUNCTIONS
158-
//////////////////////////////////////////////////////////////*/
159-
160-
function _immutableAllowlistStorage() internal pure returns (ImmutableAllowlistStorage.Data storage) {
161-
return ImmutableAllowlistStorage.data();
116+
_setOperatorAllowlistRegistry(newRegistry);
162117
}
163118

164119
}

src/module/token/immutable/ImmutableAllowlistERC721.sol

Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,13 @@ pragma solidity ^0.8.20;
44
import {Module} from "../../../Module.sol";
55
import {Role} from "../../../Role.sol";
66

7+
import {
8+
OperatorAllowlistEnforced,
9+
OperatorAllowlistEnforcedStorage
10+
} from "../../../../dependecies/immutable/allowlist/OperatorAllowlistEnforced.sol";
711
import {BeforeApproveCallbackERC721} from "../../../callback/BeforeApproveCallbackERC721.sol";
812
import {BeforeApproveForAllCallback} from "../../../callback/BeforeApproveForAllCallback.sol";
913
import {BeforeTransferCallbackERC721} from "../../../callback/BeforeTransferCallbackERC721.sol";
10-
import {OperatorAllowlistEnforced} from "@imtbl/contracts/allowlist/OperatorAllowlistEnforced.sol";
11-
12-
library ImmutableAllowlistStorage {
13-
14-
/// @custom:storage-location erc7201:token.immutableallowlist
15-
bytes32 public constant IMMUTABLE_ALLOWLIST_STORAGE_POSITION =
16-
keccak256(abi.encode(uint256(keccak256("token.immutableAllowlist.ERC721")) - 1)) & ~bytes32(uint256(0xff));
17-
18-
struct Data {
19-
address operatorAllowlistRegistry;
20-
}
21-
22-
function data() internal pure returns (Data storage data_) {
23-
bytes32 position = IMMUTABLE_ALLOWLIST_STORAGE_POSITION;
24-
assembly {
25-
data_.slot := position
26-
}
27-
}
28-
29-
}
3014

3115
contract ImmutableAllowlistERC721 is
3216
Module,
@@ -64,26 +48,14 @@ contract ImmutableAllowlistERC721 is
6448

6549
config.fallbackFunctions[0] =
6650
FallbackFunction({selector: this.setOperatorAllowlistRegistry.selector, permissionBits: Role._MANAGER_ROLE});
67-
config.fallbackFunctions[1] =
68-
FallbackFunction({selector: this.getOperatorAllowlistRegistry.selector, permissionBits: 0});
51+
config.fallbackFunctions[1] = FallbackFunction({selector: this.operatorAllowlist.selector, permissionBits: 0});
6952

7053
config.requiredInterfaces = new bytes4[](1);
7154
config.requiredInterfaces[0] = 0x80ac58cd; // ERC721
7255

7356
config.registerInstallationCallback = true;
7457
}
7558

76-
/*//////////////////////////////////////////////////////////////
77-
MODIFIERS
78-
//////////////////////////////////////////////////////////////*/
79-
80-
modifier isOperatorAllowlistSet() {
81-
if (_immutableAllowlistStorage().operatorAllowlistRegistry == address(0)) {
82-
revert OperatorAllowlistNotSet();
83-
}
84-
_;
85-
}
86-
8759
/*//////////////////////////////////////////////////////////////
8860
CALLBACK FUNCTIONS
8961
//////////////////////////////////////////////////////////////*/
@@ -92,7 +64,6 @@ contract ImmutableAllowlistERC721 is
9264
function beforeApproveERC721(address _from, address _to, uint256 _tokenId, bool _approve)
9365
external
9466
override
95-
isOperatorAllowlistSet
9667
validateApproval(_to)
9768
returns (bytes memory)
9869
{}
@@ -101,7 +72,6 @@ contract ImmutableAllowlistERC721 is
10172
function beforeApproveForAll(address _from, address _to, bool _approved)
10273
external
10374
override
104-
isOperatorAllowlistSet
10575
validateApproval(_to)
10676
returns (bytes memory)
10777
{}
@@ -110,15 +80,14 @@ contract ImmutableAllowlistERC721 is
11080
function beforeTransferERC721(address _from, address _to, uint256 _tokenId)
11181
external
11282
override
113-
isOperatorAllowlistSet
11483
validateTransfer(_from, _to)
11584
returns (bytes memory)
11685
{}
11786

11887
/// @dev Called by a Core into an Module during the installation of the Module.
11988
function onInstall(bytes calldata data) external {
12089
address registry = abi.decode(data, (address));
121-
_immutableAllowlistStorage().operatorAllowlistRegistry = registry;
90+
_setOperatorAllowlistRegistry(registry);
12291
}
12392

12493
/// @dev Called by a Core into an Module during the uninstallation of the Module.
@@ -144,20 +113,7 @@ contract ImmutableAllowlistERC721 is
144113

145114
/// @notice Set the operator allowlist registry address
146115
function setOperatorAllowlistRegistry(address newRegistry) external {
147-
_immutableAllowlistStorage().operatorAllowlistRegistry = newRegistry;
148-
}
149-
150-
/// @notice Get the current operator allowlist registry address
151-
function getOperatorAllowlistRegistry() external view returns (address) {
152-
return _immutableAllowlistStorage().operatorAllowlistRegistry;
153-
}
154-
155-
/*//////////////////////////////////////////////////////////////
156-
INTERNAL FUNCTIONS
157-
//////////////////////////////////////////////////////////////*/
158-
159-
function _immutableAllowlistStorage() internal pure returns (ImmutableAllowlistStorage.Data storage) {
160-
return ImmutableAllowlistStorage.data();
116+
_setOperatorAllowlistRegistry(newRegistry);
161117
}
162118

163119
}

0 commit comments

Comments
 (0)