ETH Price: $3,388.57 (-0.96%)

Contract

0xc2Ba6B8E0EE3cf48B045D966F1dCda767df74833
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Remove Collatera...207590622024-09-15 22:39:1172 days ago1726439951IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0 ETH0.000058330.94069182
Add Collateral E...207590512024-09-15 22:36:5972 days ago1726439819IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0.002 ETH0.000069050.9761936
Create Vault207590172024-09-15 22:30:1172 days ago1726439411IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0 ETH0.000097720.96296585
Create Vault195855182024-04-04 22:57:35236 days ago1712271455IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0 ETH0.0016010115.77560142
Create Vault182837542023-10-05 10:36:23418 days ago1696502183IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0 ETH0.000618376.09319003
Remove Collatera...170300952023-04-12 6:15:47594 days ago1681280147IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0 ETH0.0012084919.48426991
Create Vault170126542023-04-09 18:59:23597 days ago1681066763IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0 ETH0.0022847222.51246775
Add Collateral E...169212532023-03-27 21:00:47610 days ago1679950847IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0.015 ETH0.0025453935.98183534
Create Vault169212492023-03-27 20:59:59610 days ago1679950799IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0 ETH0.0030528830.08153812
Create Vault168610182023-03-19 9:56:59618 days ago1679219819IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0 ETH0.0012629212.44421733
Remove Collatera...166980382023-02-24 11:56:59641 days ago1677239819IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0 ETH0.001548224.96616721
Add Collateral E...166630342023-02-19 13:49:11646 days ago1676814551IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0.001 ETH0.0019225427.1772326
Create Vault166630292023-02-19 13:48:11646 days ago1676814491IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0 ETH0.0027999227.58897837
Add Collateral E...166579462023-02-18 20:40:11647 days ago1676752811IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0.0001 ETH0.0015510321.9254996
Create Vault166579382023-02-18 20:38:35647 days ago1676752715IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0 ETH0.0020625420.32323396
Remove Collatera...166554192023-02-18 12:07:47647 days ago1676722067IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0 ETH0.0030901849.82239748
Add Collateral E...166554072023-02-18 12:05:23647 days ago1676721923IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0.005 ETH0.0029901842.26943432
Create Vault166554022023-02-18 12:04:23647 days ago1676721863IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0 ETH0.0044581143.92791766
Add Collateral E...166549292023-02-18 10:28:47647 days ago1676716127IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0.01 ETH0.0014399920.35583969
Create Vault166549252023-02-18 10:27:59647 days ago1676716079IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0 ETH0.0021639221.32217922
Create Vault166548722023-02-18 10:16:47647 days ago1676715407IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0 ETH0.0020373620.07517495
Add Collateral E...166521172023-02-18 0:58:11648 days ago1676681891IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0.001 ETH0.0025354435.84121611
Create Vault166521162023-02-18 0:57:59648 days ago1676681879IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0 ETH0.0009753837.8277027
Create Vault166521132023-02-18 0:57:23648 days ago1676681843IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0 ETH0.0042032941.41704739
Create Vault166510422023-02-17 21:19:35648 days ago1676668775IN
Cryptex Finance: TCAP Hard ETH Vault Handler
0 ETH0.0047172946.48180685
View all transactions

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block From To
207590622024-09-15 22:39:1172 days ago1726439951
Cryptex Finance: TCAP Hard ETH Vault Handler
0.002 ETH
207590622024-09-15 22:39:1172 days ago1726439951
Cryptex Finance: TCAP Hard ETH Vault Handler
0.002 ETH
207590512024-09-15 22:36:5972 days ago1726439819
Cryptex Finance: TCAP Hard ETH Vault Handler
0.002 ETH
206954082024-09-07 1:23:3581 days ago1725672215
Cryptex Finance: TCAP Hard ETH Vault Handler
0.00001355 ETH
206954082024-09-07 1:23:3581 days ago1725672215
Cryptex Finance: TCAP Hard ETH Vault Handler
0.00135584 ETH
206954082024-09-07 1:23:3581 days ago1725672215
Cryptex Finance: TCAP Hard ETH Vault Handler
0.0013694 ETH
170300952023-04-12 6:15:47594 days ago1681280147
Cryptex Finance: TCAP Hard ETH Vault Handler
0.015 ETH
170300952023-04-12 6:15:47594 days ago1681280147
Cryptex Finance: TCAP Hard ETH Vault Handler
0.015 ETH
169212532023-03-27 21:00:47610 days ago1679950847
Cryptex Finance: TCAP Hard ETH Vault Handler
0.015 ETH
166980382023-02-24 11:56:59641 days ago1677239819
Cryptex Finance: TCAP Hard ETH Vault Handler
0.01 ETH
166980382023-02-24 11:56:59641 days ago1677239819
Cryptex Finance: TCAP Hard ETH Vault Handler
0.01 ETH
166630342023-02-19 13:49:11646 days ago1676814551
Cryptex Finance: TCAP Hard ETH Vault Handler
0.001 ETH
166579462023-02-18 20:40:11647 days ago1676752811
Cryptex Finance: TCAP Hard ETH Vault Handler
0.0001 ETH
166554192023-02-18 12:07:47647 days ago1676722067
Cryptex Finance: TCAP Hard ETH Vault Handler
0.005 ETH
166554192023-02-18 12:07:47647 days ago1676722067
Cryptex Finance: TCAP Hard ETH Vault Handler
0.005 ETH
166554072023-02-18 12:05:23647 days ago1676721923
Cryptex Finance: TCAP Hard ETH Vault Handler
0.005 ETH
166549292023-02-18 10:28:47647 days ago1676716127
Cryptex Finance: TCAP Hard ETH Vault Handler
0.01 ETH
166521172023-02-18 0:58:11648 days ago1676681891
Cryptex Finance: TCAP Hard ETH Vault Handler
0.001 ETH
166496722023-02-17 16:41:11648 days ago1676652071
Cryptex Finance: TCAP Hard ETH Vault Handler
0.001 ETH
166465692023-02-17 6:11:11648 days ago1676614271
Cryptex Finance: TCAP Hard ETH Vault Handler
0.0001 ETH
166409342023-02-16 11:16:47649 days ago1676546207
Cryptex Finance: TCAP Hard ETH Vault Handler
0.001 ETH
166409342023-02-16 11:16:47649 days ago1676546207
Cryptex Finance: TCAP Hard ETH Vault Handler
0.001 ETH
166409002023-02-16 11:09:47649 days ago1676545787
Cryptex Finance: TCAP Hard ETH Vault Handler
0.001 ETH
166408262023-02-16 10:54:47649 days ago1676544887
Cryptex Finance: TCAP Hard ETH Vault Handler
0.0005 ETH
166393612023-02-16 5:59:23649 days ago1676527163
Cryptex Finance: TCAP Hard ETH Vault Handler
0.001 ETH
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
ETHVaultHandler

Compiler Version
v0.7.5+commit.eb77ed08

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, MIT license
File 1 of 23 : ETHVaultHandler.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.7.5;

import "./IVaultHandler.sol";
import "./Orchestrator.sol";
import "./IWETH.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";

/**
 * @title ETH TCAP Vault
 * @author Cryptex.finance
 * @notice Contract in charge of handling the TCAP Vault and stake using a ETH and WETH
 */
contract ETHVaultHandler is IVaultHandler {
	/// @notice Open Zeppelin libraries
	using SafeMath for uint256;

	/**
	 * @notice Constructor
   * @param _orchestrator address
   * @param _divisor uint256
   * @param _ratio uint256
   * @param _burnFee uint256
   * @param _liquidationPenalty uint256
   * @param _tcapOracle address
   * @param _tcapAddress address
   * @param _collateralAddress address
   * @param _collateralOracle address
   * @param _ethOracle address
   * @param _treasury address
   * @param _minimumTCAP uint256
   */
	constructor(
		Orchestrator _orchestrator,
		uint256 _divisor,
		uint256 _ratio,
		uint256 _burnFee,
		uint256 _liquidationPenalty,
		address _tcapOracle,
		TCAP _tcapAddress,
		address _collateralAddress,
		address _collateralOracle,
		address _ethOracle,
		address _treasury,
		uint256 _minimumTCAP
	)
	IVaultHandler(
		_orchestrator,
		_divisor,
		_ratio,
		_burnFee,
		_liquidationPenalty,
		_tcapOracle,
		_tcapAddress,
		_collateralAddress,
		_collateralOracle,
		_ethOracle,
		_treasury,
		_minimumTCAP
	)
	{}

	/**
	 * @notice only accept ETH via fallback from the WETH contract
   */
	receive() external payable {
		assert(msg.sender == address(collateralContract));
	}

	/**
	 * @notice Adds collateral to vault using ETH
   * @dev value should be higher than 0
   * @dev ETH is turned into WETH
   */
	function addCollateralETH()
	external
	payable
	nonReentrant
	vaultExists
	whenNotPaused
	{
		require(
			msg.value > 0,
			"ETHVaultHandler::addCollateralETH: value can't be 0"
		);
		IWETH(address(collateralContract)).deposit{value : msg.value}();
		Vault storage vault = vaults[userToVault[msg.sender]];
		vault.Collateral = vault.Collateral.add(msg.value);
		emit CollateralAdded(msg.sender, vault.Id, msg.value);
	}

	/**
	 * @notice Removes not used collateral from vault
   * @param _amount of collateral to remove
   * @dev _amount should be higher than 0
   * @dev WETH is turned into ETH
   */
	function removeCollateralETH(uint256 _amount)
	external
	nonReentrant
	vaultExists
	whenNotPaused
	{
		require(
			_amount > 0,
			"ETHVaultHandler::removeCollateralETH: value can't be 0"
		);
		Vault storage vault = vaults[userToVault[msg.sender]];
		uint256 currentRatio = getVaultRatio(vault.Id);
		require(
			vault.Collateral >= _amount,
			"ETHVaultHandler::removeCollateralETH: retrieve amount higher than collateral"
		);
		vault.Collateral = vault.Collateral.sub(_amount);
		if (currentRatio != 0) {
			require(
				getVaultRatio(vault.Id) >= ratio,
				"ETHVaultHandler::removeCollateralETH: collateral below min required ratio"
			);
		}

		IWETH(address(collateralContract)).withdraw(_amount);
		safeTransferETH(msg.sender, _amount);
		emit CollateralRemoved(msg.sender, vault.Id, _amount);
	}
}

File 2 of 23 : AggregatorV3Interface.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;

interface AggregatorV3Interface {

  function decimals() external view returns (uint8);
  function description() external view returns (string memory);
  function version() external view returns (uint256);

  // getRoundData and latestRoundData should both raise "No data present"
  // if they do not have data to report, instead of returning unset values
  // which could be misinterpreted as actual reported values.
  function getRoundData(uint80 _roundId)
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );
  function latestRoundData()
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );

}

File 3 of 23 : Context.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

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

File 4 of 23 : AccessControl.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../utils/EnumerableSet.sol";
import "../utils/Address.sol";
import "../GSN/Context.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it.
 */
abstract contract AccessControl is Context {
    using EnumerableSet for EnumerableSet.AddressSet;
    using Address for address;

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

    mapping (bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

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

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

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

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

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

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

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

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) public virtual {
        require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to grant");

        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) public virtual {
        require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to revoke");

        _revokeRole(role, account);
    }

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

        _revokeRole(role, account);
    }

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

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

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

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

File 5 of 23 : Ownable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../GSN/Context.sol";
/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor () internal {
        address msgSender = _msgSender();
        _owner = msgSender;
        emit OwnershipTransferred(address(0), msgSender);
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(_owner == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        emit OwnershipTransferred(_owner, address(0));
        _owner = address(0);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
}

File 6 of 23 : ERC165Checker.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

/**
 * @dev Library used to query support of an interface declared via {IERC165}.
 *
 * Note that these functions return the actual result of the query: they do not
 * `revert` if an interface is not supported. It is up to the caller to decide
 * what to do in these cases.
 */
library ERC165Checker {
    // As per the EIP-165 spec, no interface should ever match 0xffffffff
    bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff;

    /*
     * bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7
     */
    bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;

    /**
     * @dev Returns true if `account` supports the {IERC165} interface,
     */
    function supportsERC165(address account) internal view returns (bool) {
        // Any contract that implements ERC165 must explicitly indicate support of
        // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid
        return _supportsERC165Interface(account, _INTERFACE_ID_ERC165) &&
            !_supportsERC165Interface(account, _INTERFACE_ID_INVALID);
    }

    /**
     * @dev Returns true if `account` supports the interface defined by
     * `interfaceId`. Support for {IERC165} itself is queried automatically.
     *
     * See {IERC165-supportsInterface}.
     */
    function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {
        // query support of both ERC165 as per the spec and support of _interfaceId
        return supportsERC165(account) &&
            _supportsERC165Interface(account, interfaceId);
    }

    /**
     * @dev Returns true if `account` supports all the interfaces defined in
     * `interfaceIds`. Support for {IERC165} itself is queried automatically.
     *
     * Batch-querying can lead to gas savings by skipping repeated checks for
     * {IERC165} support.
     *
     * See {IERC165-supportsInterface}.
     */
    function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {
        // query support of ERC165 itself
        if (!supportsERC165(account)) {
            return false;
        }

        // query support of each interface in _interfaceIds
        for (uint256 i = 0; i < interfaceIds.length; i++) {
            if (!_supportsERC165Interface(account, interfaceIds[i])) {
                return false;
            }
        }

        // all interfaces supported
        return true;
    }

    /**
     * @notice Query if a contract implements an interface, does not check ERC165 support
     * @param account The address of the contract to query for support of an interface
     * @param interfaceId The interface identifier, as specified in ERC-165
     * @return true if the contract at account indicates support of the interface with
     * identifier interfaceId, false otherwise
     * @dev Assumes that account contains a contract that supports ERC165, otherwise
     * the behavior of this method is undefined. This precondition can be checked
     * with {supportsERC165}.
     * Interface identification is specified in ERC-165.
     */
    function _supportsERC165Interface(address account, bytes4 interfaceId) private view returns (bool) {
        // success determines whether the staticcall succeeded and result determines
        // whether the contract at account indicates support of _interfaceId
        (bool success, bool result) = _callERC165SupportsInterface(account, interfaceId);

        return (success && result);
    }

    /**
     * @notice Calls the function with selector 0x01ffc9a7 (ERC165) and suppresses throw
     * @param account The address of the contract to query for support of an interface
     * @param interfaceId The interface identifier, as specified in ERC-165
     * @return success true if the STATICCALL succeeded, false otherwise
     * @return result true if the STATICCALL succeeded and the contract at account
     * indicates support of the interface with identifier interfaceId, false otherwise
     */
    function _callERC165SupportsInterface(address account, bytes4 interfaceId)
        private
        view
        returns (bool, bool)
    {
        bytes memory encodedParams = abi.encodeWithSelector(_INTERFACE_ID_ERC165, interfaceId);
        (bool success, bytes memory result) = account.staticcall{ gas: 30000 }(encodedParams);
        if (result.length < 32) return (false, false);
        return (success, abi.decode(result, (bool)));
    }
}

File 7 of 23 : IERC165.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

File 8 of 23 : Math.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

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

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

File 9 of 23 : SafeMath.sol
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

        return c;
    }

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

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

        return c;
    }

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

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

        return c;
    }

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

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

        return c;
    }

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

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

File 10 of 23 : ERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../../GSN/Context.sol";
import "./IERC20.sol";
import "../../math/SafeMath.sol";

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

    mapping (address => uint256) private _balances;

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

    uint256 private _totalSupply;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        _beforeTokenTransfer(sender, recipient, amount);

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

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

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

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

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

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

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

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

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

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

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

File 11 of 23 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

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

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

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

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

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

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

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

File 12 of 23 : SafeERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

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

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

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

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

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

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

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

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

File 13 of 23 : Address.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

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

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

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

        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
        (bool success, ) = recipient.call{ value: amount }("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

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

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

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

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

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

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

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

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

    function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

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

File 14 of 23 : Counters.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../math/SafeMath.sol";

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

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

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

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

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

File 15 of 23 : EnumerableSet.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;

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

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

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

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

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

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

            bytes32 lastvalue = set._values[lastIndex];

            // Move the last value to the index where the value to delete is
            set._values[toDeleteIndex] = lastvalue;
            // Update the index for the moved value
            set._indexes[lastvalue] = toDeleteIndex + 1; // All indexes are 1-based

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

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

            return true;
        } else {
            return false;
        }
    }

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

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

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

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

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

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

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

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

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

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

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

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

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

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

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


    // UintSet

    struct UintSet {
        Set _inner;
    }

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

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

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

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

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

File 16 of 23 : Pausable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../GSN/Context.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

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

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor () internal {
        _paused = false;
    }

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

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

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

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

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

