ETH Price: $3,339.20 (-1.17%)

Contract

0xCe73e22D123574879853c7606fb9A0461F3EAf12
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Distributor

Compiler Version
v0.8.17+commit.8df45f5f

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 21 : Distributor.sol
// SPDX-License-Identifier: AGPL-3.0-only

/*
    Distributor.sol - SKALE Manager
    Copyright (C) 2019-Present SKALE Labs
    @author Dmytro Stebaiev

    SKALE Manager is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    SKALE Manager is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with SKALE Manager.  If not, see <https://www.gnu.org/licenses/>.
*/

pragma solidity 0.8.17;

import "@openzeppelin/contracts/utils/introspection/IERC1820Registry.sol";
import "@openzeppelin/contracts/token/ERC777/IERC777Recipient.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import "@skalenetwork/skale-manager-interfaces/delegation/IDistributor.sol";
import "@skalenetwork/skale-manager-interfaces/delegation/IValidatorService.sol";
import "@skalenetwork/skale-manager-interfaces/delegation/IDelegationController.sol";
import "@skalenetwork/skale-manager-interfaces/delegation/ITimeHelpers.sol";

import "../Permissions.sol";
import "../ConstantsHolder.sol";
import "../utils/MathUtils.sol";


/**
 * @title Distributor
 * @dev This contract handles all distribution functions of bounty and fee
 * payments.
 */
contract Distributor is Permissions, IERC777Recipient, IDistributor {
    using MathUtils for uint;

    IERC1820Registry private _erc1820;

    // validatorId =>        month => token
    mapping (uint => mapping (uint => uint)) private _bountyPaid;
    // validatorId =>        month => token
    mapping (uint => mapping (uint => uint)) private _feePaid;
    //        holder =>   validatorId => month
    mapping (address => mapping (uint => uint)) private _firstUnwithdrawnMonth;
    // validatorId => month
    mapping (uint => uint) private _firstUnwithdrawnMonthForValidator;

    /**
     * @dev Return and update the amount of earned bounty from a validator.
     */
    function getAndUpdateEarnedBountyAmount(uint validatorId) external override returns (uint earned, uint endMonth) {
        return getAndUpdateEarnedBountyAmountOf(msg.sender, validatorId);
    }

    /**
     * @dev Allows msg.sender to withdraw earned bounty. Bounties are locked
     * until launchTimestamp and BOUNTY_LOCKUP_MONTHS have both passed.
     *
     * Emits a {WithdrawBounty} event.
     *
     * Requirements:
     *
     * - Bounty must be unlocked.
     */
    function withdrawBounty(uint validatorId, address to) external override {
        ITimeHelpers timeHelpers = ITimeHelpers(contractManager.getContract("TimeHelpers"));
        ConstantsHolder constantsHolder = ConstantsHolder(contractManager.getContract("ConstantsHolder"));

        require(block.timestamp >= timeHelpers.addMonths(
                constantsHolder.launchTimestamp(),
                constantsHolder.BOUNTY_LOCKUP_MONTHS()
            ), "Bounty is locked");

        uint bounty;
        uint endMonth;
        (bounty, endMonth) = getAndUpdateEarnedBountyAmountOf(msg.sender, validatorId);

        _firstUnwithdrawnMonth[msg.sender][validatorId] = endMonth;

        IERC20 skaleToken = IERC20(contractManager.getContract("SkaleToken"));
        require(skaleToken.transfer(to, bounty), "Failed to transfer tokens");

        emit WithdrawBounty(
            msg.sender,
            validatorId,
            to,
            bounty
        );
    }

    /**
     * @dev Allows `msg.sender` to withdraw earned validator fees. Fees are
     * locked until launchTimestamp and BOUNTY_LOCKUP_MONTHS both have passed.
     *
     * Emits a {WithdrawFee} event.
     *
     * Requirements:
     *
     * - Fee must be unlocked.
     */
    function withdrawFee(address to) external override {
        IValidatorService validatorService = IValidatorService(contractManager.getContract("ValidatorService"));
        IERC20 skaleToken = IERC20(contractManager.getContract("SkaleToken"));
        ITimeHelpers timeHelpers = ITimeHelpers(contractManager.getContract("TimeHelpers"));
        ConstantsHolder constantsHolder = ConstantsHolder(contractManager.getContract("ConstantsHolder"));

        require(block.timestamp >= timeHelpers.addMonths(
                constantsHolder.launchTimestamp(),
                constantsHolder.BOUNTY_LOCKUP_MONTHS()
            ), "Fee is locked");
        // check Validator Exist inside getValidatorId
        uint validatorId = validatorService.getValidatorId(msg.sender);

        uint fee;
        uint endMonth;
        (fee, endMonth) = getEarnedFeeAmountOf(validatorId);

        _firstUnwithdrawnMonthForValidator[validatorId] = endMonth;

        require(skaleToken.transfer(to, fee), "Failed to transfer tokens");

        emit WithdrawFee(
            validatorId,
            to,
            fee
        );
    }

    function tokensReceived(
        address,
        address,
        address to,
        uint256 amount,
        bytes calldata userData,
        bytes calldata
    )
        external
        override
        allow("SkaleToken")
    {
        require(to == address(this), "Receiver is incorrect");
        require(userData.length == 32, "Data length is incorrect");
        uint validatorId = abi.decode(userData, (uint));
        _distributeBounty(amount, validatorId);
    }

    /**
     * @dev Return the amount of earned validator fees of `msg.sender`.
     */
    function getEarnedFeeAmount() external view override returns (uint earned, uint endMonth) {
        IValidatorService validatorService = IValidatorService(contractManager.getContract("ValidatorService"));
        return getEarnedFeeAmountOf(validatorService.getValidatorId(msg.sender));
    }

    function initialize(address contractsAddress) public override initializer {
        Permissions.initialize(contractsAddress);
        _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
        _erc1820.setInterfaceImplementer(address(this), keccak256("ERC777TokensRecipient"), address(this));
    }

    /**
     * @dev Return and update the amount of earned bounties.
     */
    function getAndUpdateEarnedBountyAmountOf(address wallet, uint validatorId)
        public
        override
        returns (uint earned, uint endMonth)
    {
        IDelegationController delegationController = IDelegationController(
            contractManager.getContract("DelegationController"));
        ITimeHelpers timeHelpers = ITimeHelpers(contractManager.getContract("TimeHelpers"));

        uint currentMonth = timeHelpers.getCurrentMonth();

        uint startMonth = _firstUnwithdrawnMonth[wallet][validatorId];
        if (startMonth == 0) {
            startMonth = delegationController.getFirstDelegationMonth(wallet, validatorId);
            if (startMonth == 0) {
                return (0, 0);
            }
        }

        earned = 0;
        endMonth = currentMonth;
        if (endMonth > startMonth + 12) {
            endMonth = startMonth + 12;
        }
        for (uint i = startMonth; i < endMonth; ++i) {
            uint effectiveDelegatedToValidator =
                delegationController.getAndUpdateEffectiveDelegatedToValidator(validatorId, i);
            if (effectiveDelegatedToValidator.muchGreater(0)) {
                earned = earned +
                    _bountyPaid[validatorId][i] *
                    delegationController.getAndUpdateEffectiveDelegatedByHolderToValidator(wallet, validatorId, i) /
                    effectiveDelegatedToValidator;
            }
        }
    }

    /**
     * @dev Return the amount of earned fees by validator ID.
     */
    function getEarnedFeeAmountOf(uint validatorId) public view override returns (uint earned, uint endMonth) {
        ITimeHelpers timeHelpers = ITimeHelpers(contractManager.getContract("TimeHelpers"));

        uint currentMonth = timeHelpers.getCurrentMonth();

        uint startMonth = _firstUnwithdrawnMonthForValidator[validatorId];
        if (startMonth == 0) {
            return (0, 0);
        }

        earned = 0;
        endMonth = currentMonth;
        if (endMonth > startMonth + 12) {
            endMonth = startMonth + 12;
        }
        for (uint i = startMonth; i < endMonth; ++i) {
            earned = earned + _feePaid[validatorId][i];
        }
    }

    // private

    /**
     * @dev Distributes bounties to delegators.
     *
     * Emits a {BountyWasPaid} event.
     */
    function _distributeBounty(uint amount, uint validatorId) private {
        ITimeHelpers timeHelpers = ITimeHelpers(contractManager.getContract("TimeHelpers"));
        IValidatorService validatorService = IValidatorService(contractManager.getContract("ValidatorService"));

        uint currentMonth = timeHelpers.getCurrentMonth();
        uint feeRate = validatorService.getValidator(validatorId).feeRate;

        uint fee = amount * feeRate / 1000;
        uint bounty = amount - fee;
        _bountyPaid[validatorId][currentMonth] = _bountyPaid[validatorId][currentMonth] + bounty;
        _feePaid[validatorId][currentMonth] = _feePaid[validatorId][currentMonth] + fee;

        if (_firstUnwithdrawnMonthForValidator[validatorId] == 0) {
            _firstUnwithdrawnMonthForValidator[validatorId] = currentMonth;
        }

        emit BountyWasPaid(validatorId, amount);
    }
}

