ETH Price: $3,381.71 (-1.81%)
Gas: 2 Gwei

Contract

0xc9aC1F2571748c4d02774b8d0fE5981ee4B897A2
 

More Info

Private Name Tags

TokenTracker

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Value
Sell Micro Lot200433582024-06-07 23:53:5920 days ago1717804439IN
0xc9aC1F25...ee4B897A2
0 ETH0.000751637
Sell Micro Lot195557632024-03-31 18:51:4789 days ago1711911107IN
0xc9aC1F25...ee4B897A2
0 ETH0.0018014225.89557891
Sell Micro Lot195556112024-03-31 18:21:1189 days ago1711909271IN
0xc9aC1F25...ee4B897A2
0 ETH0.0015948922.95051184
Sell Staking Lot195555882024-03-31 18:16:3589 days ago1711908995IN
0xc9aC1F25...ee4B897A2
0 ETH0.0011140525.52236038
Sell Micro Lot195555772024-03-31 18:14:2389 days ago1711908863IN
0xc9aC1F25...ee4B897A2
0 ETH0.0015160421.80820516
Sell Staking Lot195555712024-03-31 18:13:1189 days ago1711908791IN
0xc9aC1F25...ee4B897A2
0 ETH0.0016037624.3670594
Sell Micro Lot195554722024-03-31 17:52:5989 days ago1711907579IN
0xc9aC1F25...ee4B897A2
0 ETH0.0016347223.51552023
Sell Micro Lot192578392024-02-18 23:08:35130 days ago1708297715IN
0xc9aC1F25...ee4B897A2
0 ETH0.0011493417.73647034
Sell Micro Lot192577942024-02-18 22:59:35130 days ago1708297175IN
0xc9aC1F25...ee4B897A2
0 ETH0.0014448620.78798006
Claim Profits192577832024-02-18 22:57:23130 days ago1708297043IN
0xc9aC1F25...ee4B897A2
0 ETH0.0014284520.26411493
Sell Micro Lot185529922023-11-12 2:56:11229 days ago1699757771IN
0xc9aC1F25...ee4B897A2
0 ETH0.0015090418.42798
Sell Staking Lot170797442023-04-19 9:23:59436 days ago1681896239IN
0xc9aC1F25...ee4B897A2
0 ETH0.0047408372.03053662
Sell Micro Lot169790542023-04-05 0:28:23450 days ago1680654503IN
0xc9aC1F25...ee4B897A2
0 ETH0.0035807539.65884742
Sell Micro Lot169034592023-03-25 9:02:23461 days ago1679734943IN
0xc9aC1F25...ee4B897A2
0 ETH0.0012421413.75930572
Sell Micro Lot168077852023-03-11 22:24:59474 days ago1678573499IN
0xc9aC1F25...ee4B897A2
0 ETH0.0023904726.47933215
Sell Micro Lot166606662023-02-19 5:49:35495 days ago1676785775IN
0xc9aC1F25...ee4B897A2
0 ETH0.0018490420.4818602
Sell Micro Lot166257672023-02-14 8:22:23500 days ago1676362943IN
0xc9aC1F25...ee4B897A2
0 ETH0.0019417518.07948746
Sell Micro Lot165644422023-02-05 18:42:11509 days ago1675622531IN
0xc9aC1F25...ee4B897A2
0 ETH0.0026753924.91592931
Sell Micro Lot165384132023-02-02 3:23:23512 days ago1675308203IN
0xc9aC1F25...ee4B897A2
0 ETH0.001510416.7307844
Sell Micro Lot165103402023-01-29 5:17:59516 days ago1674969479IN
0xc9aC1F25...ee4B897A2
0 ETH0.0009156214.13495604
Sell Staking Lot165103372023-01-29 5:17:23516 days ago1674969443IN
0xc9aC1F25...ee4B897A2
0 ETH0.0012437515
Sell Staking Lot164989202023-01-27 15:02:59518 days ago1674831779IN
0xc9aC1F25...ee4B897A2
0 ETH0.0019580426.38266131
Sell Micro Lot164743912023-01-24 4:50:11521 days ago1674535811IN
0xc9aC1F25...ee4B897A2
0 ETH0.001285114.23515703
Sell Micro Lot164679602023-01-23 7:18:35522 days ago1674458315IN
0xc9aC1F25...ee4B897A2
0 ETH0.0012359313.69042453
Sell Micro Lot164425622023-01-19 18:12:23526 days ago1674151943IN
0xc9aC1F25...ee4B897A2
0 ETH0.0021696933.50098196
View all transactions

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
HegicStaking

Compiler Version
v0.8.6+commit.11564f7e

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, GNU LGPLv3 license
File 1 of 40 : HegicStaking.sol
pragma solidity 0.8.6;

/**
 * SPDX-License-Identifier: GPL-3.0-or-later
 * Hegic
 * Copyright (C) 2021 Hegic Protocol
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **/

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "../Interfaces/Interfaces.sol";

/**
 * @author 0mllwntrmt3
 * @title Hegic Protocol V8888 Staking Contract
 * @notice The contract that stakes the HEGIC tokens through
 * buying the microlots (any amount of HEGIC tokens per microlot)
 * and the staking lots (888,000 HEGIC per lot), accumulates the staking
 * rewards (settlement fees) and distributes the staking rewards among
 * the microlots and staking lots holders (should be claimed manually).
 **/

contract HegicStaking is ERC20, IHegicStaking {
    using SafeERC20 for IERC20;

    IERC20 public immutable HEGIC;
    IERC20 public immutable token;

    uint256 public constant STAKING_LOT_PRICE = 888_000e18;
    uint256 internal constant ACCURACY = 1e30;
    uint256 internal realisedBalance;

    uint256 public microLotsTotal = 0;
    mapping(address => uint256) public microBalance;

    uint256 public totalProfit = 0;
    mapping(address => uint256) internal lastProfit;

    uint256 public microLotsProfits = 0;
    mapping(address => uint256) internal lastMicroLotProfits;

    mapping(address => uint256) internal savedProfit;

    uint256 public classicLockupPeriod = 1 days;
    uint256 public microLockupPeriod = 1 days;

    mapping(address => uint256) public lastBoughtTimestamp;
    mapping(address => uint256) public lastMicroBoughtTimestamp;
    mapping(address => bool) public _revertTransfersInLockUpPeriod;

    constructor(
        ERC20 _hegic,
        ERC20 _token,
        string memory name,
        string memory short
    ) ERC20(name, short) {
        HEGIC = _hegic;
        token = _token;
    }

    function decimals() public pure override returns (uint8) {
        return 0;
    }

    /**
     * @notice Used by the HEGIC microlots holders
     * or staking lots holders for claiming
     * the accumulated staking rewards.
     **/
    function claimProfits(address account)
        external
        override
        returns (uint256 profit)
    {
        saveProfits(account);
        profit = savedProfit[account];
        require(profit > 0, "Zero profit");
        savedProfit[account] = 0;
        realisedBalance -= profit;
        token.safeTransfer(account, profit);
        emit Claim(account, profit);
    }

    /**
     * @notice Used for staking any amount of the HEGIC tokens
     * higher than zero in the form of buying the microlot
     * for receiving a pro rata share of 20% of the total staking
     * rewards (settlement fees) generated by the protocol.
     **/
    function buyMicroLot(uint256 amount) external {
        require(amount > 0, "Amount is zero");
        saveProfits(msg.sender);
        lastMicroBoughtTimestamp[msg.sender] = block.timestamp;
        microLotsTotal += amount;
        microBalance[msg.sender] += amount;
        HEGIC.safeTransferFrom(msg.sender, address(this), amount);
        emit MicroLotsAcquired(msg.sender, amount);
    }

    /**
     * @notice Used for unstaking the HEGIC tokens
     * in the form of selling the microlot.
     **/
    function sellMicroLot(uint256 amount) external {
        require(amount > 0, "Amount is zero");
        require(
            lastMicroBoughtTimestamp[msg.sender] + microLockupPeriod <
                block.timestamp,
            "The action is suspended due to the lockup"
        );
        saveProfits(msg.sender);
        microLotsTotal -= amount;
        microBalance[msg.sender] -= amount;
        HEGIC.safeTransfer(msg.sender, amount);
        emit MicroLotsSold(msg.sender, amount);
    }

    /**
     * @notice Used for staking the fixed amount of 888,000 HEGIC
     * tokens in the form of buying the staking lot (transferrable)
     * for receiving a pro rata share of 80% of the total staking
     * rewards (settlement fees) generated by the protocol.
     **/
    function buyStakingLot(uint256 amount) external override {
        lastBoughtTimestamp[msg.sender] = block.timestamp;
        require(amount > 0, "Amount is zero");
        _mint(msg.sender, amount);
        HEGIC.safeTransferFrom(
            msg.sender,
            address(this),
            amount * STAKING_LOT_PRICE
        );
    }

    /**
     * @notice Used for unstaking 888,000 HEGIC
     * tokens in the form of selling the staking lot.
     **/
    function sellStakingLot(uint256 amount) external override lockupFree {
        _burn(msg.sender, amount);
        HEGIC.safeTransfer(msg.sender, amount * STAKING_LOT_PRICE);
    }

    function revertTransfersInLockUpPeriod(bool value) external {
        _revertTransfersInLockUpPeriod[msg.sender] = value;
    }

    /**
     * @notice Returns the amount of unclaimed staking rewards.
     **/
    function profitOf(address account)
        external
        view
        override
        returns (uint256)
    {
        (uint256 profit, uint256 micro) = getUnsavedProfits(account);
        return savedProfit[account] + profit + micro;
    }

    /**
     * @notice Used for calculating the amount of accumulated
     * staking rewards before the share of the staking participant
     * changes higher (buying more microlots or staking lots)
     * or lower (selling more microlots or staking lots).
     **/
    function getUnsavedProfits(address account)
        internal
        view
        returns (uint256 total, uint256 micro)
    {
        total =
            ((totalProfit - lastProfit[account]) * balanceOf(account)) /
            ACCURACY;
        micro =
            ((microLotsProfits - lastMicroLotProfits[account]) *
                microBalance[account]) /
            ACCURACY;
    }

    /**
     * @notice Used for saving the amount of accumulated
     * staking rewards before the staking participant's share
     * changes higher (buying more microlots or staking lots)
     * or lower (selling more microlots or staking lots).
     **/
    function saveProfits(address account) internal {
        (uint256 unsaved, uint256 micro) = getUnsavedProfits(account);
        lastProfit[account] = totalProfit;
        lastMicroLotProfits[account] = microLotsProfits;
        savedProfit[account] += unsaved;
        savedProfit[account] += micro;
    }

    function _beforeTokenTransfer(
        address from,
        address to,
        uint256
    ) internal override {
        if (from != address(0)) saveProfits(from);
        if (to != address(0)) saveProfits(to);
        if (
            lastBoughtTimestamp[from] + classicLockupPeriod > block.timestamp &&
            lastBoughtTimestamp[from] > lastBoughtTimestamp[to]
        ) {
            require(
                !_revertTransfersInLockUpPeriod[to],
                "The recipient does not agree to accept the locked funds"
            );
            lastBoughtTimestamp[to] = lastBoughtTimestamp[from];
        }
    }

    /**
     * @notice Used for distributing the staking rewards
     * among the microlots and staking lots holders.
     **/
    function distributeUnrealizedRewards() external override {
        uint256 amount = token.balanceOf(address(this)) - realisedBalance;
        realisedBalance += amount;
        uint256 _totalSupply = totalSupply();
        if (microLotsTotal + _totalSupply > 0) {
            if (microLotsTotal == 0) {
                totalProfit += (amount * ACCURACY) / _totalSupply;
            } else if (_totalSupply == 0) {
                microLotsProfits += (amount * ACCURACY) / microLotsTotal;
            } else {
                uint256 microAmount = amount / 5;
                uint256 baseAmount = amount - microAmount;
                microLotsProfits += (microAmount * ACCURACY) / microLotsTotal;
                totalProfit += (baseAmount * ACCURACY) / _totalSupply;
            }
            emit Profit(amount);
        }
    }

    modifier lockupFree {
        require(
            lastBoughtTimestamp[msg.sender] + classicLockupPeriod <=
                block.timestamp,
            "The action is suspended due to the lockup"
        );
        _;
    }
}

File 2 of 40 : Exerciser.sol
pragma solidity 0.8.6;

/**
 * SPDX-License-Identifier: GPL-3.0-or-later
 * Hegic
 * Copyright (C) 2021 Hegic Protocol
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **/

import "./Interfaces/IOptionsManager.sol";
import "./Interfaces/Interfaces.sol";

/**
 * @author 0mllwntrmt3
 * @title Hegic Protocol V8888 Exerciser Contract
 * @notice The contract that allows to automatically exercise options half an hour before expiration
 **/
contract Exerciser {
    IOptionsManager immutable optionsManager;

    constructor(IOptionsManager manager) {
        optionsManager = manager;
    }

    function exercise(uint256 optionId) external {
        IHegicPool pool = IHegicPool(optionsManager.tokenPool(optionId));
        (, , , , uint256 expired, , ) = pool.options(optionId);
        require(
            block.timestamp > expired - 30 minutes,
            "Facade Error: Automatically exercise for this option is not available yet"
        );
        pool.exercise(optionId);
    }
}

File 3 of 40 : IOptionsManager.sol
pragma solidity 0.8.6;

/**
 * SPDX-License-Identifier: GPL-3.0-or-later
 * Hegic
 * Copyright (C) 2021 Hegic Protocol
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **/

import "@openzeppelin/contracts/token/ERC721/IERC721.sol";

/**
 * @notice The interface for the contract
 *   that tokenizes options as ERC721.
 **/

interface IOptionsManager is IERC721 {
    /**
     * @param holder The option buyer address
     **/
    function createOptionFor(address holder) external returns (uint256);

    /**
     * @param tokenId The ERC721 token ID linked to the option
     **/
    function tokenPool(uint256 tokenId) external returns (address pool);

    /**
     * @param spender The option buyer address or another address
     *   with the granted permission to buy/exercise options on the user's behalf
     * @param tokenId The ERC721 token ID linked to the option
     **/
    function isApprovedOrOwner(address spender, uint256 tokenId)
        external
        view
        returns (bool);
}

File 4 of 40 : Interfaces.sol
pragma solidity 0.8.6;

/**
 * SPDX-License-Identifier: GPL-3.0-or-later
 * Hegic
 * Copyright (C) 2021 Hegic Protocol
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **/

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@chainlink/contracts/src/v0.7/interfaces/AggregatorV3Interface.sol";
import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router01.sol";

// /**
//  * @author 0mllwntrmt3
//  * @title Hegic Protocol V8888 Interface
//  * @notice The interface for the price calculator,
//  *   options, pools and staking contracts.
//  **/

/**
 * @notice The interface fot the contract that calculates
 *   the options prices (the premiums) that are adjusted
 *   through balancing the `ImpliedVolRate` parameter.
 **/
interface IPriceCalculator {
    /**
     * @param period The option period
     * @param amount The option size
     * @param strike The option strike
     **/
    function calculateTotalPremium(
        uint256 period,
        uint256 amount,
        uint256 strike
    ) external view returns (uint256 settlementFee, uint256 premium);
}

/**
 * @notice The interface for the contract that manages pools and the options parameters,
 *   accumulates the funds from the liquidity providers and makes the withdrawals for them,
 *   sells the options contracts to the options buyers and collateralizes them,
 *   exercises the ITM (in-the-money) options with the unrealized P&L and settles them,
 *   unlocks the expired options and distributes the premiums among the liquidity providers.
 **/
interface IHegicPool is IERC721, IPriceCalculator {
    enum OptionState {Invalid, Active, Exercised, Expired}
    enum TrancheState {Invalid, Open, Closed}

