ETH Price: $2,680.94 (+1.92%)
Gas: 1 Gwei

Contract

0x7d8767Df201055876321F3e1b3Dcb42b0CCA93C2
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
0x60806040195818052024-04-04 10:27:47128 days ago1712226467IN
 Create: StakedETHIX
0 ETH0.0631073419.9470942

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
StakedETHIX

Compiler Version
v0.7.5+commit.eb77ed08

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 24 : StakedETHIX.sol
// SPDX-License-Identifier: gpl-3.0

pragma solidity 0.7.5;
pragma experimental ABIEncoderV2;

import './bases/staking/interfaces/ITransferHook.sol';
import './bases/staking/StakedToken.sol';

/**
 * @title StakedEthix
 * @notice StakedToken with ETHIX token as staked token
 * @author Aave / Ethichub
 **/
contract StakedETHIX is StakedToken {
    function initialize(
        IERC20Upgradeable stakedToken,
        ITransferHook ethixGovernance,
        uint256 cooldownSeconds,
        uint256 unstakeWindow,
        IReserve rewardsVault,
        address emissionManager,
        uint128 distributionDuration
    ) public initializer {
        __StakedToken_init(
            'Staked ETHIX',
            'stkETHIX',
            18,
            ethixGovernance,
            stakedToken,
            cooldownSeconds,
            unstakeWindow,
            rewardsVault,
            emissionManager,
            distributionDuration
        );
    }
}

File 2 of 24 : AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../utils/EnumerableSetUpgradeable.sol";
import "../utils/AddressUpgradeable.sol";
import "../utils/ContextUpgradeable.sol";
import "../proxy/Initializable.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, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it.
 */
abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable {
    function __AccessControl_init() internal initializer {
        __Context_init_unchained();
        __AccessControl_init_unchained();
    }

    function __AccessControl_init_unchained() internal initializer {
    }
    using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet;
    using AddressUpgradeable for address;

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

    mapping (bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

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

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

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

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view 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 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 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 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 {
        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 {
        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 {
        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.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        emit RoleAdminChanged(role, _roles[role].adminRole, adminRole);
        _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 3 of 24 : MathUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library MathUpgradeable {
    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a >= b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow, so we distribute
        return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
    }
}

File 4 of 24 : SafeMathUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeMathUpgradeable {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        uint256 c = a + b;
        if (c < a) return (false, 0);
        return (true, c);
    }

    /**
     * @dev Returns the substraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b > a) return (false, 0);
        return (true, a - b);
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
        if (a == 0) return (true, 0);
        uint256 c = a * b;
        if (c / a != b) return (false, 0);
        return (true, c);
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b == 0) return (false, 0);
        return (true, a / b);
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b == 0) return (false, 0);
        return (true, a % b);
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");
        return c;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b <= a, "SafeMath: subtraction overflow");
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0) return 0;
        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");
        return c;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b > 0, "SafeMath: division by zero");
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b > 0, "SafeMath: modulo by zero");
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        return a - b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryDiv}.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        return a % b;
    }
}

File 5 of 24 : Initializable.sol
// SPDX-License-Identifier: MIT

// solhint-disable-next-line compiler-version
pragma solidity >=0.4.24 <0.8.0;

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

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-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.
 */
abstract contract Initializable {

    /**
     * @dev Indicates that the contract has been initialized.
     */
    bool private _initialized;

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

    /**
     * @dev Modifier to protect an initializer function from being invoked twice.
     */
    modifier initializer() {
        require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized");

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

        _;

        if (isTopLevelCall) {
            _initializing = false;
        }
    }

    /// @dev Returns true if and only if the function is running in the constructor
    function _isConstructor() private view returns (bool) {
        return !AddressUpgradeable.isContract(address(this));
    }
}

File 6 of 24 : ERC20SnapshotUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../../math/SafeMathUpgradeable.sol";
import "../../utils/ArraysUpgradeable.sol";
import "../../utils/CountersUpgradeable.sol";
import "./ERC20Upgradeable.sol";
import "../../proxy/Initializable.sol";

/**
 * @dev This contract extends an ERC20 token with a snapshot mechanism. When a snapshot is created, the balances and
 * total supply at the time are recorded for later access.
 *
 * This can be used to safely create mechanisms based on token balances such as trustless dividends or weighted voting.
 * In naive implementations it's possible to perform a "double spend" attack by reusing the same balance from different
 * accounts. By using snapshots to calculate dividends or voting power, those attacks no longer apply. It can also be
 * used to create an efficient ERC20 forking mechanism.
 *
 * Snapshots are created by the internal {_snapshot} function, which will emit the {Snapshot} event and return a
 * snapshot id. To get the total supply at the time of a snapshot, call the function {totalSupplyAt} with the snapshot
 * id. To get the balance of an account at the time of a snapshot, call the {balanceOfAt} function with the snapshot id
 * and the account address.
 *
 * ==== Gas Costs
 *
 * Snapshots are efficient. Snapshot creation is _O(1)_. Retrieval of balances or total supply from a snapshot is _O(log
 * n)_ in the number of snapshots that have been created, although _n_ for a specific account will generally be much
 * smaller since identical balances in subsequent snapshots are stored as a single entry.
 *
 * There is a constant overhead for normal ERC20 transfers due to the additional snapshot bookkeeping. This overhead is
 * only significant for the first transfer that immediately follows a snapshot for a particular account. Subsequent
 * transfers will have normal cost until the next snapshot, and so on.
 */
abstract contract ERC20SnapshotUpgradeable is Initializable, ERC20Upgradeable {
    function __ERC20Snapshot_init() internal initializer {
        __Context_init_unchained();
        __ERC20Snapshot_init_unchained();
    }

    function __ERC20Snapshot_init_unchained() internal initializer {
    }
    // Inspired by Jordi Baylina's MiniMeToken to record historical balances:
    // https://github.com/Giveth/minimd/blob/ea04d950eea153a04c51fa510b068b9dded390cb/contracts/MiniMeToken.sol

    using SafeMathUpgradeable for uint256;
    using ArraysUpgradeable for uint256[];
    using CountersUpgradeable for CountersUpgradeable.Counter;

    // Snapshotted values have arrays of ids and the value corresponding to that id. These could be an array of a
    // Snapshot struct, but that would impede usage of functions that work on an array.
    struct Snapshots {
        uint256[] ids;
        uint256[] values;
    }

    mapping (address => Snapshots) private _accountBalanceSnapshots;
    Snapshots private _totalSupplySnapshots;

    // Snapshot ids increase monotonically, with the first value being 1. An id of 0 is invalid.
    CountersUpgradeable.Counter private _currentSnapshotId;

    /**
     * @dev Emitted by {_snapshot} when a snapshot identified by `id` is created.
     */
    event Snapshot(uint256 id);

    /**
     * @dev Creates a new snapshot and returns its snapshot id.
     *
     * Emits a {Snapshot} event that contains the same id.
     *
     * {_snapshot} is `internal` and you have to decide how to expose it externally. Its usage may be restricted to a
     * set of accounts, for example using {AccessControl}, or it may be open to the public.
     *
     * [WARNING]
     * ====
     * While an open way of calling {_snapshot} is required for certain trust minimization mechanisms such as forking,
     * you must consider that it can potentially be used by attackers in two ways.
     *
     * First, it can be used to increase the cost of retrieval of values from snapshots, although it will grow
     * logarithmically thus rendering this attack ineffective in the long term. Second, it can be used to target
     * specific accounts and increase the cost of ERC20 transfers for them, in the ways specified in the Gas Costs
     * section above.
     *
     * We haven't measured the actual numbers; if this is something you're interested in please reach out to us.
     * ====
     */
    function _snapshot() internal virtual returns (uint256) {
        _currentSnapshotId.increment();

        uint256 currentId = _currentSnapshotId.current();
        emit Snapshot(currentId);
        return currentId;
    }

    /**
     * @dev Retrieves the balance of `account` at the time `snapshotId` was created.
     */
    function balanceOfAt(address account, uint256 snapshotId) public view virtual returns (uint256) {
        (bool snapshotted, uint256 value) = _valueAt(snapshotId, _accountBalanceSnapshots[account]);

        return snapshotted ? value : balanceOf(account);
    }

    /**
     * @dev Retrieves the total supply at the time `snapshotId` was created.
     */
    function totalSupplyAt(uint256 snapshotId) public view virtual returns(uint256) {
        (bool snapshotted, uint256 value) = _valueAt(snapshotId, _totalSupplySnapshots);

        return snapshotted ? value : totalSupply();
    }


    // Update balance and/or total supply snapshots before the values are modified. This is implemented
    // in the _beforeTokenTransfer hook, which is executed for _mint, _burn, and _transfer operations.
    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override {
      super._beforeTokenTransfer(from, to, amount);

      if (from == address(0)) {
        // mint
        _updateAccountSnapshot(to);
        _updateTotalSupplySnapshot();
      } else if (to == address(0)) {
        // burn
        _updateAccountSnapshot(from);
        _updateTotalSupplySnapshot();
      } else {
        // transfer
        _updateAccountSnapshot(from);
        _updateAccountSnapshot(to);
      }
    }

    function _valueAt(uint256 snapshotId, Snapshots storage snapshots)
        private view returns (bool, uint256)
    {
        require(snapshotId > 0, "ERC20Snapshot: id is 0");
        // solhint-disable-next-line max-line-length
        require(snapshotId <= _currentSnapshotId.current(), "ERC20Snapshot: nonexistent id");

        // When a valid snapshot is queried, there are three possibilities:
        //  a) The queried value was not modified after the snapshot was taken. Therefore, a snapshot entry was never
        //  created for this id, and all stored snapshot ids are smaller than the requested one. The value that corresponds
        //  to this id is the current one.
        //  b) The queried value was modified after the snapshot was taken. Therefore, there will be an entry with the
        //  requested id, and its value is the one to return.
        //  c) More snapshots were created after the requested one, and the queried value was later modified. There will be
        //  no entry for the requested id: the value that corresponds to it is that of the smallest snapshot id that is
        //  larger than the requested one.
        //
        // In summary, we need to find an element in an array, returning the index of the smallest value that is larger if
        // it is not found, unless said value doesn't exist (e.g. when all values are smaller). Arrays.findUpperBound does
        // exactly this.

        uint256 index = snapshots.ids.findUpperBound(snapshotId);

        if (index == snapshots.ids.length) {
            return (false, 0);
        } else {
            return (true, snapshots.values[index]);
        }
    }

    function _updateAccountSnapshot(address account) private {
        _updateSnapshot(_accountBalanceSnapshots[account], balanceOf(account));
    }

    function _updateTotalSupplySnapshot() private {
        _updateSnapshot(_totalSupplySnapshots, totalSupply());
    }

    function _updateSnapshot(Snapshots storage snapshots, uint256 currentValue) private {
        uint256 currentId = _currentSnapshotId.current();
        if (_lastSnapshotId(snapshots.ids) < currentId) {
            snapshots.ids.push(currentId);
            snapshots.values.push(currentValue);
        }
    }

    function _lastSnapshotId(uint256[] storage ids) private view returns (uint256) {
        if (ids.length == 0) {
            return 0;
        } else {
            return ids[ids.length - 1];
        }
    }
    uint256[46] private __gap;
}

File 7 of 24 : ERC20Upgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../../utils/ContextUpgradeable.sol";
import "./IERC20Upgradeable.sol";
import "../../math/SafeMathUpgradeable.sol";
import "../../proxy/Initializable.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin guidelines: functions revert instead
 * of returning `false` on failure. This behavior is nonetheless conventional
 * and does not conflict with the expectations of ERC20 applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable {
    using SafeMathUpgradeable for uint256;

    mapping (address => uint256) private _balances;

    mapping (address => mapping (address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;
    uint8 private _decimals;

    /**
     * @dev Sets the values for {name} and {symbol}, initializes {decimals} with
     * a default value of 18.
     *
     * To select a different value for {decimals}, use {_setupDecimals}.
     *
     * All three of these values are immutable: they can only be set once during
     * construction.
     */
    function __ERC20_init(string memory name_, string memory symbol_) internal initializer {
        __Context_init_unchained();
        __ERC20_init_unchained(name_, symbol_);
    }

    function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer {
        _name = name_;
        _symbol = symbol_;
        _decimals = 18;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5,05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
     * called.
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual returns (uint8) {
        return _decimals;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `recipient` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * Requirements:
     *
     * - `sender` and `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     * - the caller must have allowance for ``sender``'s tokens of at least
     * `amount`.
     */
    function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);
        _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
        return true;
    }

    /**
     * @dev Moves tokens `amount` from `sender` to `recipient`.
     *
     * This is internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `sender` cannot be the zero address.
     * - `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     */
    function _transfer(address sender, address recipient, uint256 amount) internal virtual {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(sender, recipient, amount);

        _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
        _balances[recipient] = _balances[recipient].add(amount);
        emit Transfer(sender, recipient, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply = _totalSupply.add(amount);
        _balances[account] = _balances[account].add(amount);
        emit Transfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
        _totalSupply = _totalSupply.sub(amount);
        emit Transfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(address owner, address spender, uint256 amount) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Sets {decimals} to a value other than the default one of 18.
     *
     * WARNING: This function should only be called from the constructor. Most
     * applications that interact with token contracts will not expect
     * {decimals} to ever change, and may work incorrectly if it does.
     */
    function _setupDecimals(uint8 decimals_) internal virtual {
        _decimals = decimals_;
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be to transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
    uint256[44] private __gap;
}

File 8 of 24 : IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

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

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

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

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

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

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

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

File 9 of 24 : SafeERC20Upgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "./IERC20Upgradeable.sol";
import "../../math/SafeMathUpgradeable.sol";
import "../../utils/AddressUpgradeable.sol";

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

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

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

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

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

    function safeDecreaseAllowance(IERC20Upgradeable token, address spender, uint256 value) internal {
        uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

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

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

File 10 of 24 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

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

        uint256 size;
        // solhint-disable-next-line no-inline-assembly
        assembly { size := extcodesize(account) }
        return size > 0;
    }

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

        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
        (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");

        // solhint-disable-next-line avoid-low-level-calls
        (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");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.staticcall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private 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

                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 11 of 24 : ArraysUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../math/MathUpgradeable.sol";

/**
 * @dev Collection of functions related to array types.
 */
library ArraysUpgradeable {
   /**
     * @dev Searches a sorted `array` and returns the first index that contains
     * a value greater or equal to `element`. If no such index exists (i.e. all
     * values in the array are strictly less than `element`), the array length is
     * returned. Time complexity O(log n).
     *
     * `array` is expected to be sorted in ascending order, and to contain no
     * repeated elements.
     */
    function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
        if (array.length == 0) {
            return 0;
        }

        uint256 low = 0;
        uint256 high = array.length;

        while (low < high) {
            uint256 mid = MathUpgradeable.average(low, high);

            // Note that mid will always be strictly less than high (i.e. it will be a valid array index)
            // because Math.average rounds down (it does integer division with truncation).
            if (array[mid] > element) {
                high = mid;
            } else {
                low = mid + 1;
            }
        }

        // At this point `low` is the exclusive upper bound. We will return the inclusive upper bound.
        if (low > 0 && array[low - 1] == element) {
            return low - 1;
        } else {
            return low;
        }
    }
}

File 12 of 24 : ContextUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
import "../proxy/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 GSN 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 initializer {
        __Context_init_unchained();
    }

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

    function _msgData() internal view virtual returns (bytes memory) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
    uint256[50] private __gap;
}

File 13 of 24 : CountersUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../math/SafeMathUpgradeable.sol";

/**
 * @title Counters
 * @author Matt Condon (@shrugs)
 * @dev Provides counters that can only be incremented or decremented by one. This can be used e.g. to track the number
 * of elements in a mapping, issuing ERC721 ids, or counting request ids.
 *
 * Include with `using Counters for Counters.Counter;`
 * Since it is not possible to overflow a 256 bit integer with increments of one, `increment` can skip the {SafeMath}
 * overflow check, thereby saving gas. This does assume however correct usage, in that the underlying `_value` is never
 * directly accessed.
 */
library CountersUpgradeable {
    using SafeMathUpgradeable for uint256;

    struct Counter {
        // This variable should never be directly accessed by users of the library: interactions must be restricted to
        // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
        // this feature: see https://github.com/ethereum/solidity/issues/4637
        uint256 _value; // default: 0
    }

    function current(Counter storage counter) internal view returns (uint256) {
        return counter._value;
    }

    function increment(Counter storage counter) internal {
        // The {SafeMath} overflow check can be skipped here, see the comment at the top
        counter._value += 1;
    }

    function decrement(Counter storage counter) internal {
        counter._value = counter._value.sub(1);
    }
}

File 14 of 24 : EnumerableSetUpgradeable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <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.
 */
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;

            // When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs
            // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.

            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] = toDeleteIndex + 1; // All indexes are 1-based

            // 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) {
        require(set._values.length > index, "EnumerableSet: index out of bounds");
        return set._values[index];
    }

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

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


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

File 15 of 24 : IReserve.sol
// SPDX-License-Identifier: gpl-3.0

pragma solidity 0.7.5;

interface IReserve {
    event Transfer(address indexed to, uint256 amount);
    event RescueFunds(address token, address indexed to, uint256 amount);

    function balance() external view returns (uint256);

    function transfer(address payable _to, uint256 _value) external returns (bool);

    function rescueFunds(
        address _tokenToRescue,
        address _to,
        uint256 _amount
    ) external;
}

File 16 of 24 : ICooldownManager.sol
// SPDX-License-Identifier: agpl-3.0

pragma solidity 0.7.5;

interface ICooldownManager {
    function cooldown() external;
    function setCooldown(uint256 cooldownSeconds) external;
    function setUnstakeWindow(uint256 unstakeWindow) external;
}

File 17 of 24 : IStakedToken.sol
// SPDX-License-Identifier: agpl-3.0

pragma solidity 0.7.5;

interface IStakedToken {
    function stake(address to, uint256 amount) external;
    function redeem(address to, uint256 amount) external;
    function claimRewards(address payable to, uint256 amount) external;
    function getTotalRewardsBalance(address staker) external returns (uint256);
    function getNextCooldownTimestamp(
        uint256 fromCooldownTimestamp,
        uint256 amountToReceive,
        address toAddress,
        uint256 toBalance
        ) external returns (uint256);
}

File 18 of 24 : IStakingRewards.sol
// SPDX-License-Identifier: agpl-3.0

pragma solidity 0.7.5;
pragma experimental ABIEncoderV2;

import '../lib/DistributionTypes.sol';

interface IStakingRewards {
    function changeDistributionEndDate(uint256 date) external;
    function configureAssets(DistributionTypes.AssetConfigInput[] memory assetsConfigInput)
        external;
}

File 19 of 24 : ITransferHook.sol
// SPDX-License-Identifier: agpl-3.0

pragma solidity 0.7.5;

interface ITransferHook {
    function onTransfer(
        address from,
        address to,
        uint256 amount
    ) external;
}

File 20 of 24 : DistributionTypes.sol
// SPDX-License-Identifier: agpl-3.0

pragma solidity 0.7.5;
pragma experimental ABIEncoderV2;

library DistributionTypes {
    struct AssetConfigInput {
        uint128 emissionPerSecond;
        uint256 totalStaked;
        address underlyingAsset;
    }

    struct UserStakeInput {
        address underlyingAsset;
        uint256 stakedByUser;
        uint256 totalStaked;
    }
}

File 21 of 24 : EthixERC20Snapshot.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.7.5;

import '../interfaces/ITransferHook.sol';

import '@openzeppelin/contracts-upgradeable/token/ERC20/ERC20SnapshotUpgradeable.sol';

/**
 * @title EthixERC20Snapshot
 * @notice Modified OZ ERC20Snapshot to add Aave stuff
 * @author Ethichub
 **/
contract EthixERC20Snapshot is ERC20SnapshotUpgradeable {

    function __EthixERC20Snapshot_init(string memory name_, string memory symbol_)
        public
        initializer
    {
        __ERC20Snapshot_init();
        __ERC20_init(name_, symbol_);
    }

    /// @dev reference to the Ethix governance contract to call (if initialized) on _beforeTokenTransfer
    /// !!! IMPORTANT The Ethix governance is considered a trustable contract, being its responsibility
    /// to control all potential reentrancies by calling back the this contract
    ITransferHook public _ethixGovernance;

    function _setEthixGovernance(ITransferHook ethixGovernance) internal virtual {
        _ethixGovernance = ethixGovernance;
    }

}

File 22 of 24 : StakedToken.sol
// SPDX-License-Identifier: agpl-3.0

pragma solidity 0.7.5;
pragma experimental ABIEncoderV2;

import './StakingRewards.sol';

import './interfaces/IStakedToken.sol';
import './interfaces/ITransferHook.sol';
import './interfaces/ICooldownManager.sol';

import '../../../reserve/IReserve.sol';

import './lib/EthixERC20Snapshot.sol';

import '@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol';
import '@openzeppelin/contracts-upgradeable/token/ERC20/SafeERC20Upgradeable.sol';
import '@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/proxy/Initializable.sol';

/**
 * @title StakedToken
 * @notice Contract to stake Ethix token, tokenize the position and get rewards, inheriting from a distribution manager contract
 * @author Aave / Ethichub
 **/
contract StakedToken is Initializable, IStakedToken, ICooldownManager, EthixERC20Snapshot, StakingRewards {
    using SafeERC20Upgradeable for IERC20Upgradeable;
    using SafeMathUpgradeable for uint256;

    IERC20Upgradeable public STAKED_TOKEN;
    uint256 public COOLDOWN_SECONDS;

    /// @notice Seconds available to redeem once the cooldown period is fullfilled
    uint256 public UNSTAKE_WINDOW;

    /// @notice IReserve to pull from the rewards, needs to have this contract as WITHDRAW role
    IReserve public REWARDS_VAULT;

    mapping(address => uint256) public stakerRewardsToClaim;
    mapping(address => uint256) public stakersCooldowns;

    event Staked(address indexed from, address indexed onBehalfOf, uint256 amount);
    event Redeem(address indexed from, address indexed to, uint256 amount);

    event RewardsAccrued(address user, uint256 amount);
    event RewardsClaimed(address indexed from, address indexed to, uint256 amount);

    event Cooldown(address indexed user, uint256 cooldown);

    event CooldownSet(uint256 cooldown);
    event UnstakeWindowSet(uint256 unstakeWindow);

    function __StakedToken_init(
        string memory name,
        string memory symbol,
        uint8 decimals,
        ITransferHook ethixGovernance,
        IERC20Upgradeable stakedToken,
        uint256 cooldownSeconds,
        uint256 unstakeWindow,
        IReserve rewardsVault,
        address emissionManager,
        uint128 distributionDuration
    ) internal initializer {
        __EthixERC20Snapshot_init(name, symbol);
        _setupDecimals(decimals);
        _setEthixGovernance(ethixGovernance);
        __StakingRewards_init(emissionManager, distributionDuration);
        STAKED_TOKEN = stakedToken;
        COOLDOWN_SECONDS = cooldownSeconds;
        UNSTAKE_WINDOW = unstakeWindow;
        REWARDS_VAULT = rewardsVault;
    }

    /**
     * @dev Stake tokens
     * @param onBehalfOf Address of staker
     * @param amount Amount to stake
     **/
    function stake(address onBehalfOf, uint256 amount) external virtual override {
        require(amount != 0, 'INVALID_ZERO_AMOUNT');
        uint256 balanceOfUser = balanceOf(onBehalfOf);

        uint256 accruedRewards =
            _updateUserAssetInternal(onBehalfOf, address(this), balanceOfUser, totalSupply());
        if (accruedRewards != 0) {
            emit RewardsAccrued(onBehalfOf, accruedRewards);
            stakerRewardsToClaim[onBehalfOf] = stakerRewardsToClaim[onBehalfOf].add(accruedRewards);
        }

        stakersCooldowns[onBehalfOf] = getNextCooldownTimestamp(
            0,
            amount,
            onBehalfOf,
            balanceOfUser
        );

        _mint(onBehalfOf, amount);
        IERC20Upgradeable(STAKED_TOKEN).safeTransferFrom(msg.sender, address(this), amount);

        emit Staked(msg.sender, onBehalfOf, amount);
    }

    /**
     * @dev Redeems staked tokens, and stop earning rewards
     * @param to Address to redeem to
     * @param amount Amount to redeem
     **/
    function redeem(address to, uint256 amount) external override {
        require(amount != 0, 'INVALID_ZERO_AMOUNT');
        //solium-disable-next-line
        uint256 cooldownStartTimestamp = stakersCooldowns[msg.sender];
        require(
            block.timestamp > cooldownStartTimestamp.add(COOLDOWN_SECONDS),
            'INSUFFICIENT_COOLDOWN'
        );
        require(
            block.timestamp.sub(cooldownStartTimestamp.add(COOLDOWN_SECONDS)) <= UNSTAKE_WINDOW,
            'UNSTAKE_WINDOW_FINISHED'
        );
        uint256 balanceOfMessageSender = balanceOf(msg.sender);

        uint256 amountToRedeem =
            (amount > balanceOfMessageSender) ? balanceOfMessageSender : amount;

        _updateCurrentUnclaimedRewards(msg.sender, balanceOfMessageSender, true);

        _burn(msg.sender, amountToRedeem);

        if (balanceOfMessageSender.sub(amountToRedeem) == 0) {
            stakersCooldowns[msg.sender] = 0;
        }

        IERC20Upgradeable(STAKED_TOKEN).safeTransfer(to, amountToRedeem);

        emit Redeem(msg.sender, to, amountToRedeem);
    }

    /**
     * @dev Claims an `amount` from Rewards reserve to the address `to`
     * @param to Address to stake for
     * @param amount Amount to stake
     **/
    function claimRewards(address payable to, uint256 amount) external override {
        uint256 newTotalRewards =
            _updateCurrentUnclaimedRewards(msg.sender, balanceOf(msg.sender), false);
        uint256 amountToClaim = (amount == type(uint256).max) ? newTotalRewards : amount;

        stakerRewardsToClaim[msg.sender] = newTotalRewards.sub(amountToClaim, 'INVALID_AMOUNT');

        require(REWARDS_VAULT.transfer(to, amountToClaim), 'ERROR_TRANSFER_FROM_VAULT');

        emit RewardsClaimed(msg.sender, to, amountToClaim);
    }

    /**
     * @dev Return the total rewards pending to claim by an staker
     * @param staker The staker address
     * @return The rewards
     */
    function getTotalRewardsBalance(address staker) external override view returns (uint256) {
        DistributionTypes.UserStakeInput[] memory userStakeInputs =
            new DistributionTypes.UserStakeInput[](1);
        userStakeInputs[0] = DistributionTypes.UserStakeInput({
            underlyingAsset: address(this),
            stakedByUser: balanceOf(staker),
            totalStaked: totalSupply()
        });
        return stakerRewardsToClaim[staker].add(_getUnclaimedRewards(staker, userStakeInputs));
    }


    /**
     * @dev Activates the cooldown period to unstake
     * - It can't be called if the user is not staking
     **/
    function cooldown() external override {
        require(balanceOf(msg.sender) != 0, 'INVALID_BALANCE_ON_COOLDOWN');
        //solium-disable-next-line
        stakersCooldowns[msg.sender] = block.timestamp;

        emit Cooldown(msg.sender, block.timestamp);
    }

    /**
     * @dev editable the cooldown seconds
     * @param cooldownSeconds cooldown seconds
     */
    function setCooldown(uint256 cooldownSeconds) external override {
        require(hasRole(EMISSION_MANAGER_ROLE, msg.sender), 'ONLY_EMISSION_MANAGER');
        COOLDOWN_SECONDS = cooldownSeconds;

        emit CooldownSet(cooldownSeconds);
    }

    /**
     * @dev editable unstake window
     * @param unstakeWindow unstake window
     */
    function setUnstakeWindow(uint256 unstakeWindow) external override {
        require(hasRole(EMISSION_MANAGER_ROLE, msg.sender), 'ONLY_EMISSION_MANAGER');
        UNSTAKE_WINDOW = unstakeWindow;

        emit UnstakeWindowSet(unstakeWindow);
    }

    /**
     * @dev Calculates the how is gonna be a new cooldown timestamp depending on the sender/receiver situation
     *  - If the timestamp of the sender is "better" or the timestamp of the recipient is 0, we take the one of the recipient
     *  - Weighted average of from/to cooldown timestamps if:
     *    # The sender doesn't have the cooldown activated (timestamp 0).
     *    # The sender timestamp is expired
     *    # The sender has a "worse" timestamp
     *  - If the receiver's cooldown timestamp expired (too old), the next is 0
     * @param _fromCooldownTimestamp Cooldown timestamp of the sender
     * @param _amountToReceive Amount
     * @param _toAddress Address of the recipient
     * @param _toBalance Current balance of the receiver
     * @return The new cooldown timestamp
     **/
    function getNextCooldownTimestamp(
        uint256 _fromCooldownTimestamp,
        uint256 _amountToReceive,
        address _toAddress,
        uint256 _toBalance
    ) public override returns (uint256) {
        uint256 toCooldownTimestamp = stakersCooldowns[_toAddress];
        if (toCooldownTimestamp == 0) {
            return 0;
        }

        uint256 minimalValidCooldownTimestamp =
            block.timestamp.sub(COOLDOWN_SECONDS).sub(UNSTAKE_WINDOW);

        if (minimalValidCooldownTimestamp > toCooldownTimestamp) {
            toCooldownTimestamp = 0;
        } else {
            uint256 fromCooldownTimestamp =
                (minimalValidCooldownTimestamp > _fromCooldownTimestamp)
                    ? block.timestamp
                    : _fromCooldownTimestamp;

            if (fromCooldownTimestamp < toCooldownTimestamp) {
                return toCooldownTimestamp;
            } else {
                toCooldownTimestamp = (
                    _amountToReceive.mul(fromCooldownTimestamp).add(
                        _toBalance.mul(toCooldownTimestamp)
                    )
                )
                    .div(_amountToReceive.add(_toBalance));
            }
        }
        stakersCooldowns[_toAddress] = toCooldownTimestamp;

        return toCooldownTimestamp;
    }

    /**
     * @dev Internal ERC20 _transfer of the tokenized staked tokens
     * @param from Address to transfer from
     * @param to Address to transfer to
     * @param amount Amount to transfer
     **/
    function _transfer(
        address from,
        address to,
        uint256 amount
    ) internal override {
        uint256 balanceOfFrom = balanceOf(from);
        // Sender
        _updateCurrentUnclaimedRewards(from, balanceOfFrom, true);

        // Recipient
        if (from != to) {
            uint256 balanceOfTo = balanceOf(to);
            _updateCurrentUnclaimedRewards(to, balanceOfTo, true);

            uint256 previousSenderCooldown = stakersCooldowns[from];
            stakersCooldowns[to] = getNextCooldownTimestamp(
                previousSenderCooldown,
                amount,
                to,
                balanceOfTo
            );
            // if cooldown was set and whole balance of sender was transferred - clear cooldown
            if (balanceOfFrom == amount && previousSenderCooldown != 0) {
                stakersCooldowns[from] = 0;
            }
        }

        super._transfer(from, to, amount);
    }

    /**
     * @dev Updates the user state related with his accrued rewards
     * @param user Address of the user
     * @param userBalance The current balance of the user
     * @param updateStorage Boolean flag used to update or not the stakerRewardsToClaim of the user
     * @return The unclaimed rewards that were added to the total accrued
     **/
    function _updateCurrentUnclaimedRewards(
        address user,
        uint256 userBalance,
        bool updateStorage
    ) internal returns (uint256) {
        uint256 accruedRewards =
            _updateUserAssetInternal(user, address(this), userBalance, totalSupply());
        uint256 unclaimedRewards = stakerRewardsToClaim[user].add(accruedRewards);

        if (accruedRewards != 0) {
            if (updateStorage) {
                stakerRewardsToClaim[user] = unclaimedRewards;
            }
            emit RewardsAccrued(user, accruedRewards);
        }

        return unclaimedRewards;
    }
}

File 23 of 24 : StakingRewards.sol
// SPDX-License-Identifier: agpl-3.0

pragma solidity 0.7.5;
pragma experimental ABIEncoderV2;

import './lib/DistributionTypes.sol';
import './interfaces/IStakingRewards.sol';

import '@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol';
import '../../../utils/SafeMathUint128.sol';
import '@openzeppelin/contracts-upgradeable/proxy/Initializable.sol';
import '@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol';

/**
 * @title StakingRewards
 * @notice Accounting contract to manage multiple staking distributions
 * @author Aave / Ethichub
 **/
contract StakingRewards is Initializable, IStakingRewards, AccessControlUpgradeable {
    bytes32 public constant EMISSION_MANAGER_ROLE = keccak256('EMISSION_MANAGER');
    using SafeMathUpgradeable for uint256;
    using SafeMathUint128 for uint128;

    struct AssetData {
        uint128 emissionPerSecond;
        uint128 lastUpdateTimestamp;
        uint256 index;
        mapping(address => uint256) users;
    }

    uint256 public DISTRIBUTION_END;

    uint8 constant public PRECISION = 18;

    mapping(address => AssetData) public assets;

    event AssetConfigUpdated(address indexed asset, uint256 emission);
    event AssetIndexUpdated(address indexed asset, uint256 index);
    event UserIndexUpdated(address indexed user, address indexed asset, uint256 index);
    event DistributionEndChanged(uint256 distributionEnd);

    function __StakingRewards_init(address emissionManager, uint256 distributionDuration)
        public
        initializer
    {
        __AccessControl_init_unchained();
        DISTRIBUTION_END = block.timestamp.add(distributionDuration);
        _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
        _setupRole(EMISSION_MANAGER_ROLE, emissionManager);
    }

    /**
     * @dev Configures the distribution of rewards for a list of assets
     * @param assetsConfigInput The list of configurations to apply
     **/
    function configureAssets(DistributionTypes.AssetConfigInput[] memory assetsConfigInput)
        public
        override
    {
        require(hasRole(EMISSION_MANAGER_ROLE, msg.sender), 'ONLY_EMISSION_MANAGER');

        for (uint256 i = 0; i < assetsConfigInput.length; i++) {
            AssetData storage assetConfig = assets[assetsConfigInput[i].underlyingAsset];

            _updateAssetStateInternal(
                assetsConfigInput[i].underlyingAsset,
                assetConfig,
                assetsConfigInput[i].totalStaked
            );

            assetConfig.emissionPerSecond = assetsConfigInput[i].emissionPerSecond;

            emit AssetConfigUpdated(
                assetsConfigInput[i].underlyingAsset,
                assetsConfigInput[i].emissionPerSecond
            );
        }
    }

    /**
     * @notice Change distribution end datetime
     * @param _distributionEndDate new distribution end datetime (UNIX Timestamp)
     */
    function changeDistributionEndDate(uint256 _distributionEndDate) public override {
        require(hasRole(EMISSION_MANAGER_ROLE, msg.sender), 'ONLY_EMISSION_MANAGER');
        return _changeDistributionEndDate(_distributionEndDate);
    }

    /**
     * @notice Change distribution end datetime internal function
     * @param _distributionEndDate new distribution end datetime (UNIX Timestamp)
     */
    function _changeDistributionEndDate(uint256 _distributionEndDate) internal {
        DISTRIBUTION_END = _distributionEndDate;
        emit DistributionEndChanged(DISTRIBUTION_END);
    }

    /**
     * @dev Updates the state of one distribution, mainly rewards index and timestamp
     * @param underlyingAsset The address used as key in the distribution
     * @param assetConfig Storage pointer to the distribution's config
     * @param totalStaked Current total of staked assets for this distribution
     * @return The new distribution index
     **/
    function _updateAssetStateInternal(
        address underlyingAsset,
        AssetData storage assetConfig,
        uint256 totalStaked
    ) internal returns (uint256) {
        uint256 oldIndex = assetConfig.index;
        uint128 lastUpdateTimestamp = assetConfig.lastUpdateTimestamp;

        if (block.timestamp == lastUpdateTimestamp) {
            return oldIndex;
        }

        uint256 newIndex =
            _getAssetIndex(
                oldIndex,
                assetConfig.emissionPerSecond,
                lastUpdateTimestamp,
                totalStaked
            );

        if (newIndex != oldIndex) {
            assetConfig.index = newIndex;
            emit AssetIndexUpdated(underlyingAsset, newIndex);
        }

        assetConfig.lastUpdateTimestamp = uint128(block.timestamp);

        return newIndex;
    }

    /**
     * @dev Updates the state of an user in a distribution
     * @param user The user's address
     * @param asset The address of the reference asset of the distribution
     * @param stakedByUser Amount of tokens staked by the user in the distribution at the moment
     * @param totalStaked Total tokens staked in the distribution
     * @return The accrued rewards for the user until the moment
     **/
    function _updateUserAssetInternal(
        address user,
        address asset,
        uint256 stakedByUser,
        uint256 totalStaked
    ) internal returns (uint256) {
        AssetData storage assetData = assets[asset];
        uint256 userIndex = assetData.users[user];
        uint256 accruedRewards = 0;

        uint256 newIndex = _updateAssetStateInternal(asset, assetData, totalStaked);

        if (userIndex != newIndex) {
            if (stakedByUser != 0) {
                accruedRewards = _getRewards(stakedByUser, newIndex, userIndex);
            }

            assetData.users[user] = newIndex;
            emit UserIndexUpdated(user, asset, newIndex);
        }

        return accruedRewards;
    }

    /**
     * @dev Used by "frontend" stake contracts to update the data of an user when claiming rewards from there
     * @param user The address of the user
     * @param stakes List of structs of the user data related with his stake
     * @return The accrued rewards for the user until the moment
     **/
    function _claimRewards(address payable user, DistributionTypes.UserStakeInput[] memory stakes)
        internal
        returns (uint256)
    {
        uint256 accruedRewards = 0;

        for (uint256 i = 0; i < stakes.length; i++) {
            accruedRewards = accruedRewards.add(
                _updateUserAssetInternal(
                    user,
                    stakes[i].underlyingAsset,
                    stakes[i].stakedByUser,
                    stakes[i].totalStaked
                )
            );
        }

        return accruedRewards;
    }

    /**
     * @dev Return the accrued rewards for an user over a list of distribution
     * @param user The address of the user
     * @param stakes List of structs of the user data related with his stake
     * @return The accrued rewards for the user until the moment
     **/
    function _getUnclaimedRewards(address user, DistributionTypes.UserStakeInput[] memory stakes)
        internal
        view
        returns (uint256)
    {
        uint256 accruedRewards = 0;

        for (uint256 i = 0; i < stakes.length; i++) {
            AssetData storage assetConfig = assets[stakes[i].underlyingAsset];
            uint256 assetIndex =
                _getAssetIndex(
                    assetConfig.index,
                    assetConfig.emissionPerSecond,
                    assetConfig.lastUpdateTimestamp,
                    stakes[i].totalStaked
                );

            accruedRewards = accruedRewards.add(
                _getRewards(stakes[i].stakedByUser, assetIndex, assetConfig.users[user])
            );
        }
        return accruedRewards;
    }

    /**
     * @dev Internal function for the calculation of user's rewards on a distribution
     * @param principalUserBalance Amount staked by the user on a distribution
     * @param reserveIndex Current index of the distribution
     * @param userIndex Index stored for the user, representation his staking moment
     * @return The rewards
     **/
    function _getRewards(
        uint256 principalUserBalance,
        uint256 reserveIndex,
        uint256 userIndex
    ) internal view returns (uint256) {
        return principalUserBalance.mul(reserveIndex.sub(userIndex)).div(10**uint256(PRECISION));
    }

    /**
     * @dev Calculates the next value of an specific distribution index, with validations
     * @param currentIndex Current index of the distribution
     * @param emissionPerSecond Representing the total rewards distributed per second per asset unit, on the distribution
     * @param lastUpdateTimestamp Last moment this distribution was updated
     * @param totalBalance of tokens considered for the distribution
     * @return The new index.
     **/
    function _getAssetIndex(
        uint256 currentIndex,
        uint256 emissionPerSecond,
        uint128 lastUpdateTimestamp,
        uint256 totalBalance
    ) internal view returns (uint256) {
        if (
            emissionPerSecond == 0 ||
            totalBalance == 0 ||
            lastUpdateTimestamp == block.timestamp ||
            lastUpdateTimestamp >= DISTRIBUTION_END
        ) {
            return currentIndex;
        }

        uint256 currentTimestamp =
            block.timestamp > DISTRIBUTION_END ? DISTRIBUTION_END : block.timestamp;
        uint256 timeDelta = currentTimestamp.sub(lastUpdateTimestamp);
        return
            emissionPerSecond.mul(timeDelta).mul(10**uint256(PRECISION)).div(totalBalance).add(
                currentIndex
            );
    }

    /**
     * @dev Returns the data of an user on a distribution
     * @param user Address of the user
     * @param asset The address of the reference asset of the distribution
     * @return The new index
     **/
    function getUserAssetData(address user, address asset) public view returns (uint256) {
        return assets[asset].users[user];
    }
}

File 24 of 24 : SafeMathUint128.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeMathUint128 {
    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint128 a, uint128 b) internal pure returns (uint128) {
        uint128 c = a + b;
        require(c >= a, "SafeMath: addition overflow");

        return c;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint128 a, uint128 b) internal pure returns (uint128) {
        return sub(a, b, "SafeMath: subtraction overflow");
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint128 a, uint128 b, string memory errorMessage) internal pure returns (uint128) {
        require(b <= a, errorMessage);
        uint128 c = a - b;

        return c;
    }
    

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint128 a, uint128 b) internal pure returns (uint128) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
        if (a == 0) {
            return 0;
        }

        uint128 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");

        return c;
    }

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint128 a, uint128 b) internal pure returns (uint128) {
        return div(a, b, "SafeMath: division by zero");
    }

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint128 a, uint128 b, string memory errorMessage) internal pure returns (uint128) {
        require(b > 0, errorMessage);
        uint128 c = a / b;
        // assert(a == b * c + a % b); // There is no case in which this doesn't hold

        return c;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * Reverts when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint128 a, uint128 b) internal pure returns (uint128) {
        return mod(a, b, "SafeMath: modulo by zero");
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * Reverts with custom message when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint128 a, uint128 b, string memory errorMessage) internal pure returns (uint128) {
        require(b != 0, errorMessage);
        return a % b;
    }
}

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":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"emission","type":"uint256"}],"name":"AssetConfigUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"index","type":"uint256"}],"name":"AssetIndexUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"cooldown","type":"uint256"}],"name":"Cooldown","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"cooldown","type":"uint256"}],"name":"CooldownSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"distributionEnd","type":"uint256"}],"name":"DistributionEndChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Redeem","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"RewardsAccrued","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"RewardsClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"}],"name":"Snapshot","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"onBehalfOf","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Staked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"unstakeWindow","type":"uint256"}],"name":"UnstakeWindowSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"index","type":"uint256"}],"name":"UserIndexUpdated","type":"event"},{"inputs":[],"name":"COOLDOWN_SECONDS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DISTRIBUTION_END","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"EMISSION_MANAGER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PRECISION","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REWARDS_VAULT","outputs":[{"internalType":"contract IReserve","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"STAKED_TOKEN","outputs":[{"internalType":"contract IERC20Upgradeable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNSTAKE_WINDOW","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"name_","type":"string"},{"internalType":"string","name":"symbol_","type":"string"}],"name":"__EthixERC20Snapshot_init","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"emissionManager","type":"address"},{"internalType":"uint256","name":"distributionDuration","type":"uint256"}],"name":"__StakingRewards_init","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"_ethixGovernance","outputs":[{"internalType":"contract ITransferHook","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"assets","outputs":[{"internalType":"uint128","name":"emissionPerSecond","type":"uint128"},{"internalType":"uint128","name":"lastUpdateTimestamp","type":"uint128"},{"internalType":"uint256","name":"index","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"snapshotId","type":"uint256"}],"name":"balanceOfAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_distributionEndDate","type":"uint256"}],"name":"changeDistributionEndDate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"claimRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint128","name":"emissionPerSecond","type":"uint128"},{"internalType":"uint256","name":"totalStaked","type":"uint256"},{"internalType":"address","name":"underlyingAsset","type":"address"}],"internalType":"struct DistributionTypes.AssetConfigInput[]","name":"assetsConfigInput","type":"tuple[]"}],"name":"configureAssets","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cooldown","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_fromCooldownTimestamp","type":"uint256"},{"internalType":"uint256","name":"_amountToReceive","type":"uint256"},{"internalType":"address","name":"_toAddress","type":"address"},{"internalType":"uint256","name":"_toBalance","type":"uint256"}],"name":"getNextCooldownTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","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":"address","name":"staker","type":"address"}],"name":"getTotalRewardsBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"asset","type":"address"}],"name":"getUserAssetData","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":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20Upgradeable","name":"stakedToken","type":"address"},{"internalType":"contract ITransferHook","name":"ethixGovernance","type":"address"},{"internalType":"uint256","name":"cooldownSeconds","type":"uint256"},{"internalType":"uint256","name":"unstakeWindow","type":"uint256"},{"internalType":"contract IReserve","name":"rewardsVault","type":"address"},{"internalType":"address","name":"emissionManager","type":"address"},{"internalType":"uint128","name":"distributionDuration","type":"uint128"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"redeem","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":"uint256","name":"cooldownSeconds","type":"uint256"}],"name":"setCooldown","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"unstakeWindow","type":"uint256"}],"name":"setUnstakeWindow","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"onBehalfOf","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"stake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"stakerRewardsToClaim","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"stakersCooldowns","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"snapshotId","type":"uint256"}],"name":"totalSupplyAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]