File 2 of 21 : IERC1820Registry.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (utils/introspection/IERC1820Registry.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the global ERC1820 Registry, as defined in the
 * https://eips.ethereum.org/EIPS/eip-1820[EIP]. Accounts may register
 * implementers for interfaces in this registry, as well as query support.
 *
 * Implementers may be shared by multiple accounts, and can also implement more
 * than a single interface for each account. Contracts can implement interfaces
 * for themselves, but externally-owned accounts (EOA) must delegate this to a
 * contract.
 *
 * {IERC165} interfaces can also be queried via the registry.
 *
 * For an in-depth explanation and source code analysis, see the EIP text.
 */
interface IERC1820Registry {
    event InterfaceImplementerSet(address indexed account, bytes32 indexed interfaceHash, address indexed implementer);

    event ManagerChanged(address indexed account, address indexed newManager);

    /**
     * @dev Sets `newManager` as the manager for `account`. A manager of an
     * account is able to set interface implementers for it.
     *
     * By default, each account is its own manager. Passing a value of `0x0` in
     * `newManager` will reset the manager to this initial state.
     *
     * Emits a {ManagerChanged} event.
     *
     * Requirements:
     *
     * - the caller must be the current manager for `account`.
     */
    function setManager(address account, address newManager) external;

    /**
     * @dev Returns the manager for `account`.
     *
     * See {setManager}.
     */
    function getManager(address account) external view returns (address);

    /**
     * @dev Sets the `implementer` contract as ``account``'s implementer for
     * `interfaceHash`.
     *
     * `account` being the zero address is an alias for the caller's address.
     * The zero address can also be used in `implementer` to remove an old one.
     *
     * See {interfaceHash} to learn how these are created.
     *
     * Emits an {InterfaceImplementerSet} event.
     *
     * Requirements:
     *
     * - the caller must be the current manager for `account`.
     * - `interfaceHash` must not be an {IERC165} interface id (i.e. it must not
     * end in 28 zeroes).
     * - `implementer` must implement {IERC1820Implementer} and return true when
     * queried for support, unless `implementer` is the caller. See
     * {IERC1820Implementer-canImplementInterfaceForAddress}.
     */
    function setInterfaceImplementer(
        address account,
        bytes32 _interfaceHash,
        address implementer
    ) external;

    /**
     * @dev Returns the implementer of `interfaceHash` for `account`. If no such
     * implementer is registered, returns the zero address.
     *
     * If `interfaceHash` is an {IERC165} interface id (i.e. it ends with 28
     * zeroes), `account` will be queried for support of it.
     *
     * `account` being the zero address is an alias for the caller's address.
     */
    function getInterfaceImplementer(address account, bytes32 _interfaceHash) external view returns (address);

    /**
     * @dev Returns the interface hash for an `interfaceName`, as defined in the
     * corresponding
     * https://eips.ethereum.org/EIPS/eip-1820#interface-name[section of the EIP].
     */
    function interfaceHash(string calldata interfaceName) external pure returns (bytes32);

    /**
     * @notice Updates the cache with whether the contract implements an ERC165 interface or not.
     * @param account Address of the contract for which to update the cache.
     * @param interfaceId ERC165 interface for which to update the cache.
     */
    function updateERC165Cache(address account, bytes4 interfaceId) external;

    /**
     * @notice Checks whether a contract implements an ERC165 interface or not.
     * If the result is not cached a direct lookup on the contract address is performed.
     * If the result is not cached or the cached value is out-of-date, the cache MUST be updated manually by calling
     * {updateERC165Cache} with the contract address.
     * @param account Address of the contract to check.
     * @param interfaceId ERC165 interface to check.
     * @return True if `account` implements `interfaceId`, false otherwise.
     */
    function implementsERC165Interface(address account, bytes4 interfaceId) external view returns (bool);

    /**
     * @notice Checks whether a contract implements an ERC165 interface or not without using nor updating the cache.
     * @param account Address of the contract to check.
     * @param interfaceId ERC165 interface to check.
     * @return True if `account` implements `interfaceId`, false otherwise.
     */
    function implementsERC165InterfaceNoCache(address account, bytes4 interfaceId) external view returns (bool);
}

File 3 of 21 : IERC777Recipient.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC777/IERC777Recipient.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC777TokensRecipient standard as defined in the EIP.
 *
 * Accounts can be notified of {IERC777} tokens being sent to them by having a
 * contract implement this interface (contract holders can be their own
 * implementer) and registering it on the
 * https://eips.ethereum.org/EIPS/eip-1820[ERC1820 global registry].
 *
 * See {IERC1820Registry} and {ERC1820Implementer}.
 */
interface IERC777Recipient {
    /**
     * @dev Called by an {IERC777} token contract whenever tokens are being
     * moved or created into a registered account (`to`). The type of operation
     * is conveyed by `from` being the zero address or not.
     *
     * This call occurs _after_ the token contract's state is updated, so
     * {IERC777-balanceOf}, etc., can be used to query the post-operation state.
     *
     * This function may revert to prevent the operation from being executed.
     */
    function tokensReceived(
        address operator,
        address from,
        address to,
        uint256 amount,
        bytes calldata userData,
        bytes calldata operatorData
    ) external;
}

File 4 of 21 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

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

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

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

File 5 of 21 : IDistributor.sol
// SPDX-License-Identifier: AGPL-3.0-only

/*
    IDistributor.sol - SKALE Manager
    Copyright (C) 2018-Present SKALE Labs
    @author Artem Payvin

    SKALE Manager is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    SKALE Manager is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with SKALE Manager.  If not, see <https://www.gnu.org/licenses/>.
*/

pragma solidity >=0.6.10 <0.9.0;

interface IDistributor {
    /**
     * @dev Emitted when bounty is withdrawn.
     */
    event WithdrawBounty(
        address holder,
        uint validatorId,
        address destination,
        uint amount
    );

    /**
     * @dev Emitted when a validator fee is withdrawn.
     */
    event WithdrawFee(
        uint validatorId,
        address destination,
        uint amount
    );

    /**
     * @dev Emitted when bounty is distributed.
     */
    event BountyWasPaid(
        uint validatorId,
        uint amount
    );
    
    function getAndUpdateEarnedBountyAmount(uint validatorId) external returns (uint earned, uint endMonth);
    function withdrawBounty(uint validatorId, address to) external;
    function withdrawFee(address to) external;
    function getAndUpdateEarnedBountyAmountOf(address wallet, uint validatorId)
        external
        returns (uint earned, uint endMonth);
    function getEarnedFeeAmount() external view returns (uint earned, uint endMonth);
    function getEarnedFeeAmountOf(uint validatorId) external view returns (uint earned, uint endMonth);
}

File 6 of 21 : IValidatorService.sol
// SPDX-License-Identifier: AGPL-3.0-only

/*
    IValidatorService.sol - SKALE Manager
    Copyright (C) 2018-Present SKALE Labs
    @author Artem Payvin

    SKALE Manager is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    SKALE Manager is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with SKALE Manager.  If not, see <https://www.gnu.org/licenses/>.
*/

pragma solidity >=0.6.10 <0.9.0;

interface IValidatorService {
    struct Validator {
        string name;
        address validatorAddress;
        address requestedAddress;
        string description;
        uint feeRate;
        uint registrationTime;
        uint minimumDelegationAmount;
        bool acceptNewRequests;
    }
    
    /**
     * @dev Emitted when a validator registers.
     */
    event ValidatorRegistered(
        uint validatorId
    );

    /**
     * @dev Emitted when a validator address changes.
     */
    event ValidatorAddressChanged(
        uint validatorId,
        address newAddress
    );

    /**
     * @dev Emitted when a validator is enabled.
     */
    event ValidatorWasEnabled(
        uint validatorId
    );

    /**
     * @dev Emitted when a validator is disabled.
     */
    event ValidatorWasDisabled(
        uint validatorId
    );

    /**
     * @dev Emitted when a node address is linked to a validator.
     */
    event NodeAddressWasAdded(
        uint validatorId,
        address nodeAddress
    );

    /**
     * @dev Emitted when a node address is unlinked from a validator.
     */
    event NodeAddressWasRemoved(
        uint validatorId,
        address nodeAddress
    );

    /**
     * @dev Emitted when whitelist disabled.
     */
    event WhitelistDisabled(bool status);

    /**
     * @dev Emitted when validator requested new address.
     */
    event RequestNewAddress(uint indexed validatorId, address previousAddress, address newAddress);

    /**
     * @dev Emitted when validator set new minimum delegation amount.
     */
    event SetMinimumDelegationAmount(uint indexed validatorId, uint previousMDA, uint newMDA);

    /**
     * @dev Emitted when validator set new name.
     */
    event SetValidatorName(uint indexed validatorId, string previousName, string newName);

    /**
     * @dev Emitted when validator set new description.
     */
    event SetValidatorDescription(uint indexed validatorId, string previousDescription, string newDescription);

    /**
     * @dev Emitted when validator start or stop accepting new delegation requests.
     */
    event AcceptingNewRequests(uint indexed validatorId, bool status);
    
    function registerValidator(
        string calldata name,
        string calldata description,
        uint feeRate,
        uint minimumDelegationAmount
    )
        external
        returns (uint validatorId);
    function enableValidator(uint validatorId) external;
    function disableValidator(uint validatorId) external;
    function disableWhitelist() external;
    function requestForNewAddress(address newValidatorAddress) external;
    function confirmNewAddress(uint validatorId) external;
    function linkNodeAddress(address nodeAddress, bytes calldata sig) external;
    function unlinkNodeAddress(address nodeAddress) external;
    function setValidatorMDA(uint minimumDelegationAmount) external;
    function setValidatorName(string calldata newName) external;
    function setValidatorDescription(string calldata newDescription) external;
    function startAcceptingNewRequests() external;
    function stopAcceptingNewRequests() external;
    function removeNodeAddress(uint validatorId, address nodeAddress) external;
    function getAndUpdateBondAmount(uint validatorId) external returns (uint);
    function getMyNodesAddresses() external view returns (address[] memory);
    function getTrustedValidators() external view returns (uint[] memory);
    function checkValidatorAddressToId(address validatorAddress, uint validatorId)
        external
        view
        returns (bool);
    function getValidatorIdByNodeAddress(address nodeAddress) external view returns (uint validatorId);
    function checkValidatorCanReceiveDelegation(uint validatorId, uint amount) external view;
    function getNodeAddresses(uint validatorId) external view returns (address[] memory);
    function validatorExists(uint validatorId) external view returns (bool);
    function validatorAddressExists(address validatorAddress) external view returns (bool);
    function checkIfValidatorAddressExists(address validatorAddress) external view;
    function getValidator(uint validatorId) external view returns (Validator memory);
    function getValidatorId(address validatorAddress) external view returns (uint);
    function isAcceptingNewRequests(uint validatorId) external view returns (bool);
    function isAuthorizedValidator(uint validatorId) external view returns (bool);
}

File 7 of 21 : IDelegationController.sol
// SPDX-License-Identifier: AGPL-3.0-only

/*
    IDelegationController.sol - SKALE Manager
    Copyright (C) 2018-Present SKALE Labs
    @author Artem Payvin

    SKALE Manager is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    SKALE Manager is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with SKALE Manager.  If not, see <https://www.gnu.org/licenses/>.
*/

pragma solidity >=0.6.10 <0.9.0;

interface IDelegationController {
    enum State {
        PROPOSED,
        ACCEPTED,
        CANCELED,
        REJECTED,
        DELEGATED,
        UNDELEGATION_REQUESTED,
        COMPLETED
    }

    struct Delegation {
        address holder; // address of token owner
        uint validatorId;
        uint amount;
        uint delegationPeriod;
        uint created; // time of delegation creation
        uint started; // month when a delegation becomes active
        uint finished; // first month after a delegation ends
        string info;
    }

    /**
     * @dev Emitted when validator was confiscated.
     */
    event Confiscated(
        uint indexed validatorId,
        uint amount
    );

    /**
     * @dev Emitted when validator was confiscated.
     */
    event SlashesProcessed(
        address indexed holder,
        uint limit
    );

    /**
     * @dev Emitted when a delegation is proposed to a validator.
     */
    event DelegationProposed(
        uint delegationId
    );

    /**
     * @dev Emitted when a delegation is accepted by a validator.
     */
    event DelegationAccepted(
        uint delegationId
    );

    /**
     * @dev Emitted when a delegation is cancelled by the delegator.
     */
    event DelegationRequestCanceledByUser(
        uint delegationId
    );

    /**
     * @dev Emitted when a delegation is requested to undelegate.
     */
    event UndelegationRequested(
        uint delegationId
    );
    
    function getAndUpdateDelegatedToValidatorNow(uint validatorId) external returns (uint);
    function getAndUpdateDelegatedAmount(address holder) external returns (uint);
    function getAndUpdateEffectiveDelegatedByHolderToValidator(address holder, uint validatorId, uint month)
        external
        returns (uint effectiveDelegated);
    function delegate(
        uint validatorId,
        uint amount,
        uint delegationPeriod,
        string calldata info
    )
        external;
    function cancelPendingDelegation(uint delegationId) external;
    function acceptPendingDelegation(uint delegationId) external;
    function requestUndelegation(uint delegationId) external;
    function confiscate(uint validatorId, uint amount) external;
    function getAndUpdateEffectiveDelegatedToValidator(uint validatorId, uint month) external returns (uint);
    function getAndUpdateDelegatedByHolderToValidatorNow(address holder, uint validatorId) external returns (uint);
    function processSlashes(address holder, uint limit) external;
    function processAllSlashes(address holder) external;
    function getEffectiveDelegatedValuesByValidator(uint validatorId) external view returns (uint[] memory);
    function getEffectiveDelegatedToValidator(uint validatorId, uint month) external view returns (uint);
    function getDelegatedToValidator(uint validatorId, uint month) external view returns (uint);
    function getDelegation(uint delegationId) external view returns (Delegation memory);
    function getFirstDelegationMonth(address holder, uint validatorId) external view returns(uint);
    function getDelegationsByValidatorLength(uint validatorId) external view returns (uint);
    function getDelegationsByHolderLength(address holder) external view returns (uint);
    function getState(uint delegationId) external view returns (State state);
    function getLockedInPendingDelegations(address holder) external view returns (uint);
    function hasUnprocessedSlashes(address holder) external view returns (bool);
}

File 8 of 21 : ITimeHelpers.sol
// SPDX-License-Identifier: AGPL-3.0-only

/*
    ITimeHelpers.sol - SKALE Manager
    Copyright (C) 2018-Present SKALE Labs
    @author Artem Payvin

    SKALE Manager is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    SKALE Manager is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with SKALE Manager.  If not, see <https://www.gnu.org/licenses/>.
*/

pragma solidity >=0.6.10 <0.9.0;

interface ITimeHelpers {
    function calculateProofOfUseLockEndTime(uint month, uint lockUpPeriodDays) external view returns (uint timestamp);
    function getCurrentMonth() external view returns (uint);
    function timestampToYear(uint timestamp) external view returns (uint);
    function timestampToMonth(uint timestamp) external view returns (uint);
    function monthToTimestamp(uint month) external view returns (uint timestamp);
    function addDays(uint fromTimestamp, uint n) external pure returns (uint);
    function addMonths(uint fromTimestamp, uint n) external pure returns (uint);
    function addYears(uint fromTimestamp, uint n) external pure returns (uint);
}

File 9 of 21 : Permissions.sol
// SPDX-License-Identifier: AGPL-3.0-only

/*
    Permissions.sol - SKALE Manager
    Copyright (C) 2018-Present SKALE Labs
    @author Artem Payvin

    SKALE Manager is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    SKALE Manager is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with SKALE Manager.  If not, see <https://www.gnu.org/licenses/>.
*/

pragma solidity 0.8.17;

import "@skalenetwork/skale-manager-interfaces/IContractManager.sol";
import "@skalenetwork/skale-manager-interfaces/IPermissions.sol";

import "./thirdparty/openzeppelin/AccessControlUpgradeableLegacy.sol";


/**
 * @title Permissions
 * @dev Contract is connected module for Upgradeable approach, knows ContractManager
 */
contract Permissions is AccessControlUpgradeableLegacy, IPermissions {
    using AddressUpgradeable for address;

    IContractManager public contractManager;

    /**
     * @dev Modifier to make a function callable only when caller is the Owner.
     *
     * Requirements:
     *
     * - The caller must be the owner.
     */
    modifier onlyOwner() {
        require(_isOwner(), "Caller is not the owner");
        _;
    }

    /**
     * @dev Modifier to make a function callable only when caller is an Admin.
     *
     * Requirements:
     *
     * - The caller must be an admin.
     */
    modifier onlyAdmin() {
        require(_isAdmin(msg.sender), "Caller is not an admin");
        _;
    }

    /**
     * @dev Modifier to make a function callable only when caller is the Owner
     * or `contractName` contract.
     *
     * Requirements:
     *
     * - The caller must be the owner or `contractName`.
     */
    modifier allow(string memory contractName) {
        require(
            contractManager.getContract(contractName) == msg.sender || _isOwner(),
            "Message sender is invalid");
        _;
    }

    /**
     * @dev Modifier to make a function callable only when caller is the Owner
     * or `contractName1` or `contractName2` contract.
     *
     * Requirements:
     *
     * - The caller must be the owner, `contractName1`, or `contractName2`.
     */
    modifier allowTwo(string memory contractName1, string memory contractName2) {
        require(
            contractManager.getContract(contractName1) == msg.sender ||
            contractManager.getContract(contractName2) == msg.sender ||
            _isOwner(),
            "Message sender is invalid");
        _;
    }

    /**
     * @dev Modifier to make a function callable only when caller is the Owner
     * or `contractName1`, `contractName2`, or `contractName3` contract.
     *
     * Requirements:
     *
     * - The caller must be the owner, `contractName1`, `contractName2`, or
     * `contractName3`.
     */
    modifier allowThree(string memory contractName1, string memory contractName2, string memory contractName3) {
        require(
            contractManager.getContract(contractName1) == msg.sender ||
            contractManager.getContract(contractName2) == msg.sender ||
            contractManager.getContract(contractName3) == msg.sender ||
            _isOwner(),
            "Message sender is invalid");
        _;
    }

    function initialize(address contractManagerAddress) public virtual override initializer {
        AccessControlUpgradeableLegacy.__AccessControl_init();
        _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
        _setContractManager(contractManagerAddress);
    }

    function _isOwner() internal view returns (bool) {
        return hasRole(DEFAULT_ADMIN_ROLE, msg.sender);
    }

    function _isAdmin(address account) internal view returns (bool) {
        address skaleManagerAddress = contractManager.contracts(keccak256(abi.encodePacked("SkaleManager")));
        if (skaleManagerAddress != address(0)) {
            AccessControlUpgradeableLegacy skaleManager = AccessControlUpgradeableLegacy(skaleManagerAddress);
            return skaleManager.hasRole(keccak256("ADMIN_ROLE"), account) || _isOwner();
        } else {
            return _isOwner();
        }
    }

    function _setContractManager(address contractManagerAddress) private {
        require(contractManagerAddress != address(0), "ContractManager address is not set");
        require(contractManagerAddress.isContract(), "Address is not contract");
        contractManager = IContractManager(contractManagerAddress);
    }
}

File 10 of 21 : ConstantsHolder.sol
// SPDX-License-Identifier: AGPL-3.0-only

/*
    ConstantsHolder.sol - SKALE Manager
    Copyright (C) 2018-Present SKALE Labs
    @author Artem Payvin

    SKALE Manager is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    SKALE Manager is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with SKALE Manager.  If not, see <https://www.gnu.org/licenses/>.
*/

pragma solidity 0.8.17;

import "@skalenetwork/skale-manager-interfaces/IConstantsHolder.sol";

import "./Permissions.sol";


/**
 * @title ConstantsHolder
 * @dev Contract contains constants and common variables for the SKALE Network.
 */
contract ConstantsHolder is Permissions, IConstantsHolder {

    // initial price for creating Node (100 SKL)
    uint public constant NODE_DEPOSIT = 100 * 1e18;

    uint8 public constant TOTAL_SPACE_ON_NODE = 128;

    // part of Node for Small Skale-chain (1/128 of Node)
    uint8 public constant SMALL_DIVISOR = 128;

    // part of Node for Medium Skale-chain (1/32 of Node)
    uint8 public constant MEDIUM_DIVISOR = 32;

    // part of Node for Large Skale-chain (full Node)
    uint8 public constant LARGE_DIVISOR = 1;

    // part of Node for Medium Test Skale-chain (1/4 of Node)
    uint8 public constant MEDIUM_TEST_DIVISOR = 4;

    // typically number of Nodes for Skale-chain (16 Nodes)
    uint public constant NUMBER_OF_NODES_FOR_SCHAIN = 16;

    // number of Nodes for Test Skale-chain (2 Nodes)
    uint public constant NUMBER_OF_NODES_FOR_TEST_SCHAIN = 2;

    // number of Nodes for Test Skale-chain (4 Nodes)
    uint public constant NUMBER_OF_NODES_FOR_MEDIUM_TEST_SCHAIN = 4;

    // number of seconds in one year
    uint32 public constant SECONDS_TO_YEAR = 31622400;

    // initial number of monitors
    uint public constant NUMBER_OF_MONITORS = 24;

    uint public constant OPTIMAL_LOAD_PERCENTAGE = 80;

    uint public constant ADJUSTMENT_SPEED = 1000;

    uint public constant COOLDOWN_TIME = 60;

    uint public constant MIN_PRICE = 10**6;

    uint public constant MSR_REDUCING_COEFFICIENT = 2;

    uint public constant DOWNTIME_THRESHOLD_PART = 30;

    uint public constant BOUNTY_LOCKUP_MONTHS = 2;

    uint public constant ALRIGHT_DELTA = 134161;
    uint public constant BROADCAST_DELTA = 177490;
    uint public constant COMPLAINT_BAD_DATA_DELTA = 80995;
    uint public constant PRE_RESPONSE_DELTA = 100061;
    uint public constant COMPLAINT_DELTA = 106611;
    uint public constant RESPONSE_DELTA = 48132;

    // MSR - Minimum staking requirement
    uint public msr;

    // Reward period - 30 days (each 30 days Node would be granted for bounty)
    uint32 public rewardPeriod;

    // Allowable latency - 150000 ms by default
    uint32 public allowableLatency;

    /**
     * Delta period - 1 hour (1 hour before Reward period became Monitors need
     * to send Verdicts and 1 hour after Reward period became Node need to come
     * and get Bounty)
     */
    uint32 public deltaPeriod;

    /**
     * Check time - 2 minutes (every 2 minutes monitors should check metrics
     * from checked nodes)
     */
    uint public checkTime;

    //Need to add minimal allowed parameters for verdicts

    uint public launchTimestamp;

    uint public rotationDelay;

    uint public proofOfUseLockUpPeriodDays;

    uint public proofOfUseDelegationPercentage;

    uint public limitValidatorsPerDelegator;

    uint256 public firstDelegationsMonth; // deprecated

    // date when schains will be allowed for creation
    uint public schainCreationTimeStamp;

    uint public minimalSchainLifetime;

    uint public complaintTimeLimit;

    uint public minNodeBalance;

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

    modifier onlyConstantsHolderManager() {
        require(hasRole(CONSTANTS_HOLDER_MANAGER_ROLE, msg.sender), "CONSTANTS_HOLDER_MANAGER_ROLE is required");
        _;
    }

    /**
     * @dev Allows the Owner to set new reward and delta periods
     * This function is only for tests.
     */
    function setPeriods(uint32 newRewardPeriod, uint32 newDeltaPeriod) external override onlyConstantsHolderManager {
        require(
            newRewardPeriod >= newDeltaPeriod && newRewardPeriod - newDeltaPeriod >= checkTime,
            "Incorrect Periods"
        );
        emit ConstantUpdated(
            keccak256(abi.encodePacked("RewardPeriod")),
            uint(rewardPeriod),
            uint(newRewardPeriod)
        );
        rewardPeriod = newRewardPeriod;
        emit ConstantUpdated(
            keccak256(abi.encodePacked("DeltaPeriod")),
            uint(deltaPeriod),
            uint(newDeltaPeriod)
        );
        deltaPeriod = newDeltaPeriod;
    }

    /**
     * @dev Allows the Owner to set the new check time.
     * This function is only for tests.
     */
    function setCheckTime(uint newCheckTime) external override onlyConstantsHolderManager {
        require(rewardPeriod - deltaPeriod >= checkTime, "Incorrect check time");
        emit ConstantUpdated(
            keccak256(abi.encodePacked("CheckTime")),
            uint(checkTime),
            uint(newCheckTime)
        );
        checkTime = newCheckTime;
    }

    /**
     * @dev Allows the Owner to set the allowable latency in milliseconds.
     * This function is only for testing purposes.
     */
    function setLatency(uint32 newAllowableLatency) external override onlyConstantsHolderManager {
        emit ConstantUpdated(
            keccak256(abi.encodePacked("AllowableLatency")),
            uint(allowableLatency),
            uint(newAllowableLatency)
        );
        allowableLatency = newAllowableLatency;
    }

    /**
     * @dev Allows the Owner to set the minimum stake requirement.
     */
    function setMSR(uint newMSR) external override onlyConstantsHolderManager {
        emit ConstantUpdated(
            keccak256(abi.encodePacked("MSR")),
            uint(msr),
            uint(newMSR)
        );
        msr = newMSR;
    }

    /**
     * @dev Allows the Owner to set the launch timestamp.
     */
    function setLaunchTimestamp(uint timestamp) external override onlyConstantsHolderManager {
        require(
            block.timestamp < launchTimestamp,
            "Cannot set network launch timestamp because network is already launched"
        );
        emit ConstantUpdated(
            keccak256(abi.encodePacked("LaunchTimestamp")),
            uint(launchTimestamp),
            uint(timestamp)
        );
        launchTimestamp = timestamp;
    }

    /**
     * @dev Allows the Owner to set the node rotation delay.
     */
    function setRotationDelay(uint newDelay) external override onlyConstantsHolderManager {
        emit ConstantUpdated(
            keccak256(abi.encodePacked("RotationDelay")),
            uint(rotationDelay),
            uint(newDelay)
        );
        rotationDelay = newDelay;
    }

    /**
     * @dev Allows the Owner to set the proof-of-use lockup period.
     */
    function setProofOfUseLockUpPeriod(uint periodDays) external override onlyConstantsHolderManager {
        emit ConstantUpdated(
            keccak256(abi.encodePacked("ProofOfUseLockUpPeriodDays")),
            uint(proofOfUseLockUpPeriodDays),
            uint(periodDays)
        );
        proofOfUseLockUpPeriodDays = periodDays;
    }

    /**
     * @dev Allows the Owner to set the proof-of-use delegation percentage
     * requirement.
     */
    function setProofOfUseDelegationPercentage(uint percentage) external override onlyConstantsHolderManager {
        require(percentage <= 100, "Percentage value is incorrect");
        emit ConstantUpdated(
            keccak256(abi.encodePacked("ProofOfUseDelegationPercentage")),
            uint(proofOfUseDelegationPercentage),
            uint(percentage)
        );
        proofOfUseDelegationPercentage = percentage;
    }

    /**
     * @dev Allows the Owner to set the maximum number of validators that a
     * single delegator can delegate to.
     */
    function setLimitValidatorsPerDelegator(uint newLimit) external override onlyConstantsHolderManager {
        emit ConstantUpdated(
            keccak256(abi.encodePacked("LimitValidatorsPerDelegator")),
            uint(limitValidatorsPerDelegator),
            uint(newLimit)
        );
        limitValidatorsPerDelegator = newLimit;
    }

    function setSchainCreationTimeStamp(uint timestamp) external override onlyConstantsHolderManager {
        emit ConstantUpdated(
            keccak256(abi.encodePacked("SchainCreationTimeStamp")),
            uint(schainCreationTimeStamp),
            uint(timestamp)
        );
        schainCreationTimeStamp = timestamp;
    }

    function setMinimalSchainLifetime(uint lifetime) external override onlyConstantsHolderManager {
        emit ConstantUpdated(
            keccak256(abi.encodePacked("MinimalSchainLifetime")),
            uint(minimalSchainLifetime),
            uint(lifetime)
        );
        minimalSchainLifetime = lifetime;
    }

    function setComplaintTimeLimit(uint timeLimit) external override onlyConstantsHolderManager {
        emit ConstantUpdated(
            keccak256(abi.encodePacked("ComplaintTimeLimit")),
            uint(complaintTimeLimit),
            uint(timeLimit)
        );
        complaintTimeLimit = timeLimit;
    }

    function setMinNodeBalance(uint newMinNodeBalance) external override onlyConstantsHolderManager {
        emit ConstantUpdated(
            keccak256(abi.encodePacked("MinNodeBalance")),
            uint(minNodeBalance),
            uint(newMinNodeBalance)
        );
        minNodeBalance = newMinNodeBalance;
    }

    function reinitialize() external override reinitializer(2) {
        minNodeBalance = 1.5 ether;
    }

    function initialize(address contractsAddress) public override initializer {
        Permissions.initialize(contractsAddress);

        msr = 0;
        rewardPeriod = 2592000;
        allowableLatency = 150000;
        deltaPeriod = 3600;
        checkTime = 300;
        launchTimestamp = type(uint).max;
        rotationDelay = 12 hours;
        proofOfUseLockUpPeriodDays = 90;
        proofOfUseDelegationPercentage = 50;
        limitValidatorsPerDelegator = 20;
        firstDelegationsMonth = 0;
        complaintTimeLimit = 1800;
        minNodeBalance = 1.5 ether;
    }
}

File 11 of 21 : MathUtils.sol
// SPDX-License-Identifier: AGPL-3.0-only

/*
    MathUtils.sol - SKALE Manager
    Copyright (C) 2018-Present SKALE Labs
    @author Dmytro Stebaiev

    SKALE Manager is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    SKALE Manager is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with SKALE Manager.  If not, see <https://www.gnu.org/licenses/>.
*/

pragma solidity 0.8.17;


library MathUtils {

    uint constant private _EPS = 1e6;

    event UnderflowError(
        uint a,
        uint b
    );

    function boundedSub(uint256 a, uint256 b) internal returns (uint256) {
        if (a >= b) {
            return a - b;
        } else {
            emit UnderflowError(a, b);
            return 0;
        }
    }

    function boundedSubWithoutEvent(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a >= b) {
            return a - b;
        } else {
            return 0;
        }
    }

    function muchGreater(uint256 a, uint256 b) internal pure returns (bool) {
        assert(type(uint).max - _EPS > b);
        return a > b + _EPS;
    }

    function approximatelyEqual(uint256 a, uint256 b) internal pure returns (bool) {
        if (a > b) {
            return a - b < _EPS;
        } else {
            return b - a < _EPS;
        }
    }
}