    /**
     * @param state The state of the option: Invalid, Active, Exercised, Expired
     * @param strike The option strike
     * @param amount The option size
     * @param lockedAmount The option collateral size locked
     * @param expired The option expiration timestamp
     * @param hedgePremium The share of the premium paid for hedging from the losses
     * @param unhedgePremium The share of the premium paid to the hedged liquidity provider
     **/
    struct Option {
        OptionState state;
        uint256 strike;
        uint256 amount;
        uint256 lockedAmount;
        uint256 expired;
        uint256 hedgePremium;
        uint256 unhedgePremium;
    }

    /**
     * @param state The state of the liquidity tranche: Invalid, Open, Closed
     * @param share The liquidity provider's share in the pool
     * @param amount The size of liquidity provided
     * @param creationTimestamp The liquidity deposit timestamp
     * @param hedged The liquidity tranche type: hedged or unhedged (classic)
     **/
    struct Tranche {
        TrancheState state;
        uint256 share;
        uint256 amount;
        uint256 creationTimestamp;
        bool hedged;
    }

    /**
     * @param id The ERC721 token ID linked to the option
     * @param settlementFee The part of the premium that
     *   is distributed among the HEGIC staking participants
     * @param premium The part of the premium that
     *   is distributed among the liquidity providers
     **/
    event Acquired(uint256 indexed id, uint256 settlementFee, uint256 premium);

    /**
     * @param id The ERC721 token ID linked to the option
     * @param profit The profits of the option if exercised
     **/
    event Exercised(uint256 indexed id, uint256 profit);

    /**
     * @param id The ERC721 token ID linked to the option
     **/
    event Expired(uint256 indexed id);

    /**
     * @param account The liquidity provider's address
     * @param trancheID The liquidity tranche ID
     **/
    event Withdrawn(
        address indexed account,
        uint256 indexed trancheID,
        uint256 amount
    );

    /**
     * @param id The ERC721 token ID linked to the option
     **/
    function unlock(uint256 id) external;

    /**
     * @param id The ERC721 token ID linked to the option
     **/
    function exercise(uint256 id) external;

    function setLockupPeriod(uint256, uint256) external;

    /**
     * @param value The hedging pool address
     **/
    function setHedgePool(address value) external;

    /**
     * @param trancheID The liquidity tranche ID
     * @return amount The liquidity to be received with
     *   the positive or negative P&L earned or lost during
     *   the period of holding the liquidity tranche considered
     **/
    function withdraw(uint256 trancheID) external returns (uint256 amount);

    function pricer() external view returns (IPriceCalculator);

    /**
     * @return amount The unhedged liquidity size
     *   (unprotected from the losses on selling the options)
     **/
    function unhedgedBalance() external view returns (uint256 amount);

    /**
     * @return amount The hedged liquidity size
     * (protected from the losses on selling the options)
     **/
    function hedgedBalance() external view returns (uint256 amount);

    /**
     * @param account The liquidity provider's address
     * @param amount The size of the liquidity tranche
     * @param hedged The type of the liquidity tranche
     * @param minShare The minimum share in the pool of the user
     **/
    function provideFrom(
        address account,
        uint256 amount,
        bool hedged,
        uint256 minShare
    ) external returns (uint256 share);

    /**
     * @param holder The option buyer address
     * @param period The option period
     * @param amount The option size
     * @param strike The option strike
     **/
    function sellOption(
        address holder,
        uint256 period,
        uint256 amount,
        uint256 strike
    ) external returns (uint256 id);

    /**
     * @param trancheID The liquidity tranche ID
     * @return amount The amount to be received after the withdrawal
     **/
    function withdrawWithoutHedge(uint256 trancheID)
        external
        returns (uint256 amount);

    /**
     * @return amount The total liquidity provided into the pool
     **/
    function totalBalance() external view returns (uint256 amount);

    /**
     * @return amount The total liquidity locked in the pool
     **/
    function lockedAmount() external view returns (uint256 amount);

    function token() external view returns (IERC20);

    /**
     * @return state The state of the option: Invalid, Active, Exercised, Expired
     * @return strike The option strike
     * @return amount The option size
     * @return lockedAmount The option collateral size locked
     * @return expired The option expiration timestamp
     * @return hedgePremium The share of the premium paid for hedging from the losses
     * @return unhedgePremium The share of the premium paid to the hedged liquidity provider
     **/
    function options(uint256 id)
        external
        view
        returns (
            OptionState state,
            uint256 strike,
            uint256 amount,
            uint256 lockedAmount,
            uint256 expired,
            uint256 hedgePremium,
            uint256 unhedgePremium
        );

    /**
     * @return state The state of the liquidity tranche: Invalid, Open, Closed
     * @return share The liquidity provider's share in the pool
     * @return amount The size of liquidity provided
     * @return creationTimestamp The liquidity deposit timestamp
     * @return hedged The liquidity tranche type: hedged or unhedged (classic)
     **/
    function tranches(uint256 id)
        external
        view
        returns (
            TrancheState state,
            uint256 share,
            uint256 amount,
            uint256 creationTimestamp,
            bool hedged
        );
}

/**
 * @notice The interface for the contract that stakes HEGIC tokens
 *   through buying microlots (any amount of HEGIC tokens per microlot)
 *   and staking lots (888,000 HEGIC per lot), accumulates the staking
 *   rewards (settlement fees) and distributes the staking rewards among
 *   the microlots and staking lots holders (should be claimed manually).
 **/
interface IHegicStaking {
    event Claim(address indexed account, uint256 amount);
    event Profit(uint256 amount);
    event MicroLotsAcquired(address indexed account, uint256 amount);
    event MicroLotsSold(address indexed account, uint256 amount);

    function claimProfits(address account) external returns (uint256 profit);

    function buyStakingLot(uint256 amount) external;

    function sellStakingLot(uint256 amount) external;

    function distributeUnrealizedRewards() external;

    function profitOf(address account) external view returns (uint256);
}

interface IWETH is IERC20 {
    function deposit() external payable;

    function withdraw(uint256 value) external;
}

File 5 of 40 : IERC721.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

File 6 of 40 : IERC165.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

File 7 of 40 : ERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.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, IERC20Metadata {
    mapping(address => uint256) private _balances;

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

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

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual override 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 this function is
     * overridden;
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual override returns (uint8) {
        return 18;
    }

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

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

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

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

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

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

        uint256 currentAllowance = _allowances[sender][_msgSender()];
        require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
        unchecked {
            _approve(sender, _msgSender(), currentAllowance - amount);
        }

        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] + 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) {
        uint256 currentAllowance = _allowances[_msgSender()][spender];
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(_msgSender(), spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `sender` to `recipient`.
     *
     * This 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);

        uint256 senderBalance = _balances[sender];
        require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[sender] = senderBalance - amount;
        }
        _balances[recipient] += amount;

        emit Transfer(sender, recipient, amount);

        _afterTokenTransfer(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:
     *
     * - `account` 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 += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(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);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
        }
        _totalSupply -= amount;

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(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 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 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 {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been 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 _afterTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}
}

File 8 of 40 : ERC721.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/ERC165.sol";

/**
 * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
 * the Metadata extension, but not including the Enumerable extension, which is available separately as
 * {ERC721Enumerable}.
 */
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
    using Address for address;
    using Strings for uint256;

    // Token name
    string private _name;

    // Token symbol
    string private _symbol;

    // Mapping from token ID to owner address
    mapping(uint256 => address) private _owners;

    // Mapping owner address to token count
    mapping(address => uint256) private _balances;

    // Mapping from token ID to approved address
    mapping(uint256 => address) private _tokenApprovals;

    // Mapping from owner to operator approvals
    mapping(address => mapping(address => bool)) private _operatorApprovals;

    /**
     * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

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

    /**
     * @dev See {IERC721-balanceOf}.
     */
    function balanceOf(address owner) public view virtual override returns (uint256) {
        require(owner != address(0), "ERC721: balance query for the zero address");
        return _balances[owner];
    }

    /**
     * @dev See {IERC721-ownerOf}.
     */
    function ownerOf(uint256 tokenId) public view virtual override returns (address) {
        address owner = _owners[tokenId];
        require(owner != address(0), "ERC721: owner query for nonexistent token");
        return owner;
    }

    /**
     * @dev See {IERC721Metadata-name}.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev See {IERC721Metadata-symbol}.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev See {IERC721Metadata-tokenURI}.
     */
    function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
        require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");

        string memory baseURI = _baseURI();
        return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
    }

    /**
     * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
     * token will be the concatenation of the `baseURI` and the `tokenId`. Empty
     * by default, can be overriden in child contracts.
     */
    function _baseURI() internal view virtual returns (string memory) {
        return "";
    }

    /**
     * @dev See {IERC721-approve}.
     */
    function approve(address to, uint256 tokenId) public virtual override {
        address owner = ERC721.ownerOf(tokenId);
        require(to != owner, "ERC721: approval to current owner");

        require(
            _msgSender() == owner || isApprovedForAll(owner, _msgSender()),
            "ERC721: approve caller is not owner nor approved for all"
        );

        _approve(to, tokenId);
    }

    /**
     * @dev See {IERC721-getApproved}.
     */
    function getApproved(uint256 tokenId) public view virtual override returns (address) {
        require(_exists(tokenId), "ERC721: approved query for nonexistent token");

        return _tokenApprovals[tokenId];
    }

    /**
     * @dev See {IERC721-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual override {
        require(operator != _msgSender(), "ERC721: approve to caller");

        _operatorApprovals[_msgSender()][operator] = approved;
        emit ApprovalForAll(_msgSender(), operator, approved);
    }

    /**
     * @dev See {IERC721-isApprovedForAll}.
     */
    function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
        return _operatorApprovals[owner][operator];
    }

    /**
     * @dev See {IERC721-transferFrom}.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) public virtual override {
        //solhint-disable-next-line max-line-length
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");

        _transfer(from, to, tokenId);
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId
    ) public virtual override {
        safeTransferFrom(from, to, tokenId, "");
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data
    ) public virtual override {
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
        _safeTransfer(from, to, tokenId, _data);
    }

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * `_data` is additional data, it has no specified format and it is sent in call to `to`.
     *
     * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
     * implement alternative mechanisms to perform token transfer, such as signature-based.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeTransfer(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data
    ) internal virtual {
        _transfer(from, to, tokenId);
        require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
    }

    /**
     * @dev Returns whether `tokenId` exists.
     *
     * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
     *
     * Tokens start existing when they are minted (`_mint`),
     * and stop existing when they are burned (`_burn`).
     */
    function _exists(uint256 tokenId) internal view virtual returns (bool) {
        return _owners[tokenId] != address(0);
    }

    /**
     * @dev Returns whether `spender` is allowed to manage `tokenId`.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
        require(_exists(tokenId), "ERC721: operator query for nonexistent token");
        address owner = ERC721.ownerOf(tokenId);
        return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
    }

    /**
     * @dev Safely mints `tokenId` and transfers it to `to`.
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeMint(address to, uint256 tokenId) internal virtual {
        _safeMint(to, tokenId, "");
    }

    /**
     * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
     * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
     */
    function _safeMint(
        address to,
        uint256 tokenId,
        bytes memory _data
    ) internal virtual {
        _mint(to, tokenId);
        require(
            _checkOnERC721Received(address(0), to, tokenId, _data),
            "ERC721: transfer to non ERC721Receiver implementer"
        );
    }

    /**
     * @dev Mints `tokenId` and transfers it to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - `to` cannot be the zero address.
     *
     * Emits a {Transfer} event.
     */
    function _mint(address to, uint256 tokenId) internal virtual {
        require(to != address(0), "ERC721: mint to the zero address");
        require(!_exists(tokenId), "ERC721: token already minted");

        _beforeTokenTransfer(address(0), to, tokenId);

        _balances[to] += 1;
        _owners[tokenId] = to;

        emit Transfer(address(0), to, tokenId);
    }

    /**
     * @dev Destroys `tokenId`.
     * The approval is cleared when the token is burned.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     *
     * Emits a {Transfer} event.
     */
    function _burn(uint256 tokenId) internal virtual {
        address owner = ERC721.ownerOf(tokenId);

        _beforeTokenTransfer(owner, address(0), tokenId);

        // Clear approvals
        _approve(address(0), tokenId);

        _balances[owner] -= 1;
        delete _owners[tokenId];

        emit Transfer(owner, address(0), tokenId);
    }

    /**
     * @dev Transfers `tokenId` from `from` to `to`.
     *  As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     *
     * Emits a {Transfer} event.
     */
    function _transfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual {
        require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
        require(to != address(0), "ERC721: transfer to the zero address");

        _beforeTokenTransfer(from, to, tokenId);

        // Clear approvals from the previous owner
        _approve(address(0), tokenId);

        _balances[from] -= 1;
        _balances[to] += 1;
        _owners[tokenId] = to;

        emit Transfer(from, to, tokenId);
    }

    /**
     * @dev Approve `to` to operate on `tokenId`
     *
     * Emits a {Approval} event.
     */
    function _approve(address to, uint256 tokenId) internal virtual {
        _tokenApprovals[tokenId] = to;
        emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
    }

    /**
     * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
     * The call is not executed if the target address is not a contract.
     *
     * @param from address representing the previous owner of the given token ID
     * @param to target address that will receive the tokens
     * @param tokenId uint256 ID of the token to be transferred
     * @param _data bytes optional data to send along with the call
     * @return bool whether the call correctly returned the expected magic value
     */
    function _checkOnERC721Received(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data
    ) private returns (bool) {
        if (to.isContract()) {
            try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
                return retval == IERC721Receiver(to).onERC721Received.selector;
            } catch (bytes memory reason) {
                if (reason.length == 0) {
                    revert("ERC721: transfer to non ERC721Receiver implementer");
                } else {
                    assembly {
                        revert(add(32, reason), mload(reason))
                    }
                }
            }
        } else {
            return true;
        }
    }

    /**
     * @dev Hook that is called before any token transfer. This includes minting
     * and burning.
     *
     * Calling conditions:
     *
     * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
     * transferred to `to`.
     * - When `from` is zero, `tokenId` will be minted for `to`.
     * - When `to` is zero, ``from``'s `tokenId` 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 tokenId
    ) internal virtual {}
}

File 9 of 40 : SafeERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

File 10 of 40 : Ownable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../utils/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() {
        _setOwner(_msgSender());
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual 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 {
        _setOwner(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");
        _setOwner(newOwner);
    }

    function _setOwner(address newOwner) private {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

File 11 of 40 : AggregatorV3Interface.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.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 12 of 40 : IUniswapV2Router01.sol
pragma solidity >=0.6.2;

interface IUniswapV2Router01 {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);
    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountToken, uint amountETH);
    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountToken, uint amountETH);
    function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);
    function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);

    function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
    function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}

File 13 of 40 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

File 14 of 40 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

File 15 of 40 : Context.sol
// SPDX-License-Identifier: MIT

pragma solidity ^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 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) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

File 16 of 40 : IERC721Receiver.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

File 17 of 40 : IERC721Metadata.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Metadata is IERC721 {
    /**
     * @dev Returns the token collection name.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the token collection symbol.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
     */
    function tokenURI(uint256 tokenId) external view returns (string memory);
}

File 18 of 40 : Address.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    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

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

File 19 of 40 : Strings.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

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

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

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

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

File 20 of 40 : ERC165.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./IERC165.sol";

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

File 21 of 40 : OptionsManager.sol
pragma solidity 0.8.6;

/**
 * SPDX-License-Identifier: GPL-3.0-or-later
 * Hegic
 * Copyright (C) 2021 Hegic Protocol
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **/

import "../Interfaces/IOptionsManager.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";

/**
 * @author 0mllwntrmt3
 * @title Hegic Protocol V8888 Options Manager Contract
 * @notice The contract that buys the options contracts for the options holders
 * as well as checks whether the contract that is used for buying/exercising
 * options has been been granted with the permission to do it on the user's behalf.
 **/