608060405234801561001057600080fd5b50613840806100206000396000f3fe608060405234801561001057600080fd5b506004361061028a5760003560e01c80639010d07c1161015c578063adc9772e116100ce578063ca15c87311610087578063ca15c87314610539578063d547741f1461054c578063dd62ed3e1461055f578063f11b818814610572578063f1cc432a14610594578063f8f10dfc146105a75761028a565b8063adc9772e146104d2578063b2a5dbfa146104e5578063b398741a146104f8578063b4f0e8c31461050b578063c1a9d6e914610513578063c3c9e42d146105265761028a565b8063981b24d011610120578063981b24d0146104765780639a99b4f014610489578063a217fddf1461049c578063a457c2d7146104a4578063a9059cbb146104b7578063aaf5eb68146104ca5761028a565b80639010d07c14610438578063919cd40f1461044b57806391d1485414610453578063946776cd1461046657806395d89b411461046e5761028a565b80633373ee4c116102005780635fe5952a116101b95780635fe5952a146103e757806370a08231146103ef57806372b49d6314610402578063787a08a61461040a5780637e90d7ef146104125780638dbefee2146104255761028a565b80633373ee4c14610380578063359c4a961461039357806336568abe1461039b57806339509351146103ae5780634ee2cd7e146103c15780634fc3f41a146103d45761028a565b806323b872dd1161025257806323b872dd1461030a578063248a9ca31461031d5780632752f89a146103305780632f2ff15d14610343578063312f6b8314610356578063313ce5671461036b5761028a565b806306fdde031461028f578063091030c3146102ad578063095ea7b3146102cd57806318160ddd146102ed5780631e9a6950146102f5575b600080fd5b6102976105ba565b6040516102a49190613355565b60405180910390f35b6102c06102bb366004612ffa565b610650565b6040516102a4919061334c565b6102e06102db3660046130b9565b610662565b6040516102a49190613341565b6102c0610680565b6103086103033660046130b9565b610686565b005b6102e0610318366004613079565b6107e7565b6102c061032b366004613199565b61086f565b61030861033e366004613199565b610887565b6103086103513660046131b1565b6108c7565b61035e61092e565b6040516102a49190613314565b61037361093d565b6040516102a49190613510565b6102c061038e366004613041565b610946565b6102c0610976565b6103086103a93660046131b1565b61097c565b6102e06103bc3660046130b9565b6109dd565b6102c06103cf3660046130b9565b610a2b565b6103086103e2366004613199565b610a74565b61035e610ae8565b6102c06103fd366004612ffa565b610af7565b6102c0610b12565b610308610b18565b6102c0610420366004612ffa565b610b8a565b6102c0610433366004612ffa565b610b9c565b61035e6104463660046131d5565b610c4b565b6102c0610c63565b6102e06104613660046131b1565b610c69565b61035e610c81565b610297610c90565b6102c0610484366004613199565b610cf1565b610308610497366004613016565b610d21565b6102c0610e8e565b6102e06104b23660046130b9565b610e93565b6102e06104c53660046130b9565b610efb565b610373610f0f565b6103086104e03660046130b9565b610f14565b6103086104f33660046130cb565b61105c565b6103086105063660046130b9565b6111cb565b6102c06112a7565b6103086105213660046131f6565b6112b9565b610308610534366004613275565b6113b9565b6102c0610547366004613199565b611458565b61030861055a3660046131b1565b61146f565b6102c061056d366004613041565b6114c8565b610585610580366004612ffa565b6114f3565b6040516102a4939291906134ec565b6102c06105a23660046132d6565b611521565b6103086105b5366004613199565b6115ff565b60368054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156106465780601f1061061b57610100808354040283529160200191610646565b820191906000526020600020905b81548152906001019060200180831161062957829003601f168201915b5050505050905090565b60d16020526000908152604090205481565b600061067661066f611668565b848461166c565b5060015b92915050565b60355490565b806106ac5760405162461bcd60e51b81526004016106a3906133a8565b60405180910390fd5b33600090815260d1602052604090205460cd546106ca908290611758565b42116106e85760405162461bcd60e51b81526004016106a39061340c565b60ce5461070a61070360cd548461175890919063ffffffff16565b42906117b2565b11156107285760405162461bcd60e51b81526004016106a39061346a565b600061073333610af7565b905060008184116107445783610746565b815b90506107543383600161180f565b5061075f33826118b3565b61076982826117b2565b61077e5733600090815260d160205260408120555b60cc54610795906001600160a01b031686836119af565b846001600160a01b0316336001600160a01b03167fd12200efa34901b99367694174c3b0d32c99585fdf37c7c26892136ddd0836d9836040516107d8919061334c565b60405180910390a35050505050565b60006107f4848484611a01565b61086484610800611668565b61085f856040518060600160405280602881526020016136fb602891396001600160a01b038a1660009081526034602052604081209061083e611668565b6001600160a01b031681526020810191909152604001600020549190611acd565b61166c565b5060015b9392505050565b6000818152609860205260409020600201545b919050565b61089f6000805160206135ee83398151915233610c69565b6108bb5760405162461bcd60e51b81526004016106a39061343b565b6108c481611b64565b50565b6000828152609860205260409020600201546108e590610461611668565b6109205760405162461bcd60e51b815260040180806020018281038252602f81526020018061359d602f913960400191505060405180910390fd5b61092a8282611b99565b5050565b60cc546001600160a01b031681565b60385460ff1690565b6001600160a01b03808216600090815260cb60209081526040808320938616835260029093019052205492915050565b60ce5481565b610984611668565b6001600160a01b0316816001600160a01b0316146109d35760405162461bcd60e51b815260040180806020018281038252602f8152602001806137dc602f913960400191505060405180910390fd5b61092a8282611c02565b60006106766109ea611668565b8461085f85603460006109fb611668565b6001600160a01b03908116825260208083019390935260409182016000908120918c168152925290205490611758565b6001600160a01b038216600090815260656020526040812081908190610a52908590611c6b565b9150915081610a6957610a6485610af7565b610a6b565b805b95945050505050565b610a8c6000805160206135ee83398151915233610c69565b610aa85760405162461bcd60e51b81526004016106a39061343b565b60cd8190556040517ff4f81c8df394c367119ef9185e49924fbc14f33668d8c0fe5a767cc822858ae290610add90839061334c565b60405180910390a150565b6097546001600160a01b031681565b6001600160a01b031660009081526033602052604090205490565b60cd5481565b610b2133610af7565b610b3d5760405162461bcd60e51b81526004016106a3906134a1565b33600081815260d1602052604090819020429081905590517f8a05f911d8ab7fc50fec37ef4ba7f9bfcb1a3c191c81dcd824ad0946c4e20d6591610b809161334c565b60405180910390a2565b60d06020526000908152604090205481565b60408051600180825281830190925260009160609190816020015b610bbf612e4d565b815260200190600190039081610bb75790505090506040518060600160405280306001600160a01b03168152602001610bf785610af7565b8152602001610c04610680565b81525081600081518110610c1457fe5b6020026020010181905250610868610c2c8483611d68565b6001600160a01b038516600090815260d0602052604090205490611758565b60008281526098602052604081206108689083611e59565b60ca5481565b60008281526098602052604081206108689083611e65565b60cf546001600160a01b031681565b60378054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156106465780601f1061061b57610100808354040283529160200191610646565b6000806000610d01846066611c6b565b9150915081610d1757610d12610680565b610d19565b805b949350505050565b6000610d3733610d3033610af7565b600061180f565b905060006000198314610d4a5782610d4c565b815b9050610d89816040518060400160405280600e81526020016d1253959053125117d05353d5539560921b81525084611acd9092919063ffffffff16565b33600090815260d06020526040908190209190915560cf54905163a9059cbb60e01b81526001600160a01b039091169063a9059cbb90610dcf9087908590600401613328565b602060405180830381600087803b158015610de957600080fd5b505af1158015610dfd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e219190613179565b610e3d5760405162461bcd60e51b81526004016106a3906133d5565b836001600160a01b0316336001600160a01b03167f9310ccfcb8de723f578a9e4282ea9f521f05ae40dc08f3068dfad528a65ee3c783604051610e80919061334c565b60405180910390a350505050565b600081565b6000610676610ea0611668565b8461085f856040518060600160405280602581526020016137b76025913960346000610eca611668565b6001600160a01b03908116825260208083019390935260409182016000908120918d16815292529020549190611acd565b6000610676610f08611668565b8484611a01565b601281565b80610f315760405162461bcd60e51b81526004016106a3906133a8565b6000610f3c83610af7565b90506000610f53843084610f4e610680565b611e7a565b90508015610fd1577f2468f9268c60ad90e2d49edb0032c8a001e733ae888b3ab8e982edf535be1a768482604051610f8c929190613328565b60405180910390a16001600160a01b038416600090815260d06020526040902054610fb79082611758565b6001600160a01b038516600090815260d060205260409020555b610fde6000848685611521565b6001600160a01b038516600090815260d160205260409020556110018484611f39565b60cc54611019906001600160a01b031633308661202b565b836001600160a01b0316336001600160a01b03167f5dac0c1b1112564a045ba943c9d50270893e8e826c49be8e7073adc713ab7bd785604051610e80919061334c565b6110746000805160206135ee83398151915233610c69565b6110905760405162461bcd60e51b81526004016106a39061343b565b60005b815181101561092a57600060cb60008484815181106110ae57fe5b6020026020010151604001516001600160a01b03166001600160a01b0316815260200190815260200160002090506111158383815181106110eb57fe5b6020026020010151604001518285858151811061110457fe5b602002602001015160200151612085565b5082828151811061112257fe5b60209081029190910101515181546fffffffffffffffffffffffffffffffff19166001600160801b03909116178155825183908390811061115f57fe5b6020026020010151604001516001600160a01b03167f87fa03892a0556cb6b8f97e6d533a150d4d55fcbf275fff5fa003fa636bcc7fa8484815181106111a157fe5b6020026020010151600001516040516111ba91906134d8565b60405180910390a250600101611093565b600054610100900460ff16806111e457506111e4612142565b806111f2575060005460ff16155b61122d5760405162461bcd60e51b815260040180806020018281038252602e8152602001806136ac602e913960400191505060405180910390fd5b600054610100900460ff16158015611258576000805460ff1961ff0019909116610100171660011790555b611260612153565b61126a4283611758565b60ca55611278600033610920565b6112906000805160206135ee83398151915284610920565b80156112a2576000805461ff00191690555b505050565b6000805160206135ee83398151915281565b600054610100900460ff16806112d257506112d2612142565b806112e0575060005460ff16155b61131b5760405162461bcd60e51b815260040180806020018281038252602e8152602001806136ac602e913960400191505060405180910390fd5b600054610100900460ff16158015611346576000805460ff1961ff0019909116610100171660011790555b61139d6040518060400160405280600c81526020016b0a6e8c2d6cac8408aa89092b60a31b815250604051806040016040528060088152602001670e6e8d68aa89092b60c31b81525060128a8c8b8b8b8b8b6121f4565b80156113af576000805461ff00191690555b5050505050505050565b600054610100900460ff16806113d257506113d2612142565b806113e0575060005460ff16155b61141b5760405162461bcd60e51b815260040180806020018281038252602e8152602001806136ac602e913960400191505060405180910390fd5b600054610100900460ff16158015611446576000805460ff1961ff0019909116610100171660011790555b61144e612309565b61129083836123a6565b600081815260986020526040812061067a90612445565b60008281526098602052604090206002015461148d90610461611668565b6109d35760405162461bcd60e51b815260040180806020018281038252603081526020018061367c6030913960400191505060405180910390fd5b6001600160a01b03918216600090815260346020908152604080832093909416825291909152205490565b60cb60205260009081526040902080546001909101546001600160801b0380831692600160801b9004169083565b6001600160a01b038216600090815260d1602052604081205480611549576000915050610d19565b600061156c60ce5461156660cd54426117b290919063ffffffff16565b906117b2565b90508181111561157f57600091506115d9565b600087821161158e5787611590565b425b9050828110156115a557829350505050610d19565b6115d56115b28887611758565b6115cf6115bf8887612450565b6115c98b86612450565b90611758565b906124a9565b9250505b506001600160a01b038416600090815260d1602052604090208190559050949350505050565b6116176000805160206135ee83398151915233610c69565b6116335760405162461bcd60e51b81526004016106a39061343b565b60ce8190556040517f2569aa72cd2c41c9d0fcc0ee222fb1c8c0b26ba03e48d3cd2db5461c6c160a1690610add90839061334c565b3390565b6001600160a01b0383166116b15760405162461bcd60e51b81526004018080602001828103825260248152602001806137696024913960400191505060405180910390fd5b6001600160a01b0382166116f65760405162461bcd60e51b815260040180806020018281038252602281526020018061360e6022913960400191505060405180910390fd5b6001600160a01b03808416600081815260346020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b600082820183811015610868576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b600082821115611809576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b600080611820853086610f4e610680565b6001600160a01b038616600090815260d06020526040812054919250906118479083611758565b90508115610a6b578315611871576001600160a01b038616600090815260d0602052604090208190555b7f2468f9268c60ad90e2d49edb0032c8a001e733ae888b3ab8e982edf535be1a7686836040516118a2929190613328565b60405180910390a195945050505050565b6001600160a01b0382166118f85760405162461bcd60e51b81526004018080602001828103825260218152602001806137236021913960400191505060405180910390fd5b61190482600083612510565b611941816040518060600160405280602281526020016135cc602291396001600160a01b0385166000908152603360205260409020549190611acd565b6001600160a01b03831660009081526033602052604090205560355461196790826117b2565b6035556040805182815290516000916001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526112a2908490612568565b6000611a0c84610af7565b9050611a1a8482600161180f565b50826001600160a01b0316846001600160a01b031614611abc576000611a3f84610af7565b9050611a4d8482600161180f565b506001600160a01b038516600090815260d16020526040902054611a7381858785611521565b6001600160a01b038616600090815260d160205260409020558284148015611a9a57508015155b15611ab9576001600160a01b038616600090815260d160205260408120555b50505b611ac7848484612619565b50505050565b60008184841115611b5c5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611b21578181015183820152602001611b09565b50505050905090810190601f168015611b4e5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b60ca8190556040517f04719fa2f4e8205ff1369b5c7d2b3eb66c25570e7bf668ae7ccecb8fbd7ed52e90610add90839061334c565b6000828152609860205260409020611bb19082612776565b1561092a57611bbe611668565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152609860205260409020611c1a908261278b565b1561092a57611c27611668565b6001600160a01b0316816001600160a01b0316837ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b60405160405180910390a45050565b60008060008411611cbc576040805162461bcd60e51b815260206004820152601660248201527504552433230536e617073686f743a20696420697320360541b604482015290519081900360640190fd5b611cc660686127a0565b841115611d1a576040805162461bcd60e51b815260206004820152601d60248201527f4552433230536e617073686f743a206e6f6e6578697374656e74206964000000604482015290519081900360640190fd5b6000611d2684866127a4565b8454909150811415611d3f576000809250925050611d61565b6001846001018281548110611d5057fe5b906000526020600020015492509250505b9250929050565b600080805b8351811015611e5157600060cb6000868481518110611d8857fe5b602090810291909101810151516001600160a01b031682528101919091526040016000908120600181015481548851929450611df0926001600160801b0380831692600160801b900416908a9088908110611ddf57fe5b602002602001015160400151612845565b9050611e45611e3e878581518110611e0457fe5b602002602001015160200151838560020160008c6001600160a01b03166001600160a01b03168152602001908152602001600020546128e4565b8590611758565b93505050600101611d6d565b509392505050565b60006108688383612906565b6000610868836001600160a01b03841661296a565b6001600160a01b03808416600090815260cb602090815260408083209388168352600284019091528120549091908280611eb5888588612085565b9050808314611f2d578615611ed257611ecf8782856128e4565b91505b6001600160a01b03808a1660008181526002870160205260409081902084905551918a16917fbb123b5c06d5408bbea3c4fef481578175cfb432e3b482c6186f02ed9086585b90611f2490859061334c565b60405180910390a35b50979650505050505050565b6001600160a01b038216611f94576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b611fa060008383612510565b603554611fad9082611758565b6035556001600160a01b038216600090815260336020526040902054611fd39082611758565b6001600160a01b03831660008181526033602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b604080516001600160a01b0380861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b179052611ac7908590612568565b6001820154825460009190600160801b90046001600160801b0316428114156120b057509050610868565b84546000906120cb9084906001600160801b03168488612845565b905082811461211f57808660010181905550866001600160a01b03167f5777ca300dfe5bead41006fbce4389794dbc0ed8d6cccebfaf94630aa04184bc82604051612116919061334c565b60405180910390a25b85546001600160801b03428116600160801b029116178655925050509392505050565b600061214d30612982565b15905090565b600054610100900460ff168061216c575061216c612142565b8061217a575060005460ff16155b6121b55760405162461bcd60e51b815260040180806020018281038252602e8152602001806136ac602e913960400191505060405180910390fd5b600054610100900460ff161580156121e0576000805460ff1961ff0019909116610100171660011790555b80156108c4576000805461ff001916905550565b600054610100900460ff168061220d575061220d612142565b8061221b575060005460ff16155b6122565760405162461bcd60e51b815260040180806020018281038252602e8152602001806136ac602e913960400191505060405180910390fd5b600054610100900460ff16158015612281576000805460ff1961ff0019909116610100171660011790555b61228b8b8b6113b9565b61229489612988565b61229d8861299e565b6122b083836001600160801b03166111cb565b60cc80546001600160a01b03808a166001600160a01b03199283161790925560cd88905560ce87905560cf80549287169290911691909117905580156122fc576000805461ff00191690555b5050505050505050505050565b600054610100900460ff16806123225750612322612142565b80612330575060005460ff16155b61236b5760405162461bcd60e51b815260040180806020018281038252602e8152602001806136ac602e913960400191505060405180910390fd5b600054610100900460ff16158015612396576000805460ff1961ff0019909116610100171660011790555b61239e612153565b6121e0612153565b600054610100900460ff16806123bf57506123bf612142565b806123cd575060005460ff16155b6124085760405162461bcd60e51b815260040180806020018281038252602e8152602001806136ac602e913960400191505060405180910390fd5b600054610100900460ff16158015612433576000805460ff1961ff0019909116610100171660011790555b61243b612153565b61129083836129c0565b600061067a826127a0565b60008261245f5750600061067a565b8282028284828161246c57fe5b04146108685760405162461bcd60e51b81526004018080602001828103825260218152602001806136da6021913960400191505060405180910390fd5b60008082116124ff576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b81838161250857fe5b049392505050565b61251b8383836112a2565b6001600160a01b03831661253f5761253282612a98565b61253a612ac2565b6112a2565b6001600160a01b0382166125565761253283612a98565b61255f83612a98565b6112a282612a98565b60606125bd826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612ad19092919063ffffffff16565b8051909150156112a2578080602001905160208110156125dc57600080fd5b50516112a25760405162461bcd60e51b815260040180806020018281038252602a81526020018061378d602a913960400191505060405180910390fd5b6001600160a01b03831661265e5760405162461bcd60e51b81526004018080602001828103825260258152602001806137446025913960400191505060405180910390fd5b6001600160a01b0382166126a35760405162461bcd60e51b815260040180806020018281038252602381526020018061357a6023913960400191505060405180910390fd5b6126ae838383612510565b6126eb81604051806060016040528060268152602001613630602691396001600160a01b0386166000908152603360205260409020549190611acd565b6001600160a01b03808516600090815260336020526040808220939093559084168152205461271a9082611758565b6001600160a01b0380841660008181526033602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b6000610868836001600160a01b038416612ae0565b6000610868836001600160a01b038416612b2a565b5490565b81546000906127b55750600061067a565b82546000905b808210156128045760006127cf8383612bf0565b9050848682815481106127de57fe5b906000526020600020015411156127f7578091506127fe565b8060010192505b506127bb565b60008211801561282c57508385600184038154811061281f57fe5b9060005260206000200154145b1561283d575060001901905061067a565b50905061067a565b6000831580612852575081155b80612865575042836001600160801b0316145b8061287b575060ca54836001600160801b031610155b15612887575083610d19565b600060ca544211612898574261289c565b60ca545b905060006128b3826001600160801b0387166117b2565b90506128d9876115c9866115cf670de0b6b3a76400006128d38c88612450565b90612450565b979650505050505050565b6000610d19670de0b6b3a76400006115cf6128ff86866117b2565b8790612450565b815460009082106129485760405162461bcd60e51b81526004018080602001828103825260228152602001806135586022913960400191505060405180910390fd5b82600001828154811061295757fe5b9060005260206000200154905092915050565b60009081526001919091016020526040902054151590565b3b151590565b6038805460ff191660ff92909216919091179055565b609780546001600160a01b0319166001600160a01b0392909216919091179055565b600054610100900460ff16806129d957506129d9612142565b806129e7575060005460ff16155b612a225760405162461bcd60e51b815260040180806020018281038252602e8152602001806136ac602e913960400191505060405180910390fd5b600054610100900460ff16158015612a4d576000805460ff1961ff0019909116610100171660011790555b8251612a60906036906020860190612e77565b508151612a74906037906020850190612e77565b506038805460ff1916601217905580156112a2576000805461ff0019169055505050565b6001600160a01b03811660009081526065602052604090206108c490612abd83610af7565b612c15565b612acf6066612abd610680565b565b6060610d198484600085612c61565b6000612aec838361296a565b612b225750815460018181018455600084815260208082209093018490558454848252828601909352604090209190915561067a565b50600061067a565b60008181526001830160205260408120548015612be65783546000198083019190810190600090879083908110612b5d57fe5b9060005260206000200154905080876000018481548110612b7a57fe5b600091825260208083209091019290925582815260018981019092526040902090840190558654879080612baa57fe5b6001900381819060005260206000200160009055905586600101600087815260200190815260200160002060009055600194505050505061067a565b600091505061067a565b60006002808306600285060181612c0357fe5b04600283046002850401019392505050565b6000612c2160686127a0565b905080612c2d84612db2565b10156112a2578254600180820185556000858152602080822090930193909355938401805494850181558252902090910155565b606082471015612ca25760405162461bcd60e51b81526004018080602001828103825260268152602001806136566026913960400191505060405180910390fd5b612cab85612982565b612cfc576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b60006060866001600160a01b031685876040518082805190602001908083835b60208310612d3b5780518252601f199092019160209182019101612d1c565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114612d9d576040519150601f19603f3d011682016040523d82523d6000602084013e612da2565b606091505b50915091506128d9828286612de7565b8054600090612dc357506000610882565b815482906000198101908110612dd557fe5b90600052602060002001549050610882565b60608315612df6575081610868565b825115612e065782518084602001fd5b60405162461bcd60e51b8152602060048201818152845160248401528451859391928392604401919085019080838360008315611b21578181015183820152602001611b09565b604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282612ead5760008555612ef3565b82601f10612ec657805160ff1916838001178555612ef3565b82800160010185558215612ef3579182015b82811115612ef3578251825591602001919060010190612ed8565b50612eff929150612f03565b5090565b5b80821115612eff5760008155600101612f04565b600082601f830112612f28578081fd5b813567ffffffffffffffff811115612f3c57fe5b612f4f601f8201601f191660200161351e565b9150808252836020828501011115612f6657600080fd5b8060208401602084013760009082016020015292915050565b600060608284031215612f90578081fd5b6040516060810181811067ffffffffffffffff82111715612fad57fe5b604052905080612fbc83612fe3565b8152602083013560208201526040830135612fd681613542565b6040919091015292915050565b80356001600160801b038116811461088257600080fd5b60006020828403121561300b578081fd5b813561086881613542565b60008060408385031215613028578081fd5b823561303381613542565b946020939093013593505050565b60008060408385031215613053578182fd5b823561305e81613542565b9150602083013561306e81613542565b809150509250929050565b60008060006060848603121561308d578081fd5b833561309881613542565b925060208401356130a881613542565b929592945050506040919091013590565b60008060408385031215613028578182fd5b600060208083850312156130dd578182fd5b823567ffffffffffffffff808211156130f4578384fd5b818501915085601f830112613107578384fd5b81358181111561311357fe5b613120848583020161351e565b81815284810192508385016060808402860187018a101561313f578788fd5b8795505b8386101561316b576131558a83612f7f565b8552600195909501949386019390810190613143565b509098975050505050505050565b60006020828403121561318a578081fd5b81518015158114610868578182fd5b6000602082840312156131aa578081fd5b5035919050565b600080604083850312156131c3578182fd5b82359150602083013561306e81613542565b600080604083850312156131e7578182fd5b50508035926020909101359150565b600080600080600080600060e0888a031215613210578283fd5b873561321b81613542565b9650602088013561322b81613542565b95506040880135945060608801359350608088013561324981613542565b925060a088013561325981613542565b915061326760c08901612fe3565b905092959891949750929550565b60008060408385031215613287578182fd5b823567ffffffffffffffff8082111561329e578384fd5b6132aa86838701612f18565b935060208501359150808211156132bf578283fd5b506132cc85828601612f18565b9150509250929050565b600080600080608085870312156132eb578182fd5b8435935060208501359250604085013561330481613542565b9396929550929360600135925050565b6001600160a01b0391909116815260200190565b6001600160a01b03929092168252602082015260400190565b901515815260200190565b90815260200190565b6000602080835283518082850152825b8181101561338157858101830151858201604001528201613365565b818111156133925783604083870101525b50601f01601f1916929092016040019392505050565b6020808252601390820152721253959053125117d6915493d7d05353d55395606a1b604082015260600190565b60208082526019908201527f4552524f525f5452414e534645525f46524f4d5f5641554c5400000000000000604082015260600190565b60208082526015908201527424a729aaa32324a1a4a2a72a2fa1a7a7a62227aba760591b604082015260600190565b60208082526015908201527427a7262cafa2a6a4a9a9a4a7a72fa6a0a720a3a2a960591b604082015260600190565b60208082526017908201527f554e5354414b455f57494e444f575f46494e4953484544000000000000000000604082015260600190565b6020808252601b908201527f494e56414c49445f42414c414e43455f4f4e5f434f4f4c444f574e0000000000604082015260600190565b6001600160801b0391909116815260200190565b6001600160801b039384168152919092166020820152604081019190915260600190565b60ff91909116815260200190565b60405181810167ffffffffffffffff8111828210171561353a57fe5b604052919050565b6001600160a01b03811681146108c457600080fdfe456e756d657261626c655365743a20696e646578206f7574206f6620626f756e647345524332303a207472616e7366657220746f20746865207a65726f2061646472657373416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e2061646d696e20746f206772616e7445524332303a206275726e20616d6f756e7420657863656564732062616c616e63650178ef1edee9408b9148e43c7402964baa5d7066a35d0ff56e2596c8e1dc0f6745524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e6365416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e2061646d696e20746f207265766f6b65496e697469616c697a61626c653a20636f6e747261637420697320616c726561647920696e697469616c697a6564536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7745524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f20616464726573735361666545524332303a204552433230206f7065726174696f6e20646964206e6f74207375636365656445524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636520726f6c657320666f722073656c66a264697066735822122057d3dc5dbb6fe69a62a27f8b764096c5963cc4f87460c590bc43565e9706fc0e64736f6c63430007050033