File 17 of 23 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

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

    uint256 private _status;

    constructor () internal {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and make it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

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

        _;

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

File 18 of 23 : SafeCast.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;


/**
 * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 *
 * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
 * all math on `uint256` and `int256` and then downcasting.
 */
library SafeCast {

    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        require(value < 2**128, "SafeCast: value doesn\'t fit in 128 bits");
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint64 from uint256, reverting on
     * overflow (when the input is greater than largest uint64).
     *
     * Counterpart to Solidity's `uint64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        require(value < 2**64, "SafeCast: value doesn\'t fit in 64 bits");
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint32 from uint256, reverting on
     * overflow (when the input is greater than largest uint32).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        require(value < 2**32, "SafeCast: value doesn\'t fit in 32 bits");
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint16 from uint256, reverting on
     * overflow (when the input is greater than largest uint16).
     *
     * Counterpart to Solidity's `uint16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        require(value < 2**16, "SafeCast: value doesn\'t fit in 16 bits");
        return uint16(value);
    }

    /**
     * @dev Returns the downcasted uint8 from uint256, reverting on
     * overflow (when the input is greater than largest uint8).
     *
     * Counterpart to Solidity's `uint8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits.
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        require(value < 2**8, "SafeCast: value doesn\'t fit in 8 bits");
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        require(value >= 0, "SafeCast: value must be positive");
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v3.1._
     */
    function toInt128(int256 value) internal pure returns (int128) {
        require(value >= -2**127 && value < 2**127, "SafeCast: value doesn\'t fit in 128 bits");
        return int128(value);
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v3.1._
     */
    function toInt64(int256 value) internal pure returns (int64) {
        require(value >= -2**63 && value < 2**63, "SafeCast: value doesn\'t fit in 64 bits");
        return int64(value);
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v3.1._
     */
    function toInt32(int256 value) internal pure returns (int32) {
        require(value >= -2**31 && value < 2**31, "SafeCast: value doesn\'t fit in 32 bits");
        return int32(value);
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v3.1._
     */
    function toInt16(int256 value) internal pure returns (int16) {
        require(value >= -2**15 && value < 2**15, "SafeCast: value doesn\'t fit in 16 bits");
        return int16(value);
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits.
     *
     * _Available since v3.1._
     */
    function toInt8(int256 value) internal pure returns (int8) {
        require(value >= -2**7 && value < 2**7, "SafeCast: value doesn\'t fit in 8 bits");
        return int8(value);
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        require(value < 2**255, "SafeCast: value doesn't fit in an int256");
        return int256(value);
    }
}

File 19 of 23 : IVaultHandler.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.7.5;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/math/Math.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/SafeCast.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/Pausable.sol";
import "@openzeppelin/contracts/introspection/IERC165.sol";
import "./TCAP.sol";
import "./Orchestrator.sol";
import "./oracles/ChainlinkOracle.sol";

/**
 * @title TCAP Vault Handler Abstract Contract
 * @author Cryptex.Finance
 * @notice Contract in charge of handling the TCAP Token and stake
 */
abstract contract IVaultHandler is
Ownable,
AccessControl,
ReentrancyGuard,
Pausable,
IERC165
{
	/// @notice Open Zeppelin libraries
	using SafeMath for uint256;
	using SafeCast for int256;
	using Counters for Counters.Counter;
	using SafeERC20 for IERC20;

	/**
	 * @notice Vault object created to manage the mint and burns of TCAP tokens
   * @param Id, unique identifier of the vault
   * @param Collateral, current collateral on vault
   * @param Debt, current amount of TCAP tokens minted
   * @param Owner, owner of the vault
   */
	struct Vault {
		uint256 Id;
		uint256 Collateral;
		uint256 Debt;
		address Owner;
	}

	/// @notice Vault Id counter
	Counters.Counter public counter;

	/// @notice value used to divide collateral to adjust the decimal places
	uint256 public immutable collateralDecimalsAdjustmentFactor;

	/// @notice TCAP Token Address
	TCAP public immutable TCAPToken;

	/// @notice Total Market Cap/USD Oracle Address
	ChainlinkOracle public immutable tcapOracle;

	/// @notice Collateral Token Address
	IERC20 public immutable collateralContract;

	/// @notice Collateral/USD Oracle Address
	ChainlinkOracle public immutable collateralPriceOracle;

	/// @notice ETH/USD Oracle Address
	ChainlinkOracle public immutable ETHPriceOracle;

	/// @notice Value used as divisor with the total market cap, just like the S&P 500 or any major financial index would to define the final tcap token price
	uint256 public divisor;

	/// @notice Minimum ratio required to prevent liquidation of vault
	uint256 public ratio;

	/// @notice Fee percentage of the total amount to burn charged on ETH when burning TCAP Tokens
	uint256 public burnFee;

	/// @notice Penalty charged to vault owner when a vault is liquidated, this value goes to the liquidator
	uint256 public liquidationPenalty;

	/// @notice Minimum amount of TCAP an user can mint
	uint256 public minimumTCAP = 0;

	/// @notice Address of the treasury contract (usually the timelock) where the funds generated by the protocol are sent
	address public treasury;

	/// @notice Owner address to Vault Id
	mapping(address => uint256) public userToVault;

	/// @notice Id To Vault
	mapping(uint256 => Vault) public vaults;

	/// @notice value used to multiply chainlink oracle for handling decimals
	uint256 public constant oracleDigits = 10000000000;

	/// @notice Maximum decimal places that are supported by the collateral
	uint8 public constant MAX_DECIMAL_PLACES = 18;

	/// @notice Minimum value that the ratio can be set to
	uint256 public constant MIN_RATIO = 100;

	/// @notice Maximum value that the burn fee can be set to, the fee has two decimals, so it's multiplied by 100
	uint256 public constant MAX_FEE = 1000; /// max fee 10%

	/**
	 * @dev the computed interface ID according to ERC-165. The interface ID is a XOR of interface method selectors.
   * setRatio.selector ^
   * setBurnFee.selector ^
   * setLiquidationPenalty.selector ^
   * pause.selector ^
   * unpause.selector =>  0x9e75ab0c
   */
	bytes4 private constant _INTERFACE_ID_IVAULT = 0x9e75ab0c;

	/// @dev bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7
	bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;

	/// @notice An event emitted when the ratio is updated
	event NewRatio(address indexed _owner, uint256 _ratio);

	/// @notice An event emitted when the burn fee is updated
	event NewBurnFee(address indexed _owner, uint256 _burnFee);

	/// @notice An event emitted when the liquidation penalty is updated
	event NewLiquidationPenalty(
		address indexed _owner,
		uint256 _liquidationPenalty
	);

	/// @notice An event emitted when the minimum required TCAP is updated
	event NewMinimumTCAP(
		address indexed _owner,
		uint256 _minimumTCAP
	);

	/// @notice An event emitted when the treasury contract is updated
	event NewTreasury(address indexed _owner, address _tresury);

	/// @notice An event emitted when a vault is created
	event VaultCreated(address indexed _owner, uint256 indexed _id);

	/// @notice An event emitted when collateral is added to a vault
	event CollateralAdded(
		address indexed _owner,
		uint256 indexed _id,
		uint256 _amount
	);

	/// @notice An event emitted when collateral is removed from a vault
	event CollateralRemoved(
		address indexed _owner,
		uint256 indexed _id,
		uint256 _amount
	);

	/// @notice An event emitted when tokens are minted
	event TokensMinted(
		address indexed _owner,
		uint256 indexed _id,
		uint256 _amount
	);

	/// @notice An event emitted when tokens are burned
	event TokensBurned(
		address indexed _owner,
		uint256 indexed _id,
		uint256 _amount
	);

	/// @notice An event emitted when a vault is liquidated
	event VaultLiquidated(
		uint256 indexed _vaultId,
		address indexed _liquidator,
		uint256 _liquidationCollateral,
		uint256 _reward
	);

	/// @notice An event emitted when a erc20 token is recovered
	event Recovered(address _token, uint256 _amount);

	/**
	 * @notice Constructor
   * @param _orchestrator address
   * @param _divisor uint256
   * @param _ratio uint256
   * @param _burnFee uint256
   * @param _liquidationPenalty uint256
   * @param _tcapOracle address
   * @param _tcapAddress address
   * @param _collateralAddress address
   * @param _collateralOracle address
   * @param _ethOracle address
   * @param _treasury address
   * @param _minimumTCAP uint256
   */
	constructor(
		Orchestrator _orchestrator,
		uint256 _divisor,
		uint256 _ratio,
		uint256 _burnFee,
		uint256 _liquidationPenalty,
		address _tcapOracle,
		TCAP _tcapAddress,
		address _collateralAddress,
		address _collateralOracle,
		address _ethOracle,
		address _treasury,
		uint256 _minimumTCAP
	) {
		require(
			_liquidationPenalty.add(100) < _ratio,
			"VaultHandler::constructor: liquidation penalty too high"
		);
		require(
			_ratio >= MIN_RATIO,
			"VaultHandler::constructor: ratio lower than MIN_RATIO"
		);

		require(
			_burnFee <= MAX_FEE,
			"VaultHandler::constructor: burn fee higher than MAX_FEE"
		);

		divisor = _divisor;
		ratio = _ratio;
		burnFee = _burnFee;
		liquidationPenalty = _liquidationPenalty;
		tcapOracle = ChainlinkOracle(_tcapOracle);
		collateralContract = IERC20(_collateralAddress);
		collateralPriceOracle = ChainlinkOracle(_collateralOracle);
		ETHPriceOracle = ChainlinkOracle(_ethOracle);
		TCAPToken = _tcapAddress;
		treasury = _treasury;
		minimumTCAP = _minimumTCAP;
		uint8 _collateralDecimals = ERC20(_collateralAddress).decimals();
		require(
			_collateralDecimals <= MAX_DECIMAL_PLACES,
			"Collateral decimals greater than MAX_DECIMAL_PLACES"
		);
		collateralDecimalsAdjustmentFactor = 10 ** (MAX_DECIMAL_PLACES - _collateralDecimals);

		/// @dev counter starts in 1 as 0 is reserved for empty objects
		counter.increment();

		/// @dev transfer ownership to orchestrator
		_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
		transferOwnership(address(_orchestrator));
	}

	/// @notice Reverts if the user hasn't created a vault.
	modifier vaultExists() {
		require(
			userToVault[msg.sender] != 0,
			"VaultHandler::vaultExists: no vault created"
		);
		_;
	}

	/// @notice Reverts if value is 0.
	modifier notZero(uint256 _value) {
		require(_value != 0, "VaultHandler::notZero: value can't be 0");
		_;
	}

	/**
	 * @notice Sets the collateral ratio needed to mint tokens
   * @param _ratio uint
   * @dev Only owner can call it
   */
	function setRatio(uint256 _ratio) external virtual onlyOwner {
		require(
			_ratio >= MIN_RATIO,
			"VaultHandler::setRatio: ratio lower than MIN_RATIO"
		);
		require(
			liquidationPenalty.add(100) < _ratio,
			"VaultHandler::setRatio: liquidation penalty too high"
		);

		ratio = _ratio;
		emit NewRatio(msg.sender, _ratio);
	}

	/**
	 * @notice Sets the burn fee percentage an user pays when burning tcap tokens
   * @param _burnFee uint
   * @dev Only owner can call it
   */
	function setBurnFee(uint256 _burnFee) external virtual onlyOwner {
		require(
			_burnFee <= MAX_FEE,
			"VaultHandler::setBurnFee: burn fee higher than MAX_FEE"
		);
		burnFee = _burnFee;
		emit NewBurnFee(msg.sender, _burnFee);
	}

	/**
	 * @notice Sets the liquidation penalty % charged on liquidation
   * @param _liquidationPenalty uint
   * @dev Only owner can call it
   * @dev recommended value is between 1-15% and can't be above 100%
   */
	function setLiquidationPenalty(uint256 _liquidationPenalty)
	external
	virtual
	onlyOwner
	{
		require(
			_liquidationPenalty.add(100) < ratio,
			"VaultHandler::setLiquidationPenalty: liquidation penalty too high"
		);

		liquidationPenalty = _liquidationPenalty;
		emit NewLiquidationPenalty(msg.sender, _liquidationPenalty);
	}

	/**
	 * @notice Sets the minimum TCAP a vault owner can mint
   * @param _minimumTCAP uint
   * @dev Only owner can call it
   * @dev this is mostly used on hard mode vaults with low collateral ratio vaults
   */
	function setMinimumTCAP(uint256 _minimumTCAP)
	external
	virtual
	onlyOwner
	{
		minimumTCAP = _minimumTCAP;
		emit NewMinimumTCAP(msg.sender, _minimumTCAP);
	}

	/**
	 * @notice Sets the treasury contract address where fees are transferred to
   * @param _treasury address
   * @dev Only owner can call it
   */
	function setTreasury(address _treasury) external virtual onlyOwner {
		require(
			_treasury != address(0),
			"VaultHandler::setTreasury: not a valid treasury"
		);
		treasury = _treasury;
		emit NewTreasury(msg.sender, _treasury);
	}

	/**
	 * @notice Allows an user to create an unique Vault
   * @dev Only one vault per address can be created
   */
	function createVault() external virtual whenNotPaused {
		require(
			userToVault[msg.sender] == 0,
			"VaultHandler::createVault: vault already created"
		);

		uint256 id = counter.current();
		userToVault[msg.sender] = id;
		Vault memory vault = Vault(id, 0, 0, msg.sender);
		vaults[id] = vault;
		counter.increment();
		emit VaultCreated(msg.sender, id);
	}

	/**
	 * @notice Allows users to add collateral to their vaults
   * @param _amount of collateral to be added
   * @dev _amount should be higher than 0
   * @dev ERC20 token must be approved first
   */
	function addCollateral(uint256 _amount)
	external
	virtual
	nonReentrant
	vaultExists
	whenNotPaused
	notZero(_amount)
	{
		require(
			collateralContract.transferFrom(msg.sender, address(this), _amount),
			"VaultHandler::addCollateral: ERC20 transfer did not succeed"
		);

		Vault storage vault = vaults[userToVault[msg.sender]];
		vault.Collateral = vault.Collateral.add(_amount);
		emit CollateralAdded(msg.sender, vault.Id, _amount);
	}

	/**
	 * @notice Allows users to remove collateral currently not being used to generate TCAP tokens from their vaults
   * @param _amount of collateral to remove
   * @dev reverts if the resulting ratio is less than the minimum ratio
   * @dev _amount should be higher than 0
   * @dev transfers the collateral back to the user
   */
	function removeCollateral(uint256 _amount)
	external
	virtual
	nonReentrant
	vaultExists
	whenNotPaused
	notZero(_amount)
	{
		Vault storage vault = vaults[userToVault[msg.sender]];
		uint256 currentRatio = getVaultRatio(vault.Id);

		require(
			vault.Collateral >= _amount,
			"VaultHandler::removeCollateral: retrieve amount higher than collateral"
		);

		vault.Collateral = vault.Collateral.sub(_amount);
		if (currentRatio != 0) {
			require(
				getVaultRatio(vault.Id) >= ratio,
				"VaultHandler::removeCollateral: collateral below min required ratio"
			);
		}
		require(
			collateralContract.transfer(msg.sender, _amount),
			"VaultHandler::removeCollateral: ERC20 transfer did not succeed"
		);
		emit CollateralRemoved(msg.sender, vault.Id, _amount);
	}

	/**
	 * @notice Uses collateral to generate debt on TCAP Tokens which are minted and assigned to caller
   * @param _amount of tokens to mint
   * @dev _amount should be higher than 0
   * @dev requires to have a vault ratio above the minimum ratio
   * @dev if reward handler is set stake to earn rewards
   */
	function mint(uint256 _amount)
	external
	virtual
	nonReentrant
	vaultExists
	whenNotPaused
	notZero(_amount)
	{
		Vault storage vault = vaults[userToVault[msg.sender]];
		uint256 collateral = requiredCollateral(_amount);

		require(
			vault.Collateral >= collateral,
			"VaultHandler::mint: not enough collateral"
		);

		vault.Debt = vault.Debt.add(_amount);

		require(
			getVaultRatio(vault.Id) >= ratio,
			"VaultHandler::mint: collateral below min required ratio"
		);

		require(vault.Debt >= minimumTCAP, "VaultHandler::mint: mint amount less than required");

		TCAPToken.mint(msg.sender, _amount);
		emit TokensMinted(msg.sender, vault.Id, _amount);
	}

	/**
	 * @notice Pays the debt of TCAP tokens resulting them on burn, this releases collateral up to minimum vault ratio
   * @param _amount of tokens to burn
   * @dev _amount should be higher than 0
   * @dev A fee of exactly burnFee must be sent as value on ETH
   * @dev The fee goes to the treasury contract
   * @dev if reward handler is set exit rewards
   */
	function burn(uint256 _amount)
	external
	payable
	virtual
	nonReentrant
	vaultExists
	whenNotPaused
	notZero(_amount)
	{
		uint256 fee = getFee(_amount);
		require(
			msg.value >= fee,
			"VaultHandler::burn: burn fee less than required"
		);

		Vault memory vault = vaults[userToVault[msg.sender]];

		_burn(vault.Id, _amount);
		safeTransferETH(treasury, fee);

		//send back ETH above fee
		safeTransferETH(msg.sender, msg.value.sub(fee));
		emit TokensBurned(msg.sender, vault.Id, _amount);
	}

	/**
	 * @notice Allow users to burn TCAP tokens to liquidate vaults with vault collateral ratio under the minimum ratio, the liquidator receives the staked collateral of the liquidated vault at a premium
   * @param _vaultId to liquidate
   * @param _maxTCAP max amount of TCAP the liquidator is willing to pay to liquidate vault
   * @dev Resulting ratio must be above or equal minimum ratio
   * @dev A fee of exactly burnFee must be sent as value on ETH
   * @dev The fee goes to the treasury contract
   */
	function liquidateVault(uint256 _vaultId, uint256 _maxTCAP)
	external
	payable
	nonReentrant
	whenNotPaused
	{
		Vault storage vault = vaults[_vaultId];
		require(vault.Id != 0, "VaultHandler::liquidateVault: no vault created");

		uint256 vaultRatio = getVaultRatio(vault.Id);
		require(
			vaultRatio < ratio,
			"VaultHandler::liquidateVault: vault is not liquidable"
		);

		uint256 requiredTCAP = requiredLiquidationTCAP(vault.Id);
		require(
			_maxTCAP >= requiredTCAP,
			"VaultHandler::liquidateVault: liquidation amount different than required"
		);

		uint256 fee = getFee(requiredTCAP);
		require(
			msg.value >= fee,
			"VaultHandler::liquidateVault: burn fee less than required"
		);

		uint256 reward = liquidationReward(vault.Id);
		_burn(vault.Id, requiredTCAP);

		//Removes the collateral that is rewarded to liquidator
		vault.Collateral = vault.Collateral.sub(reward);

		require(
			collateralContract.transfer(msg.sender, reward),
			"VaultHandler::liquidateVault: ERC20 transfer did not succeed"
		);
		safeTransferETH(treasury, fee);

		//send back ETH above fee
		safeTransferETH(msg.sender, msg.value.sub(fee));
		emit VaultLiquidated(vault.Id, msg.sender, requiredTCAP, reward);
	}

	/**
	 * @notice Allows the owner to Pause the Contract
   */
	function pause() external onlyOwner {
		_pause();
	}

	/**
	 * @notice Allows the owner to Unpause the Contract
   */
	function unpause() external onlyOwner {
		_unpause();
	}

	/**
	 * @notice  Added to support recovering LP Rewards from other systems such as BAL to be distributed to holders
   * @param _tokenAddress address
   * @param _tokenAmount uint
   * @dev Only owner  can call it
   */
	function recoverERC20(address _tokenAddress, uint256 _tokenAmount)
	external
	onlyOwner
	{
		// Cannot recover the collateral token
		require(
			_tokenAddress != address(collateralContract),
			"Cannot withdraw the collateral tokens"
		);
		IERC20(_tokenAddress).safeTransfer(owner(), _tokenAmount);
		emit Recovered(_tokenAddress, _tokenAmount);
	}

	/**
	 * @notice Allows the safe transfer of ETH
   * @param _to account to transfer ETH
   * @param _value amount of ETH
   */
	function safeTransferETH(address _to, uint256 _value) internal {
		(bool success,) = _to.call{value : _value}(new bytes(0));
		require(success, "IVaultHandler::safeTransferETH: ETH transfer failed");
	}

	/**
	 * @notice ERC165 Standard for support of interfaces
   * @param _interfaceId bytes of interface
   * @return bool
   */
	function supportsInterface(bytes4 _interfaceId)
	external
	pure
	override
	returns (bool)
	{
		return (_interfaceId == _INTERFACE_ID_IVAULT ||
		_interfaceId == _INTERFACE_ID_ERC165);
	}

	/**
	 * @notice Returns the Vault information of specified identifier
   * @param _id of vault
   * @return Id, Collateral, Owner, Debt
   */
	function getVault(uint256 _id)
	external
	view
	virtual
	returns (
		uint256,
		uint256,
		address,
		uint256
	)
	{
		Vault memory vault = vaults[_id];
		return (vault.Id, vault.Collateral, vault.Owner, vault.Debt);
	}

	/**
	 * @notice Returns the price of the chainlink oracle multiplied by the digits to get 18 decimals format
   * @param _oracle to be the price called
   * @return price
   * @dev The price returned here is in USD is equivalent to 1 `ether` unit  times 10 ** 18
   * eg. For ETH This will return the price of USD of 1 ETH * 10 ** 18 and **not** 1 wei * 10 ** 18
   * eg. For DAI This will return the price of USD of 1 DAI * 10 ** 18 and **not** (1 / 10 ** 18) * 10 ** 18
   */
	function getOraclePrice(ChainlinkOracle _oracle)
	public
	view
	virtual
	returns (uint256 price)
	{
		price = _oracle.getLatestAnswer().toUint256().mul(oracleDigits);
	}

	/**
	 * @notice Returns the price of the TCAP token
   * @return price of the TCAP Token
   * @dev TCAP token is 18 decimals
   * @dev oracle totalMarketPrice must be in wei format
   * @dev P = T / d
   * P = TCAP Token Price
   * T = Total Crypto Market Cap
   * d = Divisor
   */
	function TCAPPrice() public view virtual returns (uint256 price) {
		uint256 totalMarketPrice = getOraclePrice(tcapOracle);
		price = totalMarketPrice.div(divisor);
	}

	/**
	 * @notice Returns the minimal required collateral to mint TCAP token
   * @param _amount uint amount to mint
   * @return collateral of the TCAP Token
   * @dev TCAP token is 18 decimals
   * @dev C = ((P * A * r) / 100) / (cp * cdaf)
   * C = Required Collateral
   * P = TCAP Token Price
   * A = Amount to Mint
   * cp = Collateral Price
   * r = Minimum Ratio for Liquidation
   * cdaf = Collateral decimals adjust factor
   */
	function requiredCollateral(uint256 _amount)
	public
	view
	virtual
	returns (uint256 collateral)
	{
		uint256 tcapPrice = TCAPPrice();
		uint256 collateralPrice = getOraclePrice(collateralPriceOracle);
		collateral = ((tcapPrice.mul(_amount).mul(ratio)).div(100)).div(
			collateralPrice
		).div(collateralDecimalsAdjustmentFactor);
	}

	/**
	 * @notice Returns the minimal required TCAP to liquidate a Vault
   * @param _vaultId of the vault to liquidate
   * @return amount required of the TCAP Token
   * @dev LT = ((((D * r) / 100) - cTcap) * 100) / (r - (p + 100))
   * cTcap = ((C * cdaf * cp) / P)
   * LT = Required TCAP
   * D = Vault Debt
   * C = Required Collateral
   * P = TCAP Token Price
   * cdaf = Collateral Decimals adjustment Factor
   * cp = Collateral Price
   * r = Min Vault Ratio
   * p = Liquidation Penalty
   */
	function requiredLiquidationTCAP(uint256 _vaultId)
	public
	view
	virtual
	returns (uint256 amount)
	{
		Vault memory vault = vaults[_vaultId];
		uint256 tcapPrice = TCAPPrice();
		uint256 collateralPrice = getOraclePrice(collateralPriceOracle);
		uint256 collateralTcap = (
		vault.Collateral.mul(collateralDecimalsAdjustmentFactor).mul(collateralPrice)
		).div(tcapPrice);
		uint256 reqDividend =
		(((vault.Debt.mul(ratio)).div(100)).sub(collateralTcap)).mul(100);
		uint256 reqDivisor = ratio.sub(liquidationPenalty.add(100));
		amount = Math.min(vault.Debt, reqDividend.div(reqDivisor));
	}

	/**
	 * @notice Returns the Reward Collateral amount for liquidating a vault
   * @param _vaultId of the vault to liquidate
   * @return rewardCollateral for liquidating Vault
   * @dev the returned value is returned as collateral currency
   * @dev R = (LT * (p  + 100)) / 100
   * @dev RC = R / (cp * cdaf)
   * R = Liquidation Reward
   * RC = Liquidation Reward Collateral
   * LT = Required Liquidation TCAP
   * p = liquidation penalty
   * cp = Collateral Price
   * cdaf = Collateral Decimals adjustment factor
   */
	function liquidationReward(uint256 _vaultId)
	public
	view
	virtual
	returns (uint256 rewardCollateral)
	{
		Vault memory vault = vaults[_vaultId];
		uint256 req = requiredLiquidationTCAP(_vaultId);
		uint256 tcapPrice = TCAPPrice();
		uint256 collateralPrice = getOraclePrice(collateralPriceOracle);
		uint256 reward = (req.mul(liquidationPenalty.add(100)));
		uint256 _rewardCollateral = (
		reward.mul(tcapPrice)
		).div(
			collateralPrice.mul(100)
		).div(collateralDecimalsAdjustmentFactor);
		rewardCollateral = Math.min(vault.Collateral, _rewardCollateral);
	}

	/**
	 * @notice Returns the Collateral Ratio of the Vault
   * @param _vaultId id of vault
   * @return currentRatio
   * @dev vr = (cp * (C * 100 * cdaf)) / D * P
   * vr = Vault Ratio
   * C = Vault Collateral
   * cdaf = Collateral Decimals Adjustment Factor
   * cp = Collateral Price
   * D = Vault Debt
   * P = TCAP Token Price
   */
	function getVaultRatio(uint256 _vaultId)
	public
	view
	virtual
	returns (uint256 currentRatio)
	{
		Vault memory vault = vaults[_vaultId];
		if (vault.Id == 0 || vault.Debt == 0) {
			currentRatio = 0;
		} else {
			uint256 collateralPrice = getOraclePrice(collateralPriceOracle);
			currentRatio = ((
			collateralPrice.mul(vault.Collateral.mul(100).mul(collateralDecimalsAdjustmentFactor)
			)).div(
				vault.Debt.mul(TCAPPrice())
			)
			);
		}
	}

	/**
	 * @notice Returns the required fee of ETH to burn the TCAP tokens
   * @param _amount to burn
   * @return fee
   * @dev The returned value is returned in wei
   * @dev f = (((P * A * b)/ 10000))/ EP
   * f = Burn Fee Value in wei
   * P = TCAP Token Price
   * A = TCAP Amount to Burn
   * b = Burn Fee %
   * EP = ETH Price
   * 10000 = the value is 100 multiplied by 100 to support two decimals on the burn fee
   */
	function getFee(uint256 _amount) public view virtual returns (uint256 fee) {
		uint256 ethPrice = getOraclePrice(ETHPriceOracle);
		fee = (TCAPPrice().mul(_amount).mul(burnFee)).div(10000).div(ethPrice);
	}

	/**
	 * @notice Burns an amount of TCAP Tokens
   * @param _vaultId vault id
   * @param _amount to burn
   */
	function _burn(uint256 _vaultId, uint256 _amount) internal {
		Vault storage vault = vaults[_vaultId];
		require(
			vault.Debt >= _amount,
			"VaultHandler::burn: amount greater than debt"
		);
		vault.Debt = vault.Debt.sub(_amount);
		TCAPToken.burn(msg.sender, _amount);
	}
}

File 20 of 23 : IWETH.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.7.5;

interface IWETH {
	function deposit() external payable;

	function withdraw(uint256) external;

	function totalSupply() external view returns (uint256);

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

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

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

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

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

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

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

File 21 of 23 : Orchestrator.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.7.5;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/introspection/ERC165Checker.sol";
import "./IVaultHandler.sol";
import "./TCAP.sol";
import "./oracles/ChainlinkOracle.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/**
 * @title TCAP Orchestrator
 * @author Cryptex.finance
 * @notice Orchestrator contract in charge of managing the settings of the vaults, rewards and TCAP token. It acts as the owner of these contracts.
 */
contract Orchestrator is Ownable {
	/// @dev Enum which saves the available functions to emergency call.
	enum Functions {BURNFEE, LIQUIDATION, PAUSE}

	/// @notice Address that can set to 0 the fees or pause the vaults in an emergency event
	address public guardian;

	/** @dev Interface constants*/
	bytes4 private constant _INTERFACE_ID_IVAULT = 0x9e75ab0c;
	bytes4 private constant _INTERFACE_ID_TCAP = 0xbd115939;
	bytes4 private constant _INTERFACE_ID_CHAINLINK_ORACLE = 0x85be402b;

	/// @dev tracks which vault was emergency called
	mapping(IVaultHandler => mapping(Functions => bool)) private emergencyCalled;

	/// @notice An event emitted when the guardian is updated
	event GuardianSet(address indexed _owner, address guardian);

	/// @notice An event emitted when a transaction is executed
	event TransactionExecuted(
		address indexed target,
		uint256 value,
		string signature,
		bytes data
	);

	/**
	 * @notice Constructor
   * @param _guardian The guardian address
   */
	constructor(address _guardian) {
		require(
			_guardian != address(0),
			"Orchestrator::constructor: guardian can't be zero"
		);
		guardian = _guardian;
	}

	/// @notice Throws if called by any account other than the guardian
	modifier onlyGuardian() {
		require(
			msg.sender == guardian,
			"Orchestrator::onlyGuardian: caller is not the guardian"
		);
		_;
	}

	/**
	 * @notice Throws if vault is not valid.
   * @param _vault address
   */
	modifier validVault(IVaultHandler _vault) {
		require(
			ERC165Checker.supportsInterface(address(_vault), _INTERFACE_ID_IVAULT),
			"Orchestrator::validVault: not a valid vault"
		);
		_;
	}

	/**
	 * @notice Throws if TCAP Token is not valid
   * @param _tcap address
   */
	modifier validTCAP(TCAP _tcap) {
		require(
			ERC165Checker.supportsInterface(address(_tcap), _INTERFACE_ID_TCAP),
			"Orchestrator::validTCAP: not a valid TCAP ERC20"
		);
		_;
	}

	/**
	 * @notice Throws if Chainlink Oracle is not valid
   * @param _oracle address
   */
	modifier validChainlinkOracle(address _oracle) {
		require(
			ERC165Checker.supportsInterface(
				address(_oracle),
				_INTERFACE_ID_CHAINLINK_ORACLE
			),
			"Orchestrator::validChainlinkOrchestrator: not a valid Chainlink Oracle"
		);
		_;
	}

	/**
	 * @notice Sets the guardian of the orchestrator
   * @param _guardian address of the guardian
   * @dev Only owner can call it
   */
	function setGuardian(address _guardian) external onlyOwner {
		require(
			_guardian != address(0),
			"Orchestrator::setGuardian: guardian can't be zero"
		);
		guardian = _guardian;
		emit GuardianSet(msg.sender, _guardian);
	}

	/**
	 * @notice Sets the ratio of a vault
   * @param _vault address
   * @param _ratio value
   * @dev Only owner can call it
   */
	function setRatio(IVaultHandler _vault, uint256 _ratio)
	external
	onlyOwner
	validVault(_vault)
	{
		_vault.setRatio(_ratio);
	}

	/**
	 * @notice Sets the burn fee of a vault
   * @param _vault address
   * @param _burnFee value
   * @dev Only owner can call it
   */
	function setBurnFee(IVaultHandler _vault, uint256 _burnFee)
	external
	onlyOwner
	validVault(_vault)
	{
		_vault.setBurnFee(_burnFee);
	}

	/**
	 * @notice Sets the burn fee to 0, only used on a black swan event
   * @param _vault address
   * @dev Only guardian can call it
   * @dev Validates if _vault is valid
   */
	function setEmergencyBurnFee(IVaultHandler _vault)
	external
	onlyGuardian
	validVault(_vault)
	{
		require(
			emergencyCalled[_vault][Functions.BURNFEE] != true,
			"Orchestrator::setEmergencyBurnFee: emergency call already used"
		);
		emergencyCalled[_vault][Functions.BURNFEE] = true;
		_vault.setBurnFee(0);
	}

	/**
	 * @notice Sets the liquidation penalty of a vault
   * @param _vault address
   * @param _liquidationPenalty value
   * @dev Only owner can call it
   */
	function setLiquidationPenalty(
		IVaultHandler _vault,
		uint256 _liquidationPenalty
	) external onlyOwner validVault(_vault) {
		_vault.setLiquidationPenalty(_liquidationPenalty);
	}

	/**
	 * @notice Sets the liquidation penalty of a vault to 0, only used on a black swan event
   * @param _vault address
   * @dev Only guardian can call it
   * @dev Validates if _vault is valid
   */
	function setEmergencyLiquidationPenalty(IVaultHandler _vault)
	external
	onlyGuardian
	validVault(_vault)
	{
		require(
			emergencyCalled[_vault][Functions.LIQUIDATION] != true,
			"Orchestrator::setEmergencyLiquidationPenalty: emergency call already used"
		);
		emergencyCalled[_vault][Functions.LIQUIDATION] = true;
		_vault.setLiquidationPenalty(0);
	}

	/**
	 * @notice Pauses the Vault
   * @param _vault address
   * @dev Only guardian can call it
   * @dev Validates if _vault is valid
   */
	function pauseVault(IVaultHandler _vault)
	external
	onlyGuardian
	validVault(_vault)
	{
		require(
			emergencyCalled[_vault][Functions.PAUSE] != true,
			"Orchestrator::pauseVault: emergency call already used"
		);
		emergencyCalled[_vault][Functions.PAUSE] = true;
		_vault.pause();
	}

	/**
	 * @notice Unpauses the Vault
   * @param _vault address
   * @dev Only guardian can call it
   * @dev Validates if _vault is valid
   */
	function unpauseVault(IVaultHandler _vault)
	external
	onlyGuardian
	validVault(_vault)
	{
		_vault.unpause();
	}

	/**
	 * @notice Enables or disables the TCAP Cap
   * @param _tcap address
   * @param _enable bool
   * @dev Only owner can call it
   * @dev Validates if _tcap is valid
   */
	function enableTCAPCap(TCAP _tcap, bool _enable)
	external
	onlyOwner
	validTCAP(_tcap)
	{
		_tcap.enableCap(_enable);
	}

	/**
	 * @notice Sets the TCAP maximum minting value
   * @param _tcap address
   * @param _cap uint value
   * @dev Only owner can call it
   * @dev Validates if _tcap is valid
   */
	function setTCAPCap(TCAP _tcap, uint256 _cap)
	external
	onlyOwner
	validTCAP(_tcap)
	{
		_tcap.setCap(_cap);
	}

	/**
	 * @notice Adds Vault to TCAP ERC20
   * @param _tcap address
   * @param _vault address
   * @dev Only owner can call it
   * @dev Validates if _tcap is valid
   * @dev Validates if _vault is valid
   */
	function addTCAPVault(TCAP _tcap, IVaultHandler _vault)
	external
	onlyOwner
	validTCAP(_tcap)
	validVault(_vault)
	{
		_tcap.addVaultHandler(address(_vault));
	}

	/**
	 * @notice Removes Vault to TCAP ERC20
   * @param _tcap address
   * @param _vault address
   * @dev Only owner can call it
   * @dev Validates if _tcap is valid
   * @dev Validates if _vault is valid
   */
	function removeTCAPVault(TCAP _tcap, IVaultHandler _vault)
	external
	onlyOwner
	validTCAP(_tcap)
	validVault(_vault)
	{
		_tcap.removeVaultHandler(address(_vault));
	}

	/**
	 * @notice Allows the owner to execute custom transactions
   * @param target address
   * @param value uint256
   * @param signature string
   * @param data bytes
   * @dev Only owner can call it
   */
	function executeTransaction(
		address target,
		uint256 value,
		string memory signature,
		bytes memory data
	) external payable onlyOwner returns (bytes memory) {
		bytes memory callData;
		if (bytes(signature).length == 0) {
			callData = data;
		} else {
			callData = abi.encodePacked(bytes4(keccak256(bytes(signature))), data);
		}

		require(
			target != address(0),
			"Orchestrator::executeTransaction: target can't be zero"
		);

		// solium-disable-next-line security/no-call-value
		(bool success, bytes memory returnData) =
		target.call{value : value}(callData);
		require(
			success,
			"Orchestrator::executeTransaction: Transaction execution reverted."
		);

		emit TransactionExecuted(target, value, signature, data);
		(target, value, signature, data);

		return returnData;
	}

	/**
	 * @notice Retrieves the eth stuck on the orchestrator
   * @param _to address
   * @dev Only owner can call it
   */
	function retrieveETH(address _to) external onlyOwner {
		require(
			_to != address(0),
			"Orchestrator::retrieveETH: address can't be zero"
		);
		uint256 amount = address(this).balance;
		payable(_to).transfer(amount);
	}

	/// @notice Allows the contract to receive ETH
	receive() external payable {}
}

File 22 of 23 : TCAP.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.7.5;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/introspection/IERC165.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "./Orchestrator.sol";

/**
 * @title Total Market Cap Token
 * @author Cryptex.finance
 * @notice ERC20 token on the Ethereum Blockchain that provides total exposure to the cryptocurrency sector.
 */
contract TCAP is ERC20, Ownable, IERC165 {
	/// @notice Open Zeppelin libraries
	using SafeMath for uint256;

	/// @notice if enabled TCAP can't be minted if the total supply is above or equal the cap value
	bool public capEnabled = false;

	/// @notice Maximum value the total supply of TCAP
	uint256 public cap;

	/**
	 * @notice Address to Vault Handler
   * @dev Only vault handlers can mint and burn TCAP
   */
	mapping(address => bool) public vaultHandlers;

	/**
	 * @dev the computed interface ID according to ERC-165. The interface ID is a XOR of interface method selectors.
   * mint.selector ^
   * burn.selector ^
   * setCap.selector ^
   * enableCap.selector ^
   * transfer.selector ^
   * transferFrom.selector ^
   * addVaultHandler.selector ^
   * removeVaultHandler.selector ^
   * approve.selector => 0xbd115939
   */
	bytes4 private constant _INTERFACE_ID_TCAP = 0xbd115939;

	/// @dev bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7
	bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;

	/// @notice An event emitted when a vault handler is added
	event VaultHandlerAdded(
		address indexed _owner,
		address indexed _tokenHandler
	);

	/// @notice An event emitted when a vault handler is removed
	event VaultHandlerRemoved(
		address indexed _owner,
		address indexed _tokenHandler
	);

	/// @notice An event emitted when the cap value is updated
	event NewCap(address indexed _owner, uint256 _amount);

	/// @notice An event emitted when the cap is enabled or disabled
	event NewCapEnabled(address indexed _owner, bool _enable);

	/**
	 * @notice Constructor
   * @param _name uint256
   * @param _symbol uint256
   * @param _cap uint256
   * @param _orchestrator address
   */
	constructor(
		string memory _name,
		string memory _symbol,
		uint256 _cap,
		Orchestrator _orchestrator
	) ERC20(_name, _symbol) {
		cap = _cap;

		/// @dev transfer ownership to orchestrator
		transferOwnership(address(_orchestrator));
	}

	/// @notice Reverts if called by any account that is not a vault.
	modifier onlyVault() {
		require(
			vaultHandlers[msg.sender],
			"TCAP::onlyVault: caller is not a vault"
		);
		_;
	}

	/**
	 * @notice Adds a new address as a vault
   * @param _vaultHandler address of a contract with permissions to mint and burn tokens
   * @dev Only owner can call it
   */
	function addVaultHandler(address _vaultHandler) external onlyOwner {
		vaultHandlers[_vaultHandler] = true;
		emit VaultHandlerAdded(msg.sender, _vaultHandler);
	}

	/**
	 * @notice Removes an address as a vault
   * @param _vaultHandler address of the contract to be removed as vault
   * @dev Only owner can call it
   */
	function removeVaultHandler(address _vaultHandler) external onlyOwner {
		vaultHandlers[_vaultHandler] = false;
		emit VaultHandlerRemoved(msg.sender, _vaultHandler);
	}

	/**
	 * @notice Mints TCAP Tokens
   * @param _account address of the receiver of tokens
   * @param _amount uint of tokens to mint
   * @dev Only vault can call it
   */
	function mint(address _account, uint256 _amount) external onlyVault {
		_mint(_account, _amount);
	}

	/**
	 * @notice Burns TCAP Tokens
   * @param _account address of the account which is burning tokens.
   * @param _amount uint of tokens to burn
   * @dev Only vault can call it
   */
	function burn(address _account, uint256 _amount) external onlyVault {
		_burn(_account, _amount);
	}

	/**
	 * @notice Sets maximum value the total supply of TCAP can have
   * @param _cap value
   * @dev When capEnabled is true, mint is not allowed to issue tokens that would increase the total supply above or equal the specified capacity.
   * @dev Only owner can call it
   */
	function setCap(uint256 _cap) external onlyOwner {
		cap = _cap;
		emit NewCap(msg.sender, _cap);
	}

	/**
	 * @notice Enables or Disables the Total Supply Cap.
   * @param _enable value
   * @dev When capEnabled is true, minting will not be allowed above the max capacity. It can exist a supply above the cap, but it prevents minting above the cap.
   * @dev Only owner can call it
   */
	function enableCap(bool _enable) external onlyOwner {
		capEnabled = _enable;
		emit NewCapEnabled(msg.sender, _enable);
	}

	/**
	 * @notice ERC165 Standard for support of interfaces
   * @param _interfaceId bytes of interface
   * @return bool
   */
	function supportsInterface(bytes4 _interfaceId)
	external
	pure
	override
	returns (bool)
	{
		return (_interfaceId == _INTERFACE_ID_TCAP ||
		_interfaceId == _INTERFACE_ID_ERC165);
	}

	/**
	 * @notice executes before each token transfer or mint
   * @param _from address
   * @param _to address
   * @param _amount value to transfer
   * @dev See {ERC20-_beforeTokenTransfer}.
   * @dev minted tokens must not cause the total supply to go over the cap.
   * @dev Reverts if the to address is equal to token address
   */
	function _beforeTokenTransfer(
		address _from,
		address _to,
		uint256 _amount
	) internal virtual override {
		super._beforeTokenTransfer(_from, _to, _amount);

		require(
			_to != address(this),
			"TCAP::transfer: can't transfer to TCAP contract"
		);

		if (_from == address(0) && capEnabled) {
			// When minting tokens
			require(
				totalSupply().add(_amount) <= cap,
				"TCAP::Transfer: TCAP cap exceeded"
			);
		}
	}
}

File 23 of 23 : ChainlinkOracle.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.7.5;

import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/introspection/IERC165.sol";

/**
 * @title Chainlink Oracle
 * @author Cryptex.finance
 * @notice Contract in charge or reading the information from a Chainlink Oracle. TCAP contracts read the price directly from this contract. More information can be found on Chainlink Documentation
 */
contract ChainlinkOracle is Ownable, IERC165 {
  AggregatorV3Interface internal aggregatorContract;

  /*
   * setReferenceContract.selector ^
   * getLatestAnswer.selector ^
   * getLatestTimestamp.selector ^
   * getPreviousAnswer.selector ^
   * getPreviousTimestamp.selector =>  0x85be402b
   */
  bytes4 private constant _INTERFACE_ID_CHAINLINK_ORACLE = 0x85be402b;

  /*
   * bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7
   */
  bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;

  /**
   * @notice Called once the contract is deployed.
   * Set the Chainlink Oracle as an aggregator.
   */
  constructor(address _aggregator, address _owner) {
		require(_aggregator != address(0) && _owner != address(0), "address can't be 0");
    aggregatorContract = AggregatorV3Interface(_aggregator);
	  transferOwnership(_owner);
  }

  /**
   * @notice Changes the reference contract.
   * @dev Only owner can call it.
   */
  function setReferenceContract(address _aggregator) public onlyOwner() {
    aggregatorContract = AggregatorV3Interface(_aggregator);
  }

  /**
   * @notice Returns the latest answer from the reference contract.
   * @return price
   */
  function getLatestAnswer() public view returns (int256) {
    (
      uint80 roundID,
      int256 price,
      ,
      uint256 timeStamp,
      uint80 answeredInRound
    ) = aggregatorContract.latestRoundData();
    require(
      timeStamp != 0,
      "ChainlinkOracle::getLatestAnswer: round is not complete"
    );
    require(
      answeredInRound >= roundID,
      "ChainlinkOracle::getLatestAnswer: stale data"
    );
    return price;
  }

  /**
   * @notice Returns the latest round from the reference contract.
   */
  function getLatestRound()
    public
    view
    returns (
      uint80,
      int256,
      uint256,
      uint256,
      uint80
    )
  {
    (
      uint80 roundID,
      int256 price,
      uint256 startedAt,
      uint256 timeStamp,
      uint80 answeredInRound
    ) = aggregatorContract.latestRoundData();

    return (roundID, price, startedAt, timeStamp, answeredInRound);
  }

  /**
   * @notice Returns a given round from the reference contract.
   * @param _id of round
   */
  function getRound(uint80 _id)
    public
    view
    returns (
      uint80,
      int256,
      uint256,
      uint256,
      uint80
    )
  {
    (
      uint80 roundID,
      int256 price,
      uint256 startedAt,
      uint256 timeStamp,
      uint80 answeredInRound
    ) = aggregatorContract.getRoundData(_id);

    return (roundID, price, startedAt, timeStamp, answeredInRound);
  }

  /**
   * @notice Returns the last time the Oracle was updated.
   */
  function getLatestTimestamp() public view returns (uint256) {
    (, , , uint256 timeStamp, ) = aggregatorContract.latestRoundData();
    return timeStamp;
  }

  /**
   * @notice Returns a previous answer updated on the Oracle.
   * @param _id of round
   * @return price
   */
  function getPreviousAnswer(uint80 _id) public view returns (int256) {
    (uint80 roundID, int256 price, , , ) = aggregatorContract.getRoundData(_id);
    require(
      _id <= roundID,
      "ChainlinkOracle::getPreviousAnswer: not enough history"
    );
    return price;
  }

  /**
   * @notice Returns a previous time the Oracle was updated.
   * @param _id of round
   * @return timeStamp
   */
  function getPreviousTimestamp(uint80 _id) public view returns (uint256) {
    (uint80 roundID, , , uint256 timeStamp, ) =
      aggregatorContract.getRoundData(_id);
    require(
      _id <= roundID,
      "ChainlinkOracle::getPreviousTimestamp: not enough history"
    );
    return timeStamp;
  }

  /**
   * @notice ERC165 Standard for support of interfaces.
   */
  function supportsInterface(bytes4 interfaceId)
    external
    pure
    override
    returns (bool)
  {
    return (interfaceId == _INTERFACE_ID_CHAINLINK_ORACLE ||
      interfaceId == _INTERFACE_ID_ERC165);
  }
}

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

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"contract Orchestrator","name":"_orchestrator","type":"address"},{"internalType":"uint256","name":"_divisor","type":"uint256"},{"internalType":"uint256","name":"_ratio","type":"uint256"},{"internalType":"uint256","name":"_burnFee","type":"uint256"},{"internalType":"uint256","name":"_liquidationPenalty","type":"uint256"},{"internalType":"address","name":"_tcapOracle","type":"address"},{"internalType":"contract TCAP","name":"_tcapAddress","type":"address"},{"internalType":"address","name":"_collateralAddress","type":"address"},{"internalType":"address","name":"_collateralOracle","type":"address"},{"internalType":"address","name":"_ethOracle","type":"address"},{"internalType":"address","name":"_treasury","type":"address"},{"internalType":"uint256","name":"_minimumTCAP","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"uint256","name":"_id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"CollateralAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"uint256","name":"_id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"CollateralRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"_burnFee","type":"uint256"}],"name":"NewBurnFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"_liquidationPenalty","type":"uint256"}],"name":"NewLiquidationPenalty","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"_minimumTCAP","type":"uint256"}],"name":"NewMinimumTCAP","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"_ratio","type":"uint256"}],"name":"NewRatio","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":false,"internalType":"address","name":"_tresury","type":"address"}],"name":"NewTreasury","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_token","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"Recovered","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"uint256","name":"_id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"TokensBurned","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"uint256","name":"_id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"TokensMinted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"uint256","name":"_id","type":"uint256"}],"name":"VaultCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"_vaultId","type":"uint256"},{"indexed":true,"internalType":"address","name":"_liquidator","type":"address"},{"indexed":false,"internalType":"uint256","name":"_liquidationCollateral","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_reward","type":"uint256"}],"name":"VaultLiquidated","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ETHPriceOracle","outputs":[{"internalType":"contract ChainlinkOracle","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_DECIMAL_PLACES","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_FEE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MIN_RATIO","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TCAPPrice","outputs":[{"internalType":"uint256","name":"price","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TCAPToken","outputs":[{"internalType":"contract TCAP","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"addCollateral","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"addCollateralETH","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"burnFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"collateralContract","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"collateralDecimalsAdjustmentFactor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"collateralPriceOracle","outputs":[{"internalType":"contract ChainlinkOracle","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"counter","outputs":[{"internalType":"uint256","name":"_value","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"createVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"divisor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"getFee","outputs":[{"internalType":"uint256","name":"fee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ChainlinkOracle","name":"_oracle","type":"address"}],"name":"getOraclePrice","outputs":[{"internalType":"uint256","name":"price","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getRoleMember","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleMemberCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_id","type":"uint256"}],"name":"getVault","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_vaultId","type":"uint256"}],"name":"getVaultRatio","outputs":[{"internalType":"uint256","name":"currentRatio","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_vaultId","type":"uint256"},{"internalType":"uint256","name":"_maxTCAP","type":"uint256"}],"name":"liquidateVault","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"liquidationPenalty","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_vaultId","type":"uint256"}],"name":"liquidationReward","outputs":[{"internalType":"uint256","name":"rewardCollateral","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minimumTCAP","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"oracleDigits","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ratio","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"},{"internalType":"uint256","name":"_tokenAmount","type":"uint256"}],"name":"recoverERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"removeCollateral","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"removeCollateralETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"requiredCollateral","outputs":[{"internalType":"uint256","name":"collateral","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_vaultId","type":"uint256"}],"name":"requiredLiquidationTCAP","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_burnFee","type":"uint256"}],"name":"setBurnFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_liquidationPenalty","type":"uint256"}],"name":"setLiquidationPenalty","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_minimumTCAP","type":"uint256"}],"name":"setMinimumTCAP","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_ratio","type":"uint256"}],"name":"setRatio","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_treasury","type":"address"}],"name":"setTreasury","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"tcapOracle","outputs":[{"internalType":"contract ChainlinkOracle","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"treasury","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userToVault","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"vaults","outputs":[{"internalType":"uint256","name":"Id","type":"uint256"},{"internalType":"uint256","name":"Collateral","type":"uint256"},{"internalType":"uint256","name":"Debt","type":"uint256"},{"internalType":"address","name":"Owner","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]