contract OptionsManager is
    IOptionsManager,
    ERC721("Hegic V8888 Options (Tokenized)", "HOT8888"),
    AccessControl
{
    bytes32 public constant HEGIC_POOL_ROLE = keccak256("HEGIC_POOL_ROLE");
    uint256 public nextTokenId = 0;
    mapping(uint256 => address) public override tokenPool;

    constructor() {
        _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
    }

    /**
     * @dev See EIP-165: ERC-165 Standard Interface Detection
     * https://eips.ethereum.org/EIPS/eip-165
     **/
    function createOptionFor(address holder)
        public
        override
        onlyRole(HEGIC_POOL_ROLE)
        returns (uint256 id)
    {
        id = nextTokenId++;
        tokenPool[id] = msg.sender;
        _safeMint(holder, id);
    }

    /**
     * @dev See EIP-165: ERC-165 Standard Interface Detection
     * https://eips.ethereum.org/EIPS/eip-165
     **/
    function supportsInterface(bytes4 interfaceId)
        public
        view
        virtual
        override(ERC721, AccessControl, IERC165)
        returns (bool)
    {
        return
            interfaceId == type(IOptionsManager).interfaceId ||
            AccessControl.supportsInterface(interfaceId) ||
            ERC721.supportsInterface(interfaceId);
    }

    /**
     * @notice Used for checking whether the user has approved
     * the contract to buy/exercise the options on her behalf.
     * @param spender The address of the contract
     * that is used for exercising the options
     * @param tokenId The ERC721 token ID that is linked to the option
     **/
    function isApprovedOrOwner(address spender, uint256 tokenId)
        external
        view
        virtual
        override
        returns (bool)
    {
        address owner = ERC721.ownerOf(tokenId);
        return (spender == owner ||
            getApproved(tokenId) == spender ||
            isApprovedForAll(owner, spender));
    }
}

File 22 of 40 : AccessControl.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    function hasRole(bytes32 role, address account) external view returns (bool);

    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    function grantRole(bytes32 role, address account) external;

    function revokeRole(bytes32 role, address account) external;

    function renounceRole(bytes32 role, address account) external;
}

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address => bool) 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 Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{20}) is missing role (0x[0-9a-f]{32})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role, _msgSender());
        _;
    }

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

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

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

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

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

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

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

        _revokeRole(role, account);
    }

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

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

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

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

File 23 of 40 : HegicPool.sol
pragma solidity 0.8.6;

/**
 * SPDX-License-Identifier: GPL-3.0-or-later
 * Hegic
 * Copyright (C) 2021 Hegic Protocol
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **/

import "../Interfaces/Interfaces.sol";
import "../Interfaces/IOptionsManager.sol";
import "../Interfaces/Interfaces.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

/**
 * @author 0mllwntrmt3
 * @title Hegic Protocol V8888 Main Pool Contract
 * @notice One of the main contracts that manages the pools and the options parameters,
 * accumulates the funds from the liquidity providers and makes the withdrawals for them,
 * sells the options contracts to the options buyers and collateralizes them,
 * exercises the ITM (in-the-money) options with the unrealized P&L and settles them,
 * unlocks the expired options and distributes the premiums among the liquidity providers.
 **/
abstract contract HegicPool is
    IHegicPool,
    ERC721,
    AccessControl,
    ReentrancyGuard
{
    using SafeERC20 for IERC20;

    uint256 public constant INITIAL_RATE = 1e20;
    IOptionsManager public immutable optionsManager;
    AggregatorV3Interface public immutable priceProvider;
    IPriceCalculator public override pricer;
    uint256 public lockupPeriodForHedgedTranches = 60 days;
    uint256 public lockupPeriodForUnhedgedTranches = 30 days;
    uint256 public hedgeFeeRate = 80;
    uint256 public maxUtilizationRate = 80;
    uint256 public collateralizationRatio = 50;
    uint256 public override lockedAmount;
    uint256 public maxDepositAmount = type(uint256).max;
    uint256 public maxHedgedDepositAmount = type(uint256).max;

    uint256 public unhedgedShare = 0;
    uint256 public hedgedShare = 0;
    uint256 public override unhedgedBalance = 0;
    uint256 public override hedgedBalance = 0;
    IHegicStaking public settlementFeeRecipient;
    address public hedgePool;

    Tranche[] public override tranches;
    mapping(uint256 => Option) public override options;
    IERC20 public override token;

    constructor(
        IERC20 _token,
        string memory name,
        string memory symbol,
        IOptionsManager manager,
        IPriceCalculator _pricer,
        IHegicStaking _settlementFeeRecipient,
        AggregatorV3Interface _priceProvider
    ) ERC721(name, symbol) {
        _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
        priceProvider = _priceProvider;
        settlementFeeRecipient = _settlementFeeRecipient;
        pricer = _pricer;
        token = _token;
        hedgePool = _msgSender();
        optionsManager = manager;
    }

    /**
     * @notice Used for setting the liquidity lock-up periods during which
     * the liquidity providers who deposited the funds into the pools contracts
     * won't be able to withdraw them. Note that different lock-ups could
     * be set for the hedged and unhedged — classic — liquidity tranches.
     * @param hedgedValue Hedged liquidity tranches lock-up in seconds
     * @param unhedgedValue Unhedged (classic) liquidity tranches lock-up in seconds
     **/
    function setLockupPeriod(uint256 hedgedValue, uint256 unhedgedValue)
        external
        override
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        require(
            hedgedValue <= 60 days,
            "The lockup period for hedged tranches is too long"
        );
        require(
            unhedgedValue <= 30 days,
            "The lockup period for unhedged tranches is too long"
        );
        lockupPeriodForHedgedTranches = hedgedValue;
        lockupPeriodForUnhedgedTranches = unhedgedValue;
    }

    /**
     * @notice Used for setting the total maximum amount
     * that could be deposited into the pools contracts.
     * Note that different total maximum amounts could be set
     * for the hedged and unhedged — classic — liquidity tranches.
     * @param total Maximum amount of assets in the pool
     * in hedged and unhedged (classic) liquidity tranches combined
     * @param hedged Maximum amount of assets in the pool
     * in hedged liquidity tranches only
     **/
    function setMaxDepositAmount(uint256 total, uint256 hedged)
        external
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        require(
            total >= hedged,
            "Pool Error: The total amount shouldn't be lower than the hedged amount"
        );
        maxDepositAmount = total;
        maxHedgedDepositAmount = hedged;
    }

    /**
     * @notice Used for setting the maximum share of the pool
     * size that could be utilized as a collateral in the options.
     *
     * Example: if `MaxUtilizationRate` = 50, then only 50%
     * of liquidity on the pools contracts would be used for
     * collateralizing options while 50% will be sitting idle
     * available for withdrawals by the liquidity providers.
     * @param value The utilization ratio in a range of 50% — 100%
     **/
    function setMaxUtilizationRate(uint256 value)
        external
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        require(
            50 <= value && value <= 100,
            "Pool error: Wrong utilization rate limitation value"
        );
        maxUtilizationRate = value;
    }

    /**
     * @notice Used for setting the collateralization ratio for the option
     * collateral size that will be locked at the moment of buying them.
     *
     * Example: if `CollateralizationRatio` = 50, then 50% of an option's
     * notional size will be locked in the pools at the moment of buying it:
     * say, 1 ETH call option will be collateralized with 0.5 ETH (50%).
     * Note that if an option holder's net P&L USD value (as options
     * are cash-settled) will exceed the amount of the collateral locked
     * in the option, she will receive the required amount at the moment
     * of exercising the option using the pool's unutilized (unlocked) funds.
     * @param value The collateralization ratio in a range of 30% — 100%
     **/
    function setCollateralizationRatio(uint256 value)
        external
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        require(
            30 <= value && value <= 100,
            "Pool Error: Wrong collateralization ratio value"
        );
        collateralizationRatio = value;
    }

    /**
     * @dev See EIP-165: ERC-165 Standard Interface Detection
     * https://eips.ethereum.org/EIPS/eip-165.
     **/
    function supportsInterface(bytes4 interfaceId)
        public
        view
        virtual
        override(ERC721, AccessControl, IERC165)
        returns (bool)
    {
        return
            interfaceId == type(IHegicPool).interfaceId ||
            AccessControl.supportsInterface(interfaceId) ||
            ERC721.supportsInterface(interfaceId);
    }

    /**
     * @notice Used for changing the hedging pool address
     * that will be accumulating the hedging premiums paid
     * as a share of the total premium redirected to this address.
     * @param value The address for receiving hedging premiums
     **/
    function setHedgePool(address value)
        external
        override
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        require(value != address(0));
        hedgePool = value;
    }

    /**
     * @notice Used for selling the options contracts
     * with the parameters chosen by the option buyer
     * such as the period of holding, option size (amount),
     * strike price and the premium to be paid for the option.
     * @param holder The option buyer address
     * @param period The option period
     * @param amount The option size
     * @param strike The option strike
     * @return id ID of ERC721 token linked to the option
     **/
    function sellOption(
        address holder,
        uint256 period,
        uint256 amount,
        uint256 strike
    ) external override returns (uint256 id) {
        if (strike == 0) strike = _currentPrice();
        uint256 balance = totalBalance();
        uint256 amountToBeLocked = _calculateLockedAmount(amount);

        require(period >= 1 days, "Pool Error: The period is too short");
        require(period <= 90 days, "Pool Error: The period is too long");
        require(
            (lockedAmount + amountToBeLocked) * 100 <=
                balance * maxUtilizationRate,
            "Pool Error: The amount is too large"
        );

        (uint256 settlementFee, uint256 premium) =
            _calculateTotalPremium(period, amount, strike);
        uint256 hedgedPremiumTotal = (premium * hedgedBalance) / balance;
        uint256 hedgeFee = (hedgedPremiumTotal * hedgeFeeRate) / 100;
        uint256 hedgePremium = hedgedPremiumTotal - hedgeFee;
        uint256 unhedgePremium = premium - hedgedPremiumTotal;

        lockedAmount += amountToBeLocked;
        id = optionsManager.createOptionFor(holder);
        options[id] = Option(
            OptionState.Active,
            strike,
            amount,
            amountToBeLocked,
            block.timestamp + period,
            hedgePremium,
            unhedgePremium
        );

        token.safeTransferFrom(
            _msgSender(),
            address(this),
            premium + settlementFee
        );
        token.safeTransfer(address(settlementFeeRecipient), settlementFee);
        settlementFeeRecipient.distributeUnrealizedRewards();
        if (hedgeFee > 0) token.safeTransfer(hedgePool, hedgeFee);
        emit Acquired(id, settlementFee, premium);
    }

    /**
     * @notice Used for setting the price calculator
     * contract that will be used for pricing the options.
     * @param pc A new price calculator contract address
     **/
    function setPriceCalculator(IPriceCalculator pc)
        public
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        pricer = pc;
    }

    /**
     * @notice Used for exercising the ITM (in-the-money)
     * options contracts in case of having the unrealized profits
     * accrued during the period of holding the option contract.
     * @param id ID of ERC721 token linked to the option
     **/
    function exercise(uint256 id) external override {
        Option storage option = options[id];
        uint256 profit = _profitOf(option);
        require(
            optionsManager.isApprovedOrOwner(_msgSender(), id),
            "Pool Error: msg.sender can't exercise this option"
        );
        require(
            option.expired > block.timestamp,
            "Pool Error: The option has already expired"
        );
        require(
            profit > 0,
            "Pool Error: There are no unrealized profits for this option"
        );
        _unlock(option);
        option.state = OptionState.Exercised;
        _send(optionsManager.ownerOf(id), profit);
        emit Exercised(id, profit);
    }

    function _send(address to, uint256 transferAmount) private {
        require(to != address(0));
        uint256 hedgeLoss = (transferAmount * hedgedBalance) / totalBalance();
        uint256 unhedgeLoss = transferAmount - hedgeLoss;
        hedgedBalance -= hedgeLoss;
        unhedgedBalance -= unhedgeLoss;
        token.safeTransfer(to, transferAmount);
    }

    /**
     * @notice Used for unlocking the expired OTM (out-of-the-money)
     * options contracts in case if there was no unrealized P&L
     * accrued during the period of holding a particular option.
     * Note that the `unlock` function releases the liquidity that
     * was locked in the option when it was active and the premiums
     * that are distributed pro rata among the liquidity providers.
     * @param id ID of ERC721 token linked to the option
     **/
    function unlock(uint256 id) external override {
        Option storage option = options[id];
        require(
            option.expired < block.timestamp,
            "Pool Error: The option has not expired yet"
        );
        _unlock(option);
        option.state = OptionState.Expired;
        emit Expired(id);
    }

    function _unlock(Option storage option) internal {
        require(
            option.state == OptionState.Active,
            "Pool Error: The option with such an ID has already been exercised or expired"
        );
        lockedAmount -= option.lockedAmount;
        hedgedBalance += option.hedgePremium;
        unhedgedBalance += option.unhedgePremium;
    }

    function _calculateLockedAmount(uint256 amount)
        internal
        virtual
        returns (uint256)
    {
        return (amount * collateralizationRatio) / 100;
    }

    /**
     * @notice Used for depositing the funds into the pool
     * and minting the liquidity tranche ERC721 token
     * which represents the liquidity provider's share
     * in the pool and her unrealized P&L for this tranche.
     * @param account The liquidity provider's address
     * @param amount The size of the liquidity tranche
     * @param hedged The type of the liquidity tranche
     * @param minShare The minimum share in the pool for the user
     **/
    function provideFrom(
        address account,
        uint256 amount,
        bool hedged,
        uint256 minShare
    ) external override nonReentrant returns (uint256 share) {
        uint256 totalShare = hedged ? hedgedShare : unhedgedShare;
        uint256 balance = hedged ? hedgedBalance : unhedgedBalance;
        share = totalShare > 0 && balance > 0
            ? (amount * totalShare) / balance
            : amount * INITIAL_RATE;
        uint256 limit =
            hedged
                ? maxHedgedDepositAmount - hedgedBalance
                : maxDepositAmount - hedgedBalance - unhedgedBalance;
        require(share >= minShare, "Pool Error: The mint limit is too large");
        require(share > 0, "Pool Error: The amount is too small");
        require(
            amount <= limit,
            "Pool Error: Depositing into the pool is not available"
        );

        if (hedged) {
            hedgedShare += share;
            hedgedBalance += amount;
        } else {
            unhedgedShare += share;
            unhedgedBalance += amount;
        }

        uint256 trancheID = tranches.length;
        tranches.push(
            Tranche(TrancheState.Open, share, amount, block.timestamp, hedged)
        );
        _safeMint(account, trancheID);
        token.safeTransferFrom(_msgSender(), address(this), amount);
    }

    /**
     * @notice Used for withdrawing the funds from the pool
     * plus the net positive P&L earned or
     * minus the net negative P&L lost on
     * providing liquidity and selling options.
     * @param trancheID The liquidity tranche ID
     * @return amount The amount received after the withdrawal
     **/
    function withdraw(uint256 trancheID)
        external
        override
        nonReentrant
        returns (uint256 amount)
    {
        address owner = ownerOf(trancheID);
        Tranche memory t = tranches[trancheID];
        amount = _withdraw(owner, trancheID);
        if (t.hedged && amount < t.amount) {
            token.safeTransferFrom(hedgePool, owner, t.amount - amount);
            amount = t.amount;
        }
        emit Withdrawn(owner, trancheID, amount);
    }

    /**
     * @notice Used for withdrawing the funds from the pool
     * by the hedged liquidity tranches providers
     * in case of an urgent need to withdraw the liquidity
     * without receiving the loss compensation from
     * the hedging pool: the net difference between
     * the amount deposited and the withdrawal amount.
     * @param trancheID ID of liquidity tranche
     * @return amount The amount received after the withdrawal
     **/
    function withdrawWithoutHedge(uint256 trancheID)
        external
        override
        nonReentrant
        returns (uint256 amount)
    {
        address owner = ownerOf(trancheID);
        amount = _withdraw(owner, trancheID);
        emit Withdrawn(owner, trancheID, amount);
    }

    function _withdraw(address owner, uint256 trancheID)
        internal
        returns (uint256 amount)
    {
        Tranche storage t = tranches[trancheID];
        uint256 lockupPeriod =
            t.hedged
                ? lockupPeriodForHedgedTranches
                : lockupPeriodForUnhedgedTranches;
        require(t.state == TrancheState.Open);
        require(_isApprovedOrOwner(_msgSender(), trancheID));
        require(
            block.timestamp > t.creationTimestamp + lockupPeriod,
            "Pool Error: The withdrawal is locked up"
        );

        t.state = TrancheState.Closed;
        if (t.hedged) {
            amount = (t.share * hedgedBalance) / hedgedShare;
            hedgedShare -= t.share;
            hedgedBalance -= amount;
        } else {
            amount = (t.share * unhedgedBalance) / unhedgedShare;
            unhedgedShare -= t.share;
            unhedgedBalance -= amount;
        }

        token.safeTransfer(owner, amount);
    }

    /**
     * @return balance Returns the amount of liquidity available for withdrawing
     **/
    function availableBalance() public view returns (uint256 balance) {
        return totalBalance() - lockedAmount;
    }

    /**
     * @return balance Returns the total balance of liquidity provided to the pool
     **/
    function totalBalance() public view override returns (uint256 balance) {
        return hedgedBalance + unhedgedBalance;
    }

    function _beforeTokenTransfer(
        address,
        address,
        uint256 id
    ) internal view override {
        require(
            tranches[id].state == TrancheState.Open,
            "Pool Error: The closed tranches can not be transferred"
        );
    }

    /**
     * @notice Returns the amount of unrealized P&L of the option
     * that could be received by the option holder in case
     * if she exercises it as an ITM (in-the-money) option.
     * @param id ID of ERC721 token linked to the option
     **/
    function profitOf(uint256 id) external view returns (uint256) {
        return _profitOf(options[id]);
    }

    function _profitOf(Option memory option)
        internal
        view
        virtual
        returns (uint256 amount);

    /**
     * @notice Used for calculating the `TotalPremium`
     * for the particular option with regards to
     * the parameters chosen by the option buyer
     * such as the period of holding, size (amount)
     * and strike price.
     * @param period The period of holding the option
     * @param period The size of the option
     **/
    function calculateTotalPremium(
        uint256 period,
        uint256 amount,
        uint256 strike
    ) external view override returns (uint256 settlementFee, uint256 premium) {
        return _calculateTotalPremium(period, amount, strike);
    }

    function _calculateTotalPremium(
        uint256 period,
        uint256 amount,
        uint256 strike
    ) internal view virtual returns (uint256 settlementFee, uint256 premium) {
        (settlementFee, premium) = pricer.calculateTotalPremium(
            period,
            amount,
            strike
        );
        require(
            settlementFee + premium > amount / 1000,
            "HegicPool: The option's price is too low"
        );
    }

    /**
     * @notice Used for changing the `settlementFeeRecipient`
     * contract address for distributing the settlement fees
     * (staking rewards) among the staking participants.
     * @param recipient New staking contract address
     **/
    function setSettlementFeeRecipient(IHegicStaking recipient)
        external
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        require(address(recipient) != address(0));
        settlementFeeRecipient = recipient;
    }

    function _currentPrice() internal view returns (uint256 price) {
        (, int256 latestPrice, , , ) = priceProvider.latestRoundData();
        price = uint256(latestPrice);
    }
}

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