File 12 of 21 : IContractManager.sol
// SPDX-License-Identifier: AGPL-3.0-only

/*
    IContractManager.sol - SKALE Manager Interfaces
    Copyright (C) 2021-Present SKALE Labs
    @author Dmytro Stebaeiv

    SKALE Manager Interfaces is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    SKALE Manager Interfaces is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with SKALE Manager Interfaces.  If not, see <https://www.gnu.org/licenses/>.
*/

pragma solidity >=0.6.10 <0.9.0;

interface IContractManager {
    /**
     * @dev Emitted when contract is upgraded.
     */
    event ContractUpgraded(string contractsName, address contractsAddress);

    function initialize() external;
    function setContractsAddress(string calldata contractsName, address newContractsAddress) external;
    function contracts(bytes32 nameHash) external view returns (address);
    function getDelegationPeriodManager() external view returns (address);
    function getBounty() external view returns (address);
    function getValidatorService() external view returns (address);
    function getTimeHelpers() external view returns (address);
    function getConstantsHolder() external view returns (address);
    function getSkaleToken() external view returns (address);
    function getTokenState() external view returns (address);
    function getPunisher() external view returns (address);
    function getContract(string calldata name) external view returns (address);
}

File 13 of 21 : IPermissions.sol
// SPDX-License-Identifier: AGPL-3.0-only

