TokenRegistryUpgradeable

Description:

Proxy contract enabling upgradeable smart contract patterns. Delegates calls to an implementation contract.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "TokenRegistryUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "./AccessControlUpgradeable.sol";

contract TokenRegistryUpgradeable is
    Initializable,
    ReentrancyGuardUpgradeable,
    UUPSUpgradeable,
    LaxceAccessControlUpgradeable
{

    uint256 public constant MAX_TOKENS = 10000;
    uint256 public constant MAX_NAME_LENGTH = 50;
    uint256 public constant MAX_SYMBOL_LENGTH = 10;
    uint256 public constant MIN_DECIMALS = 6;
    uint256 public constant MAX_DECIMALS = 18;

    enum TokenStatus {
        PENDING,
        APPROVED,
        SUSPENDED,
        BLACKLISTED
    }

    enum TokenType {
        STANDARD,
        LP_TOKEN,
        WRAPPED,
        STABLECOIN,
        GOVERNANCE
    }

    struct TokenInfo {
        address tokenAddress;
        string name;
        string symbol;
        uint8 decimals;
        TokenType tokenType;
        TokenStatus status;
        uint256 registeredAt;
        uint256 lastUpdate;
        address registrar;
        bool isActive;
        uint256 tradingVolume24h;
        uint256 totalTradingVolume;
    }

    struct TokenMetadata {
        string description;
        string website;
        string logoUrl;
        string[] socialLinks;
        bytes32[] tags;
    }

    struct TokenFees {
        uint256 registrationFee;
        uint256 listingFee;
        uint256 tradingFee;
        bool feeDiscountEligible;
    }

    struct TokenLimits {
        uint256 maxSupply;
        uint256 minLiquidity;
        uint256 maxPriceImpact;
        bool hasLimits;
    }

    mapping(address => TokenInfo) public tokenInfo;

    mapping(address => TokenMetadata) public tokenMetadata;

    mapping(address => TokenFees) public tokenFees;

    mapping(address => TokenLimits) public tokenLimits;

    address[] public allTokens;

    mapping(TokenStatus => address[]) public tokensByStatus;

    mapping(TokenType => address[]) public tokensByType;

    mapping(string => address) public symbolToAddress;

    struct RegistrySettings {
        uint256 defaultRegistrationFee;
        uint256 defaultListingFee;
        uint256 defaultTradingFee;
        bool autoApproval;
        bool requireMetadata;
        uint256 minRegistrationDelay;
    }

    RegistrySettings public registrySettings;

    mapping(address => bool) public whitelist;
    mapping(address => bool) public blacklist;

    struct RegistryStats {
        uint256 totalTokens;
        uint256 activeTokens;
        uint256 pendingTokens;
        uint256 totalVolume;
        uint256 totalFees;
    }

    RegistryStats public registryStats;

    event TokenRegistered(
        address indexed tokenAddress,
        string name,
        string symbol,
        TokenType tokenType,
        address indexed registrar
    );

    event TokenStatusChanged(
        address indexed tokenAddress,
        TokenStatus oldStatus,
        TokenStatus newStatus,
        address indexed updater
    );

    event TokenMetadataUpdated(
        address indexed tokenAddress,
        address indexed updater
    );

    event TokenFeesUpdated(
        address indexed tokenAddress,
        TokenFees fees
    );

    event TokenLimitsUpdated(
        address indexed tokenAddress,
        TokenLimits limits
    );

    event TokenWhitelisted(address indexed tokenAddress, bool whitelisted);
    event TokenBlacklisted(address indexed tokenAddress, bool blacklisted);

    event RegistrySettingsUpdated(RegistrySettings settings);

    event TradingVolumeUpdated(
        address indexed tokenAddress,
        uint256 volume24h,
        uint256 totalVolume
    );

    error Registry__TokenAlreadyExists();
    error Registry__TokenNotExists();
    error Registry__InvalidTokenAddress();
    error Registry__InvalidTokenData();
    error Registry__MaxTokensReached();
    error Registry__TokenSuspended();
    error Registry__TokenBlacklisted();
    error Registry__InsufficientFee();
    error Registry__RegistrationDelayNotMet();
    error Registry__InvalidSymbol();
    error Registry__MetadataRequired();

    modifier onlyValidToken(address token) {
        if (tokenInfo[token].tokenAddress == address(0)) revert Registry__TokenNotExists();
        _;
    }

    modifier onlyActiveToken(address token) {
        TokenInfo memory info = tokenInfo[token];
        if (info.status == TokenStatus.SUSPENDED) revert Registry__TokenSuspended();
        if (info.status == TokenStatus.BLACKLISTED) revert Registry__TokenBlacklisted();
        _;
    }

    modifier notBlacklisted(address token) {
        if (blacklist[token]) revert Registry__TokenBlacklisted();
        _;
    }

    function initialize(
        address _admin,
        RegistrySettings memory _settings
    ) external initializer {
        __ReentrancyGuard_init();
        __UUPSUpgradeable_init();

        SecuritySettings memory securitySettings = SecuritySettings({
            emergencyDelay: 24 hours,
            adminDelay: 1 hours,
            emergencyMode: false,
            lastEmergencyTime: 0
        });

        __LaxceAccessControl_init(_admin, "1.0.0", securitySettings);

        registrySettings = _settings;
    }

    function registerToken(
        address tokenAddress,
        TokenType tokenType,
        TokenMetadata calldata metadata,
        TokenLimits calldata limits
    ) external payable nonReentrant notBlacklisted(tokenAddress) {
        if (tokenAddress == address(0)) revert Registry__InvalidTokenAddress();
        if (tokenInfo[tokenAddress].tokenAddress != address(0)) revert Registry__TokenAlreadyExists();
        if (allTokens.length >= MAX_TOKENS) revert Registry__MaxTokensReached();

        if (msg.value < registrySettings.defaultRegistrationFee) revert Registry__InsufficientFee();

        IERC20Metadata token = IERC20Metadata(tokenAddress);
        string memory name = token.name();
        string memory symbol = token.symbol();
        uint8 decimals = token.decimals();

        _validateTokenData(name, symbol, decimals);

        if (symbolToAddress[symbol] != address(0)) revert Registry__InvalidSymbol();

        if (registrySettings.requireMetadata && bytes(metadata.description).length == 0) {
            revert Registry__MetadataRequired();
        }

        TokenStatus status = registrySettings.autoApproval ? TokenStatus.APPROVED : TokenStatus.PENDING;

        tokenInfo[tokenAddress] = TokenInfo({
            tokenAddress: tokenAddress,
            name: name,
            symbol: symbol,
            decimals: decimals,
            tokenType: tokenType,
            status: status,
            registeredAt: block.timestamp,
            lastUpdate: block.timestamp,
            registrar: msg.sender,
            isActive: status == TokenStatus.APPROVED,
            tradingVolume24h: 0,
            totalTradingVolume: 0
        });

        tokenMetadata[tokenAddress] = metadata;

        tokenLimits[tokenAddress] = limits;

        tokenFees[tokenAddress] = TokenFees({
            registrationFee: registrySettings.defaultRegistrationFee,
            listingFee: registrySettings.defaultListingFee,
            tradingFee: registrySettings.defaultTradingFee,
            feeDiscountEligible: false
        });

        allTokens.push(tokenAddress);
        tokensByStatus[status].push(tokenAddress);
        tokensByType[tokenType].push(tokenAddress);
        symbolToAddress[symbol] = tokenAddress;

        registryStats.totalTokens++;
        if (status == TokenStatus.APPROVED) {
            registryStats.activeTokens++;
        } else {
            registryStats.pendingTokens++;
        }
        registryStats.totalFees += msg.value;

        emit TokenRegistered(tokenAddress, name, symbol, tokenType, msg.sender);
    }

    function _validateTokenData(
        string memory name,
        string memory symbol,
        uint8 decimals
    ) internal pure {
        if (bytes(name).length == 0 || bytes(name).length > MAX_NAME_LENGTH) {
            revert Registry__InvalidTokenData();
        }
        if (bytes(symbol).length == 0 || bytes(symbol).length > MAX_SYMBOL_LENGTH) {
            revert Registry__InvalidTokenData();
        }
        if (decimals < MIN_DECIMALS || decimals > MAX_DECIMALS) {
            revert Registry__InvalidTokenData();
        }
    }

    function setTokenStatus(
        address tokenAddress,
        TokenStatus newStatus
    ) external onlyRole(ADMIN_ROLE) onlyValidToken(tokenAddress) {
        TokenInfo storage info = tokenInfo[tokenAddress];
        TokenStatus oldStatus = info.status;

        if (oldStatus == newStatus) return;

        info.status = newStatus;
        info.isActive = (newStatus == TokenStatus.APPROVED);
        info.lastUpdate = block.timestamp;

        _removeFromStatusList(tokenAddress, oldStatus);
        tokensByStatus[newStatus].push(tokenAddress);

        if (oldStatus == TokenStatus.PENDING && newStatus == TokenStatus.APPROVED) {
            registryStats.pendingTokens--;
            registryStats.activeTokens++;
        } else if (oldStatus == TokenStatus.APPROVED && newStatus == TokenStatus.PENDING) {
            registryStats.activeTokens--;
            registryStats.pendingTokens++;
        } else if (oldStatus == TokenStatus.APPROVED) {
            registryStats.activeTokens--;
        } else if (newStatus == TokenStatus.APPROVED) {
            registryStats.activeTokens++;
        }

        emit TokenStatusChanged(tokenAddress, oldStatus, newStatus, msg.sender);
    }

    function _removeFromStatusList(address tokenAddress, TokenStatus status) internal {
        address[] storage statusList = tokensByStatus[status];
        for (uint256 i = 0; i < statusList.length; i++) {
            if (statusList[i] == tokenAddress) {
                statusList[i] = statusList[statusList.length - 1];
                statusList.pop();
                break;
            }
        }
    }

    function updateTokenMetadata(
        address tokenAddress,
        TokenMetadata calldata metadata
    ) external onlyValidToken(tokenAddress) {

        TokenInfo memory info = tokenInfo[tokenAddress];
        require(
            msg.sender == info.registrar || hasRole(ADMIN_ROLE, msg.sender),
            "Not authorized"
        );

        tokenMetadata[tokenAddress] = metadata;
        tokenInfo[tokenAddress].lastUpdate = block.timestamp;

        emit TokenMetadataUpdated(tokenAddress, msg.sender);
    }

    function updateTokenFees(
        address tokenAddress,
        TokenFees calldata fees
    ) external onlyRole(ADMIN_ROLE) onlyValidToken(tokenAddress) {
        tokenFees[tokenAddress] = fees;
        emit TokenFeesUpdated(tokenAddress, fees);
    }

    function updateTokenLimits(
        address tokenAddress,
        TokenLimits calldata limits
    ) external onlyRole(ADMIN_ROLE) onlyValidToken(tokenAddress) {
        tokenLimits[tokenAddress] = limits;
        emit TokenLimitsUpdated(tokenAddress, limits);
    }

    function setWhitelist(
        address tokenAddress,
        bool whitelisted
    ) external onlyRole(ADMIN_ROLE) {
        whitelist[tokenAddress] = whitelisted;
        emit TokenWhitelisted(tokenAddress, whitelisted);
    }

    function setBlacklist(
        address tokenAddress,
        bool blacklisted
    ) external onlyRole(ADMIN_ROLE) {
        blacklist[tokenAddress] = blacklisted;

        if (blacklisted && tokenInfo[tokenAddress].tokenAddress != address(0)) {
            this.setTokenStatus(tokenAddress, TokenStatus.BLACKLISTED);
        }

        emit TokenBlacklisted(tokenAddress, blacklisted);
    }

    function updateTradingVolume(
        address tokenAddress,
        uint256 volume
    ) external onlyRole(OPERATOR_ROLE) onlyValidToken(tokenAddress) {
        TokenInfo storage info = tokenInfo[tokenAddress];
        info.tradingVolume24h = volume;
        info.totalTradingVolume += volume;

        registryStats.totalVolume += volume;

        emit TradingVolumeUpdated(tokenAddress, volume, info.totalTradingVolume);
    }

    function batchApproveTokens(address[] calldata tokens) external onlyRole(ADMIN_ROLE) {
        for (uint256 i = 0; i < tokens.length; i++) {
            this.setTokenStatus(tokens[i], TokenStatus.APPROVED);
        }
    }

    function batchSuspendTokens(address[] calldata tokens) external onlyRole(ADMIN_ROLE) {
        for (uint256 i = 0; i < tokens.length; i++) {
            this.setTokenStatus(tokens[i], TokenStatus.SUSPENDED);
        }
    }

    function isTokenTradeable(address tokenAddress) external view returns (bool) {
        TokenInfo memory info = tokenInfo[tokenAddress];
        return info.isActive &&
               info.status == TokenStatus.APPROVED &&
               !blacklist[tokenAddress];
    }

    function getTokensByStatus(TokenStatus status) external view returns (address[] memory) {
        return tokensByStatus[status];
    }

    function getTokensByType(TokenType tokenType) external view returns (address[] memory) {
        return tokensByType[tokenType];
    }

    function getTokenCount() external view returns (uint256) {
        return allTokens.length;
    }

    function getTokensPaginated(
        uint256 offset,
        uint256 limit
    ) external view returns (address[] memory tokens, uint256 total) {
        total = allTokens.length;

        if (offset >= total) {
            return (new address[](0), total);
        }

        uint256 end = offset + limit;
        if (end > total) {
            end = total;
        }

        tokens = new address[](end - offset);
        for (uint256 i = offset; i < end; i++) {
            tokens[i - offset] = allTokens[i];
        }
    }

    function searchTokens(
        string calldata query,
        uint256 limit
    ) external view returns (address[] memory results) {
        address[] memory matches = new address[](limit);
        uint256 matchCount = 0;

        for (uint256 i = 0; i < allTokens.length && matchCount < limit; i++) {
            address token = allTokens[i];
            TokenInfo memory info = tokenInfo[token];

            if (_stringContains(info.name, query) || _stringContains(info.symbol, query)) {
                matches[matchCount] = token;
                matchCount++;
            }
        }

        results = new address[](matchCount);
        for (uint256 i = 0; i < matchCount; i++) {
            results[i] = matches[i];
        }
    }

    function _stringContains(string memory str, string memory substr) internal pure returns (bool) {
        bytes memory strBytes = bytes(str);
        bytes memory substrBytes = bytes(substr);

        if (substrBytes.length > strBytes.length) return false;
        if (substrBytes.length == 0) return true;

        for (uint256 i = 0; i <= strBytes.length - substrBytes.length; i++) {
            bool found = true;
            for (uint256 j = 0; j < substrBytes.length; j++) {
                if (strBytes[i + j] != substrBytes[j]) {
                    found = false;
                    break;
                }
            }
            if (found) return true;
        }

        return false;
    }

    function updateRegistrySettings(
        RegistrySettings calldata settings
    ) external onlyRole(ADMIN_ROLE) {
        registrySettings = settings;
        emit RegistrySettingsUpdated(settings);
    }

    function withdrawFees(address to) external onlyRole(TREASURY_ROLE) {
        uint256 balance = address(this).balance;
        if (balance > 0) {
            payable(to).transfer(balance);
        }
    }

    function _authorizeUpgrade(address newImplementation)
        internal
        override(UUPSUpgradeable, LaxceAccessControlUpgradeable)
        onlyRole(UPGRADER_ROLE)
    {}
}
"
    },
    "AccessControlUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

