Skip to content

Commit 3ab2205

Browse files
Fix OSRF initialization when subscription contract is not deployed + apply OSRF to Edition contract (#375)
* Fix OSRF initialization when subscription contract is not deployed + apply OSRF to Edition contract * Update OSF subscription flow --------- Co-authored-by: Krishang <[email protected]>
1 parent bd8b010 commit 3ab2205

File tree

6 files changed

+48
-25
lines changed

6 files changed

+48
-25
lines changed

contracts/extension/DefaultOperatorFilterer.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ abstract contract DefaultOperatorFilterer is OperatorFilterer {
1313
address constant DEFAULT_SUBSCRIPTION = address(0x3cc6CddA760b79bAfa08dF41ECFA224f810dCeB6);
1414

1515
constructor() OperatorFilterer(DEFAULT_SUBSCRIPTION, true) {}
16+
17+
function subscribeToRegistry(address _subscription) external {
18+
require(_canSetOperatorRestriction(), "Not authorized to subscribe to registry.");
19+
_register(_subscription, true);
20+
}
1621
}

contracts/extension/DefaultOperatorFiltererUpgradeable.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ abstract contract DefaultOperatorFiltererUpgradeable is OperatorFiltererUpgradea
1111
function __DefaultOperatorFilterer_init() internal {
1212
OperatorFiltererUpgradeable.__OperatorFilterer_init(DEFAULT_SUBSCRIPTION, true);
1313
}
14+
15+
function subscribeToRegistry(address _subscription) external {
16+
require(_canSetOperatorRestriction(), "Not authorized to subscribe to registry.");
17+
_register(_subscription, true);
18+
}
1419
}

contracts/extension/OperatorFilterer.sol

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,7 @@ abstract contract OperatorFilterer is OperatorFilterToggle {
2525
// If an inheriting token contract is deployed to a network without the registry deployed, the modifier
2626
// will not revert, but the contract will need to be registered with the registry once it is deployed in
2727
// order for the modifier to filter addresses.
28-
if (address(OPERATOR_FILTER_REGISTRY).code.length > 0) {
29-
if (subscribe) {
30-
OPERATOR_FILTER_REGISTRY.registerAndSubscribe(address(this), subscriptionOrRegistrantToCopy);
31-
} else {
32-
if (subscriptionOrRegistrantToCopy != address(0)) {
33-
OPERATOR_FILTER_REGISTRY.registerAndCopyEntries(address(this), subscriptionOrRegistrantToCopy);
34-
} else {
35-
OPERATOR_FILTER_REGISTRY.register(address(this));
36-
}
37-
}
38-
}
28+
_register(subscriptionOrRegistrantToCopy, subscribe);
3929
}
4030

4131
modifier onlyAllowedOperator(address from) virtual {
@@ -63,4 +53,21 @@ abstract contract OperatorFilterer is OperatorFilterToggle {
6353
}
6454
}
6555
}
56+
57+
function _register(address subscriptionOrRegistrantToCopy, bool subscribe) internal {
58+
// Is the registry deployed?
59+
if (address(OPERATOR_FILTER_REGISTRY).code.length > 0) {
60+
// Is the subscription contract deployed?
61+
if (address(subscriptionOrRegistrantToCopy).code.length > 0) {
62+
// Do we want to subscribe?
63+
if (subscribe) {
64+
OPERATOR_FILTER_REGISTRY.registerAndSubscribe(address(this), subscriptionOrRegistrantToCopy);
65+
} else {
66+
OPERATOR_FILTER_REGISTRY.registerAndCopyEntries(address(this), subscriptionOrRegistrantToCopy);
67+
}
68+
} else {
69+
OPERATOR_FILTER_REGISTRY.register(address(this));
70+
}
71+
}
72+
}
6673
}

contracts/extension/OperatorFiltererUpgradeable.sol

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,7 @@ abstract contract OperatorFiltererUpgradeable is OperatorFilterToggle {
1616
// If an inheriting token contract is deployed to a network without the registry deployed, the modifier
1717
// will not revert, but the contract will need to be registered with the registry once it is deployed in
1818
// order for the modifier to filter addresses.
19-
if (address(OPERATOR_FILTER_REGISTRY).code.length > 0) {
20-
if (!OPERATOR_FILTER_REGISTRY.isRegistered(address(this))) {
21-
if (subscribe) {
22-
OPERATOR_FILTER_REGISTRY.registerAndSubscribe(address(this), subscriptionOrRegistrantToCopy);
23-
} else {
24-
if (subscriptionOrRegistrantToCopy != address(0)) {
25-
OPERATOR_FILTER_REGISTRY.registerAndCopyEntries(address(this), subscriptionOrRegistrantToCopy);
26-
} else {
27-
OPERATOR_FILTER_REGISTRY.register(address(this));
28-
}
29-
}
30-
}
31-
}
19+
_register(subscriptionOrRegistrantToCopy, subscribe);
3220
}
3321

3422
modifier onlyAllowedOperator(address from) virtual {
@@ -61,4 +49,21 @@ abstract contract OperatorFiltererUpgradeable is OperatorFilterToggle {
6149
}
6250
_;
6351
}
52+
53+
function _register(address subscriptionOrRegistrantToCopy, bool subscribe) internal {
54+
// Is the registry deployed?
55+
if (address(OPERATOR_FILTER_REGISTRY).code.length > 0) {
56+
// Is the subscription contract deployed?
57+
if (address(subscriptionOrRegistrantToCopy).code.length > 0) {
58+
// Do we want to subscribe?
59+
if (subscribe) {
60+
OPERATOR_FILTER_REGISTRY.registerAndSubscribe(address(this), subscriptionOrRegistrantToCopy);
61+
} else {
62+
OPERATOR_FILTER_REGISTRY.registerAndCopyEntries(address(this), subscriptionOrRegistrantToCopy);
63+
}
64+
} else {
65+
OPERATOR_FILTER_REGISTRY.register(address(this));
66+
}
67+
}
68+
}
6469
}

contracts/token/TokenERC1155.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ contract TokenERC1155 is
162162
__EIP712_init("TokenERC1155", "1");
163163
__ERC2771Context_init(_trustedForwarders);
164164
__ERC1155_init("");
165+
__DefaultOperatorFilterer_init();
165166

166167
// Initialize this contract's state.
167168
_setOperatorRestriction(true);

foundry.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ gas_reports = ["Multiwrap", "SignatureDrop"]
88
libraries = []
99
libs = ['lib']
1010
optimizer = true
11-
optimizer_runs = 300
11+
optimizer_runs = 200
1212
out = 'artifacts_forge'
1313
remappings = [
1414
#' @chainlink=node_modules/@chainlink/contracts/src/',

0 commit comments

Comments
 (0)