Skip to content
Verified contractPartialMIT

OptimisticSelectorRegistry

Address0x9b1750b22de9ca882f15cd89cddf6f5909593692
Balance

0 ETH

 

Transactions

0

 

Compiler

solc 0.8.33

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.33+commit.64118f21
Language
solidity
Optimization
Yes, 149 runs
EVM version
cancun
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,245,937
Creation transaction
0x8e80b94cd5…39f12ef9c4

68 files

The source code is large: one file is shown at a time. Choose a file in the list.

contracts/governance/OptimisticSelectorRegistry.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

import { IOptimisticSelectorRegistry } from "@interfaces/IOptimisticSelectorRegistry.sol";

import { ReserveOptimisticGovernor } from "@governance/ReserveOptimisticGovernor.sol";

contract OptimisticSelectorRegistry is Initializable, IOptimisticSelectorRegistry {
    using EnumerableSet for EnumerableSet.AddressSet;
    using EnumerableSet for EnumerableSet.Bytes32Set;

    // === State ===

    ReserveOptimisticGovernor public governor;

    EnumerableSet.AddressSet private _targets;
    mapping(address target => EnumerableSet.Bytes32Set) private _allowedSelectors;

    // === Initialization ===

    constructor() {
        _disableInitializers();
    }

    function initialize(address _governor, SelectorData[] memory selectorData) public initializer {
        governor = ReserveOptimisticGovernor(payable(_governor));

        // validate governor
        governor.timelock();
        governor.token();

        for (uint256 i = 0; i < selectorData.length; i++) {
            _add(selectorData[i].target, selectorData[i].selectors);
        }
    }

    // === External ===

    modifier onlyTimelock() {
        require(msg.sender == governor.timelock(), SelectorRegistry__OnlyOwner(msg.sender));
        _;
    }

    function registerSelectors(SelectorData[] calldata selectorData) external onlyTimelock {
        for (uint256 i = 0; i < selectorData.length; i++) {
            _add(selectorData[i].target, selectorData[i].selectors);
        }
    }

    /// @dev Warning: Does NOT cancel existing optimistic proposals using these selectors
    ///      CANCELLER_ROLE must cancel existing optimistic proposals if execution should be prevented
    function unregisterSelectors(SelectorData[] calldata selectorData) external onlyTimelock {
        for (uint256 i = 0; i < selectorData.length; i++) {
            _remove(selectorData[i].target, selectorData[i].selectors);
        }
    }

    // === View ===

    function targets() external view returns (address[] memory) {
        return _targets.values();
    }

    function isAllowed(address target, bytes4 selector) external view returns (bool) {
        return _allowedSelectors[target].contains(bytes32(selector));
    }

    function selectorsAllowed(address target) external view returns (bytes4[] memory allowedSelectors4) {
        bytes32[] memory allowedSelectors = _allowedSelectors[target].values();

        allowedSelectors4 = new bytes4[](allowedSelectors.length);

        for (uint256 i = 0; i < allowedSelectors.length; i++) {
            allowedSelectors4[i] = bytes4(allowedSelectors[i]);
        }
    }

    // === Internal ===

    function _add(address target, bytes4[] memory selectors) internal {
        // target != self, governor, timelock, token
        require(
            target != address(this) && target != address(governor) && target != address(governor.timelock())
                && target != address(governor.token()),
            SelectorRegistry__InvalidTarget(target)
        );

        for (uint256 i = 0; i < selectors.length; i++) {
            // no empty selectors
            require(selectors[i] != bytes4(0), SelectorRegistry__InvalidSelector(selectors[i]));

            bool added = _allowedSelectors[target].add(bytes32(selectors[i]));

            if (added) {
                _targets.add(target);

                emit SelectorAdded(target, selectors[i]);
            }
        }
    }

    function _remove(address target, bytes4[] memory selectors) internal {
        for (uint256 i = 0; i < selectors.length; i++) {
            bool removed = _allowedSelectors[target].remove(bytes32(selectors[i]));

            if (removed) {
                if (_allowedSelectors[target].length() == 0) {
                    _targets.remove(target);
                }

                emit SelectorRemoved(target, selectors[i]);
            }
        }
    }
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "none",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 149,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "forge-std/=node_modules/forge-std/src/",
    "@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/",
    "@openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable/",
    "@prb/math/=node_modules/@prb/math/",
    "@reserve-protocol/trusted-fillers/=node_modules/@reserve-protocol/trusted-fillers/",
    "node_modules/@reserve-protocol/trusted-fillers/:@interfaces/=node_modules/@reserve-protocol/trusted-fillers/contracts/interfaces/",
    "@src/=contracts/",
    "@governance/=contracts/governance/",
    "@interfaces/=contracts/interfaces/",
    "@staking/=contracts/staking/",
    "@utils/=contracts/utils/",
    "@mocks/=test/mocks/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.