61014060405260006009553480156200001757600080fd5b5060405162004b2538038062004b2583398181016040526101808110156200003e57600080fd5b508051602082015160408301516060840151608085015160a086015160c087015160e08801516101008901516101208a01516101408b0151610160909b0151999a9899979896979596949593949293919290918b8b8b8b8b8b8b8b8b8b8b8b6000620000a96200034d565b600080546001600160a01b0319166001600160a01b03831690811782556040519293509160008051602062004b05833981519152908290a35060016002556003805460ff19169055896200010b89606462000351602090811b6200305f17901c565b10620001495760405162461bcd60e51b815260040180806020018281038252603781526020018062004a646037913960400191505060405180910390fd5b60648a10156200018b5760405162461bcd60e51b815260040180806020018281038252603581526020018062004a096035913960400191505060405180910390fd5b6103e8891115620001ce5760405162461bcd60e51b815260040180806020018281038252603781526020018062004a9b6037913960400191505060405180910390fd5b60058b905560068a9055600789905560088890556001600160601b0319606088811b821660c05286811b821660e05285811b82166101005284811b82166101205287901b1660a052600a80546001600160a01b038481166001600160a01b03199092169190911790915560098290556040805163313ce56760e01b8152905160009288169163313ce567916004808301926020929190829003018186803b1580156200027957600080fd5b505afa1580156200028e573d6000803e3d6000fd5b505050506040513d6020811015620002a557600080fd5b50519050601260ff82161115620002ee5760405162461bcd60e51b815260040180806020018281038252603381526020018062004ad26033913960400191505060405180910390fd5b8060120360ff16600a0a60808181525050620003166004620003b560201b620030b91760201c565b62000323600033620003be565b6200032e8d620003ce565b50505050505050505050505050505050505050505050505050620005bf565b3390565b600082820183811015620003ac576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b90505b92915050565b80546001019055565b620003ca8282620004cc565b5050565b620003d86200034d565b6000546001600160a01b039081169116146200043b576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b038116620004825760405162461bcd60e51b815260040180806020018281038252602681526020018062004a3e6026913960400191505060405180910390fd5b600080546040516001600160a01b038085169392169160008051602062004b0583398151915291a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b6000828152600160209081526040909120620004f3918390620030c262000547821b17901c565b15620003ca57620005036200034d565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000620003ac836001600160a01b0384166000620005668383620005a7565b6200059e57508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155620003af565b506000620003af565b60009081526001919091016020526040902054151590565b60805160a05160601c60c05160601c60e05160601c6101005160601c6101205160601c6143926200067760003980612231528061301d525080610e805280611b595280611d7f52806125865280612d4a52508061037f5280610d2552806112d75280611c355280612111528061287552806129985280612bc5525080610f2c52806116d5525080611a0f52806124c952806133ca525080610ed15280611dc6528061225552806125b15280612d7f52506143926000f3fe60806040526004361061036f5760003560e01c8063842e357c116101c6578063abb7bc4a116100f7578063d318a7df11610095578063f0f442601161006f578063f0f4426014610b29578063f2fde38b14610b5c578063fce589d814610b8f578063fcee45f414610ba4576103a8565b8063d318a7df14610a9c578063d547741f14610ac6578063de9952c914610aff576103a8565b8063bc721a96116100d1578063bc721a9614610a00578063bcc46e8314610a33578063c6e1c7c914610a5d578063ca15c87314610a72576103a8565b8063abb7bc4a14610997578063b2237ba3146109c1578063bc063e1a146109eb576103a8565b806391d148541161016457806397994e301161013e57806397994e301461092e5780639d9b581814610943578063a0712d6814610958578063a217fddf14610982576103a8565b806391d148541461087a5780639403b634146108b3578063952cc86a1461090b576103a8565b80638c01f211116101a05780638c01f211146107b25780638c64ea4a146107dc5780638da5cb5b146108355780639010d07c1461084a576103a8565b8063842e357c1461074f5780638456cb59146107645780638980f11f14610779576103a8565b8063422b9181116102a057806361bc221a1161023e5780636ca2143c116102185780636ca2143c146106dd578063715018a6146106f257806371ca337d1461070757806375f620ac1461071c576103a8565b806361bc221a1461069e57806361d027b3146106b35780636ae7adc1146106c8576103a8565b80634bf2c7c91161027a5780634bf2c7c914610620578063574b786d1461064a5780635c975abb146106745780635d12928b14610689576103a8565b8063422b9181146105d957806342966c68146105ee57806346dc90071461060b576103a8565b8063248a9ca31161030d5780632f2ff15d116102e75780632f2ff15d146105285780633237c1581461056157806336568abe1461058b5780633f4ba83a146105c4576103a8565b8063248a9ca3146104a95780632806a743146104d35780632c5a8142146104fd576103a8565b806311d850e81161034957806311d850e8146104245780631cc244ba1461044e5780631f2dc5ef1461047f57806323f5589a14610494576103a8565b806301ffc9a7146103ad5780630d23cc79146103f55780630f0aeb8d146103fd576103a8565b366103a857336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146103a657fe5b005b600080fd5b3480156103b957600080fd5b506103e1600480360360208110156103d057600080fd5b50356001600160e01b031916610bce565b604080519115158252519081900360200190f35b6103a6610c05565b34801561040957600080fd5b50610412610e0a565b60408051918252519081900360200190f35b34801561043057600080fd5b506104126004803603602081101561044757600080fd5b5035610e0f565b34801561045a57600080fd5b50610463610f2a565b604080516001600160a01b039092168252519081900360200190f35b34801561048b57600080fd5b50610412610f4e565b3480156104a057600080fd5b50610412610f54565b3480156104b557600080fd5b50610412600480360360208110156104cc57600080fd5b5035610f5a565b3480156104df57600080fd5b506103a6600480360360208110156104f657600080fd5b5035610f6f565b34801561050957600080fd5b5061051261104f565b6040805160ff9092168252519081900360200190f35b34801561053457600080fd5b506103a66004803603604081101561054b57600080fd5b50803590602001356001600160a01b0316611054565b34801561056d57600080fd5b506103a66004803603602081101561058457600080fd5b50356110c0565b34801561059757600080fd5b506103a6600480360360408110156105ae57600080fd5b50803590602001356001600160a01b03166113c9565b3480156105d057600080fd5b506103a661142a565b3480156105e557600080fd5b5061041261148c565b6103a66004803603602081101561060457600080fd5b5035611492565b34801561061757600080fd5b506104126116cd565b34801561062c57600080fd5b506103a66004803603602081101561064357600080fd5b5035611716565b34801561065657600080fd5b506103a66004803603602081101561066d57600080fd5b50356117ed565b34801561068057600080fd5b506103e1611883565b34801561069557600080fd5b506103a661188c565b3480156106aa57600080fd5b506104126119ef565b3480156106bf57600080fd5b506104636119f5565b3480156106d457600080fd5b50610412611a04565b3480156106e957600080fd5b50610463611a0d565b3480156106fe57600080fd5b506103a6611a31565b34801561071357600080fd5b50610412611ad3565b34801561072857600080fd5b506104126004803603602081101561073f57600080fd5b50356001600160a01b0316611ad9565b34801561075b57600080fd5b50610463611b57565b34801561077057600080fd5b506103a6611b7b565b34801561078557600080fd5b506103a66004803603604081101561079c57600080fd5b506001600160a01b038135169060200135611bdb565b3480156107be57600080fd5b50610412600480360360208110156107d557600080fd5b5035611d08565b3480156107e857600080fd5b50610806600480360360208110156107ff57600080fd5b5035611e0e565b604080519485526020850193909352838301919091526001600160a01b03166060830152519081900360800190f35b34801561084157600080fd5b50610463611e3e565b34801561085657600080fd5b506104636004803603604081101561086d57600080fd5b5080359060200135611e4d565b34801561088657600080fd5b506103e16004803603604081101561089d57600080fd5b50803590602001356001600160a01b0316611e6c565b3480156108bf57600080fd5b506108dd600480360360208110156108d657600080fd5b5035611e84565b6040805194855260208501939093526001600160a01b03909116838301526060830152519081900360800190f35b6103a66004803603604081101561092157600080fd5b5080359060200135611eeb565b34801561093a57600080fd5b5061046361222f565b34801561094f57600080fd5b50610412612253565b34801561096457600080fd5b506103a66004803603602081101561097b57600080fd5b5035612277565b34801561098e57600080fd5b5061041261256d565b3480156109a357600080fd5b50610412600480360360208110156109ba57600080fd5b5035612572565b3480156109cd57600080fd5b506103a6600480360360208110156109e457600080fd5b50356125f2565b3480156109f757600080fd5b50610412612714565b348015610a0c57600080fd5b5061041260048036036020811015610a2357600080fd5b50356001600160a01b031661271a565b348015610a3f57600080fd5b506103a660048036036020811015610a5657600080fd5b503561272c565b348015610a6957600080fd5b50610463612996565b348015610a7e57600080fd5b5061041260048036036020811015610a9557600080fd5b50356129ba565b348015610aa857600080fd5b506103a660048036036020811015610abf57600080fd5b50356129d1565b348015610ad257600080fd5b506103a660048036036040811015610ae957600080fd5b50803590602001356001600160a01b0316612c8d565b348015610b0b57600080fd5b5061041260048036036020811015610b2257600080fd5b5035612ce6565b348015610b3557600080fd5b506103a660048036036020811015610b4c57600080fd5b50356001600160a01b0316612e23565b348015610b6857600080fd5b506103a660048036036020811015610b7f57600080fd5b50356001600160a01b0316612f17565b348015610b9b57600080fd5b5061041261300f565b348015610bb057600080fd5b5061041260048036036020811015610bc757600080fd5b5035613015565b60006001600160e01b0319821663279d6ac360e21b1480610bff57506001600160e01b031982166301ffc9a760e01b145b92915050565b600280541415610c4a576040805162461bcd60e51b815260206004820152601f6024820152600080516020613c9f833981519152604482015290519081900360640190fd5b60028055336000908152600b6020526040902054610c995760405162461bcd60e51b815260040180806020018281038252602b815260200180613ce4602b913960400191505060405180910390fd5b60035460ff1615610ce4576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b60003411610d235760405162461bcd60e51b815260040180806020018281038252603381526020018061414a6033913960400191505060405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b158015610d7e57600080fd5b505af1158015610d92573d6000803e3d6000fd5b5050336000908152600b60209081526040808320548352600c90915290206001810154909350610dc5925090503461305f565b6001820155805460408051348152905133917f11f8990ac38271f23dea447d5728e9914fca7cea2edda43af6c43c415f8bc30b919081900360200190a3506001600255565b606481565b6000610e19613bb1565b506000828152600c60209081526040808320815160808101835281548152600182015493810193909352600281015491830191909152600301546001600160a01b0316606082015290610e6b84612ce6565b90506000610e776116cd565b90506000610ea47f0000000000000000000000000000000000000000000000000000000000000000611ad9565b90506000610ec8610ec1606460085461305f90919063ffffffff16565b85906130d7565b90506000610f0e7f0000000000000000000000000000000000000000000000000000000000000000610f08610efe8660646130d7565b610f0886896130d7565b90613130565b9050610f1e866020015182613172565b98975050505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60055481565b60085481565b60009081526001602052604090206002015490565b610f77613188565b6000546001600160a01b03908116911614610fc7576040805162461bcd60e51b8152602060048201819052602482015260008051602061417d833981519152604482015290519081900360640190fd5b600654610fd582606461305f565b106110115760405162461bcd60e51b815260040180806020018281038252604181526020018061403c6041913960600191505060405180910390fd5b600881905560408051828152905133917f76fea7ef18b6b073facb4f15d873d45dc60e1ac9448931a44b388f40c49e3267919081900360200190a250565b601281565b60008281526001602052604090206002015461107790611072613188565b611e6c565b6110b25760405162461bcd60e51b815260040180806020018281038252602f815260200180613c70602f913960400191505060405180910390fd5b6110bc828261318c565b5050565b600280541415611105576040805162461bcd60e51b815260206004820152601f6024820152600080516020613c9f833981519152604482015290519081900360640190fd5b60028055336000908152600b60205260409020546111545760405162461bcd60e51b815260040180806020018281038252602b815260200180613ce4602b913960400191505060405180910390fd5b60035460ff161561119f576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b80806111dc5760405162461bcd60e51b81526004018080602001828103825260278152602001806142476027913960400191505060405180910390fd5b336000908152600b60209081526040808320548352600c9091528120805490919061120690611d08565b9050838260010154101561124b5760405162461bcd60e51b8152600401808060200182810382526046815260200180613ff66046913960600191505060405180910390fd5b600182015461125a90856131f5565b600183015580156112b057600654825461127390611d08565b10156112b05760405162461bcd60e51b81526004018080602001828103825260438152602001806140b36043913960600191505060405180910390fd5b6040805163a9059cbb60e01b81523360048201526024810186905290516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163a9059cbb9160448083019260209291908290030181600087803b15801561131f57600080fd5b505af1158015611333573d6000803e3d6000fd5b505050506040513d602081101561134957600080fd5b50516113865760405162461bcd60e51b815260040180806020018281038252603e8152602001806141d4603e913960400191505060405180910390fd5b815460408051868152905133917f47e1336b6fdb5f42c3a1d28b558fa98786d820c3705d726358dcc8e63a401eef919081900360200190a3505060016002555050565b6113d1613188565b6001600160a01b0316816001600160a01b0316146114205760405162461bcd60e51b815260040180806020018281038252602f81526020018061432e602f913960400191505060405180910390fd5b6110bc8282613237565b611432613188565b6000546001600160a01b03908116911614611482576040805162461bcd60e51b8152602060048201819052602482015260008051602061417d833981519152604482015290519081900360640190fd5b61148a6132a0565b565b60095481565b6002805414156114d7576040805162461bcd60e51b815260206004820152601f6024820152600080516020613c9f833981519152604482015290519081900360640190fd5b60028055336000908152600b60205260409020546115265760405162461bcd60e51b815260040180806020018281038252602b815260200180613ce4602b913960400191505060405180910390fd5b60035460ff1615611571576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b80806115ae5760405162461bcd60e51b81526004018080602001828103825260278152602001806142476027913960400191505060405180910390fd5b60006115b983613015565b9050803410156115fa5760405162461bcd60e51b815260040180806020018281038252602f8152602001806142c6602f913960400191505060405180910390fd5b611602613bb1565b50336000908152600b60209081526040808320548352600c82529182902082516080810184528154808252600183015493820193909352600282015493810193909352600301546001600160a01b03166060830152611661908561333e565b600a54611677906001600160a01b03168361342e565b61168a3361168534856131f5565b61342e565b805160408051868152905133917fccbea4088a3b7ae9ca2d15fab9a9742a4075b4d7247768a1eecea917565aba00919081900360200190a3505060016002555050565b6000806116f97f0000000000000000000000000000000000000000000000000000000000000000611ad9565b90506117106005548261313090919063ffffffff16565b91505090565b61171e613188565b6000546001600160a01b0390811691161461176e576040805162461bcd60e51b8152602060048201819052602482015260008051602061417d833981519152604482015290519081900360640190fd5b6103e88111156117af5760405162461bcd60e51b8152600401808060200182810382526036815260200180613fc06036913960400191505060405180910390fd5b600781905560408051828152905133917f2b29c7e5fe28010036a94929b56a0eb76bf5e90700e842a971eaa6e4abc45f04919081900360200190a250565b6117f5613188565b6000546001600160a01b03908116911614611845576040805162461bcd60e51b8152602060048201819052602482015260008051602061417d833981519152604482015290519081900360640190fd5b600981905560408051828152905133917fb276aeff8481b22fb866569892ac1e4127fe82fefd28354c38957d5dc76bd86c919081900360200190a250565b60035460ff1690565b60035460ff16156118d7576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b336000908152600b6020526040902054156119235760405162461bcd60e51b8152600401808060200182810382526030815260200180613be36030913960400191505060405180910390fd5b600061192f6004613526565b336000908152600b60205260409020819055905061194b613bb1565b5060408051608081018252828152600060208083018281528385018381523360608601908152878552600c909352949092208351815591516001830155925160028201559151600390920180546001600160a01b0319166001600160a01b03909316929092179091556119be60046130b9565b604051829033907fa510df27d6e51efd91d3f55722bad1f26bf924a63e5dcee07c2ab4c3d4992dcc90600090a35050565b60045481565b600a546001600160a01b031681565b6402540be40081565b7f000000000000000000000000000000000000000000000000000000000000000081565b611a39613188565b6000546001600160a01b03908116911614611a89576040805162461bcd60e51b8152602060048201819052602482015260008051602061417d833981519152604482015290519081900360640190fd5b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b60065481565b6000610bff6402540be400611b51846001600160a01b03166396237c026040518163ffffffff1660e01b815260040160206040518083038186803b158015611b2057600080fd5b505afa158015611b34573d6000803e3d6000fd5b505050506040513d6020811015611b4a57600080fd5b505161352a565b906130d7565b7f000000000000000000000000000000000000000000000000000000000000000081565b611b83613188565b6000546001600160a01b03908116911614611bd3576040805162461bcd60e51b8152602060048201819052602482015260008051602061417d833981519152604482015290519081900360640190fd5b61148a613585565b611be3613188565b6000546001600160a01b03908116911614611c33576040805162461bcd60e51b8152602060048201819052602482015260008051602061417d833981519152604482015290519081900360640190fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161415611ca45760405162461bcd60e51b8152600401808060200182810382526025815260200180613cbf6025913960400191505060405180910390fd5b611cc0611caf611e3e565b6001600160a01b0384169083613606565b604080516001600160a01b03841681526020810183905281517f8c1256b8896378cd5044f80c202f9772b9d77dc85c8a6eb51967210b09bfaa28929181900390910190a15050565b6000611d12613bb1565b506000828152600c602090815260409182902082516080810184528154808252600183015493820193909352600282015493810193909352600301546001600160a01b031660608301521580611d6a57506040810151155b15611d785760009150611e08565b6000611da37f0000000000000000000000000000000000000000000000000000000000000000611ad9565b9050611e04611dbe611db36116cd565b6040850151906130d7565b610f08611dfd7f0000000000000000000000000000000000000000000000000000000000000000611b51606488602001516130d790919063ffffffff16565b84906130d7565b9250505b50919050565b600c602052600090815260409020805460018201546002830154600390930154919290916001600160a01b031684565b6000546001600160a01b031690565b6000828152600160205260408120611e659083613658565b9392505050565b6000828152600160205260408120611e659083613664565b600080600080611e92613bb1565b50505060009283525050600c602090815260409182902082516080810184528154808252600183015493820184905260028301549482018590526003909201546001600160a01b03166060909101819052909391929091565b600280541415611f30576040805162461bcd60e51b815260206004820152601f6024820152600080516020613c9f833981519152604482015290519081900360640190fd5b6002805560035460ff1615611f7f576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6000828152600c602052604090208054611fca5760405162461bcd60e51b815260040180806020018281038252602e815260200180614298602e913960400191505060405180910390fd5b6000611fd98260000154611d08565b9050600654811061201b5760405162461bcd60e51b81526004018080602001828103825260358152602001806142126035913960400191505060405180910390fd5b600061202a8360000154612ce6565b90508084101561206b5760405162461bcd60e51b8152600401808060200182810382526048815260200180613e546048913960600191505060405180910390fd5b600061207682613015565b9050803410156120b75760405162461bcd60e51b81526004018080602001828103825260398152602001806142f56039913960400191505060405180910390fd5b60006120c68560000154610e0f565b90506120d685600001548461333e565b60018501546120e590826131f5565b60018601556040805163a9059cbb60e01b81523360048201526024810183905290516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163a9059cbb9160448083019260209291908290030181600087803b15801561215957600080fd5b505af115801561216d573d6000803e3d6000fd5b505050506040513d602081101561218357600080fd5b50516121c05760405162461bcd60e51b815260040180806020018281038252603c815260200180613e9c603c913960400191505060405180910390fd5b600a546121d6906001600160a01b03168361342e565b6121e43361168534856131f5565b8454604080518581526020810184905281513393927fba5789da846390370bbfbf693007be2c95d0cfac69a8d175805f742dc7938321928290030190a3505060016002555050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b6002805414156122bc576040805162461bcd60e51b815260206004820152601f6024820152600080516020613c9f833981519152604482015290519081900360640190fd5b60028055336000908152600b602052604090205461230b5760405162461bcd60e51b815260040180806020018281038252602b815260200180613ce4602b913960400191505060405180910390fd5b60035460ff1615612356576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b80806123935760405162461bcd60e51b81526004018080602001828103825260278152602001806142476027913960400191505060405180910390fd5b336000908152600b60209081526040808320548352600c9091528120906123b984612572565b905080826001015410156123fe5760405162461bcd60e51b8152600401808060200182810382526029815260200180613d646029913960400191505060405180910390fd5b600282015461240d908561305f565b6002830155600654825461242090611d08565b101561245d5760405162461bcd60e51b815260040180806020018281038252603781526020018061419d6037913960400191505060405180910390fd5b600954826002015410156124a25760405162461bcd60e51b8152600401808060200182810382526032815260200180613e226032913960400191505060405180910390fd5b604080516340c10f1960e01b81523360048201526024810186905290516001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016916340c10f1991604480830192600092919082900301818387803b15801561251057600080fd5b505af1158015612524573d6000803e3d6000fd5b505083546040805188815290519193503392507f2e8ac5177a616f2aec08c3048f5021e4e9743ece034e8d83ba5caf76688bb475919081900360200190a3505060016002555050565b600081565b60008061257d6116cd565b905060006125aa7f0000000000000000000000000000000000000000000000000000000000000000611ad9565b9050611e047f0000000000000000000000000000000000000000000000000000000000000000610f0883610f086064610f08600654611b518c8b6130d790919063ffffffff16565b6125fa613188565b6000546001600160a01b0390811691161461264a576040805162461bcd60e51b8152602060048201819052602482015260008051602061417d833981519152604482015290519081900360640190fd5b606481101561268a5760405162461bcd60e51b8152600401808060200182810382526032815260200180613f8e6032913960400191505060405180910390fd5b600854819061269a90606461305f565b106126d65760405162461bcd60e51b8152600401808060200182810382526034815260200180613efe6034913960400191505060405180910390fd5b600681905560408051828152905133917f6126d9241e4aeb647b01ddffba35de720a5b4ad692f117a43b5b281e49126fc4919081900360200190a250565b6103e881565b600b6020526000908152604090205481565b600280541415612771576040805162461bcd60e51b815260206004820152601f6024820152600080516020613c9f833981519152604482015290519081900360640190fd5b60028055336000908152600b60205260409020546127c05760405162461bcd60e51b815260040180806020018281038252602b815260200180613ce4602b913960400191505060405180910390fd5b60035460ff161561280b576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b80806128485760405162461bcd60e51b81526004018080602001828103825260278152602001806142476027913960400191505060405180910390fd5b604080516323b872dd60e01b81523360048201523060248201526044810184905290516001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016916323b872dd9160648083019260209291908290030181600087803b1580156128bd57600080fd5b505af11580156128d1573d6000803e3d6000fd5b505050506040513d60208110156128e757600080fd5b50516129245760405162461bcd60e51b815260040180806020018281038252603b815260200180613c35603b913960400191505060405180910390fd5b336000908152600b60209081526040808320548352600c9091529020600181015461294f908461305f565b6001820155805460408051858152905133917f11f8990ac38271f23dea447d5728e9914fca7cea2edda43af6c43c415f8bc30b919081900360200190a35050600160025550565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000818152600160205260408120610bff90613679565b600280541415612a16576040805162461bcd60e51b815260206004820152601f6024820152600080516020613c9f833981519152604482015290519081900360640190fd5b60028055336000908152600b6020526040902054612a655760405162461bcd60e51b815260040180806020018281038252602b815260200180613ce4602b913960400191505060405180910390fd5b60035460ff1615612ab0576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b60008111612aef5760405162461bcd60e51b815260040180806020018281038252603681526020018061407d6036913960400191505060405180910390fd5b336000908152600b60209081526040808320548352600c90915281208054909190612b1990611d08565b90508282600101541015612b5e5760405162461bcd60e51b815260040180806020018281038252604c815260200180613d8d604c913960600191505060405180910390fd5b6001820154612b6d90846131f5565b60018301558015612bc3576006548254612b8690611d08565b1015612bc35760405162461bcd60e51b8152600401808060200182810382526049815260200180613dd96049913960600191505060405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316632e1a7d4d846040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b158015612c2957600080fd5b505af1158015612c3d573d6000803e3d6000fd5b50505050612c4b338461342e565b815460408051858152905133917f47e1336b6fdb5f42c3a1d28b558fa98786d820c3705d726358dcc8e63a401eef919081900360200190a35050600160025550565b600082815260016020526040902060020154612cab90611072613188565b6114205760405162461bcd60e51b8152600401808060200182810382526030815260200180613f326030913960400191505060405180910390fd5b6000612cf0613bb1565b506000828152600c60209081526040808320815160808101835281548152600182015493810193909352600281015491830191909152600301546001600160a01b0316606082015290612d416116cd565b90506000612d6e7f0000000000000000000000000000000000000000000000000000000000000000611ad9565b90506000612db183610f0884611b517f000000000000000000000000000000000000000000000000000000000000000089602001516130d790919063ffffffff16565b90506000612de26064611b5184612ddc6064610f086006548c604001516130d790919063ffffffff16565b906131f5565b90506000612e08612dff606460085461305f90919063ffffffff16565b600654906131f5565b6040870151909150610f1e90612e1e8484613130565b613172565b612e2b613188565b6000546001600160a01b03908116911614612e7b576040805162461bcd60e51b8152602060048201819052602482015260008051602061417d833981519152604482015290519081900360640190fd5b6001600160a01b038116612ec05760405162461bcd60e51b815260040180806020018281038252602f815260200180613d35602f913960400191505060405180910390fd5b600a80546001600160a01b0383166001600160a01b03199091168117909155604080519182525133917f567657fa3f286518b318f4a29870674f433f622fdfc819691acb13105b228225919081900360200190a250565b612f1f613188565b6000546001600160a01b03908116911614612f6f576040805162461bcd60e51b8152602060048201819052602482015260008051602061417d833981519152604482015290519081900360640190fd5b6001600160a01b038116612fb45760405162461bcd60e51b8152600401808060200182810382526026815260200180613d0f6026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b60075481565b6000806130417f0000000000000000000000000000000000000000000000000000000000000000611ad9565b9050611e6581610f08612710610f08600754611b5189611b516116cd565b600082820183811015611e65576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b80546001019055565b6000611e65836001600160a01b038416613684565b6000826130e657506000610bff565b828202828482816130f357fe5b0414611e655760405162461bcd60e51b81526004018080602001828103825260218152602001806141296021913960400191505060405180910390fd5b6000611e6583836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f0000000000008152506136ce565b60008183106131815781611e65565b5090919050565b3390565b60008281526001602052604090206131a490826130c2565b156110bc576131b1613188565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000611e6583836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250613770565b600082815260016020526040902061324f90826137ca565b156110bc5761325c613188565b6001600160a01b0316816001600160a01b0316837ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b60405160405180910390a45050565b60035460ff166132ee576040805162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015290519081900360640190fd5b6003805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa613321613188565b604080516001600160a01b039092168252519081900360200190a1565b6000828152600c60205260409020600281015482111561338f5760405162461bcd60e51b815260040180806020018281038252602c815260200180613f62602c913960400191505060405180910390fd5b600281015461339e90836131f5565b600282015560408051632770a7eb60e21b81523360048201526024810184905290516001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001691639dc29fac91604480830192600092919082900301818387803b15801561341157600080fd5b505af1158015613425573d6000803e3d6000fd5b50505050505050565b604080516000808252602082019092526001600160a01b0384169083906040518082805190602001908083835b6020831061347a5780518252601f19909201916020918201910161345b565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d80600081146134dc576040519150601f19603f3d011682016040523d82523d6000602084013e6134e1565b606091505b50509050806135215760405162461bcd60e51b81526004018080602001828103825260338152602001806140f66033913960400191505060405180910390fd5b505050565b5490565b600080821215613581576040805162461bcd60e51b815260206004820181905260248201527f53616665436173743a2076616c7565206d75737420626520706f736974697665604482015290519081900360640190fd5b5090565b60035460ff16156135d0576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6003805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258613321613188565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526135219084906137df565b6000611e658383613890565b6000611e65836001600160a01b0384166138f4565b6000610bff82613526565b600061369083836138f4565b6136c657508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610bff565b506000610bff565b6000818361375a5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561371f578181015183820152602001613707565b50505050905090810190601f16801561374c5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b50600083858161376657fe5b0495945050505050565b600081848411156137c25760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561371f578181015183820152602001613707565b505050900390565b6000611e65836001600160a01b03841661390c565b6060613834826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166139d29092919063ffffffff16565b8051909150156135215780806020019051602081101561385357600080fd5b50516135215760405162461bcd60e51b815260040180806020018281038252602a81526020018061426e602a913960400191505060405180910390fd5b815460009082106138d25760405162461bcd60e51b8152600401808060200182810382526022815260200180613c136022913960400191505060405180910390fd5b8260000182815481106138e157fe5b9060005260206000200154905092915050565b60009081526001919091016020526040902054151590565b600081815260018301602052604081205480156139c8578354600019808301919081019060009087908390811061393f57fe5b906000526020600020015490508087600001848154811061395c57fe5b60009182526020808320909101929092558281526001898101909252604090209084019055865487908061398c57fe5b60019003818190600052602060002001600090559055866001016000878152602001908152602001600020600090556001945050505050610bff565b6000915050610bff565b60606139e184846000856139e9565b949350505050565b606082471015613a2a5760405162461bcd60e51b8152600401808060200182810382526026815260200180613ed86026913960400191505060405180910390fd5b613a3385613b45565b613a84576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b60006060866001600160a01b031685876040518082805190602001908083835b60208310613ac35780518252601f199092019160209182019101613aa4565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114613b25576040519150601f19603f3d011682016040523d82523d6000602084013e613b2a565b606091505b5091509150613b3a828286613b4b565b979650505050505050565b3b151590565b60608315613b5a575081611e65565b825115613b6a5782518084602001fd5b60405162461bcd60e51b815260206004820181815284516024840152845185939192839260440191908501908083836000831561371f578181015183820152602001613707565b604051806080016040528060008152602001600081526020016000815260200160006001600160a01b03168152509056fe5661756c7448616e646c65723a3a6372656174655661756c743a207661756c7420616c72656164792063726561746564456e756d657261626c655365743a20696e646578206f7574206f6620626f756e64735661756c7448616e646c65723a3a616464436f6c6c61746572616c3a204552433230207472616e7366657220646964206e6f742073756363656564416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e2061646d696e20746f206772616e745265656e7472616e637947756172643a207265656e7472616e742063616c6c0043616e6e6f742077697468647261772074686520636f6c6c61746572616c20746f6b656e735661756c7448616e646c65723a3a7661756c744578697374733a206e6f207661756c7420637265617465644f776e61626c653a206e6577206f776e657220697320746865207a65726f20616464726573735661756c7448616e646c65723a3a73657454726561737572793a206e6f7420612076616c69642074726561737572795661756c7448616e646c65723a3a6d696e743a206e6f7420656e6f75676820636f6c6c61746572616c4554485661756c7448616e646c65723a3a72656d6f7665436f6c6c61746572616c4554483a20726574726965766520616d6f756e7420686967686572207468616e20636f6c6c61746572616c4554485661756c7448616e646c65723a3a72656d6f7665436f6c6c61746572616c4554483a20636f6c6c61746572616c2062656c6f77206d696e20726571756972656420726174696f5661756c7448616e646c65723a3a6d696e743a206d696e7420616d6f756e74206c657373207468616e2072657175697265645661756c7448616e646c65723a3a6c69717569646174655661756c743a206c69717569646174696f6e20616d6f756e7420646966666572656e74207468616e2072657175697265645661756c7448616e646c65723a3a6c69717569646174655661756c743a204552433230207472616e7366657220646964206e6f742073756363656564416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c5661756c7448616e646c65723a3a736574526174696f3a206c69717569646174696f6e2070656e616c747920746f6f2068696768416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e2061646d696e20746f207265766f6b655661756c7448616e646c65723a3a6275726e3a20616d6f756e742067726561746572207468616e20646562745661756c7448616e646c65723a3a736574526174696f3a20726174696f206c6f776572207468616e204d494e5f524154494f5661756c7448616e646c65723a3a7365744275726e4665653a206275726e2066656520686967686572207468616e204d41585f4645455661756c7448616e646c65723a3a72656d6f7665436f6c6c61746572616c3a20726574726965766520616d6f756e7420686967686572207468616e20636f6c6c61746572616c5661756c7448616e646c65723a3a7365744c69717569646174696f6e50656e616c74793a206c69717569646174696f6e2070656e616c747920746f6f20686967684554485661756c7448616e646c65723a3a72656d6f7665436f6c6c61746572616c4554483a2076616c75652063616e277420626520305661756c7448616e646c65723a3a72656d6f7665436f6c6c61746572616c3a20636f6c6c61746572616c2062656c6f77206d696e20726571756972656420726174696f495661756c7448616e646c65723a3a736166655472616e736665724554483a20455448207472616e73666572206661696c6564536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f774554485661756c7448616e646c65723a3a616464436f6c6c61746572616c4554483a2076616c75652063616e277420626520304f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65725661756c7448616e646c65723a3a6d696e743a20636f6c6c61746572616c2062656c6f77206d696e20726571756972656420726174696f5661756c7448616e646c65723a3a72656d6f7665436f6c6c61746572616c3a204552433230207472616e7366657220646964206e6f7420737563636565645661756c7448616e646c65723a3a6c69717569646174655661756c743a207661756c74206973206e6f74206c697175696461626c655661756c7448616e646c65723a3a6e6f745a65726f3a2076616c75652063616e277420626520305361666545524332303a204552433230206f7065726174696f6e20646964206e6f7420737563636565645661756c7448616e646c65723a3a6c69717569646174655661756c743a206e6f207661756c7420637265617465645661756c7448616e646c65723a3a6275726e3a206275726e20666565206c657373207468616e2072657175697265645661756c7448616e646c65723a3a6c69717569646174655661756c743a206275726e20666565206c657373207468616e207265717569726564416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636520726f6c657320666f722073656c66a264697066735822122099a764c5cc3339c791fdfcf7fd01a9d031fc2276fe56cc98fc19d2462074ee7f64736f6c634300070500335661756c7448616e646c65723a3a636f6e7374727563746f723a20726174696f206c6f776572207468616e204d494e5f524154494f4f776e61626c653a206e6577206f776e657220697320746865207a65726f20616464726573735661756c7448616e646c65723a3a636f6e7374727563746f723a206c69717569646174696f6e2070656e616c747920746f6f20686967685661756c7448616e646c65723a3a636f6e7374727563746f723a206275726e2066656520686967686572207468616e204d41585f464545436f6c6c61746572616c20646563696d616c732067726561746572207468616e204d41585f444543494d414c5f504c414345538be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0000000000000000000000000373c74bce7893097ab26d22f05691907d4f2c18e00000000000000000000000000000000000000000000000000000002540be400000000000000000000000000000000000000000000000000000000000000006e00000000000000000000000000000000000000000000000000000000000000320000000000000000000000000000000000000000000000000000000000000005000000000000000000000000a4e581bd159b869e8290707a7fbf841fe7fe97b600000000000000000000000016c52ceece2ed57dad87319d91b5e3637d50afa4000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000002cfeaf282fe9ae050b210e7bda65d288c40c61040000000000000000000000002cfeaf282fe9ae050b210e7bda65d288c40c6104000000000000000000000000a54074b2cc0e96a43048d4a68472f7f046ac0da8000000000000000000000000000000000000000000000001158e460913d00000