/*
    IPermissions.sol - SKALE Manager
    Copyright (C) 2018-Present SKALE Labs
    @author Artem Payvin

    SKALE Manager is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    SKALE Manager is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with SKALE Manager.  If not, see <https://www.gnu.org/licenses/>.
*/

pragma solidity >=0.6.10 <0.9.0;

interface IPermissions {
    function initialize(address contractManagerAddress) external;
}

File 14 of 21 : AccessControlUpgradeableLegacy.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol";
import "@skalenetwork/skale-manager-interfaces/thirdparty/openzeppelin/IAccessControlUpgradeableLegacy.sol";
import "./InitializableWithGap.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms.
 *
 * 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, _msgSender()));
 *     ...
 * }
 * ```
 *
 * 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}.
 */
abstract contract AccessControlUpgradeableLegacy is InitializableWithGap, ContextUpgradeable, IAccessControlUpgradeableLegacy {
    function __AccessControl_init() internal initializer {
        __Context_init_unchained();
        __AccessControl_init_unchained();
    }

    function __AccessControl_init_unchained() internal initializer {


    }

    using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet;

    struct RoleData {
        EnumerableSetUpgradeable.AddressSet members;
        bytes32 adminRole;
    }

    mapping (bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

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

    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) public view override returns (uint256) {
        return _roles[role].members.length();
    }

    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) public view override returns (address) {
        return _roles[role].members.at(index);
    }

    /**
     * @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 {
        require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to grant");

        _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 {
        require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to revoke");

        _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 granted `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}.
     * ====
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

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

    function _grantRole(bytes32 role, address account) private {
        if (_roles[role].members.add(account)) {
            emit RoleGranted(role, account, _msgSender());
        }
    }

    function _revokeRole(bytes32 role, address account) private {
        if (_roles[role].members.remove(account)) {
            emit RoleRevoked(role, account, _msgSender());
        }
    }

    uint256[49] private __gap;
}

