Contract 0x647fA31bEc9114D4C1a37750C5e0e83FCA0AbFC0

 
 
Txn Hash
Method
Block
From
To
Value
0x55c6e834c877cfd9a57ed1886036ee136e93942e3c4454b41e7148d72f8f42c40x60806040143001652022-03-01 9:01:10215 days 1 hr agoLido: Deployer IN  Create: NodeOperatorRegistry0 Ether0.5676995125
[ Download CSV Export 
View more zero value Internal Transactions in Advanced View mode
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
NodeOperatorRegistry

Compiler Version
v0.8.7+commit.e28d00a7

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 29 : NodeOperatorRegistry.sol
// SPDX-FileCopyrightText: 2021 ShardLabs
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.7;

import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";

import "./interfaces/INodeOperatorRegistry.sol";
import "./interfaces/IValidatorFactory.sol";
import "./interfaces/IValidator.sol";
import "./interfaces/IStMATIC.sol";

/// @title NodeOperatorRegistry
/// @author 2021 ShardLabs.
/// @notice NodeOperatorRegistry is the main contract that manage validators
/// @dev NodeOperatorRegistry is the main contract that manage operators.
contract NodeOperatorRegistry is
    INodeOperatorRegistry,
    PausableUpgradeable,
    AccessControlUpgradeable,
    ReentrancyGuardUpgradeable
{
    enum NodeOperatorStatus {
        INACTIVE,
        ACTIVE,
        STOPPED,
        UNSTAKED,
        CLAIMED,
        EXIT,
        JAILED,
        EJECTED
    }
    /// @notice The node operator struct
    /// @param status node operator status(INACTIVE, ACTIVE, STOPPED, CLAIMED, UNSTAKED, EXIT, JAILED, EJECTED).
    /// @param name node operator name.
    /// @param rewardAddress Validator public key used for access control and receive rewards.
    /// @param validatorId validator id of this node operator on the polygon stake manager.
    /// @param signerPubkey public key used on heimdall.
    /// @param validatorShare validator share contract used to delegate for on polygon.
    /// @param validatorProxy the validator proxy, the owner of the validator.
    /// @param commissionRate the commission rate applied by the operator on polygon.
    /// @param maxDelegateLimit max delegation limit that StMatic contract will delegate to this operator each time delegate function is called.
    struct NodeOperator {
        NodeOperatorStatus status;
        string name;
        address rewardAddress;
        bytes signerPubkey;
        address validatorShare;
        address validatorProxy;
        uint256 validatorId;
        uint256 commissionRate;
        uint256 maxDelegateLimit;
    }

    /// @notice all the roles.
    bytes32 public constant REMOVE_OPERATOR_ROLE =
        keccak256("LIDO_REMOVE_OPERATOR");
    bytes32 public constant PAUSE_OPERATOR_ROLE =
        keccak256("LIDO_PAUSE_OPERATOR");
    bytes32 public constant DAO_ROLE = keccak256("LIDO_DAO");

    /// @notice contract version.
    string public version;
    /// @notice total node operators.
    uint256 private totalNodeOperators;

    /// @notice validatorFactory address.
    address private validatorFactory;
    /// @notice stakeManager address.
    address private stakeManager;
    /// @notice polygonERC20 token (Matic) address.
    address private polygonERC20;
    /// @notice stMATIC address.
    address private stMATIC;

    /// @notice keeps track of total number of operators
    uint256 nodeOperatorCounter;

    /// @notice min amount allowed to stake per validator.
    uint256 public minAmountStake;

    /// @notice min HeimdallFees allowed to stake per validator.
    uint256 public minHeimdallFees;

    /// @notice commision rate applied to all the operators.
    uint256 public commissionRate;

    /// @notice allows restake.
    bool public allowsRestake;

    /// @notice default max delgation limit.
    uint256 public defaultMaxDelegateLimit;

    /// @notice This stores the operators ids.
    uint256[] private operatorIds;

    /// @notice Mapping of all owners with node operator id. Mapping is used to be able to
    /// extend the struct.
    mapping(address => uint256) private operatorOwners;


    /// @notice Mapping of all node operators. Mapping is used to be able to extend the struct.
    mapping(uint256 => NodeOperator) private operators;

    /// --------------------------- Modifiers-----------------------------------

    /// @notice Check if the msg.sender has permission.
    /// @param _role role needed to call function.
    modifier userHasRole(bytes32 _role) {
        checkCondition(hasRole(_role, msg.sender), "unauthorized");
        _;
    }

    /// @notice Check if the amount is inbound.
    /// @param _amount amount to stake.
    modifier checkStakeAmount(uint256 _amount) {
        checkCondition(_amount >= minAmountStake, "Invalid amount");
        _;
    }

    /// @notice Check if the heimdall fee is inbound.
    /// @param _heimdallFee heimdall fee.
    modifier checkHeimdallFees(uint256 _heimdallFee) {
        checkCondition(_heimdallFee >= minHeimdallFees, "Invalid fees");
        _;
    }

    /// @notice Check if the maxDelegateLimit is less or equal to 10 Billion.
    /// @param _maxDelegateLimit max delegate limit.
    modifier checkMaxDelegationLimit(uint256 _maxDelegateLimit) {
        checkCondition(
            _maxDelegateLimit <= 10000000000 ether,
            "Max amount <= 10B"
        );
        _;
    }

    /// @notice Check if the rewardAddress is already used.
    /// @param _rewardAddress new reward address.
    modifier checkIfRewardAddressIsUsed(address _rewardAddress) {
        checkCondition(
            operatorOwners[_rewardAddress] == 0 && _rewardAddress != address(0),
            "Address used"
        );
        _;
    }

    /// -------------------------- initialize ----------------------------------

    /// @notice Initialize the NodeOperator contract.
    function initialize(
        address _validatorFactory,
        address _stakeManager,
        address _polygonERC20,
        address _stMATIC
    ) external initializer {
        __Pausable_init();
        __AccessControl_init();
        __ReentrancyGuard_init();

        validatorFactory = _validatorFactory;
        stakeManager = _stakeManager;
        polygonERC20 = _polygonERC20;
        stMATIC = _stMATIC;

        minAmountStake = 10 * 10**18;
        minHeimdallFees = 20 * 10**18;
        defaultMaxDelegateLimit = 10 ether;

        _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
        _setupRole(REMOVE_OPERATOR_ROLE, msg.sender);
        _setupRole(PAUSE_OPERATOR_ROLE, msg.sender);
        _setupRole(DAO_ROLE, msg.sender);
    }

    /// ----------------------------- API --------------------------------------

    /// @notice Add a new node operator to the system.
    /// @dev The operator life cycle starts when we call the addOperator
    /// func allows adding a new operator. During this call, a new validatorProxy is
    /// deployed by the ValidatorFactory which we can use later to interact with the
    /// Polygon StakeManager. At the end of this call, the status of the operator
    /// will be INACTIVE.
    /// @param _name the node operator name.
    /// @param _rewardAddress address used for ACL and receive rewards.
    /// @param _signerPubkey public key used on heimdall len 64 bytes.
    function addOperator(
        string memory _name,
        address _rewardAddress,
        bytes memory _signerPubkey
    )
        external
        override
        whenNotPaused
        userHasRole(DAO_ROLE)
        checkIfRewardAddressIsUsed(_rewardAddress)
    {
        nodeOperatorCounter++;
        address validatorProxy = IValidatorFactory(validatorFactory).create();

        operators[nodeOperatorCounter] = NodeOperator({
            status: NodeOperatorStatus.INACTIVE,
            name: _name,
            rewardAddress: _rewardAddress,
            validatorId: 0,
            signerPubkey: _signerPubkey,
            validatorShare: address(0),
            validatorProxy: validatorProxy,
            commissionRate: commissionRate,
            maxDelegateLimit: defaultMaxDelegateLimit
        });
        operatorIds.push(nodeOperatorCounter);
        totalNodeOperators++;
        operatorOwners[_rewardAddress] = nodeOperatorCounter;

        emit AddOperator(nodeOperatorCounter);
    }

    /// @notice Allows to stop an operator from the system.
    /// @param _operatorId the node operator id.
    function stopOperator(uint256 _operatorId)
        external
        override
    {

        (, NodeOperator storage no) = getOperator(_operatorId);
        require(
            no.rewardAddress == msg.sender || hasRole(DAO_ROLE, msg.sender), "unauthorized"
        );
        NodeOperatorStatus status = getOperatorStatus(no);
        checkCondition(
            status == NodeOperatorStatus.ACTIVE || status == NodeOperatorStatus.INACTIVE ||
            status == NodeOperatorStatus.JAILED
        , "Invalid status");

        if (status == NodeOperatorStatus.INACTIVE) {
            no.status = NodeOperatorStatus.EXIT;
        } else {
            IStMATIC(stMATIC).withdrawTotalDelegated(no.validatorShare);
            no.status = NodeOperatorStatus.STOPPED;
        }
        emit StopOperator(_operatorId);
    }

    /// @notice Allows to remove an operator from the system.when the operator status is
    /// set to EXIT the GOVERNANCE can call the removeOperator func to delete the operator,
    /// and the validatorProxy used to interact with the Polygon stakeManager.
    /// @param _operatorId the node operator id.
    function removeOperator(uint256 _operatorId)
        external
        override
        whenNotPaused
        userHasRole(REMOVE_OPERATOR_ROLE)
    {
        (, NodeOperator storage no) = getOperator(_operatorId);
        checkCondition(no.status == NodeOperatorStatus.EXIT, "Invalid status");

        // update the operatorIds array by removing the operator id.
        for (uint256 idx = 0; idx < operatorIds.length - 1; idx++) {
            if (_operatorId == operatorIds[idx]) {
                operatorIds[idx] = operatorIds[operatorIds.length - 1];
                break;
            }
        }
        operatorIds.pop();

        totalNodeOperators--;
        IValidatorFactory(validatorFactory).remove(no.validatorProxy);
        delete operatorOwners[no.rewardAddress];
        delete operators[_operatorId];

        emit RemoveOperator(_operatorId);
    }

    /// @notice Allows a validator that was already staked on the polygon stake manager
    /// to join the PoLido protocol.
    function joinOperator() external override whenNotPaused {
        (uint256 operatorId, NodeOperator storage no) = getOperator(0);
        checkCondition(
            getOperatorStatus(no) == NodeOperatorStatus.INACTIVE,
            "Invalid status"
        );

        IStakeManager sm = IStakeManager(stakeManager);
        uint256 validatorId = sm.getValidatorId(msg.sender);

        checkCondition(validatorId != 0, "ValidatorId=0");

        IStakeManager.Validator memory poValidator = sm.validators(validatorId);

        checkCondition(
            poValidator.contractAddress != address(0),
            "Validator has no ValidatorShare"
        );

        checkCondition(
            (poValidator.status == IStakeManager.Status.Active
                ) && poValidator.deactivationEpoch == 0 ,
            "Validator isn't ACTIVE"
        );

        checkCondition(
            poValidator.signer ==
                address(uint160(uint256(keccak256(no.signerPubkey)))),
            "Invalid Signer"
        );

        IValidator(no.validatorProxy).join(
            validatorId,
            sm.NFTContract(),
            msg.sender,
            no.commissionRate,
            stakeManager
        );

        no.validatorId = validatorId;

        address validatorShare = sm.getValidatorContract(validatorId);
        no.validatorShare = validatorShare;

        emit JoinOperator(operatorId);
    }

    /// ------------------------Stake Manager API-------------------------------

    /// @notice Allows to stake a validator on the Polygon stakeManager contract.
    /// @dev The stake func allows each operator's owner to stake, but before that,
    /// the owner has to approve the amount + Heimdall fees to the ValidatorProxy.
    /// At the end of this call, the status of the operator is set to ACTIVE.
    /// @param _amount amount to stake.
    /// @param _heimdallFee heimdall fees.
    function stake(uint256 _amount, uint256 _heimdallFee)
        external
        override
        whenNotPaused
        checkStakeAmount(_amount)
        checkHeimdallFees(_heimdallFee)
    {
        (uint256 operatorId, NodeOperator storage no) = getOperator(0);
        checkCondition(
            getOperatorStatus(no) == NodeOperatorStatus.INACTIVE,
            "Invalid status"
        );

        (uint256 validatorId, address validatorShare) = IValidator(
            no.validatorProxy
        ).stake(
                msg.sender,
                _amount,
                _heimdallFee,
                true,
                no.signerPubkey,
                no.commissionRate,
                stakeManager,
                polygonERC20
            );

        no.validatorId = validatorId;
        no.validatorShare = validatorShare;

        emit StakeOperator(operatorId, _amount, _heimdallFee);
    }

    /// @notice Allows to restake Matics to Polygon stakeManager
    /// @dev restake allows an operator's owner to increase the total staked amount
    /// on Polygon. The owner has to approve the amount to the ValidatorProxy then make
    /// a call.
    /// @param _amount amount to stake.
    function restake(uint256 _amount, bool _restakeRewards)
        external
        override
        whenNotPaused
    {
        checkCondition(allowsRestake, "Restake is disabled");
        if (_amount == 0) {
            revert("Amount is ZERO");
        }

        (uint256 operatorId, NodeOperator storage no) = getOperator(0);
        checkCondition(
            getOperatorStatus(no) == NodeOperatorStatus.ACTIVE,
            "Invalid status"
        );
        IValidator(no.validatorProxy).restake(
            msg.sender,
            no.validatorId,
            _amount,
            _restakeRewards,
            stakeManager,
            polygonERC20
        );

        emit RestakeOperator(operatorId, _amount, _restakeRewards);
    }

    /// @notice Unstake a validator from the Polygon stakeManager contract.
    /// @dev when the operators's owner wants to quite the PoLido protocol he can call
    /// the unstake func, in this case, the operator status is set to UNSTAKED.
    function unstake() external override whenNotPaused {
        (uint256 operatorId, NodeOperator storage no) = getOperator(0);
        NodeOperatorStatus status = getOperatorStatus(no);
        checkCondition(
            status == NodeOperatorStatus.ACTIVE ||
            status == NodeOperatorStatus.JAILED ||
            status == NodeOperatorStatus.EJECTED,
            "Invalid status"
        );
        if (status == NodeOperatorStatus.ACTIVE) {
            IValidator(no.validatorProxy).unstake(no.validatorId, stakeManager);
        }
        _unstake(operatorId, no);
    }

    /// @notice The DAO unstake the operator if it was unstaked by the stakeManager.
    /// @dev when the operator was unstaked by the stage Manager the DAO can use this
    /// function to update the operator status and also withdraw the delegated tokens,
    /// without waiting for the owner to call the unstake function
    /// @param _operatorId operator id.
    function unstake(uint256 _operatorId) external userHasRole(DAO_ROLE) {
        NodeOperator storage no = operators[_operatorId];
        NodeOperatorStatus status = getOperatorStatus(no);
        checkCondition(status == NodeOperatorStatus.EJECTED, "Invalid status");
        _unstake(_operatorId, no);
    }

    function _unstake(uint256 _operatorId, NodeOperator storage no)
        private
        whenNotPaused
    {
        IStMATIC(stMATIC).withdrawTotalDelegated(no.validatorShare);
        no.status = NodeOperatorStatus.UNSTAKED;

        emit UnstakeOperator(_operatorId);
    }

    /// @notice Allows the operator's owner to migrate the validator ownership to rewardAddress.
    /// This can be done only in the case where this operator was stopped by the DAO.
    function migrate() external override nonReentrant {
        (uint256 operatorId, NodeOperator storage no) = getOperator(0);
        checkCondition(no.status == NodeOperatorStatus.STOPPED, "Invalid status");
        IValidator(no.validatorProxy).migrate(
            no.validatorId,
            IStakeManager(stakeManager).NFTContract(),
            no.rewardAddress
        );

        no.status = NodeOperatorStatus.EXIT;
        emit MigrateOperator(operatorId);
    }

    /// @notice Allows to unjail the validator and turn his status from UNSTAKED to ACTIVE.
    /// @dev when an operator is JAILED the owner can switch back and stake the
    /// operator by calling the unjail func, in this case, the operator status is set
    /// to back ACTIVE.
    function unjail() external override whenNotPaused {
        (uint256 operatorId, NodeOperator storage no) = getOperator(0);

        checkCondition(
            getOperatorStatus(no) == NodeOperatorStatus.JAILED,
            "Invalid status"
        );

        IValidator(no.validatorProxy).unjail(no.validatorId, stakeManager);

        emit Unjail(operatorId);
    }

    /// @notice Allows to top up heimdall fees.
    /// @dev the operator's owner can topUp the heimdall fees by calling the
    /// topUpForFee, but before that node operator needs to approve the amount of heimdall
    /// fees to his validatorProxy.
    /// @param _heimdallFee amount
    function topUpForFee(uint256 _heimdallFee)
        external
        override
        whenNotPaused
        checkHeimdallFees(_heimdallFee)
    {
        (uint256 operatorId, NodeOperator storage no) = getOperator(0);
        checkCondition(
            getOperatorStatus(no) == NodeOperatorStatus.ACTIVE,
            "Invalid status"
        );
        IValidator(no.validatorProxy).topUpForFee(
            msg.sender,
            _heimdallFee,
            stakeManager,
            polygonERC20
        );

        emit TopUpHeimdallFees(operatorId, _heimdallFee);
    }

    /// @notice Allows to unstake staked tokens after withdraw delay.
    /// @dev after the unstake the operator and waiting for the Polygon withdraw_delay
    /// the owner can transfer back his staked balance by calling
    /// unsttakeClaim, after that the operator status is set to CLAIMED
    function unstakeClaim() external override whenNotPaused {
        (uint256 operatorId, NodeOperator storage no) = getOperator(0);
        checkCondition(
            getOperatorStatus(no) == NodeOperatorStatus.UNSTAKED,
            "Invalid status"
        );
        uint256 amount = IValidator(no.validatorProxy).unstakeClaim(
            no.validatorId,
            msg.sender,
            stakeManager,
            polygonERC20
        );

        no.status = NodeOperatorStatus.CLAIMED;
        emit UnstakeClaim(operatorId, amount);
    }

    /// @notice Allows withdraw heimdall fees
    /// @dev the operator's owner can claim the heimdall fees.
    /// func, after that the operator status is set to EXIT.
    /// @param _accumFeeAmount accumulated heimdall fees
    /// @param _index index
    /// @param _proof proof
    function claimFee(
        uint256 _accumFeeAmount,
        uint256 _index,
        bytes memory _proof
    ) external override whenNotPaused {
        (uint256 operatorId, NodeOperator storage no) = getOperator(0);
        checkCondition(
            no.status == NodeOperatorStatus.CLAIMED,
            "Invalid status"
        );
        IValidator(no.validatorProxy).claimFee(
            _accumFeeAmount,
            _index,
            _proof,
            no.rewardAddress,
            stakeManager,
            polygonERC20
        );

        no.status = NodeOperatorStatus.EXIT;
        emit ClaimFee(operatorId);
    }

    /// @notice Allows the operator's owner to withdraw rewards.
    function withdrawRewards() external override whenNotPaused {
        (uint256 operatorId, NodeOperator storage no) = getOperator(0);
        checkCondition(
            getOperatorStatus(no) == NodeOperatorStatus.ACTIVE,
            "Invalid status"
        );
        address rewardAddress = no.rewardAddress;
        uint256 rewards = IValidator(no.validatorProxy).withdrawRewards(
            no.validatorId,
            rewardAddress,
            stakeManager,
            polygonERC20
        );

        emit WithdrawRewards(operatorId, rewardAddress, rewards);
    }

    /// @notice Allows the operator's owner to update signer publickey.
    /// @param _signerPubkey new signer publickey
    function updateSigner(bytes memory _signerPubkey)
        external
        override
        whenNotPaused
    {
        (uint256 operatorId, NodeOperator storage no) = getOperator(0);
        NodeOperatorStatus status = getOperatorStatus(no);
        checkCondition(
            status == NodeOperatorStatus.ACTIVE || status == NodeOperatorStatus.INACTIVE,
            "Invalid status"
        );
        if (status == NodeOperatorStatus.ACTIVE) {
            IValidator(no.validatorProxy).updateSigner(
                no.validatorId,
                _signerPubkey,
                stakeManager
            );
        }

        no.signerPubkey = _signerPubkey;

        emit UpdateSignerPubkey(operatorId);
    }

    /// @notice Allows the operator owner to update the name.
    /// @param _name new operator name.
    function setOperatorName(string memory _name)
        external
        override
        whenNotPaused
    {
        // uint256 operatorId = getOperatorId(msg.sender);
        // NodeOperator storage no = operators[operatorId];
        (uint256 operatorId, NodeOperator storage no) = getOperator(0);
        NodeOperatorStatus status = getOperatorStatus(no);

        checkCondition(
            status == NodeOperatorStatus.ACTIVE || status == NodeOperatorStatus.INACTIVE,
            "Invalid status"
        );
        no.name = _name;

        emit NewName(operatorId, _name);
    }

    /// @notice Allows the operator owner to update the rewardAddress.
    /// @param _rewardAddress new reward address.
    function setOperatorRewardAddress(address _rewardAddress)
        external
        override
        whenNotPaused
        checkIfRewardAddressIsUsed(_rewardAddress)
    {
        (uint256 operatorId, NodeOperator storage no) = getOperator(0);
        no.rewardAddress = _rewardAddress;

        operatorOwners[_rewardAddress] = operatorId;
        delete operatorOwners[msg.sender];

        emit NewRewardAddress(operatorId, _rewardAddress);
    }

    /// -------------------------------DAO--------------------------------------

    /// @notice Allows the DAO to set the operator defaultMaxDelegateLimit.
    /// @param _defaultMaxDelegateLimit default max delegation amount.
    function setDefaultMaxDelegateLimit(uint256 _defaultMaxDelegateLimit)
        external
        override
        userHasRole(DAO_ROLE)
        checkMaxDelegationLimit(_defaultMaxDelegateLimit)
    {
        defaultMaxDelegateLimit = _defaultMaxDelegateLimit;
    }

    /// @notice Allows the DAO to set the operator maxDelegateLimit.
    /// @param _operatorId operator id.
    /// @param _maxDelegateLimit max amount to delegate .
    function setMaxDelegateLimit(uint256 _operatorId, uint256 _maxDelegateLimit)
        external
        override
        userHasRole(DAO_ROLE)
        checkMaxDelegationLimit(_maxDelegateLimit)
    {
        (, NodeOperator storage no) = getOperator(_operatorId);
        no.maxDelegateLimit = _maxDelegateLimit;
    }

    /// @notice Allows to set the commission rate used.
    function setCommissionRate(uint256 _commissionRate)
        external
        override
        userHasRole(DAO_ROLE)
    {
        commissionRate = _commissionRate;
    }

    /// @notice Allows the dao to update commission rate for an operator.
    /// @param _operatorId id of the operator
    /// @param _newCommissionRate new commission rate
    function updateOperatorCommissionRate(
        uint256 _operatorId,
        uint256 _newCommissionRate
    ) external override userHasRole(DAO_ROLE) {
        (, NodeOperator storage no) = getOperator(_operatorId);
        NodeOperatorStatus status = getOperatorStatus(no);
        checkCondition(
            no.rewardAddress != address(0) ||
                status == NodeOperatorStatus.ACTIVE,
            "Invalid status"
        );

        if (status == NodeOperatorStatus.ACTIVE) {
            IValidator(no.validatorProxy).updateCommissionRate(
                no.validatorId,
                _newCommissionRate,
                stakeManager
            );
        }

        no.commissionRate = _newCommissionRate;

        emit UpdateCommissionRate(_operatorId, _newCommissionRate);
    }

    /// @notice Allows to update the stake amount and heimdall fees
    /// @param _minAmountStake min amount to stake
    /// @param _minHeimdallFees min amount of heimdall fees
    function setStakeAmountAndFees(
        uint256 _minAmountStake,
        uint256 _minHeimdallFees
    )
        external
        override
        userHasRole(DAO_ROLE)
        checkStakeAmount(_minAmountStake)
        checkHeimdallFees(_minHeimdallFees)
    {
        minAmountStake = _minAmountStake;
        minHeimdallFees = _minHeimdallFees;
    }

    /// @notice Allows to pause the contract.
    function togglePause() external override userHasRole(PAUSE_OPERATOR_ROLE) {
        paused() ? _unpause() : _pause();
    }

    /// @notice Allows to toggle restake.
    function setRestake(bool _restake) external override userHasRole(DAO_ROLE) {
        allowsRestake = _restake;
    }

    /// @notice Allows to set the StMATIC contract address.
    function setStMATIC(address _stMATIC)
        external
        override
        userHasRole(DAO_ROLE)
    {
        stMATIC = _stMATIC;
    }

    /// @notice Allows to set the validator factory contract address.
    function setValidatorFactory(address _validatorFactory)
        external
        override
        userHasRole(DAO_ROLE)
    {
        validatorFactory = _validatorFactory;
    }

    /// @notice Allows to set the stake manager contract address.
    function setStakeManager(address _stakeManager)
        external
        override
        userHasRole(DAO_ROLE)
    {
        stakeManager = _stakeManager;
    }

    /// @notice Allows to set the contract version.
    /// @param _version contract version
    function setVersion(string memory _version)
        external
        override
        userHasRole(DEFAULT_ADMIN_ROLE)
    {
        version = _version;
    }

    /// @notice Allows to get a node operator by msg.sender.
    /// @param _owner a valid address of an operator owner, if not set msg.sender will be used.
    /// @return op returns a node operator.
    function getNodeOperator(address _owner)
        external
        view
        returns (NodeOperator memory)
    {
        uint256 operatorId = operatorOwners[_owner];
        return _getNodeOperator(operatorId);
    }

    /// @notice Allows to get a node operator by _operatorId.
    /// @param _operatorId the id of the operator.
    /// @return op returns a node operator.
    function getNodeOperator(uint256 _operatorId)
        external
        view
        returns (NodeOperator memory)
    {
        return _getNodeOperator(_operatorId);
    }

    function _getNodeOperator(uint256 _operatorId)
        private
        view
        returns (NodeOperator memory)
    {
        (, NodeOperator memory nodeOperator) = getOperator(_operatorId);
        nodeOperator.status = getOperatorStatus(nodeOperator);
        return nodeOperator;
    }

    function getOperatorStatus(NodeOperator memory _op)
        private
        view
        returns (NodeOperatorStatus res)
    {
        if (_op.status == NodeOperatorStatus.STOPPED) {
            res = NodeOperatorStatus.STOPPED;
        } else if (_op.status == NodeOperatorStatus.CLAIMED) {
            res = NodeOperatorStatus.CLAIMED;
        } else if (_op.status == NodeOperatorStatus.EXIT) {
            res = NodeOperatorStatus.EXIT;
        } else if (_op.status == NodeOperatorStatus.UNSTAKED) {
            res = NodeOperatorStatus.UNSTAKED;
        } else {
            IStakeManager.Validator memory v = IStakeManager(stakeManager)
                .validators(_op.validatorId);
            if (
                v.status == IStakeManager.Status.Active &&
                v.deactivationEpoch == 0
            ) {
                res = NodeOperatorStatus.ACTIVE;
            } else if (
                (
                    v.status == IStakeManager.Status.Active ||
                    v.status == IStakeManager.Status.Locked
                ) &&
                v.deactivationEpoch != 0
            ) {
                res = NodeOperatorStatus.EJECTED;
            } else if (
                v.status == IStakeManager.Status.Locked &&
                v.deactivationEpoch == 0
            ) {
                res = NodeOperatorStatus.JAILED;
            } else {
                res = NodeOperatorStatus.INACTIVE;
            }
        }
    }

    /// @notice Allows to get a validator share address.
    /// @param _operatorId the id of the operator.
    /// @return va returns a stake manager validator.
    function getValidatorShare(uint256 _operatorId)
        external
        view
        returns (address)
    {
        (, NodeOperator memory op) = getOperator(_operatorId);
        return op.validatorShare;
    }

    /// @notice Allows to get a validator from stake manager.
    /// @param _operatorId the id of the operator.
    /// @return va returns a stake manager validator.
    function getValidator(uint256 _operatorId)
        external
        view
        returns (IStakeManager.Validator memory va)
    {
        (, NodeOperator memory op) = getOperator(_operatorId);
        va = IStakeManager(stakeManager).validators(op.validatorId);
    }

    /// @notice Allows to get a validator from stake manager.
    /// @param _owner user address.
    /// @return va returns a stake manager validator.
    function getValidator(address _owner)
        external
        view
        returns (IStakeManager.Validator memory va)
    {
        (, NodeOperator memory op) = getOperator(operatorOwners[_owner]);
        va = IStakeManager(stakeManager).validators(op.validatorId);
    }

    /// @notice Get the stMATIC contract addresses
    function getContracts()
        external
        view
        override
        returns (
            address _validatorFactory,
            address _stakeManager,
            address _polygonERC20,
            address _stMATIC
        )
    {
        _validatorFactory = validatorFactory;
        _stakeManager = stakeManager;
        _polygonERC20 = polygonERC20;
        _stMATIC = stMATIC;
    }

    /// @notice Get the global state
    function getState()
        external
        view
        override
        returns (
            uint256 _totalNodeOperator,
            uint256 _totalInactiveNodeOperator,
            uint256 _totalActiveNodeOperator,
            uint256 _totalStoppedNodeOperator,
            uint256 _totalUnstakedNodeOperator,
            uint256 _totalClaimedNodeOperator,
            uint256 _totalExitNodeOperator,
            uint256 _totalJailedNodeOperator,
            uint256 _totalEjectedNodeOperator
        )
    {
        uint256 operatorIdsLength = operatorIds.length;
        _totalNodeOperator = operatorIdsLength;
        for (uint256 idx = 0; idx < operatorIdsLength; idx++) {
            uint256 operatorId = operatorIds[idx];
            NodeOperator memory op = operators[operatorId];
            NodeOperatorStatus status = getOperatorStatus(op);

            if (status == NodeOperatorStatus.INACTIVE) {
                _totalInactiveNodeOperator++;
            } else if (status == NodeOperatorStatus.ACTIVE) {
                _totalActiveNodeOperator++;
            } else if (status == NodeOperatorStatus.STOPPED) {
                _totalStoppedNodeOperator++;
            } else if (status == NodeOperatorStatus.UNSTAKED) {
                _totalUnstakedNodeOperator++;
            } else if (status == NodeOperatorStatus.CLAIMED) {
                _totalClaimedNodeOperator++;
            } else if (status == NodeOperatorStatus.JAILED) {
                _totalJailedNodeOperator++;
            } else if (status == NodeOperatorStatus.EJECTED) {
                _totalEjectedNodeOperator++;
            } else {
                _totalExitNodeOperator++;
            }
        }
    }

    /// @notice Get operatorIds.
    function getOperatorIds()
        external
        view
        override
        returns (uint256[] memory)
    {
        return operatorIds;
    }

    /// @notice Returns an operatorInfo list.
    /// @param _allWithStake if true return all operators with ACTIVE, EJECTED, JAILED.
    /// @param _delegation if true return all operators that delegation is set to true.
    /// @return Returns a list of operatorInfo.
    function getOperatorInfos(
        bool _delegation,
        bool _allWithStake
    ) external view override returns (Operator.OperatorInfo[] memory) {
        Operator.OperatorInfo[]
            memory operatorInfos = new Operator.OperatorInfo[](
                totalNodeOperators
            );

        uint256 length = operatorIds.length;
        uint256 index;

        for (uint256 idx = 0; idx < length; idx++) {
            uint256 operatorId = operatorIds[idx];
            NodeOperator storage no = operators[operatorId];
            NodeOperatorStatus status = getOperatorStatus(no);

            // if operator status is not ACTIVE we continue. But, if _allWithStake is true
            // we include EJECTED and JAILED operators.
            if (
                status != NodeOperatorStatus.ACTIVE &&
                !(_allWithStake &&
                    (status == NodeOperatorStatus.EJECTED ||
                        status == NodeOperatorStatus.JAILED))
            ) continue;

            // if true we check if the operator delegation is true.
            if (_delegation) {
                if (!IValidatorShare(no.validatorShare).delegation()) continue;
            }

            operatorInfos[index] = Operator.OperatorInfo({
                operatorId: operatorId,
                validatorShare: no.validatorShare,
                maxDelegateLimit: no.maxDelegateLimit,
                rewardAddress: no.rewardAddress
            });
            index++;
        }
        if (index != totalNodeOperators) {
            Operator.OperatorInfo[]
                memory operatorInfosOut = new Operator.OperatorInfo[](index);

            for (uint256 i = 0; i < index; i++) {
                operatorInfosOut[i] = operatorInfos[i];
            }
            return operatorInfosOut;
        }
        return operatorInfos;
    }

    /// @notice Checks condition and displays the message
    /// @param _condition a condition
    /// @param _message message to display
    function checkCondition(bool _condition, string memory _message)
        private
        pure
    {
        require(_condition, _message);
    }

    /// @notice Retrieve the operator struct based on the operatorId
    /// @param _operatorId id of the operator
    /// @return NodeOperator structure
    function getOperator(uint256 _operatorId)
        private
        view
        returns (uint256, NodeOperator storage)
    {
        if (_operatorId == 0) {
            _operatorId = getOperatorId(msg.sender);
        }
        NodeOperator storage no = operators[_operatorId];
        require(no.rewardAddress != address(0), "Operator not found");
        return (_operatorId, no);
    }

    /// @notice Retrieve the operator struct based on the operator owner address
    /// @param _user address of the operator owner
    /// @return NodeOperator structure
    function getOperatorId(address _user) private view returns (uint256) {
        uint256 operatorId = operatorOwners[_user];
        checkCondition(operatorId != 0, "Operator not found");
        return operatorId;
    }

    /// -------------------------------Events-----------------------------------

    /// @notice A new node operator was added.
    /// @param operatorId node operator id.
    event AddOperator(uint256 operatorId);

    /// @notice A new node operator joined.
    /// @param operatorId node operator id.
    event JoinOperator(uint256 operatorId);

    /// @notice A node operator was removed.
    /// @param operatorId node operator id.
    event RemoveOperator(uint256 operatorId);

    /// @param operatorId node operator id.
    event StopOperator(uint256 operatorId);

    /// @param operatorId node operator id.
    event MigrateOperator(uint256 operatorId);

    /// @notice A node operator was staked.
    /// @param operatorId node operator id.
    event StakeOperator(
        uint256 operatorId,
        uint256 amount,
        uint256 heimdallFees
    );

    /// @notice A node operator restaked.
    /// @param operatorId node operator id.
    /// @param amount amount to restake.
    /// @param restakeRewards restake rewards.
    event RestakeOperator(
        uint256 operatorId,
        uint256 amount,
        bool restakeRewards
    );

    /// @notice A node operator was unstaked.
    /// @param operatorId node operator id.
    event UnstakeOperator(uint256 operatorId);

    /// @notice TopUp heimadall fees.
    /// @param operatorId node operator id.
    /// @param amount amount.
    event TopUpHeimdallFees(uint256 operatorId, uint256 amount);

    /// @notice Withdraw rewards.
    /// @param operatorId node operator id.
    /// @param rewardAddress reward address.
    /// @param amount amount.
    event WithdrawRewards(
        uint256 operatorId,
        address rewardAddress,
        uint256 amount
    );

    /// @notice claims unstake.
    /// @param operatorId node operator id.
    /// @param amount amount.
    event UnstakeClaim(uint256 operatorId, uint256 amount);

    /// @notice update signer publickey.
    /// @param operatorId node operator id.
    event UpdateSignerPubkey(uint256 operatorId);

    /// @notice claim herimdall fee.
    /// @param operatorId node operator id.
    event ClaimFee(uint256 operatorId);

    /// @notice update commission rate.
    event UpdateCommissionRate(uint256 operatorId, uint256 newCommissionRate);

    /// @notice Unjail a validator.
    event Unjail(uint256 operatorId);

    /// @notice update operator name.
    event NewName(uint256 operatorId, string name);

    /// @notice update operator name.
    event NewRewardAddress(uint256 operatorId, address rewardAddress);
}

File 2 of 29 : PausableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/Pausable.sol)

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import "../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 {
    /**
     * @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);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    function __Pausable_init() internal onlyInitializing {
        __Context_init_unchained();
        __Pausable_init_unchained();
    }

    function __Pausable_init_unchained() internal onlyInitializing {
        _paused = false;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

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

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

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

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
    uint256[49] private __gap;
}

File 3 of 29 : AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/AccessControl.sol)

pragma solidity ^0.8.0;

import "./IAccessControlUpgradeable.sol";
import "../utils/ContextUpgradeable.sol";
import "../utils/StringsUpgradeable.sol";
import "../utils/introspection/ERC165Upgradeable.sol";
import "../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:
 *
 * ```
 * 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}:
 *
 * ```
 * 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.
 */
abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable {
    function __AccessControl_init() internal onlyInitializing {
        __Context_init_unchained();
        __ERC165_init_unchained();
        __AccessControl_init_unchained();
    }

    function __AccessControl_init_unchained() internal onlyInitializing {
    }
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role, _msgSender());
        _;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId);
    }

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

    /**
     * @dev Revert with a standard message if `account` is missing `role`.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     */
    function _checkRole(bytes32 role, address account) internal view {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        StringsUpgradeable.toHexString(uint160(account), 20),
                        " is missing role ",
                        StringsUpgradeable.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

    /**
     * @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 override returns (bytes32) {
        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.
     */
    function grantRole(bytes32 role, address account) public virtual override 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.
     */
    function revokeRole(bytes32 role, address account) public virtual override 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 `account`.
     */
    function renounceRole(bytes32 role, address account) public virtual override {
        require(account == _msgSender(), "AccessControl: can only renounce roles for self");

        _revokeRole(role, account);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     *
     * NOTE: This function is deprecated in favor of {_grantRole}.
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

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

    /**
     * @dev Grants `role` to `account`.
     *
     * Internal function without access restriction.
     */
    function _grantRole(bytes32 role, address account) internal virtual {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * Internal function without access restriction.
     */
    function _revokeRole(bytes32 role, address account) internal virtual {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }
    uint256[49] private __gap;
}

File 4 of 29 : ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;
import "../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 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;

    uint256 private _status;

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

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        _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() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
    uint256[49] private __gap;
}

File 5 of 29 : INodeOperatorRegistry.sol
// SPDX-FileCopyrightText: 2021 ShardLabs
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.7;

import "../lib/Operator.sol";

/// @title INodeOperatorRegistry
/// @author 2021 ShardLabs
/// @notice Node operator registry interface
interface INodeOperatorRegistry {
    /// @notice Allows to add a new node operator to the system.
    /// @param _name the node operator name.
    /// @param _rewardAddress public address used for ACL and receive rewards.
    /// @param _signerPubkey public key used on heimdall len 64 bytes.
    function addOperator(
        string memory _name,
        address _rewardAddress,
        bytes memory _signerPubkey
    ) external;

    /// @notice Allows to stop a node operator.
    /// @param _operatorId node operator id.
    function stopOperator(uint256 _operatorId) external;

    /// @notice Allows to remove a node operator from the system.
    /// @param _operatorId node operator id.
    function removeOperator(uint256 _operatorId) external;

    /// @notice Allows a staked validator to join the system.
    function joinOperator() external;

    /// @notice Allows to stake an operator on the Polygon stakeManager.
    /// This function calls Polygon transferFrom so the totalAmount(_amount + _heimdallFee)
    /// has to be approved first.
    /// @param _amount amount to stake.
    /// @param _heimdallFee heimdallFee to stake.
    function stake(uint256 _amount, uint256 _heimdallFee) external;

    /// @notice Restake Matics for a validator on polygon stake manager.
    /// @param _amount amount to stake.
    /// @param _restakeRewards restake rewards.
    function restake(uint256 _amount, bool _restakeRewards) external;

    /// @notice Allows the operator's owner to migrate the NFT. This can be done only
    /// if the DAO stopped the operator.
    function migrate() external;

    /// @notice Allows to unstake an operator from the stakeManager. After the withdraw_delay
    /// the operator owner can call claimStake func to withdraw the staked tokens.
    function unstake() external;

    /// @notice Allows to topup heimdall fees on polygon stakeManager.
    /// @param _heimdallFee amount to topup.
    function topUpForFee(uint256 _heimdallFee) external;

    /// @notice Allows to claim staked tokens on the stake Manager after the end of the
    /// withdraw delay
    function unstakeClaim() external;

    /// @notice Allows an owner to withdraw rewards from the stakeManager.
    function withdrawRewards() external;

    /// @notice Allows to update the signer pubkey
    /// @param _signerPubkey update signer public key
    function updateSigner(bytes memory _signerPubkey) external;

    /// @notice Allows to claim the heimdall fees staked by the owner of the operator
    /// @param _accumFeeAmount accumulated fees amount
    /// @param _index index
    /// @param _proof proof
    function claimFee(
        uint256 _accumFeeAmount,
        uint256 _index,
        bytes memory _proof
    ) external;

    /// @notice Allows to unjail a validator and switch from UNSTAKE status to STAKED
    function unjail() external;

    /// @notice Allows an operator's owner to set the operator name.
    function setOperatorName(string memory _name) external;

    /// @notice Allows an operator's owner to set the operator rewardAddress.
    function setOperatorRewardAddress(address _rewardAddress) external;

    /// @notice Allows the DAO to set _defaultMaxDelegateLimit.
    function setDefaultMaxDelegateLimit(uint256 _defaultMaxDelegateLimit)
        external;

    /// @notice Allows the DAO to set _maxDelegateLimit for an operator.
    function setMaxDelegateLimit(uint256 _operatorId, uint256 _maxDelegateLimit)
        external;

    /// @notice Allows the DAO to set _commissionRate.
    function setCommissionRate(uint256 _commissionRate) external;

    /// @notice Allows the DAO to set _commissionRate for an operator.
    /// @param _operatorId id of the operator
    /// @param _newCommissionRate new commission rate
    function updateOperatorCommissionRate(
        uint256 _operatorId,
        uint256 _newCommissionRate
    ) external;

    /// @notice Allows the DAO to set _minAmountStake and _minHeimdallFees.
    function setStakeAmountAndFees(
        uint256 _minAmountStake,
        uint256 _minHeimdallFees
    ) external;

    /// @notice Allows to pause/unpause the node operator contract.
    function togglePause() external;

    /// @notice Allows the DAO to enable/disable restake.
    function setRestake(bool _restake) external;

    /// @notice Allows the DAO to set stMATIC contract.
    function setStMATIC(address _stMATIC) external;

    /// @notice Allows the DAO to set validator factory contract.
    function setValidatorFactory(address _validatorFactory) external;

    /// @notice Allows the DAO to set stake manager contract.
    function setStakeManager(address _stakeManager) external;

    /// @notice Allows to set contract version.
    function setVersion(string memory _version) external;

    /// @notice Get the stMATIC contract addresses
    function getContracts()
        external
        view
        returns (
            address _validatorFactory,
            address _stakeManager,
            address _polygonERC20,
            address _stMATIC
        );

    /// @notice Allows to get stats.
    function getState()
        external
        view
        returns (
            uint256 _totalNodeOperator,
            uint256 _totalInactiveNodeOperator,
            uint256 _totalActiveNodeOperator,
            uint256 _totalStoppedNodeOperator,
            uint256 _totalUnstakedNodeOperator,
            uint256 _totalClaimedNodeOperator,
            uint256 _totalExitNodeOperator,
            uint256 _totalSlashedNodeOperator,
            uint256 _totalEjectedNodeOperator
        );

    /// @notice Allows to get a list of operatorInfo.
    function getOperatorInfos(bool _delegation, bool _allActive)
        external
        view
        returns (Operator.OperatorInfo[] memory);


    /// @notice Allows to get all the operator ids.
    function getOperatorIds() external view returns (uint256[] memory);
}

File 6 of 29 : IValidatorFactory.sol
// SPDX-FileCopyrightText: 2021 ShardLabs
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.7;

import "../Validator.sol";

/// @title IValidatorFactory.
/// @author 2021 ShardLabs
interface IValidatorFactory {
    /// @notice Deploy a new validator proxy contract.
    /// @return return the address of the deployed contract.
    function create() external returns (address);

    /// @notice Remove a validator proxy from the validators.
    function remove(address _validatorProxy) external;

    /// @notice Set the node operator contract address.
    function setOperator(address _operator) external;

    /// @notice Set validator implementation contract address.
    function setValidatorImplementation(address _validatorImplementation)
        external;
}

File 7 of 29 : IValidator.sol
// SPDX-FileCopyrightText: 2021 ShardLabs
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.7;

import "../Validator.sol";

/// @title IValidator.
/// @author 2021 ShardLabs
/// @notice Validator interface.
interface IValidator {
    /// @notice Allows to stake a validator on the Polygon stakeManager contract.
    /// @dev Stake a validator on the Polygon stakeManager contract.
    /// @param _sender msg.sender.
    /// @param _amount amount to stake.
    /// @param _heimdallFee herimdall fees.
    /// @param _acceptDelegation accept delegation.
    /// @param _signerPubkey signer public key used on the heimdall.
    /// @param _commisionRate commision rate of a validator
    function stake(
        address _sender,
        uint256 _amount,
        uint256 _heimdallFee,
        bool _acceptDelegation,
        bytes memory _signerPubkey,
        uint256 _commisionRate,
        address stakeManager,
        address polygonERC20
    ) external returns (uint256, address);

    /// @notice Restake Matics for a validator on polygon stake manager.
    /// @param sender operator owner which approved tokens to the validato contract.
    /// @param validatorId validator id.
    /// @param amount amount to stake.
    /// @param stakeRewards restake rewards.
    /// @param stakeManager stake manager address
    /// @param polygonERC20 address of the MATIC token
    function restake(
        address sender,
        uint256 validatorId,
        uint256 amount,
        bool stakeRewards,
        address stakeManager,
        address polygonERC20
    ) external;

    /// @notice Unstake a validator from the Polygon stakeManager contract.
    /// @dev Unstake a validator from the Polygon stakeManager contract by passing the validatorId
    /// @param _validatorId validatorId.
    /// @param _stakeManager address of the stake manager
    function unstake(uint256 _validatorId, address _stakeManager) external;

    /// @notice Allows to top up heimdall fees.
    /// @param _heimdallFee amount
    /// @param _sender msg.sender
    /// @param _stakeManager stake manager address
    /// @param _polygonERC20 address of the MATIC token
    function topUpForFee(
        address _sender,
        uint256 _heimdallFee,
        address _stakeManager,
        address _polygonERC20
    ) external;

    /// @notice Allows to withdraw rewards from the validator.
    /// @dev Allows to withdraw rewards from the validator using the _validatorId. Only the
    /// owner can request withdraw in this the owner is this contract.
    /// @param _validatorId validator id.
    /// @param _rewardAddress user address used to transfer the staked tokens.
    /// @param _stakeManager stake manager address
    /// @param _polygonERC20 address of the MATIC token
    /// @return Returns the amount transfered to the user.
    function withdrawRewards(
        uint256 _validatorId,
        address _rewardAddress,
        address _stakeManager,
        address _polygonERC20
    ) external returns (uint256);

    /// @notice Allows to claim staked tokens on the stake Manager after the end of the
    /// withdraw delay
    /// @param _validatorId validator id.
    /// @param _rewardAddress user address used to transfer the staked tokens.
    /// @return Returns the amount transfered to the user.
    function unstakeClaim(
        uint256 _validatorId,
        address _rewardAddress,
        address _stakeManager,
        address _polygonERC20
    ) external returns (uint256);

    /// @notice Allows to update the signer pubkey
    /// @param _validatorId validator id
    /// @param _signerPubkey update signer public key
    /// @param _stakeManager stake manager address
    function updateSigner(
        uint256 _validatorId,
        bytes memory _signerPubkey,
        address _stakeManager
    ) external;

    /// @notice Allows to claim the heimdall fees.
    /// @param _accumFeeAmount accumulated fees amount
    /// @param _index index
    /// @param _proof proof
    /// @param _ownerRecipient owner recipient
    /// @param _stakeManager stake manager address
    /// @param _polygonERC20 address of the MATIC token
    function claimFee(
        uint256 _accumFeeAmount,
        uint256 _index,
        bytes memory _proof,
        address _ownerRecipient,
        address _stakeManager,
        address _polygonERC20
    ) external;

    /// @notice Allows to update the commision rate of a validator
    /// @param _validatorId operator id
    /// @param _newCommissionRate commission rate
    /// @param _stakeManager stake manager address
    function updateCommissionRate(
        uint256 _validatorId,
        uint256 _newCommissionRate,
        address _stakeManager
    ) external;

    /// @notice Allows to unjail a validator.
    /// @param _validatorId operator id
    function unjail(uint256 _validatorId, address _stakeManager) external;

    /// @notice Allows to migrate the ownership to an other user.
    /// @param _validatorId operator id.
    /// @param _stakeManagerNFT stake manager nft contract.
    /// @param _rewardAddress reward address.
    function migrate(
        uint256 _validatorId,
        address _stakeManagerNFT,
        address _rewardAddress
    ) external;

    /// @notice Allows a validator that was already staked on the polygon stake manager
    /// to join the PoLido protocol.
    /// @param _validatorId validator id
    /// @param _stakeManagerNFT address of the staking NFT
    /// @param _rewardAddress address that will receive the rewards from staking
    /// @param _newCommissionRate commission rate
    /// @param _stakeManager address of the stake manager
    function join(
        uint256 _validatorId,
        address _stakeManagerNFT,
        address _rewardAddress,
        uint256 _newCommissionRate,
        address _stakeManager
    ) external;
}

File 8 of 29 : IStMATIC.sol
// SPDX-FileCopyrightText: 2021 ShardLabs
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.7;

import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";

import "./IValidatorShare.sol";
import "./INodeOperatorRegistry.sol";
import "./INodeOperatorRegistry.sol";
import "./IStakeManager.sol";
import "./IPoLidoNFT.sol";
import "./IFxStateRootTunnel.sol";

/// @title StMATIC interface.
/// @author 2021 ShardLabs
interface IStMATIC is IERC20Upgradeable {
    struct RequestWithdraw {
        uint256 amount2WithdrawFromStMATIC;
        uint256 validatorNonce;
        uint256 requestEpoch;
        address validatorAddress;
    }

    struct FeeDistribution {
        uint8 dao;
        uint8 operators;
        uint8 insurance;
    }

    function withdrawTotalDelegated(address _validatorShare) external;

    function nodeOperatorRegistry() external returns (INodeOperatorRegistry);

    function entityFees()
        external
        returns (
            uint8,
            uint8,
            uint8
        );

    function getMaticFromTokenId(uint256 _tokenId)
        external
        view
        returns (uint256);

    function stakeManager() external view returns (IStakeManager);

    function poLidoNFT() external view returns (IPoLidoNFT);

    function fxStateRootTunnel() external view returns (IFxStateRootTunnel);

    function version() external view returns (string memory);

    function dao() external view returns (address);

    function insurance() external view returns (address);

    function token() external view returns (address);

    function lastWithdrawnValidatorId() external view returns (uint256);

    function totalBuffered() external view returns (uint256);

    function delegationLowerBound() external view returns (uint256);

    function rewardDistributionLowerBound() external view returns (uint256);

    function reservedFunds() external view returns (uint256);

    function submitThreshold() external view returns (uint256);

    function submitHandler() external view returns (bool);

    function getMinValidatorBalance() external view returns (uint256);

    function token2WithdrawRequest(uint256 _requestId)
        external
        view
        returns (
            uint256,
            uint256,
            uint256,
            address
        );

    function DAO() external view returns (bytes32);

    function initialize(
        address _nodeOperatorRegistry,
        address _token,
        address _dao,
        address _insurance,
        address _stakeManager,
        address _poLidoNFT,
        address _fxStateRootTunnel,
        uint256 _submitThreshold
    ) external;

    function submit(uint256 _amount) external returns (uint256);

    function requestWithdraw(uint256 _amount) external;

    function delegate() external;

    function claimTokens(uint256 _tokenId) external;

    function distributeRewards() external;

    function claimTokens2StMatic(uint256 _tokenId) external;

    function togglePause() external;

    function getTotalStake(IValidatorShare _validatorShare)
        external
        view
        returns (uint256, uint256);

    function getLiquidRewards(IValidatorShare _validatorShare)
        external
        view
        returns (uint256);

    function getTotalStakeAcrossAllValidators() external view returns (uint256);

    function getTotalPooledMatic() external view returns (uint256);

    function convertStMaticToMatic(uint256 _balance)
        external
        view
        returns (
            uint256,
            uint256,
            uint256
        );

    function convertMaticToStMatic(uint256 _balance)
        external
        view
        returns (
            uint256,
            uint256,
            uint256
        );

    function setFees(
        uint8 _daoFee,
        uint8 _operatorsFee,
        uint8 _insuranceFee
    ) external;

    function setDaoAddress(address _address) external;

    function setInsuranceAddress(address _address) external;

    function setNodeOperatorRegistryAddress(address _address) external;

    function setDelegationLowerBound(uint256 _delegationLowerBound) external;

    function setRewardDistributionLowerBound(
        uint256 _rewardDistributionLowerBound
    ) external;

    function setPoLidoNFT(address _poLidoNFT) external;

    function setFxStateRootTunnel(address _fxStateRootTunnel) external;

    function setSubmitThreshold(uint256 _submitThreshold) external;

    function flipSubmitHandler() external;

    function setVersion(string calldata _version) external;
}

File 9 of 29 : ContextUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract ContextUpgradeable is Initializable {
    function __Context_init() internal onlyInitializing {
        __Context_init_unchained();
    }

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
    uint256[50] private __gap;
}

File 10 of 29 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/utils/Initializable.sol)