Deployed Bytecode

0x60806040526004361061036f5760003560e01c8063842e357c116101c6578063abb7bc4a116100f7578063d318a7df11610095578063f0f442601161006f578063f0f4426014610b29578063f2fde38b14610b5c578063fce589d814610b8f578063fcee45f414610ba4576103a8565b8063d318a7df14610a9c578063d547741f14610ac6578063de9952c914610aff576103a8565b8063bc721a96116100d1578063bc721a9614610a00578063bcc46e8314610a33578063c6e1c7c914610a5d578063ca15c87314610a72576103a8565b8063abb7bc4a14610997578063b2237ba3146109c1578063bc063e1a146109eb576103a8565b806391d148541161016457806397994e301161013e57806397994e301461092e5780639d9b581814610943578063a0712d6814610958578063a217fddf14610982576103a8565b806391d148541461087a5780639403b634146108b3578063952cc86a1461090b576103a8565b80638c01f211116101a05780638c01f211146107b25780638c64ea4a146107dc5780638da5cb5b146108355780639010d07c1461084a576103a8565b8063842e357c1461074f5780638456cb59146107645780638980f11f14610779576103a8565b8063422b9181116102a057806361bc221a1161023e5780636ca2143c116102185780636ca2143c146106dd578063715018a6146106f257806371ca337d1461070757806375f620ac1461071c576103a8565b806361bc221a1461069e57806361d027b3146106b35780636ae7adc1146106c8576103a8565b80634bf2c7c91161027a5780634bf2c7c914610620578063574b786d1461064a5780635c975abb146106745780635d12928b14610689576103a8565b8063422b9181146105d957806342966c68146105ee57806346dc90071461060b576103a8565b8063248a9ca31161030d5780632f2ff15d116102e75780632f2ff15d146105285780633237c1581461056157806336568abe1461058b5780633f4ba83a146105c4576103a8565b8063248a9ca3146104a95780632806a743146104d35780632c5a8142146104fd576103a8565b806311d850e81161034957806311d850e8146104245780631cc244ba1461044e5780631f2dc5ef1461047f57806323f5589a14610494576103a8565b806301ffc9a7146103ad5780630d23cc79146103f55780630f0aeb8d146103fd576103a8565b366103a857336001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216146103a657fe5b005b600080fd5b3480156103b957600080fd5b506103e1600480360360208110156103d057600080fd5b50356001600160e01b031916610bce565b604080519115158252519081900360200190f35b6103a6610c05565b34801561040957600080fd5b50610412610e0a565b60408051918252519081900360200190f35b34801561043057600080fd5b506104126004803603602081101561044757600080fd5b5035610e0f565b34801561045a57600080fd5b50610463610f2a565b604080516001600160a01b039092168252519081900360200190f35b34801561048b57600080fd5b50610412610f4e565b3480156104a057600080fd5b50610412610f54565b3480156104b557600080fd5b50610412600480360360208110156104cc57600080fd5b5035610f5a565b3480156104df57600080fd5b506103a6600480360360208110156104f657600080fd5b5035610f6f565b34801561050957600080fd5b5061051261104f565b6040805160ff9092168252519081900360200190f35b34801561053457600080fd5b506103a66004803603604081101561054b57600080fd5b50803590602001356001600160a01b0316611054565b34801561056d57600080fd5b506103a66004803603602081101561058457600080fd5b50356110c0565b34801561059757600080fd5b506103a6600480360360408110156105ae57600080fd5b50803590602001356001600160a01b03166113c9565b3480156105d057600080fd5b506103a661142a565b3480156105e557600080fd5b5061041261148c565b6103a66004803603602081101561060457600080fd5b5035611492565b34801561061757600080fd5b506104126116cd565b34801561062c57600080fd5b506103a66004803603602081101561064357600080fd5b5035611716565b34801561065657600080fd5b506103a66004803603602081101561066d57600080fd5b50356117ed565b34801561068057600080fd5b506103e1611883565b34801561069557600080fd5b506103a661188c565b3480156106aa57600080fd5b506104126119ef565b3480156106bf57600080fd5b506104636119f5565b3480156106d457600080fd5b50610412611a04565b3480156106e957600080fd5b50610463611a0d565b3480156106fe57600080fd5b506103a6611a31565b34801561071357600080fd5b50610412611ad3565b34801561072857600080fd5b506104126004803603602081101561073f57600080fd5b50356001600160a01b0316611ad9565b34801561075b57600080fd5b50610463611b57565b34801561077057600080fd5b506103a6611b7b565b34801561078557600080fd5b506103a66004803603604081101561079c57600080fd5b506001600160a01b038135169060200135611bdb565b3480156107be57600080fd5b50610412600480360360208110156107d557600080fd5b5035611d08565b3480156107e857600080fd5b50610806600480360360208110156107ff57600080fd5b5035611e0e565b604080519485526020850193909352838301919091526001600160a01b03166060830152519081900360800190f35b34801561084157600080fd5b50610463611e3e565b34801561085657600080fd5b506104636004803603604081101561086d57600080fd5b5080359060200135611e4d565b34801561088657600080fd5b506103e16004803603604081101561089d57600080fd5b50803590602001356001600160a01b0316611e6c565b3480156108bf57600080fd5b506108dd600480360360208110156108d657600080fd5b5035611e84565b6040805194855260208501939093526001600160a01b03909116838301526060830152519081900360800190f35b6103a66004803603604081101561092157600080fd5b5080359060200135611eeb565b34801561093a57600080fd5b5061046361222f565b34801561094f57600080fd5b50610412612253565b34801561096457600080fd5b506103a66004803603602081101561097b57600080fd5b5035612277565b34801561098e57600080fd5b5061041261256d565b3480156109a357600080fd5b50610412600480360360208110156109ba57600080fd5b5035612572565b3480156109cd57600080fd5b506103a6600480360360208110156109e457600080fd5b50356125f2565b3480156109f757600080fd5b50610412612714565b348015610a0c57600080fd5b5061041260048036036020811015610a2357600080fd5b50356001600160a01b031661271a565b348015610a3f57600080fd5b506103a660048036036020811015610a5657600080fd5b503561272c565b348015610a6957600080fd5b50610463612996565b348015610a7e57600080fd5b5061041260048036036020811015610a9557600080fd5b50356129ba565b348015610aa857600080fd5b506103a660048036036020811015610abf57600080fd5b50356129d1565b348015610ad257600080fd5b506103a660048036036040811015610ae957600080fd5b50803590602001356001600160a01b0316612c8d565b348015610b0b57600080fd5b5061041260048036036020811015610b2257600080fd5b5035612ce6565b348015610b3557600080fd5b506103a660048036036020811015610b4c57600080fd5b50356001600160a01b0316612e23565b348015610b6857600080fd5b506103a660048036036020811015610b7f57600080fd5b50356001600160a01b0316612f17565b348015610b9b57600080fd5b5061041261300f565b348015610bb057600080fd5b5061041260048036036020811015610bc757600080fd5b5035613015565b60006001600160e01b0319821663279d6ac360e21b1480610bff57506001600160e01b031982166301ffc9a760e01b145b92915050565b600280541415610c4a576040805162461bcd60e51b815260206004820152601f6024820152600080516020613c9f833981519152604482015290519081900360640190fd5b60028055336000908152600b6020526040902054610c995760405162461bcd60e51b815260040180806020018281038252602b815260200180613ce4602b913960400191505060405180910390fd5b60035460ff1615610ce4576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b60003411610d235760405162461bcd60e51b815260040180806020018281038252603381526020018061414a6033913960400191505060405180910390fd5b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b158015610d7e57600080fd5b505af1158015610d92573d6000803e3d6000fd5b5050336000908152600b60209081526040808320548352600c90915290206001810154909350610dc5925090503461305f565b6001820155805460408051348152905133917f11f8990ac38271f23dea447d5728e9914fca7cea2edda43af6c43c415f8bc30b919081900360200190a3506001600255565b606481565b6000610e19613bb1565b506000828152600c60209081526040808320815160808101835281548152600182015493810193909352600281015491830191909152600301546001600160a01b0316606082015290610e6b84612ce6565b90506000610e776116cd565b90506000610ea47f0000000000000000000000002cfeaf282fe9ae050b210e7bda65d288c40c6104611ad9565b90506000610ec8610ec1606460085461305f90919063ffffffff16565b85906130d7565b90506000610f0e7f0000000000000000000000000000000000000000000000000000000000000001610f08610efe8660646130d7565b610f0886896130d7565b90613130565b9050610f1e866020015182613172565b98975050505050505050565b7f000000000000000000000000a4e581bd159b869e8290707a7fbf841fe7fe97b681565b60055481565b60085481565b60009081526001602052604090206002015490565b610f77613188565b6000546001600160a01b03908116911614610fc7576040805162461bcd60e51b8152602060048201819052602482015260008051602061417d833981519152604482015290519081900360640190fd5b600654610fd582606461305f565b106110115760405162461bcd60e51b815260040180806020018281038252604181526020018061403c6041913960600191505060405180910390fd5b600881905560408051828152905133917f76fea7ef18b6b073facb4f15d873d45dc60e1ac9448931a44b388f40c49e3267919081900360200190a250565b601281565b60008281526001602052604090206002015461107790611072613188565b611e6c565b6110b25760405162461bcd60e51b815260040180806020018281038252602f815260200180613c70602f913960400191505060405180910390fd5b6110bc828261318c565b5050565b600280541415611105576040805162461bcd60e51b815260206004820152601f6024820152600080516020613c9f833981519152604482015290519081900360640190fd5b60028055336000908152600b60205260409020546111545760405162461bcd60e51b815260040180806020018281038252602b815260200180613ce4602b913960400191505060405180910390fd5b60035460ff161561119f576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b80806111dc5760405162461bcd60e51b81526004018080602001828103825260278152602001806142476027913960400191505060405180910390fd5b336000908152600b60209081526040808320548352600c9091528120805490919061120690611d08565b9050838260010154101561124b5760405162461bcd60e51b8152600401808060200182810382526046815260200180613ff66046913960600191505060405180910390fd5b600182015461125a90856131f5565b600183015580156112b057600654825461127390611d08565b10156112b05760405162461bcd60e51b81526004018080602001828103825260438152602001806140b36043913960600191505060405180910390fd5b6040805163a9059cbb60e01b81523360048201526024810186905290516001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2169163a9059cbb9160448083019260209291908290030181600087803b15801561131f57600080fd5b505af1158015611333573d6000803e3d6000fd5b505050506040513d602081101561134957600080fd5b50516113865760405162461bcd60e51b815260040180806020018281038252603e8152602001806141d4603e913960400191505060405180910390fd5b815460408051868152905133917f47e1336b6fdb5f42c3a1d28b558fa98786d820c3705d726358dcc8e63a401eef919081900360200190a3505060016002555050565b6113d1613188565b6001600160a01b0316816001600160a01b0316146114205760405162461bcd60e51b815260040180806020018281038252602f81526020018061432e602f913960400191505060405180910390fd5b6110bc8282613237565b611432613188565b6000546001600160a01b03908116911614611482576040805162461bcd60e51b8152602060048201819052602482015260008051602061417d833981519152604482015290519081900360640190fd5b61148a6132a0565b565b60095481565b6002805414156114d7576040805162461bcd60e51b815260206004820152601f6024820152600080516020613c9f833981519152604482015290519081900360640190fd5b60028055336000908152600b60205260409020546115265760405162461bcd60e51b815260040180806020018281038252602b815260200180613ce4602b913960400191505060405180910390fd5b60035460ff1615611571576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b80806115ae5760405162461bcd60e51b81526004018080602001828103825260278152602001806142476027913960400191505060405180910390fd5b60006115b983613015565b9050803410156115fa5760405162461bcd60e51b815260040180806020018281038252602f8152602001806142c6602f913960400191505060405180910390fd5b611602613bb1565b50336000908152600b60209081526040808320548352600c82529182902082516080810184528154808252600183015493820193909352600282015493810193909352600301546001600160a01b03166060830152611661908561333e565b600a54611677906001600160a01b03168361342e565b61168a3361168534856131f5565b61342e565b805160408051868152905133917fccbea4088a3b7ae9ca2d15fab9a9742a4075b4d7247768a1eecea917565aba00919081900360200190a3505060016002555050565b6000806116f97f000000000000000000000000a4e581bd159b869e8290707a7fbf841fe7fe97b6611ad9565b90506117106005548261313090919063ffffffff16565b91505090565b61171e613188565b6000546001600160a01b0390811691161461176e576040805162461bcd60e51b8152602060048201819052602482015260008051602061417d833981519152604482015290519081900360640190fd5b6103e88111156117af5760405162461bcd60e51b8152600401808060200182810382526036815260200180613fc06036913960400191505060405180910390fd5b600781905560408051828152905133917f2b29c7e5fe28010036a94929b56a0eb76bf5e90700e842a971eaa6e4abc45f04919081900360200190a250565b6117f5613188565b6000546001600160a01b03908116911614611845576040805162461bcd60e51b8152602060048201819052602482015260008051602061417d833981519152604482015290519081900360640190fd5b600981905560408051828152905133917fb276aeff8481b22fb866569892ac1e4127fe82fefd28354c38957d5dc76bd86c919081900360200190a250565b60035460ff1690565b60035460ff16156118d7576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b336000908152600b6020526040902054156119235760405162461bcd60e51b8152600401808060200182810382526030815260200180613be36030913960400191505060405180910390fd5b600061192f6004613526565b336000908152600b60205260409020819055905061194b613bb1565b5060408051608081018252828152600060208083018281528385018381523360608601908152878552600c909352949092208351815591516001830155925160028201559151600390920180546001600160a01b0319166001600160a01b03909316929092179091556119be60046130b9565b604051829033907fa510df27d6e51efd91d3f55722bad1f26bf924a63e5dcee07c2ab4c3d4992dcc90600090a35050565b60045481565b600a546001600160a01b031681565b6402540be40081565b7f00000000000000000000000016c52ceece2ed57dad87319d91b5e3637d50afa481565b611a39613188565b6000546001600160a01b03908116911614611a89576040805162461bcd60e51b8152602060048201819052602482015260008051602061417d833981519152604482015290519081900360640190fd5b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b60065481565b6000610bff6402540be400611b51846001600160a01b03166396237c026040518163ffffffff1660e01b815260040160206040518083038186803b158015611b2057600080fd5b505afa158015611b34573d6000803e3d6000fd5b505050506040513d6020811015611b4a57600080fd5b505161352a565b906130d7565b7f0000000000000000000000002cfeaf282fe9ae050b210e7bda65d288c40c610481565b611b83613188565b6000546001600160a01b03908116911614611bd3576040805162461bcd60e51b8152602060048201819052602482015260008051602061417d833981519152604482015290519081900360640190fd5b61148a613585565b611be3613188565b6000546001600160a01b03908116911614611c33576040805162461bcd60e51b8152602060048201819052602482015260008051602061417d833981519152604482015290519081900360640190fd5b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316826001600160a01b03161415611ca45760405162461bcd60e51b8152600401808060200182810382526025815260200180613cbf6025913960400191505060405180910390fd5b611cc0611caf611e3e565b6001600160a01b0384169083613606565b604080516001600160a01b03841681526020810183905281517f8c1256b8896378cd5044f80c202f9772b9d77dc85c8a6eb51967210b09bfaa28929181900390910190a15050565b6000611d12613bb1565b506000828152600c602090815260409182902082516080810184528154808252600183015493820193909352600282015493810193909352600301546001600160a01b031660608301521580611d6a57506040810151155b15611d785760009150611e08565b6000611da37f0000000000000000000000002cfeaf282fe9ae050b210e7bda65d288c40c6104611ad9565b9050611e04611dbe611db36116cd565b6040850151906130d7565b610f08611dfd7f0000000000000000000000000000000000000000000000000000000000000001611b51606488602001516130d790919063ffffffff16565b84906130d7565b9250505b50919050565b600c602052600090815260409020805460018201546002830154600390930154919290916001600160a01b031684565b6000546001600160a01b031690565b6000828152600160205260408120611e659083613658565b9392505050565b6000828152600160205260408120611e659083613664565b600080600080611e92613bb1565b50505060009283525050600c602090815260409182902082516080810184528154808252600183015493820184905260028301549482018590526003909201546001600160a01b03166060909101819052909391929091565b600280541415611f30576040805162461bcd60e51b815260206004820152601f6024820152600080516020613c9f833981519152604482015290519081900360640190fd5b6002805560035460ff1615611f7f576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6000828152600c602052604090208054611fca5760405162461bcd60e51b815260040180806020018281038252602e815260200180614298602e913960400191505060405180910390fd5b6000611fd98260000154611d08565b9050600654811061201b5760405162461bcd60e51b81526004018080602001828103825260358152602001806142126035913960400191505060405180910390fd5b600061202a8360000154612ce6565b90508084101561206b5760405162461bcd60e51b8152600401808060200182810382526048815260200180613e546048913960600191505060405180910390fd5b600061207682613015565b9050803410156120b75760405162461bcd60e51b81526004018080602001828103825260398152602001806142f56039913960400191505060405180910390fd5b60006120c68560000154610e0f565b90506120d685600001548461333e565b60018501546120e590826131f5565b60018601556040805163a9059cbb60e01b81523360048201526024810183905290516001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2169163a9059cbb9160448083019260209291908290030181600087803b15801561215957600080fd5b505af115801561216d573d6000803e3d6000fd5b505050506040513d602081101561218357600080fd5b50516121c05760405162461bcd60e51b815260040180806020018281038252603c815260200180613e9c603c913960400191505060405180910390fd5b600a546121d6906001600160a01b03168361342e565b6121e43361168534856131f5565b8454604080518581526020810184905281513393927fba5789da846390370bbfbf693007be2c95d0cfac69a8d175805f742dc7938321928290030190a3505060016002555050505050565b7f0000000000000000000000002cfeaf282fe9ae050b210e7bda65d288c40c610481565b7f000000000000000000000000000000000000000000000000000000000000000181565b6002805414156122bc576040805162461bcd60e51b815260206004820152601f6024820152600080516020613c9f833981519152604482015290519081900360640190fd5b60028055336000908152600b602052604090205461230b5760405162461bcd60e51b815260040180806020018281038252602b815260200180613ce4602b913960400191505060405180910390fd5b60035460ff1615612356576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b80806123935760405162461bcd60e51b81526004018080602001828103825260278152602001806142476027913960400191505060405180910390fd5b336000908152600b60209081526040808320548352600c9091528120906123b984612572565b905080826001015410156123fe5760405162461bcd60e51b8152600401808060200182810382526029815260200180613d646029913960400191505060405180910390fd5b600282015461240d908561305f565b6002830155600654825461242090611d08565b101561245d5760405162461bcd60e51b815260040180806020018281038252603781526020018061419d6037913960400191505060405180910390fd5b600954826002015410156124a25760405162461bcd60e51b8152600401808060200182810382526032815260200180613e226032913960400191505060405180910390fd5b604080516340c10f1960e01b81523360048201526024810186905290516001600160a01b037f00000000000000000000000016c52ceece2ed57dad87319d91b5e3637d50afa416916340c10f1991604480830192600092919082900301818387803b15801561251057600080fd5b505af1158015612524573d6000803e3d6000fd5b505083546040805188815290519193503392507f2e8ac5177a616f2aec08c3048f5021e4e9743ece034e8d83ba5caf76688bb475919081900360200190a3505060016002555050565b600081565b60008061257d6116cd565b905060006125aa7f0000000000000000000000002cfeaf282fe9ae050b210e7bda65d288c40c6104611ad9565b9050611e047f0000000000000000000000000000000000000000000000000000000000000001610f0883610f086064610f08600654611b518c8b6130d790919063ffffffff16565b6125fa613188565b6000546001600160a01b0390811691161461264a576040805162461bcd60e51b8152602060048201819052602482015260008051602061417d833981519152604482015290519081900360640190fd5b606481101561268a5760405162461bcd60e51b8152600401808060200182810382526032815260200180613f8e6032913960400191505060405180910390fd5b600854819061269a90606461305f565b106126d65760405162461bcd60e51b8152600401808060200182810382526034815260200180613efe6034913960400191505060405180910390fd5b600681905560408051828152905133917f6126d9241e4aeb647b01ddffba35de720a5b4ad692f117a43b5b281e49126fc4919081900360200190a250565b6103e881565b600b6020526000908152604090205481565b600280541415612771576040805162461bcd60e51b815260206004820152601f6024820152600080516020613c9f833981519152604482015290519081900360640190fd5b60028055336000908152600b60205260409020546127c05760405162461bcd60e51b815260040180806020018281038252602b815260200180613ce4602b913960400191505060405180910390fd5b60035460ff161561280b576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b80806128485760405162461bcd60e51b81526004018080602001828103825260278152602001806142476027913960400191505060405180910390fd5b604080516323b872dd60e01b81523360048201523060248201526044810184905290516001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216916323b872dd9160648083019260209291908290030181600087803b1580156128bd57600080fd5b505af11580156128d1573d6000803e3d6000fd5b505050506040513d60208110156128e757600080fd5b50516129245760405162461bcd60e51b815260040180806020018281038252603b815260200180613c35603b913960400191505060405180910390fd5b336000908152600b60209081526040808320548352600c9091529020600181015461294f908461305f565b6001820155805460408051858152905133917f11f8990ac38271f23dea447d5728e9914fca7cea2edda43af6c43c415f8bc30b919081900360200190a35050600160025550565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b6000818152600160205260408120610bff90613679565b600280541415612a16576040805162461bcd60e51b815260206004820152601f6024820152600080516020613c9f833981519152604482015290519081900360640190fd5b60028055336000908152600b6020526040902054612a655760405162461bcd60e51b815260040180806020018281038252602b815260200180613ce4602b913960400191505060405180910390fd5b60035460ff1615612ab0576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b60008111612aef5760405162461bcd60e51b815260040180806020018281038252603681526020018061407d6036913960400191505060405180910390fd5b336000908152600b60209081526040808320548352600c90915281208054909190612b1990611d08565b90508282600101541015612b5e5760405162461bcd60e51b815260040180806020018281038252604c815260200180613d8d604c913960600191505060405180910390fd5b6001820154612b6d90846131f5565b60018301558015612bc3576006548254612b8690611d08565b1015612bc35760405162461bcd60e51b8152600401808060200182810382526049815260200180613dd96049913960600191505060405180910390fd5b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316632e1a7d4d846040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b158015612c2957600080fd5b505af1158015612c3d573d6000803e3d6000fd5b50505050612c4b338461342e565b815460408051858152905133917f47e1336b6fdb5f42c3a1d28b558fa98786d820c3705d726358dcc8e63a401eef919081900360200190a35050600160025550565b600082815260016020526040902060020154612cab90611072613188565b6114205760405162461bcd60e51b8152600401808060200182810382526030815260200180613f326030913960400191505060405180910390fd5b6000612cf0613bb1565b506000828152600c60209081526040808320815160808101835281548152600182015493810193909352600281015491830191909152600301546001600160a01b0316606082015290612d416116cd565b90506000612d6e7f0000000000000000000000002cfeaf282fe9ae050b210e7bda65d288c40c6104611ad9565b90506000612db183610f0884611b517f000000000000000000000000000000000000000000000000000000000000000189602001516130d790919063ffffffff16565b90506000612de26064611b5184612ddc6064610f086006548c604001516130d790919063ffffffff16565b906131f5565b90506000612e08612dff606460085461305f90919063ffffffff16565b600654906131f5565b6040870151909150610f1e90612e1e8484613130565b613172565b612e2b613188565b6000546001600160a01b03908116911614612e7b576040805162461bcd60e51b8152602060048201819052602482015260008051602061417d833981519152604482015290519081900360640190fd5b6001600160a01b038116612ec05760405162461bcd60e51b815260040180806020018281038252602f815260200180613d35602f913960400191505060405180910390fd5b600a80546001600160a01b0383166001600160a01b03199091168117909155604080519182525133917f567657fa3f286518b318f4a29870674f433f622fdfc819691acb13105b228225919081900360200190a250565b612f1f613188565b6000546001600160a01b03908116911614612f6f576040805162461bcd60e51b8152602060048201819052602482015260008051602061417d833981519152604482015290519081900360640190fd5b6001600160a01b038116612fb45760405162461bcd60e51b8152600401808060200182810382526026815260200180613d0f6026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b60075481565b6000806130417f0000000000000000000000002cfeaf282fe9ae050b210e7bda65d288c40c6104611ad9565b9050611e6581610f08612710610f08600754611b5189611b516116cd565b600082820183811015611e65576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b80546001019055565b6000611e65836001600160a01b038416613684565b6000826130e657506000610bff565b828202828482816130f357fe5b0414611e655760405162461bcd60e51b81526004018080602001828103825260218152602001806141296021913960400191505060405180910390fd5b6000611e6583836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f0000000000008152506136ce565b60008183106131815781611e65565b5090919050565b3390565b60008281526001602052604090206131a490826130c2565b156110bc576131b1613188565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000611e6583836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250613770565b600082815260016020526040902061324f90826137ca565b156110bc5761325c613188565b6001600160a01b0316816001600160a01b0316837ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b60405160405180910390a45050565b60035460ff166132ee576040805162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015290519081900360640190fd5b6003805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa613321613188565b604080516001600160a01b039092168252519081900360200190a1565b6000828152600c60205260409020600281015482111561338f5760405162461bcd60e51b815260040180806020018281038252602c815260200180613f62602c913960400191505060405180910390fd5b600281015461339e90836131f5565b600282015560408051632770a7eb60e21b81523360048201526024810184905290516001600160a01b037f00000000000000000000000016c52ceece2ed57dad87319d91b5e3637d50afa41691639dc29fac91604480830192600092919082900301818387803b15801561341157600080fd5b505af1158015613425573d6000803e3d6000fd5b50505050505050565b604080516000808252602082019092526001600160a01b0384169083906040518082805190602001908083835b6020831061347a5780518252601f19909201916020918201910161345b565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d80600081146134dc576040519150601f19603f3d011682016040523d82523d6000602084013e6134e1565b606091505b50509050806135215760405162461bcd60e51b81526004018080602001828103825260338152602001806140f66033913960400191505060405180910390fd5b505050565b5490565b600080821215613581576040805162461bcd60e51b815260206004820181905260248201527f53616665436173743a2076616c7565206d75737420626520706f736974697665604482015290519081900360640190fd5b5090565b60035460ff16156135d0576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6003805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258613321613188565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526135219084906137df565b6000611e658383613890565b6000611e65836001600160a01b0384166138f4565b6000610bff82613526565b600061369083836138f4565b6136c657508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610bff565b506000610bff565b6000818361375a5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561371f578181015183820152602001613707565b50505050905090810190601f16801561374c5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b50600083858161376657fe5b0495945050505050565b600081848411156137c25760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561371f578181015183820152602001613707565b505050900390565b6000611e65836001600160a01b03841661390c565b6060613834826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166139d29092919063ffffffff16565b8051909150156135215780806020019051602081101561385357600080fd5b50516135215760405162461bcd60e51b815260040180806020018281038252602a81526020018061426e602a913960400191505060405180910390fd5b815460009082106138d25760405162461bcd60e51b8152600401808060200182810382526022815260200180613c136022913960400191505060405180910390fd5b8260000182815481106138e157fe5b9060005260206000200154905092915050565b60009081526001919091016020526040902054151590565b600081815260018301602052604081205480156139c8578354600019808301919081019060009087908390811061393f57fe5b906000526020600020015490508087600001848154811061395c57fe5b60009182526020808320909101929092558281526001898101909252604090209084019055865487908061398c57fe5b60019003818190600052602060002001600090559055866001016000878152602001908152602001600020600090556001945050505050610bff565b6000915050610bff565b60606139e184846000856139e9565b949350505050565b606082471015613a2a5760405162461bcd60e51b8152600401808060200182810382526026815260200180613ed86026913960400191505060405180910390fd5b613a3385613b45565b613a84576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b60006060866001600160a01b031685876040518082805190602001908083835b60208310613ac35780518252601f199092019160209182019101613aa4565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114613b25576040519150601f19603f3d011682016040523d82523d6000602084013e613b2a565b606091505b5091509150613b3a828286613b4b565b979650505050505050565b3b151590565b60608315613b5a575081611e65565b825115613b6a5782518084602001fd5b60405162461bcd60e51b815260206004820181815284516024840152845185939192839260440191908501908083836000831561371f578181015183820152602001613707565b604051806080016040528060008152602001600081526020016000815260200160006001600160a01b03168152509056fe5661756c7448616e646c65723a3a6372656174655661756c743a207661756c7420616c72656164792063726561746564456e756d657261626c655365743a20696e646578206f7574206f6620626f756e64735661756c7448616e646c65723a3a616464436f6c6c61746572616c3a204552433230207472616e7366657220646964206e6f742073756363656564416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e2061646d696e20746f206772616e745265656e7472616e637947756172643a207265656e7472616e742063616c6c0043616e6e6f742077697468647261772074686520636f6c6c61746572616c20746f6b656e735661756c7448616e646c65723a3a7661756c744578697374733a206e6f207661756c7420637265617465644f776e61626c653a206e6577206f776e657220697320746865207a65726f20616464726573735661756c7448616e646c65723a3a73657454726561737572793a206e6f7420612076616c69642074726561737572795661756c7448616e646c65723a3a6d696e743a206e6f7420656e6f75676820636f6c6c61746572616c4554485661756c7448616e646c65723a3a72656d6f7665436f6c6c61746572616c4554483a20726574726965766520616d6f756e7420686967686572207468616e20636f6c6c61746572616c4554485661756c7448616e646c65723a3a72656d6f7665436f6c6c61746572616c4554483a20636f6c6c61746572616c2062656c6f77206d696e20726571756972656420726174696f5661756c7448616e646c65723a3a6d696e743a206d696e7420616d6f756e74206c657373207468616e2072657175697265645661756c7448616e646c65723a3a6c69717569646174655661756c743a206c69717569646174696f6e20616d6f756e7420646966666572656e74207468616e2072657175697265645661756c7448616e646c65723a3a6c69717569646174655661756c743a204552433230207472616e7366657220646964206e6f742073756363656564416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c5661756c7448616e646c65723a3a736574526174696f3a206c69717569646174696f6e2070656e616c747920746f6f2068696768416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e2061646d696e20746f207265766f6b655661756c7448616e646c65723a3a6275726e3a20616d6f756e742067726561746572207468616e20646562745661756c7448616e646c65723a3a736574526174696f3a20726174696f206c6f776572207468616e204d494e5f524154494f5661756c7448616e646c65723a3a7365744275726e4665653a206275726e2066656520686967686572207468616e204d41585f4645455661756c7448616e646c65723a3a72656d6f7665436f6c6c61746572616c3a20726574726965766520616d6f756e7420686967686572207468616e20636f6c6c61746572616c5661756c7448616e646c65723a3a7365744c69717569646174696f6e50656e616c74793a206c69717569646174696f6e2070656e616c747920746f6f20686967684554485661756c7448616e646c65723a3a72656d6f7665436f6c6c61746572616c4554483a2076616c75652063616e277420626520305661756c7448616e646c65723a3a72656d6f7665436f6c6c61746572616c3a20636f6c6c61746572616c2062656c6f77206d696e20726571756972656420726174696f495661756c7448616e646c65723a3a736166655472616e736665724554483a20455448207472616e73666572206661696c6564536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f774554485661756c7448616e646c65723a3a616464436f6c6c61746572616c4554483a2076616c75652063616e277420626520304f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65725661756c7448616e646c65723a3a6d696e743a20636f6c6c61746572616c2062656c6f77206d696e20726571756972656420726174696f5661756c7448616e646c65723a3a72656d6f7665436f6c6c61746572616c3a204552433230207472616e7366657220646964206e6f7420737563636565645661756c7448616e646c65723a3a6c69717569646174655661756c743a207661756c74206973206e6f74206c697175696461626c655661756c7448616e646c65723a3a6e6f745a65726f3a2076616c75652063616e277420626520305361666545524332303a204552433230206f7065726174696f6e20646964206e6f7420737563636565645661756c7448616e646c65723a3a6c69717569646174655661756c743a206e6f207661756c7420637265617465645661756c7448616e646c65723a3a6275726e3a206275726e20666565206c657373207468616e2072657175697265645661756c7448616e646c65723a3a6c69717569646174655661756c743a206275726e20666565206c657373207468616e207265717569726564416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636520726f6c657320666f722073656c66a264697066735822122099a764c5cc3339c791fdfcf7fd01a9d031fc2276fe56cc98fc19d2462074ee7f64736f6c63430007050033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