pragma solidity ^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() {
        _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 25 of 40 : HegicPut.sol
pragma solidity 0.8.6;

/**
 * SPDX-License-Identifier: GPL-3.0-or-later
 * Hegic
 * Copyright (C) 2021 Hegic Protocol
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **/

import "./HegicPool.sol";

/**
 * @author 0mllwntrmt3
 * @title Hegic Protocol V8888 Put Liquidity Pool Contract
 * @notice The Put Liquidity Pool Contract
 **/

contract HegicPUT is HegicPool {
    uint256 private immutable SpotDecimals; // 1e18
    uint256 private constant TokenDecimals = 1e6; // 1e6

    /**
     * @param name The pool contract name
     * @param symbol The pool ticker for the ERC721 options
     **/

    constructor(
        IERC20 _token,
        string memory name,
        string memory symbol,
        IOptionsManager manager,
        IPriceCalculator _pricer,
        IHegicStaking _settlementFeeRecipient,
        AggregatorV3Interface _priceProvider,
        uint8 spotDecimals
    )
        HegicPool(
            _token,
            name,
            symbol,
            manager,
            _pricer,
            _settlementFeeRecipient,
            _priceProvider
        )
    {
        SpotDecimals = 10**spotDecimals;
    }

    function _profitOf(Option memory option)
        internal
        view
        override
        returns (uint256 amount)
    {
        uint256 currentPrice = _currentPrice();
        if (currentPrice > option.strike) return 0;
        return
            ((option.strike - currentPrice) * option.amount * TokenDecimals) /
            SpotDecimals /
            1e8;
    }

    function _calculateLockedAmount(uint256 amount)
        internal
        view
        override
        returns (uint256)
    {
        return
            (amount *
                collateralizationRatio *
                _currentPrice() *
                TokenDecimals) /
            SpotDecimals /
            1e8 /
            100;
    }

    function _calculateTotalPremium(
        uint256 period,
        uint256 amount,
        uint256 strike
    ) internal view override returns (uint256 settlementFee, uint256 premium) {
        uint256 currentPrice = _currentPrice();
        (settlementFee, premium) = pricer.calculateTotalPremium(
            period,
            amount,
            strike
        );
        settlementFee =
            (settlementFee * currentPrice * TokenDecimals) /
            1e8 /
            SpotDecimals;
        premium = (premium * currentPrice * TokenDecimals) / 1e8 / SpotDecimals;
    }
}

File 26 of 40 : Facade.sol
pragma solidity 0.8.6;

/**
 * SPDX-License-Identifier: GPL-3.0-or-later
 * Hegic
 * Copyright (C) 2021 Hegic Protocol
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **/

import "../Interfaces/Interfaces.sol";
import "../Interfaces/IOptionsManager.sol";

/**
 * @author 0mllwntrmt3
 * @title Hegic Protocol V8888 Facade Contract
 * @notice The contract that calculates the options prices,
 * conducts the process of buying options, converts the premiums
 * into the token that the pool is denominated in and grants
 * permissions to the contracts such as GSN (Gas Station Network).
 **/

contract Facade is Ownable {
    using SafeERC20 for IERC20;

    IWETH public immutable WETH;
    IUniswapV2Router01 public immutable exchange;
    IOptionsManager public immutable optionsManager;
    address public _trustedForwarder;

    constructor(
        IWETH weth,
        IUniswapV2Router01 router,
        IOptionsManager manager,
        address trustedForwarder
    ) {
        WETH = weth;
        exchange = router;
        _trustedForwarder = trustedForwarder;
        optionsManager = manager;
    }

    /**
     * @notice Used for calculating the option price (the premium) and using
     * the swap router (if needed) to convert the tokens with which the user
     * pays the premium into the token in which the pool is denominated.
     * @param period The option period
     * @param amount The option size
     * @param strike The option strike
     * @param total The total premium
     * @param baseTotal The part of the premium that
     * is distributed among the liquidity providers
     * @param settlementFee The part of the premium that
     * is distributed among the HEGIC staking participants
     **/
    function getOptionPrice(
        IHegicPool pool,
        uint256 period,
        uint256 amount,
        uint256 strike,
        address[] calldata swappath
    )
        public
        view
        returns (
            uint256 total,
            uint256 baseTotal,
            uint256 settlementFee,
            uint256 premium
        )
    {
        (uint256 _baseTotal, uint256 baseSettlementFee, uint256 basePremium) =
            getBaseOptionCost(pool, period, amount, strike);
        if (swappath.length > 1)
            total = exchange.getAmountsIn(_baseTotal, swappath)[0];
        else total = _baseTotal;

        baseTotal = _baseTotal;
        settlementFee = (total * baseSettlementFee) / baseTotal;
        premium = (total * basePremium) / baseTotal;
    }

    /**
     * @notice Used for calculating the option price (the premium)
     * in the token in which the pool is denominated.
     * @param period The option period
     * @param amount The option size
     * @param strike The option strike
     **/
    function getBaseOptionCost(
        IHegicPool pool,
        uint256 period,
        uint256 amount,
        uint256 strike
    )
        public
        view
        returns (
            uint256 total,
            uint256 settlementFee,
            uint256 premium
        )
    {
        (settlementFee, premium) = pool.calculateTotalPremium(
            period,
            amount,
            strike
        );
        total = premium + settlementFee;
    }

    /**
     * @notice Used for approving the pools contracts addresses.
     **/
    function poolApprove(IHegicPool pool) external {
        pool.token().safeApprove(address(pool), 0);
        pool.token().safeApprove(address(pool), type(uint256).max);
    }

    /**
     * @notice Used for buying the option contract and converting
     * the buyer's tokens (the total premium) into the token
     * in which the pool is denominated.
     * @param period The option period
     * @param amount The option size
     * @param strike The option strike
     * @param acceptablePrice The highest acceptable price
     **/
    function createOption(
        IHegicPool pool,
        uint256 period,
        uint256 amount,
        uint256 strike,
        address[] calldata swappath,
        uint256 acceptablePrice
    ) external payable {
        address buyer = _msgSender();
        (uint256 optionPrice, uint256 rawOptionPrice, , ) =
            getOptionPrice(pool, period, amount, strike, swappath);
        require(
            optionPrice <= acceptablePrice,
            "Facade Error: The option price is too high"
        );
        IERC20 paymentToken = IERC20(swappath[0]);
        paymentToken.safeTransferFrom(buyer, address(this), optionPrice);
        if (swappath.length > 1) {
            if (
                paymentToken.allowance(address(this), address(exchange)) <
                optionPrice
            ) {
                paymentToken.safeApprove(address(exchange), 0);
                paymentToken.safeApprove(address(exchange), type(uint256).max);
            }

            exchange.swapTokensForExactTokens(
                rawOptionPrice,
                optionPrice,
                swappath,
                address(this),
                block.timestamp
            );
        }
        pool.sellOption(buyer, period, amount, strike);
    }

    /**
     * @notice Used for converting the liquidity provider's Ether (ETH)
     * into Wrapped Ether (WETH) and providing the funds into the pool.
     * @param hedged The liquidity tranche type: hedged or unhedged (classic)
     **/
    function provideEthToPool(
        IHegicPool pool,
        bool hedged,
        uint256 minShare
    ) external payable returns (uint256) {
        WETH.deposit{value: msg.value}();
        if (WETH.allowance(address(this), address(pool)) < msg.value)
            WETH.approve(address(pool), type(uint256).max);
        return pool.provideFrom(msg.sender, msg.value, hedged, minShare);
    }

    /**
     * @notice Unlocks the array of options.
     * @param optionIDs The array of options
     **/
    function unlockAll(IHegicPool pool, uint256[] calldata optionIDs) external {
        uint256 arrayLength = optionIDs.length;
        for (uint256 i = 0; i < arrayLength; i++) {
            pool.unlock(optionIDs[i]);
        }
    }

    /**
     * @notice Used for granting the GSN (Gas Station Network) contract
     * the permission to pay the gas (transaction) fees for the users.
     * @param forwarder GSN (Gas Station Network) contract address
     **/
    function isTrustedForwarder(address forwarder) public view returns (bool) {
        return forwarder == _trustedForwarder;
    }

    function claimAllStakingProfits(
        IHegicStaking[] calldata stakings,
        address account
    ) external {
        uint256 arrayLength = stakings.length;
        for (uint256 i = 0; i < arrayLength; i++) {
            IHegicStaking s = stakings[i];
            if (s.profitOf(account) > 0) s.claimProfits(account);
        }
    }

    function _msgSender() internal view override returns (address signer) {
        signer = msg.sender;
        if (msg.data.length >= 20 && isTrustedForwarder(signer)) {
            assembly {
                signer := shr(96, calldataload(sub(calldatasize(), 20)))
            }
        }
    }

    function exercise(uint256 optionId) external {
        require(
            optionsManager.isApprovedOrOwner(_msgSender(), optionId),
            "Facade Error: _msgSender is not eligible to exercise the option"
        );
        IHegicPool(optionsManager.tokenPool(optionId)).exercise(optionId);
    }
}

File 27 of 40 : HegicCall.sol
pragma solidity 0.8.6;

/**
 * SPDX-License-Identifier: GPL-3.0-or-later
 * Hegic
 * Copyright (C) 2021 Hegic Protocol
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **/

import "./HegicPool.sol";

/**
 * @author 0mllwntrmt3
 * @title Hegic Protocol V8888 Call Liquidity Pool Contract
 * @notice The Call Liquidity Pool Contract
 **/
contract HegicCALL is HegicPool {
    /**
     * @param name The pool contract name
     * @param symbol The pool ticker for the ERC721 options
     **/
    constructor(
        IERC20 _token,
        string memory name,
        string memory symbol,
        IOptionsManager manager,
        IPriceCalculator _pricer,
        IHegicStaking _settlementFeeRecipient,
        AggregatorV3Interface _priceProvider
    )
        HegicPool(
            _token,
            name,
            symbol,
            manager,
            _pricer,
            _settlementFeeRecipient,
            _priceProvider
        )
    {}

    function _profitOf(Option memory option)
        internal
        view
        override
        returns (uint256 amount)
    {
        uint256 currentPrice = _currentPrice();
        if (currentPrice < option.strike) return 0;
        return ((currentPrice - option.strike) * option.amount) / currentPrice;
    }
}

File 28 of 40 : ERC20Mock.sol
pragma solidity 0.8.6;

/**
 * SPDX-License-Identifier: GPL-3.0-or-later
 * Hegic
 * Copyright (C) 2021 Hegic
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **/

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract ERC20Mock is ERC20 {
    uint8 private immutable _decimals;

    constructor(
        string memory name,
        string memory symbol,
        uint8 __decimals
    ) ERC20("token", "symbol") {
        _decimals = __decimals;
    }

    function decimals() public view override returns (uint8) {
        return _decimals;
    }

    function mintTo(address account, uint256 amount) public {
        _mint(account, amount);
    }

    function mint(uint256 amount) public {
        _mint(msg.sender, amount);
    }
}

File 29 of 40 : WETH.sol
pragma solidity 0.8.6;

/**
 * SPDX-License-Identifier: GPL-3.0-or-later
 * Hegic
 * Copyright (C) 2021 Hegic
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **/

import "./ERC20Mock.sol";

contract WETHMock is ERC20Mock("WETH", "Wrapped Ether", 18) {
    function deposit() external payable {
        _mint(msg.sender, msg.value);
    }

    function withdraw(uint256 amount) external {
        _burn(msg.sender, amount);
        payable(msg.sender).transfer(amount);
    }
}

File 30 of 40 : UniswapRouterMock.sol
pragma solidity 0.8.6;

/**
 * SPDX-License-Identifier: GPL-3.0-or-later
 * Hegic
 * Copyright (C) 2021 Hegic
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **/

import "./ERC20Mock.sol";
import "@chainlink/contracts/src/v0.7/interfaces/AggregatorV3Interface.sol";

contract UniswapRouterMock {
    ERC20Mock public immutable WBTC;
    ERC20Mock public immutable USDC;
    AggregatorV3Interface public immutable WBTCPriceProvider;
    AggregatorV3Interface public immutable ETHPriceProvider;

    constructor(
        ERC20Mock _wbtc,
        ERC20Mock _usdc,
        AggregatorV3Interface wpp,
        AggregatorV3Interface epp
    ) {
        WBTC = _wbtc;
        USDC = _usdc;
        WBTCPriceProvider = wpp;
        ETHPriceProvider = epp;
    }

    function swapETHForExactTokens(
        uint256 amountOut,
        address[] calldata path,
        address to,
        uint256 /*deadline*/
    ) external payable returns (uint256[] memory amounts) {
        require(path.length == 2, "UniswapMock: wrong path");
        require(
            path[1] == address(USDC) || path[1] == address(WBTC),
            "UniswapMock: too small value"
        );
        amounts = getAmountsIn(amountOut, path);
        require(msg.value >= amounts[0], "UniswapMock: too small value");
        if (msg.value > amounts[0])
            payable(msg.sender).transfer(msg.value - amounts[0]);
        ERC20Mock(path[1]).mintTo(to, amountOut);
    }

    function getAmountsIn(uint256 amountOut, address[] calldata path)
        public
        view
        returns (uint256[] memory amounts)
    {
        require(path.length == 2, "UniswapMock: wrong path");
        uint256 amount;
        if (path[1] == address(USDC)) {
            (, int256 ethPrice, , , ) = ETHPriceProvider.latestRoundData();
            amount = (amountOut * 1e8) / uint256(ethPrice);
        } else if (path[1] == address(WBTC)) {
            (, int256 ethPrice, , , ) = ETHPriceProvider.latestRoundData();
            (, int256 wbtcPrice, , , ) = WBTCPriceProvider.latestRoundData();
            amount = (amountOut * uint256(wbtcPrice)) / uint256(ethPrice);
        } else {
            revert("UniswapMock: wrong path");
        }
        amounts = new uint256[](2);
        amounts[0] = (amount * 103) / 100;
        amounts[1] = amountOut;
    }
}

File 31 of 40 : PriceCalculator.sol
pragma solidity 0.8.6;

/**
 * SPDX-License-Identifier: GPL-3.0-or-later
 * Hegic
 * Copyright (C) 2021 Hegic Protocol
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **/

import "../Interfaces/Interfaces.sol";
import "../utils/Math.sol";

/**
 * @author 0mllwntrmt3
 * @title Hegic Protocol V8888 Price Calculator Contract
 * @notice The contract that calculates the options prices (the premiums)
 * that are adjusted through the `ImpliedVolRate` parameter.
 **/

contract PriceCalculator is IPriceCalculator, Ownable {
    using HegicMath for uint256;

    uint256 public impliedVolRate;
    uint256 internal constant PRICE_DECIMALS = 1e8;
    uint256 internal constant PRICE_MODIFIER_DECIMALS = 1e8;
    uint256 public utilizationRate = 0;
    AggregatorV3Interface public priceProvider;
    IHegicPool pool;

    constructor(
        uint256 initialRate,
        AggregatorV3Interface _priceProvider,
        IHegicPool _pool
    ) {
        pool = _pool;
        priceProvider = _priceProvider;
        impliedVolRate = initialRate;
    }

    /**
     * @notice Used for adjusting the options prices (the premiums)
     * while balancing the asset's implied volatility rate.
     * @param value New IVRate value
     **/
    function setImpliedVolRate(uint256 value) external onlyOwner {
        impliedVolRate = value;
    }

    /**
     * @notice Used for updating utilizationRate value
     * @param value New utilizationRate value
     **/
    function setUtilizationRate(uint256 value) external onlyOwner {
        utilizationRate = value;
    }

    /**
     * @notice Used for calculating the options prices
     * @param period The option period in seconds (1 days <= period <= 90 days)
     * @param amount The option size
     * @param strike The option strike
     * @return settlementFee The part of the premium that
     * is distributed among the HEGIC staking participants
     * @return premium The part of the premium that
     * is distributed among the liquidity providers
     **/
    function calculateTotalPremium(
        uint256 period,
        uint256 amount,
        uint256 strike
    ) public view override returns (uint256 settlementFee, uint256 premium) {
        uint256 currentPrice = _currentPrice();
        if (strike == 0) strike = currentPrice;
        require(
            strike == currentPrice,
            "Only ATM options are currently available"
        );
        uint256 total = _calculatePeriodFee(amount, period);
        settlementFee = total / 5;
        premium = total - settlementFee;
    }

    /**
     * @notice Calculates and prices in the time value of the option
     * @param amount Option size
     * @param period The option period in seconds (1 days <= period <= 90 days)
     * @return fee The premium size to be paid
     **/
    function _calculatePeriodFee(uint256 amount, uint256 period)
        internal
        view
        returns (uint256 fee)
    {
        return
            (amount * _priceModifier(amount, period, pool)) /
            PRICE_DECIMALS /
            PRICE_MODIFIER_DECIMALS;
    }

    /**
     * @notice Calculates `periodFee` of the option
     * @param amount The option size
     * @param period The option period in seconds (1 days <= period <= 90 days)
     **/
    function _priceModifier(
        uint256 amount,
        uint256 period,
        IHegicPool pool
    ) internal view returns (uint256 iv) {
        uint256 poolBalance = pool.totalBalance();
        require(poolBalance > 0, "Pool Error: The pool is empty");
        iv = impliedVolRate * period.sqrt();

        uint256 lockedAmount = pool.lockedAmount() + amount;
        uint256 utilization = (lockedAmount * 100e8) / poolBalance;

        if (utilization > 40e8) {
            iv += (iv * (utilization - 40e8) * utilizationRate) / 40e16;
        }
    }

    /**
     * @notice Used for requesting the current price of the asset
     * using the ChainLink data feeds contracts.
     * See https://feeds.chain.link/
     * @return price Price
     **/
    function _currentPrice() internal view returns (uint256 price) {
        (, int256 latestPrice, , , ) = priceProvider.latestRoundData();
        price = uint256(latestPrice);
    }
}

File 32 of 40 : Math.sol
pragma solidity 0.8.6;

/**
 * SPDX-License-Identifier: GPL-3.0-or-later
 * Hegic
 * Copyright (C) 2021 Hegic Protocol
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **/

library HegicMath {
    /**
     * @dev Calculates a square root of the number.
     * Responds with an "invalid opcode" at uint(-1).
     **/
    function sqrt(uint256 x) internal pure returns (uint256 result) {
        result = x;
        uint256 k = (x >> 1) + 1;
        while (k < result) (result, k) = (k, (x / k + k) >> 1);
    }
}

File 33 of 40 : IWETH.sol
pragma solidity >=0.5.0;

interface IWETH {
    function deposit() external payable;
    function transfer(address to, uint value) external returns (bool);
    function withdraw(uint) external;
}

File 34 of 40 : IERC20.sol
pragma solidity >=0.5.0;

interface IERC20 {
    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint value);

    function name() external view returns (string memory);
    function symbol() external view returns (string memory);
    function decimals() external view returns (uint8);
    function totalSupply() external view returns (uint);
    function balanceOf(address owner) external view returns (uint);
    function allowance(address owner, address spender) external view returns (uint);

    function approve(address spender, uint value) external returns (bool);
    function transfer(address to, uint value) external returns (bool);
    function transferFrom(address from, address to, uint value) external returns (bool);
}