Deployed Bytecode

0x608060405234801561001057600080fd5b506004361061028a5760003560e01c80639010d07c1161015c578063adc9772e116100ce578063ca15c87311610087578063ca15c87314610539578063d547741f1461054c578063dd62ed3e1461055f578063f11b818814610572578063f1cc432a14610594578063f8f10dfc146105a75761028a565b8063adc9772e146104d2578063b2a5dbfa146104e5578063b398741a146104f8578063b4f0e8c31461050b578063c1a9d6e914610513578063c3c9e42d146105265761028a565b8063981b24d011610120578063981b24d0146104765780639a99b4f014610489578063a217fddf1461049c578063a457c2d7146104a4578063a9059cbb146104b7578063aaf5eb68146104ca5761028a565b80639010d07c14610438578063919cd40f1461044b57806391d1485414610453578063946776cd1461046657806395d89b411461046e5761028a565b80633373ee4c116102005780635fe5952a116101b95780635fe5952a146103e757806370a08231146103ef57806372b49d6314610402578063787a08a61461040a5780637e90d7ef146104125780638dbefee2146104255761028a565b80633373ee4c14610380578063359c4a961461039357806336568abe1461039b57806339509351146103ae5780634ee2cd7e146103c15780634fc3f41a146103d45761028a565b806323b872dd1161025257806323b872dd1461030a578063248a9ca31461031d5780632752f89a146103305780632f2ff15d14610343578063312f6b8314610356578063313ce5671461036b5761028a565b806306fdde031461028f578063091030c3146102ad578063095ea7b3146102cd57806318160ddd146102ed5780631e9a6950146102f5575b600080fd5b6102976105ba565b6040516102a49190613355565b60405180910390f35b6102c06102bb366004612ffa565b610650565b6040516102a4919061334c565b6102e06102db3660046130b9565b610662565b6040516102a49190613341565b6102c0610680565b6103086103033660046130b9565b610686565b005b6102e0610318366004613079565b6107e7565b6102c061032b366004613199565b61086f565b61030861033e366004613199565b610887565b6103086103513660046131b1565b6108c7565b61035e61092e565b6040516102a49190613314565b61037361093d565b6040516102a49190613510565b6102c061038e366004613041565b610946565b6102c0610976565b6103086103a93660046131b1565b61097c565b6102e06103bc3660046130b9565b6109dd565b6102c06103cf3660046130b9565b610a2b565b6103086103e2366004613199565b610a74565b61035e610ae8565b6102c06103fd366004612ffa565b610af7565b6102c0610b12565b610308610b18565b6102c0610420366004612ffa565b610b8a565b6102c0610433366004612ffa565b610b9c565b61035e6104463660046131d5565b610c4b565b6102c0610c63565b6102e06104613660046131b1565b610c69565b61035e610c81565b610297610c90565b6102c0610484366004613199565b610cf1565b610308610497366004613016565b610d21565b6102c0610e8e565b6102e06104b23660046130b9565b610e93565b6102e06104c53660046130b9565b610efb565b610373610f0f565b6103086104e03660046130b9565b610f14565b6103086104f33660046130cb565b61105c565b6103086105063660046130b9565b6111cb565b6102c06112a7565b6103086105213660046131f6565b6112b9565b610308610534366004613275565b6113b9565b6102c0610547366004613199565b611458565b61030861055a3660046131b1565b61146f565b6102c061056d366004613041565b6114c8565b610585610580366004612ffa565b6114f3565b6040516102a4939291906134ec565b6102c06105a23660046132d6565b611521565b6103086105b5366004613199565b6115ff565b60368054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156106465780601f1061061b57610100808354040283529160200191610646565b820191906000526020600020905b81548152906001019060200180831161062957829003601f168201915b5050505050905090565b60d16020526000908152604090205481565b600061067661066f611668565b848461166c565b5060015b92915050565b60355490565b806106ac5760405162461bcd60e51b81526004016106a3906133a8565b60405180910390fd5b33600090815260d1602052604090205460cd546106ca908290611758565b42116106e85760405162461bcd60e51b81526004016106a39061340c565b60ce5461070a61070360cd548461175890919063ffffffff16565b42906117b2565b11156107285760405162461bcd60e51b81526004016106a39061346a565b600061073333610af7565b905060008184116107445783610746565b815b90506107543383600161180f565b5061075f33826118b3565b61076982826117b2565b61077e5733600090815260d160205260408120555b60cc54610795906001600160a01b031686836119af565b846001600160a01b0316336001600160a01b03167fd12200efa34901b99367694174c3b0d32c99585fdf37c7c26892136ddd0836d9836040516107d8919061334c565b60405180910390a35050505050565b60006107f4848484611a01565b61086484610800611668565b61085f856040518060600160405280602881526020016136fb602891396001600160a01b038a1660009081526034602052604081209061083e611668565b6001600160a01b031681526020810191909152604001600020549190611acd565b61166c565b5060015b9392505050565b6000818152609860205260409020600201545b919050565b61089f6000805160206135ee83398151915233610c69565b6108bb5760405162461bcd60e51b81526004016106a39061343b565b6108c481611b64565b50565b6000828152609860205260409020600201546108e590610461611668565b6109205760405162461bcd60e51b815260040180806020018281038252602f81526020018061359d602f913960400191505060405180910390fd5b61092a8282611b99565b5050565b60cc546001600160a01b031681565b60385460ff1690565b6001600160a01b03808216600090815260cb60209081526040808320938616835260029093019052205492915050565b60ce5481565b610984611668565b6001600160a01b0316816001600160a01b0316146109d35760405162461bcd60e51b815260040180806020018281038252602f8152602001806137dc602f913960400191505060405180910390fd5b61092a8282611c02565b60006106766109ea611668565b8461085f85603460006109fb611668565b6001600160a01b03908116825260208083019390935260409182016000908120918c168152925290205490611758565b6001600160a01b038216600090815260656020526040812081908190610a52908590611c6b565b9150915081610a6957610a6485610af7565b610a6b565b805b95945050505050565b610a8c6000805160206135ee83398151915233610c69565b610aa85760405162461bcd60e51b81526004016106a39061343b565b60cd8190556040517ff4f81c8df394c367119ef9185e49924fbc14f33668d8c0fe5a767cc822858ae290610add90839061334c565b60405180910390a150565b6097546001600160a01b031681565b6001600160a01b031660009081526033602052604090205490565b60cd5481565b610b2133610af7565b610b3d5760405162461bcd60e51b81526004016106a3906134a1565b33600081815260d1602052604090819020429081905590517f8a05f911d8ab7fc50fec37ef4ba7f9bfcb1a3c191c81dcd824ad0946c4e20d6591610b809161334c565b60405180910390a2565b60d06020526000908152604090205481565b60408051600180825281830190925260009160609190816020015b610bbf612e4d565b815260200190600190039081610bb75790505090506040518060600160405280306001600160a01b03168152602001610bf785610af7565b8152602001610c04610680565b81525081600081518110610c1457fe5b6020026020010181905250610868610c2c8483611d68565b6001600160a01b038516600090815260d0602052604090205490611758565b60008281526098602052604081206108689083611e59565b60ca5481565b60008281526098602052604081206108689083611e65565b60cf546001600160a01b031681565b60378054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156106465780601f1061061b57610100808354040283529160200191610646565b6000806000610d01846066611c6b565b9150915081610d1757610d12610680565b610d19565b805b949350505050565b6000610d3733610d3033610af7565b600061180f565b905060006000198314610d4a5782610d4c565b815b9050610d89816040518060400160405280600e81526020016d1253959053125117d05353d5539560921b81525084611acd9092919063ffffffff16565b33600090815260d06020526040908190209190915560cf54905163a9059cbb60e01b81526001600160a01b039091169063a9059cbb90610dcf9087908590600401613328565b602060405180830381600087803b158015610de957600080fd5b505af1158015610dfd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e219190613179565b610e3d5760405162461bcd60e51b81526004016106a3906133d5565b836001600160a01b0316336001600160a01b03167f9310ccfcb8de723f578a9e4282ea9f521f05ae40dc08f3068dfad528a65ee3c783604051610e80919061334c565b60405180910390a350505050565b600081565b6000610676610ea0611668565b8461085f856040518060600160405280602581526020016137b76025913960346000610eca611668565b6001600160a01b03908116825260208083019390935260409182016000908120918d16815292529020549190611acd565b6000610676610f08611668565b8484611a01565b601281565b80610f315760405162461bcd60e51b81526004016106a3906133a8565b6000610f3c83610af7565b90506000610f53843084610f4e610680565b611e7a565b90508015610fd1577f2468f9268c60ad90e2d49edb0032c8a001e733ae888b3ab8e982edf535be1a768482604051610f8c929190613328565b60405180910390a16001600160a01b038416600090815260d06020526040902054610fb79082611758565b6001600160a01b038516600090815260d060205260409020555b610fde6000848685611521565b6001600160a01b038516600090815260d160205260409020556110018484611f39565b60cc54611019906001600160a01b031633308661202b565b836001600160a01b0316336001600160a01b03167f5dac0c1b1112564a045ba943c9d50270893e8e826c49be8e7073adc713ab7bd785604051610e80919061334c565b6110746000805160206135ee83398151915233610c69565b6110905760405162461bcd60e51b81526004016106a39061343b565b60005b815181101561092a57600060cb60008484815181106110ae57fe5b6020026020010151604001516001600160a01b03166001600160a01b0316815260200190815260200160002090506111158383815181106110eb57fe5b6020026020010151604001518285858151811061110457fe5b602002602001015160200151612085565b5082828151811061112257fe5b60209081029190910101515181546fffffffffffffffffffffffffffffffff19166001600160801b03909116178155825183908390811061115f57fe5b6020026020010151604001516001600160a01b03167f87fa03892a0556cb6b8f97e6d533a150d4d55fcbf275fff5fa003fa636bcc7fa8484815181106111a157fe5b6020026020010151600001516040516111ba91906134d8565b60405180910390a250600101611093565b600054610100900460ff16806111e457506111e4612142565b806111f2575060005460ff16155b61122d5760405162461bcd60e51b815260040180806020018281038252602e8152602001806136ac602e913960400191505060405180910390fd5b600054610100900460ff16158015611258576000805460ff1961ff0019909116610100171660011790555b611260612153565b61126a4283611758565b60ca55611278600033610920565b6112906000805160206135ee83398151915284610920565b80156112a2576000805461ff00191690555b505050565b6000805160206135ee83398151915281565b600054610100900460ff16806112d257506112d2612142565b806112e0575060005460ff16155b61131b5760405162461bcd60e51b815260040180806020018281038252602e8152602001806136ac602e913960400191505060405180910390fd5b600054610100900460ff16158015611346576000805460ff1961ff0019909116610100171660011790555b61139d6040518060400160405280600c81526020016b0a6e8c2d6cac8408aa89092b60a31b815250604051806040016040528060088152602001670e6e8d68aa89092b60c31b81525060128a8c8b8b8b8b8b6121f4565b80156113af576000805461ff00191690555b5050505050505050565b600054610100900460ff16806113d257506113d2612142565b806113e0575060005460ff16155b61141b5760405162461bcd60e51b815260040180806020018281038252602e8152602001806136ac602e913960400191505060405180910390fd5b600054610100900460ff16158015611446576000805460ff1961ff0019909116610100171660011790555b61144e612309565b61129083836123a6565b600081815260986020526040812061067a90612445565b60008281526098602052604090206002015461148d90610461611668565b6109d35760405162461bcd60e51b815260040180806020018281038252603081526020018061367c6030913960400191505060405180910390fd5b6001600160a01b03918216600090815260346020908152604080832093909416825291909152205490565b60cb60205260009081526040902080546001909101546001600160801b0380831692600160801b9004169083565b6001600160a01b038216600090815260d1602052604081205480611549576000915050610d19565b600061156c60ce5461156660cd54426117b290919063ffffffff16565b906117b2565b90508181111561157f57600091506115d9565b600087821161158e5787611590565b425b9050828110156115a557829350505050610d19565b6115d56115b28887611758565b6115cf6115bf8887612450565b6115c98b86612450565b90611758565b906124a9565b9250505b506001600160a01b038416600090815260d1602052604090208190559050949350505050565b6116176000805160206135ee83398151915233610c69565b6116335760405162461bcd60e51b81526004016106a39061343b565b60ce8190556040517f2569aa72cd2c41c9d0fcc0ee222fb1c8c0b26ba03e48d3cd2db5461c6c160a1690610add90839061334c565b3390565b6001600160a01b0383166116b15760405162461bcd60e51b81526004018080602001828103825260248152602001806137696024913960400191505060405180910390fd5b6001600160a01b0382166116f65760405162461bcd60e51b815260040180806020018281038252602281526020018061360e6022913960400191505060405180910390fd5b6001600160a01b03808416600081815260346020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b600082820183811015610868576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b600082821115611809576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b600080611820853086610f4e610680565b6001600160a01b038616600090815260d06020526040812054919250906118479083611758565b90508115610a6b578315611871576001600160a01b038616600090815260d0602052604090208190555b7f2468f9268c60ad90e2d49edb0032c8a001e733ae888b3ab8e982edf535be1a7686836040516118a2929190613328565b60405180910390a195945050505050565b6001600160a01b0382166118f85760405162461bcd60e51b81526004018080602001828103825260218152602001806137236021913960400191505060405180910390fd5b61190482600083612510565b611941816040518060600160405280602281526020016135cc602291396001600160a01b0385166000908152603360205260409020549190611acd565b6001600160a01b03831660009081526033602052604090205560355461196790826117b2565b6035556040805182815290516000916001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526112a2908490612568565b6000611a0c84610af7565b9050611a1a8482600161180f565b50826001600160a01b0316846001600160a01b031614611abc576000611a3f84610af7565b9050611a4d8482600161180f565b506001600160a01b038516600090815260d16020526040902054611a7381858785611521565b6001600160a01b038616600090815260d160205260409020558284148015611a9a57508015155b15611ab9576001600160a01b038616600090815260d160205260408120555b50505b611ac7848484612619565b50505050565b60008184841115611b5c5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611b21578181015183820152602001611b09565b50505050905090810190601f168015611b4e5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b60ca8190556040517f04719fa2f4e8205ff1369b5c7d2b3eb66c25570e7bf668ae7ccecb8fbd7ed52e90610add90839061334c565b6000828152609860205260409020611bb19082612776565b1561092a57611bbe611668565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000828152609860205260409020611c1a908261278b565b1561092a57611c27611668565b6001600160a01b0316816001600160a01b0316837ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b60405160405180910390a45050565b60008060008411611cbc576040805162461bcd60e51b815260206004820152601660248201527504552433230536e617073686f743a20696420697320360541b604482015290519081900360640190fd5b611cc660686127a0565b841115611d1a576040805162461bcd60e51b815260206004820152601d60248201527f4552433230536e617073686f743a206e6f6e6578697374656e74206964000000604482015290519081900360640190fd5b6000611d2684866127a4565b8454909150811415611d3f576000809250925050611d61565b6001846001018281548110611d5057fe5b906000526020600020015492509250505b9250929050565b600080805b8351811015611e5157600060cb6000868481518110611d8857fe5b602090810291909101810151516001600160a01b031682528101919091526040016000908120600181015481548851929450611df0926001600160801b0380831692600160801b900416908a9088908110611ddf57fe5b602002602001015160400151612845565b9050611e45611e3e878581518110611e0457fe5b602002602001015160200151838560020160008c6001600160a01b03166001600160a01b03168152602001908152602001600020546128e4565b8590611758565b93505050600101611d6d565b509392505050565b60006108688383612906565b6000610868836001600160a01b03841661296a565b6001600160a01b03808416600090815260cb602090815260408083209388168352600284019091528120549091908280611eb5888588612085565b9050808314611f2d578615611ed257611ecf8782856128e4565b91505b6001600160a01b03808a1660008181526002870160205260409081902084905551918a16917fbb123b5c06d5408bbea3c4fef481578175cfb432e3b482c6186f02ed9086585b90611f2490859061334c565b60405180910390a35b50979650505050505050565b6001600160a01b038216611f94576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b611fa060008383612510565b603554611fad9082611758565b6035556001600160a01b038216600090815260336020526040902054611fd39082611758565b6001600160a01b03831660008181526033602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b604080516001600160a01b0380861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b179052611ac7908590612568565b6001820154825460009190600160801b90046001600160801b0316428114156120b057509050610868565b84546000906120cb9084906001600160801b03168488612845565b905082811461211f57808660010181905550866001600160a01b03167f5777ca300dfe5bead41006fbce4389794dbc0ed8d6cccebfaf94630aa04184bc82604051612116919061334c565b60405180910390a25b85546001600160801b03428116600160801b029116178655925050509392505050565b600061214d30612982565b15905090565b600054610100900460ff168061216c575061216c612142565b8061217a575060005460ff16155b6121b55760405162461bcd60e51b815260040180806020018281038252602e8152602001806136ac602e913960400191505060405180910390fd5b600054610100900460ff161580156121e0576000805460ff1961ff0019909116610100171660011790555b80156108c4576000805461ff001916905550565b600054610100900460ff168061220d575061220d612142565b8061221b575060005460ff16155b6122565760405162461bcd60e51b815260040180806020018281038252602e8152602001806136ac602e913960400191505060405180910390fd5b600054610100900460ff16158015612281576000805460ff1961ff0019909116610100171660011790555b61228b8b8b6113b9565b61229489612988565b61229d8861299e565b6122b083836001600160801b03166111cb565b60cc80546001600160a01b03808a166001600160a01b03199283161790925560cd88905560ce87905560cf80549287169290911691909117905580156122fc576000805461ff00191690555b5050505050505050505050565b600054610100900460ff16806123225750612322612142565b80612330575060005460ff16155b61236b5760405162461bcd60e51b815260040180806020018281038252602e8152602001806136ac602e913960400191505060405180910390fd5b600054610100900460ff16158015612396576000805460ff1961ff0019909116610100171660011790555b61239e612153565b6121e0612153565b600054610100900460ff16806123bf57506123bf612142565b806123cd575060005460ff16155b6124085760405162461bcd60e51b815260040180806020018281038252602e8152602001806136ac602e913960400191505060405180910390fd5b600054610100900460ff16158015612433576000805460ff1961ff0019909116610100171660011790555b61243b612153565b61129083836129c0565b600061067a826127a0565b60008261245f5750600061067a565b8282028284828161246c57fe5b04146108685760405162461bcd60e51b81526004018080602001828103825260218152602001806136da6021913960400191505060405180910390fd5b60008082116124ff576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b81838161250857fe5b049392505050565b61251b8383836112a2565b6001600160a01b03831661253f5761253282612a98565b61253a612ac2565b6112a2565b6001600160a01b0382166125565761253283612a98565b61255f83612a98565b6112a282612a98565b60606125bd826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612ad19092919063ffffffff16565b8051909150156112a2578080602001905160208110156125dc57600080fd5b50516112a25760405162461bcd60e51b815260040180806020018281038252602a81526020018061378d602a913960400191505060405180910390fd5b6001600160a01b03831661265e5760405162461bcd60e51b81526004018080602001828103825260258152602001806137446025913960400191505060405180910390fd5b6001600160a01b0382166126a35760405162461bcd60e51b815260040180806020018281038252602381526020018061357a6023913960400191505060405180910390fd5b6126ae838383612510565b6126eb81604051806060016040528060268152602001613630602691396001600160a01b0386166000908152603360205260409020549190611acd565b6001600160a01b03808516600090815260336020526040808220939093559084168152205461271a9082611758565b6001600160a01b0380841660008181526033602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b6000610868836001600160a01b038416612ae0565b6000610868836001600160a01b038416612b2a565b5490565b81546000906127b55750600061067a565b82546000905b808210156128045760006127cf8383612bf0565b9050848682815481106127de57fe5b906000526020600020015411156127f7578091506127fe565b8060010192505b506127bb565b60008211801561282c57508385600184038154811061281f57fe5b9060005260206000200154145b1561283d575060001901905061067a565b50905061067a565b6000831580612852575081155b80612865575042836001600160801b0316145b8061287b575060ca54836001600160801b031610155b15612887575083610d19565b600060ca544211612898574261289c565b60ca545b905060006128b3826001600160801b0387166117b2565b90506128d9876115c9866115cf670de0b6b3a76400006128d38c88612450565b90612450565b979650505050505050565b6000610d19670de0b6b3a76400006115cf6128ff86866117b2565b8790612450565b815460009082106129485760405162461bcd60e51b81526004018080602001828103825260228152602001806135586022913960400191505060405180910390fd5b82600001828154811061295757fe5b9060005260206000200154905092915050565b60009081526001919091016020526040902054151590565b3b151590565b6038805460ff191660ff92909216919091179055565b609780546001600160a01b0319166001600160a01b0392909216919091179055565b600054610100900460ff16806129d957506129d9612142565b806129e7575060005460ff16155b612a225760405162461bcd60e51b815260040180806020018281038252602e8152602001806136ac602e913960400191505060405180910390fd5b600054610100900460ff16158015612a4d576000805460ff1961ff0019909116610100171660011790555b8251612a60906036906020860190612e77565b508151612a74906037906020850190612e77565b506038805460ff1916601217905580156112a2576000805461ff0019169055505050565b6001600160a01b03811660009081526065602052604090206108c490612abd83610af7565b612c15565b612acf6066612abd610680565b565b6060610d198484600085612c61565b6000612aec838361296a565b612b225750815460018181018455600084815260208082209093018490558454848252828601909352604090209190915561067a565b50600061067a565b60008181526001830160205260408120548015612be65783546000198083019190810190600090879083908110612b5d57fe5b9060005260206000200154905080876000018481548110612b7a57fe5b600091825260208083209091019290925582815260018981019092526040902090840190558654879080612baa57fe5b6001900381819060005260206000200160009055905586600101600087815260200190815260200160002060009055600194505050505061067a565b600091505061067a565b60006002808306600285060181612c0357fe5b04600283046002850401019392505050565b6000612c2160686127a0565b905080612c2d84612db2565b10156112a2578254600180820185556000858152602080822090930193909355938401805494850181558252902090910155565b606082471015612ca25760405162461bcd60e51b81526004018080602001828103825260268152602001806136566026913960400191505060405180910390fd5b612cab85612982565b612cfc576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b60006060866001600160a01b031685876040518082805190602001908083835b60208310612d3b5780518252601f199092019160209182019101612d1c565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114612d9d576040519150601f19603f3d011682016040523d82523d6000602084013e612da2565b606091505b50915091506128d9828286612de7565b8054600090612dc357506000610882565b815482906000198101908110612dd557fe5b90600052602060002001549050610882565b60608315612df6575081610868565b825115612e065782518084602001fd5b60405162461bcd60e51b8152602060048201818152845160248401528451859391928392604401919085019080838360008315611b21578181015183820152602001611b09565b604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282612ead5760008555612ef3565b82601f10612ec657805160ff1916838001178555612ef3565b82800160010185558215612ef3579182015b82811115612ef3578251825591602001919060010190612ed8565b50612eff929150612f03565b5090565b5b80821115612eff5760008155600101612f04565b600082601f830112612f28578081fd5b813567ffffffffffffffff811115612f3c57fe5b612f4f601f8201601f191660200161351e565b9150808252836020828501011115612f6657600080fd5b8060208401602084013760009082016020015292915050565b600060608284031215612f90578081fd5b6040516060810181811067ffffffffffffffff82111715612fad57fe5b604052905080612fbc83612fe3565b8152602083013560208201526040830135612fd681613542565b6040919091015292915050565b80356001600160801b038116811461088257600080fd5b60006020828403121561300b578081fd5b813561086881613542565b60008060408385031215613028578081fd5b823561303381613542565b946020939093013593505050565b60008060408385031215613053578182fd5b823561305e81613542565b9150602083013561306e81613542565b809150509250929050565b60008060006060848603121561308d578081fd5b833561309881613542565b925060208401356130a881613542565b929592945050506040919091013590565b60008060408385031215613028578182fd5b600060208083850312156130dd578182fd5b823567ffffffffffffffff808211156130f4578384fd5b818501915085601f830112613107578384fd5b81358181111561311357fe5b613120848583020161351e565b81815284810192508385016060808402860187018a101561313f578788fd5b8795505b8386101561316b576131558a83612f7f565b8552600195909501949386019390810190613143565b509098975050505050505050565b60006020828403121561318a578081fd5b81518015158114610868578182fd5b6000602082840312156131aa578081fd5b5035919050565b600080604083850312156131c3578182fd5b82359150602083013561306e81613542565b600080604083850312156131e7578182fd5b50508035926020909101359150565b600080600080600080600060e0888a031215613210578283fd5b873561321b81613542565b9650602088013561322b81613542565b95506040880135945060608801359350608088013561324981613542565b925060a088013561325981613542565b915061326760c08901612fe3565b905092959891949750929550565b60008060408385031215613287578182fd5b823567ffffffffffffffff8082111561329e578384fd5b6132aa86838701612f18565b935060208501359150808211156132bf578283fd5b506132cc85828601612f18565b9150509250929050565b600080600080608085870312156132eb578182fd5b8435935060208501359250604085013561330481613542565b9396929550929360600135925050565b6001600160a01b0391909116815260200190565b6001600160a01b03929092168252602082015260400190565b901515815260200190565b90815260200190565b6000602080835283518082850152825b8181101561338157858101830151858201604001528201613365565b818111156133925783604083870101525b50601f01601f1916929092016040019392505050565b6020808252601390820152721253959053125117d6915493d7d05353d55395606a1b604082015260600190565b60208082526019908201527f4552524f525f5452414e534645525f46524f4d5f5641554c5400000000000000604082015260600190565b60208082526015908201527424a729aaa32324a1a4a2a72a2fa1a7a7a62227aba760591b604082015260600190565b60208082526015908201527427a7262cafa2a6a4a9a9a4a7a72fa6a0a720a3a2a960591b604082015260600190565b60208082526017908201527f554e5354414b455f57494e444f575f46494e4953484544000000000000000000604082015260600190565b6020808252601b908201527f494e56414c49445f42414c414e43455f4f4e5f434f4f4c444f574e0000000000604082015260600190565b6001600160801b0391909116815260200190565b6001600160801b039384168152919092166020820152604081019190915260600190565b60ff91909116815260200190565b60405181810167ffffffffffffffff8111828210171561353a57fe5b604052919050565b6001600160a01b03811681146108c457600080fdfe456e756d657261626c655365743a20696e646578206f7574206f6620626f756e647345524332303a207472616e7366657220746f20746865207a65726f2061646472657373416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e2061646d696e20746f206772616e7445524332303a206275726e20616d6f756e7420657863656564732062616c616e63650178ef1edee9408b9148e43c7402964baa5d7066a35d0ff56e2596c8e1dc0f6745524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e6365416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e2061646d696e20746f207265766f6b65496e697469616c697a61626c653a20636f6e747261637420697320616c726561647920696e697469616c697a6564536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7745524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f20616464726573735361666545524332303a204552433230206f7065726174696f6e20646964206e6f74207375636365656445524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636520726f6c657320666f722073656c66a264697066735822122057d3dc5dbb6fe69a62a27f8b764096c5963cc4f87460c590bc43565e9706fc0e64736f6c63430007050033

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
[ Download: CSV Export  ]

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.