creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"../utils/EnumerableSetUpgradeable.sol\";\nimport \"../utils/AddressUpgradeable.sol\";\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/Initializable.sol\";\n\n/**\n * @dev Contract module that allows children to implement role-based access\n * control mechanisms.\n *\n * Roles are referred to by their `bytes32` identifier. These should be exposed\n * in the external API and be unique. The best way to achieve this is by\n * using `public constant` hash digests:\n *\n * ```\n * bytes32 public constant MY_ROLE = keccak256(\"MY_ROLE\");\n * ```\n *\n * Roles can be used to represent a set of permissions. To restrict access to a\n * function call, use {hasRole}:\n *\n * ```\n * function foo() public {\n *     require(hasRole(MY_ROLE, msg.sender));\n *     ...\n * }\n * ```\n *\n * Roles can be granted and revoked dynamically via the {grantRole} and\n * {revokeRole} functions. Each role has an associated admin role, and only\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\n *\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\n * that only accounts with this role will be able to grant or revoke other\n * roles. More complex role relationships can be created by using\n * {_setRoleAdmin}.\n *\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\n * grant and revoke this role. Extra precautions should be taken to secure\n * accounts that have been granted it.\n */\nabstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable {\n    function __AccessControl_init() internal initializer {\n        __Context_init_unchained();\n        __AccessControl_init_unchained();\n    }\n\n    function __AccessControl_init_unchained() internal initializer {\n    }\n    using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet;\n    using AddressUpgradeable for address;\n\n    struct RoleData {\n        EnumerableSetUpgradeable.AddressSet members;\n        bytes32 adminRole;\n    }\n\n    mapping (bytes32 => RoleData) private _roles;\n\n    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\n\n    /**\n     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\n     *\n     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\n     * {RoleAdminChanged} not being emitted signaling this.\n     *\n     * _Available since v3.1._\n     */\n    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\n\n    /**\n     * @dev Emitted when `account` is granted `role`.\n     *\n     * `sender` is the account that originated the contract call, an admin role\n     * bearer except when using {_setupRole}.\n     */\n    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\n\n    /**\n     * @dev Emitted when `account` is revoked `role`.\n     *\n     * `sender` is the account that originated the contract call:\n     *   - if using `revokeRole`, it is the admin role bearer\n     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)\n     */\n    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\n\n    /**\n     * @dev Returns `true` if `account` has been granted `role`.\n     */\n    function hasRole(bytes32 role, address account) public view returns (bool) {\n        return _roles[role].members.contains(account);\n    }\n\n    /**\n     * @dev Returns the number of accounts that have `role`. Can be used\n     * together with {getRoleMember} to enumerate all bearers of a role.\n     */\n    function getRoleMemberCount(bytes32 role) public view returns (uint256) {\n        return _roles[role].members.length();\n    }\n\n    /**\n     * @dev Returns one of the accounts that have `role`. `index` must be a\n     * value between 0 and {getRoleMemberCount}, non-inclusive.\n     *\n     * Role bearers are not sorted in any particular way, and their ordering may\n     * change at any point.\n     *\n     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure\n     * you perform all queries on the same block. See the following\n     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]\n     * for more information.\n     */\n    function getRoleMember(bytes32 role, uint256 index) public view returns (address) {\n        return _roles[role].members.at(index);\n    }\n\n    /**\n     * @dev Returns the admin role that controls `role`. See {grantRole} and\n     * {revokeRole}.\n     *\n     * To change a role's admin, use {_setRoleAdmin}.\n     */\n    function getRoleAdmin(bytes32 role) public view returns (bytes32) {\n        return _roles[role].adminRole;\n    }\n\n    /**\n     * @dev Grants `role` to `account`.\n     *\n     * If `account` had not been already granted `role`, emits a {RoleGranted}\n     * event.\n     *\n     * Requirements:\n     *\n     * - the caller must have ``role``'s admin role.\n     */\n    function grantRole(bytes32 role, address account) public virtual {\n        require(hasRole(_roles[role].adminRole, _msgSender()), \"AccessControl: sender must be an admin to grant\");\n\n        _grantRole(role, account);\n    }\n\n    /**\n     * @dev Revokes `role` from `account`.\n     *\n     * If `account` had been granted `role`, emits a {RoleRevoked} event.\n     *\n     * Requirements:\n     *\n     * - the caller must have ``role``'s admin role.\n     */\n    function revokeRole(bytes32 role, address account) public virtual {\n        require(hasRole(_roles[role].adminRole, _msgSender()), \"AccessControl: sender must be an admin to revoke\");\n\n        _revokeRole(role, account);\n    }\n\n    /**\n     * @dev Revokes `role` from the calling account.\n     *\n     * Roles are often managed via {grantRole} and {revokeRole}: this function's\n     * purpose is to provide a mechanism for accounts to lose their privileges\n     * if they are compromised (such as when a trusted device is misplaced).\n     *\n     * If the calling account had been granted `role`, emits a {RoleRevoked}\n     * event.\n     *\n     * Requirements:\n     *\n     * - the caller must be `account`.\n     */\n    function renounceRole(bytes32 role, address account) public virtual {\n        require(account == _msgSender(), \"AccessControl: can only renounce roles for self\");\n\n        _revokeRole(role, account);\n    }\n\n    /**\n     * @dev Grants `role` to `account`.\n     *\n     * If `account` had not been already granted `role`, emits a {RoleGranted}\n     * event. Note that unlike {grantRole}, this function doesn't perform any\n     * checks on the calling account.\n     *\n     * [WARNING]\n     * ====\n     * This function should only be called from the constructor when setting\n     * up the initial roles for the system.\n     *\n     * Using this function in any other way is effectively circumventing the admin\n     * system imposed by {AccessControl}.\n     * ====\n     */\n    function _setupRole(bytes32 role, address account) internal virtual {\n        _grantRole(role, account);\n    }\n\n    /**\n     * @dev Sets `adminRole` as ``role``'s admin role.\n     *\n     * Emits a {RoleAdminChanged} event.\n     */\n    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\n        emit RoleAdminChanged(role, _roles[role].adminRole, adminRole);\n        _roles[role].adminRole = adminRole;\n    }\n\n    function _grantRole(bytes32 role, address account) private {\n        if (_roles[role].members.add(account)) {\n            emit RoleGranted(role, account, _msgSender());\n        }\n    }\n\n    function _revokeRole(bytes32 role, address account) private {\n        if (_roles[role].members.remove(account)) {\n            emit RoleRevoked(role, account, _msgSender());\n        }\n    }\n    uint256[49] private __gap;\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/Initializable.sol\";\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal initializer {\n        __Context_init_unchained();\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal initializer {\n        address msgSender = _msgSender();\n        _owner = msgSender;\n        emit OwnershipTransferred(address(0), msgSender);\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n        _;\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions anymore. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby removing any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        emit OwnershipTransferred(_owner, address(0));\n        _owner = address(0);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        emit OwnershipTransferred(_owner, newOwner);\n        _owner = newOwner;\n    }\n    uint256[49] private __gap;\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations with added overflow\n * checks.\n *\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\n * in bugs, because programmers usually assume that an overflow raises an\n * error, which is the standard behavior in high level programming languages.\n * `SafeMath` restores this intuition by reverting the transaction when an\n * operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeMathUpgradeable {\n    /**\n     * @dev Returns the addition of two unsigned integers, with an overflow flag.\n     *\n     * _Available since v3.4._\n     */\n    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        uint256 c = a + b;\n        if (c < a) return (false, 0);\n        return (true, c);\n    }\n\n    /**\n     * @dev Returns the substraction of two unsigned integers, with an overflow flag.\n     *\n     * _Available since v3.4._\n     */\n    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        if (b > a) return (false, 0);\n        return (true, a - b);\n    }\n\n    /**\n     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.\n     *\n     * _Available since v3.4._\n     */\n    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n        // benefit is lost if 'b' is also tested.\n        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n        if (a == 0) return (true, 0);\n        uint256 c = a * b;\n        if (c / a != b) return (false, 0);\n        return (true, c);\n    }\n\n    /**\n     * @dev Returns the division of two unsigned integers, with a division by zero flag.\n     *\n     * _Available since v3.4._\n     */\n    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        if (b == 0) return (false, 0);\n        return (true, a / b);\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.\n     *\n     * _Available since v3.4._\n     */\n    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        if (b == 0) return (false, 0);\n        return (true, a % b);\n    }\n\n    /**\n     * @dev Returns the addition of two unsigned integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity's `+` operator.\n     *\n     * Requirements:\n     *\n     * - Addition cannot overflow.\n     */\n    function add(uint256 a, uint256 b) internal pure returns (uint256) {\n        uint256 c = a + b;\n        require(c >= a, \"SafeMath: addition overflow\");\n        return c;\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, reverting on\n     * overflow (when the result is negative).\n     *\n     * Counterpart to Solidity's `-` operator.\n     *\n     * Requirements:\n     *\n     * - Subtraction cannot overflow.\n     */\n    function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n        require(b <= a, \"SafeMath: subtraction overflow\");\n        return a - b;\n    }\n\n    /**\n     * @dev Returns the multiplication of two unsigned integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity's `*` operator.\n     *\n     * Requirements:\n     *\n     * - Multiplication cannot overflow.\n     */\n    function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n        if (a == 0) return 0;\n        uint256 c = a * b;\n        require(c / a == b, \"SafeMath: multiplication overflow\");\n        return c;\n    }\n\n    /**\n     * @dev Returns the integer division of two unsigned integers, reverting on\n     * division by zero. The result is rounded towards zero.\n     *\n     * Counterpart to Solidity's `/` operator. Note: this function uses a\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\n     * uses an invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function div(uint256 a, uint256 b) internal pure returns (uint256) {\n        require(b > 0, \"SafeMath: division by zero\");\n        return a / b;\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n     * reverting when dividing by zero.\n     *\n     * Counterpart to Solidity's `%` operator. This function uses a `revert`\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\n     * invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n        require(b > 0, \"SafeMath: modulo by zero\");\n        return a % b;\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\n     * overflow (when the result is negative).\n     *\n     * CAUTION: This function is deprecated because it requires allocating memory for the error\n     * message unnecessarily. For custom revert reasons use {trySub}.\n     *\n     * Counterpart to Solidity's `-` operator.\n     *\n     * Requirements:\n     *\n     * - Subtraction cannot overflow.\n     */\n    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n        require(b <= a, errorMessage);\n        return a - b;\n    }\n\n    /**\n     * @dev Returns the integer division of two unsigned integers, reverting with custom message on\n     * division by zero. The result is rounded towards zero.\n     *\n     * CAUTION: This function is deprecated because it requires allocating memory for the error\n     * message unnecessarily. For custom revert reasons use {tryDiv}.\n     *\n     * Counterpart to Solidity's `/` operator. Note: this function uses a\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\n     * uses an invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n        require(b > 0, errorMessage);\n        return a / b;\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n     * reverting with custom message when dividing by zero.\n     *\n     * CAUTION: This function is deprecated because it requires allocating memory for the error\n     * message unnecessarily. For custom revert reasons use {tryMod}.\n     *\n     * Counterpart to Solidity's `%` operator. This function uses a `revert`\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\n     * invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n        require(b > 0, errorMessage);\n        return a % b;\n    }\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\n// solhint-disable-next-line compiler-version\npragma solidity >=0.4.24 <0.8.0;\n\nimport \"../utils/AddressUpgradeable.sol\";\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n */\nabstract contract Initializable {\n\n    /**\n     * @dev Indicates that the contract has been initialized.\n     */\n    bool private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Modifier to protect an initializer function from being invoked twice.\n     */\n    modifier initializer() {\n        require(_initializing || _isConstructor() || !_initialized, \"Initializable: contract is already initialized\");\n\n        bool isTopLevelCall = !_initializing;\n        if (isTopLevelCall) {\n            _initializing = true;\n            _initialized = true;\n        }\n\n        _;\n\n        if (isTopLevelCall) {\n            _initializing = false;\n        }\n    }\n\n    /// @dev Returns true if and only if the function is running in the constructor\n    function _isConstructor() private view returns (bool) {\n        return !AddressUpgradeable.isContract(address(this));\n    }\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"../../utils/ContextUpgradeable.sol\";\nimport \"./IERC20Upgradeable.sol\";\nimport \"../../math/SafeMathUpgradeable.sol\";\nimport \"../../proxy/Initializable.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * We have followed general OpenZeppelin guidelines: functions revert instead\n * of returning `false` on failure. This behavior is nonetheless conventional\n * and does not conflict with the expectations of ERC20 applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable {\n    using SafeMathUpgradeable for uint256;\n\n    mapping (address => uint256) private _balances;\n\n    mapping (address => mapping (address => uint256)) private _allowances;\n\n    uint256 private _totalSupply;\n\n    string private _name;\n    string private _symbol;\n    uint8 private _decimals;\n\n    /**\n     * @dev Sets the values for {name} and {symbol}, initializes {decimals} with\n     * a default value of 18.\n     *\n     * To select a different value for {decimals}, use {_setupDecimals}.\n     *\n     * All three of these values are immutable: they can only be set once during\n     * construction.\n     */\n    function __ERC20_init(string memory name_, string memory symbol_) internal initializer {\n        __Context_init_unchained();\n        __ERC20_init_unchained(name_, symbol_);\n    }\n\n    function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer {\n        _name = name_;\n        _symbol = symbol_;\n        _decimals = 18;\n    }\n\n    /**\n     * @dev Returns the name of the token.\n     */\n    function name() public view virtual returns (string memory) {\n        return _name;\n    }\n\n    /**\n     * @dev Returns the symbol of the token, usually a shorter version of the\n     * name.\n     */\n    function symbol() public view virtual returns (string memory) {\n        return _symbol;\n    }\n\n    /**\n     * @dev Returns the number of decimals used to get its user representation.\n     * For example, if `decimals` equals `2`, a balance of `505` tokens should\n     * be displayed to a user as `5,05` (`505 / 10 ** 2`).\n     *\n     * Tokens usually opt for a value of 18, imitating the relationship between\n     * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is\n     * called.\n     *\n     * NOTE: This information is only used for _display_ purposes: it in\n     * no way affects any of the arithmetic of the contract, including\n     * {IERC20-balanceOf} and {IERC20-transfer}.\n     */\n    function decimals() public view virtual returns (uint8) {\n        return _decimals;\n    }\n\n    /**\n     * @dev See {IERC20-totalSupply}.\n     */\n    function totalSupply() public view virtual override returns (uint256) {\n        return _totalSupply;\n    }\n\n    /**\n     * @dev See {IERC20-balanceOf}.\n     */\n    function balanceOf(address account) public view virtual override returns (uint256) {\n        return _balances[account];\n    }\n\n    /**\n     * @dev See {IERC20-transfer}.\n     *\n     * Requirements:\n     *\n     * - `recipient` cannot be the zero address.\n     * - the caller must have a balance of at least `amount`.\n     */\n    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {\n        _transfer(_msgSender(), recipient, amount);\n        return true;\n    }\n\n    /**\n     * @dev See {IERC20-allowance}.\n     */\n    function allowance(address owner, address spender) public view virtual override returns (uint256) {\n        return _allowances[owner][spender];\n    }\n\n    /**\n     * @dev See {IERC20-approve}.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     */\n    function approve(address spender, uint256 amount) public virtual override returns (bool) {\n        _approve(_msgSender(), spender, amount);\n        return true;\n    }\n\n    /**\n     * @dev See {IERC20-transferFrom}.\n     *\n     * Emits an {Approval} event indicating the updated allowance. This is not\n     * required by the EIP. See the note at the beginning of {ERC20}.\n     *\n     * Requirements:\n     *\n     * - `sender` and `recipient` cannot be the zero address.\n     * - `sender` must have a balance of at least `amount`.\n     * - the caller must have allowance for ``sender``'s tokens of at least\n     * `amount`.\n     */\n    function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {\n        _transfer(sender, recipient, amount);\n        _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, \"ERC20: transfer amount exceeds allowance\"));\n        return true;\n    }\n\n    /**\n     * @dev Atomically increases the allowance granted to `spender` by the caller.\n     *\n     * This is an alternative to {approve} that can be used as a mitigation for\n     * problems described in {IERC20-approve}.\n     *\n     * Emits an {Approval} event indicating the updated allowance.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     */\n    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));\n        return true;\n    }\n\n    /**\n     * @dev Atomically decreases the allowance granted to `spender` by the caller.\n     *\n     * This is an alternative to {approve} that can be used as a mitigation for\n     * problems described in {IERC20-approve}.\n     *\n     * Emits an {Approval} event indicating the updated allowance.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     * - `spender` must have allowance for the caller of at least\n     * `subtractedValue`.\n     */\n    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, \"ERC20: decreased allowance below zero\"));\n        return true;\n    }\n\n    /**\n     * @dev Moves tokens `amount` from `sender` to `recipient`.\n     *\n     * This is internal function is equivalent to {transfer}, and can be used to\n     * e.g. implement automatic token fees, slashing mechanisms, etc.\n     *\n     * Emits a {Transfer} event.\n     *\n     * Requirements:\n     *\n     * - `sender` cannot be the zero address.\n     * - `recipient` cannot be the zero address.\n     * - `sender` must have a balance of at least `amount`.\n     */\n    function _transfer(address sender, address recipient, uint256 amount) internal virtual {\n        require(sender != address(0), \"ERC20: transfer from the zero address\");\n        require(recipient != address(0), \"ERC20: transfer to the zero address\");\n\n        _beforeTokenTransfer(sender, recipient, amount);\n\n        _balances[sender] = _balances[sender].sub(amount, \"ERC20: transfer amount exceeds balance\");\n        _balances[recipient] = _balances[recipient].add(amount);\n        emit Transfer(sender, recipient, amount);\n    }\n\n    /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n     * the total supply.\n     *\n     * Emits a {Transfer} event with `from` set to the zero address.\n     *\n     * Requirements:\n     *\n     * - `to` cannot be the zero address.\n     */\n    function _mint(address account, uint256 amount) internal virtual {\n        require(account != address(0), \"ERC20: mint to the zero address\");\n\n        _beforeTokenTransfer(address(0), account, amount);\n\n        _totalSupply = _totalSupply.add(amount);\n        _balances[account] = _balances[account].add(amount);\n        emit Transfer(address(0), account, amount);\n    }\n\n    /**\n     * @dev Destroys `amount` tokens from `account`, reducing the\n     * total supply.\n     *\n     * Emits a {Transfer} event with `to` set to the zero address.\n     *\n     * Requirements:\n     *\n     * - `account` cannot be the zero address.\n     * - `account` must have at least `amount` tokens.\n     */\n    function _burn(address account, uint256 amount) internal virtual {\n        require(account != address(0), \"ERC20: burn from the zero address\");\n\n        _beforeTokenTransfer(account, address(0), amount);\n\n        _balances[account] = _balances[account].sub(amount, \"ERC20: burn amount exceeds balance\");\n        _totalSupply = _totalSupply.sub(amount);\n        emit Transfer(account, address(0), amount);\n    }\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n     *\n     * This internal function is equivalent to `approve`, and can be used to\n     * e.g. set automatic allowances for certain subsystems, etc.\n     *\n     * Emits an {Approval} event.\n     *\n     * Requirements:\n     *\n     * - `owner` cannot be the zero address.\n     * - `spender` cannot be the zero address.\n     */\n    function _approve(address owner, address spender, uint256 amount) internal virtual {\n        require(owner != address(0), \"ERC20: approve from the zero address\");\n        require(spender != address(0), \"ERC20: approve to the zero address\");\n\n        _allowances[owner][spender] = amount;\n        emit Approval(owner, spender, amount);\n    }\n\n    /**\n     * @dev Sets {decimals} to a value other than the default one of 18.\n     *\n     * WARNING: This function should only be called from the constructor. Most\n     * applications that interact with token contracts will not expect\n     * {decimals} to ever change, and may work incorrectly if it does.\n     */\n    function _setupDecimals(uint8 decimals_) internal virtual {\n        _decimals = decimals_;\n    }\n\n    /**\n     * @dev Hook that is called before any transfer of tokens. This includes\n     * minting and burning.\n     *\n     * Calling conditions:\n     *\n     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n     * will be to transferred to `to`.\n     * - when `from` is zero, `amount` tokens will be minted for `to`.\n     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n     * - `from` and `to` are never both zero.\n     *\n     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n     */\n    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }\n    uint256[44] private __gap;\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20Upgradeable {\n    /**\n     * @dev Returns the amount of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the amount of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves `amount` tokens from the caller's account to `recipient`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address recipient, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender's allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Moves `amount` tokens from `sender` to `recipient` using the\n     * allowance mechanism. `amount` is then deducted from the caller's\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/token/ERC20/SafeERC20Upgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"./IERC20Upgradeable.sol\";\nimport \"../../math/SafeMathUpgradeable.sol\";\nimport \"../../utils/AddressUpgradeable.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20Upgradeable {\n    using SafeMathUpgradeable for uint256;\n    using AddressUpgradeable for address;\n\n    function safeTransfer(IERC20Upgradeable token, address to, uint256 value) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n    }\n\n    function safeTransferFrom(IERC20Upgradeable token, address from, address to, uint256 value) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n    }\n\n    /**\n     * @dev Deprecated. This function has issues similar to the ones found in\n     * {IERC20-approve}, and its usage is discouraged.\n     *\n     * Whenever possible, use {safeIncreaseAllowance} and\n     * {safeDecreaseAllowance} instead.\n     */\n    function safeApprove(IERC20Upgradeable token, address spender, uint256 value) internal {\n        // safeApprove should only be called when setting an initial allowance,\n        // or when resetting it to zero. To increase and decrease it, use\n        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\n        // solhint-disable-next-line max-line-length\n        require((value == 0) || (token.allowance(address(this), spender) == 0),\n            \"SafeERC20: approve from non-zero to non-zero allowance\"\n        );\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n    }\n\n    function safeIncreaseAllowance(IERC20Upgradeable token, address spender, uint256 value) internal {\n        uint256 newAllowance = token.allowance(address(this), spender).add(value);\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n    }\n\n    function safeDecreaseAllowance(IERC20Upgradeable token, address spender, uint256 value) internal {\n        uint256 newAllowance = token.allowance(address(this), spender).sub(value, \"SafeERC20: decreased allowance below zero\");\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n    }\n\n    /**\n     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n     * on the return value: the return value is optional (but if data is returned, it must not be false).\n     * @param token The token targeted by the call.\n     * @param data The call data (encoded using abi.encode or one of its variants).\n     */\n    function _callOptionalReturn(IERC20Upgradeable token, bytes memory data) private {\n        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that\n        // the target address contains contract code and also asserts for success in the low-level call.\n\n        bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n        if (returndata.length > 0) { // Return data is optional\n            // solhint-disable-next-line max-line-length\n            require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n        }\n    }\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.2 <0.8.0;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize, which returns 0 for contracts in\n        // construction, since the code is only stored at the end of the\n        // constructor execution.\n\n        uint256 size;\n        // solhint-disable-next-line no-inline-assembly\n        assembly { size := extcodesize(account) }\n        return size > 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value\n        (bool success, ) = recipient.call{ value: amount }(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain`call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n      return functionCall(target, data, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {\n        require(address(this).balance >= value, \"Address: insufficient balance for call\");\n        require(isContract(target), \"Address: call to non-contract\");\n\n        // solhint-disable-next-line avoid-low-level-calls\n        (bool success, bytes memory returndata) = target.call{ value: value }(data);\n        return _verifyCallResult(success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {\n        require(isContract(target), \"Address: static call to non-contract\");\n\n        // solhint-disable-next-line avoid-low-level-calls\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return _verifyCallResult(success, returndata, errorMessage);\n    }\n\n    function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            // Look for revert reason and bubble it up if present\n            if (returndata.length > 0) {\n                // The easiest way to bubble the revert reason is using memory via assembly\n\n                // solhint-disable-next-line no-inline-assembly\n                assembly {\n                    let returndata_size := mload(returndata)\n                    revert(add(32, returndata), returndata_size)\n                }\n            } else {\n                revert(errorMessage);\n            }\n        }\n    }\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\nimport \"../proxy/Initializable.sol\";\n\n/*\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with GSN meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal initializer {\n        __Context_init_unchained();\n    }\n\n    function __Context_init_unchained() internal initializer {\n    }\n    function _msgSender() internal view virtual returns (address payable) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes memory) {\n        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691\n        return msg.data;\n    }\n    uint256[50] private __gap;\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/utils/EnumerableSetUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev Library for managing\n * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive\n * types.\n *\n * Sets have the following properties:\n *\n * - Elements are added, removed, and checked for existence in constant time\n * (O(1)).\n * - Elements are enumerated in O(n). No guarantees are made on the ordering.\n *\n * ```\n * contract Example {\n *     // Add the library methods\n *     using EnumerableSet for EnumerableSet.AddressSet;\n *\n *     // Declare a set state variable\n *     EnumerableSet.AddressSet private mySet;\n * }\n * ```\n *\n * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)\n * and `uint256` (`UintSet`) are supported.\n */\nlibrary EnumerableSetUpgradeable {\n    // To implement this library for multiple types with as little code\n    // repetition as possible, we write it in terms of a generic Set type with\n    // bytes32 values.\n    // The Set implementation uses private functions, and user-facing\n    // implementations (such as AddressSet) are just wrappers around the\n    // underlying Set.\n    // This means that we can only create new EnumerableSets for types that fit\n    // in bytes32.\n\n    struct Set {\n        // Storage of set values\n        bytes32[] _values;\n\n        // Position of the value in the `values` array, plus 1 because index 0\n        // means a value is not in the set.\n        mapping (bytes32 => uint256) _indexes;\n    }\n\n    /**\n     * @dev Add a value to a set. O(1).\n     *\n     * Returns true if the value was added to the set, that is if it was not\n     * already present.\n     */\n    function _add(Set storage set, bytes32 value) private returns (bool) {\n        if (!_contains(set, value)) {\n            set._values.push(value);\n            // The value is stored at length-1, but we add 1 to all indexes\n            // and use 0 as a sentinel value\n            set._indexes[value] = set._values.length;\n            return true;\n        } else {\n            return false;\n        }\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the value was removed from the set, that is if it was\n     * present.\n     */\n    function _remove(Set storage set, bytes32 value) private returns (bool) {\n        // We read and store the value's index to prevent multiple reads from the same storage slot\n        uint256 valueIndex = set._indexes[value];\n\n        if (valueIndex != 0) { // Equivalent to contains(set, value)\n            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in\n            // the array, and then remove the last element (sometimes called as 'swap and pop').\n            // This modifies the order of the array, as noted in {at}.\n\n            uint256 toDeleteIndex = valueIndex - 1;\n            uint256 lastIndex = set._values.length - 1;\n\n            // When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs\n            // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.\n\n            bytes32 lastvalue = set._values[lastIndex];\n\n            // Move the last value to the index where the value to delete is\n            set._values[toDeleteIndex] = lastvalue;\n            // Update the index for the moved value\n            set._indexes[lastvalue] = toDeleteIndex + 1; // All indexes are 1-based\n\n            // Delete the slot where the moved value was stored\n            set._values.pop();\n\n            // Delete the index for the deleted slot\n            delete set._indexes[value];\n\n            return true;\n        } else {\n            return false;\n        }\n    }\n\n    /**\n     * @dev Returns true if the value is in the set. O(1).\n     */\n    function _contains(Set storage set, bytes32 value) private view returns (bool) {\n        return set._indexes[value] != 0;\n    }\n\n    /**\n     * @dev Returns the number of values on the set. O(1).\n     */\n    function _length(Set storage set) private view returns (uint256) {\n        return set._values.length;\n    }\n\n   /**\n    * @dev Returns the value stored at position `index` in the set. O(1).\n    *\n    * Note that there are no guarantees on the ordering of values inside the\n    * array, and it may change when more values are added or removed.\n    *\n    * Requirements:\n    *\n    * - `index` must be strictly less than {length}.\n    */\n    function _at(Set storage set, uint256 index) private view returns (bytes32) {\n        require(set._values.length > index, \"EnumerableSet: index out of bounds\");\n        return set._values[index];\n    }\n\n    // Bytes32Set\n\n    struct Bytes32Set {\n        Set _inner;\n    }\n\n    /**\n     * @dev Add a value to a set. O(1).\n     *\n     * Returns true if the value was added to the set, that is if it was not\n     * already present.\n     */\n    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n        return _add(set._inner, value);\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the value was removed from the set, that is if it was\n     * present.\n     */\n    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n        return _remove(set._inner, value);\n    }\n\n    /**\n     * @dev Returns true if the value is in the set. O(1).\n     */\n    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {\n        return _contains(set._inner, value);\n    }\n\n    /**\n     * @dev Returns the number of values in the set. O(1).\n     */\n    function length(Bytes32Set storage set) internal view returns (uint256) {\n        return _length(set._inner);\n    }\n\n   /**\n    * @dev Returns the value stored at position `index` in the set. O(1).\n    *\n    * Note that there are no guarantees on the ordering of values inside the\n    * array, and it may change when more values are added or removed.\n    *\n    * Requirements:\n    *\n    * - `index` must be strictly less than {length}.\n    */\n    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {\n        return _at(set._inner, index);\n    }\n\n    // AddressSet\n\n    struct AddressSet {\n        Set _inner;\n    }\n\n    /**\n     * @dev Add a value to a set. O(1).\n     *\n     * Returns true if the value was added to the set, that is if it was not\n     * already present.\n     */\n    function add(AddressSet storage set, address value) internal returns (bool) {\n        return _add(set._inner, bytes32(uint256(uint160(value))));\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the value was removed from the set, that is if it was\n     * present.\n     */\n    function remove(AddressSet storage set, address value) internal returns (bool) {\n        return _remove(set._inner, bytes32(uint256(uint160(value))));\n    }\n\n    /**\n     * @dev Returns true if the value is in the set. O(1).\n     */\n    function contains(AddressSet storage set, address value) internal view returns (bool) {\n        return _contains(set._inner, bytes32(uint256(uint160(value))));\n    }\n\n    /**\n     * @dev Returns the number of values in the set. O(1).\n     */\n    function length(AddressSet storage set) internal view returns (uint256) {\n        return _length(set._inner);\n    }\n\n   /**\n    * @dev Returns the value stored at position `index` in the set. O(1).\n    *\n    * Note that there are no guarantees on the ordering of values inside the\n    * array, and it may change when more values are added or removed.\n    *\n    * Requirements:\n    *\n    * - `index` must be strictly less than {length}.\n    */\n    function at(AddressSet storage set, uint256 index) internal view returns (address) {\n        return address(uint160(uint256(_at(set._inner, index))));\n    }\n\n\n    // UintSet\n\n    struct UintSet {\n        Set _inner;\n    }\n\n    /**\n     * @dev Add a value to a set. O(1).\n     *\n     * Returns true if the value was added to the set, that is if it was not\n     * already present.\n     */\n    function add(UintSet storage set, uint256 value) internal returns (bool) {\n        return _add(set._inner, bytes32(value));\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the value was removed from the set, that is if it was\n     * present.\n     */\n    function remove(UintSet storage set, uint256 value) internal returns (bool) {\n        return _remove(set._inner, bytes32(value));\n    }\n\n    /**\n     * @dev Returns true if the value is in the set. O(1).\n     */\n    function contains(UintSet storage set, uint256 value) internal view returns (bool) {\n        return _contains(set._inner, bytes32(value));\n    }\n\n    /**\n     * @dev Returns the number of values on the set. O(1).\n     */\n    function length(UintSet storage set) internal view returns (uint256) {\n        return _length(set._inner);\n    }\n\n   /**\n    * @dev Returns the value stored at position `index` in the set. O(1).\n    *\n    * Note that there are no guarantees on the ordering of values inside the\n    * array, and it may change when more values are added or removed.\n    *\n    * Requirements:\n    *\n    * - `index` must be strictly less than {length}.\n    */\n    function at(UintSet storage set, uint256 index) internal view returns (uint256) {\n        return uint256(_at(set._inner, index));\n    }\n}\n"
      },
      "@openzeppelin/contracts/access/Ownable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"../utils/Context.sol\";\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    constructor () internal {\n        address msgSender = _msgSender();\n        _owner = msgSender;\n        emit OwnershipTransferred(address(0), msgSender);\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n        _;\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions anymore. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby removing any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        emit OwnershipTransferred(_owner, address(0));\n        _owner = address(0);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        emit OwnershipTransferred(_owner, newOwner);\n        _owner = newOwner;\n    }\n}\n"
      },
      "@openzeppelin/contracts/proxy/Proxy.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM\n * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to\n * be specified by overriding the virtual {_implementation} function.\n *\n * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a\n * different contract through the {_delegate} function.\n *\n * The success and return data of the delegated call will be returned back to the caller of the proxy.\n */\nabstract contract Proxy {\n    /**\n     * @dev Delegates the current call to `implementation`.\n     *\n     * This function does not return to its internall call site, it will return directly to the external caller.\n     */\n    function _delegate(address implementation) internal virtual {\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Copy msg.data. We take full control of memory in this inline assembly\n            // block because it will not return to Solidity code. We overwrite the\n            // Solidity scratch pad at memory position 0.\n            calldatacopy(0, 0, calldatasize())\n\n            // Call the implementation.\n            // out and outsize are 0 because we don't know the size yet.\n            let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)\n\n            // Copy the returned data.\n            returndatacopy(0, 0, returndatasize())\n\n            switch result\n            // delegatecall returns 0 on error.\n            case 0 { revert(0, returndatasize()) }\n            default { return(0, returndatasize()) }\n        }\n    }\n\n    /**\n     * @dev This is a virtual function that should be overriden so it returns the address to which the fallback function\n     * and {_fallback} should delegate.\n     */\n    function _implementation() internal view virtual returns (address);\n\n    /**\n     * @dev Delegates the current call to the address returned by `_implementation()`.\n     *\n     * This function does not return to its internall call site, it will return directly to the external caller.\n     */\n    function _fallback() internal virtual {\n        _beforeFallback();\n        _delegate(_implementation());\n    }\n\n    /**\n     * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other\n     * function in the contract matches the call data.\n     */\n    fallback () external payable virtual {\n        _fallback();\n    }\n\n    /**\n     * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data\n     * is empty.\n     */\n    receive () external payable virtual {\n        _fallback();\n    }\n\n    /**\n     * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback`\n     * call, or as part of the Solidity `fallback` or `receive` functions.\n     *\n     * If overriden should call `super._beforeFallback()`.\n     */\n    function _beforeFallback() internal virtual {\n    }\n}\n"
      },
      "@openzeppelin/contracts/proxy/ProxyAdmin.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"../access/Ownable.sol\";\nimport \"./TransparentUpgradeableProxy.sol\";\n\n/**\n * @dev This is an auxiliary contract meant to be assigned as the admin of a {TransparentUpgradeableProxy}. For an\n * explanation of why you would want to use this see the documentation for {TransparentUpgradeableProxy}.\n */\ncontract ProxyAdmin is Ownable {\n\n    /**\n     * @dev Returns the current implementation of `proxy`.\n     *\n     * Requirements:\n     *\n     * - This contract must be the admin of `proxy`.\n     */\n    function getProxyImplementation(TransparentUpgradeableProxy proxy) public view virtual returns (address) {\n        // We need to manually run the static call since the getter cannot be flagged as view\n        // bytes4(keccak256(\"implementation()\")) == 0x5c60da1b\n        (bool success, bytes memory returndata) = address(proxy).staticcall(hex\"5c60da1b\");\n        require(success);\n        return abi.decode(returndata, (address));\n    }\n\n    /**\n     * @dev Returns the current admin of `proxy`.\n     *\n     * Requirements:\n     *\n     * - This contract must be the admin of `proxy`.\n     */\n    function getProxyAdmin(TransparentUpgradeableProxy proxy) public view virtual returns (address) {\n        // We need to manually run the static call since the getter cannot be flagged as view\n        // bytes4(keccak256(\"admin()\")) == 0xf851a440\n        (bool success, bytes memory returndata) = address(proxy).staticcall(hex\"f851a440\");\n        require(success);\n        return abi.decode(returndata, (address));\n    }\n\n    /**\n     * @dev Changes the admin of `proxy` to `newAdmin`.\n     *\n     * Requirements:\n     *\n     * - This contract must be the current admin of `proxy`.\n     */\n    function changeProxyAdmin(TransparentUpgradeableProxy proxy, address newAdmin) public virtual onlyOwner {\n        proxy.changeAdmin(newAdmin);\n    }\n\n    /**\n     * @dev Upgrades `proxy` to `implementation`. See {TransparentUpgradeableProxy-upgradeTo}.\n     *\n     * Requirements:\n     *\n     * - This contract must be the admin of `proxy`.\n     */\n    function upgrade(TransparentUpgradeableProxy proxy, address implementation) public virtual onlyOwner {\n        proxy.upgradeTo(implementation);\n    }\n\n    /**\n     * @dev Upgrades `proxy` to `implementation` and calls a function on the new implementation. See\n     * {TransparentUpgradeableProxy-upgradeToAndCall}.\n     *\n     * Requirements:\n     *\n     * - This contract must be the admin of `proxy`.\n     */\n    function upgradeAndCall(TransparentUpgradeableProxy proxy, address implementation, bytes memory data) public payable virtual onlyOwner {\n        proxy.upgradeToAndCall{value: msg.value}(implementation, data);\n    }\n}\n"
      },
      "@openzeppelin/contracts/proxy/TransparentUpgradeableProxy.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"./UpgradeableProxy.sol\";\n\n/**\n * @dev This contract implements a proxy that is upgradeable by an admin.\n *\n * To avoid https://medium.com/nomic-labs-blog/malicious-backdoors-in-ethereum-proxies-62629adf3357[proxy selector\n * clashing], which can potentially be used in an attack, this contract uses the\n * https://blog.openzeppelin.com/the-transparent-proxy-pattern/[transparent proxy pattern]. This pattern implies two\n * things that go hand in hand:\n *\n * 1. If any account other than the admin calls the proxy, the call will be forwarded to the implementation, even if\n * that call matches one of the admin functions exposed by the proxy itself.\n * 2. If the admin calls the proxy, it can access the admin functions, but its calls will never be forwarded to the\n * implementation. If the admin tries to call a function on the implementation it will fail with an error that says\n * \"admin cannot fallback to proxy target\".\n *\n * These properties mean that the admin account can only be used for admin actions like upgrading the proxy or changing\n * the admin, so it's best if it's a dedicated account that is not used for anything else. This will avoid headaches due\n * to sudden errors when trying to call a function from the proxy implementation.\n *\n * Our recommendation is for the dedicated account to be an instance of the {ProxyAdmin} contract. If set up this way,\n * you should think of the `ProxyAdmin` instance as the real administrative interface of your proxy.\n */\ncontract TransparentUpgradeableProxy is UpgradeableProxy {\n    /**\n     * @dev Initializes an upgradeable proxy managed by `_admin`, backed by the implementation at `_logic`, and\n     * optionally initialized with `_data` as explained in {UpgradeableProxy-constructor}.\n     */\n    constructor(address _logic, address admin_, bytes memory _data) public payable UpgradeableProxy(_logic, _data) {\n        assert(_ADMIN_SLOT == bytes32(uint256(keccak256(\"eip1967.proxy.admin\")) - 1));\n        _setAdmin(admin_);\n    }\n\n    /**\n     * @dev Emitted when the admin account has changed.\n     */\n    event AdminChanged(address previousAdmin, address newAdmin);\n\n    /**\n     * @dev Storage slot with the admin of the contract.\n     * This is the keccak-256 hash of \"eip1967.proxy.admin\" subtracted by 1, and is\n     * validated in the constructor.\n     */\n    bytes32 private constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;\n\n    /**\n     * @dev Modifier used internally that will delegate the call to the implementation unless the sender is the admin.\n     */\n    modifier ifAdmin() {\n        if (msg.sender == _admin()) {\n            _;\n        } else {\n            _fallback();\n        }\n    }\n\n    /**\n     * @dev Returns the current admin.\n     *\n     * NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyAdmin}.\n     *\n     * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the\n     * https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.\n     * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`\n     */\n    function admin() external ifAdmin returns (address admin_) {\n        admin_ = _admin();\n    }\n\n    /**\n     * @dev Returns the current implementation.\n     *\n     * NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyImplementation}.\n     *\n     * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the\n     * https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.\n     * `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc`\n     */\n    function implementation() external ifAdmin returns (address implementation_) {\n        implementation_ = _implementation();\n    }\n\n    /**\n     * @dev Changes the admin of the proxy.\n     *\n     * Emits an {AdminChanged} event.\n     *\n     * NOTE: Only the admin can call this function. See {ProxyAdmin-changeProxyAdmin}.\n     */\n    function changeAdmin(address newAdmin) external virtual ifAdmin {\n        require(newAdmin != address(0), \"TransparentUpgradeableProxy: new admin is the zero address\");\n        emit AdminChanged(_admin(), newAdmin);\n        _setAdmin(newAdmin);\n    }\n\n    /**\n     * @dev Upgrade the implementation of the proxy.\n     *\n     * NOTE: Only the admin can call this function. See {ProxyAdmin-upgrade}.\n     */\n    function upgradeTo(address newImplementation) external virtual ifAdmin {\n        _upgradeTo(newImplementation);\n    }\n\n    /**\n     * @dev Upgrade the implementation of the proxy, and then call a function from the new implementation as specified\n     * by `data`, which should be an encoded function call. This is useful to initialize new storage variables in the\n     * proxied contract.\n     *\n     * NOTE: Only the admin can call this function. See {ProxyAdmin-upgradeAndCall}.\n     */\n    function upgradeToAndCall(address newImplementation, bytes calldata data) external payable virtual ifAdmin {\n        _upgradeTo(newImplementation);\n        Address.functionDelegateCall(newImplementation, data);\n    }\n\n    /**\n     * @dev Returns the current admin.\n     */\n    function _admin() internal view virtual returns (address adm) {\n        bytes32 slot = _ADMIN_SLOT;\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            adm := sload(slot)\n        }\n    }\n\n    /**\n     * @dev Stores a new address in the EIP1967 admin slot.\n     */\n    function _setAdmin(address newAdmin) private {\n        bytes32 slot = _ADMIN_SLOT;\n\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            sstore(slot, newAdmin)\n        }\n    }\n\n    /**\n     * @dev Makes sure the admin cannot access the fallback function. See {Proxy-_beforeFallback}.\n     */\n    function _beforeFallback() internal virtual override {\n        require(msg.sender != _admin(), \"TransparentUpgradeableProxy: admin cannot fallback to proxy target\");\n        super._beforeFallback();\n    }\n}\n"
      },
      "@openzeppelin/contracts/proxy/UpgradeableProxy.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"./Proxy.sol\";\nimport \"../utils/Address.sol\";\n\n/**\n * @dev This contract implements an upgradeable proxy. It is upgradeable because calls are delegated to an\n * implementation address that can be changed. This address is stored in storage in the location specified by\n * https://eips.ethereum.org/EIPS/eip-1967[EIP1967], so that it doesn't conflict with the storage layout of the\n * implementation behind the proxy.\n *\n * Upgradeability is only provided internally through {_upgradeTo}. For an externally upgradeable proxy see\n * {TransparentUpgradeableProxy}.\n */\ncontract UpgradeableProxy is Proxy {\n    /**\n     * @dev Initializes the upgradeable proxy with an initial implementation specified by `_logic`.\n     *\n     * If `_data` is nonempty, it's used as data in a delegate call to `_logic`. This will typically be an encoded\n     * function call, and allows initializating the storage of the proxy like a Solidity constructor.\n     */\n    constructor(address _logic, bytes memory _data) public payable {\n        assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256(\"eip1967.proxy.implementation\")) - 1));\n        _setImplementation(_logic);\n        if(_data.length > 0) {\n            Address.functionDelegateCall(_logic, _data);\n        }\n    }\n\n    /**\n     * @dev Emitted when the implementation is upgraded.\n     */\n    event Upgraded(address indexed implementation);\n\n    /**\n     * @dev Storage slot with the address of the current implementation.\n     * This is the keccak-256 hash of \"eip1967.proxy.implementation\" subtracted by 1, and is\n     * validated in the constructor.\n     */\n    bytes32 private constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n\n    /**\n     * @dev Returns the current implementation address.\n     */\n    function _implementation() internal view virtual override returns (address impl) {\n        bytes32 slot = _IMPLEMENTATION_SLOT;\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            impl := sload(slot)\n        }\n    }\n\n    /**\n     * @dev Upgrades the proxy to a new implementation.\n     *\n     * Emits an {Upgraded} event.\n     */\n    function _upgradeTo(address newImplementation) internal virtual {\n        _setImplementation(newImplementation);\n        emit Upgraded(newImplementation);\n    }\n\n    /**\n     * @dev Stores a new address in the EIP1967 implementation slot.\n     */\n    function _setImplementation(address newImplementation) private {\n        require(Address.isContract(newImplementation), \"UpgradeableProxy: new implementation is not a contract\");\n\n        bytes32 slot = _IMPLEMENTATION_SLOT;\n\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            sstore(slot, newImplementation)\n        }\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/Address.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.2 <0.8.0;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize, which returns 0 for contracts in\n        // construction, since the code is only stored at the end of the\n        // constructor execution.\n\n        uint256 size;\n        // solhint-disable-next-line no-inline-assembly\n        assembly { size := extcodesize(account) }\n        return size > 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value\n        (bool success, ) = recipient.call{ value: amount }(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain`call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n      return functionCall(target, data, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {\n        require(address(this).balance >= value, \"Address: insufficient balance for call\");\n        require(isContract(target), \"Address: call to non-contract\");\n\n        // solhint-disable-next-line avoid-low-level-calls\n        (bool success, bytes memory returndata) = target.call{ value: value }(data);\n        return _verifyCallResult(success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {\n        require(isContract(target), \"Address: static call to non-contract\");\n\n        // solhint-disable-next-line avoid-low-level-calls\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return _verifyCallResult(success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {\n        require(isContract(target), \"Address: delegate call to non-contract\");\n\n        // solhint-disable-next-line avoid-low-level-calls\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return _verifyCallResult(success, returndata, errorMessage);\n    }\n\n    function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            // Look for revert reason and bubble it up if present\n            if (returndata.length > 0) {\n                // The easiest way to bubble the revert reason is using memory via assembly\n\n                // solhint-disable-next-line no-inline-assembly\n                assembly {\n                    let returndata_size := mload(returndata)\n                    revert(add(32, returndata), returndata_size)\n                }\n            } else {\n                revert(errorMessage);\n            }\n        }\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/Context.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/*\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with GSN meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n    function _msgSender() internal view virtual returns (address payable) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes memory) {\n        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691\n        return msg.data;\n    }\n}\n"
      },
      "contracts/factories/OriginatorStakingFactory.sol": {
        "content": "// SPDX-License-Identifier: GPLv3\n\npragma solidity ^0.7.5;\n\nimport '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol';\nimport '@openzeppelin/contracts/proxy/ProxyAdmin.sol';\n\nimport '../token/OriginatorStaking.sol';\n\n/**\n * @title  OriginatorStaking\n * @notice Contract to stake Originator Hub tokens, tokenize the position and get rewards, inheriting from a distribution manager contract\n * @author Aave / Ethichub\n **/\ncontract OriginatorStakingFactory is OwnableUpgradeable {\n    using SafeERC20Upgradeable for IERC20Upgradeable;\n    address public originatorImplementation;\n    mapping(string => address) public getOriginator;\n    address[] public allOriginators;\n    address public originatorProxyAdmin;\n\n    event OriginatorCreated(address originator, uint256);\n    event OriginatorAdded(address originator, uint256);\n    event OriginatorRemoved(address originator, uint256);\n    event OriginatorUpgraded(address originator, address implementation);\n\n    function initialize(address implementation) public initializer {\n        __Ownable_init();\n        originatorImplementation = implementation;\n        originatorProxyAdmin = address(new ProxyAdmin());\n    }\n\n    /**\n     * @notice Function to get originators length\n     * @return uint\n     */\n    function allOriginatorsLength() external view returns (uint256) {\n        return allOriginators.length;\n    }\n\n    /**\n     * @notice Function to get array of addresses for all originators\n     */\n    function getAllOriginators() external view returns (address[] memory) {\n        return allOriginators;\n    }\n\n    /**\n     * @notice Function to create new Originator proxy\n     * @param _name string\n     * @param _symbol string\n     * @param _lockedToken address (ERC20 token)\n     * @param _rewardsVault address (Rewards reserve)\n     * @param _emissionManager address \n     * @param _distributionDuration uint128 seconds\n     */\n   function createOriginator(\n        string memory _name,\n        string memory _symbol,\n        IERC20Upgradeable _lockedToken,\n        IReserve _rewardsVault,\n        address _emissionManager,\n        uint128 _distributionDuration\n    ) external onlyOwner returns (address) {\n        require(getOriginator[_symbol] == address(0), 'ORIGINATOR_EXISTS');\n        address originatorProxy = _createOriginator(\n            _name,\n            _symbol,\n            _lockedToken,\n            _rewardsVault,\n            _emissionManager,\n            _distributionDuration\n        );\n        return originatorProxy;\n    }\n\n    /**\n     * @notice Function to change originator implementation, set this to all originators\n     * @param implementation address\n     */\n    function changeOriginatorImplementation (address implementation) external onlyOwner {\n        _changeOriginatorImplementation(implementation);\n    }\n\n    /**\n     * @notice Function to add new originator\n     * @param proxy address (Originator)\n     */\n    function addOriginator(address proxy) external onlyOwner {\n        _addOriginator(proxy);\n    }\n\n    /**\n     * @notice Function to delete originator\n     * @param proxy address (Originator)\n     */\n    function deleteOriginator(address proxy) external onlyOwner {\n        _deleteOriginator(proxy);\n    }\n\n    function _createOriginator( \n        string memory _name,\n        string memory _symbol,\n        IERC20Upgradeable _lockedToken,\n        IReserve _rewardsVault,\n        address _emissionManager,\n        uint128 _distributionDuration\n    ) internal returns (address) {\n        require(getOriginator[_symbol] == address(0), 'ORIGINATOR_EXISTS');\n        // ERC1967 transparent proxy upgradeble\n        TransparentUpgradeableProxy originatorProxy = new TransparentUpgradeableProxy(\n            address(originatorImplementation), \n            address(originatorProxyAdmin), \n            abi.encodeWithSelector(\n                OriginatorStaking(originatorImplementation).initialize.selector, \n                _name,\n                _symbol,\n                _lockedToken,\n                _rewardsVault,\n                _emissionManager,\n                _distributionDuration\n            ));\n        getOriginator[_symbol] = address(originatorProxy);\n        allOriginators.push(address(originatorProxy));\n        emit OriginatorCreated(address(originatorProxy), allOriginators.length);\n        return address(originatorProxy);\n    }\n\n    function _changeOriginatorImplementation(address implementation) internal {\n        for (uint32 i = 0; i < allOriginators.length; i++) {\n            _upgradeOriginatorImplementation(allOriginators[i], implementation);\n        }\n        originatorImplementation = implementation;\n    }\n\n    function _upgradeOriginatorImplementation(address proxy, address implementation) internal {\n        ProxyAdmin(originatorProxyAdmin).upgrade(TransparentUpgradeableProxy(payable(proxy)), implementation);\n        emit OriginatorUpgraded(proxy, implementation);\n    }\n\n    function _addOriginator(address proxy) internal {\n        require(getOriginator[OriginatorStaking(proxy).symbol()] == address(0), 'ORIGINATOR_EXISTS');\n        (bool success, bytes memory implementation_data) = originatorProxyAdmin.call(\n            abi.encodeWithSignature(\"getProxyImplementation(address)\", proxy)\n        );\n        require(success, 'PROXYADMIN_IS_DIFFERENT');\n        address implementation = abi.decode(implementation_data, (address));\n        if (implementation != originatorImplementation) {\n            _upgradeOriginatorImplementation(proxy, originatorImplementation);\n        }\n        getOriginator[OriginatorStaking(proxy).symbol()] = address(proxy);\n        allOriginators.push(proxy);\n        emit OriginatorAdded(proxy, allOriginators.length);\n    }\n\n    function _deleteOriginator(address proxy) internal {\n        require(getOriginator[OriginatorStaking(proxy).symbol()] != address(0), 'ORIGINATOR_NOT_EXISTS');\n        bool found = false;\n        for (uint32 i = 0; i < allOriginators.length - 1; i++) {\n            if (proxy == allOriginators[i]) { \n                found = true;\n                allOriginators[i] = allOriginators[i + 1];\n            } else if (found) {\n                allOriginators[i] = allOriginators[i + 1];\n            }\n        }\n        delete getOriginator[OriginatorStaking(proxy).symbol()];\n        allOriginators.pop();\n        emit OriginatorRemoved(proxy, allOriginators.length);\n    }\n\n    /** \n     * @dev storage gaps \n     * 1 originatorImplementation\n     * 1 getOriginator\n     * 1 allOriginators\n     * 1 originatorProxyAdmin\n     * 46 __gap\n     */ \n    uint256[46] private __gap;\n}\n"
      },
      "contracts/reserve/IReserve.sol": {
        "content": "// SPDX-License-Identifier: gpl-3.0\n\npragma solidity 0.7.5;\n\ninterface IReserve {\n    event Transfer(address indexed to, uint256 amount);\n    event RescueFunds(address token, address indexed to, uint256 amount);\n\n    function balance() external view returns (uint256);\n\n    function transfer(address payable _to, uint256 _value) external returns (bool);\n\n    function rescueFunds(\n        address _tokenToRescue,\n        address _to,\n        uint256 _amount\n    ) external;\n}\n"
      },
      "contracts/token/bases/BaseTokenUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: gpl-3.0\n\npragma solidity 0.7.5;\n\nimport '../ERCs/ERC677/ERC677Upgradeable.sol';\nimport '../ERCs/ERC2612/ERC2612Upgradeable.sol';\n\nimport '@openzeppelin/contracts-upgradeable/proxy/Initializable.sol';\ncontract BaseTokenUpgradeable is Initializable, ERC677Upgradeable, ERC2612Upgradeable {\n\n    function __BaseTokenUpgradeable_init(\n        address _initialAccount,\n        uint256 _initialBalance,\n        string memory _name,\n        string memory _symbol,\n        string memory _EIP712Name\n    ) public initializer {\n        __ERC677_init(_initialAccount, _initialBalance, _name, _symbol);\n        __ERC2612_init(_EIP712Name);\n    }\n\n    function permit(\n        address _holder,\n        address _spender,\n        uint256 _nonce,\n        uint256 _expiry,\n        bool _allowed,\n        uint8 _v,\n        bytes32 _r,\n        bytes32 _s\n    ) public override {\n        bytes32 digest =\n            keccak256(\n                abi.encodePacked(\n                    '\\x19\\x01',\n                    DOMAIN_SEPARATOR,\n                    keccak256(\n                        abi.encode(PERMIT_TYPEHASH, _holder, _spender, _nonce, _expiry, _allowed)\n                    )\n                )\n            );\n        require(_holder != address(0), 'Token: invalid-address-0');\n        require(_holder == ecrecover(digest, _v, _r, _s), 'Token: invalid-permit');\n        require(_expiry == 0 || block.timestamp <= _expiry, 'Token: permit-expired');\n        require(_nonce == nonces[_holder]++, 'Token: invalid-nonce');\n        uint256 _amount =\n            _allowed ? 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff : 0;\n        _approve(_holder, _spender, _amount);\n    }\n}\n"
      },
      "contracts/token/bases/staking/interfaces/IOriginatorStaking.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\n\npragma solidity 0.7.5;\n\n\ninterface IOriginatorManager {\n    function setUpTerms(\n        address auditor,\n        address originator,\n        address governance,\n        uint256 auditorPercentage,\n        uint256 originatorPercentage,\n        uint256 stakingGoal,\n        uint256 defaultDelay\n    ) external;\n\n    function renewTerms(\n        uint256 newAuditorPercentage,\n        uint256 newOriginatorPercentage,\n        uint256 newStakingGoal,\n        uint128 newDistributionDuration,\n        uint256 newDefaultDelay\n    ) external;\n\n    function declareDefault(uint256 defaultedAmount) external;\n    function liquidateProposerStake(uint256 amount, bytes32 role) external;\n    function declareStakingEnd() external;\n    function hasReachedGoal() external view returns (bool);\n}\n\n\ninterface IProjectFundedRewards {\n    function startProjectFundedRewards(uint128 extraEmissionsPerSecond, address lendingContractAddress) external;\n    function endProjectFundedRewards(uint128 extraEmissionsPerSecond, address lendingContractAddress) external;\n}\n\n\ninterface IStaking {\n    function stake(address to, uint256 amount) external;\n    function redeem(address to, uint256 amount) external;\n    function claimRewards(address payable to, uint256 amount) external;\n    function withdrawProposerStake(uint256 amount) external;\n    function getTotalRewardsBalance(address staker) external view returns (uint256);\n}\n"
      },
      "contracts/token/bases/staking/interfaces/IStakingRewards.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\n\npragma solidity 0.7.5;\npragma experimental ABIEncoderV2;\n\nimport '../lib/DistributionTypes.sol';\n\ninterface IStakingRewards {\n    function changeDistributionEndDate(uint256 date) external;\n    function configureAssets(DistributionTypes.AssetConfigInput[] memory assetsConfigInput)\n        external;\n}\n"
      },
      "contracts/token/bases/staking/lib/DistributionTypes.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\n\npragma solidity 0.7.5;\npragma experimental ABIEncoderV2;\n\nlibrary DistributionTypes {\n    struct AssetConfigInput {\n        uint128 emissionPerSecond;\n        uint256 totalStaked;\n        address underlyingAsset;\n    }\n\n    struct UserStakeInput {\n        address underlyingAsset;\n        uint256 stakedByUser;\n        uint256 totalStaked;\n    }\n}\n"
      },
      "contracts/token/bases/staking/StakingRewards.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\n\npragma solidity 0.7.5;\npragma experimental ABIEncoderV2;\n\nimport './lib/DistributionTypes.sol';\nimport './interfaces/IStakingRewards.sol';\n\nimport '@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol';\nimport '../../../utils/SafeMathUint128.sol';\nimport '@openzeppelin/contracts-upgradeable/proxy/Initializable.sol';\nimport '@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol';\n\n/**\n * @title StakingRewards\n * @notice Accounting contract to manage multiple staking distributions\n * @author Aave / Ethichub\n **/\ncontract StakingRewards is Initializable, IStakingRewards, AccessControlUpgradeable {\n    bytes32 public constant EMISSION_MANAGER_ROLE = keccak256('EMISSION_MANAGER');\n    using SafeMathUpgradeable for uint256;\n    using SafeMathUint128 for uint128;\n\n    struct AssetData {\n        uint128 emissionPerSecond;\n        uint128 lastUpdateTimestamp;\n        uint256 index;\n        mapping(address => uint256) users;\n    }\n\n    uint256 public DISTRIBUTION_END;\n\n    uint8 constant public PRECISION = 18;\n\n    mapping(address => AssetData) public assets;\n\n    event AssetConfigUpdated(address indexed asset, uint256 emission);\n    event AssetIndexUpdated(address indexed asset, uint256 index);\n    event UserIndexUpdated(address indexed user, address indexed asset, uint256 index);\n    event DistributionEndChanged(uint256 distributionEnd);\n\n    function __StakingRewards_init(address emissionManager, uint256 distributionDuration)\n        public\n        initializer\n    {\n        __AccessControl_init_unchained();\n        DISTRIBUTION_END = block.timestamp.add(distributionDuration);\n        _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n        _setupRole(EMISSION_MANAGER_ROLE, emissionManager);\n    }\n\n    /**\n     * @dev Configures the distribution of rewards for a list of assets\n     * @param assetsConfigInput The list of configurations to apply\n     **/\n    function configureAssets(DistributionTypes.AssetConfigInput[] memory assetsConfigInput)\n        public\n        override\n    {\n        require(hasRole(EMISSION_MANAGER_ROLE, msg.sender), 'ONLY_EMISSION_MANAGER');\n\n        for (uint256 i = 0; i < assetsConfigInput.length; i++) {\n            AssetData storage assetConfig = assets[assetsConfigInput[i].underlyingAsset];\n\n            _updateAssetStateInternal(\n                assetsConfigInput[i].underlyingAsset,\n                assetConfig,\n                assetsConfigInput[i].totalStaked\n            );\n\n            assetConfig.emissionPerSecond = assetsConfigInput[i].emissionPerSecond;\n\n            emit AssetConfigUpdated(\n                assetsConfigInput[i].underlyingAsset,\n                assetsConfigInput[i].emissionPerSecond\n            );\n        }\n    }\n\n    /**\n     * @notice Change distribution end datetime\n     * @param _distributionEndDate new distribution end datetime (UNIX Timestamp)\n     */\n    function changeDistributionEndDate(uint256 _distributionEndDate) public override {\n        require(hasRole(EMISSION_MANAGER_ROLE, msg.sender), 'ONLY_EMISSION_MANAGER');\n        return _changeDistributionEndDate(_distributionEndDate);\n    }\n\n    /**\n     * @notice Change distribution end datetime internal function\n     * @param _distributionEndDate new distribution end datetime (UNIX Timestamp)\n     */\n    function _changeDistributionEndDate(uint256 _distributionEndDate) internal {\n        DISTRIBUTION_END = _distributionEndDate;\n        emit DistributionEndChanged(DISTRIBUTION_END);\n    }\n\n    /**\n     * @dev Updates the state of one distribution, mainly rewards index and timestamp\n     * @param underlyingAsset The address used as key in the distribution\n     * @param assetConfig Storage pointer to the distribution's config\n     * @param totalStaked Current total of staked assets for this distribution\n     * @return The new distribution index\n     **/\n    function _updateAssetStateInternal(\n        address underlyingAsset,\n        AssetData storage assetConfig,\n        uint256 totalStaked\n    ) internal returns (uint256) {\n        uint256 oldIndex = assetConfig.index;\n        uint128 lastUpdateTimestamp = assetConfig.lastUpdateTimestamp;\n\n        if (block.timestamp == lastUpdateTimestamp) {\n            return oldIndex;\n        }\n\n        uint256 newIndex =\n            _getAssetIndex(\n                oldIndex,\n                assetConfig.emissionPerSecond,\n                lastUpdateTimestamp,\n                totalStaked\n            );\n\n        if (newIndex != oldIndex) {\n            assetConfig.index = newIndex;\n            emit AssetIndexUpdated(underlyingAsset, newIndex);\n        }\n\n        assetConfig.lastUpdateTimestamp = uint128(block.timestamp);\n\n        return newIndex;\n    }\n\n    /**\n     * @dev Updates the state of an user in a distribution\n     * @param user The user's address\n     * @param asset The address of the reference asset of the distribution\n     * @param stakedByUser Amount of tokens staked by the user in the distribution at the moment\n     * @param totalStaked Total tokens staked in the distribution\n     * @return The accrued rewards for the user until the moment\n     **/\n    function _updateUserAssetInternal(\n        address user,\n        address asset,\n        uint256 stakedByUser,\n        uint256 totalStaked\n    ) internal returns (uint256) {\n        AssetData storage assetData = assets[asset];\n        uint256 userIndex = assetData.users[user];\n        uint256 accruedRewards = 0;\n\n        uint256 newIndex = _updateAssetStateInternal(asset, assetData, totalStaked);\n\n        if (userIndex != newIndex) {\n            if (stakedByUser != 0) {\n                accruedRewards = _getRewards(stakedByUser, newIndex, userIndex);\n            }\n\n            assetData.users[user] = newIndex;\n            emit UserIndexUpdated(user, asset, newIndex);\n        }\n\n        return accruedRewards;\n    }\n\n    /**\n     * @dev Used by \"frontend\" stake contracts to update the data of an user when claiming rewards from there\n     * @param user The address of the user\n     * @param stakes List of structs of the user data related with his stake\n     * @return The accrued rewards for the user until the moment\n     **/\n    function _claimRewards(address payable user, DistributionTypes.UserStakeInput[] memory stakes)\n        internal\n        returns (uint256)\n    {\n        uint256 accruedRewards = 0;\n\n        for (uint256 i = 0; i < stakes.length; i++) {\n            accruedRewards = accruedRewards.add(\n                _updateUserAssetInternal(\n                    user,\n                    stakes[i].underlyingAsset,\n                    stakes[i].stakedByUser,\n                    stakes[i].totalStaked\n                )\n            );\n        }\n\n        return accruedRewards;\n    }\n\n    /**\n     * @dev Return the accrued rewards for an user over a list of distribution\n     * @param user The address of the user\n     * @param stakes List of structs of the user data related with his stake\n     * @return The accrued rewards for the user until the moment\n     **/\n    function _getUnclaimedRewards(address user, DistributionTypes.UserStakeInput[] memory stakes)\n        internal\n        view\n        returns (uint256)\n    {\n        uint256 accruedRewards = 0;\n\n        for (uint256 i = 0; i < stakes.length; i++) {\n            AssetData storage assetConfig = assets[stakes[i].underlyingAsset];\n            uint256 assetIndex =\n                _getAssetIndex(\n                    assetConfig.index,\n                    assetConfig.emissionPerSecond,\n                    assetConfig.lastUpdateTimestamp,\n                    stakes[i].totalStaked\n                );\n\n            accruedRewards = accruedRewards.add(\n                _getRewards(stakes[i].stakedByUser, assetIndex, assetConfig.users[user])\n            );\n        }\n        return accruedRewards;\n    }\n\n    /**\n     * @dev Internal function for the calculation of user's rewards on a distribution\n     * @param principalUserBalance Amount staked by the user on a distribution\n     * @param reserveIndex Current index of the distribution\n     * @param userIndex Index stored for the user, representation his staking moment\n     * @return The rewards\n     **/\n    function _getRewards(\n        uint256 principalUserBalance,\n        uint256 reserveIndex,\n        uint256 userIndex\n    ) internal view returns (uint256) {\n        return principalUserBalance.mul(reserveIndex.sub(userIndex)).div(10**uint256(PRECISION));\n    }\n\n    /**\n     * @dev Calculates the next value of an specific distribution index, with validations\n     * @param currentIndex Current index of the distribution\n     * @param emissionPerSecond Representing the total rewards distributed per second per asset unit, on the distribution\n     * @param lastUpdateTimestamp Last moment this distribution was updated\n     * @param totalBalance of tokens considered for the distribution\n     * @return The new index.\n     **/\n    function _getAssetIndex(\n        uint256 currentIndex,\n        uint256 emissionPerSecond,\n        uint128 lastUpdateTimestamp,\n        uint256 totalBalance\n    ) internal view returns (uint256) {\n        if (\n            emissionPerSecond == 0 ||\n            totalBalance == 0 ||\n            lastUpdateTimestamp == block.timestamp ||\n            lastUpdateTimestamp >= DISTRIBUTION_END\n        ) {\n            return currentIndex;\n        }\n\n        uint256 currentTimestamp =\n            block.timestamp > DISTRIBUTION_END ? DISTRIBUTION_END : block.timestamp;\n        uint256 timeDelta = currentTimestamp.sub(lastUpdateTimestamp);\n        return\n            emissionPerSecond.mul(timeDelta).mul(10**uint256(PRECISION)).div(totalBalance).add(\n                currentIndex\n            );\n    }\n\n    /**\n     * @dev Returns the data of an user on a distribution\n     * @param user Address of the user\n     * @param asset The address of the reference asset of the distribution\n     * @return The new index\n     **/\n    function getUserAssetData(address user, address asset) public view returns (uint256) {\n        return assets[asset].users[user];\n    }\n}\n"
      },
      "contracts/token/ERCs/ERC2612/ERC2612Upgradeable.sol": {
        "content": "// SPDX-License-Identifier: gpl-3.0\n\npragma solidity 0.7.5;\n\nimport '@openzeppelin/contracts-upgradeable/proxy/Initializable.sol';\n\nabstract contract ERC2612Upgradeable is Initializable {\n    // --- EIP712 niceties ---\n    bytes32 public DOMAIN_SEPARATOR;\n    // bytes32 public constant PERMIT_TYPEHASH = keccak256(\"Permit(address holder,address spender,uint256 nonce,uint256 expiry,bool allowed)\");\n    bytes32 public PERMIT_TYPEHASH;\n\n    string public version;\n    mapping(address => uint256) public nonces;\n\n    function __ERC2612_init(string memory _EIP712Name) internal initializer {\n        version = '1';\n        DOMAIN_SEPARATOR = keccak256(\n            abi.encode(\n                keccak256(\n                    'EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'\n                ),\n                keccak256(bytes(_EIP712Name)),\n                keccak256(bytes(version)),\n                getChainId(),\n                address(this)\n            )\n        );\n        PERMIT_TYPEHASH = 0xea2aa0a1be11a07ed86d755c93467f4f82362b452371d1ba94d1715123511acb;\n    }\n\n    function permit(\n        address holder,\n        address spender,\n        uint256 nonce,\n        uint256 expiry,\n        bool allowed,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) public virtual;\n\n    function getChainId() public pure returns (uint256 chainId) {\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            chainId := chainid()\n        }\n    }\n}\n"
      },
      "contracts/token/ERCs/ERC677/ERC677Upgradeable.sol": {
        "content": "// SPDX-License-Identifier: gpl-3.0\n\npragma solidity 0.7.5;\n\nimport './IERC677.sol';\nimport './IERC677Receiver.sol';\n\nimport '@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol';\nimport '@openzeppelin/contracts-upgradeable/proxy/Initializable.sol';\n\ncontract ERC677Upgradeable is Initializable, IERC677, ERC20Upgradeable {\n    /**\n     * @dev Sets the values for {_name} and {_symbol}, initializes {_decimals} with\n     * a default value of 18. And mints {_initialBalance} to address {_initialAccount}\n     *\n     * All three of these values are immutable: they can only be set once during\n     * construction.\n     */\n    function __ERC677_init(\n        address _initialAccount,\n        uint256 _initialBalance,\n        string memory _name,\n        string memory _symbol\n    ) internal initializer {\n        __ERC20_init(_name, _symbol);\n        if (_initialBalance != 0) {\n          _mint(_initialAccount, _initialBalance);\n        }\n    }\n\n    /**\n     * @dev check if an address is a contract.\n     * @param _addr The address to check.\n     */\n    function isContract(address _addr) private view returns (bool hasCode) {\n        uint256 length;\n        assembly {\n            length := extcodesize(_addr)\n        }\n        return length > 0;\n    }\n\n    /**\n     * @dev transfer token to a contract address with additional data if the recipient is a contact.\n     * @param _to The address to transfer to.\n     * @param _value The amount to be transferred.\n     * @param _data The extra data to be passed to the receiving contract.\n     */\n    function transferAndCall(\n        address _to,\n        uint256 _value,\n        bytes memory _data\n    ) public virtual override returns (bool success) {\n        require(super.transfer(_to, _value), 'ERC677Upgradeable: transfer failed');\n        if (isContract(_to)) {\n            IERC677Receiver(_to).onTokenTransfer(msg.sender, _value, _data);\n        }\n        return true;\n    }\n}\n"
      },
      "contracts/token/ERCs/ERC677/IERC677.sol": {
        "content": "// SPDX-License-Identifier: gpl-3.0\n\npragma solidity 0.7.5;\n\ninterface IERC677 {\n    function transferAndCall(\n        address to,\n        uint256 value,\n        bytes memory data\n    ) external returns (bool ok);\n}\n"
      },
      "contracts/token/ERCs/ERC677/IERC677Receiver.sol": {
        "content": "// SPDX-License-Identifier: gpl-3.0\n\npragma solidity 0.7.5;\n\ninterface IERC677Receiver {\n    function onTokenTransfer(\n        address from,\n        uint256 amount,\n        bytes calldata data\n    ) external returns (bool);\n}\n"
      },
      "contracts/token/OriginatorStaking.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\n\npragma solidity 0.7.5;\npragma experimental ABIEncoderV2;\n\nimport './bases/staking/StakingRewards.sol';\nimport './bases/BaseTokenUpgradeable.sol';\nimport './bases/staking/interfaces/IOriginatorStaking.sol';\nimport '../reserve/IReserve.sol';\nimport '../utils/SafeMathUint128.sol';\n\nimport '@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol';\nimport '@openzeppelin/contracts-upgradeable/token/ERC20/SafeERC20Upgradeable.sol';\nimport '@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol';\nimport '@openzeppelin/contracts-upgradeable/proxy/Initializable.sol';\n\n\n/**\n * @title  OriginatorStaking\n * @notice Contract to stake Originator Hub tokens, tokenize the position and get rewards, inheriting from a distribution manager contract\n * @author Aave / Ethichub\n **/\ncontract OriginatorStaking is Initializable, StakingRewards, BaseTokenUpgradeable, IStaking, IProjectFundedRewards, IOriginatorManager {\n    using SafeERC20Upgradeable for IERC20Upgradeable;\n    using SafeMathUpgradeable for uint256;\n    using SafeMathUint128 for uint128;\n\n    enum OriginatorStakingState {\n        UNINITIALIZED,\n        STAKING,\n        STAKING_END,\n        DEFAULT\n    }\n\n    OriginatorStakingState public state;\n\n    IERC20Upgradeable public STAKED_TOKEN;\n\n    /// @notice IReserve to pull from the rewards, needs to have this contract as WITHDRAW role\n    IReserve public REWARDS_VAULT;\n\n    bytes32 public constant GOVERNANCE_ROLE = keccak256('GOVERNANCE_ROLE');\n \n    uint256 public stakingGoal;\n    uint256 public defaultedAmount;\n\n    mapping(address => uint256) public stakerRewardsToClaim;\n\n    bytes32 public constant ORIGINATOR_ROLE = keccak256('ORIGINATOR_ROLE');\n    bytes32 public constant AUDITOR_ROLE = keccak256('AUDITOR_ROLE');\n\n    uint256 public DEFAULT_DATE;\n\n    mapping(bytes32 => uint256) public proposerBalances;\n\n    event StateChange(uint256 state);\n\n    event Staked(address indexed from, address indexed onBehalfOf, uint256 amount);\n    event Redeem(address indexed from, address indexed to, uint256 amount);\n    \n    event Withdraw(address indexed proposer, uint256 amount);\n\n    event RewardsAccrued(address user, uint256 amount);\n    event RewardsClaimed(address indexed from, address indexed to, uint256 amount);\n\n    event StartRewardsProjectFunded(uint128 previousEmissionPerSecond, uint128 extraEmissionsPerSecond, address lendingContractAddress);\n    event EndRewardsProjectFunded(uint128 restoredEmissionsPerSecond, uint128 extraEmissionsPerSecond, address lendingContractAddress);\n\n    modifier onlyGovernance() {\n        require(hasRole(GOVERNANCE_ROLE, msg.sender), 'ONLY_GOVERNANCE');\n        _;\n    }\n\n    modifier onlyEmissionManager() {\n        require(hasRole(EMISSION_MANAGER_ROLE, msg.sender), 'ONLY_EMISSION_MANAGER');\n        _;\n    }\n\n    modifier onlyOnStakingState() {\n        require(state == OriginatorStakingState.STAKING, 'ONLY_ON_STAKING_STATE');\n        _;\n    }\n\n    modifier notZeroAmount(uint256 _amount) {\n        require(_amount > 0, 'INVALID_ZERO_AMOUNT');\n        _;\n    }\n\n    function initialize(\n        string memory _name,\n        string memory _symbol,\n        IERC20Upgradeable _lockedToken,\n        IReserve _rewardsVault,\n        address _emissionManager,\n        uint128 _distributionDuration\n    ) public initializer {\n        __BaseTokenUpgradeable_init(\n            msg.sender,\n            0,\n            _name,\n            _symbol,\n            _name\n        );\n        __StakingRewards_init(_emissionManager, _distributionDuration);\n        STAKED_TOKEN = _lockedToken;\n        REWARDS_VAULT = _rewardsVault;\n        _changeState(OriginatorStakingState.UNINITIALIZED);\n    }\n\n    /**\n     * @notice Function to set up proposers (originator and auditor)\n     * in proposal period.\n     * @param _auditor address\n     * @param _originator address\n     * @param _auditorPercentage uint256 (value * 100 e.g. 20% == 2000)\n     * @param _originatorPercentage uint256 (value * 100 e.g. 20% == 2000)\n     * @param _stakingGoal uint256 wei amount in Ethix\n     * @param _defaultDelay uint256 seconds\n     */\n    function setUpTerms(\n        address _auditor, \n        address _originator,\n        address _governance,\n        uint256 _auditorPercentage, \n        uint256 _originatorPercentage, \n        uint256 _stakingGoal,\n        uint256 _defaultDelay\n    ) external override notZeroAmount(_stakingGoal) onlyEmissionManager {\n        require(_auditor != _originator, 'PROPOSERS_CANNOT_BE_THE_SAME');\n        require(_auditorPercentage != 0 && _originatorPercentage != 0, 'INVALID_PERCENTAGE_ZERO');\n        require(state == OriginatorStakingState.UNINITIALIZED, 'ONLY_ON_UNINITILIZED_STATE');\n\n        _setupRole(AUDITOR_ROLE, _auditor);\n        _setupRole(ORIGINATOR_ROLE, _originator);\n        _setupRole(GOVERNANCE_ROLE, _governance);\n            \n        _depositProposer(_auditor, _auditorPercentage, _stakingGoal);\n        _depositProposer(_originator, _originatorPercentage, _stakingGoal);\n        stakingGoal = _stakingGoal;\n        DEFAULT_DATE = _defaultDelay.add(DISTRIBUTION_END);\n        _changeState(OriginatorStakingState.STAKING);\n    }\n\n    /**\n     * @notice Function to renew terms in STAKING_END or DEFAULT period.\n     * @param _newAuditorPercentage uint256 (value * 100 e.g. 20% == 2000)\n     * @param _newOriginatorPercentage uint256 (value * 100 e.g. 20% == 2000)\n     * @param _newStakingGoal uint256 wei amount in Ethix\n     * @param _newDistributionDuration uint128 seconds (e.g. 365 days == 31536000)\n     * @param _newDefaultDelay uint256 seconds (e.g 90 days == 7776000)\n     */\n    function renewTerms(\n        uint256 _newAuditorPercentage,\n        uint256 _newOriginatorPercentage,\n        uint256 _newStakingGoal,\n        uint128 _newDistributionDuration,\n        uint256 _newDefaultDelay) external override notZeroAmount(_newStakingGoal) onlyGovernance {\n        require(state == OriginatorStakingState.STAKING_END || state == OriginatorStakingState.DEFAULT, 'INVALID_STATE');\n        DISTRIBUTION_END = block.timestamp.add(_newDistributionDuration);\n        _depositProposer(getRoleMember(AUDITOR_ROLE, 0), _newAuditorPercentage, _newStakingGoal);\n        _depositProposer(getRoleMember(ORIGINATOR_ROLE, 0), _newOriginatorPercentage, _newStakingGoal);\n        stakingGoal = _newStakingGoal;\n        DEFAULT_DATE = _newDefaultDelay.add(DISTRIBUTION_END);\n        _changeState(OriginatorStakingState.STAKING);\n    }\n\n    /**\n     * @notice Function to stake tokens\n     * @param _onBehalfOf Address to stake to\n     * @param _amount Amount to stake\n     **/\n    function stake(address _onBehalfOf, uint256 _amount) external override notZeroAmount(_amount) onlyOnStakingState {\n        require(!hasReachedGoal(), 'GOAL_HAS_REACHED');\n\n        if (STAKED_TOKEN.balanceOf(address(this)).add(_amount) > stakingGoal) {\n            _amount = stakingGoal.sub(STAKED_TOKEN.balanceOf(address(this)));\n        }\n        uint256 balanceOfUser = balanceOf(_onBehalfOf);\n        uint256 accruedRewards =\n            _updateUserAssetInternal(_onBehalfOf, address(this), balanceOfUser, totalSupply());\n        if (accruedRewards != 0) {\n            emit RewardsAccrued(_onBehalfOf, accruedRewards);\n            stakerRewardsToClaim[_onBehalfOf] = stakerRewardsToClaim[_onBehalfOf].add(accruedRewards);\n        }\n\n        _mint(_onBehalfOf, _amount);\n        IERC20Upgradeable(STAKED_TOKEN).safeTransferFrom(msg.sender, address(this), _amount);\n\n        emit Staked(msg.sender, _onBehalfOf, _amount);\n    }\n\n    /**\n     * @dev Redeems staked tokens, and stop earning rewards\n     * @param _to Address to redeem to\n     * @param _amount Amount to redeem\n     **/\n    function redeem(address _to, uint256 _amount) external override notZeroAmount(_amount) {\n        require(_checkRedeemEligibilityState(), 'WRONG_STATE');\n        require(balanceOf(msg.sender) != 0, 'SENDER_BALANCE_ZERO');\n\n        uint256 balanceOfMessageSender = balanceOf(msg.sender);\n\n        uint256 amountToRedeem =\n            (_amount > balanceOfMessageSender) ? balanceOfMessageSender : _amount;\n\n        _updateCurrentUnclaimedRewards(msg.sender, balanceOfMessageSender, true);\n\n        _burn(msg.sender, amountToRedeem);\n\n        IERC20Upgradeable(STAKED_TOKEN).safeTransfer(_to, amountToRedeem);\n\n        emit Redeem(msg.sender, _to, amountToRedeem);\n    }\n\n    /**\n     * @notice method to withdraw deposited amount.\n     * @param _amount Amount to withdraw\n     */\n    function withdrawProposerStake(uint256 _amount) external override {\n        require(state == OriginatorStakingState.STAKING_END, 'ONLY_ON_STAKING_END_STATE');\n        bytes32 senderRole = 0x00;\n        \n        if (msg.sender == getRoleMember(ORIGINATOR_ROLE, 0)) {\n            senderRole = ORIGINATOR_ROLE;\n        } else if (msg.sender == getRoleMember(AUDITOR_ROLE, 0)) {\n            senderRole = AUDITOR_ROLE;\n        } else {\n            revert('WITHDRAW_PERMISSION_DENIED');\n        }\n        require(proposerBalances[senderRole] != 0, 'INVALID_ZERO_AMOUNT');\n\n        uint256 amountToWithdraw =\n            (_amount > proposerBalances[senderRole]) ? proposerBalances[senderRole] : _amount;\n\n        proposerBalances[senderRole] = proposerBalances[senderRole].sub(amountToWithdraw);\n        IERC20Upgradeable(STAKED_TOKEN).safeTransfer(msg.sender, amountToWithdraw);\n        emit Withdraw(msg.sender, amountToWithdraw);\n    }\n\n    /**\n     * @dev Claims an `amount` from Rewards reserve to the address `to`\n     * @param _to Address to stake for\n     * @param _amount Amount to stake\n     **/\n    function claimRewards(address payable _to, uint256 _amount) external override {\n        uint256 newTotalRewards = _updateCurrentUnclaimedRewards(msg.sender, balanceOf(msg.sender), false);\n        uint256 amountToClaim = (_amount == type(uint256).max) ? newTotalRewards : _amount;\n\n        stakerRewardsToClaim[msg.sender] = newTotalRewards.sub(amountToClaim, 'INVALID_AMOUNT');\n        require(REWARDS_VAULT.transfer(_to, amountToClaim), 'ERROR_TRANSFER_FROM_VAULT');\n\n        emit RewardsClaimed(msg.sender, _to, amountToClaim);\n    }\n\n    /**\n     * Function to add an extra emissions per second corresponding to staker rewards when a lending project by this originator\n     * is funded.\n     * @param _extraEmissionsPerSecond  emissions per second to be added to current ones.\n     * @param _lendingContractAddress lending contract address is relationated with this rewards\n     */\n    function startProjectFundedRewards(uint128 _extraEmissionsPerSecond, address _lendingContractAddress) external override onlyOnStakingState {\n        AssetData storage currentDistribution = assets[address(this)];\n        uint128 currentEmission = currentDistribution.emissionPerSecond;\n\n        uint128 newEmissionsPerSecond = currentDistribution.emissionPerSecond.add(_extraEmissionsPerSecond);\n        DistributionTypes.AssetConfigInput[] memory newAssetConfig = new DistributionTypes.AssetConfigInput[](1);\n        newAssetConfig[0] = DistributionTypes.AssetConfigInput({\n            emissionPerSecond: newEmissionsPerSecond,\n            totalStaked: totalSupply(),\n            underlyingAsset: address(this)\n        });\n        configureAssets(newAssetConfig);\n\n        emit StartRewardsProjectFunded(currentEmission, _extraEmissionsPerSecond, _lendingContractAddress);\n    }\n\n    /**\n     * Function to end extra emissions per second corresponding to staker rewards when a lending project by this originator\n     * is funded.\n     * @param _extraEmissionsPerSecond  emissions per second to be added to current ones.\n     * @param _lendingContractAddress lending contract address is relationated with this rewards.\n     */\n    function endProjectFundedRewards(uint128 _extraEmissionsPerSecond, address _lendingContractAddress) external override onlyOnStakingState {\n        AssetData storage currentDistribution = assets[address(this)];\n        uint128 currentEmission = currentDistribution.emissionPerSecond;\n        uint128 newEmissionsPerSecond = currentDistribution.emissionPerSecond.sub(_extraEmissionsPerSecond);\n        DistributionTypes.AssetConfigInput[] memory newAssetConfig = new DistributionTypes.AssetConfigInput[](1);\n        newAssetConfig[0] = DistributionTypes.AssetConfigInput({\n            emissionPerSecond: newEmissionsPerSecond,\n            totalStaked: totalSupply(),\n            underlyingAsset: address(this)\n        });\n        configureAssets(newAssetConfig);\n        emit EndRewardsProjectFunded(currentEmission, _extraEmissionsPerSecond, _lendingContractAddress);\n    }\n\n    /**\n     * @notice Amount to substract of the contract when state is default \n     * @param _amount amount to substract\n     * @param _role role to substract the amount (Originator, Auditor)\n     */\n    function liquidateProposerStake(uint256 _amount, bytes32 _role) external override notZeroAmount(_amount) onlyGovernance {\n        require(state == OriginatorStakingState.DEFAULT, 'ONLY_ON_DEFAULT');\n        require(_role == AUDITOR_ROLE || _role == ORIGINATOR_ROLE, 'INVALID_PROPOSER_ROLE');\n        proposerBalances[_role] = proposerBalances[_role].sub(_amount, 'INVALID_LIQUIDATE_AMOUNT');\n        IERC20Upgradeable(STAKED_TOKEN).safeTransfer(msg.sender, _amount);\n    }\n\n    /**\n     * @notice Function to declare contract on staking end state\n     * Only governance could change to this state\n     **/\n    function declareStakingEnd() external override onlyGovernance onlyOnStakingState {\n        _endDistributionIfNeeded();\n        _changeState(OriginatorStakingState.STAKING_END);\n    }\n\n    /**\n     * @notice Function to declare as DEFAULT\n     * @param _defaultedAmount uint256\n     **/\n    function declareDefault(uint256 _defaultedAmount) external override onlyGovernance onlyOnStakingState {\n        require(block.timestamp >= DEFAULT_DATE, 'DEFAULT_DATE_NOT_REACHED');\n        defaultedAmount = _defaultedAmount;\n        _endDistributionIfNeeded();\n        _changeState(OriginatorStakingState.DEFAULT);\n    }\n\n    /**\n     * @dev Return the total rewards pending to claim by an staker\n     * @param _staker The staker address\n     * @return The rewards\n     */\n    function getTotalRewardsBalance(address _staker) external override view returns (uint256) {\n        DistributionTypes.UserStakeInput[] memory userStakeInputs =\n            new DistributionTypes.UserStakeInput[](1);\n        userStakeInputs[0] = DistributionTypes.UserStakeInput({\n            underlyingAsset: address(this),\n            stakedByUser: balanceOf(_staker),\n            totalStaked: totalSupply()\n        });\n        return stakerRewardsToClaim[_staker].add(_getUnclaimedRewards(_staker, userStakeInputs));\n    }\n\n    /**\n     * @notice Check if fulfilled the objective (Only valid on STAKING state!!)\n     */\n    function hasReachedGoal() public override notZeroAmount(stakingGoal) view returns (bool) {\n        if (proposerBalances[ORIGINATOR_ROLE].add(proposerBalances[AUDITOR_ROLE]).add(totalSupply()) >= stakingGoal) {\n            return true;\n        }\n        return  false;\n    }\n\n    /**\n     * @notice Function to transfer participation amount (originator or auditor)\n     */\n    function _depositProposer(address _proposer, uint256 _percentage, uint256 _goalAmount) internal {\n        uint256 percentageAmount = _calculatePercentage(_goalAmount, _percentage);\n        uint256 depositAmount = 0;\n\n        if (_proposer == getRoleMember(ORIGINATOR_ROLE, 0)) {\n            depositAmount = _calculateDepositAmount(ORIGINATOR_ROLE, percentageAmount);\n            proposerBalances[ORIGINATOR_ROLE] = proposerBalances[ORIGINATOR_ROLE].add(depositAmount);\n        } else if (_proposer == getRoleMember(AUDITOR_ROLE, 0)) {\n            depositAmount = _calculateDepositAmount(AUDITOR_ROLE, percentageAmount);\n            proposerBalances[AUDITOR_ROLE] = proposerBalances[AUDITOR_ROLE].add(depositAmount);\n        }\n        IERC20Upgradeable(STAKED_TOKEN).safeTransferFrom(_proposer, address(this), depositAmount);\n    }\n\n    /**\n     * @dev Internal ERC20 _transfer of the tokenized staked tokens\n     * @param _from Address to transfer from\n     * @param _to Address to transfer to\n     * @param _amount Amount to transfer\n     **/\n    function _transfer(\n        address _from,\n        address _to,\n        uint256 _amount\n    ) internal override {\n        uint256 balanceOfFrom = balanceOf(_from);\n        // Sender\n        _updateCurrentUnclaimedRewards(_from, balanceOfFrom, true);\n\n        // Recipient\n        if (_from != _to) {\n            uint256 balanceOfTo = balanceOf(_to);\n            _updateCurrentUnclaimedRewards(_to, balanceOfTo, true);\n        }\n\n        super._transfer(_from, _to, _amount);\n    }\n\n    /** \n     * @dev Check if the state of contract is suitable to redeem\n     */\n    function _checkRedeemEligibilityState() internal view returns (bool) {\n        if (state == OriginatorStakingState.STAKING_END) {\n            return true;\n        } else if (state == OriginatorStakingState.DEFAULT && defaultedAmount <= proposerBalances[ORIGINATOR_ROLE].add(proposerBalances[AUDITOR_ROLE])) {\n            return true;\n        } else {\n            return false;\n        }\n    }\n\n    /**\n     * @dev Updates the user state related with his accrued rewards\n     * @param _user Address of the user\n     * @param _userBalance The current balance of the user\n     * @param _updateStorage Boolean flag used to update or not the stakerRewardsToClaim of the user\n     * @return The unclaimed rewards that were added to the total accrued\n     **/\n    function _updateCurrentUnclaimedRewards(\n        address _user,\n        uint256 _userBalance,\n        bool _updateStorage\n    ) internal returns (uint256) {\n        uint256 accruedRewards =\n            _updateUserAssetInternal(_user, address(this), _userBalance, totalSupply());\n        uint256 unclaimedRewards = stakerRewardsToClaim[_user].add(accruedRewards);\n\n        if (accruedRewards != 0) {\n            if (_updateStorage) {\n                stakerRewardsToClaim[_user] = unclaimedRewards;\n            }\n            emit RewardsAccrued(_user, accruedRewards);\n        }\n\n        return unclaimedRewards;\n    }\n\n    /**\n     * @notice Function to calculate a percentage of an amount\n     * @param _amount Amount to calculate the percentage of\n     * @param _percentage Percentage to calculate of this amount\n     * @return (amount)\n     */\n    function _calculatePercentage(uint256 _amount, uint256 _percentage) internal pure returns (uint256) {\n        return uint256(_amount.mul(_percentage).div(10000));\n    }\n\n    /**\n     * @notice Function to get the actual participation amount\n     * of proposers according the amount that already exists in the contract\n     * @param _role Auditor or originator role\n     * @param _percentageAmount Percentage of staking goal amount\n     * Note _percentageAmount SHOULD BE GREATER than the previously existing amount\n     */\n    function _calculateDepositAmount(bytes32 _role, uint256 _percentageAmount) internal view returns (uint256){\n        return uint256(_percentageAmount.sub(proposerBalances[_role]));\n    }\n\n    /**\n     * @notice Function to change contract state\n     * @param _newState New contract state\n     **/\n    function _changeState(OriginatorStakingState _newState) internal {\n        state = _newState;\n        emit StateChange(uint256(_newState));\n    }\n\n    /**\n     * @notice Function to change DISTRIBUTION_END if timestamp is less than the initial one\n     **/\n    function _endDistributionIfNeeded() internal {\n        if (block.timestamp <= DISTRIBUTION_END) {\n            _changeDistributionEndDate(block.timestamp);\n        }\n    }\n}"
      },
      "contracts/utils/SafeMathUint128.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.7.0;\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations with added overflow\n * checks.\n *\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\n * in bugs, because programmers usually assume that an overflow raises an\n * error, which is the standard behavior in high level programming languages.\n * `SafeMath` restores this intuition by reverting the transaction when an\n * operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeMathUint128 {\n    /**\n     * @dev Returns the addition of two unsigned integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity's `+` operator.\n     *\n     * Requirements:\n     *\n     * - Addition cannot overflow.\n     */\n    function add(uint128 a, uint128 b) internal pure returns (uint128) {\n        uint128 c = a + b;\n        require(c >= a, \"SafeMath: addition overflow\");\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, reverting on\n     * overflow (when the result is negative).\n     *\n     * Counterpart to Solidity's `-` operator.\n     *\n     * Requirements:\n     *\n     * - Subtraction cannot overflow.\n     */\n    function sub(uint128 a, uint128 b) internal pure returns (uint128) {\n        return sub(a, b, \"SafeMath: subtraction overflow\");\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\n     * overflow (when the result is negative).\n     *\n     * Counterpart to Solidity's `-` operator.\n     *\n     * Requirements:\n     *\n     * - Subtraction cannot overflow.\n     */\n    function sub(uint128 a, uint128 b, string memory errorMessage) internal pure returns (uint128) {\n        require(b <= a, errorMessage);\n        uint128 c = a - b;\n\n        return c;\n    }\n    \n\n    /**\n     * @dev Returns the multiplication of two unsigned integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity's `*` operator.\n     *\n     * Requirements:\n     *\n     * - Multiplication cannot overflow.\n     */\n    function mul(uint128 a, uint128 b) internal pure returns (uint128) {\n        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n        // benefit is lost if 'b' is also tested.\n        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n        if (a == 0) {\n            return 0;\n        }\n\n        uint128 c = a * b;\n        require(c / a == b, \"SafeMath: multiplication overflow\");\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the integer division of two unsigned integers. Reverts on\n     * division by zero. The result is rounded towards zero.\n     *\n     * Counterpart to Solidity's `/` operator. Note: this function uses a\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\n     * uses an invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function div(uint128 a, uint128 b) internal pure returns (uint128) {\n        return div(a, b, \"SafeMath: division by zero\");\n    }\n\n    /**\n     * @dev Returns the integer division of two unsigned integers. Reverts with custom message on\n     * division by zero. The result is rounded towards zero.\n     *\n     * Counterpart to Solidity's `/` operator. Note: this function uses a\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\n     * uses an invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function div(uint128 a, uint128 b, string memory errorMessage) internal pure returns (uint128) {\n        require(b > 0, errorMessage);\n        uint128 c = a / b;\n        // assert(a == b * c + a % b); // There is no case in which this doesn't hold\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n     * Reverts when dividing by zero.\n     *\n     * Counterpart to Solidity's `%` operator. This function uses a `revert`\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\n     * invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function mod(uint128 a, uint128 b) internal pure returns (uint128) {\n        return mod(a, b, \"SafeMath: modulo by zero\");\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n     * Reverts with custom message when dividing by zero.\n     *\n     * Counterpart to Solidity's `%` operator. This function uses a `revert`\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\n     * invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function mod(uint128 a, uint128 b, string memory errorMessage) internal pure returns (uint128) {\n        require(b != 0, errorMessage);\n        return a % b;\n    }\n}\n"
      }
    },
    "settings": {
      "optimizer": {
        "enabled": true,
        "runs": 200
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "libraries": {}
    }
  }}