Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions contracts/extension/DefaultOperatorFilterer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ abstract contract DefaultOperatorFilterer is OperatorFilterer {
address constant DEFAULT_SUBSCRIPTION = address(0x3cc6CddA760b79bAfa08dF41ECFA224f810dCeB6);

constructor() OperatorFilterer(DEFAULT_SUBSCRIPTION, true) {}

function subscribeToRegistry(address _subscription) external {
require(_canSetOperatorRestriction(), "Not authorized to subscribe to registry.");
_register(_subscription, true);
}
}
5 changes: 5 additions & 0 deletions contracts/extension/DefaultOperatorFiltererUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ abstract contract DefaultOperatorFiltererUpgradeable is OperatorFiltererUpgradea
function __DefaultOperatorFilterer_init() internal {
OperatorFiltererUpgradeable.__OperatorFilterer_init(DEFAULT_SUBSCRIPTION, true);
}

function subscribeToRegistry(address _subscription) external {
require(_canSetOperatorRestriction(), "Not authorized to subscribe to registry.");
_register(_subscription, true);
}
}
29 changes: 18 additions & 11 deletions contracts/extension/OperatorFilterer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,7 @@ abstract contract OperatorFilterer is OperatorFilterToggle {
// If an inheriting token contract is deployed to a network without the registry deployed, the modifier
// will not revert, but the contract will need to be registered with the registry once it is deployed in
// order for the modifier to filter addresses.
if (address(OPERATOR_FILTER_REGISTRY).code.length > 0) {
if (subscribe) {
OPERATOR_FILTER_REGISTRY.registerAndSubscribe(address(this), subscriptionOrRegistrantToCopy);
} else {
if (subscriptionOrRegistrantToCopy != address(0)) {
OPERATOR_FILTER_REGISTRY.registerAndCopyEntries(address(this), subscriptionOrRegistrantToCopy);
} else {
OPERATOR_FILTER_REGISTRY.register(address(this));
}
}
}
_register(subscriptionOrRegistrantToCopy, subscribe);
}

modifier onlyAllowedOperator(address from) virtual {
Expand Down Expand Up @@ -63,4 +53,21 @@ abstract contract OperatorFilterer is OperatorFilterToggle {
}
}
}

function _register(address subscriptionOrRegistrantToCopy, bool subscribe) internal {
// Is the registry deployed?
if (address(OPERATOR_FILTER_REGISTRY).code.length > 0) {
// Is the subscription contract deployed?
if (address(subscriptionOrRegistrantToCopy).code.length > 0) {
// Do we want to subscribe?
if (subscribe) {
OPERATOR_FILTER_REGISTRY.registerAndSubscribe(address(this), subscriptionOrRegistrantToCopy);
} else {
OPERATOR_FILTER_REGISTRY.registerAndCopyEntries(address(this), subscriptionOrRegistrantToCopy);
}
} else {
OPERATOR_FILTER_REGISTRY.register(address(this));
}
}
}
}
31 changes: 18 additions & 13 deletions contracts/extension/OperatorFiltererUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,7 @@ abstract contract OperatorFiltererUpgradeable is OperatorFilterToggle {
// If an inheriting token contract is deployed to a network without the registry deployed, the modifier
// will not revert, but the contract will need to be registered with the registry once it is deployed in
// order for the modifier to filter addresses.
if (address(OPERATOR_FILTER_REGISTRY).code.length > 0) {
if (!OPERATOR_FILTER_REGISTRY.isRegistered(address(this))) {
if (subscribe) {
OPERATOR_FILTER_REGISTRY.registerAndSubscribe(address(this), subscriptionOrRegistrantToCopy);
} else {
if (subscriptionOrRegistrantToCopy != address(0)) {
OPERATOR_FILTER_REGISTRY.registerAndCopyEntries(address(this), subscriptionOrRegistrantToCopy);
} else {
OPERATOR_FILTER_REGISTRY.register(address(this));
}
}
}
}
_register(subscriptionOrRegistrantToCopy, subscribe);
}

modifier onlyAllowedOperator(address from) virtual {
Expand Down Expand Up @@ -61,4 +49,21 @@ abstract contract OperatorFiltererUpgradeable is OperatorFilterToggle {
}
_;
}

function _register(address subscriptionOrRegistrantToCopy, bool subscribe) internal {
// Is the registry deployed?
if (address(OPERATOR_FILTER_REGISTRY).code.length > 0) {
// Is the subscription contract deployed?
if (address(subscriptionOrRegistrantToCopy).code.length > 0) {
// Do we want to subscribe?
if (subscribe) {
OPERATOR_FILTER_REGISTRY.registerAndSubscribe(address(this), subscriptionOrRegistrantToCopy);
} else {
OPERATOR_FILTER_REGISTRY.registerAndCopyEntries(address(this), subscriptionOrRegistrantToCopy);
}
} else {
OPERATOR_FILTER_REGISTRY.register(address(this));
}
}
}
}
1 change: 1 addition & 0 deletions contracts/token/TokenERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ contract TokenERC1155 is
__EIP712_init("TokenERC1155", "1");
__ERC2771Context_init(_trustedForwarders);
__ERC1155_init("");
__DefaultOperatorFilterer_init();

// Initialize this contract's state.
_setOperatorRestriction(true);
Expand Down
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ gas_reports = ["Multiwrap", "SignatureDrop"]
libraries = []
libs = ['lib']
optimizer = true
optimizer_runs = 300
optimizer_runs = 200
out = 'artifacts_forge'
remappings = [
#' @chainlink=node_modules/@chainlink/contracts/src/',
Expand Down