File 15 of 21 : EnumerableSetUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/structs/EnumerableSet.sol)

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 *  Trying to delete such a structure from storage will likely result in data corruption, rendering the structure unusable.
 *  See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 *  In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an array of EnumerableSet.
 * ====
 */
library EnumerableSetUpgradeable {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastValue;
                // Update the index for the moved value
                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        return _values(set._inner);
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}

File 16 of 21 : 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 {
    }

    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;
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}

File 17 of 21 : IAccessControlUpgradeableLegacy.sol
// SPDX-License-Identifier: AGPL-3.0-only

/*
    IAccessControlUpgradeableLegacy.sol - SKALE Manager
    Copyright (C) 2018-Present SKALE Labs
    @author Artem Payvin

    SKALE Manager is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    SKALE Manager is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with SKALE Manager.  If not, see <https://www.gnu.org/licenses/>.
*/

pragma solidity >=0.6.10 <0.9.0;

interface IAccessControlUpgradeableLegacy {
    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {_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);
    
    function grantRole(bytes32 role, address account) external;
    function revokeRole(bytes32 role, address account) external;
    function renounceRole(bytes32 role, address account) external;
    function hasRole(bytes32 role, address account) external view returns (bool);
    function getRoleMemberCount(bytes32 role) external view returns (uint256);
    function getRoleMember(bytes32 role, uint256 index) external view returns (address);
    function getRoleAdmin(bytes32 role) external view returns (bytes32);
}

File 18 of 21 : InitializableWithGap.sol
// SPDX-License-Identifier: AGPL-3.0-only

pragma solidity ^0.8.7;

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


contract InitializableWithGap is Initializable {
    uint256[50] private ______gap;
}

File 19 of 21 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

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

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

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

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.
     */
    modifier initializer() {
        bool isTopLevelCall = !_initializing;
        require(
            (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
            "Initializable: contract is already initialized"
        );
        _initialized = 1;
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original
     * initialization step. This is essential to configure modules that are added through upgrades and that require
     * initialization.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _initialized = version;
        _initializing = true;
        _;
        _initializing = false;
        emit Initialized(version);
    }

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

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     */
    function _disableInitializers() internal virtual {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized < type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }
}

File 20 of 21 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @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
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 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
                /// @solidity memory-safe-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 21 of 21 : IConstantsHolder.sol
// SPDX-License-Identifier: AGPL-3.0-only

/*
    IConstantsHolder.sol - SKALE Manager Interfaces
    Copyright (C) 2021-Present SKALE Labs
    @author Artem Payvin

    SKALE Manager Interfaces is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    SKALE Manager Interfaces is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with SKALE Manager Interfaces.  If not, see <https://www.gnu.org/licenses/>.
*/

pragma solidity >=0.6.10 <0.9.0;

interface IConstantsHolder {

    /**
     * @dev Emitted when constants updated.
     */
    event ConstantUpdated(
        bytes32 indexed constantHash,
        uint previousValue,
        uint newValue
    );

    function setPeriods(uint32 newRewardPeriod, uint32 newDeltaPeriod) external;
    function setCheckTime(uint newCheckTime) external;
    function setLatency(uint32 newAllowableLatency) external;
    function setMSR(uint newMSR) external;
    function setLaunchTimestamp(uint timestamp) external;
    function setRotationDelay(uint newDelay) external;
    function setProofOfUseLockUpPeriod(uint periodDays) external;
    function setProofOfUseDelegationPercentage(uint percentage) external;
    function setLimitValidatorsPerDelegator(uint newLimit) external;
    function setSchainCreationTimeStamp(uint timestamp) external;
    function setMinimalSchainLifetime(uint lifetime) external;
    function setComplaintTimeLimit(uint timeLimit) external;
    function setMinNodeBalance(uint newMinNodeBalance) external;
    function reinitialize() external;
    function msr() external view returns (uint);
    function launchTimestamp() external view returns (uint);
    function rotationDelay() external view returns (uint);
    function limitValidatorsPerDelegator() external view returns (uint);
    function schainCreationTimeStamp() external view returns (uint);
    function minimalSchainLifetime() external view returns (uint);
    function complaintTimeLimit() external view returns (uint);
    function minNodeBalance() external view returns (uint);
}

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":"validatorId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"BountyWasPaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","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":"address","name":"holder","type":"address"},{"indexed":false,"internalType":"uint256","name":"validatorId","type":"uint256"},{"indexed":false,"internalType":"address","name":"destination","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawBounty","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"validatorId","type":"uint256"},{"indexed":false,"internalType":"address","name":"destination","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawFee","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"contractManager","outputs":[{"internalType":"contract IContractManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"}],"name":"getAndUpdateEarnedBountyAmount","outputs":[{"internalType":"uint256","name":"earned","type":"uint256"},{"internalType":"uint256","name":"endMonth","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"wallet","type":"address"},{"internalType":"uint256","name":"validatorId","type":"uint256"}],"name":"getAndUpdateEarnedBountyAmountOf","outputs":[{"internalType":"uint256","name":"earned","type":"uint256"},{"internalType":"uint256","name":"endMonth","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getEarnedFeeAmount","outputs":[{"internalType":"uint256","name":"earned","type":"uint256"},{"internalType":"uint256","name":"endMonth","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"}],"name":"getEarnedFeeAmountOf","outputs":[{"internalType":"uint256","name":"earned","type":"uint256"},{"internalType":"uint256","name":"endMonth","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getRoleMember","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleMemberCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"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":"contractsAddress","type":"address"}],"name":"initialize","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":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"userData","type":"bytes"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"tokensReceived","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"address","name":"to","type":"address"}],"name":"withdrawBounty","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"withdrawFee","outputs":[],"stateMutability":"nonpayable","type":"function"}]