pragma solidity ^0.8.0;

import "../../utils/AddressUpgradeable.sol";

/**
 * @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 a proxied contract can't have 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.
 *
 * 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 initialize the implementation contract, you can either invoke the
 * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() initializer {}
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     */
    bool private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Modifier to protect an initializer function from being invoked twice.
     */
    modifier initializer() {
        // If the contract is initializing we ignore whether _initialized is set in order to support multiple
        // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the
        // contract may have been reentered.
        require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized");

        bool isTopLevelCall = !_initializing;
        if (isTopLevelCall) {
            _initializing = true;
            _initialized = true;
        }

        _;

        if (isTopLevelCall) {
            _initializing = false;
        }
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} modifier, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    function _isConstructor() private view returns (bool) {
        return !AddressUpgradeable.isContract(address(this));
    }
}

File 11 of 29 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Address.sol)

pragma solidity ^0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 12 of 29 : IAccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControlUpgradeable {
    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @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.
     */
    function grantRole(bytes32 role, address account) external;

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

    /**
     * @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 granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) external;
}

File 13 of 29 : StringsUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library StringsUpgradeable {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _HEX_SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }
}

File 14 of 29 : ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./IERC165Upgradeable.sol";
import "../../proxy/utils/Initializable.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable {
    function __ERC165_init() internal onlyInitializing {
        __ERC165_init_unchained();
    }

    function __ERC165_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165Upgradeable).interfaceId;
    }
    uint256[50] private __gap;
}

File 15 of 29 : IERC165Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165Upgradeable {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

File 16 of 29 : Operator.sol
// SPDX-FileCopyrightText: 2021 ShardLabs
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.7;

library Operator {
    struct OperatorInfo {
        uint256 operatorId;
        address validatorShare;
        uint256 maxDelegateLimit;
        address rewardAddress;
    }
}

File 17 of 29 : Validator.sol
// SPDX-FileCopyrightText: 2021 ShardLabs
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.7;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";

import "./interfaces/IStakeManager.sol";
import "./interfaces/IValidator.sol";
import "./interfaces/INodeOperatorRegistry.sol";

/// @title ValidatorImplementation
/// @author 2021 ShardLabs.
/// @notice The validator contract is a simple implementation of the stakeManager API, the
/// ValidatorProxies use this contract to interact with the stakeManager.
/// When a ValidatorProxy calls this implementation the state is copied
/// (owner, implementation, operatorRegistry), then they are used to check if the msg-sender is the
/// node operator contract, and if the validatorProxy implementation match with the current
/// validator contract.
contract Validator is IERC721Receiver, IValidator {
    using SafeERC20 for IERC20;

    address private implementation;
    address private operatorRegistry;
    address private validatorFactory;

    /// @notice Check if the operator contract is the msg.sender.
    modifier isOperatorRegistry() {
        require(
            msg.sender == operatorRegistry,
            "Caller should be the operator contract"
        );
        _;
    }

    /// @notice Allows to stake on the Polygon stakeManager contract by
    /// calling stakeFor function and set the user as the equal to this validator proxy
    /// address.
    /// @param _sender the address of the operator-owner that approved Matics.
    /// @param _amount the amount to stake with.
    /// @param _heimdallFee the heimdall fees.
    /// @param _acceptDelegation accept delegation.
    /// @param _signerPubkey signer public key used on the heimdall node.
    /// @param _commissionRate validator commision rate
    /// @return Returns the validatorId and the validatorShare contract address.
    function stake(
        address _sender,
        uint256 _amount,
        uint256 _heimdallFee,
        bool _acceptDelegation,
        bytes memory _signerPubkey,
        uint256 _commissionRate,
        address _stakeManager,
        address _polygonERC20
    ) external override isOperatorRegistry returns (uint256, address) {
        IStakeManager stakeManager = IStakeManager(_stakeManager);
        IERC20 polygonERC20 = IERC20(_polygonERC20);

        uint256 totalAmount = _amount + _heimdallFee;
        polygonERC20.safeTransferFrom(_sender, address(this), totalAmount);
        polygonERC20.safeApprove(address(stakeManager), totalAmount);
        stakeManager.stakeFor(
            address(this),
            _amount,
            _heimdallFee,
            _acceptDelegation,
            _signerPubkey
        );

        uint256 validatorId = stakeManager.getValidatorId(address(this));
        address validatorShare = stakeManager.getValidatorContract(validatorId);
        if (_commissionRate > 0) {
            stakeManager.updateCommissionRate(validatorId, _commissionRate);
        }

        return (validatorId, validatorShare);
    }

    /// @notice Restake validator rewards or new Matics validator on stake manager.
    /// @param _sender operator's owner that approved tokens to the validator contract.
    /// @param _validatorId validator id.
    /// @param _amount amount to stake.
    /// @param _stakeRewards restake rewards.
    /// @param _stakeManager stake manager address
    /// @param _polygonERC20 address of the MATIC token
    function restake(
        address _sender,
        uint256 _validatorId,
        uint256 _amount,
        bool _stakeRewards,
        address _stakeManager,
        address _polygonERC20
    ) external override isOperatorRegistry {
        if (_amount > 0) {
            IERC20 polygonERC20 = IERC20(_polygonERC20);
            polygonERC20.safeTransferFrom(_sender, address(this), _amount);
            polygonERC20.safeApprove(address(_stakeManager), _amount);
        }
        IStakeManager(_stakeManager).restake(_validatorId, _amount, _stakeRewards);
    }

    /// @notice Unstake a validator from the Polygon stakeManager contract.
    /// @param _validatorId validatorId.
    /// @param _stakeManager address of the stake manager
    function unstake(uint256 _validatorId, address _stakeManager)
        external
        override
        isOperatorRegistry
    {
        // stakeManager
        IStakeManager(_stakeManager).unstake(_validatorId);
    }

    /// @notice Allows a validator to top-up the heimdall fees.
    /// @param _sender address that approved the _heimdallFee amount.
    /// @param _heimdallFee amount.
    /// @param _stakeManager stake manager address
    /// @param _polygonERC20 address of the MATIC token
    function topUpForFee(
        address _sender,
        uint256 _heimdallFee,
        address _stakeManager,
        address _polygonERC20
    ) external override isOperatorRegistry {
        IStakeManager stakeManager = IStakeManager(_stakeManager);
        IERC20 polygonERC20 = IERC20(_polygonERC20);

        polygonERC20.safeTransferFrom(_sender, address(this), _heimdallFee);
        polygonERC20.safeApprove(address(stakeManager), _heimdallFee);
        stakeManager.topUpForFee(address(this), _heimdallFee);
    }

    /// @notice Allows to withdraw rewards from the validator using the _validatorId. Only the
    /// owner can request withdraw. The rewards are transfered to the _rewardAddress.
    /// @param _validatorId validator id.
    /// @param _rewardAddress reward address.
    /// @param _stakeManager stake manager address
    /// @param _polygonERC20 address of the MATIC token
    function withdrawRewards(
        uint256 _validatorId,
        address _rewardAddress,
        address _stakeManager,
        address _polygonERC20
    ) external override isOperatorRegistry returns (uint256) {
        IStakeManager(_stakeManager).withdrawRewards(_validatorId);

        IERC20 polygonERC20 = IERC20(_polygonERC20);
        uint256 balance = polygonERC20.balanceOf(address(this));
        polygonERC20.safeTransfer(_rewardAddress, balance);

        return balance;
    }

    /// @notice Allows to unstake the staked tokens (+rewards) and transfer them
    /// to the owner rewardAddress.
    /// @param _validatorId validator id.
    /// @param _rewardAddress rewardAddress address.
    /// @param _stakeManager stake manager address
    /// @param _polygonERC20 address of the MATIC token
    function unstakeClaim(
        uint256 _validatorId,
        address _rewardAddress,
        address _stakeManager,
        address _polygonERC20
    ) external override isOperatorRegistry returns (uint256) {
        IStakeManager stakeManager = IStakeManager(_stakeManager);
        stakeManager.unstakeClaim(_validatorId);
        // polygonERC20
        // stakeManager
        IERC20 polygonERC20 = IERC20(_polygonERC20);
        uint256 balance = polygonERC20.balanceOf(address(this));
        polygonERC20.safeTransfer(_rewardAddress, balance);

        return balance;
    }

    /// @notice Allows to update signer publickey.
    /// @param _validatorId validator id.
    /// @param _signerPubkey new publickey.
    /// @param _stakeManager stake manager address
    function updateSigner(
        uint256 _validatorId,
        bytes memory _signerPubkey,
        address _stakeManager
    ) external override isOperatorRegistry {
        IStakeManager(_stakeManager).updateSigner(_validatorId, _signerPubkey);
    }

    /// @notice Allows withdraw heimdall fees.
    /// @param _accumFeeAmount accumulated heimdall fees.
    /// @param _index index.
    /// @param _proof proof.
    function claimFee(
        uint256 _accumFeeAmount,
        uint256 _index,
        bytes memory _proof,
        address _rewardAddress,
        address _stakeManager,
        address _polygonERC20
    ) external override isOperatorRegistry {
        IStakeManager stakeManager = IStakeManager(_stakeManager);
        stakeManager.claimFee(_accumFeeAmount, _index, _proof);

        IERC20 polygonERC20 = IERC20(_polygonERC20);
        uint256 balance = polygonERC20.balanceOf(address(this));
        polygonERC20.safeTransfer(_rewardAddress, balance);
    }

    /// @notice Allows to update commission rate of a validator.
    /// @param _validatorId validator id.
    /// @param _newCommissionRate new commission rate.
    /// @param _stakeManager stake manager address
    function updateCommissionRate(
        uint256 _validatorId,
        uint256 _newCommissionRate,
        address _stakeManager
    ) public override isOperatorRegistry {
        IStakeManager(_stakeManager).updateCommissionRate(
            _validatorId,
            _newCommissionRate
        );
    }

    /// @notice Allows to unjail a validator.
    /// @param _validatorId validator id
    function unjail(uint256 _validatorId, address _stakeManager)
        external
        override
        isOperatorRegistry
    {
        IStakeManager(_stakeManager).unjail(_validatorId);
    }

    /// @notice Allows to transfer the validator nft token to the reward address a validator.
    /// @param _validatorId operator id.
    /// @param _stakeManagerNFT stake manager nft contract.
    /// @param _rewardAddress reward address.
    function migrate(
        uint256 _validatorId,
        address _stakeManagerNFT,
        address _rewardAddress
    ) external override isOperatorRegistry {
        IERC721 erc721 = IERC721(_stakeManagerNFT);
        erc721.approve(_rewardAddress, _validatorId);
        erc721.safeTransferFrom(address(this), _rewardAddress, _validatorId);
    }

    /// @notice Allows a validator that was already staked on the polygon stake manager
    /// to join the PoLido protocol.
    /// @param _validatorId validator id
    /// @param _stakeManagerNFT address of the staking NFT
    /// @param _rewardAddress address that will receive the rewards from staking
    /// @param _newCommissionRate commission rate
    /// @param _stakeManager address of the stake manager
    function join(
        uint256 _validatorId,
        address _stakeManagerNFT,
        address _rewardAddress,
        uint256 _newCommissionRate,
        address _stakeManager
    ) external override isOperatorRegistry {
        IERC721 erc721 = IERC721(_stakeManagerNFT);
        erc721.safeTransferFrom(_rewardAddress, address(this), _validatorId);
        updateCommissionRate(_validatorId, _newCommissionRate, _stakeManager);
    }

    /// @notice Allows to get the version of the validator implementation.
    /// @return Returns the version.
    function version() external pure returns (string memory) {
        return "1.0.0";
    }

    /// @notice Implement @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol interface.
    function onERC721Received(
        address,
        address,
        uint256,
        bytes calldata
    ) external pure override returns (bytes4) {
        return
            bytes4(
                keccak256("onERC721Received(address,address,uint256,bytes)")
            );
    }
}

File 18 of 29 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

    /**
     * @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);
}

File 19 of 29 : IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165.sol";

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the caller.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool _approved) external;

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes calldata data
    ) external;
}

File 20 of 29 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 21 of 29 : IERC721Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol)

pragma solidity ^0.8.0;

/**
 * @title ERC721 token receiver interface
 * @dev Interface for any contract that wants to support safeTransfers
 * from ERC721 asset contracts.
 */
interface IERC721Receiver {
    /**
     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
     * by `operator` from `from`, this function is called.
     *
     * It must return its Solidity selector to confirm the token transfer.
     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
     *
     * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}

File 22 of 29 : IStakeManager.sol
// SPDX-FileCopyrightText: 2021 ShardLabs
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.7;

/// @title polygon stake manager interface.
/// @author 2021 ShardLabs
/// @notice User to interact with the polygon stake manager.
interface IStakeManager {
    /// @notice Stake a validator on polygon stake manager.
    /// @param user user that own the validator in our case the validator contract.
    /// @param amount amount to stake.
    /// @param heimdallFee heimdall fees.
    /// @param acceptDelegation accept delegation.
    /// @param signerPubkey signer publickey used in heimdall node.
    function stakeFor(
        address user,
        uint256 amount,
        uint256 heimdallFee,
        bool acceptDelegation,
        bytes memory signerPubkey
    ) external;

    /// @notice Restake Matics for a validator on polygon stake manager.
    /// @param validatorId validator id.
    /// @param amount amount to stake.
    /// @param stakeRewards restake rewards.
    function restake(
        uint256 validatorId,
        uint256 amount,
        bool stakeRewards
    ) external;

    /// @notice Request unstake a validator.
    /// @param validatorId validator id.
    function unstake(uint256 validatorId) external;

    /// @notice Increase the heimdall fees.
    /// @param user user that own the validator in our case the validator contract.
    /// @param heimdallFee heimdall fees.
    function topUpForFee(address user, uint256 heimdallFee) external;

    /// @notice Get the validator id using the user address.
    /// @param user user that own the validator in our case the validator contract.
    /// @return return the validator id
    function getValidatorId(address user) external view returns (uint256);

    /// @notice get the validator contract used for delegation.
    /// @param validatorId validator id.
    /// @return return the address of the validator contract.
    function getValidatorContract(uint256 validatorId)
        external
        view
        returns (address);

    /// @notice Withdraw accumulated rewards
    /// @param validatorId validator id.
    function withdrawRewards(uint256 validatorId) external;

    /// @notice Get validator total staked.
    /// @param validatorId validator id.
    function validatorStake(uint256 validatorId)
        external
        view
        returns (uint256);

    /// @notice Allows to unstake the staked tokens on the stakeManager.
    /// @param validatorId validator id.
    function unstakeClaim(uint256 validatorId) external;

    /// @notice Allows to update the signer pubkey
    /// @param _validatorId validator id
    /// @param _signerPubkey update signer public key
    function updateSigner(uint256 _validatorId, bytes memory _signerPubkey)
        external;

    /// @notice Allows to claim the heimdall fees.
    /// @param _accumFeeAmount accumulated fees amount
    /// @param _index index
    /// @param _proof proof
    function claimFee(
        uint256 _accumFeeAmount,
        uint256 _index,
        bytes memory _proof
    ) external;

    /// @notice Allows to update the commision rate of a validator
    /// @param _validatorId operator id
    /// @param _newCommissionRate commission rate
    function updateCommissionRate(
        uint256 _validatorId,
        uint256 _newCommissionRate
    ) external;

    /// @notice Allows to unjail a validator.
    /// @param _validatorId id of the validator that is to be unjailed
    function unjail(uint256 _validatorId) external;

    /// @notice Returns a withdrawal delay.
    function withdrawalDelay() external view returns (uint256);

    /// @notice Transfers amount from delegator
    function delegationDeposit(
        uint256 validatorId,
        uint256 amount,
        address delegator
    ) external returns (bool);

    function epoch() external view returns (uint256);

    enum Status {
        Inactive,
        Active,
        Locked,
        Unstaked
    }

    struct Validator {
        uint256 amount;
        uint256 reward;
        uint256 activationEpoch;
        uint256 deactivationEpoch;
        uint256 jailTime;
        address signer;
        address contractAddress;
        Status status;
        uint256 commissionRate;
        uint256 lastCommissionUpdate;
        uint256 delegatorsReward;
        uint256 delegatedAmount;
        uint256 initialRewardPerStake;
    }

    function validators(uint256 _index)
        external
        view
        returns (Validator memory);

    /// @notice Returns the address of the nft contract
    function NFTContract() external view returns (address);

    /// @notice Returns the validator accumulated rewards on stake manager.
    function validatorReward(uint256 validatorId)
        external
        view
        returns (uint256);
}

File 23 of 29 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

File 24 of 29 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Address.sol)

pragma solidity ^0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 25 of 29 : IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20Upgradeable {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

    /**
     * @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);
}

File 26 of 29 : IValidatorShare.sol
// SPDX-FileCopyrightText: 2021 ShardLabs
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.7;

interface IValidatorShare {
    struct DelegatorUnbond {
        uint256 shares;
        uint256 withdrawEpoch;
    }

    function unbondNonces(address _address) external view returns (uint256);

    function activeAmount() external view returns (uint256);

    function validatorId() external view returns (uint256);

    function withdrawExchangeRate() external view returns (uint256);

    function withdrawRewards() external;

    function unstakeClaimTokens() external;

    function minAmount() external view returns (uint256);

    function getLiquidRewards(address user) external view returns (uint256);

    function delegation() external view returns (bool);

    function updateDelegation(bool _delegation) external;

    function buyVoucher(uint256 _amount, uint256 _minSharesToMint)
        external
        returns (uint256);

    function sellVoucher_new(uint256 claimAmount, uint256 maximumSharesToBurn)
        external;

    function unstakeClaimTokens_new(uint256 unbondNonce) external;

    function unbonds_new(address _address, uint256 _unbondNonce)
        external
        view
        returns (DelegatorUnbond memory);

    function getTotalStake(address user)
        external
        view
        returns (uint256, uint256);

    function owner() external view returns (address);

    function restake() external returns (uint256, uint256);

    function unlock() external;

    function lock() external;

    function drain(
        address token,
        address payable destination,
        uint256 amount
    ) external;

    function slash(uint256 _amount) external;

    function migrateOut(address user, uint256 amount) external;

    function migrateIn(address user, uint256 amount) external;
}

File 27 of 29 : IPoLidoNFT.sol
// SPDX-FileCopyrightText: 2021 ShardLabs
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.7;

import "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol";

/// @title PoLidoNFT interface.
/// @author 2021 ShardLabs
interface IPoLidoNFT is IERC721Upgradeable {
    function mint(address _to) external returns (uint256);

    function burn(uint256 _tokenId) external;

    function isApprovedOrOwner(address _spender, uint256 _tokenId)
        external
        view
        returns (bool);

    function setStMATIC(address _stMATIC) external;
}

File 28 of 29 : IFxStateRootTunnel.sol
// SPDX-FileCopyrightText: 2021 ShardLabs
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.7;

interface IFxStateRootTunnel {
    function latestData() external view returns (bytes memory);

    function setFxChildTunnel(address _fxChildTunnel) external;

    function sendMessageToChild(bytes memory message) external;

    function setStMATIC(address _stMATIC) external;
}

File 29 of 29 : IERC721Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165Upgradeable.sol";

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721Upgradeable is IERC165Upgradeable {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the caller.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool _approved) external;

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes calldata data
    ) external;
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"operatorId","type":"uint256"}],"name":"AddOperator","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"operatorId","type":"uint256"}],"name":"ClaimFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"operatorId","type":"uint256"}],"name":"JoinOperator","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"operatorId","type":"uint256"}],"name":"MigrateOperator","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"operatorId","type":"uint256"},{"indexed":false,"internalType":"string","name":"name","type":"string"}],"name":"NewName","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"operatorId","type":"uint256"},{"indexed":false,"internalType":"address","name":"rewardAddress","type":"address"}],"name":"NewRewardAddress","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"operatorId","type":"uint256"}],"name":"RemoveOperator","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"operatorId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"bool","name":"restakeRewards","type":"bool"}],"name":"RestakeOperator","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"operatorId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"heimdallFees","type":"uint256"}],"name":"StakeOperator","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"operatorId","type":"uint256"}],"name":"StopOperator","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"operatorId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"TopUpHeimdallFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"operatorId","type":"uint256"}],"name":"Unjail","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"operatorId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"UnstakeClaim","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"operatorId","type":"uint256"}],"name":"UnstakeOperator","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"operatorId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newCommissionRate","type":"uint256"}],"name":"UpdateCommissionRate","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"operatorId","type":"uint256"}],"name":"UpdateSignerPubkey","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"operatorId","type":"uint256"},{"indexed":false,"internalType":"address","name":"rewardAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawRewards","type":"event"},{"inputs":[],"name":"DAO_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PAUSE_OPERATOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REMOVE_OPERATOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"address","name":"_rewardAddress","type":"address"},{"internalType":"bytes","name":"_signerPubkey","type":"bytes"}],"name":"addOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"allowsRestake","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_accumFeeAmount","type":"uint256"},{"internalType":"uint256","name":"_index","type":"uint256"},{"internalType":"bytes","name":"_proof","type":"bytes"}],"name":"claimFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"commissionRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultMaxDelegateLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getContracts","outputs":[{"internalType":"address","name":"_validatorFactory","type":"address"},{"internalType":"address","name":"_stakeManager","type":"address"},{"internalType":"address","name":"_polygonERC20","type":"address"},{"internalType":"address","name":"_stMATIC","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"getNodeOperator","outputs":[{"components":[{"internalType":"enum NodeOperatorRegistry.NodeOperatorStatus","name":"status","type":"uint8"},{"internalType":"string","name":"name","type":"string"},{"internalType":"address","name":"rewardAddress","type":"address"},{"internalType":"bytes","name":"signerPubkey","type":"bytes"},{"internalType":"address","name":"validatorShare","type":"address"},{"internalType":"address","name":"validatorProxy","type":"address"},{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"uint256","name":"commissionRate","type":"uint256"},{"internalType":"uint256","name":"maxDelegateLimit","type":"uint256"}],"internalType":"struct NodeOperatorRegistry.NodeOperator","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_operatorId","type":"uint256"}],"name":"getNodeOperator","outputs":[{"components":[{"internalType":"enum NodeOperatorRegistry.NodeOperatorStatus","name":"status","type":"uint8"},{"internalType":"string","name":"name","type":"string"},{"internalType":"address","name":"rewardAddress","type":"address"},{"internalType":"bytes","name":"signerPubkey","type":"bytes"},{"internalType":"address","name":"validatorShare","type":"address"},{"internalType":"address","name":"validatorProxy","type":"address"},{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"uint256","name":"commissionRate","type":"uint256"},{"internalType":"uint256","name":"maxDelegateLimit","type":"uint256"}],"internalType":"struct NodeOperatorRegistry.NodeOperator","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getOperatorIds","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"_delegation","type":"bool"},{"internalType":"bool","name":"_allWithStake","type":"bool"}],"name":"getOperatorInfos","outputs":[{"components":[{"internalType":"uint256","name":"operatorId","type":"uint256"},{"internalType":"address","name":"validatorShare","type":"address"},{"internalType":"uint256","name":"maxDelegateLimit","type":"uint256"},{"internalType":"address","name":"rewardAddress","type":"address"}],"internalType":"struct Operator.OperatorInfo[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getState","outputs":[{"internalType":"uint256","name":"_totalNodeOperator","type":"uint256"},{"internalType":"uint256","name":"_totalInactiveNodeOperator","type":"uint256"},{"internalType":"uint256","name":"_totalActiveNodeOperator","type":"uint256"},{"internalType":"uint256","name":"_totalStoppedNodeOperator","type":"uint256"},{"internalType":"uint256","name":"_totalUnstakedNodeOperator","type":"uint256"},{"internalType":"uint256","name":"_totalClaimedNodeOperator","type":"uint256"},{"internalType":"uint256","name":"_totalExitNodeOperator","type":"uint256"},{"internalType":"uint256","name":"_totalJailedNodeOperator","type":"uint256"},{"internalType":"uint256","name":"_totalEjectedNodeOperator","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"getValidator","outputs":[{"components":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"reward","type":"uint256"},{"internalType":"uint256","name":"activationEpoch","type":"uint256"},{"internalType":"uint256","name":"deactivationEpoch","type":"uint256"},{"internalType":"uint256","name":"jailTime","type":"uint256"},{"internalType":"address","name":"signer","type":"address"},{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"enum IStakeManager.Status","name":"status","type":"uint8"},{"internalType":"uint256","name":"commissionRate","type":"uint256"},{"internalType":"uint256","name":"lastCommissionUpdate","type":"uint256"},{"internalType":"uint256","name":"delegatorsReward","type":"uint256"},{"internalType":"uint256","name":"delegatedAmount","type":"uint256"},{"internalType":"uint256","name":"initialRewardPerStake","type":"uint256"}],"internalType":"struct IStakeManager.Validator","name":"va","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_operatorId","type":"uint256"}],"name":"getValidator","outputs":[{"components":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"reward","type":"uint256"},{"internalType":"uint256","name":"activationEpoch","type":"uint256"},{"internalType":"uint256","name":"deactivationEpoch","type":"uint256"},{"internalType":"uint256","name":"jailTime","type":"uint256"},{"internalType":"address","name":"signer","type":"address"},{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"enum IStakeManager.Status","name":"status","type":"uint8"},{"internalType":"uint256","name":"commissionRate","type":"uint256"},{"internalType":"uint256","name":"lastCommissionUpdate","type":"uint256"},{"internalType":"uint256","name":"delegatorsReward","type":"uint256"},{"internalType":"uint256","name":"delegatedAmount","type":"uint256"},{"internalType":"uint256","name":"initialRewardPerStake","type":"uint256"}],"internalType":"struct IStakeManager.Validator","name":"va","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_operatorId","type":"uint256"}],"name":"getValidatorShare","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_validatorFactory","type":"address"},{"internalType":"address","name":"_stakeManager","type":"address"},{"internalType":"address","name":"_polygonERC20","type":"address"},{"internalType":"address","name":"_stMATIC","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"joinOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"migrate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"minAmountStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minHeimdallFees","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_operatorId","type":"uint256"}],"name":"removeOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"bool","name":"_restakeRewards","type":"bool"}],"name":"restake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_commissionRate","type":"uint256"}],"name":"setCommissionRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_defaultMaxDelegateLimit","type":"uint256"}],"name":"setDefaultMaxDelegateLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_operatorId","type":"uint256"},{"internalType":"uint256","name":"_maxDelegateLimit","type":"uint256"}],"name":"setMaxDelegateLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_name","type":"string"}],"name":"setOperatorName","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_rewardAddress","type":"address"}],"name":"setOperatorRewardAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_restake","type":"bool"}],"name":"setRestake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_stMATIC","type":"address"}],"name":"setStMATIC","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_minAmountStake","type":"uint256"},{"internalType":"uint256","name":"_minHeimdallFees","type":"uint256"}],"name":"setStakeAmountAndFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_stakeManager","type":"address"}],"name":"setStakeManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_validatorFactory","type":"address"}],"name":"setValidatorFactory","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_version","type":"string"}],"name":"setVersion","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"_heimdallFee","type":"uint256"}],"name":"stake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_operatorId","type":"uint256"}],"name":"stopOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"togglePause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_heimdallFee","type":"uint256"}],"name":"topUpForFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unjail","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unstake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_operatorId","type":"uint256"}],"name":"unstake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unstakeClaim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_operatorId","type":"uint256"},{"internalType":"uint256","name":"_newCommissionRate","type":"uint256"}],"name":"updateOperatorCommissionRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"_signerPubkey","type":"bytes"}],"name":"updateSigner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"withdrawRewards","outputs":[],"stateMutability":"nonpayable","type":"function"}]

608060405234801561001057600080fd5b5061512f806100206000396000f3fe608060405234801561001057600080fd5b506004361061035c5760003560e01c80637b0472f0116101d3578063cbfe71b111610104578063e9c26518116100a2578063f46673f61161007c578063f46673f61461079d578063f679d305146107b0578063f8c8765e146107b8578063fee2e770146107cb57600080fd5b8063e9c2651814610762578063eb40ea0514610777578063ec7b5fc01461078a57600080fd5b8063dcbc62a4116100de578063dcbc62a414610700578063e1d95a2e14610713578063e41289d814610728578063e5bc85851461073b57600080fd5b8063cbfe71b1146106c7578063d547741f146106da578063d8d50a2a146106ed57600080fd5b8063b13cb01d11610171578063c4ae31681161014b578063c4ae31681461069a578063c7b8981c146106a2578063c83112b7146106aa578063cb2c0668146106b457600080fd5b8063b13cb01d14610633578063b5d8962714610646578063c3a2a93a1461065957600080fd5b80638fd3ab80116101ad5780638fd3ab80146105fd57806391d148541461060557806394b75bd714610618578063a217fddf1461062b57600080fd5b80637b0472f0146105c95780637d52880b146105dc5780638889bd55146105ea57600080fd5b80632e17de78116102ad5780635ea1d6f81161024b57806365c14dc71161022557806365c14dc71461057d57806368cb812a146105905780636f9e459d146105a3578063788bc78c146105b657600080fd5b80635ea1d6f81461055f5780635fa7155d14610569578063626203a21461057357600080fd5b80634a84dabb116102875780634a84dabb146104f857806354fd4d50146105185780635c975abb1461052d5780635d53be4a1461053857600080fd5b80632e17de78146104bf5780632f2ff15d146104d257806336568abe146104e557600080fd5b80631865c57d1161031a5780631a521d83116102f45780631a521d831461046b5780631b889cfa1461047e578063248a9ca3146104865780632def6620146104b757600080fd5b80631865c57d146103ec5780631904bb2e1461043857806319fac8fd1461045857600080fd5b8062f43a661461036157806301ffc9a7146103765780630e2c0b101461039e5780630e7c67fc146103be57806312102cc9146103d157806316f1ceb9146103d9575b600080fd5b61037461036f3660046147d9565b6107f6565b005b610389610384366004614772565b610b50565b60405190151581526020015b60405180910390f35b6103b16103ac36600461462b565b610b87565b6040516103959190614d26565b6103746103cc36600461462b565b610bb9565b610374610bf8565b6103746103e7366004614734565b610f1f565b6103f4610f86565b60408051998a5260208a0198909852968801959095526060870193909352608086019190915260a085015260c084015260e083015261010082015261012001610395565b61044b61044636600461462b565b6112fa565b6040516103959190614ded565b610374610466366004614734565b61155f565b61037461047936600461462b565b611582565b6103746115c1565b6104a9610494366004614734565b60009081526097602052604090206001015490565b604051908152602001610395565b610374611a34565b6103746104cd366004614734565b611bb0565b6103746104e036600461474d565b611c23565b6103746104f336600461474d565b611c49565b61050b6105063660046146fb565b611cc7565b6040516103959190614bea565b610520611fd2565b6040516103959190614c9e565b60335460ff16610389565b6104a97ff6242721b06fefc650a24712f3590e1f7a66d3e4695d678965bdb1c332b04d1481565b6104a96101045481565b6104a96101035481565b6104a96101025481565b6103b161058b366004614734565b612060565b61037461059e366004614990565b612071565b6103746105b1366004614949565b612187565b6103746105c436600461479c565b61231c565b6103746105d736600461496e565b61233e565b610105546103899060ff1681565b6103746105f8366004614734565b612534565b6103746126eb565b61038961061336600461474d565b6128a0565b61037461062636600461496e565b6128cb565b6104a9600081565b6103746106413660046146c1565b612963565b61044b610654366004614734565b612994565b60fd5460fe5460ff5461010054604080516001600160a01b039586168152938516602085015291841691830191909152919091166060820152608001610395565b6103746129a7565b6103746129f2565b6104a96101065481565b6103746106c236600461462b565b612b26565b6103746106d536600461462b565b612c2d565b6103746106e836600461474d565b612c6d565b6103746106fb36600461479c565b612c93565b61037461070e36600461496e565b612df2565b61071b612e6a565b6040516103959190614c5a565b61037461073636600461479c565b612ec3565b6104a97f8a58d7fa900007312ba6adff22a16225160a4b0eb83ca229b65951837329000281565b6104a96000805160206150da83398151915281565b610374610785366004614734565b612f7a565b61037461079836600461496e565b6130a0565b6103746107ab366004614734565b6131ec565b610374613468565b6103746107c6366004614665565b613555565b6107de6107d9366004614734565b61370d565b6040516001600160a01b039091168152602001610395565b60335460ff16156108225760405162461bcd60e51b815260040161081990614cb1565b60405180910390fd5b6000805160206150da83398151915261086861083e82336128a0565b6040518060400160405280600c81526020016b1d5b985d5d1a1bdc9a5e995960a21b8152506138dd565b6001600160a01b0383166000908152610108602052604090205483906108c79015801561089d57506001600160a01b03821615155b6040518060400160405280600c81526020016b1059191c995cdcc81d5cd95960a21b8152506138dd565b61010180549060006108d88361502d565b909155505060fd5460408051633bf206a360e21b815290516000926001600160a01b03169163efc81a8c91600480830192602092919082900301818787803b15801561092357600080fd5b505af1158015610937573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061095b9190614648565b6040805161012081018252600080825260208083018b90526001600160a01b038a811684860152606084018a905260808401839052851660a084015260c083018290526101045460e084015261010654610100840152610101548252610109905291909120815181549394509192909190829060ff191660018360078111156109e6576109e661505e565b02179055506020828101518051610a039260018501920190614388565b5060408201516002820180546001600160a01b0319166001600160a01b0390921691909117905560608201518051610a45916003840191602090910190614388565b5060808201516004820180546001600160a01b039283166001600160a01b03199182161790915560a084015160058401805491909316911617905560c0820151600682015560e082015160078201556101009091015160089091015561010154610107805460018101825560009182527f47c4908e245f386bfc1825973249847f4053a761ddb4880ad63c323a7b5a2a25019190915560fc805491610ae98361502d565b9091555050610101546001600160a01b0386166000908152610108602052604090819020829055517fcae723e16b1fc1da344314a026beb6efbac6c544b6e34705a2fc29599e8183b191610b409190815260200190565b60405180910390a1505050505050565b60006001600160e01b03198216637965db0b60e01b1480610b8157506301ffc9a760e01b6001600160e01b03198316145b92915050565b610b8f61440c565b6001600160a01b03821660009081526101086020526040902054610bb2816138fc565b9392505050565b6000805160206150da833981519152610bd561083e82336128a0565b5060fe80546001600160a01b0319166001600160a01b0392909216919091179055565b60335460ff1615610c1b5760405162461bcd60e51b815260040161081990614cb1565b600080610c286000613b01565b9092509050610e3060035b6040805161012081019091528354610df291908590829060ff166007811115610c5e57610c5e61505e565b6007811115610c6f57610c6f61505e565b8152602001600182018054610c8390614ff8565b80601f0160208091040260200160405190810160405280929190818152602001828054610caf90614ff8565b8015610cfc5780601f10610cd157610100808354040283529160200191610cfc565b820191906000526020600020905b815481529060010190602001808311610cdf57829003601f168201915b505050918352505060028201546001600160a01b03166020820152600382018054604090920191610d2c90614ff8565b80601f0160208091040260200160405190810160405280929190818152602001828054610d5890614ff8565b8015610da55780601f10610d7a57610100808354040283529160200191610da5565b820191906000526020600020905b815481529060010190602001808311610d8857829003601f168201915b505050918352505060048201546001600160a01b0390811660208301526005830154166040820152600682015460608201526007820154608082015260089091015460a090910152613b7a565b6007811115610e0357610e0361505e565b146040518060400160405280600e81526020016d496e76616c69642073746174757360901b8152506138dd565b6005810154600682015460fe5460ff5460405163234440ef60e01b815260048101939093523360248401526001600160a01b03918216604484015281166064830152600092169063234440ef90608401602060405180830381600087803b158015610e9a57600080fd5b505af1158015610eae573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ed2919061490b565b825460ff1916600417835560408051858152602081018390529192507f831e7a759c81774656e01db0116457c9336942c3f3f397f4a5e7270094a901e591015b60405180910390a1505050565b6000805160206150da833981519152610f3b61083e82336128a0565b81610f7e6b204fce5e3e250261100000008211156040518060400160405280601181526020017026b0bc1030b6b7bab73a101e1e9018982160791b8152506138dd565b505061010655565b6101075460008080808080808088815b818110156112ed5760006101078281548110610fb457610fb461508a565b600091825260208083209091015480835261010990915260408083208151610120810190925280549294509091829060ff166007811115610ff757610ff761505e565b60078111156110085761100861505e565b815260200160018201805461101c90614ff8565b80601f016020809104026020016040519081016040528092919081815260200182805461104890614ff8565b80156110955780601f1061106a57610100808354040283529160200191611095565b820191906000526020600020905b81548152906001019060200180831161107857829003601f168201915b505050918352505060028201546001600160a01b031660208201526003820180546040909201916110c590614ff8565b80601f01602080910402602001604051908101604052809291908181526020018280546110f190614ff8565b801561113e5780601f106111135761010080835404028352916020019161113e565b820191906000526020600020905b81548152906001019060200180831161112157829003601f168201915b505050918352505060048201546001600160a01b0390811660208301526005830154166040820152600682015460608201526007820154608082015260089091015460a0909101529050600061119382613b7a565b905060008160078111156111a9576111a961505e565b14156111c1578c6111b98161502d565b9d50506112d7565b60018160078111156111d5576111d561505e565b14156111ed578b6111e58161502d565b9c50506112d7565b60028160078111156112015761120161505e565b1415611219578a6112118161502d565b9b50506112d7565b600381600781111561122d5761122d61505e565b1415611245578961123d8161502d565b9a50506112d7565b60048160078111156112595761125961505e565b141561127157886112698161502d565b9950506112d7565b60068160078111156112855761128561505e565b141561129d57866112958161502d565b9750506112d7565b60078160078111156112b1576112b161505e565b14156112c957856112c18161502d565b9650506112d7565b876112d38161502d565b9850505b50505080806112e59061502d565b915050610f96565b5050909192939495969798565b611302614474565b6001600160a01b0382166000908152610108602052604081205461132590613b01565b6040805161012081019091528154909190829060ff16600781111561134c5761134c61505e565b600781111561135d5761135d61505e565b815260200160018201805461137190614ff8565b80601f016020809104026020016040519081016040528092919081815260200182805461139d90614ff8565b80156113ea5780601f106113bf576101008083540402835291602001916113ea565b820191906000526020600020905b8154815290600101906020018083116113cd57829003601f168201915b505050918352505060028201546001600160a01b0316602082015260038201805460409092019161141a90614ff8565b80601f016020809104026020016040519081016040528092919081815260200182805461144690614ff8565b80156114935780601f1061146857610100808354040283529160200191611493565b820191906000526020600020905b81548152906001019060200180831161147657829003601f168201915b50505091835250506004828101546001600160a01b03908116602084015260058401548116604080850191909152600685015460608501526007850154608085015260089094015460a09093019290925260fe5460c08501519351630d6a8b9160e21b8152918201939093529294501691506335aa2e44906024016101a06040518083038186803b15801561152757600080fd5b505afa15801561153b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bb29190614851565b6000805160206150da83398151915261157b61083e82336128a0565b5061010455565b6000805160206150da83398151915261159e61083e82336128a0565b5060fd80546001600160a01b0319166001600160a01b0392909216919091179055565b60335460ff16156115e45760405162461bcd60e51b815260040161081990614cb1565b6000806115f16000613b01565b90925090506116006000610c33565b60fe54604051630ba7341960e11b81523360048201526001600160a01b0390911690600090829063174e68329060240160206040518083038186803b15801561164857600080fd5b505afa15801561165c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611680919061490b565b90506116b581600014156040518060400160405280600d81526020016c056616c696461746f7249643d3609c1b8152506138dd565b604051630d6a8b9160e21b8152600481018290526000906001600160a01b038416906335aa2e44906024016101a06040518083038186803b1580156116f957600080fd5b505afa15801561170d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117319190614851565b905061178c60006001600160a01b03168260c001516001600160a01b031614156040518060400160405280601f81526020017f56616c696461746f7220686173206e6f2056616c696461746f725368617265008152506138dd565b6117ea60018260e0015160038111156117a7576117a761505e565b1480156117b657506060820151155b6040518060400160405280601681526020017556616c696461746f722069736e27742041435449564560501b8152506138dd565b61184d846003016040516117fe9190614a26565b604051809103902060001c6001600160a01b03168260a001516001600160a01b0316146040518060400160405280600e81526020016d24b73b30b634b21029b4b3b732b960911b8152506138dd565b8360050160009054906101000a90046001600160a01b03166001600160a01b031663b966011a83856001600160a01b03166331c2273b6040518163ffffffff1660e01b815260040160206040518083038186803b1580156118ad57600080fd5b505afa1580156118c1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118e59190614648565b600788015460fe5460405160e086901b6001600160e01b031916815260048101949094526001600160a01b039283166024850152336044850152606484019190915216608482015260a401600060405180830381600087803b15801561194a57600080fd5b505af115801561195e573d6000803e3d6000fd5b505050506006840182905560405163158d0b6360e21b8152600481018390526000906001600160a01b038516906356342d8c9060240160206040518083038186803b1580156119ac57600080fd5b505afa1580156119c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119e49190614648565b6004860180546001600160a01b0319166001600160a01b0383161790556040518781529091507f3da3a55b69634a8a7f8e519cbcb95c702e89cad19d14b665d7c7c5db9e84c0f390602001610b40565b60335460ff1615611a575760405162461bcd60e51b815260040161081990614cb1565b600080611a646000613b01565b6040805161012081019091528154929450909250600091611a9891908490829060ff166007811115610c5e57610c5e61505e565b9050611b156001826007811115611ab157611ab161505e565b1480611ace57506006826007811115611acc57611acc61505e565b145b80611ae9575060075b826007811115610e0357610e0361505e565b6040518060400160405280600e81526020016d496e76616c69642073746174757360901b8152506138dd565b6001816007811115611b2957611b2961505e565b1415611ba1576005820154600683015460fe546040516341c0f0c160e11b815260048101929092526001600160a01b03908116602483015290911690638381e18290604401600060405180830381600087803b158015611b8857600080fd5b505af1158015611b9c573d6000803e3d6000fd5b505050505b611bab8383613d5a565b505050565b6000805160206150da833981519152611bcc61083e82336128a0565b60008281526101096020526040808220815161012081019092528054909291611c07918490829060ff166007811115610c5e57610c5e61505e565b9050611c136007611ad7565b611c1d8483613d5a565b50505050565b600082815260976020526040902060010154611c3f8133613e20565b611bab8383613e84565b6001600160a01b0381163314611cb95760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610819565b611cc38282613f0a565b5050565b6060600060fc5467ffffffffffffffff811115611ce657611ce66150a0565b604051908082528060200260200182016040528015611d1f57816020015b611d0c6144ff565b815260200190600190039081611d045790505b50610107549091506000805b82811015611f065760006101078281548110611d4957611d4961508a565b600091825260208083209091015480835261010990915260408083208151610120810190925280549294509291611d9391908490829060ff166007811115610c5e57610c5e61505e565b90506001816007811115611da957611da961505e565b14158015611ded5750888015611deb57506007816007811115611dce57611dce61505e565b1480611deb57506006816007811115611de957611de961505e565b145b155b15611dfa57505050611ef4565b8915611e88576004808301546040805163df5cf72360e01b815290516001600160a01b039092169263df5cf723928282019260209290829003018186803b158015611e4457600080fd5b505afa158015611e58573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e7c91906146de565b611e8857505050611ef4565b6040805160808101825284815260048401546001600160a01b039081166020830152600885015492820192909252600284015490911660608201528751889087908110611ed757611ed761508a565b60200260200101819052508480611eed9061502d565b9550505050505b80611efe8161502d565b915050611d2b565b5060fc548114611fc85760008167ffffffffffffffff811115611f2b57611f2b6150a0565b604051908082528060200260200182016040528015611f6457816020015b611f516144ff565b815260200190600190039081611f495790505b50905060005b82811015611fbc57848181518110611f8457611f8461508a565b6020026020010151828281518110611f9e57611f9e61508a565b60200260200101819052508080611fb49061502d565b915050611f6a565b509350610b8192505050565b5090949350505050565b60fb8054611fdf90614ff8565b80601f016020809104026020016040519081016040528092919081815260200182805461200b90614ff8565b80156120585780601f1061202d57610100808354040283529160200191612058565b820191906000526020600020905b81548152906001019060200180831161203b57829003601f168201915b505050505081565b61206861440c565b610b81826138fc565b60335460ff16156120945760405162461bcd60e51b815260040161081990614cb1565b6000806120a16000613b01565b90925090506120c260045b825460ff166007811115610e0357610e0361505e565b6005810154600282015460fe5460ff546040516349c0951960e11b81526001600160a01b03948516946393812a329461210f948c948c948c94938416939283169290911690600401614ef3565b600060405180830381600087803b15801561212957600080fd5b505af115801561213d573d6000803e3d6000fd5b5050825460ff1916600517835550506040518281527ff0f9e33722220fdcabe8003eb48d6c0c29121a045e723c954982fe1c5713c70d906020015b60405180910390a15050505050565b60335460ff16156121aa5760405162461bcd60e51b815260040161081990614cb1565b6101055460408051808201909152601381527214995cdd185ad9481a5cc8191a5cd8589b1959606a1b60208201526121e59160ff16906138dd565b816122235760405162461bcd60e51b815260206004820152600e60248201526d416d6f756e74206973205a45524f60901b6044820152606401610819565b6000806122306000613b01565b909250905061223f6001610c33565b6005810154600682015460fe5460ff5460405163386611fb60e01b815233600482015260248101939093526044830188905286151560648401526001600160a01b039182166084840152811660a48301529091169063386611fb9060c401600060405180830381600087803b1580156122b757600080fd5b505af11580156122cb573d6000803e3d6000fd5b50506040805185815260208101889052861515918101919091527f0deeff244cc1b1ec80d1cf0cb2f216f09692ebffd07eba1f86413945c04099f1925060600190505b60405180910390a150505050565b600061232b61083e82336128a0565b8151611bab9060fb906020850190614388565b60335460ff16156123615760405162461bcd60e51b815260040161081990614cb1565b81612398610102548210156040518060400160405280600e81526020016d125b9d985b1a5908185b5bdd5b9d60921b8152506138dd565b816123cd610103548210156040518060400160405280600c81526020016b496e76616c6964206665657360a01b8152506138dd565b6000806123da6000613b01565b90925090506123e96000610c33565b6000808260050160009054906101000a90046001600160a01b03166001600160a01b031663eb27befc338a8a600188600301896007015460fe60009054906101000a90046001600160a01b031660ff60009054906101000a90046001600160a01b03166040518963ffffffff1660e01b815260040161246f989796959493929190614b0d565b6040805180830381600087803b15801561248857600080fd5b505af115801561249c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124c09190614924565b600685018290556004850180546001600160a01b0319166001600160a01b03831617905560408051878152602081018c90529081018a905291935091507f59255107a227197b9463edbf1d0859fb8c767bf3ba0acfcf5c63f7c544c8366d9060600160405180910390a15050505050505050565b600061253f82613b01565b60028101549092506001600160a01b0316331490508061257257506125726000805160206150da833981519152336128a0565b6125ad5760405162461bcd60e51b815260206004820152600c60248201526b1d5b985d5d1a1bdc9a5e995960a21b6044820152606401610819565b60408051610120810190915281546000916125da918490829060ff166007811115610c5e57610c5e61505e565b905061261d60018260078111156125f3576125f361505e565b14806126105750600082600781111561260e5761260e61505e565b145b80611ae957506006611ad7565b60008160078111156126315761263161505e565b141561264757815460ff191660051782556126bb565b610100546004838101546040516363af3c1960e11b81526001600160a01b03918216928101929092529091169063c75e783290602401600060405180830381600087803b15801561269757600080fd5b505af11580156126ab573d6000803e3d6000fd5b5050835460ff1916600217845550505b6040518381527ff92be76e5e18026c846f095943eecf899b91f9c6c5549587adf3e72864de05c990602001610f12565b600260c954141561273e5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610819565b600260c95560008061274f81613b01565b909250905061275e60026120ac565b6005810154600682015460fe54604080516331c2273b60e01b815290516001600160a01b039485169463ff8985a7949316916331c2273b916004808301926020929190829003018186803b1580156127b557600080fd5b505afa1580156127c9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127ed9190614648565b600285015460405160e085901b6001600160e01b031916815260048101939093526001600160a01b039182166024840152166044820152606401600060405180830381600087803b15801561284157600080fd5b505af1158015612855573d6000803e3d6000fd5b5050825460ff1916600517835550506040518281527fb6b1aa812734ca55bf89381b0bb17b5799f2788923e2aac3a23f2ca2b822dce49060200160405180910390a15050600160c955565b60009182526097602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6000805160206150da8339815191526128e761083e82336128a0565b8261291e610102548210156040518060400160405280600e81526020016d125b9d985b1a5908185b5bdd5b9d60921b8152506138dd565b82612953610103548210156040518060400160405280600c81526020016b496e76616c6964206665657360a01b8152506138dd565b5050506101029190915561010355565b6000805160206150da83398151915261297f61083e82336128a0565b50610105805460ff1916911515919091179055565b61299c614474565b600061132583613b01565b7ff6242721b06fefc650a24712f3590e1f7a66d3e4695d678965bdb1c332b04d146129d561083e82336128a0565b60335460ff166129ea576129e7613f71565b50565b6129e7613fe6565b60335460ff1615612a155760405162461bcd60e51b815260040161081990614cb1565b600080612a226000613b01565b9092509050612a316001610c33565b60028101546005820154600683015460fe5460ff54604051637eb13ddb60e11b815260048101939093526001600160a01b039485166024840181905291851660448401528416606483015292600092169063fd627bb690608401602060405180830381600087803b158015612aa557600080fd5b505af1158015612ab9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612add919061490b565b604080518681526001600160a01b03851660208201529081018290529091507f93dd29733f7a730d27e925c382690a016b3822f139998e207e7a2c7377b4512f9060600161230e565b60335460ff1615612b495760405162461bcd60e51b815260040161081990614cb1565b6001600160a01b038116600090815261010860205260409020548190612ba79015801561089d57506001600160a01b03821615156040518060400160405280600c81526020016b1059191c995cdcc81d5cd95960a21b8152506138dd565b600080612bb46000613b01565b6002810180546001600160a01b0319166001600160a01b038816908117909155600081815261010860209081526040808320869055338352808320929092558151858152908101929092529294509092507f334b3003fc5d383b8d22c6c86c5aa5549b90857e00cfed3e507e50561ac1a07a910161230e565b6000805160206150da833981519152612c4961083e82336128a0565b5061010080546001600160a01b0319166001600160a01b0392909216919091179055565b600082815260976020526040902060010154612c898133613e20565b611bab8383613f0a565b60335460ff1615612cb65760405162461bcd60e51b815260040161081990614cb1565b600080612cc36000613b01565b6040805161012081019091528154929450909250600091612cf791908490829060ff166007811115610c5e57610c5e61505e565b9050612d1f60015b826007811115612d1157612d1161505e565b1480611ae957506000611ad7565b6001816007811115612d3357612d3361505e565b1415612dac576005820154600683015460fe5460405163f9e81c9560e01b81526001600160a01b039384169363f9e81c9593612d799390928a9290911690600401614ea9565b600060405180830381600087803b158015612d9357600080fd5b505af1158015612da7573d6000803e3d6000fd5b505050505b8351612dc19060038401906020870190614388565b506040518381527f5c81e0cd6f21a34d25dbb8d557e78a85926308636d2e7d585e3ff639347c9c849060200161230e565b6000805160206150da833981519152612e0e61083e82336128a0565b81612e516b204fce5e3e250261100000008211156040518060400160405280601181526020017026b0bc1030b6b7bab73a101e1e9018982160791b8152506138dd565b6000612e5c85613b01565b600801949094555050505050565b6060610107805480602002602001604051908101604052809291908181526020018280548015612eb957602002820191906000526020600020905b815481526020019060010190808311612ea5575b5050505050905090565b60335460ff1615612ee65760405162461bcd60e51b815260040161081990614cb1565b600080612ef36000613b01565b6040805161012081019091528154929450909250600091612f2791908490829060ff166007811115610c5e57610c5e61505e565b9050612f336001612cff565b8351612f489060018401906020870190614388565b507f080ed5f3376f5613820bc515f7ae7b286120168a7fa7389842a1d56571fa169e838560405161230e929190614eda565b60335460ff1615612f9d5760405162461bcd60e51b815260040161081990614cb1565b80612fd2610103548210156040518060400160405280600c81526020016b496e76616c6964206665657360a01b8152506138dd565b600080612fdf6000613b01565b9092509050612fee6001610c33565b600581015460fe5460ff546040516352a6f31360e01b8152336004820152602481018890526001600160a01b03928316604482015290821660648201529116906352a6f31390608401600060405180830381600087803b15801561305157600080fd5b505af1158015613065573d6000803e3d6000fd5b505060408051858152602081018890527f377d51bf90a7215e4ab9b72220f038863c4f9fbba822a7e04a563e5abe5e44bf935001905061230e565b6000805160206150da8339815191526130bc61083e82336128a0565b60006130c784613b01565b6040805161012081019091528154919350600092506130f8918490829060ff166007811115610c5e57610c5e61505e565b600283015490915061311c906001600160a01b0316151580611ae957506001611ad7565b60018160078111156131305761313061505e565b14156131af576005820154600683015460fe54604051634b98417560e01b81526004810192909252602482018790526001600160a01b03908116604483015290911690634b98417590606401600060405180830381600087803b15801561319657600080fd5b505af11580156131aa573d6000803e3d6000fd5b505050505b6007820184905560408051868152602081018690527f67fb2216d844c3553cf557bffa85f0fde0294999f808e61dcae1773d50d5e1509101612178565b60335460ff161561320f5760405162461bcd60e51b815260040161081990614cb1565b7f8a58d7fa900007312ba6adff22a16225160a4b0eb83ca229b65951837329000261323d61083e82336128a0565b600061324883613b01565b9150613256905060056120ac565b60005b6101075461326990600190614f9e565b8110156132f95761010781815481106132845761328461508a565b90600052602060002001548414156132e75761010780546132a790600190614f9e565b815481106132b7576132b761508a565b906000526020600020015461010782815481106132d6576132d661508a565b6000918252602090912001556132f9565b806132f18161502d565b915050613259565b5061010780548061330c5761330c615074565b6001900381819060005260206000200160009055905560fc600081548092919061333590614fe1565b909155505060fd546005820154604051631484968760e11b81526001600160a01b0391821660048201529116906329092d0e90602401600060405180830381600087803b15801561338557600080fd5b505af1158015613399573d6000803e3d6000fd5b50505060028201546001600160a01b03166000908152610108602090815260408083208390558683526101099091528120805460ff1916815591506133e16001830182614539565b6002820180546001600160a01b0319169055613401600383016000614539565b506004810180546001600160a01b03199081169091556005820180549091169055600060068201819055600782018190556008909101556040518381527fd021155f6056c972f1293e05d6b4b1153d05448084907570bb2d42603aafb3e890602001610f12565b60335460ff161561348b5760405162461bcd60e51b815260040161081990614cb1565b6000806134986000613b01565b90925090506134a76006610c33565b6005810154600682015460fe5460405163b5f3b80560e01b815260048101929092526001600160a01b0390811660248301529091169063b5f3b80590604401600060405180830381600087803b15801561350057600080fd5b505af1158015613514573d6000803e3d6000fd5b505050507f45f752fdf7817c92acd768d21cade15c741d2d69d3d9dea5b829d918a9dcee4c8260405161354991815260200190565b60405180910390a15050565b600054610100900460ff166135705760005460ff1615613574565b303b155b6135d75760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610819565b600054610100900460ff161580156135f9576000805461ffff19166101011790555b613601614060565b613609614099565b6136116140d8565b60fd80546001600160a01b038088166001600160a01b03199283161790925560fe805487841690831617905560ff8054868416908316179055610100805492851692909116919091179055678ac7230489e800006101028190556801158e460913d000006101035561010655613688600033614107565b6136b27f8a58d7fa900007312ba6adff22a16225160a4b0eb83ca229b65951837329000233614107565b6136dc7ff6242721b06fefc650a24712f3590e1f7a66d3e4695d678965bdb1c332b04d1433614107565b6136f46000805160206150da83398151915233614107565b8015613706576000805461ff00191690555b5050505050565b60008061371983613b01565b6040805161012081019091528154909190829060ff1660078111156137405761374061505e565b60078111156137515761375161505e565b815260200160018201805461376590614ff8565b80601f016020809104026020016040519081016040528092919081815260200182805461379190614ff8565b80156137de5780601f106137b3576101008083540402835291602001916137de565b820191906000526020600020905b8154815290600101906020018083116137c157829003601f168201915b505050918352505060028201546001600160a01b0316602082015260038201805460409092019161380e90614ff8565b80601f016020809104026020016040519081016040528092919081815260200182805461383a90614ff8565b80156138875780601f1061385c57610100808354040283529160200191613887565b820191906000526020600020905b81548152906001019060200180831161386a57829003601f168201915b505050918352505060048201546001600160a01b039081166020830152600583015416604082015260068201546060820152600782015460808083019190915260089092015460a0909101520151949350505050565b8082611bab5760405162461bcd60e51b81526004016108199190614c9e565b61390461440c565b600061390f83613b01565b6040805161012081019091528154909190829060ff1660078111156139365761393661505e565b60078111156139475761394761505e565b815260200160018201805461395b90614ff8565b80601f016020809104026020016040519081016040528092919081815260200182805461398790614ff8565b80156139d45780601f106139a9576101008083540402835291602001916139d4565b820191906000526020600020905b8154815290600101906020018083116139b757829003601f168201915b505050918352505060028201546001600160a01b03166020820152600382018054604090920191613a0490614ff8565b80601f0160208091040260200160405190810160405280929190818152602001828054613a3090614ff8565b8015613a7d5780601f10613a5257610100808354040283529160200191613a7d565b820191906000526020600020905b815481529060010190602001808311613a6057829003601f168201915b505050918352505060048201546001600160a01b0390811660208301526005830154166040820152600682015460608201526007820154608082015260089091015460a0909101529150613ad2905081613b7a565b81906007811115613ae557613ae561505e565b90816007811115613af857613af861505e565b90525092915050565b60008082613b1557613b1233614111565b92505b60008381526101096020526040902060028101546001600160a01b0316613b735760405162461bcd60e51b815260206004820152601260248201527113dc195c985d1bdc881b9bdd08199bdd5b9960721b6044820152606401610819565b9293915050565b6000600282516007811115613b9157613b9161505e565b1415613b9f57506002919050565b600482516007811115613bb457613bb461505e565b1415613bc257506004919050565b600582516007811115613bd757613bd761505e565b1415613be557506005919050565b600382516007811115613bfa57613bfa61505e565b1415613c0857506003919050565b60fe5460c0830151604051630d6a8b9160e21b815260048101919091526000916001600160a01b0316906335aa2e44906024016101a06040518083038186803b158015613c5457600080fd5b505afa158015613c68573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c8c9190614851565b905060018160e001516003811115613ca657613ca661505e565b148015613cb557506060810151155b15613cc35760019150613d53565b60018160e001516003811115613cdb57613cdb61505e565b1480613cfc575060028160e001516003811115613cfa57613cfa61505e565b145b8015613d0b5750606081015115155b15613d195760079150613d53565b60028160e001516003811115613d3157613d3161505e565b148015613d4057506060810151155b15613d4e5760069150613d53565b600091505b505b919050565b60335460ff1615613d7d5760405162461bcd60e51b815260040161081990614cb1565b610100546004828101546040516363af3c1960e11b81526001600160a01b03918216928101929092529091169063c75e783290602401600060405180830381600087803b158015613dcd57600080fd5b505af1158015613de1573d6000803e3d6000fd5b5050825460ff1916600317835550506040518281527f34517c4e1982cc18df7af765b99449d46b30e0bd54abd2096f846f13ca79d44890602001613549565b613e2a82826128a0565b611cc357613e42816001600160a01b03166014614164565b613e4d836020614164565b604051602001613e5e929190614a98565b60408051601f198184030181529082905262461bcd60e51b825261081991600401614c9e565b613e8e82826128a0565b611cc35760008281526097602090815260408083206001600160a01b03851684529091529020805460ff19166001179055613ec63390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b613f1482826128a0565b15611cc35760008281526097602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60335460ff1615613f945760405162461bcd60e51b815260040161081990614cb1565b6033805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258613fc93390565b6040516001600160a01b03909116815260200160405180910390a1565b60335460ff1661402f5760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610819565b6033805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa33613fc9565b600054610100900460ff166140875760405162461bcd60e51b815260040161081990614cdb565b61408f614300565b614097614327565b565b600054610100900460ff166140c05760405162461bcd60e51b815260040161081990614cdb565b6140c8614300565b6140d0614300565b614097614300565b600054610100900460ff166140ff5760405162461bcd60e51b815260040161081990614cdb565b61409761435a565b611cc38282613e84565b6001600160a01b038116600090815261010860209081526040808320548151808301909252601282527113dc195c985d1bdc881b9bdd08199bdd5b9960721b92820192909252610b8190821515906138dd565b60606000614173836002614f7f565b61417e906002614f67565b67ffffffffffffffff811115614196576141966150a0565b6040519080825280601f01601f1916602001820160405280156141c0576020820181803683370190505b509050600360fc1b816000815181106141db576141db61508a565b60200101906001600160f81b031916908160001a905350600f60fb1b8160018151811061420a5761420a61508a565b60200101906001600160f81b031916908160001a905350600061422e846002614f7f565b614239906001614f67565b90505b60018111156142b1576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061426d5761426d61508a565b1a60f81b8282815181106142835761428361508a565b60200101906001600160f81b031916908160001a90535060049490941c936142aa81614fe1565b905061423c565b508315610bb25760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610819565b600054610100900460ff166140975760405162461bcd60e51b815260040161081990614cdb565b600054610100900460ff1661434e5760405162461bcd60e51b815260040161081990614cdb565b6033805460ff19169055565b600054610100900460ff166143815760405162461bcd60e51b815260040161081990614cdb565b600160c955565b82805461439490614ff8565b90600052602060002090601f0160209004810192826143b657600085556143fc565b82601f106143cf57805160ff19168380011785556143fc565b828001600101855582156143fc579182015b828111156143fc5782518255916020019190600101906143e1565b5061440892915061456f565b5090565b60408051610120810190915280600081526020016060815260200160006001600160a01b031681526020016060815260200160006001600160a01b0316815260200160006001600160a01b031681526020016000815260200160008152602001600081525090565b604051806101a00160405280600081526020016000815260200160008152602001600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b03168152602001600060038111156144d6576144d661505e565b815260200160008152602001600081526020016000815260200160008152602001600081525090565b60405180608001604052806000815260200160006001600160a01b031681526020016000815260200160006001600160a01b031681525090565b50805461454590614ff8565b6000825580601f10614555575050565b601f0160209004906000526020600020908101906129e791905b5b808211156144085760008155600101614570565b8051613d55816150b6565b600082601f8301126145a057600080fd5b813567ffffffffffffffff808211156145bb576145bb6150a0565b604051601f8301601f19908116603f011681019082821181831017156145e3576145e36150a0565b816040528381528660208588010111156145fc57600080fd5b836020870160208301376000602085830101528094505050505092915050565b805160048110613d5557600080fd5b60006020828403121561463d57600080fd5b8135610bb2816150b6565b60006020828403121561465a57600080fd5b8151610bb2816150b6565b6000806000806080858703121561467b57600080fd5b8435614686816150b6565b93506020850135614696816150b6565b925060408501356146a6816150b6565b915060608501356146b6816150b6565b939692955090935050565b6000602082840312156146d357600080fd5b8135610bb2816150cb565b6000602082840312156146f057600080fd5b8151610bb2816150cb565b6000806040838503121561470e57600080fd5b8235614719816150cb565b91506020830135614729816150cb565b809150509250929050565b60006020828403121561474657600080fd5b5035919050565b6000806040838503121561476057600080fd5b823591506020830135614729816150b6565b60006020828403121561478457600080fd5b81356001600160e01b031981168114610bb257600080fd5b6000602082840312156147ae57600080fd5b813567ffffffffffffffff8111156147c557600080fd5b6147d18482850161458f565b949350505050565b6000806000606084860312156147ee57600080fd5b833567ffffffffffffffff8082111561480657600080fd5b6148128783880161458f565b945060208601359150614824826150b6565b9092506040850135908082111561483a57600080fd5b506148478682870161458f565b9150509250925092565b60006101a0828403121561486457600080fd5b61486c614f3d565b82518152602083015160208201526040830151604082015260608301516060820152608083015160808201526148a460a08401614584565b60a08201526148b560c08401614584565b60c08201526148c660e0840161461c565b60e08201526101008381015190820152610120808401519082015261014080840151908201526101608084015190820152610180928301519281019290925250919050565b60006020828403121561491d57600080fd5b5051919050565b6000806040838503121561493757600080fd5b825191506020830151614729816150b6565b6000806040838503121561495c57600080fd5b823591506020830135614729816150cb565b6000806040838503121561498157600080fd5b50508035926020909101359150565b6000806000606084860312156149a557600080fd5b8335925060208401359150604084013567ffffffffffffffff8111156149ca57600080fd5b6148478682870161458f565b600081518084526149ee816020860160208601614fb5565b601f01601f19169290920160200192915050565b60088110614a1257614a1261505e565b9052565b60048110614a1257614a1261505e565b6000808354614a3481614ff8565b60018281168015614a4c5760018114614a5d57614a8c565b60ff19841687528287019450614a8c565b8760005260208060002060005b85811015614a835781548a820152908401908201614a6a565b50505082870194505b50929695505050505050565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351614ad0816017850160208801614fb5565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351614b01816028840160208801614fb5565b01602801949350505050565b600061010060018060a01b038b16835260208a81850152896040850152881515606085015281608085015260008854614b4581614ff8565b9386018490526101209360018281168015614b675760018114614b7c57614baa565b60ff1984168988015261014089019450614baa565b8c6000528560002060005b84811015614ba25781548b82018a0152908301908701614b87565b8a0188019550505b5050505060a085018890526001600160a01b03871660c08601529250614bce915050565b6001600160a01b03831660e08301529998505050505050505050565b602080825282518282018190526000919060409081850190868401855b82811015614c4d57815180518552868101516001600160a01b03908116888701528682015187870152606091820151169085015260809093019290850190600101614c07565b5091979650505050505050565b6020808252825182820181905260009190848201906040850190845b81811015614c9257835183529284019291840191600101614c76565b50909695505050505050565b602081526000610bb260208301846149d6565b60208082526010908201526f14185d5cd8589b194e881c185d5cd95960821b604082015260600190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b60208152614d38602082018351614a02565b60006020830151610120806040850152614d566101408501836149d6565b91506040850151614d7260608601826001600160a01b03169052565b506060850151848303601f19016080860152614d8e83826149d6565b9250506080850151614dab60a08601826001600160a01b03169052565b5060a08501516001600160a01b03811660c08601525060c085015160e085015260e0850151610100818187015280870151838701525050508091505092915050565b60006101a082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015260a0830151614e3c60a08401826001600160a01b03169052565b5060c0830151614e5760c08401826001600160a01b03169052565b5060e0830151614e6a60e0840182614a16565b50610100838101519083015261012080840151908301526101408084015190830152610160808401519083015261018092830151929091019190915290565b838152606060208201526000614ec260608301856149d6565b905060018060a01b0383166040830152949350505050565b8281526040602082015260006147d160408301846149d6565b86815285602082015260c060408201526000614f1260c08301876149d6565b6001600160a01b039586166060840152938516608083015250921660a0909201919091529392505050565b6040516101a0810167ffffffffffffffff81118282101715614f6157614f616150a0565b60405290565b60008219821115614f7a57614f7a615048565b500190565b6000816000190483118215151615614f9957614f99615048565b500290565b600082821015614fb057614fb0615048565b500390565b60005b83811015614fd0578181015183820152602001614fb8565b83811115611c1d5750506000910152565b600081614ff057614ff0615048565b506000190190565b600181811c9082168061500c57607f821691505b60208210811415613d5357634e487b7160e01b600052602260045260246000fd5b600060001982141561504157615041615048565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052603160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b03811681146129e757600080fd5b80151581146129e757600080fdfe5dfbc033a771e47196819dc2abbb370160d9edb780ccfa0fc3dff94ae417be9ba2646970667358221220e1cbcd789ee3fb6762583cfe2df4bf9ea0e437325b99130085315769e71026c264736f6c63430008070033

Block Transaction Difficulty Gas Used Reward
Block Uncle Number Difficulty Gas Used Reward
Loading
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.