contract LaxceAccessControlUpgradeable is
    Initializable,
    AccessControlUpgradeable,
    PausableUpgradeable,
    ReentrancyGuardUpgradeable,
    UUPSUpgradeable
{

    bytes32 public constant OWNER_ROLE = keccak256("OWNER_ROLE");

    bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");

    bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE");

    bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");

    bytes32 public constant UPGRADER_ROLE = keccak256("UPGRADER_ROLE");

    bytes32 public constant TREASURY_ROLE = keccak256("TREASURY_ROLE");

    bytes32 public constant ORACLE_ROLE = keccak256("ORACLE_ROLE");

    bytes32 public constant POOL_MANAGER_ROLE = keccak256("POOL_MANAGER_ROLE");

    bytes32 public constant EMERGENCY_ROLE = keccak256("EMERGENCY_ROLE");

    bytes32 public constant FEE_MANAGER_ROLE = keccak256("FEE_MANAGER_ROLE");

    bytes32 public constant STAKING_MANAGER_ROLE = keccak256("STAKING_MANAGER_ROLE");

    bytes32 public constant GOVERNANCE_ROLE = keccak256("GOVERNANCE_ROLE");

    address public deployer;

    uint256 public deploymentTime;

    string public version;

    struct SecuritySettings {
        uint256 emergencyDelay;
        uint256 adminDelay;
        bool emergencyMode;
        uint256 lastEmergencyTime;
    }

    SecuritySettings public securitySettings;

    mapping(bytes32 => address[]) public roleMembers;

    mapping(bytes32 => uint256) public roleMemberCount;

    struct RoleChange {
        bytes32 role;
        address account;
        bool granted;
        uint256 timestamp;
        address admin;
    }

    RoleChange[] public roleChanges;

    mapping(bytes32 => mapping(address => uint256)) public roleTimeRestrictions;

    event SecuritySettingsUpdated(
        uint256 emergencyDelay,
        uint256 adminDelay,
        address indexed updater
    );

    event EmergencyModeToggled(bool enabled, address indexed toggler);

    event RoleGrantedWithTimeRestriction(
        bytes32 indexed role,
        address indexed account,
        address indexed sender,
        uint256 validUntil
    );

    event RoleTimeRestrictionUpdated(
        bytes32 indexed role,
        address indexed account,
        uint256 newValidUntil
    );

    error AccessControl__EmergencyModeActive();
    error AccessControl__TimeRestrictionExpired();
    error AccessControl__InvalidDelay();
    error AccessControl__EmergencyDelayNotMet();
    error AccessControl__AdminDelayNotMet();

    modifier whenNotInEmergency() {
        if (securitySettings.emergencyMode) revert AccessControl__EmergencyModeActive();
        _;
    }

    modifier withTimeRestriction(bytes32 role) {
        uint256 validUntil = roleTimeRestrictions[role][msg.sender];
        if (validUntil > 0 && block.timestamp > validUntil) {
            revert AccessControl__TimeRestrictionExpired();
        }
        _;
    }

    modifier emergencyDelayMet() {
        if (block.timestamp < securitySettings.lastEmergencyTime + securitySettings.emergencyDelay) {
            revert AccessControl__EmergencyDelayNotMet();
        }
        _;
    }

    function __LaxceAccessControl_init(
        address _deployer,
        string memory _version,
        SecuritySettings memory _securitySettings
    ) internal onlyInitializing {
        __AccessControl_init();
        __Pausable_init();
        __ReentrancyGuard_init();
        __UUPSUpgradeable_init();

        deployer = _deployer;
        deploymentTime = block.timestamp;
        version = _version;
        securitySettings = _securitySettings;

        _setupInitialRoles(_deployer);
    }

    function initialize(
        address _deployer,
        string memory _version,
        SecuritySettings memory _securitySettings
    ) external initializer {
        __LaxceAccessControl_init(_deployer, _version, _securitySettings);
    }

    function grantRoleWithTimeRestriction(
        bytes32 role,
        address account,
        uint256 validUntil
    ) external onlyRole(getRoleAdmin(role)) whenNotInEmergency {
        grantRole(role, account);

        if (validUntil > 0) {
            roleTimeRestrictions[role][account] = validUntil;
            emit RoleGrantedWithTimeRestriction(role, account, msg.sender, validUntil);
        }

        _updateRoleMembersList(role, account, true);
    }

    function revokeRole(bytes32 role, address account)
        public
        override
        onlyRole(getRoleAdmin(role))
        whenNotInEmergency
    {
        super.revokeRole(role, account);
        _updateRoleMembersList(role, account, false);

        delete roleTimeRestrictions[role][account];
    }

    function updateRoleTimeRestriction(
        bytes32 role,
        address account,
        uint256 newValidUntil
    ) external onlyRole(getRoleAdmin(role)) {
        require(hasRole(role, account), "Account does not have role");

        roleTimeRestrictions[role][account] = newValidUntil;
        emit RoleTimeRestrictionUpdated(role, account, newValidUntil);
    }

    function _setupInitialRoles(address _deployer) internal {

        _grantRole(DEFAULT_ADMIN_ROLE, _deployer);
        _grantRole(OWNER_ROLE, _deployer);
        _grantRole(ADMIN_ROLE, _deployer);
        _grantRole(UPGRADER_ROLE, _deployer);
        _grantRole(EMERGENCY_ROLE, _deployer);
        _grantRole(PAUSER_ROLE, _deployer);

        _setRoleAdmin(ADMIN_ROLE, OWNER_ROLE);
        _setRoleAdmin(OPERATOR_ROLE, ADMIN_ROLE);
        _setRoleAdmin(TREASURY_ROLE, ADMIN_ROLE);
        _setRoleAdmin(ORACLE_ROLE, ADMIN_ROLE);
        _setRoleAdmin(POOL_MANAGER_ROLE, ADMIN_ROLE);
        _setRoleAdmin(FEE_MANAGER_ROLE, ADMIN_ROLE);
        _setRoleAdmin(STAKING_MANAGER_ROLE, ADMIN_ROLE);
        _setRoleAdmin(GOVERNANCE_ROLE, OWNER_ROLE);
        _setRoleAdmin(PAUSER_ROLE, EMERGENCY_ROLE);
        _setRoleAdmin(UPGRADER_ROLE, OWNER_ROLE);
    }

    function _updateRoleMembersList(bytes32 role, address account, bool granted) internal {
        if (granted) {
            roleMembers[role].push(account);
            roleMemberCount[role]++;
        } else {

            address[] storage members = roleMembers[role];
            for (uint256 i = 0; i < members.length; i++) {
                if (members[i] == account) {
                    members[i] = members[members.length - 1];
                    members.pop();
                    roleMemberCount[role]--;
                    break;
                }
            }
        }

        roleChanges.push(RoleChange({
            role: role,
            account: account,
            granted: granted,
            timestamp: block.timestamp,
            admin: msg.sender
        }));
    }

    function updateSecuritySettings(
        uint256 _emergencyDelay,
        uint256 _adminDelay
    ) external onlyRole(OWNER_ROLE) {
        if (_emergencyDelay < 1 hours || _adminDelay < 30 minutes) {
            revert AccessControl__InvalidDelay();
        }

        securitySettings.emergencyDelay = _emergencyDelay;
        securitySettings.adminDelay = _adminDelay;

        emit SecuritySettingsUpdated(_emergencyDelay, _adminDelay, msg.sender);
    }

    function toggleEmergencyMode() external virtual onlyRole(EMERGENCY_ROLE) emergencyDelayMet {
        securitySettings.emergencyMode = !securitySettings.emergencyMode;
        securitySettings.lastEmergencyTime = block.timestamp;

        emit EmergencyModeToggled(securitySettings.emergencyMode, msg.sender);
    }

    function pause() external onlyRole(PAUSER_ROLE) {
        _pause();
    }

    function unpause() external onlyRole(PAUSER_ROLE) {
        _unpause();
    }

    function hasValidRole(bytes32 role, address account) external view returns (bool) {
        if (!hasRole(role, account)) return false;

        uint256 validUntil = roleTimeRestrictions[role][account];
        if (validUntil > 0 && block.timestamp > validUntil) return false;

        return true;
    }

    function getRoleMembers(bytes32 role) external view returns (address[] memory) {
        return roleMembers[role];
    }

    function getRoleMemberCount(bytes32 role) external view returns (uint256) {
        return roleMemberCount[role];
    }

    function getRoleChangesCount() external view returns (uint256) {
        return roleChanges.length;
    }

    function isEmergencyMode() external view returns (bool) {
        return securitySettings.emergencyMode;
    }

    function _authorizeUpgrade(address newImplementation)
        internal
        virtual
        override
        onlyRole(UPGRADER_ROLE)
        whenNotInEmergency
    {}

    function getVersion() external view returns (string memory) {
        return version;
    }

    function updateVersion(string memory _newVersion) external onlyRole(UPGRADER_ROLE) {
        version = _newVersion;
    }
}
"
    },
    "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity >=0.6.2;