608060405234801561001057600080fd5b50612625806100206000396000f3fe608060405234801561001057600080fd5b506004361061010a5760003560e01c806376d07f6b116100a2578063af6967bb11610071578063af6967bb1461023f578063b39e12cf14610252578063c4d66de814610265578063ca15c87314610278578063d547741f1461028b57600080fd5b806376d07f6b146101d65780639010d07c146101e957806391d1485414610214578063a217fddf1461023757600080fd5b80632f2ff15d116100de5780632f2ff15d14610195578063312ddd2d146101a857806336568abe146101b057806366d9fab6146101c357600080fd5b806223de291461010f5780631ac3ddeb14610124578063248a9ca3146101375780632906264a1461016d575b600080fd5b61012261011d366004612083565b61029e565b005b610122610132366004612134565b610461565b61015a610145366004612158565b60009081526065602052604090206002015490565b6040519081526020015b60405180910390f35b61018061017b366004612158565b61097e565b60408051928352602083019190915201610164565b6101226101a3366004612171565b610af1565b610180610b7f565b6101226101be366004612171565b610c6b565b6101806101d13660046121a1565b610ce5565b6101226101e4366004612171565b61109f565b6101fc6101f73660046121cd565b6114ea565b6040516001600160a01b039091168152602001610164565b610227610222366004612171565b61150b565b6040519015158152602001610164565b61015a600081565b61018061024d366004612158565b611523565b6097546101fc906001600160a01b031681565b610122610273366004612134565b611539565b61015a610286366004612158565b611697565b610122610299366004612171565b6116ae565b604080518082018252600a81526929b5b0b632aa37b5b2b760b11b60208201526097549151633581777360e01b8152909133916001600160a01b03909116906335817773906102f1908590600401612213565b602060405180830381865afa15801561030e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103329190612256565b6001600160a01b0316148061034a575061034a61172f565b61039b5760405162461bcd60e51b815260206004820152601960248201527f4d6573736167652073656e64657220697320696e76616c69640000000000000060448201526064015b60405180910390fd5b6001600160a01b03871630146103eb5760405162461bcd60e51b8152602060048201526015602482015274149958d95a5d995c881a5cc81a5b98dbdc9c9958dd605a1b6044820152606401610392565b6020841461043b5760405162461bcd60e51b815260206004820152601860248201527f44617461206c656e67746820697320696e636f727265637400000000000000006044820152606401610392565b600061044985870187612158565b90506104558782611740565b50505050505050505050565b609754604051633581777360e01b81526000916001600160a01b03169063358177739061049090600401612273565b602060405180830381865afa1580156104ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104d19190612256565b609754604051633581777360e01b815260206004820152600a60248201526929b5b0b632aa37b5b2b760b11b60448201529192506000916001600160a01b0390911690633581777390606401602060405180830381865afa15801561053a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061055e9190612256565b609754604051633581777360e01b81529192506000916001600160a01b03909116906335817773906105929060040161229d565b602060405180830381865afa1580156105af573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105d39190612256565b609754604051633581777360e01b815260206004820152600f60248201526e21b7b739ba30b73a39a437b63232b960891b60448201529192506000916001600160a01b0390911690633581777390606401602060405180830381865afa158015610641573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106659190612256565b9050816001600160a01b0316634355644d826001600160a01b03166365cf7c9b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156106b4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106d891906122c2565b836001600160a01b031663d62d5bb86040518163ffffffff1660e01b8152600401602060405180830381865afa158015610716573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061073a91906122c2565b6040516001600160e01b031960e085901b16815260048101929092526024820152604401602060405180830381865afa15801561077b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061079f91906122c2565b4210156107de5760405162461bcd60e51b815260206004820152600d60248201526c119959481a5cc81b1bd8dad959609a1b6044820152606401610392565b604051630ba7341960e11b81523360048201526000906001600160a01b0386169063174e683290602401602060405180830381865afa158015610825573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061084991906122c2565b90506000806108578361097e565b6000858152609c6020526040908190208290555163a9059cbb60e01b81526001600160a01b038b81166004830152602482018490529294509092509087169063a9059cbb906044016020604051808303816000875af11580156108be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108e291906122eb565b61092a5760405162461bcd60e51b81526020600482015260196024820152784661696c656420746f207472616e7366657220746f6b656e7360381b6044820152606401610392565b604080518481526001600160a01b038a1660208201529081018390527fd6dedabc1e5ce29aec4ffd8504fa7c09b9c9c2f53b0e745f0b6a9b1e5c19f0dd906060015b60405180910390a15050505050505050565b609754604051633581777360e01b8152600091829182916001600160a01b0316906335817773906109b19060040161229d565b602060405180830381865afa1580156109ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109f29190612256565b90506000816001600160a01b031663ddd1b67e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a34573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a5891906122c2565b6000868152609c6020526040812054919250819003610a7f57506000958695509350505050565b6000945081935080600c610a93919061231c565b841115610aa857610aa581600c61231c565b93505b805b84811015610ae8576000878152609a60209081526040808320848452909152902054610ad6908761231c565b9550610ae18161232f565b9050610aaa565b50505050915091565b600082815260656020526040902060020154610b0d903361150b565b610b715760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e60448201526e0818591b5a5b881d1bc819dc985b9d608a1b6064820152608401610392565b610b7b8282611a02565b5050565b609754604051633581777360e01b8152600091829182916001600160a01b031690633581777390610bb290600401612273565b602060405180830381865afa158015610bcf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bf39190612256565b604051630ba7341960e11b8152336004820152909150610c62906001600160a01b0383169063174e683290602401602060405180830381865afa158015610c3e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061017b91906122c2565b92509250509091565b6001600160a01b0381163314610cdb5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610392565b610b7b8282611a5b565b609754604051633581777360e01b81526020600482015260146024820152732232b632b3b0ba34b7b721b7b73a3937b63632b960611b6044820152600091829182916001600160a01b031690633581777390606401602060405180830381865afa158015610d57573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d7b9190612256565b609754604051633581777360e01b81529192506000916001600160a01b0390911690633581777390610daf9060040161229d565b602060405180830381865afa158015610dcc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610df09190612256565b90506000816001600160a01b031663ddd1b67e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e32573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e5691906122c2565b6001600160a01b0388166000908152609b602090815260408083208a8452909152812054919250819003610f0f57604051634b2a7f8b60e11b81526001600160a01b03898116600483015260248201899052851690639654ff1690604401602060405180830381865afa158015610ed1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ef591906122c2565b905080600003610f0f576000809550955050505050611098565b6000955081945080600c610f23919061231c565b851115610f3857610f3581600c61231c565b94505b805b8581101561109257604051630416880b60e41b815260048101899052602481018290526000906001600160a01b0387169063416880b0906044016020604051808303816000875af1158015610f93573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fb791906122c2565b9050610fc4816000611ab4565b15611081576040516301c037ff60e31b81526001600160a01b038b81166004830152602482018b905260448201849052829190881690630e01bff8906064016020604051808303816000875af1158015611022573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061104691906122c2565b60008b815260996020908152604080832087845290915290205461106a9190612348565b611074919061235f565b61107e908961231c565b97505b5061108b8161232f565b9050610f3a565b50505050505b9250929050565b609754604051633581777360e01b81526000916001600160a01b0316906335817773906110ce9060040161229d565b602060405180830381865afa1580156110eb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061110f9190612256565b609754604051633581777360e01b815260206004820152600f60248201526e21b7b739ba30b73a39a437b63232b960891b60448201529192506000916001600160a01b0390911690633581777390606401602060405180830381865afa15801561117d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111a19190612256565b9050816001600160a01b0316634355644d826001600160a01b03166365cf7c9b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156111f0573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061121491906122c2565b836001600160a01b031663d62d5bb86040518163ffffffff1660e01b8152600401602060405180830381865afa158015611252573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061127691906122c2565b6040516001600160e01b031960e085901b16815260048101929092526024820152604401602060405180830381865afa1580156112b7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112db91906122c2565b42101561131d5760405162461bcd60e51b815260206004820152601060248201526f109bdd5b9d1e481a5cc81b1bd8dad95960821b6044820152606401610392565b60008061132a3387610ce5565b336000908152609b602090815260408083208b845282528083208490556097549051633581777360e01b81526004810192909252600a60248301526929b5b0b632aa37b5b2b760b11b6044830152939550919350916001600160a01b031690633581777390606401602060405180830381865afa1580156113af573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113d39190612256565b60405163a9059cbb60e01b81526001600160a01b038881166004830152602482018690529192509082169063a9059cbb906044016020604051808303816000875af1158015611426573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061144a91906122eb565b6114925760405162461bcd60e51b81526020600482015260196024820152784661696c656420746f207472616e7366657220746f6b656e7360381b6044820152606401610392565b60408051338152602081018990526001600160a01b038816818301526060810185905290517fa2d778d83fa0634d6e6efcba5c032aca209cb96bb1a612e84986b948cd75f38f9181900360800190a150505050505050565b60008281526065602052604081206115029083611ae9565b90505b92915050565b60008281526065602052604081206115029083611af5565b6000806115303384610ce5565b91509150915091565b600054610100900460ff16158080156115595750600054600160ff909116105b806115735750303b158015611573575060005460ff166001145b61158f5760405162461bcd60e51b815260040161039290612381565b6000805460ff1916600117905580156115b2576000805461ff0019166101001790555b6115bb82611b17565b609880546001600160a01b031916731820a4b7618bde71dce8cdc73aab6c95905fad249081179091556040516329965a1d60e01b815230600482018190527fb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b602483015260448201526329965a1d90606401600060405180830381600087803b15801561164757600080fd5b505af115801561165b573d6000803e3d6000fd5b505050508015610b7b576000805461ff0019169055604051600181526000805160206125d0833981519152906020015b60405180910390a15050565b600081815260656020526040812061150590611bdc565b6000828152606560205260409020600201546116ca903361150b565b610cdb5760405162461bcd60e51b815260206004820152603060248201527f416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e60448201526f2061646d696e20746f207265766f6b6560801b6064820152608401610392565b600061173b813361150b565b905090565b609754604051633581777360e01b81526000916001600160a01b03169063358177739061176f9060040161229d565b602060405180830381865afa15801561178c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117b09190612256565b609754604051633581777360e01b81529192506000916001600160a01b03909116906335817773906117e490600401612273565b602060405180830381865afa158015611801573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118259190612256565b90506000826001600160a01b031663ddd1b67e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611867573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061188b91906122c2565b60405163b5d8962760e01b8152600481018690529091506000906001600160a01b0384169063b5d8962790602401600060405180830381865afa1580156118d6573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526118fe9190810190612497565b60800151905060006103e86119138389612348565b61191d919061235f565b9050600061192b828961257a565b600088815260996020908152604080832088845290915290205490915061195390829061231c565b6000888152609960209081526040808320888452825280832093909355898252609a81528282208783529052205461198c90839061231c565b6000888152609a60209081526040808320888452825280832093909355898252609c90529081205490036119cc576000878152609c602052604090208490555b60408051888152602081018a90527f92ba628f701eb8dddfffbfa9748da1d157c46a4ff477ebd022d3e729249bf1bf910161096c565b6000828152606560205260409020611a1a9082611be6565b15610b7b5760405133906001600160a01b0383169084907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d90600090a45050565b6000828152606560205260409020611a739082611bfb565b15610b7b5760405133906001600160a01b0383169084907ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b90600090a45050565b600081611ac6620f424060001961257a565b11611ad357611ad361258d565b611ae0620f42408361231c565b90921192915050565b60006115028383611c10565b6001600160a01b03811660009081526001830160205260408120541515611502565b600054610100900460ff1615808015611b375750600054600160ff909116105b80611b515750303b158015611b51575060005460ff166001145b611b6d5760405162461bcd60e51b815260040161039290612381565b6000805460ff191660011790558015611b90576000805461ff0019166101001790555b611b98611c3a565b611ba3600033610b71565b611bac82611cfb565b8015610b7b576000805461ff0019169055604051600181526000805160206125d08339815191529060200161168b565b6000611505825490565b6000611502836001600160a01b038416611dd5565b6000611502836001600160a01b038416611e24565b6000826000018281548110611c2757611c276125a3565b9060005260206000200154905092915050565b600054610100900460ff1615808015611c5a5750600054600160ff909116105b80611c745750303b158015611c74575060005460ff166001145b611c905760405162461bcd60e51b815260040161039290612381565b6000805460ff191660011790558015611cb3576000805461ff0019166101001790555b611cbb611f17565b611cc3611f84565b8015611cf8576000805461ff0019169055604051600181526000805160206125d0833981519152906020015b60405180910390a15b50565b6001600160a01b038116611d5c5760405162461bcd60e51b815260206004820152602260248201527f436f6e74726163744d616e616765722061646472657373206973206e6f742073604482015261195d60f21b6064820152608401610392565b6001600160a01b0381163b611db35760405162461bcd60e51b815260206004820152601760248201527f41646472657373206973206e6f7420636f6e74726163740000000000000000006044820152606401610392565b609780546001600160a01b0319166001600160a01b0392909216919091179055565b6000818152600183016020526040812054611e1c57508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155611505565b506000611505565b60008181526001830160205260408120548015611f0d576000611e4860018361257a565b8554909150600090611e5c9060019061257a565b9050818114611ec1576000866000018281548110611e7c57611e7c6125a3565b9060005260206000200154905080876000018481548110611e9f57611e9f6125a3565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080611ed257611ed26125b9565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050611505565b6000915050611505565b600054610100900460ff16611f825760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610392565b565b600054610100900460ff1615808015611fa45750600054600160ff909116105b80611fbe5750303b158015611fbe575060005460ff166001145b611fda5760405162461bcd60e51b815260040161039290612381565b6000805460ff191660011790558015611cc3576000805461ff0019166101001790558015611cf8576000805461ff0019169055604051600181526000805160206125d083398151915290602001611cef565b6001600160a01b0381168114611cf857600080fd5b60008083601f84011261205357600080fd5b50813567ffffffffffffffff81111561206b57600080fd5b60208301915083602082850101111561109857600080fd5b60008060008060008060008060c0898b03121561209f57600080fd5b88356120aa8161202c565b975060208901356120ba8161202c565b965060408901356120ca8161202c565b955060608901359450608089013567ffffffffffffffff808211156120ee57600080fd5b6120fa8c838d01612041565b909650945060a08b013591508082111561211357600080fd5b506121208b828c01612041565b999c989b5096995094979396929594505050565b60006020828403121561214657600080fd5b81356121518161202c565b9392505050565b60006020828403121561216a57600080fd5b5035919050565b6000806040838503121561218457600080fd5b8235915060208301356121968161202c565b809150509250929050565b600080604083850312156121b457600080fd5b82356121bf8161202c565b946020939093013593505050565b600080604083850312156121e057600080fd5b50508035926020909101359150565b60005b8381101561220a5781810151838201526020016121f2565b50506000910152565b60208152600082518060208401526122328160408501602087016121ef565b601f01601f19169190910160400192915050565b80516122518161202c565b919050565b60006020828403121561226857600080fd5b81516121518161202c565b60208082526010908201526f56616c696461746f725365727669636560801b604082015260600190565b6020808252600b908201526a54696d6548656c7065727360a81b604082015260600190565b6000602082840312156122d457600080fd5b5051919050565b8051801515811461225157600080fd5b6000602082840312156122fd57600080fd5b611502826122db565b634e487b7160e01b600052601160045260246000fd5b8082018082111561150557611505612306565b60006001820161234157612341612306565b5060010190565b808202811582820484141761150557611505612306565b60008261237c57634e487b7160e01b600052601260045260246000fd5b500490565b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b634e487b7160e01b600052604160045260246000fd5b604051610100810167ffffffffffffffff81118282101715612409576124096123cf565b60405290565b600082601f83011261242057600080fd5b815167ffffffffffffffff8082111561243b5761243b6123cf565b604051601f8301601f19908116603f01168101908282118183101715612463576124636123cf565b8160405283815286602085880101111561247c57600080fd5b61248d8460208301602089016121ef565b9695505050505050565b6000602082840312156124a957600080fd5b815167ffffffffffffffff808211156124c157600080fd5b9083019061010082860312156124d657600080fd5b6124de6123e5565b8251828111156124ed57600080fd5b6124f98782860161240f565b82525061250860208401612246565b602082015261251960408401612246565b604082015260608301518281111561253057600080fd5b61253c8782860161240f565b6060830152506080830151608082015260a083015160a082015260c083015160c082015261256c60e084016122db565b60e082015295945050505050565b8181038181111561150557611505612306565b634e487b7160e01b600052600160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052603160045260246000fdfe7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498a2646970667358221220665eef9e146b79d21af7caf7fe1c7e922e9dcf52212dd189bd7f279ea02a0bf964736f6c63430008110033