000000000000000000000000373c74bce7893097ab26d22f05691907d4f2c18e00000000000000000000000000000000000000000000000000000002540be400000000000000000000000000000000000000000000000000000000000000006e00000000000000000000000000000000000000000000000000000000000000320000000000000000000000000000000000000000000000000000000000000005000000000000000000000000a4e581bd159b869e8290707a7fbf841fe7fe97b600000000000000000000000016c52ceece2ed57dad87319d91b5e3637d50afa4000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000002cfeaf282fe9ae050b210e7bda65d288c40c61040000000000000000000000002cfeaf282fe9ae050b210e7bda65d288c40c6104000000000000000000000000a54074b2cc0e96a43048d4a68472f7f046ac0da8000000000000000000000000000000000000000000000001158e460913d00000

-----Decoded View---------------
Arg [0] : _orchestrator (address): 0x373C74BcE7893097ab26d22f05691907D4f2c18e
Arg [1] : _divisor (uint256): 10000000000
Arg [2] : _ratio (uint256): 110
Arg [3] : _burnFee (uint256): 50
Arg [4] : _liquidationPenalty (uint256): 5
Arg [5] : _tcapOracle (address): 0xa4e581BD159B869e8290707A7FBF841fe7FE97b6
Arg [6] : _tcapAddress (address): 0x16c52CeeCE2ed57dAd87319D91B5e3637d50aFa4
Arg [7] : _collateralAddress (address): 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
Arg [8] : _collateralOracle (address): 0x2cFeaf282FE9ae050b210e7BDa65D288C40c6104
Arg [9] : _ethOracle (address): 0x2cFeaf282FE9ae050b210e7BDa65D288C40c6104
Arg [10] : _treasury (address): 0xa54074b2cc0e96a43048d4a68472F7F046aC0DA8
Arg [11] : _minimumTCAP (uint256): 20000000000000000000

-----Encoded View---------------
12 Constructor Arguments found :
Arg [0] : 000000000000000000000000373c74bce7893097ab26d22f05691907d4f2c18e
Arg [1] : 00000000000000000000000000000000000000000000000000000002540be400
Arg [2] : 000000000000000000000000000000000000000000000000000000000000006e
Arg [3] : 0000000000000000000000000000000000000000000000000000000000000032
Arg [4] : 0000000000000000000000000000000000000000000000000000000000000005
Arg [5] : 000000000000000000000000a4e581bd159b869e8290707a7fbf841fe7fe97b6
Arg [6] : 00000000000000000000000016c52ceece2ed57dad87319d91b5e3637d50afa4
Arg [7] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Arg [8] : 0000000000000000000000002cfeaf282fe9ae050b210e7bda65d288c40c6104
Arg [9] : 0000000000000000000000002cfeaf282fe9ae050b210e7bda65d288c40c6104
Arg [10] : 000000000000000000000000a54074b2cc0e96a43048d4a68472f7f046ac0da8
Arg [11] : 000000000000000000000000000000000000000000000001158e460913d00000


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]
[ Download: CSV Export  ]

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