File 35 of 40 : IUniswapV2Pair.sol
pragma solidity >=0.5.0;

interface IUniswapV2Pair {
    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint value);

    function name() external pure returns (string memory);
    function symbol() external pure returns (string memory);
    function decimals() external pure returns (uint8);
    function totalSupply() external view returns (uint);
    function balanceOf(address owner) external view returns (uint);
    function allowance(address owner, address spender) external view returns (uint);

    function approve(address spender, uint value) external returns (bool);
    function transfer(address to, uint value) external returns (bool);
    function transferFrom(address from, address to, uint value) external returns (bool);

    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function PERMIT_TYPEHASH() external pure returns (bytes32);
    function nonces(address owner) external view returns (uint);

    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;

    event Mint(address indexed sender, uint amount0, uint amount1);
    event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
    event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
    );
    event Sync(uint112 reserve0, uint112 reserve1);

    function MINIMUM_LIQUIDITY() external pure returns (uint);
    function factory() external view returns (address);
    function token0() external view returns (address);
    function token1() external view returns (address);
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
    function price0CumulativeLast() external view returns (uint);
    function price1CumulativeLast() external view returns (uint);
    function kLast() external view returns (uint);

    function mint(address to) external returns (uint liquidity);
    function burn(address to) external returns (uint amount0, uint amount1);
    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
    function skim(address to) external;
    function sync() external;

    function initialize(address, address) external;
}

File 36 of 40 : IUniswapV2Factory.sol
pragma solidity >=0.5.0;

interface IUniswapV2Factory {
    event PairCreated(address indexed token0, address indexed token1, address pair, uint);

    function feeTo() external view returns (address);
    function feeToSetter() external view returns (address);

    function getPair(address tokenA, address tokenB) external view returns (address pair);
    function allPairs(uint) external view returns (address pair);
    function allPairsLength() external view returns (uint);

    function createPair(address tokenA, address tokenB) external returns (address pair);

    function setFeeTo(address) external;
    function setFeeToSetter(address) external;
}

File 37 of 40 : IUniswapV2Callee.sol
pragma solidity >=0.5.0;

interface IUniswapV2Callee {
    function uniswapV2Call(address sender, uint amount0, uint amount1, bytes calldata data) external;
}

File 38 of 40 : IERC20.sol
pragma solidity >=0.5.0;

interface IERC20 {
    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint value);

    function name() external view returns (string memory);
    function symbol() external view returns (string memory);
    function decimals() external view returns (uint8);
    function totalSupply() external view returns (uint);
    function balanceOf(address owner) external view returns (uint);
    function allowance(address owner, address spender) external view returns (uint);

    function approve(address spender, uint value) external returns (bool);
    function transfer(address to, uint value) external returns (bool);
    function transferFrom(address from, address to, uint value) external returns (bool);
}

File 39 of 40 : IUniswapV2ERC20.sol
pragma solidity >=0.5.0;

interface IUniswapV2ERC20 {
    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint value);

    function name() external pure returns (string memory);
    function symbol() external pure returns (string memory);
    function decimals() external pure returns (uint8);
    function totalSupply() external view returns (uint);
    function balanceOf(address owner) external view returns (uint);
    function allowance(address owner, address spender) external view returns (uint);

    function approve(address spender, uint value) external returns (bool);
    function transfer(address to, uint value) external returns (bool);
    function transferFrom(address from, address to, uint value) external returns (bool);

    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function PERMIT_TYPEHASH() external pure returns (bytes32);
    function nonces(address owner) external view returns (uint);

    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
}

File 40 of 40 : TransferHelper.sol
pragma solidity >=0.6.0;

// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
library TransferHelper {
    function safeApprove(address token, address to, uint value) internal {
        // bytes4(keccak256(bytes('approve(address,uint256)')));
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: APPROVE_FAILED');
    }

    function safeTransfer(address token, address to, uint value) internal {
        // bytes4(keccak256(bytes('transfer(address,uint256)')));
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FAILED');
    }

    function safeTransferFrom(address token, address from, address to, uint value) internal {
        // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED');
    }

    function safeTransferETH(address to, uint value) internal {
        (bool success,) = to.call{value:value}(new bytes(0));
        require(success, 'TransferHelper: ETH_TRANSFER_FAILED');
    }
}

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

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"contract ERC20","name":"_hegic","type":"address"},{"internalType":"contract ERC20","name":"_token","type":"address"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"short","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Claim","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"MicroLotsAcquired","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"MicroLotsSold","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Profit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"HEGIC","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"STAKING_LOT_PRICE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"_revertTransfersInLockUpPeriod","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"buyMicroLot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"buyStakingLot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"claimProfits","outputs":[{"internalType":"uint256","name":"profit","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"classicLockupPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"distributeUnrealizedRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lastBoughtTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lastMicroBoughtTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"microBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"microLockupPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"microLotsProfits","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"microLotsTotal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"profitOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"value","type":"bool"}],"name":"revertTransfersInLockUpPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"sellMicroLot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"sellStakingLot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalProfit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]

60c0604052600060065560006008556000600a5562015180600d5562015180600e553480156200002e57600080fd5b5060405162001e7838038062001e7883398101604081905262000051916200021f565b8151829082906200006a906003906020850190620000a5565b50805162000080906004906020840190620000a5565b5050505050606091821b6001600160601b0319908116608052911b1660a05262000302565b828054620000b390620002af565b90600052602060002090601f016020900481019282620000d7576000855562000122565b82601f10620000f257805160ff191683800117855562000122565b8280016001018555821562000122579182015b828111156200012257825182559160200191906001019062000105565b506200013092915062000134565b5090565b5b8082111562000130576000815560010162000135565b80516001600160a01b03811681146200016357600080fd5b919050565b600082601f8301126200017a57600080fd5b81516001600160401b0380821115620001975762000197620002ec565b604051601f8301601f19908116603f01168101908282118183101715620001c257620001c2620002ec565b81604052838152602092508683858801011115620001df57600080fd5b600091505b83821015620002035785820183015181830184015290820190620001e4565b83821115620002155760008385830101525b9695505050505050565b600080600080608085870312156200023657600080fd5b62000241856200014b565b935062000251602086016200014b565b60408601519093506001600160401b03808211156200026f57600080fd5b6200027d8883890162000168565b935060608701519150808211156200029457600080fd5b50620002a38782880162000168565b91505092959194509250565b600181811c90821680620002c457607f821691505b60208210811415620002e657634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052604160045260246000fd5b60805160601c60a05160601c611b2062000358600039600081816104b10152818161094d0152610b9c01526000818161036601528181610715015281816107f901528181610a240152610b500152611b206000f3fe608060405234801561001057600080fd5b50600436106101e55760003560e01c806371e395a81161010f578063a457c2d7116100a2578063b0d05a1811610071578063b0d05a1814610462578063da34364b1461046b578063dd62ed3e14610473578063fc0c546a146104ac57600080fd5b8063a457c2d714610409578063a67372911461041c578063a9059cbb1461043c578063ac1ec28f1461044f57600080fd5b806392c1ead3116100de57806392c1ead3146103d257806395d89b41146103db578063993ac84c146103e35780639b96ad7a146103f657600080fd5b806371e395a81461036157806380e22e7e146103a057806383829928146103a957806386001519146103c957600080fd5b80632d3008dd116101875780633f40406c116101565780633f40406c146102ef5780634e7a191a1461031257806354198ce91461032557806370a082311461033857600080fd5b80632d3008dd146102a9578063313ce567146102ba57806339509351146102c957806339d91ec3146102dc57600080fd5b806318160ddd116101c357806318160ddd146102555780631b7150301461025d57806323b872dd146102665780632ba591751461027957600080fd5b806301c9c3b7146101ea57806306fdde031461021d578063095ea7b314610232575b600080fd5b61020a6101f836600461180f565b60106020526000908152604090205481565b6040519081526020015b60405180910390f35b6102256104d3565b604051610214919061194b565b610245610240366004611899565b610565565b6040519015158152602001610214565b60025461020a565b61020a600d5481565b61024561027436600461185d565b61057b565b6102a76102873660046118c3565b336000908152601160205260409020805460ff1916911515919091179055565b005b61020a69bc0a9392c65c3b00000081565b60405160008152602001610214565b6102456102d7366004611899565b61062c565b6102a76102ea3660046118fd565b610668565b6102456102fd36600461180f565b60116020526000908152604090205460ff1681565b6102a76103203660046118fd565b610775565b61020a61033336600461180f565b610853565b61020a61034636600461180f565b6001600160a01b031660009081526020819052604090205490565b6103887f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610214565b61020a600e5481565b61020a6103b736600461180f565b60076020526000908152604090205481565b61020a60085481565b61020a600a5481565b61022561089e565b61020a6103f136600461180f565b6108ad565b6102a76104043660046118fd565b6109bc565b610245610417366004611899565b610a4e565b61020a61042a36600461180f565b600f6020526000908152604090205481565b61024561044a366004611899565b610ae7565b6102a761045d3660046118fd565b610af4565b61020a60065481565b6102a7610b78565b61020a61048136600461182a565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6103887f000000000000000000000000000000000000000000000000000000000000000081565b6060600380546104e290611a8b565b80601f016020809104026020016040519081016040528092919081815260200182805461050e90611a8b565b801561055b5780601f106105305761010080835404028352916020019161055b565b820191906000526020600020905b81548152906001019060200180831161053e57829003601f168201915b5050505050905090565b6000610572338484610d9d565b50600192915050565b6000610588848484610ec1565b6001600160a01b0384166000908152600160209081526040808320338452909152902054828110156106125760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b60648201526084015b60405180910390fd5b61061f8533858403610d9d565b60019150505b9392505050565b3360008181526001602090815260408083206001600160a01b038716845290915281205490916105729185906106639086906119ef565b610d9d565b600081116106885760405162461bcd60e51b8152600401610609906119c7565b600e543360009081526010602052604090205442916106a6916119ef565b106106c35760405162461bcd60e51b81526004016106099061197e565b6106cc3361109c565b80600660008282546106de9190611a48565b90915550503360009081526007602052604081208054839290610702908490611a48565b9091555061073c90506001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163383611128565b60405181815233907fe9306b701d178418bf4ab8cb60b94e25a6b7024fe6ec6c9e216ec2dc4e383a06906020015b60405180910390a250565b600081116107955760405162461bcd60e51b8152600401610609906119c7565b61079e3361109c565b336000908152601060205260408120429055600680548392906107c29084906119ef565b909155505033600090815260076020526040812080548392906107e69084906119ef565b9091555061082190506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016333084611190565b60405181815233907f4391190baaaaacfb4e8fe9299153f996ab726ab06e4d0a80a1be3c8fff79e2229060200161076a565b6000806000610861846111c8565b6001600160a01b0386166000908152600c60205260409020549193509150819061088c9084906119ef565b61089691906119ef565b949350505050565b6060600480546104e290611a8b565b60006108b88261109c565b506001600160a01b0381166000908152600c60205260409020548061090d5760405162461bcd60e51b815260206004820152600b60248201526a16995c9bc81c1c9bd99a5d60aa1b6044820152606401610609565b6001600160a01b0382166000908152600c602052604081208190556005805483929061093a908490611a48565b9091555061097490506001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168383611128565b816001600160a01b03167f47cee97cb7acd717b3c0aa1435d004cd5b3c8c57d70dbceb4e4458bbd60e39d4826040516109af91815260200190565b60405180910390a2919050565b600d54336000908152600f602052604090205442916109da916119ef565b11156109f85760405162461bcd60e51b81526004016106099061197e565b610a023382611291565b610a4b33610a1a69bc0a9392c65c3b00000084611a29565b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169190611128565b50565b3360009081526001602090815260408083206001600160a01b038616845290915281205482811015610ad05760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610609565b610add3385858403610d9d565b5060019392505050565b6000610572338484610ec1565b336000908152600f6020526040902042905580610b235760405162461bcd60e51b8152600401610609906119c7565b610b2d33826113eb565b610a4b3330610b4669bc0a9392c65c3b00000085611a29565b6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016929190611190565b6005546040516370a0823160e01b8152306004820152600091906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a082319060240160206040518083038186803b158015610bde57600080fd5b505afa158015610bf2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c169190611916565b610c209190611a48565b90508060056000828254610c3491906119ef565b9091555050600254600081600654610c4c91906119ef565b1115610d9957600654610c975780610c716c0c9f2c9cd04674edea4000000084611a29565b610c7b9190611a07565b60086000828254610c8c91906119ef565b90915550610d659050565b80610cd157600654610cb66c0c9f2c9cd04674edea4000000084611a29565b610cc09190611a07565b600a6000828254610c8c91906119ef565b6000610cde600584611a07565b90506000610cec8285611a48565b600654909150610d096c0c9f2c9cd04674edea4000000084611a29565b610d139190611a07565b600a6000828254610d2491906119ef565b90915550839050610d426c0c9f2c9cd04674edea4000000083611a29565b610d4c9190611a07565b60086000828254610d5d91906119ef565b909155505050505b6040518281527f357d905f1831209797df4d55d79c5c5bf1d9f7311c976afd05e13d881eab9bc89060200160405180910390a15b5050565b6001600160a01b038316610dff5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610609565b6001600160a01b038216610e605760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610609565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b038316610f255760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610609565b6001600160a01b038216610f875760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610609565b610f928383836114d6565b6001600160a01b0383166000908152602081905260409020548181101561100a5760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610609565b6001600160a01b038085166000908152602081905260408082208585039055918516815290812080548492906110419084906119ef565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161108d91815260200190565b60405180910390a35b50505050565b6000806110a8836111c8565b6008546001600160a01b038616600090815260096020908152604080832093909355600a54600b825283832055600c9052908120805493955091935084926110f19084906119ef565b90915550506001600160a01b0383166000908152600c60205260408120805483929061111e9084906119ef565b9091555050505050565b6040516001600160a01b03831660248201526044810182905261118b90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611616565b505050565b6040516001600160a01b03808516602483015283166044820152606481018290526110969085906323b872dd60e01b90608401611154565b6000806c0c9f2c9cd04674edea400000006111f8846001600160a01b031660009081526020819052604090205490565b6001600160a01b03851660009081526009602052604090205460085461121e9190611a48565b6112289190611a29565b6112329190611a07565b6001600160a01b038416600090815260076020908152604080832054600b90925290912054600a549294506c0c9f2c9cd04674edea40000000926112769190611a48565b6112809190611a29565b61128a9190611a07565b9050915091565b6001600160a01b0382166112f15760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610609565b6112fd826000836114d6565b6001600160a01b038216600090815260208190526040902054818110156113715760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610609565b6001600160a01b03831660009081526020819052604081208383039055600280548492906113a0908490611a48565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3505050565b6001600160a01b0382166114415760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610609565b61144d600083836114d6565b806002600082825461145f91906119ef565b90915550506001600160a01b0382166000908152602081905260408120805483929061148c9084906119ef565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b6001600160a01b038316156114ee576114ee8361109c565b6001600160a01b03821615611506576115068261109c565b600d546001600160a01b0384166000908152600f6020526040902054429161152d916119ef565b11801561155a57506001600160a01b038083166000908152600f6020526040808220549286168252902054115b1561118b576001600160a01b03821660009081526011602052604090205460ff16156115ee5760405162461bcd60e51b815260206004820152603760248201527f54686520726563697069656e7420646f6573206e6f7420616772656520746f2060448201527f61636365707420746865206c6f636b65642066756e64730000000000000000006064820152608401610609565b6001600160a01b038084166000908152600f6020526040808220549285168252902055505050565b600061166b826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166116e89092919063ffffffff16565b80519091501561118b578080602001905181019061168991906118e0565b61118b5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610609565b6060610896848460008585843b6117415760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610609565b600080866001600160a01b0316858760405161175d919061192f565b60006040518083038185875af1925050503d806000811461179a576040519150601f19603f3d011682016040523d82523d6000602084013e61179f565b606091505b50915091506117af8282866117ba565b979650505050505050565b606083156117c9575081610625565b8251156117d95782518084602001fd5b8160405162461bcd60e51b8152600401610609919061194b565b80356001600160a01b038116811461180a57600080fd5b919050565b60006020828403121561182157600080fd5b610625826117f3565b6000806040838503121561183d57600080fd5b611846836117f3565b9150611854602084016117f3565b90509250929050565b60008060006060848603121561187257600080fd5b61187b846117f3565b9250611889602085016117f3565b9150604084013590509250925092565b600080604083850312156118ac57600080fd5b6118b5836117f3565b946020939093013593505050565b6000602082840312156118d557600080fd5b813561062581611adc565b6000602082840312156118f257600080fd5b815161062581611adc565b60006020828403121561190f57600080fd5b5035919050565b60006020828403121561192857600080fd5b5051919050565b60008251611941818460208701611a5f565b9190910192915050565b602081526000825180602084015261196a816040850160208701611a5f565b601f01601f19169190910160400192915050565b60208082526029908201527f54686520616374696f6e2069732073757370656e6465642064756520746f207460408201526806865206c6f636b75760bc1b606082015260800190565b6020808252600e908201526d416d6f756e74206973207a65726f60901b604082015260600190565b60008219821115611a0257611a02611ac6565b500190565b600082611a2457634e487b7160e01b600052601260045260246000fd5b500490565b6000816000190483118215151615611a4357611a43611ac6565b500290565b600082821015611a5a57611a5a611ac6565b500390565b60005b83811015611a7a578181015183820152602001611a62565b838111156110965750506000910152565b600181811c90821680611a9f57607f821691505b60208210811415611ac057634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b8015158114610a4b57600080fdfea26469706673582212209908360c5f827822f17d695dd790dd5c9756c700e0edc1d7bc0c3a36500e2b1764736f6c63430008060033000000000000000000000000584bc13c7d411c00c01a62e8019472de68768430000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000c57425443205374616b696e67000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000065745544820530000000000000000000000000000000000000000000000000000

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106101e55760003560e01c806371e395a81161010f578063a457c2d7116100a2578063b0d05a1811610071578063b0d05a1814610462578063da34364b1461046b578063dd62ed3e14610473578063fc0c546a146104ac57600080fd5b8063a457c2d714610409578063a67372911461041c578063a9059cbb1461043c578063ac1ec28f1461044f57600080fd5b806392c1ead3116100de57806392c1ead3146103d257806395d89b41146103db578063993ac84c146103e35780639b96ad7a146103f657600080fd5b806371e395a81461036157806380e22e7e146103a057806383829928146103a957806386001519146103c957600080fd5b80632d3008dd116101875780633f40406c116101565780633f40406c146102ef5780634e7a191a1461031257806354198ce91461032557806370a082311461033857600080fd5b80632d3008dd146102a9578063313ce567146102ba57806339509351146102c957806339d91ec3146102dc57600080fd5b806318160ddd116101c357806318160ddd146102555780631b7150301461025d57806323b872dd146102665780632ba591751461027957600080fd5b806301c9c3b7146101ea57806306fdde031461021d578063095ea7b314610232575b600080fd5b61020a6101f836600461180f565b60106020526000908152604090205481565b6040519081526020015b60405180910390f35b6102256104d3565b604051610214919061194b565b610245610240366004611899565b610565565b6040519015158152602001610214565b60025461020a565b61020a600d5481565b61024561027436600461185d565b61057b565b6102a76102873660046118c3565b336000908152601160205260409020805460ff1916911515919091179055565b005b61020a69bc0a9392c65c3b00000081565b60405160008152602001610214565b6102456102d7366004611899565b61062c565b6102a76102ea3660046118fd565b610668565b6102456102fd36600461180f565b60116020526000908152604090205460ff1681565b6102a76103203660046118fd565b610775565b61020a61033336600461180f565b610853565b61020a61034636600461180f565b6001600160a01b031660009081526020819052604090205490565b6103887f000000000000000000000000584bc13c7d411c00c01a62e8019472de6876843081565b6040516001600160a01b039091168152602001610214565b61020a600e5481565b61020a6103b736600461180f565b60076020526000908152604090205481565b61020a60085481565b61020a600a5481565b61022561089e565b61020a6103f136600461180f565b6108ad565b6102a76104043660046118fd565b6109bc565b610245610417366004611899565b610a4e565b61020a61042a36600461180f565b600f6020526000908152604090205481565b61024561044a366004611899565b610ae7565b6102a761045d3660046118fd565b610af4565b61020a60065481565b6102a7610b78565b61020a61048136600461182a565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6103887f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b6060600380546104e290611a8b565b80601f016020809104026020016040519081016040528092919081815260200182805461050e90611a8b565b801561055b5780601f106105305761010080835404028352916020019161055b565b820191906000526020600020905b81548152906001019060200180831161053e57829003601f168201915b5050505050905090565b6000610572338484610d9d565b50600192915050565b6000610588848484610ec1565b6001600160a01b0384166000908152600160209081526040808320338452909152902054828110156106125760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b60648201526084015b60405180910390fd5b61061f8533858403610d9d565b60019150505b9392505050565b3360008181526001602090815260408083206001600160a01b038716845290915281205490916105729185906106639086906119ef565b610d9d565b600081116106885760405162461bcd60e51b8152600401610609906119c7565b600e543360009081526010602052604090205442916106a6916119ef565b106106c35760405162461bcd60e51b81526004016106099061197e565b6106cc3361109c565b80600660008282546106de9190611a48565b90915550503360009081526007602052604081208054839290610702908490611a48565b9091555061073c90506001600160a01b037f000000000000000000000000584bc13c7d411c00c01a62e8019472de68768430163383611128565b60405181815233907fe9306b701d178418bf4ab8cb60b94e25a6b7024fe6ec6c9e216ec2dc4e383a06906020015b60405180910390a250565b600081116107955760405162461bcd60e51b8152600401610609906119c7565b61079e3361109c565b336000908152601060205260408120429055600680548392906107c29084906119ef565b909155505033600090815260076020526040812080548392906107e69084906119ef565b9091555061082190506001600160a01b037f000000000000000000000000584bc13c7d411c00c01a62e8019472de6876843016333084611190565b60405181815233907f4391190baaaaacfb4e8fe9299153f996ab726ab06e4d0a80a1be3c8fff79e2229060200161076a565b6000806000610861846111c8565b6001600160a01b0386166000908152600c60205260409020549193509150819061088c9084906119ef565b61089691906119ef565b949350505050565b6060600480546104e290611a8b565b60006108b88261109c565b506001600160a01b0381166000908152600c60205260409020548061090d5760405162461bcd60e51b815260206004820152600b60248201526a16995c9bc81c1c9bd99a5d60aa1b6044820152606401610609565b6001600160a01b0382166000908152600c602052604081208190556005805483929061093a908490611a48565b9091555061097490506001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2168383611128565b816001600160a01b03167f47cee97cb7acd717b3c0aa1435d004cd5b3c8c57d70dbceb4e4458bbd60e39d4826040516109af91815260200190565b60405180910390a2919050565b600d54336000908152600f602052604090205442916109da916119ef565b11156109f85760405162461bcd60e51b81526004016106099061197e565b610a023382611291565b610a4b33610a1a69bc0a9392c65c3b00000084611a29565b6001600160a01b037f000000000000000000000000584bc13c7d411c00c01a62e8019472de68768430169190611128565b50565b3360009081526001602090815260408083206001600160a01b038616845290915281205482811015610ad05760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610609565b610add3385858403610d9d565b5060019392505050565b6000610572338484610ec1565b336000908152600f6020526040902042905580610b235760405162461bcd60e51b8152600401610609906119c7565b610b2d33826113eb565b610a4b3330610b4669bc0a9392c65c3b00000085611a29565b6001600160a01b037f000000000000000000000000584bc13c7d411c00c01a62e8019472de6876843016929190611190565b6005546040516370a0823160e01b8152306004820152600091906001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216906370a082319060240160206040518083038186803b158015610bde57600080fd5b505afa158015610bf2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c169190611916565b610c209190611a48565b90508060056000828254610c3491906119ef565b9091555050600254600081600654610c4c91906119ef565b1115610d9957600654610c975780610c716c0c9f2c9cd04674edea4000000084611a29565b610c7b9190611a07565b60086000828254610c8c91906119ef565b90915550610d659050565b80610cd157600654610cb66c0c9f2c9cd04674edea4000000084611a29565b610cc09190611a07565b600a6000828254610c8c91906119ef565b6000610cde600584611a07565b90506000610cec8285611a48565b600654909150610d096c0c9f2c9cd04674edea4000000084611a29565b610d139190611a07565b600a6000828254610d2491906119ef565b90915550839050610d426c0c9f2c9cd04674edea4000000083611a29565b610d4c9190611a07565b60086000828254610d5d91906119ef565b909155505050505b6040518281527f357d905f1831209797df4d55d79c5c5bf1d9f7311c976afd05e13d881eab9bc89060200160405180910390a15b5050565b6001600160a01b038316610dff5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610609565b6001600160a01b038216610e605760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610609565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b038316610f255760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610609565b6001600160a01b038216610f875760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610609565b610f928383836114d6565b6001600160a01b0383166000908152602081905260409020548181101561100a5760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610609565b6001600160a01b038085166000908152602081905260408082208585039055918516815290812080548492906110419084906119ef565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161108d91815260200190565b60405180910390a35b50505050565b6000806110a8836111c8565b6008546001600160a01b038616600090815260096020908152604080832093909355600a54600b825283832055600c9052908120805493955091935084926110f19084906119ef565b90915550506001600160a01b0383166000908152600c60205260408120805483929061111e9084906119ef565b9091555050505050565b6040516001600160a01b03831660248201526044810182905261118b90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611616565b505050565b6040516001600160a01b03808516602483015283166044820152606481018290526110969085906323b872dd60e01b90608401611154565b6000806c0c9f2c9cd04674edea400000006111f8846001600160a01b031660009081526020819052604090205490565b6001600160a01b03851660009081526009602052604090205460085461121e9190611a48565b6112289190611a29565b6112329190611a07565b6001600160a01b038416600090815260076020908152604080832054600b90925290912054600a549294506c0c9f2c9cd04674edea40000000926112769190611a48565b6112809190611a29565b61128a9190611a07565b9050915091565b6001600160a01b0382166112f15760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610609565b6112fd826000836114d6565b6001600160a01b038216600090815260208190526040902054818110156113715760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610609565b6001600160a01b03831660009081526020819052604081208383039055600280548492906113a0908490611a48565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3505050565b6001600160a01b0382166114415760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610609565b61144d600083836114d6565b806002600082825461145f91906119ef565b90915550506001600160a01b0382166000908152602081905260408120805483929061148c9084906119ef565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b6001600160a01b038316156114ee576114ee8361109c565b6001600160a01b03821615611506576115068261109c565b600d546001600160a01b0384166000908152600f6020526040902054429161152d916119ef565b11801561155a57506001600160a01b038083166000908152600f6020526040808220549286168252902054115b1561118b576001600160a01b03821660009081526011602052604090205460ff16156115ee5760405162461bcd60e51b815260206004820152603760248201527f54686520726563697069656e7420646f6573206e6f7420616772656520746f2060448201527f61636365707420746865206c6f636b65642066756e64730000000000000000006064820152608401610609565b6001600160a01b038084166000908152600f6020526040808220549285168252902055505050565b600061166b826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166116e89092919063ffffffff16565b80519091501561118b578080602001905181019061168991906118e0565b61118b5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610609565b6060610896848460008585843b6117415760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610609565b600080866001600160a01b0316858760405161175d919061192f565b60006040518083038185875af1925050503d806000811461179a576040519150601f19603f3d011682016040523d82523d6000602084013e61179f565b606091505b50915091506117af8282866117ba565b979650505050505050565b606083156117c9575081610625565b8251156117d95782518084602001fd5b8160405162461bcd60e51b8152600401610609919061194b565b80356001600160a01b038116811461180a57600080fd5b919050565b60006020828403121561182157600080fd5b610625826117f3565b6000806040838503121561183d57600080fd5b611846836117f3565b9150611854602084016117f3565b90509250929050565b60008060006060848603121561187257600080fd5b61187b846117f3565b9250611889602085016117f3565b9150604084013590509250925092565b600080604083850312156118ac57600080fd5b6118b5836117f3565b946020939093013593505050565b6000602082840312156118d557600080fd5b813561062581611adc565b6000602082840312156118f257600080fd5b815161062581611adc565b60006020828403121561190f57600080fd5b5035919050565b60006020828403121561192857600080fd5b5051919050565b60008251611941818460208701611a5f565b9190910192915050565b602081526000825180602084015261196a816040850160208701611a5f565b601f01601f19169190910160400192915050565b60208082526029908201527f54686520616374696f6e2069732073757370656e6465642064756520746f207460408201526806865206c6f636b75760bc1b606082015260800190565b6020808252600e908201526d416d6f756e74206973207a65726f60901b604082015260600190565b60008219821115611a0257611a02611ac6565b500190565b600082611a2457634e487b7160e01b600052601260045260246000fd5b500490565b6000816000190483118215151615611a4357611a43611ac6565b500290565b600082821015611a5a57611a5a611ac6565b500390565b60005b83811015611a7a578181015183820152602001611a62565b838111156110965750506000910152565b600181811c90821680611a9f57607f821691505b60208210811415611ac057634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b8015158114610a4b57600080fdfea26469706673582212209908360c5f827822f17d695dd790dd5c9756c700e0edc1d7bc0c3a36500e2b1764736f6c63430008060033

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

000000000000000000000000584bc13c7d411c00c01a62e8019472de68768430000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000c57425443205374616b696e67000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000065745544820530000000000000000000000000000000000000000000000000000

-----Decoded View---------------
Arg [0] : _hegic (address): 0x584bC13c7D411c00c01A62e8019472dE68768430
Arg [1] : _token (address): 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
Arg [2] : name (string): WBTC Staking
Arg [3] : short (string): WETH S

-----Encoded View---------------
8 Constructor Arguments found :
Arg [0] : 000000000000000000000000584bc13c7d411c00c01a62e8019472de68768430
Arg [1] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000080
Arg [3] : 00000000000000000000000000000000000000000000000000000000000000c0
Arg [4] : 000000000000000000000000000000000000000000000000000000000000000c
Arg [5] : 57425443205374616b696e670000000000000000000000000000000000000000
Arg [6] : 0000000000000000000000000000000000000000000000000000000000000006
Arg [7] : 5745544820530000000000000000000000000000000000000000000000000000


Deployed Bytecode Sourcemap

1360:7475:38:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2161:59;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;10903:25:40;;;10891:2;10876:18;2161:59:38;;;;;;;;2074:98:4;;;:::i;:::-;;;;;;;:::i;4171:166::-;;;;;;:::i;:::-;;:::i;:::-;;;3421:14:40;;3414:22;3396:41;;3384:2;3369:18;4171:166:4;3351:92:40;3162:106:4;3249:12;;3162:106;;2004:43:38;;;;;;4804:478:4;;;;;;:::i;:::-;;:::i;5325:127:38:-;;;;;;:::i;:::-;5426:10;5395:42;;;;:30;:42;;;;;:50;;-1:-1:-1;;5395:50:38;;;;;;;;;;5325:127;;;1516:54;;1560:10;1516:54;;2494:82;;;2544:5;11081:36:40;;11069:2;11054:18;2494:82:38;11036:87:40;5677:212:4;;;;;;:::i;:::-;;:::i;3898:496:38:-;;;;;;:::i;:::-;;:::i;2226:62::-;;;;;;:::i;:::-;;;;;;;;;;;;;;;;3386:394;;;;;;:::i;:::-;;:::i;5539:243::-;;;;;;:::i;:::-;;:::i;3326:125:4:-;;;;;;:::i;:::-;-1:-1:-1;;;;;3426:18:4;3400:7;3426:18;;;;;;;;;;;;3326:125;1445:29:38;;;;;;;;-1:-1:-1;;;;;2553:32:40;;;2535:51;;2523:2;2508:18;1445:29:38;2490:102:40;2053:41:38;;;;;;1701:47;;;;;;:::i;:::-;;;;;;;;;;;;;;1755:30;;;;;;1845:35;;;;;;2285:102:4;;;:::i;2734:381:38:-;;;;;;:::i;:::-;;:::i;5140:179::-;;;;;;:::i;:::-;;:::i;6376:405:4:-;;;;;;:::i;:::-;;:::i;2101:54:38:-;;;;;;:::i;:::-;;;;;;;;;;;;;;3654:172:4;;;;;;:::i;:::-;;:::i;4677:338:38:-;;;;;;:::i;:::-;;:::i;1662:33::-;;;;;;7773:830;;;:::i;3884:149:4:-;;;;;;:::i;:::-;-1:-1:-1;;;;;3999:18:4;;;3973:7;3999:18;;;:11;:18;;;;;;;;:27;;;;;;;;;;;;;3884:149;1480:29:38;;;;;2074:98:4;2128:13;2160:5;2153:12;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2074:98;:::o;4171:166::-;4254:4;4270:39;665:10:13;4293:7:4;4302:6;4270:8;:39::i;:::-;-1:-1:-1;4326:4:4;4171:166;;;;:::o;4804:478::-;4940:4;4956:36;4966:6;4974:9;4985:6;4956:9;:36::i;:::-;-1:-1:-1;;;;;5030:19:4;;5003:24;5030:19;;;:11;:19;;;;;;;;665:10:13;5030:33:4;;;;;;;;5081:26;;;;5073:79;;;;-1:-1:-1;;;5073:79:4;;7462:2:40;5073:79:4;;;7444:21:40;7501:2;7481:18;;;7474:30;7540:34;7520:18;;;7513:62;-1:-1:-1;;;7591:18:40;;;7584:38;7639:19;;5073:79:4;;;;;;;;;5186:57;5195:6;665:10:13;5236:6:4;5217:16;:25;5186:8;:57::i;:::-;5271:4;5264:11;;;4804:478;;;;;;:::o;5677:212::-;665:10:13;5765:4:4;5813:25;;;:11;:25;;;;;;;;-1:-1:-1;;;;;5813:34:4;;;;;;;;;;5765:4;;5781:80;;5804:7;;5813:47;;5850:10;;5813:47;:::i;:::-;5781:8;:80::i;3898:496:38:-;3972:1;3963:6;:10;3955:37;;;;-1:-1:-1;;;3955:37:38;;;;;;;:::i;:::-;4062:17;;4048:10;4023:36;;;;:24;:36;;;;;;4098:15;;4023:56;;;:::i;:::-;:90;4002:178;;;;-1:-1:-1;;;4002:178:38;;;;;;;:::i;:::-;4190:23;4202:10;4190:11;:23::i;:::-;4241:6;4223:14;;:24;;;;;;;:::i;:::-;;;;-1:-1:-1;;4270:10:38;4257:24;;;;:12;:24;;;;;:34;;4285:6;;4257:24;:34;;4285:6;;4257:34;:::i;:::-;;;;-1:-1:-1;4301:38:38;;-1:-1:-1;;;;;;4301:5:38;:18;4320:10;4332:6;4301:18;:38::i;:::-;4354:33;;10903:25:40;;;4368:10:38;;4354:33;;10891:2:40;10876:18;4354:33:38;;;;;;;;3898:496;:::o;3386:394::-;3459:1;3450:6;:10;3442:37;;;;-1:-1:-1;;;3442:37:38;;;;;;;:::i;:::-;3489:23;3501:10;3489:11;:23::i;:::-;3547:10;3522:36;;;;:24;:36;;;;;3561:15;3522:54;;3586:14;:24;;3604:6;;3522:36;3586:24;;3604:6;;3586:24;:::i;:::-;;;;-1:-1:-1;;3633:10:38;3620:24;;;;:12;:24;;;;;:34;;3648:6;;3620:24;:34;;3648:6;;3620:34;:::i;:::-;;;;-1:-1:-1;3664:57:38;;-1:-1:-1;;;;;;3664:5:38;:22;3687:10;3707:4;3714:6;3664:22;:57::i;:::-;3736:37;;10903:25:40;;;3754:10:38;;3736:37;;10891:2:40;10876:18;3736:37:38;10858:76:40;5539:243:38;5638:7;5662:14;5678:13;5695:26;5713:7;5695:17;:26::i;:::-;-1:-1:-1;;;;;5738:20:38;;;;;;:11;:20;;;;;;5661:60;;-1:-1:-1;5661:60:38;-1:-1:-1;5661:60:38;;5738:29;;5661:60;;5738:29;:::i;:::-;:37;;;;:::i;:::-;5731:44;5539:243;-1:-1:-1;;;;5539:243:38:o;2285:102:4:-;2341:13;2373:7;2366:14;;;;;:::i;2734:381:38:-;2824:14;2854:20;2866:7;2854:11;:20::i;:::-;-1:-1:-1;;;;;;2893:20:38;;;;;;:11;:20;;;;;;2931:10;2923:34;;;;-1:-1:-1;;;2923:34:38;;10259:2:40;2923:34:38;;;10241:21:40;10298:2;10278:18;;;10271:30;-1:-1:-1;;;10317:18:40;;;10310:41;10368:18;;2923:34:38;10231:161:40;2923:34:38;-1:-1:-1;;;;;2967:20:38;;2990:1;2967:20;;;:11;:20;;;;;:24;;;3001:15;:25;;3020:6;;2990:1;3001:25;;3020:6;;3001:25;:::i;:::-;;;;-1:-1:-1;3036:35:38;;-1:-1:-1;;;;;;3036:5:38;:18;3055:7;3064:6;3036:18;:35::i;:::-;3092:7;-1:-1:-1;;;;;3086:22:38;;3101:6;3086:22;;;;10903:25:40;;10891:2;10876:18;;10858:76;3086:22:38;;;;;;;;2734:381;;;:::o;5140:179::-;8694:19;;8680:10;8660:31;;;;:19;:31;;;;;;8733:15;;8660:53;;;:::i;:::-;:88;;8639:176;;;;-1:-1:-1;;;8639:176:38;;;;;;;:::i;:::-;5219:25:::1;5225:10;5237:6;5219:5;:25::i;:::-;5254:58;5273:10;5285:26;1560:10;5285:6:::0;:26:::1;:::i;:::-;-1:-1:-1::0;;;;;5254:5:38::1;:18;::::0;:58;:18:::1;:58::i;:::-;5140:179:::0;:::o;6376:405:4:-;665:10:13;6469:4:4;6512:25;;;:11;:25;;;;;;;;-1:-1:-1;;;;;6512:34:4;;;;;;;;;;6564:35;;;;6556:85;;;;-1:-1:-1;;;6556:85:4;;9853:2:40;6556:85:4;;;9835:21:40;9892:2;9872:18;;;9865:30;9931:34;9911:18;;;9904:62;-1:-1:-1;;;9982:18:40;;;9975:35;10027:19;;6556:85:4;9825:227:40;6556:85:4;6675:67;665:10:13;6698:7:4;6726:15;6707:16;:34;6675:8;:67::i;:::-;-1:-1:-1;6770:4:4;;6376:405;-1:-1:-1;;;6376:405:4:o;3654:172::-;3740:4;3756:42;665:10:13;3780:9:4;3791:6;3756:9;:42::i;4677:338:38:-;4764:10;4744:31;;;;:19;:31;;;;;4778:15;4744:49;;4811:10;4803:37;;;;-1:-1:-1;;;4803:37:38;;;;;;;:::i;:::-;4850:25;4856:10;4868:6;4850:5;:25::i;:::-;4885:123;4921:10;4953:4;4972:26;1560:10;4972:6;:26;:::i;:::-;-1:-1:-1;;;;;4885:5:38;:22;;:123;;:22;:123::i;7773:830::-;7890:15;;7857:30;;-1:-1:-1;;;7857:30:38;;7881:4;7857:30;;;2535:51:40;7840:14:38;;7890:15;-1:-1:-1;;;;;7857:5:38;:15;;;;2508:18:40;;7857:30:38;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;:48;;;;:::i;:::-;7840:65;;7934:6;7915:15;;:25;;;;;;;:::i;:::-;;;;-1:-1:-1;;3249:12:4;;8032:1:38;8017:12;8000:14;;:29;;;;:::i;:::-;:33;7996:601;;;8053:14;;8049:505;;8129:12;8108:17;1613:4;8108:6;:17;:::i;:::-;8107:34;;;;:::i;:::-;8092:11;;:49;;;;;;;:::i;:::-;;;;-1:-1:-1;8049:505:38;;-1:-1:-1;8049:505:38;;8166:17;8162:392;;8245:14;;8224:17;1613:4;8224:6;:17;:::i;:::-;8223:36;;;;:::i;:::-;8203:16;;:56;;;;;;;:::i;8162:392::-;8298:19;8320:10;8329:1;8320:6;:10;:::i;:::-;8298:32;-1:-1:-1;8348:18:38;8369:20;8298:32;8369:6;:20;:::i;:::-;8454:14;;8348:41;;-1:-1:-1;8428:22:38;1613:4;8428:11;:22;:::i;:::-;8427:41;;;;:::i;:::-;8407:16;;:61;;;;;;;:::i;:::-;;;;-1:-1:-1;8527:12:38;;-1:-1:-1;8502:21:38;1613:4;8502:10;:21;:::i;:::-;8501:38;;;;:::i;:::-;8486:11;;:53;;;;;;;:::i;:::-;;;;-1:-1:-1;;;;8162:392:38;8572:14;;10903:25:40;;;8572:14:38;;10891:2:40;10876:18;8572:14:38;;;;;;;7996:601;7830:773;;7773:830::o;9952:370:4:-;-1:-1:-1;;;;;10083:19:4;;10075:68;;;;-1:-1:-1;;;10075:68:4;;8679:2:40;10075:68:4;;;8661:21:40;8718:2;8698:18;;;8691:30;8757:34;8737:18;;;8730:62;-1:-1:-1;;;8808:18:40;;;8801:34;8852:19;;10075:68:4;8651:226:40;10075:68:4;-1:-1:-1;;;;;10161:21:4;;10153:68;;;;-1:-1:-1;;;10153:68:4;;5068:2:40;10153:68:4;;;5050:21:40;5107:2;5087:18;;;5080:30;5146:34;5126:18;;;5119:62;-1:-1:-1;;;5197:18:40;;;5190:32;5239:19;;10153:68:4;5040:224:40;10153:68:4;-1:-1:-1;;;;;10232:18:4;;;;;;;:11;:18;;;;;;;;:27;;;;;;;;;;;;;:36;;;10283:32;;10903:25:40;;;10283:32:4;;10876:18:40;10283:32:4;;;;;;;9952:370;;;:::o;7255:713::-;-1:-1:-1;;;;;7390:20:4;;7382:70;;;;-1:-1:-1;;;7382:70:4;;8273:2:40;7382:70:4;;;8255:21:40;8312:2;8292:18;;;8285:30;8351:34;8331:18;;;8324:62;-1:-1:-1;;;8402:18:40;;;8395:35;8447:19;;7382:70:4;8245:227:40;7382:70:4;-1:-1:-1;;;;;7470:23:4;;7462:71;;;;-1:-1:-1;;;7462:71:4;;4261:2:40;7462:71:4;;;4243:21:40;4300:2;4280:18;;;4273:30;4339:34;4319:18;;;4312:62;-1:-1:-1;;;4390:18:40;;;4383:33;4433:19;;7462:71:4;4233:225:40;7462:71:4;7544:47;7565:6;7573:9;7584:6;7544:20;:47::i;:::-;-1:-1:-1;;;;;7626:17:4;;7602:21;7626:17;;;;;;;;;;;7661:23;;;;7653:74;;;;-1:-1:-1;;;7653:74:4;;5471:2:40;7653:74:4;;;5453:21:40;5510:2;5490:18;;;5483:30;5549:34;5529:18;;;5522:62;-1:-1:-1;;;5600:18:40;;;5593:36;5646:19;;7653:74:4;5443:228:40;7653:74:4;-1:-1:-1;;;;;7761:17:4;;;:9;:17;;;;;;;;;;;7781:22;;;7761:42;;7823:20;;;;;;;;:30;;7797:6;;7761:9;7823:30;;7797:6;;7823:30;:::i;:::-;;;;;;;;7886:9;-1:-1:-1;;;;;7869:35:4;7878:6;-1:-1:-1;;;;;7869:35:4;;7897:6;7869:35;;;;10903:25:40;;10891:2;10876:18;;10858:76;7869:35:4;;;;;;;;7915:46;7372:596;7255:713;;;:::o;6703:305:38:-;6761:15;6778:13;6795:26;6813:7;6795:17;:26::i;:::-;6853:11;;-1:-1:-1;;;;;6831:19:38;;;;;;:10;:19;;;;;;;;:33;;;;6905:16;;6874:19;:28;;;;;:47;6931:11;:20;;;;;:31;;6760:61;;-1:-1:-1;6760:61:38;;-1:-1:-1;6760:61:38;;6931:31;;6760:61;;6931:31;:::i;:::-;;;;-1:-1:-1;;;;;;;6972:20:38;;;;;;:11;:20;;;;;:29;;6996:5;;6972:20;:29;;6996:5;;6972:29;:::i;:::-;;;;-1:-1:-1;;;;;6703:305:38:o;634:205:7:-;773:58;;-1:-1:-1;;;;;3169:32:40;;773:58:7;;;3151:51:40;3218:18;;;3211:34;;;746:86:7;;766:5;;-1:-1:-1;;;796:23:7;3124:18:40;;773:58:7;;;;-1:-1:-1;;773:58:7;;;;;;;;;;;;;;-1:-1:-1;;;;;773:58:7;-1:-1:-1;;;;;;773:58:7;;;;;;;;;;746:19;:86::i;:::-;634:205;;;:::o;845:241::-;1010:68;;-1:-1:-1;;;;;2855:15:40;;;1010:68:7;;;2837:34:40;2907:15;;2887:18;;;2880:43;2939:18;;;2932:34;;;983:96:7;;1003:5;;-1:-1:-1;;;1033:27:7;2772:18:40;;1010:68:7;2754:218:40;6054:387:38;6145:13;6160;1613:4;6248:18;6258:7;-1:-1:-1;;;;;3426:18:4;3400:7;3426:18;;;;;;;;;;;;3326:125;6248:18:38;-1:-1:-1;;;;;6225:19:38;;;;;;:10;:19;;;;;;6211:11;;:33;;6225:19;6211:33;:::i;:::-;6210:56;;;;:::i;:::-;6209:81;;;;:::i;:::-;-1:-1:-1;;;;;6389:21:38;;;;;;:12;:21;;;;;;;;;6341:19;:28;;;;;;;6322:16;;6189:101;;-1:-1:-1;1613:4:38;;6322:47;;6341:28;6322:47;:::i;:::-;6321:89;;;;:::i;:::-;6320:114;;;;:::i;:::-;6300:134;;6054:387;;;:::o;8953:576:4:-;-1:-1:-1;;;;;9036:21:4;;9028:67;;;;-1:-1:-1;;;9028:67:4;;7871:2:40;9028:67:4;;;7853:21:40;7910:2;7890:18;;;7883:30;7949:34;7929:18;;;7922:62;-1:-1:-1;;;8000:18:40;;;7993:31;8041:19;;9028:67:4;7843:223:40;9028:67:4;9106:49;9127:7;9144:1;9148:6;9106:20;:49::i;:::-;-1:-1:-1;;;;;9191:18:4;;9166:22;9191:18;;;;;;;;;;;9227:24;;;;9219:71;;;;-1:-1:-1;;;9219:71:4;;4665:2:40;9219:71:4;;;4647:21:40;4704:2;4684:18;;;4677:30;4743:34;4723:18;;;4716:62;-1:-1:-1;;;4794:18:40;;;4787:32;4836:19;;9219:71:4;4637:224:40;9219:71:4;-1:-1:-1;;;;;9324:18:4;;:9;:18;;;;;;;;;;9345:23;;;9324:44;;9388:12;:22;;9362:6;;9324:9;9388:22;;9362:6;;9388:22;:::i;:::-;;;;-1:-1:-1;;9426:37:4;;10903:25:40;;;9452:1:4;;-1:-1:-1;;;;;9426:37:4;;;;;10891:2:40;10876:18;9426:37:4;;;;;;;634:205:7;;;:::o;8244:389:4:-;-1:-1:-1;;;;;8327:21:4;;8319:65;;;;-1:-1:-1;;;8319:65:4;;10599:2:40;8319:65:4;;;10581:21:40;10638:2;10618:18;;;10611:30;10677:33;10657:18;;;10650:61;10728:18;;8319:65:4;10571:181:40;8319:65:4;8395:49;8424:1;8428:7;8437:6;8395:20;:49::i;:::-;8471:6;8455:12;;:22;;;;;;;:::i;:::-;;;;-1:-1:-1;;;;;;;8487:18:4;;:9;:18;;;;;;;;;;:28;;8509:6;;8487:9;:28;;8509:6;;8487:28;:::i;:::-;;;;-1:-1:-1;;8530:37:4;;10903:25:40;;;-1:-1:-1;;;;;8530:37:4;;;8547:1;;8530:37;;10891:2:40;10876:18;8530:37:4;;;;;;;7830:773:38;;7773:830::o;7014:626::-;-1:-1:-1;;;;;7141:18:38;;;7137:41;;7161:17;7173:4;7161:11;:17::i;:::-;-1:-1:-1;;;;;7192:16:38;;;7188:37;;7210:15;7222:2;7210:11;:15::i;:::-;7280:19;;-1:-1:-1;;;;;7252:25:38;;;;;;:19;:25;;;;;;7302:15;;7252:47;;;:::i;:::-;:65;:132;;;;-1:-1:-1;;;;;;7361:23:38;;;;;;;:19;:23;;;;;;;7333:25;;;;;;;;:51;7252:132;7235:399;;;-1:-1:-1;;;;;7435:34:38;;;;;;:30;:34;;;;;;;;7434:35;7409:149;;;;-1:-1:-1;;;7409:149:38;;6695:2:40;7409:149:38;;;6677:21:40;6734:2;6714:18;;;6707:30;6773:34;6753:18;;;6746:62;6844:25;6824:18;;;6817:53;6887:19;;7409:149:38;6667:245:40;7409:149:38;-1:-1:-1;;;;;7598:25:38;;;;;;;:19;:25;;;;;;;7572:23;;;;;;;:51;7014:626;;;:::o;3140:706:7:-;3559:23;3585:69;3613:4;3585:69;;;;;;;;;;;;;;;;;3593:5;-1:-1:-1;;;;;3585:27:7;;;:69;;;;;:::i;:::-;3668:17;;3559:95;;-1:-1:-1;3668:21:7;3664:176;;3763:10;3752:30;;;;;;;;;;;;:::i;:::-;3744:85;;;;-1:-1:-1;;;3744:85:7;;9442:2:40;3744:85:7;;;9424:21:40;9481:2;9461:18;;;9454:30;9520:34;9500:18;;;9493:62;-1:-1:-1;;;9571:18:40;;;9564:40;9621:19;;3744:85:7;9414:232:40;3461:223:12;3594:12;3625:52;3647:6;3655:4;3661:1;3664:12;3594;1034:20;;4828:60;;;;-1:-1:-1;;;4828:60:12;;9084:2:40;4828:60:12;;;9066:21:40;9123:2;9103:18;;;9096:30;9162:31;9142:18;;;9135:59;9211:18;;4828:60:12;9056:179:40;4828:60:12;4900:12;4914:23;4941:6;-1:-1:-1;;;;;4941:11:12;4960:5;4967:4;4941:31;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4899:73;;;;4989:52;5007:7;5016:10;5028:12;4989:17;:52::i;:::-;4982:59;4548:500;-1:-1:-1;;;;;;;4548:500:12:o;6950:692::-;7096:12;7124:7;7120:516;;;-1:-1:-1;7154:10:12;7147:17;;7120:516;7265:17;;:21;7261:365;;7459:10;7453:17;7519:15;7506:10;7502:2;7498:19;7491:44;7261:365;7598:12;7591:20;;-1:-1:-1;;;7591:20:12;;;;;;;;:::i;14:173:40:-;82:20;;-1:-1:-1;;;;;131:31:40;;121:42;;111:2;;177:1;174;167:12;111:2;63:124;;;:::o;192:186::-;251:6;304:2;292:9;283:7;279:23;275:32;272:2;;;320:1;317;310:12;272:2;343:29;362:9;343:29;:::i;383:260::-;451:6;459;512:2;500:9;491:7;487:23;483:32;480:2;;;528:1;525;518:12;480:2;551:29;570:9;551:29;:::i;:::-;541:39;;599:38;633:2;622:9;618:18;599:38;:::i;:::-;589:48;;470:173;;;;;:::o;648:328::-;725:6;733;741;794:2;782:9;773:7;769:23;765:32;762:2;;;810:1;807;800:12;762:2;833:29;852:9;833:29;:::i;:::-;823:39;;881:38;915:2;904:9;900:18;881:38;:::i;:::-;871:48;;966:2;955:9;951:18;938:32;928:42;;752:224;;;;;:::o;981:254::-;1049:6;1057;1110:2;1098:9;1089:7;1085:23;1081:32;1078:2;;;1126:1;1123;1116:12;1078:2;1149:29;1168:9;1149:29;:::i;:::-;1139:39;1225:2;1210:18;;;;1197:32;;-1:-1:-1;;;1068:167:40:o;1240:241::-;1296:6;1349:2;1337:9;1328:7;1324:23;1320:32;1317:2;;;1365:1;1362;1355:12;1317:2;1404:9;1391:23;1423:28;1445:5;1423:28;:::i;1486:245::-;1553:6;1606:2;1594:9;1585:7;1581:23;1577:32;1574:2;;;1622:1;1619;1612:12;1574:2;1654:9;1648:16;1673:28;1695:5;1673:28;:::i;1736:180::-;1795:6;1848:2;1836:9;1827:7;1823:23;1819:32;1816:2;;;1864:1;1861;1854:12;1816:2;-1:-1:-1;1887:23:40;;1806:110;-1:-1:-1;1806:110:40:o;1921:184::-;1991:6;2044:2;2032:9;2023:7;2019:23;2015:32;2012:2;;;2060:1;2057;2050:12;2012:2;-1:-1:-1;2083:16:40;;2002:103;-1:-1:-1;2002:103:40:o;2110:274::-;2239:3;2277:6;2271:13;2293:53;2339:6;2334:3;2327:4;2319:6;2315:17;2293:53;:::i;:::-;2362:16;;;;;2247:137;-1:-1:-1;;2247:137:40:o;3671:383::-;3820:2;3809:9;3802:21;3783:4;3852:6;3846:13;3895:6;3890:2;3879:9;3875:18;3868:34;3911:66;3970:6;3965:2;3954:9;3950:18;3945:2;3937:6;3933:15;3911:66;:::i;:::-;4038:2;4017:15;-1:-1:-1;;4013:29:40;3998:45;;;;4045:2;3994:54;;3792:262;-1:-1:-1;;3792:262:40:o;5676:405::-;5878:2;5860:21;;;5917:2;5897:18;;;5890:30;5956:34;5951:2;5936:18;;5929:62;-1:-1:-1;;;6022:2:40;6007:18;;6000:39;6071:3;6056:19;;5850:231::o;6917:338::-;7119:2;7101:21;;;7158:2;7138:18;;;7131:30;-1:-1:-1;;;7192:2:40;7177:18;;7170:44;7246:2;7231:18;;7091:164::o;11128:128::-;11168:3;11199:1;11195:6;11192:1;11189:13;11186:2;;;11205:18;;:::i;:::-;-1:-1:-1;11241:9:40;;11176:80::o;11261:217::-;11301:1;11327;11317:2;;11371:10;11366:3;11362:20;11359:1;11352:31;11406:4;11403:1;11396:15;11434:4;11431:1;11424:15;11317:2;-1:-1:-1;11463:9:40;;11307:171::o;11483:168::-;11523:7;11589:1;11585;11581:6;11577:14;11574:1;11571:21;11566:1;11559:9;11552:17;11548:45;11545:2;;;11596:18;;:::i;:::-;-1:-1:-1;11636:9:40;;11535:116::o;11656:125::-;11696:4;11724:1;11721;11718:8;11715:2;;;11729:18;;:::i;:::-;-1:-1:-1;11766:9:40;;11705:76::o;11786:258::-;11858:1;11868:113;11882:6;11879:1;11876:13;11868:113;;;11958:11;;;11952:18;11939:11;;;11932:39;11904:2;11897:10;11868:113;;;11999:6;11996:1;11993:13;11990:2;;;-1:-1:-1;;12034:1:40;12016:16;;12009:27;11839:205::o;12049:380::-;12128:1;12124:12;;;;12171;;;12192:2;;12246:4;12238:6;12234:17;12224:27;;12192:2;12299;12291:6;12288:14;12268:18;12265:38;12262:2;;;12345:10;12340:3;12336:20;12333:1;12326:31;12380:4;12377:1;12370:15;12408:4;12405:1;12398:15;12262:2;;12104:325;;;:::o;12434:127::-;12495:10;12490:3;12486:20;12483:1;12476:31;12526:4;12523:1;12516:15;12550:4;12547:1;12540:15;12566:118;12652:5;12645:13;12638:21;12631:5;12628:32;12618:2;;12674:1;12671;12664:12

Swarm Source

ipfs://9908360c5f827822f17d695dd790dd5c9756c700e0edc1d7bc0c3a36500e2b17

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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