Deployed Bytecode

0x608060405234801561001057600080fd5b506004361061010a5760003560e01c806376d07f6b116100a2578063af6967bb11610071578063af6967bb1461023f578063b39e12cf14610252578063c4d66de814610265578063ca15c87314610278578063d547741f1461028b57600080fd5b806376d07f6b146101d65780639010d07c146101e957806391d1485414610214578063a217fddf1461023757600080fd5b80632f2ff15d116100de5780632f2ff15d14610195578063312ddd2d146101a857806336568abe146101b057806366d9fab6146101c357600080fd5b806223de291461010f5780631ac3ddeb14610124578063248a9ca3146101375780632906264a1461016d575b600080fd5b61012261011d366004612083565b61029e565b005b610122610132366004612134565b610461565b61015a610145366004612158565b60009081526065602052604090206002015490565b6040519081526020015b60405180910390f35b61018061017b366004612158565b61097e565b60408051928352602083019190915201610164565b6101226101a3366004612171565b610af1565b610180610b7f565b6101226101be366004612171565b610c6b565b6101806101d13660046121a1565b610ce5565b6101226101e4366004612171565b61109f565b6101fc6101f73660046121cd565b6114ea565b6040516001600160a01b039091168152602001610164565b610227610222366004612171565b61150b565b6040519015158152602001610164565b61015a600081565b61018061024d366004612158565b611523565b6097546101fc906001600160a01b031681565b610122610273366004612134565b611539565b61015a610286366004612158565b611697565b610122610299366004612171565b6116ae565b604080518082018252600a81526929b5b0b632aa37b5b2b760b11b60208201526097549151633581777360e01b8152909133916001600160a01b03909116906335817773906102f1908590600401612213565b602060405180830381865afa15801561030e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103329190612256565b6001600160a01b0316148061034a575061034a61172f565b61039b5760405162461bcd60e51b815260206004820152601960248201527f4d6573736167652073656e64657220697320696e76616c69640000000000000060448201526064015b60405180910390fd5b6001600160a01b03871630146103eb5760405162461bcd60e51b8152602060048201526015602482015274149958d95a5d995c881a5cc81a5b98dbdc9c9958dd605a1b6044820152606401610392565b6020841461043b5760405162461bcd60e51b815260206004820152601860248201527f44617461206c656e67746820697320696e636f727265637400000000000000006044820152606401610392565b600061044985870187612158565b90506104558782611740565b50505050505050505050565b609754604051633581777360e01b81526000916001600160a01b03169063358177739061049090600401612273565b602060405180830381865afa1580156104ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104d19190612256565b609754604051633581777360e01b815260206004820152600a60248201526929b5b0b632aa37b5b2b760b11b60448201529192506000916001600160a01b0390911690633581777390606401602060405180830381865afa15801561053a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061055e9190612256565b609754604051633581777360e01b81529192506000916001600160a01b03909116906335817773906105929060040161229d565b602060405180830381865afa1580156105af573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105d39190612256565b609754604051633581777360e01b815260206004820152600f60248201526e21b7b739ba30b73a39a437b63232b960891b60448201529192506000916001600160a01b0390911690633581777390606401602060405180830381865afa158015610641573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106659190612256565b9050816001600160a01b0316634355644d826001600160a01b03166365cf7c9b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156106b4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106d891906122c2565b836001600160a01b031663d62d5bb86040518163ffffffff1660e01b8152600401602060405180830381865afa158015610716573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061073a91906122c2565b6040516001600160e01b031960e085901b16815260048101929092526024820152604401602060405180830381865afa15801561077b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061079f91906122c2565b4210156107de5760405162461bcd60e51b815260206004820152600d60248201526c119959481a5cc81b1bd8dad959609a1b6044820152606401610392565b604051630ba7341960e11b81523360048201526000906001600160a01b0386169063174e683290602401602060405180830381865afa158015610825573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061084991906122c2565b90506000806108578361097e565b6000858152609c6020526040908190208290555163a9059cbb60e01b81526001600160a01b038b81166004830152602482018490529294509092509087169063a9059cbb906044016020604051808303816000875af11580156108be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108e291906122eb565b61092a5760405162461bcd60e51b81526020600482015260196024820152784661696c656420746f207472616e7366657220746f6b656e7360381b6044820152606401610392565b604080518481526001600160a01b038a1660208201529081018390527fd6dedabc1e5ce29aec4ffd8504fa7c09b9c9c2f53b0e745f0b6a9b1e5c19f0dd906060015b60405180910390a15050505050505050565b609754604051633581777360e01b8152600091829182916001600160a01b0316906335817773906109b19060040161229d565b602060405180830381865afa1580156109ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109f29190612256565b90506000816001600160a01b031663ddd1b67e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a34573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a5891906122c2565b6000868152609c6020526040812054919250819003610a7f57506000958695509350505050565b6000945081935080600c610a93919061231c565b841115610aa857610aa581600c61231c565b93505b805b84811015610ae8576000878152609a60209081526040808320848452909152902054610ad6908761231c565b9550610ae18161232f565b9050610aaa565b50505050915091565b600082815260656020526040902060020154610b0d903361150b565b610b715760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e60448201526e0818591b5a5b881d1bc819dc985b9d608a1b6064820152608401610392565b610b7b8282611a02565b5050565b609754604051633581777360e01b8152600091829182916001600160a01b031690633581777390610bb290600401612273565b602060405180830381865afa158015610bcf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bf39190612256565b604051630ba7341960e11b8152336004820152909150610c62906001600160a01b0383169063174e683290602401602060405180830381865afa158015610c3e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061017b91906122c2565b92509250509091565b6001600160a01b0381163314610cdb5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610392565b610b7b8282611a5b565b609754604051633581777360e01b81526020600482015260146024820152732232b632b3b0ba34b7b721b7b73a3937b63632b960611b6044820152600091829182916001600160a01b031690633581777390606401602060405180830381865afa158015610d57573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d7b9190612256565b609754604051633581777360e01b81529192506000916001600160a01b0390911690633581777390610daf9060040161229d565b602060405180830381865afa158015610dcc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610df09190612256565b90506000816001600160a01b031663ddd1b67e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e32573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e5691906122c2565b6001600160a01b0388166000908152609b602090815260408083208a8452909152812054919250819003610f0f57604051634b2a7f8b60e11b81526001600160a01b03898116600483015260248201899052851690639654ff1690604401602060405180830381865afa158015610ed1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ef591906122c2565b905080600003610f0f576000809550955050505050611098565b6000955081945080600c610f23919061231c565b851115610f3857610f3581600c61231c565b94505b805b8581101561109257604051630416880b60e41b815260048101899052602481018290526000906001600160a01b0387169063416880b0906044016020604051808303816000875af1158015610f93573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fb791906122c2565b9050610fc4816000611ab4565b15611081576040516301c037ff60e31b81526001600160a01b038b81166004830152602482018b905260448201849052829190881690630e01bff8906064016020604051808303816000875af1158015611022573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061104691906122c2565b60008b815260996020908152604080832087845290915290205461106a9190612348565b611074919061235f565b61107e908961231c565b97505b5061108b8161232f565b9050610f3a565b50505050505b9250929050565b609754604051633581777360e01b81526000916001600160a01b0316906335817773906110ce9060040161229d565b602060405180830381865afa1580156110eb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061110f9190612256565b609754604051633581777360e01b815260206004820152600f60248201526e21b7b739ba30b73a39a437b63232b960891b60448201529192506000916001600160a01b0390911690633581777390606401602060405180830381865afa15801561117d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111a19190612256565b9050816001600160a01b0316634355644d826001600160a01b03166365cf7c9b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156111f0573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061121491906122c2565b836001600160a01b031663d62d5bb86040518163ffffffff1660e01b8152600401602060405180830381865afa158015611252573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061127691906122c2565b6040516001600160e01b031960e085901b16815260048101929092526024820152604401602060405180830381865afa1580156112b7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112db91906122c2565b42101561131d5760405162461bcd60e51b815260206004820152601060248201526f109bdd5b9d1e481a5cc81b1bd8dad95960821b6044820152606401610392565b60008061132a3387610ce5565b336000908152609b602090815260408083208b845282528083208490556097549051633581777360e01b81526004810192909252600a60248301526929b5b0b632aa37b5b2b760b11b6044830152939550919350916001600160a01b031690633581777390606401602060405180830381865afa1580156113af573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113d39190612256565b60405163a9059cbb60e01b81526001600160a01b038881166004830152602482018690529192509082169063a9059cbb906044016020604051808303816000875af1158015611426573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061144a91906122eb565b6114925760405162461bcd60e51b81526020600482015260196024820152784661696c656420746f207472616e7366657220746f6b656e7360381b6044820152606401610392565b60408051338152602081018990526001600160a01b038816818301526060810185905290517fa2d778d83fa0634d6e6efcba5c032aca209cb96bb1a612e84986b948cd75f38f9181900360800190a150505050505050565b60008281526065602052604081206115029083611ae9565b90505b92915050565b60008281526065602052604081206115029083611af5565b6000806115303384610ce5565b91509150915091565b600054610100900460ff16158080156115595750600054600160ff909116105b806115735750303b158015611573575060005460ff166001145b61158f5760405162461bcd60e51b815260040161039290612381565b6000805460ff1916600117905580156115b2576000805461ff0019166101001790555b6115bb82611b17565b609880546001600160a01b031916731820a4b7618bde71dce8cdc73aab6c95905fad249081179091556040516329965a1d60e01b815230600482018190527fb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b602483015260448201526329965a1d90606401600060405180830381600087803b15801561164757600080fd5b505af115801561165b573d6000803e3d6000fd5b505050508015610b7b576000805461ff0019169055604051600181526000805160206125d0833981519152906020015b60405180910390a15050565b600081815260656020526040812061150590611bdc565b6000828152606560205260409020600201546116ca903361150b565b610cdb5760405162461bcd60e51b815260206004820152603060248201527f416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e60448201526f2061646d696e20746f207265766f6b6560801b6064820152608401610392565b600061173b813361150b565b905090565b609754604051633581777360e01b81526000916001600160a01b03169063358177739061176f9060040161229d565b602060405180830381865afa15801561178c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117b09190612256565b609754604051633581777360e01b81529192506000916001600160a01b03909116906335817773906117e490600401612273565b602060405180830381865afa158015611801573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118259190612256565b90506000826001600160a01b031663ddd1b67e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611867573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061188b91906122c2565b60405163b5d8962760e01b8152600481018690529091506000906001600160a01b0384169063b5d8962790602401600060405180830381865afa1580156118d6573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526118fe9190810190612497565b60800151905060006103e86119138389612348565b61191d919061235f565b9050600061192b828961257a565b600088815260996020908152604080832088845290915290205490915061195390829061231c565b6000888152609960209081526040808320888452825280832093909355898252609a81528282208783529052205461198c90839061231c565b6000888152609a60209081526040808320888452825280832093909355898252609c90529081205490036119cc576000878152609c602052604090208490555b60408051888152602081018a90527f92ba628f701eb8dddfffbfa9748da1d157c46a4ff477ebd022d3e729249bf1bf910161096c565b6000828152606560205260409020611a1a9082611be6565b15610b7b5760405133906001600160a01b0383169084907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d90600090a45050565b6000828152606560205260409020611a739082611bfb565b15610b7b5760405133906001600160a01b0383169084907ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b90600090a45050565b600081611ac6620f424060001961257a565b11611ad357611ad361258d565b611ae0620f42408361231c565b90921192915050565b60006115028383611c10565b6001600160a01b03811660009081526001830160205260408120541515611502565b600054610100900460ff1615808015611b375750600054600160ff909116105b80611b515750303b158015611b51575060005460ff166001145b611b6d5760405162461bcd60e51b815260040161039290612381565b6000805460ff191660011790558015611b90576000805461ff0019166101001790555b611b98611c3a565b611ba3600033610b71565b611bac82611cfb565b8015610b7b576000805461ff0019169055604051600181526000805160206125d08339815191529060200161168b565b6000611505825490565b6000611502836001600160a01b038416611dd5565b6000611502836001600160a01b038416611e24565b6000826000018281548110611c2757611c276125a3565b9060005260206000200154905092915050565b600054610100900460ff1615808015611c5a5750600054600160ff909116105b80611c745750303b158015611c74575060005460ff166001145b611c905760405162461bcd60e51b815260040161039290612381565b6000805460ff191660011790558015611cb3576000805461ff0019166101001790555b611cbb611f17565b611cc3611f84565b8015611cf8576000805461ff0019169055604051600181526000805160206125d0833981519152906020015b60405180910390a15b50565b6001600160a01b038116611d5c5760405162461bcd60e51b815260206004820152602260248201527f436f6e74726163744d616e616765722061646472657373206973206e6f742073604482015261195d60f21b6064820152608401610392565b6001600160a01b0381163b611db35760405162461bcd60e51b815260206004820152601760248201527f41646472657373206973206e6f7420636f6e74726163740000000000000000006044820152606401610392565b609780546001600160a01b0319166001600160a01b0392909216919091179055565b6000818152600183016020526040812054611e1c57508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155611505565b506000611505565b60008181526001830160205260408120548015611f0d576000611e4860018361257a565b8554909150600090611e5c9060019061257a565b9050818114611ec1576000866000018281548110611e7c57611e7c6125a3565b9060005260206000200154905080876000018481548110611e9f57611e9f6125a3565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080611ed257611ed26125b9565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050611505565b6000915050611505565b600054610100900460ff16611f825760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610392565b565b600054610100900460ff1615808015611fa45750600054600160ff909116105b80611fbe5750303b158015611fbe575060005460ff166001145b611fda5760405162461bcd60e51b815260040161039290612381565b6000805460ff191660011790558015611cc3576000805461ff0019166101001790558015611cf8576000805461ff0019169055604051600181526000805160206125d083398151915290602001611cef565b6001600160a01b0381168114611cf857600080fd5b60008083601f84011261205357600080fd5b50813567ffffffffffffffff81111561206b57600080fd5b60208301915083602082850101111561109857600080fd5b60008060008060008060008060c0898b03121561209f57600080fd5b88356120aa8161202c565b975060208901356120ba8161202c565b965060408901356120ca8161202c565b955060608901359450608089013567ffffffffffffffff808211156120ee57600080fd5b6120fa8c838d01612041565b909650945060a08b013591508082111561211357600080fd5b506121208b828c01612041565b999c989b5096995094979396929594505050565b60006020828403121561214657600080fd5b81356121518161202c565b9392505050565b60006020828403121561216a57600080fd5b5035919050565b6000806040838503121561218457600080fd5b8235915060208301356121968161202c565b809150509250929050565b600080604083850312156121b457600080fd5b82356121bf8161202c565b946020939093013593505050565b600080604083850312156121e057600080fd5b50508035926020909101359150565b60005b8381101561220a5781810151838201526020016121f2565b50506000910152565b60208152600082518060208401526122328160408501602087016121ef565b601f01601f19169190910160400192915050565b80516122518161202c565b919050565b60006020828403121561226857600080fd5b81516121518161202c565b60208082526010908201526f56616c696461746f725365727669636560801b604082015260600190565b6020808252600b908201526a54696d6548656c7065727360a81b604082015260600190565b6000602082840312156122d457600080fd5b5051919050565b8051801515811461225157600080fd5b6000602082840312156122fd57600080fd5b611502826122db565b634e487b7160e01b600052601160045260246000fd5b8082018082111561150557611505612306565b60006001820161234157612341612306565b5060010190565b808202811582820484141761150557611505612306565b60008261237c57634e487b7160e01b600052601260045260246000fd5b500490565b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b634e487b7160e01b600052604160045260246000fd5b604051610100810167ffffffffffffffff81118282101715612409576124096123cf565b60405290565b600082601f83011261242057600080fd5b815167ffffffffffffffff8082111561243b5761243b6123cf565b604051601f8301601f19908116603f01168101908282118183101715612463576124636123cf565b8160405283815286602085880101111561247c57600080fd5b61248d8460208301602089016121ef565b9695505050505050565b6000602082840312156124a957600080fd5b815167ffffffffffffffff808211156124c157600080fd5b9083019061010082860312156124d657600080fd5b6124de6123e5565b8251828111156124ed57600080fd5b6124f98782860161240f565b82525061250860208401612246565b602082015261251960408401612246565b604082015260608301518281111561253057600080fd5b61253c8782860161240f565b6060830152506080830151608082015260a083015160a082015260c083015160c082015261256c60e084016122db565b60e082015295945050505050565b8181038181111561150557611505612306565b634e487b7160e01b600052600160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052603160045260246000fdfe7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498a2646970667358221220665eef9e146b79d21af7caf7fe1c7e922e9dcf52212dd189bd7f279ea02a0bf964736f6c63430008110033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

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.