import {IERC20} from "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC-20 standard.
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}
"
    },
    "@openzeppelin/contracts/token/ERC20/IERC20.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 value) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}
"
    },
    "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
 * consider using {ReentrancyGuardTransient} instead.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuardUpgradeable is Initializable {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant NOT_ENTERED = 1;
    uint256 private constant ENTERED = 2;

    /// @custom:storage-location erc7201:openzeppelin.storage.ReentrancyGuard
    struct ReentrancyGuardStorage {
        uint256 _status;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant ReentrancyGuardStorageLocation = 0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;

    function _getReentrancyGuardStorage() private pure returns (ReentrancyGuardStorage storage $) {
        assembly {
            $.slot := ReentrancyGuardStorageLocation
        }
    }

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    function __ReentrancyGuard_init() internal onlyInitializing {
        __ReentrancyGuard_init_unchained();
    }

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        $._status = NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if ($._status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

        // Any calls to nonReentrant after this point will fail
        $._status = ENTERED;
    }

    function _nonReentrantAfter() private {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        $._status = NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        return $._status == ENTERED;
    }
}
"
    },
    "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/UUPSUpgradeable.sol)

pragma solidity ^0.8.22;

import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {Initializable} from "./Initializable.sol";

/**
 * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
 * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
 *
 * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
 * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
 * `UUPSUpgradeable` with a custom implementation of upgrades.
 *
 * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
 */
abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable {
    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
    address private immutable __self = address(this);

    /**
     * @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`
     * and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
     * while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.
     * If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must
     * be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
     * during an upgrade.
     */
    string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";

    /**
     * @dev The call is from an unauthorized context.
     */
    error UUPSUnauthorizedCallContext();

    /**
     * @dev The storage `slot` is unsupported as a UUID.
     */
    error UUPSUnsupportedProxiableUUID(bytes32 slot);

    /**
     * @dev Check that the execution is being performed through a delegatecall call and that the execution context is
     * a proxy contract with an implementation (as defined in ERC-1967) pointing to self. This should only be the case
     * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
     * function through ERC-1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
     * fail.
     */
    modifier onlyProxy() {
        _checkProxy();
        _;
    }

    /**
     * @dev Check that the execution is not being performed through a delegate call. This allows a function to be
     * callable on the implementing contract but not through proxies.
     */
    modifier notDelegated() {
        _checkNotDelegated();
        _;
    }

    function __UUPSUpgradeable_init() internal onlyInitializing {
    }

    function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Implementation of the ERC-1822 {proxiableUUID} function. This returns the storage slot used by the
     * implementation. It is used to validate the implementation's compatibility when performing an upgrade.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
     */
    function proxiableUUID() external view virtual notDelegated returns (bytes32) {
        return ERC1967Utils.IMPLEMENTATION_SLOT;
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
     * encoded in `data`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     *
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, data);
    }

    /**
     * @dev Reverts if the execution is not performed via delegatecall or the execution
     * context is not of a proxy with an ERC-1967 compliant implementation pointing to self.
     */
    function _checkProxy() internal view virtual {
        if (
            address(this) == __self || // Must be called through delegatecall
            ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
        ) {
            revert UUPSUnauthorizedCallContext();
        }
    }

    /**
     * @dev Reverts if the execution is performed via delegatecall.
     * See {notDelegated}.
     */
    function _checkNotDelegated() internal view virtual {
        if (address(this) != __self) {
            // Must not be called through delegatecall
            revert UUPSUnauthorizedCallContext();
        }
    }

    /**
     * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
     * {upgradeToAndCall}.
     *
     * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
     *
     * ```solidity
     * function _authorizeUpgrade(address) internal onlyOwner {}
     * ```
     */
    function _authorizeUpgrade(address newImplementation) internal virtual;

    /**
     * @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.
     *
     * As a security check, {proxiableUUID} is invoked in the new implementation, and the return value
     * is expected to be the implementation slot in ERC-1967.
     *
     * Emits an {IERC1967-Upgraded} event.
     */
    function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {
        try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
            if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
                revert UUPSUnsupportedProxiableUUID(slot);
            }
            ERC1967Utils.upgradeToAndCall(newImplementation, data);
        } catch {
            // The implementation is not UUPS
            revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
        }
    }
}
"
    },
    "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.20;

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```solidity
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 *
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Storage of the initializable contract.
     *
     * It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
     * when using with upgradeable contracts.
     *
     * @custom:storage-location erc7201:openzeppelin.storage.Initializable
     */
    struct InitializableStorage {
        /**
         * @dev Indicates that the contract has been initialized.
         */
        uint64 _initialized;
        /**
         * @dev Indicates that the contract is in the process of being initialized.
         */
        bool _initializing;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;

    /**
     * @dev The contract is already initialized.
     */
    error InvalidInitialization();

    /**
     * @dev The contract is not initializing.
     */
    error NotInitializing();

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint64 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
     * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
     * production.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        // Cache values to avoid duplicated sloads
        bool isTopLevelCall = !$._initializing;
        uint64 initialized = $._initialized;

        // Allowed calls:
        // - initialSetup: the contract is not in the initializing state and no previous version was
        //                 initialized
        // - construction: the contract is initialized at version 1 (no reinitialization) and the
        //                 current contract is just being deployed
        bool initialSetup = initialized == 0 && isTopLevelCall;
        bool construction = initialized == 1 && address(this).code.length == 0;

        if (!initialSetup && !construction) {
            revert InvalidInitialization();
        }
        $._initialized = 1;
        if (isTopLevelCall) {
            $._initializing = true;
        }
        _;
        if (isTopLevelCall) {
            $._initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint64 version) {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing || $._initialized >= version) {
            revert InvalidInitialization();
        }
        $._initialized = version;
        $._initializing = true;
        _;
        $._initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        _checkInitializing();
        _;
    }

    /**
     * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
     */
    function _checkInitializing() internal view virtual {
        if (!_isInitializing()) {
            revert NotInitializing();
        }
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing) {
            revert InvalidInitialization();
        }
        if ($._initialized != type(uint64).max) {
            $._initialized = type(uint64).max;
            emit Initialized(type(uint64).max);
        }
    }

    /**
     * @dev Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint64) {
        return _getInitializableStorage()._initialized;
    }

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _getInitializableStorage()._initializing;
    }

    /**
     * @dev Pointer to storage slot. Allows integrators to override it with a custom storage location.
     *
     * NOTE: Consider following the ERC-7201 formula to derive storage locations.
     */
    function _initializableStorageSlot() internal pure virtual returns (bytes32) {
        return INITIALIZABLE_STORAGE;
    }

    /**
     * @dev Returns a pointer to the storage namespace.
     */
    // solhint-disable-next-line var-name-mixedcase
    function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
        bytes32 slot = _initializableStorageSlot();
        assembly {
            $.slot := slot
        }
    }
}
"
    },
    "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Pausable.sol)

pragma solidity ^0.8.20;

import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
    /// @custom:storage-location erc7201:openzeppelin.storage.Pausable
    struct PausableStorage {
        bool _paused;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Pausable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant PausableStorageLocation = 0xcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300;

    function _getPausableStorage() private pure returns (PausableStorage storage $) {
        assembly {
            $.slot := PausableStorageLocation
        }
    }

    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    /**
     * @dev The operation failed because the contract is paused.
     */
    error EnforcedPause();

    /**
     * @dev The operation failed because the contract is not paused.
     */
    error ExpectedPause();

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    function __Pausable_init() internal onlyInitializing {
    }

    function __Pausable_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        PausableStorage storage $ = _getPausableStorage();
        return $._paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        if (paused()) {
            revert EnforcedPause();
        }
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        if (!paused()) {
            revert ExpectedPause();
        }
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        PausableStorage storage $ = _getPausableStorage();
        $._paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        PausableStorage storage $ = _getPausableStorage();
        $._paused = false;
        emit Unpaused(_msgSender());
    }
}
"
    },
    "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (access/AccessControl.sol)

pragma solidity ^0.8.20;

import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {ERC165Upgradeable} from "../utils/introspection/ERC165Upgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```solidity
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```solidity
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
 * to enforce additional security measures for this role.
 */
abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControl, ERC165Upgradeable {
    struct RoleData {
        mapping(address account => bool) hasRole;
        bytes32 adminRole;
    }

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;


    /// @custom:storage-location erc7201:openzeppelin.storage.AccessControl
    struct AccessControlStorage {
        mapping(bytes32 role => RoleData) _roles;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.AccessControl")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant AccessControlStorageLocation = 0x02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800;

    function _getAccessControlStorage() private pure returns (AccessControlStorage storage $) {
        assembly {
            $.slot := AccessControlStorageLocation
        }
    }

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with an {AccessControlUnauthorizedAccount} error including the required role.
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    function __AccessControl_init() internal onlyInitializing {
    }

    function __AccessControl_init_unchained() internal onlyInitializing {
    }
    /// @inheritdoc IERC165
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual returns (bool) {
        AccessControlStorage storage $ = _getAccessControlStorage();
        return $._roles[role].hasRole[account];
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
     * is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
     * is missing `role`.
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert AccessControlUnauthorizedAccount(account, role);
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
        AccessControlStorage storage $ = _getAccessControlStorage();
        return $._roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleGranted} event.
     */
    function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleRevoked} event.
     */
    function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address callerConfirmation) public virtual {
        if (callerConfirmation != _msgSender()) {
            revert AccessControlBadConfirmation();
        }

        _revokeRole(role, callerConfirmation);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        AccessControlStorage storage $ = _getAccessControlStorage();
        bytes32 previousAdminRole = getRoleAdmin(role);
        $._roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
        AccessControlStorage storage $ = _getAccessControlStorage();
        if (!hasRole(role, account)) {
            $._roles[role].hasRole[account] = true;
            emit RoleGranted(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Attempts to revoke `role` from `account` and returns a boolean indicating if `role` was revoked.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
        AccessControlStorage storage $ = _getAccessControlStorage();
        if (hasRole(role, account)) {
            $._roles[role].hasRole[account] = false;
            emit RoleRevoked(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }
}
"
    },
    "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (proxy/ERC1967/ERC1967Utils.sol)

pragma solidity ^0.8.21;

import {IBeacon} from "../beacon/IBeacon.sol";
import {IERC1967} from "../../interfaces/IERC1967.sol";
import {Address} from "../../utils/Address.sol";
import {StorageSlot} from "../../utils/StorageSlot.sol";

/**
 * @dev This library provides getters and event emitting update functions for
 * https://eips.ethereum.org/EIPS/eip-1967[ERC-1967] slots.
 */
library ERC1967Utils {
    /**
     * @dev Storage slot with the address of the current implementation.
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    /**
     * @dev The `implementation` of the proxy is invalid.
     */
    error ERC1967InvalidImplementation(address implementation);

    /**
     * @dev The `admin` of the proxy is invalid.
     */
    error ERC1967InvalidAdmin(address admin);

    /**
     * @dev The `beacon` of the proxy is invalid.
     */
    error ERC1967InvalidBeacon(address beacon);

    /**
     * @dev An upgrade function sees `msg.value > 0` that may be lost.
     */
    error ERC1967NonPayable();

    /**
     * @dev Returns the current implementation address.
     */
    function getIm

Tags:
ERC20, ERC165, Proxy, Pausable, Voting, Upgradeable, Factory, Oracle|addr:0x4b5539ac83c5d4154dd1b43634b2a1b293cfd0cb|verified:true|block:23527528|tx:0xbd449d6ff93aa718b9843b6ddffa4b97077228371391559a3f2dc85081488f17|first_check:1759863638

Submitted on: 2025-10-07 21:00:38

Comments

Log in to comment.

No comments yet.