ETH Price: $3,403.06 (+2.05%)

Contract

0x4b8e58D252ba251e044ec63125E83172ECa5118f
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Set Governance145193182022-04-04 11:39:11999 days ago1649072351IN
0x4b8e58D2...2ECa5118f
0 ETH0.0016105356.31229829
Set Unipilot Det...145014832022-04-01 16:33:301002 days ago1648830810IN
0x4b8e58D2...2ECa5118f
0 ETH0.00347309102.35163583
Create Vault144963882022-03-31 21:33:041003 days ago1648762384IN
0x4b8e58D2...2ECa5118f
0 ETH0.1694502440
Create Vault144962052022-03-31 20:50:091003 days ago1648759809IN
0x4b8e58D2...2ECa5118f
0 ETH0.1703347640
Create Vault144962002022-03-31 20:49:321003 days ago1648759772IN
0x4b8e58D2...2ECa5118f
0 ETH0.1673576939.50581506
Create Vault144962002022-03-31 20:49:321003 days ago1648759772IN
0x4b8e58D2...2ECa5118f
0 ETH0.1673576939.50581506
Create Vault144959642022-03-31 19:59:011003 days ago1648756741IN
0x4b8e58D2...2ECa5118f
0 ETH0.2079067549.07766981

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block
From
To
173913012023-06-02 6:31:59576 days ago1685687519
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
172137032023-05-08 5:29:23601 days ago1683523763
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
171790412023-05-03 8:33:11606 days ago1683102791
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
171790412023-05-03 8:33:11606 days ago1683102791
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
171790412023-05-03 8:33:11606 days ago1683102791
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
171150952023-04-24 8:55:47615 days ago1682326547
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
169896312023-04-06 12:41:23632 days ago1680784883
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
169895722023-04-06 12:29:23632 days ago1680784163
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
169323332023-03-29 10:23:23641 days ago1680085403
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
168905582023-03-23 13:33:23646 days ago1679578403
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
167333252023-03-01 10:57:59668 days ago1677668279
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
167254952023-02-28 8:33:35670 days ago1677573215
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
167202272023-02-27 14:49:11670 days ago1677509351
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
156959742022-10-07 11:37:11813 days ago1665142631
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
154336092022-08-29 10:34:16853 days ago1661769256
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
154335992022-08-29 10:32:25853 days ago1661769145
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
149193442022-06-07 6:32:03936 days ago1654583523
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
148721582022-05-30 10:56:34943 days ago1653908194
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
148721532022-05-30 10:54:38943 days ago1653908078
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
145769762022-04-13 12:00:00990 days ago1649851200
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
145636502022-04-11 9:40:19993 days ago1649670019
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
144963882022-03-31 21:33:041003 days ago1648762384
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
144962052022-03-31 20:50:091003 days ago1648759809
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
144962002022-03-31 20:49:321003 days ago1648759772
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
144962002022-03-31 20:49:321003 days ago1648759772
0x4b8e58D2...2ECa5118f
 Contract Creation0 ETH
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
UnipilotActiveFactory

Compiler Version
v0.7.6+commit.7338295f

Optimization Enabled:
Yes with 10 runs

Other Settings:
default evmVersion
File 1 of 36 : UnipilotActiveFactory.sol
//SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;

import "./UnipilotActiveVault.sol";
import "./interfaces/IUnipilotFactory.sol";
import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol";
import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

/// @title Unipilot Active Factory
/// @author 0xMudassir & 721Orbit
/// @notice Deploys Unipilot active vaults and manages ownership and control over all active vaults
/// active liquidity managament strategy will be used in these vaults
/// all active vaults will be managed by Unipilot Captains
contract UnipilotActiveFactory is IUnipilotFactory {
    address private governance;
    address private strategy;
    address private indexFund;
    address private WETH;
    uint8 private swapPercentage;
    uint8 private indexFundPercentage;
    IUniswapV3Factory private uniswapFactory;

    constructor(
        address _uniswapFactory,
        address _governance,
        address _uniStrategy,
        address _indexFund,
        address _WETH,
        uint8 percentage
    ) {
        governance = _governance;
        strategy = _uniStrategy;
        uniswapFactory = IUniswapV3Factory(_uniswapFactory);
        indexFund = _indexFund;
        WETH = _WETH;
        indexFundPercentage = percentage;
    }

    /// @inheritdoc IUnipilotFactory
    mapping(address => bool) public override isWhitelist;

    /// @inheritdoc IUnipilotFactory
    mapping(address => mapping(address => mapping(uint24 => address)))
        public
        override vaults;

    modifier onlyGovernance() {
        require(msg.sender == governance);
        _;
    }

    /// @inheritdoc IUnipilotFactory
    function getUnipilotDetails()
        external
        view
        override
        returns (
            address,
            address,
            address,
            uint8,
            uint8
        )
    {
        return (
            governance,
            strategy,
            indexFund,
            indexFundPercentage,
            swapPercentage
        );
    }

    /// @inheritdoc IUnipilotFactory
    function createVault(
        address _tokenA,
        address _tokenB,
        uint24 _fee,
        uint160 _sqrtPriceX96,
        string memory _name,
        string memory _symbol
    ) external override onlyGovernance returns (address _vault) {
        require(_tokenA != _tokenB);
        (address token0, address token1) = _tokenA < _tokenB
            ? (_tokenA, _tokenB)
            : (_tokenB, _tokenA);
        require(vaults[token0][token1][_fee] == address(0));
        address pool = uniswapFactory.getPool(token0, token1, _fee);

        if (pool == address(0)) {
            pool = uniswapFactory.createPool(token0, token1, _fee);
            IUniswapV3Pool(pool).initialize(_sqrtPriceX96);
        }

        _vault = address(
            new UnipilotActiveVault{
                salt: keccak256(abi.encodePacked(_tokenA, _tokenB, _fee))
            }(pool, address(this), WETH, governance, _name, _symbol)
        );

        vaults[token0][token1][_fee] = _vault;
        vaults[token1][token0][_fee] = _vault; // populate mapping in the reverse direction
        emit VaultCreated(token0, token1, _fee, _vault);
    }

    /// @notice Updates the governance of the Unipilot factory
    /// @dev Must be called by the current governance
    /// @param _newGovernance The new governance of the Unipilot factory
    function setGovernance(address _newGovernance) external onlyGovernance {
        require(_newGovernance != address(0));
        emit GovernanceChanged(governance, _newGovernance);
        governance = _newGovernance;
    }

    /// @notice Updates the whitelist status of given account
    /// @dev Must be called by the current governance
    /// @param _address Account to update status
    function toggleWhitelistAccount(address _address) external onlyGovernance {
        isWhitelist[_address] = !isWhitelist[_address];
    }

    /// @notice Updates all the necessary Unipilot details used in active vaults
    /// @dev Must be called by the current governance
    /// @param _strategy Unipilot strategy address
    /// @param _indexFund Unipilot index fund account
    /// @param _indexFundPercentage Percentage of fees for index fund
    function setUnipilotDetails(
        address _strategy,
        address _indexFund,
        uint8 _indexFundPercentage
    ) external onlyGovernance {
        strategy = _strategy;
        indexFund = _indexFund;
        indexFundPercentage = _indexFundPercentage;
    }
}

File 2 of 36 : UnipilotActiveVault.sol
//SPDX-License-Identifier: MIT
pragma solidity 0.7.6;
pragma abicoder v2;

import "./libraries/TransferHelper.sol";
import "./interfaces/external/IWETH9.sol";
import "./interfaces/IUnipilotVault.sol";
import "./interfaces/IUnipilotStrategy.sol";
import "./interfaces/IUnipilotFactory.sol";
import "./libraries/UniswapLiquidityManagement.sol";
import "./libraries/UniswapPoolActions.sol";

import "@openzeppelin/contracts/drafts/ERC20Permit.sol";

/// @title Unipilot Active Vault
/// @author 0xMudassir & 721Orbit
/// @dev Active liquidity managment contract that handles user liquidity of any Uniswap V3 pool & earn fees for them
/// @dev minimalist, and gas-optimized contract that ensures user liquidity is always
/// in range and earns maximum amount of fees available at current liquidity utilization
/// rate.
/// @dev In order to minimize IL for users contract pulls liquidity to the vault (HODL) when necessary
contract UnipilotActiveVault is ERC20Permit, IUnipilotVault {
    using LowGasSafeMath for uint256;
    using UniswapPoolActions for IUniswapV3Pool;
    using UniswapLiquidityManagement for IUniswapV3Pool;

    IERC20 private token0;
    IERC20 private token1;
    uint24 private fee;
    int24 private tickSpacing;

    TicksData public ticksData;
    IUniswapV3Pool private pool;
    IUnipilotFactory private unipilotFactory;

    address private WETH;
    uint32 private _pulled = 1;
    uint32 private _unlocked = 1;
    uint32 private _initialized = 1;

    mapping(address => bool) private _operatorApproved;

    modifier onlyGovernance() {
        (address governance, , , , ) = getProtocolDetails();
        require(msg.sender == governance);
        _;
    }

    modifier onlyOperator() {
        require(_operatorApproved[msg.sender]);
        _;
    }

    modifier nonReentrant() {
        require(_unlocked == 1);
        _unlocked = 2;
        _;
        _unlocked = 1;
    }

    modifier checkDeviation() {
        (, address strategy, , , ) = getProtocolDetails();
        IUnipilotStrategy(strategy).checkDeviation(address(pool));
        _;
    }

    constructor(
        address _pool,
        address _unipilotFactory,
        address _WETH,
        address governance,
        string memory _name,
        string memory _symbol
    ) ERC20Permit(_name) ERC20(_name, _symbol) {
        WETH = _WETH;
        unipilotFactory = IUnipilotFactory(_unipilotFactory);
        pool = IUniswapV3Pool(_pool);
        token0 = IERC20(pool.token0());
        token1 = IERC20(pool.token1());
        fee = pool.fee();
        tickSpacing = pool.tickSpacing();
        _operatorApproved[governance] = true;
    }

    receive() external payable {}

    fallback() external payable {}

    /// @dev sets initial position of the vault & can only called once by the governer
    function init() external onlyGovernance {
        require(_initialized == 1);
        _initialized = 2;
        int24 _tickSpacing = tickSpacing;
        int24 baseThreshold = _tickSpacing * getBaseThreshold();
        (, int24 currentTick, ) = pool.getSqrtRatioX96AndTick();

        int24 tickFloor = UniswapLiquidityManagement.floor(
            currentTick,
            _tickSpacing
        );

        ticksData.baseTickLower = tickFloor - baseThreshold;
        ticksData.baseTickUpper = tickFloor + baseThreshold;

        UniswapLiquidityManagement.checkRange(
            ticksData.baseTickLower,
            ticksData.baseTickUpper
        );
    }

    /// @inheritdoc IUnipilotVault
    function deposit(
        uint256 amount0Desired,
        uint256 amount1Desired,
        address recipient
    )
        external
        payable
        override
        nonReentrant
        returns (
            uint256 lpShares,
            uint256 amount0,
            uint256 amount1
        )
    {
        require(amount0Desired > 0 && amount1Desired > 0);

        address sender = _msgSender();
        (lpShares, amount0, amount1) = pool.computeLpShares(
            true,
            amount0Desired,
            amount1Desired,
            _balance0(),
            _balance1(),
            totalSupply(),
            ticksData
        );

        pay(address(token0), sender, address(this), amount0);
        pay(address(token1), sender, address(this), amount1);

        if (_pulled == 1) {
            pool.mintLiquidity(
                ticksData.baseTickLower,
                ticksData.baseTickUpper,
                amount0,
                amount1
            );
        }

        if (address(this).balance > 0)
            TransferHelper.safeTransferETH(msg.sender, address(this).balance);

        _mint(recipient, lpShares);
        emit Deposit(sender, recipient, amount0, amount1, lpShares);
    }

    /// @inheritdoc IUnipilotVault
    function withdraw(
        uint256 liquidity,
        address recipient,
        bool refundAsETH
    )
        external
        override
        nonReentrant
        returns (uint256 amount0, uint256 amount1)
    {
        require(liquidity > 0);
        uint256 totalSupply = totalSupply();

        /// @dev if liquidity has pulled in contract then calculate share accordingly
        if (_pulled == 1) {
            uint256 liquidityShare = FullMath.mulDiv(
                liquidity,
                1e18,
                totalSupply
            );

            (amount0, amount1) = pool.burnUserLiquidity(
                ticksData.baseTickLower,
                ticksData.baseTickUpper,
                liquidityShare,
                address(this)
            );

            (uint256 fees0, uint256 fees1) = pool.collectPendingFees(
                address(this),
                ticksData.baseTickLower,
                ticksData.baseTickUpper
            );

            transferFeesToIF(false, fees0, fees1);
        }

        uint256 unusedAmount0 = FullMath.mulDiv(
            _balance0().sub(amount0),
            liquidity,
            totalSupply
        );

        uint256 unusedAmount1 = FullMath.mulDiv(
            _balance1().sub(amount1),
            liquidity,
            totalSupply
        );

        amount0 = amount0.add(unusedAmount0);
        amount1 = amount1.add(unusedAmount1);

        if (amount0 > 0) {
            transferFunds(refundAsETH, recipient, address(token0), amount0);
        }

        if (amount1 > 0) {
            transferFunds(refundAsETH, recipient, address(token1), amount1);
        }

        _burn(msg.sender, liquidity);
        emit Withdraw(recipient, liquidity, amount0, amount1);

        if (_pulled == 1) {
            (uint256 c0, uint256 c1) = pool.mintLiquidity(
                ticksData.baseTickLower,
                ticksData.baseTickUpper,
                _balance0(),
                _balance1()
            );

            emit CompoundFees(c0, c1);
        }
    }

    /// @inheritdoc IUnipilotVault
    function readjustLiquidity() external override onlyOperator checkDeviation {
        _pulled = 1;
        ReadjustVars memory a;

        (uint128 totalLiquidity, , ) = pool.getPositionLiquidity(
            ticksData.baseTickLower,
            ticksData.baseTickUpper
        );

        (a.amount0Desired, a.amount1Desired, a.fees0, a.fees1) = pool
            .burnLiquidity(
                ticksData.baseTickLower,
                ticksData.baseTickUpper,
                address(this)
            );

        transferFeesToIF(true, a.fees0, a.fees1);

        int24 baseThreshold = tickSpacing * getBaseThreshold();
        (, a.currentTick, ) = pool.getSqrtRatioX96AndTick();

        (a.tickLower, a.tickUpper) = UniswapLiquidityManagement.getBaseTicks(
            a.currentTick,
            baseThreshold,
            tickSpacing
        );

        if (
            (totalLiquidity > 0) &&
            (a.amount0Desired == 0 || a.amount1Desired == 0)
        ) {
            bool zeroForOne = a.amount0Desired > 0 ? true : false;

            int256 amountSpecified = zeroForOne
                ? int256(FullMath.mulDiv(a.amount0Desired, 50, 100))
                : int256(FullMath.mulDiv(a.amount1Desired, 50, 100));

            pool.swapToken(address(this), zeroForOne, amountSpecified);
        } else {
            a.amount0Desired = _balance0();
            a.amount1Desired = _balance1();

            a.liquidity = pool.getLiquidityForAmounts(
                a.amount0Desired,
                a.amount1Desired,
                a.tickLower,
                a.tickUpper
            );

            (a.amount0, a.amount1) = pool.getAmountsForLiquidity(
                a.liquidity,
                a.tickLower,
                a.tickUpper
            );

            a.zeroForOne = UniswapLiquidityManagement.amountsDirection(
                a.amount0Desired,
                a.amount1Desired,
                a.amount0,
                a.amount1
            );

            a.amountSpecified = a.zeroForOne
                ? int256(
                    FullMath.mulDiv(a.amount0Desired.sub(a.amount0), 50, 100)
                )
                : int256(
                    FullMath.mulDiv(a.amount1Desired.sub(a.amount1), 50, 100)
                );

            pool.swapToken(address(this), a.zeroForOne, a.amountSpecified);
        }

        a.amount0Desired = _balance0();
        a.amount1Desired = _balance1();

        (ticksData.baseTickLower, ticksData.baseTickUpper) = pool
            .getPositionTicks(
                a.amount0Desired,
                a.amount1Desired,
                baseThreshold,
                tickSpacing
            );

        pool.mintLiquidity(
            ticksData.baseTickLower,
            ticksData.baseTickUpper,
            a.amount0Desired,
            a.amount1Desired
        );
    }

    /// @notice Updates Unipilot's position.
    /// @dev Finds base position and limit position for imbalanced token
    /// mints all amounts to this position(including earned fees)
    /// @dev Must be called by the current governer or selected operators
    function rerange() external onlyOperator {
        _pulled = 1;

        (, , uint256 fees0, uint256 fees1) = pool.burnLiquidity(
            ticksData.baseTickLower,
            ticksData.baseTickUpper,
            address(this)
        );

        transferFeesToIF(true, fees0, fees1);

        int24 baseThreshold = tickSpacing * getBaseThreshold();

        (ticksData.baseTickLower, ticksData.baseTickUpper) = pool
            .rerangeLiquidity(
                baseThreshold,
                tickSpacing,
                _balance0(),
                _balance1()
            );
    }

    /// @inheritdoc IUnipilotVault
    function uniswapV3MintCallback(
        uint256 amount0Owed,
        uint256 amount1Owed,
        bytes calldata data
    ) external override {
        _verifyCallback();
        address recipient = msg.sender;
        address payer = abi.decode(data, (address));
        if (amount0Owed > 0)
            pay(address(token0), payer, recipient, amount0Owed);
        if (amount1Owed > 0)
            pay(address(token1), payer, recipient, amount1Owed);
    }

    /// @inheritdoc IUnipilotVault
    function uniswapV3SwapCallback(
        int256 amount0,
        int256 amount1,
        bytes calldata data
    ) external override {
        _verifyCallback();

        require(amount0 > 0 || amount1 > 0);
        bool zeroForOne = abi.decode(data, (bool));

        if (zeroForOne)
            pay(address(token0), address(this), msg.sender, uint256(amount0));
        else pay(address(token1), address(this), msg.sender, uint256(amount1));
    }

    /// @dev Burns all the Unipilot position and HODL in the vault to prevent users from huge IL
    /// Only called by the governer or selected operators
    /// @dev Users can also deposit/withdraw during HODL period.
    function pullLiquidity(address recipient) external onlyOperator {
        require(unipilotFactory.isWhitelist(recipient));

        (
            uint256 reserves0,
            uint256 reserves1,
            uint256 fees0,
            uint256 fees1
        ) = pool.burnLiquidity(
                ticksData.baseTickLower,
                ticksData.baseTickUpper,
                recipient
            );

        if (recipient != address(this)) {
            pay(address(token0), address(this), recipient, _balance0());
            pay(address(token1), address(this), recipient, _balance1());
        }

        _pulled = 2;
        emit PullLiquidity(reserves0, reserves1, fees0, fees1);
    }

    /// @notice Calculates the vault's total holdings of TOKEN0 and TOKEN1 - in
    /// other words, how much of each token the vault would hold if it withdrew
    /// all its liquidity from Uniswap.
    /// @dev Updates the position and return the updated reserves, fees & liquidity.
    /// @return amount0 Amount of token0 in the unipilot vault
    /// @return amount1 Amount of token1 in the unipilot vault
    /// @return fees0 Total amount of fees collected by unipilot position in terms of token0
    /// @return fees1 Total amount of fees collected by unipilot position in terms of token1
    /// @return baseLiquidity The total liquidity of the base position
    /// @return rangeLiquidity The total liquidity of the range position - N/A for active vault
    function getPositionDetails()
        external
        returns (
            uint256 amount0,
            uint256 amount1,
            uint256 fees0,
            uint256 fees1,
            uint128 baseLiquidity,
            uint128 rangeLiquidity
        )
    {
        return pool.getTotalAmounts(true, ticksData);
    }

    /// @notice Updates the status of given account as operator
    /// @dev Must be called by the current governance
    /// @param _operator Account to update status
    function toggleOperator(address _operator) external onlyGovernance {
        _operatorApproved[_operator] = !_operatorApproved[_operator];
    }

    /// @notice Returns the status for a given operator that can operate readjust & pull liquidity
    function isOperator(address _operator) external view returns (bool) {
        return _operatorApproved[_operator];
    }

    /// @notice Returns unipilot vault details
    /// @return The first of the two tokens of the pool, sorted by address
    /// @return The second of the two tokens of the pool, sorted by address
    /// @return The pool's fee in hundredths of a bip, i.e. 1e-6
    /// @return The address of the Uniswap V3 Pool
    function getVaultInfo()
        external
        view
        returns (
            address,
            address,
            uint24,
            address
        )
    {
        return (address(token0), address(token1), fee, address(pool));
    }

    /// @dev Amount of token0 held as unused balance.
    function _balance0() internal view returns (uint256) {
        return token0.balanceOf(address(this));
    }

    /// @dev Amount of token1 held as unused balance.
    function _balance1() internal view returns (uint256) {
        return token1.balanceOf(address(this));
    }

    /// @notice Verify that caller should be the address of a valid Uniswap V3 Pool
    function _verifyCallback() internal view {
        require(msg.sender == address(pool));
    }

    function getBaseThreshold() internal view returns (int24 baseThreshold) {
        (, address strategy, , , ) = getProtocolDetails();
        return IUnipilotStrategy(strategy).getBaseThreshold(address(pool));
    }

    function getProtocolDetails()
        internal
        view
        returns (
            address governance,
            address strategy,
            address indexFund,
            uint8 indexFundPercentage,
            uint8 swapPercentage
        )
    {
        return unipilotFactory.getUnipilotDetails();
    }

    /// @dev method to transfer unipilot earned fees to Index Fund
    function transferFeesToIF(
        bool isReadjustLiquidity,
        uint256 fees0,
        uint256 fees1
    ) internal {
        (, , address indexFund, uint8 percentage, ) = getProtocolDetails();

        if (fees0 > 0)
            TransferHelper.safeTransfer(
                address(token0),
                indexFund,
                FullMath.mulDiv(fees0, percentage, 100)
            );

        if (fees1 > 0)
            TransferHelper.safeTransfer(
                address(token1),
                indexFund,
                FullMath.mulDiv(fees1, percentage, 100)
            );

        emit FeesSnapshot(isReadjustLiquidity, fees0, fees1);
    }

    function transferFunds(
        bool refundAsETH,
        address recipient,
        address token,
        uint256 amount
    ) internal {
        if (refundAsETH && token == WETH) {
            IWETH9(WETH).withdraw(amount);
            TransferHelper.safeTransferETH(recipient, amount);
        } else {
            TransferHelper.safeTransfer(token, recipient, amount);
        }
    }

    /// @param token The token to pay
    /// @param payer The entity that must pay
    /// @param recipient The entity that will receive payment
    /// @param value The amount to pay
    function pay(
        address token,
        address payer,
        address recipient,
        uint256 value
    ) internal {
        if (token == WETH && address(this).balance >= value) {
            // pay with WETH9
            IWETH9(WETH).deposit{ value: value }(); // wrap only what is needed to pay
            IWETH9(WETH).transfer(recipient, value);
        } else if (payer == address(this)) {
            // pay with tokens already in the contract (for the exact input multihop case)
            TransferHelper.safeTransfer(token, recipient, value);
        } else {
            // pull payment
            TransferHelper.safeTransferFrom(token, payer, recipient, value);
        }
    }
}

File 3 of 36 : IUnipilotFactory.sol
//SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;

/// @title The interface for the Unipilot Factory
interface IUnipilotFactory {
    /// @notice Emitted when a vault is created
    /// @param _tokenA The first token of the pool by address sort order
    /// @param _tokenB The second token of the pool by address sort order
    /// @param _fee The fee tier for which the vault is created
    /// @param _vault The address of the vault that is created
    event VaultCreated(
        address indexed _tokenA,
        address indexed _tokenB,
        uint24 _fee,
        address indexed _vault
    );

    /// @notice Emitted when the governance of the factory is changed
    /// @param _oldGovernance The governance before the governance was changed
    /// @param _newGovernance The governance after the governance was changed
    event GovernanceChanged(
        address indexed _oldGovernance,
        address indexed _newGovernance
    );

    /// @notice Creates a vault for the given two tokens and fee
    /// @param _tokenA The first token of the pool by address sort order
    /// @param _tokenB The second token of the pool by address sort order
    /// @param _fee The desired fee for the unipilot vault
    /// @dev tokenA and tokenB may be passed in either order: token0/token1 or token1/token0.
    /// The call will revert if the vault already exists, the fee is invalid, or the token arguments
    /// are invalid.
    /// @return _vault The address of the newly created pool
    function createVault(
        address _tokenA,
        address _tokenB,
        uint24 _fee,
        uint160 _sqrtPriceX96,
        string memory _name,
        string memory _symbol
    ) external returns (address _vault);

    /// @notice Returns the vault address for a given uniswap v3 pair of tokens and a fee
    /// @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order
    /// @param tokenA The contract address of either token0 or token1
    /// @param tokenB The contract address of the other token
    /// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
    /// @return vault The vault address
    function vaults(
        address tokenA,
        address tokenB,
        uint24 fee
    ) external view returns (address vault);

    /// @notice Returns the status for a given account that can recieve the vault reserves after pull liquidity
    /// @dev by default vault address will be whitelist as a recipient in order to resist IL
    /// @dev Only applicable for active vaults
    function isWhitelist(address recipient) external view returns (bool);

    /// @notice Used to give addresses of governance, strategy, indexFund
    /// @return governance address, strategy address, indexFund address
    function getUnipilotDetails()
        external
        view
        returns (
            address,
            address,
            address,
            uint8,
            uint8
        );
}

File 4 of 36 : IUniswapV3Factory.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title The interface for the Uniswap V3 Factory
/// @notice The Uniswap V3 Factory facilitates creation of Uniswap V3 pools and control over the protocol fees
interface IUniswapV3Factory {
    /// @notice Emitted when the owner of the factory is changed
    /// @param oldOwner The owner before the owner was changed
    /// @param newOwner The owner after the owner was changed
    event OwnerChanged(address indexed oldOwner, address indexed newOwner);

    /// @notice Emitted when a pool is created
    /// @param token0 The first token of the pool by address sort order
    /// @param token1 The second token of the pool by address sort order
    /// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
    /// @param tickSpacing The minimum number of ticks between initialized ticks
    /// @param pool The address of the created pool
    event PoolCreated(
        address indexed token0,
        address indexed token1,
        uint24 indexed fee,
        int24 tickSpacing,
        address pool
    );

    /// @notice Emitted when a new fee amount is enabled for pool creation via the factory
    /// @param fee The enabled fee, denominated in hundredths of a bip
    /// @param tickSpacing The minimum number of ticks between initialized ticks for pools created with the given fee
    event FeeAmountEnabled(uint24 indexed fee, int24 indexed tickSpacing);

    /// @notice Returns the current owner of the factory
    /// @dev Can be changed by the current owner via setOwner
    /// @return The address of the factory owner
    function owner() external view returns (address);

    /// @notice Returns the tick spacing for a given fee amount, if enabled, or 0 if not enabled
    /// @dev A fee amount can never be removed, so this value should be hard coded or cached in the calling context
    /// @param fee The enabled fee, denominated in hundredths of a bip. Returns 0 in case of unenabled fee
    /// @return The tick spacing
    function feeAmountTickSpacing(uint24 fee) external view returns (int24);

    /// @notice Returns the pool address for a given pair of tokens and a fee, or address 0 if it does not exist
    /// @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order
    /// @param tokenA The contract address of either token0 or token1
    /// @param tokenB The contract address of the other token
    /// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
    /// @return pool The pool address
    function getPool(
        address tokenA,
        address tokenB,
        uint24 fee
    ) external view returns (address pool);

    /// @notice Creates a pool for the given two tokens and fee
    /// @param tokenA One of the two tokens in the desired pool
    /// @param tokenB The other of the two tokens in the desired pool
    /// @param fee The desired fee for the pool
    /// @dev tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. tickSpacing is retrieved
    /// from the fee. The call will revert if the pool already exists, the fee is invalid, or the token arguments
    /// are invalid.
    /// @return pool The address of the newly created pool
    function createPool(
        address tokenA,
        address tokenB,
        uint24 fee
    ) external returns (address pool);

    /// @notice Updates the owner of the factory
    /// @dev Must be called by the current owner
    /// @param _owner The new owner of the factory
    function setOwner(address _owner) external;

    /// @notice Enables a fee amount with the given tickSpacing
    /// @dev Fee amounts may never be removed once enabled
    /// @param fee The fee amount to enable, denominated in hundredths of a bip (i.e. 1e-6)
    /// @param tickSpacing The spacing between ticks to be enforced for all pools created with the given fee amount
    function enableFeeAmount(uint24 fee, int24 tickSpacing) external;
}

File 5 of 36 : IUniswapV3Pool.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import './pool/IUniswapV3PoolImmutables.sol';
import './pool/IUniswapV3PoolState.sol';
import './pool/IUniswapV3PoolDerivedState.sol';
import './pool/IUniswapV3PoolActions.sol';
import './pool/IUniswapV3PoolOwnerActions.sol';
import './pool/IUniswapV3PoolEvents.sol';

/// @title The interface for a Uniswap V3 Pool
/// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform
/// to the ERC20 specification
/// @dev The pool interface is broken up into many smaller pieces
interface IUniswapV3Pool is
    IUniswapV3PoolImmutables,
    IUniswapV3PoolState,
    IUniswapV3PoolDerivedState,
    IUniswapV3PoolActions,
    IUniswapV3PoolOwnerActions,
    IUniswapV3PoolEvents
{

}

File 6 of 36 : ERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

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

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

    mapping (address => uint256) private _balances;

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

    uint256 private _totalSupply;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        _beforeTokenTransfer(sender, recipient, amount);

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

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

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

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

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

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

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

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

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

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

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

File 7 of 36 : TransferHelper.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.6.0;

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

//import "../interfaces/external/IERC20.sol";

library TransferHelper {
    /// @notice Transfers tokens from the targeted address to the given destination
    /// @notice Errors with 'STF' if transfer fails
    /// @param token The contract address of the token to be transferred
    /// @param from The originating address from which the tokens will be transferred
    /// @param to The destination address of the transfer
    /// @param value The amount to be transferred
    function safeTransferFrom(
        address token,
        address from,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) = token.call(
            abi.encodeWithSelector(
                IERC20.transferFrom.selector,
                from,
                to,
                value
            )
        );
        require(
            success && (data.length == 0 || abi.decode(data, (bool))),
            "STF"
        );
    }

    /// @notice Transfers tokens from msg.sender to a recipient
    /// @dev Errors with ST if transfer fails
    /// @param token The contract address of the token which will be transferred
    /// @param to The recipient of the transfer
    /// @param value The value of the transfer
    function safeTransfer(
        address token,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) = token.call(
            abi.encodeWithSelector(IERC20.transfer.selector, to, value)
        );
        require(
            success && (data.length == 0 || abi.decode(data, (bool))),
            "ST"
        );
    }

    /// @notice Approves the stipulated contract to spend the given allowance in the given token
    /// @dev Errors with 'SA' if transfer fails
    /// @param token The contract address of the token to be approved
    /// @param to The target of the approval
    /// @param value The amount of the given token the target will be allowed to spend
    function safeApprove(
        address token,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) = token.call(
            abi.encodeWithSelector(IERC20.approve.selector, to, value)
        );
        require(
            success && (data.length == 0 || abi.decode(data, (bool))),
            "SA"
        );
    }

    /// @notice Transfers ETH to the recipient address
    /// @dev Fails with `STE`
    /// @param to The destination of the transfer
    /// @param value The value to be transferred
    function safeTransferETH(address to, uint256 value) internal {
        (bool success, ) = to.call{ value: value }(new bytes(0));
        require(success, "STE");
    }
}

File 8 of 36 : IWETH9.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;

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

/// @title Interface for WETH9
interface IWETH9 is IERC20 {
    /// @notice Deposit ether to get wrapped ether
    function deposit() external payable;

    /// @notice Withdraw wrapped ether to get ether
    function withdraw(uint256) external;
}

File 9 of 36 : IUnipilotVault.sol
//SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;

interface IUnipilotVault {
    struct ReadjustVars {
        uint256 fees0;
        uint256 fees1;
        int24 currentTick;
        int24 tickLower;
        int24 tickUpper;
        uint256 amount0Desired;
        uint256 amount1Desired;
        uint128 liquidity;
        uint256 amount0;
        uint256 amount1;
        bool zeroForOne;
        int256 amountSpecified;
        uint160 exactSqrtPriceImpact;
        uint160 sqrtPriceLimitX96;
    }

    struct TicksData {
        int24 baseTickLower;
        int24 baseTickUpper;
        int24 rangeTickLower;
        int24 rangeTickUpper;
    }

    struct Tick {
        int24 baseTickLower;
        int24 baseTickUpper;
        int24 bidTickLower;
        int24 bidTickUpper;
        int24 rangeTickLower;
        int24 rangeTickUpper;
    }

    struct Cache {
        uint256 totalSupply;
        uint256 liquidityShare;
    }

    event Deposit(
        address indexed depositor,
        address indexed recipient,
        uint256 amount0,
        uint256 amount1,
        uint256 lpShares
    );

    event FeesSnapshot(bool isReadjustLiquidity, uint256 fees0, uint256 fees1);

    event Withdraw(
        address indexed recipient,
        uint256 shares,
        uint256 amount0,
        uint256 amount1
    );

    event PullLiquidity(
        uint256 reserves0,
        uint256 reserves1,
        uint256 fees0,
        uint256 fees1
    );

    event CompoundFees(uint256 amount0, uint256 amount1);

    /// @notice Deposits tokens in proportion to the Unipilot's current holdings & mints them
    /// `Unipilot`s LP token.
    /// @param amount0Desired Max amount of token0 to deposit
    /// @param amount1Desired Max amount of token1 to deposit
    /// @param recipient Recipient of shares
    /// @return lpShares Number of shares minted
    /// @return amount0 Amount of token0 deposited in vault
    /// @return amount1 Amount of token1 deposited in vault
    function deposit(
        uint256 amount0Desired,
        uint256 amount1Desired,
        address recipient
    )
        external
        payable
        returns (
            uint256 lpShares,
            uint256 amount0,
            uint256 amount1
        );

    /// @notice Withdraws the desired shares from the vault with accumulated user fees and transfers to recipient.
    /// @param recipient Recipient of tokens
    /// @param refundAsETH whether to recieve in WETH or ETH (only valid for WETH/ALT pairs)
    /// @return amount0 Amount of token0 sent to recipient
    /// @return amount1 Amount of token1 sent to recipient
    function withdraw(
        uint256 liquidity,
        address recipient,
        bool refundAsETH
    ) external returns (uint256 amount0, uint256 amount1);

    /// @notice Pull in tokens from sender. Called to `msg.sender` after minting liquidity to a position from IUniswapV3Pool#mint.
    /// @dev In the implementation you must pay to the pool for the minted liquidity.
    /// @param amount0Owed The amount of token0 due to the pool for the minted liquidity
    /// @param amount1Owed The amount of token1 due to the pool for the minted liquidity
    /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#mint call
    function uniswapV3MintCallback(
        uint256 amount0Owed,
        uint256 amount1Owed,
        bytes calldata data
    ) external;

    /// @notice Called to `msg.sender` after minting swaping from IUniswapV3Pool#swap.
    /// @dev In the implementation you must pay to the pool for swap.
    /// @param amount0Delta The amount of token0 due to the pool for the swap
    /// @param amount1Delta The amount of token1 due to the pool for the swap
    /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call
    function uniswapV3SwapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes calldata data
    ) external;

    /// @notice Burns all position(s), collects any fees accrued and updates Unipilot's position(s)
    /// @dev mints all amounts to this position(s) (including earned fees)
    /// @dev For active vaults it can be called by the governance or operator,
    /// swaps imbalanced token and add all liquidity in base position.
    /// @dev For passive vaults it can be called by any user.
    /// Two positions are placed - a base position and a limit position. The base
    /// position is placed first with as much liquidity as possible. This position
    /// should use up all of one token, leaving only the other one. This excess
    /// amount is then placed as a single-sided bid or ask position.
    function readjustLiquidity() external;
}

File 10 of 36 : IUnipilotStrategy.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.6;
pragma abicoder v2;

interface IUnipilotStrategy {
    struct PoolStrategy {
        int24 baseThreshold;
        int24 rangeThreshold;
        int24 maxTwapDeviation;
        int24 readjustThreshold;
        uint32 twapDuration;
        int24 baseMultiplier;
    }

    event GovernanceUpdated(address oldGovernance, address newGovernance);
    event StrategyUpdated(PoolStrategy oldStrategy, PoolStrategy newStrategy);
    event MaxTwapDeviationUpdated(int24 oldDeviation, int24 newDeviation);
    event BaseTicksUpdated(int24 oldBaseTicks, int24 newBaseTicks);
    event RangeTicksUpdated(int24 oldRangeTicks, int24 newRangeTicks);
    event TwapDurationUpdated(uint32 oldDuration, uint32 newDuration);
    event ReadjustMultiplierUpdated(int24 oldMultiplier, int24 newMultiplier);

    function getTicks(address _pool)
        external
        returns (
            int24 baseLower,
            int24 baseUpper,
            int24 bidLower,
            int24 bidUpper,
            int24 askLower,
            int24 askUpper
        );

    function getTwap(address _pool) external view returns (int24);

    function getStrategy(address _pool)
        external
        view
        returns (PoolStrategy memory strategy);

    function getBaseThreshold(address _pool)
        external
        view
        returns (int24 baseThreshold);

    function twapDuration() external view returns (uint32);

    function maxTwapDeviation() external view returns (int24);

    function checkDeviation(address pool) external view;
}

File 11 of 36 : UniswapLiquidityManagement.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import "./UniswapPoolActions.sol";
import "@uniswap/v3-core/contracts/libraries/TickMath.sol";
import "@uniswap/v3-core/contracts/libraries/SqrtPriceMath.sol";
import "@uniswap/v3-periphery/contracts/libraries/PositionKey.sol";
import "@uniswap/v3-periphery/contracts/libraries/LiquidityAmounts.sol";
import "../interfaces/IUnipilotVault.sol";

/// @title Liquidity and ticks functions
/// @notice Provides functions for computing liquidity and ticks for token amounts and prices
library UniswapLiquidityManagement {
    using LowGasSafeMath for uint256;

    struct Info {
        uint256 amount0Desired;
        uint256 amount1Desired;
        uint256 amount0;
        uint256 amount1;
        uint128 liquidity;
        int24 tickLower;
        int24 tickUpper;
    }

    /// @dev Wrapper around `LiquidityAmounts.getAmountsForLiquidity()`.
    /// @param pool Uniswap V3 pool
    /// @param liquidity  The liquidity being valued
    /// @param _tickLower The lower tick of the range
    /// @param _tickUpper The upper tick of the range
    /// @return amounts of token0 and token1 that corresponds to liquidity
    function getAmountsForLiquidity(
        IUniswapV3Pool pool,
        uint128 liquidity,
        int24 _tickLower,
        int24 _tickUpper
    ) internal view returns (uint256, uint256) {
        (uint160 sqrtRatioX96, , , , , , ) = pool.slot0();
        return
            LiquidityAmounts.getAmountsForLiquidity(
                sqrtRatioX96,
                TickMath.getSqrtRatioAtTick(_tickLower),
                TickMath.getSqrtRatioAtTick(_tickUpper),
                liquidity
            );
    }

    /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmounts()`.
    /// @param pool Uniswap V3 pool
    /// @param amount0 The amount of token0
    /// @param amount1 The amount of token1
    /// @param _tickLower The lower tick of the range
    /// @param _tickUpper The upper tick of the range
    /// @return The maximum amount of liquidity that can be held amount0 and amount1
    function getLiquidityForAmounts(
        IUniswapV3Pool pool,
        uint256 amount0,
        uint256 amount1,
        int24 _tickLower,
        int24 _tickUpper
    ) internal view returns (uint128) {
        (uint160 sqrtRatioX96, , , , , , ) = pool.slot0();

        return
            LiquidityAmounts.getLiquidityForAmounts(
                sqrtRatioX96,
                TickMath.getSqrtRatioAtTick(_tickLower),
                TickMath.getSqrtRatioAtTick(_tickUpper),
                amount0,
                amount1
            );
    }

    /// @dev Amount of liquidity in contract position.
    /// @param pool Uniswap V3 pool
    /// @param _tickLower The lower tick of the range
    /// @param _tickUpper The upper tick of the range
    /// @return liquidity stored in position
    function getPositionLiquidity(
        IUniswapV3Pool pool,
        int24 _tickLower,
        int24 _tickUpper
    )
        internal
        view
        returns (
            uint128 liquidity,
            uint128 tokensOwed0,
            uint128 tokensOwed1
        )
    {
        bytes32 positionKey = PositionKey.compute(
            address(this),
            _tickLower,
            _tickUpper
        );
        (liquidity, , , tokensOwed0, tokensOwed1) = pool.positions(positionKey);
    }

    /// @dev Rounds tick down towards negative infinity so that it's a multiple
    /// of `tickSpacing`.
    function floor(int24 tick, int24 tickSpacing)
        internal
        pure
        returns (int24)
    {
        int24 compressed = tick / tickSpacing;
        if (tick < 0 && tick % tickSpacing != 0) compressed--;
        return compressed * tickSpacing;
    }

    function getSqrtRatioX96AndTick(IUniswapV3Pool pool)
        internal
        view
        returns (
            uint160 _sqrtRatioX96,
            int24 _tick,
            uint16 observationCardinality
        )
    {
        (_sqrtRatioX96, _tick, , observationCardinality, , , ) = pool.slot0();
    }

    /// @dev Calc base ticks depending on base threshold and tickspacing
    function getBaseTicks(
        int24 currentTick,
        int24 baseThreshold,
        int24 tickSpacing
    ) internal pure returns (int24 tickLower, int24 tickUpper) {
        int24 tickFloor = floor(currentTick, tickSpacing);
        tickLower = tickFloor - baseThreshold;
        tickUpper = tickFloor + baseThreshold;
    }

    function collectableAmountsInPosition(
        IUniswapV3Pool pool,
        int24 _lowerTick,
        int24 _upperTick
    )
        internal
        view
        returns (
            uint256,
            uint256,
            uint256,
            uint256
        )
    {
        (
            uint128 liquidity,
            uint128 earnable0,
            uint128 earnable1
        ) = getPositionLiquidity(pool, _lowerTick, _upperTick);
        (uint256 burnable0, uint256 burnable1) = UniswapLiquidityManagement
            .getAmountsForLiquidity(pool, liquidity, _lowerTick, _upperTick);

        return (burnable0, burnable1, earnable0, earnable1);
    }

    function computeLpShares(
        IUniswapV3Pool pool,
        bool isWhitelisted,
        uint256 amount0Max,
        uint256 amount1Max,
        uint256 balance0,
        uint256 balance1,
        uint256 totalSupply,
        IUnipilotVault.TicksData memory ticks
    )
        internal
        returns (
            uint256 shares,
            uint256 amount0,
            uint256 amount1
        )
    {
        (
            uint256 res0,
            uint256 res1,
            uint256 fees0,
            uint256 fees1,
            ,

        ) = getTotalAmounts(pool, isWhitelisted, ticks);

        uint256 reserve0 = res0.add(fees0).add(balance0);
        uint256 reserve1 = res1.add(fees1).add(balance1);

        // If total supply > 0, pool can't be empty
        assert(totalSupply == 0 || reserve0 != 0 || reserve1 != 0);
        (shares, amount0, amount1) = calculateShare(
            amount0Max,
            amount1Max,
            reserve0,
            reserve1,
            totalSupply
        );
    }

    function getTotalAmounts(
        IUniswapV3Pool pool,
        bool isWhitelisted,
        IUnipilotVault.TicksData memory ticks
    )
        internal
        returns (
            uint256 amount0,
            uint256 amount1,
            uint256 fees0,
            uint256 fees1,
            uint128 baseLiquidity,
            uint128 rangeLiquidity
        )
    {
        (amount0, amount1, fees0, fees1, baseLiquidity) = getReserves(
            pool,
            ticks.baseTickLower,
            ticks.baseTickUpper
        );

        if (!isWhitelisted) {
            (
                uint256 range0,
                uint256 range1,
                uint256 rangeFees0,
                uint256 rangeFees1,
                uint128 rangeliquidity
            ) = getReserves(pool, ticks.rangeTickLower, ticks.rangeTickUpper);

            amount0 = amount0.add(range0);
            amount1 = amount1.add(range1);
            fees0 = fees0.add(rangeFees0);
            fees1 = fees1.add(rangeFees1);
            rangeLiquidity = rangeliquidity;
        }
    }

    function getReserves(
        IUniswapV3Pool pool,
        int24 tickLower,
        int24 tickUpper
    )
        internal
        returns (
            uint256 amount0,
            uint256 amount1,
            uint256 fees0,
            uint256 fees1,
            uint128 liquidity
        )
    {
        liquidity = UniswapPoolActions.updatePosition(
            pool,
            tickLower,
            tickUpper
        );
        if (liquidity > 0) {
            (amount0, amount1, fees0, fees1) = collectableAmountsInPosition(
                pool,
                tickLower,
                tickUpper
            );
        }
    }

    function calculateShare(
        uint256 amount0Max,
        uint256 amount1Max,
        uint256 reserve0,
        uint256 reserve1,
        uint256 totalSupply
    )
        internal
        pure
        returns (
            uint256 shares,
            uint256 amount0,
            uint256 amount1
        )
    {
        if (totalSupply == 0) {
            // For first deposit, just use the amounts desired
            amount0 = amount0Max;
            amount1 = amount1Max;
            shares = amount0 > amount1 ? amount0 : amount1; // max
        } else if (reserve0 == 0) {
            amount1 = amount1Max;
            shares = FullMath.mulDiv(amount1, totalSupply, reserve1);
        } else if (reserve1 == 0) {
            amount0 = amount0Max;
            shares = FullMath.mulDiv(amount0, totalSupply, reserve0);
        } else {
            amount0 = FullMath.mulDiv(amount1Max, reserve0, reserve1);
            if (amount0 < amount0Max) {
                amount1 = amount1Max;
                shares = FullMath.mulDiv(amount1, totalSupply, reserve1);
            } else {
                amount0 = amount0Max;
                amount1 = FullMath.mulDiv(amount0, reserve1, reserve0);
                shares = FullMath.mulDiv(amount0, totalSupply, reserve0);
            }
        }
    }

    /// @dev Gets ticks with proportion equivalent to desired amount
    /// @param pool Uniswap V3 pool
    /// @param amount0Desired The desired amount of token0
    /// @param amount1Desired The desired amount of token1
    /// @param baseThreshold The range for upper and lower ticks
    /// @param tickSpacing The pool tick spacing
    /// @return tickLower The lower tick of the range
    /// @return tickUpper The upper tick of the range
    function getPositionTicks(
        IUniswapV3Pool pool,
        uint256 amount0Desired,
        uint256 amount1Desired,
        int24 baseThreshold,
        int24 tickSpacing
    ) internal view returns (int24 tickLower, int24 tickUpper) {
        Info memory cache = Info(amount0Desired, amount1Desired, 0, 0, 0, 0, 0);
        // Get current price and tick from the pool
        (uint160 sqrtPriceX96, int24 currentTick, , , , , ) = pool.slot0();
        //Calc base ticks
        (cache.tickLower, cache.tickUpper) = getBaseTicks(
            currentTick,
            baseThreshold,
            tickSpacing
        );
        //Calc amounts of token0 and token1 that can be stored in base range
        (cache.amount0, cache.amount1) = getAmountsForTicks(
            pool,
            cache.amount0Desired,
            cache.amount1Desired,
            cache.tickLower,
            cache.tickUpper
        );
        // //Liquidity that can be stored in base range
        cache.liquidity = getLiquidityForAmounts(
            pool,
            cache.amount0,
            cache.amount1,
            cache.tickLower,
            cache.tickUpper
        );

        // //Get imbalanced token
        bool zeroGreaterOne = amountsDirection(
            cache.amount0Desired,
            cache.amount1Desired,
            cache.amount0,
            cache.amount1
        );

        //Calc new tick(upper or lower) for imbalanced token
        if (zeroGreaterOne) {
            uint160 nextSqrtPrice0 = SqrtPriceMath
                .getNextSqrtPriceFromAmount0RoundingUp(
                    sqrtPriceX96,
                    cache.liquidity,
                    cache.amount0Desired,
                    false
                );
            cache.tickUpper = floor(
                TickMath.getTickAtSqrtRatio(nextSqrtPrice0),
                tickSpacing
            );
        } else {
            uint160 nextSqrtPrice1 = SqrtPriceMath
                .getNextSqrtPriceFromAmount1RoundingDown(
                    sqrtPriceX96,
                    cache.liquidity,
                    cache.amount1Desired,
                    false
                );
            cache.tickLower = floor(
                TickMath.getTickAtSqrtRatio(nextSqrtPrice1),
                tickSpacing
            );
        }

        checkRange(cache.tickLower, cache.tickUpper);

        /// floor the tick again because one tick is still not valid tick due to + - baseThreshold
        tickLower = floor(cache.tickLower, tickSpacing);
        tickUpper = floor(cache.tickUpper, tickSpacing);
    }

    /// @dev Gets amounts of token0 and token1 that can be stored in range of upper and lower ticks
    /// @param pool Uniswap V3 pool
    /// @param amount0Desired The desired amount of token0
    /// @param amount1Desired The desired amount of token1
    /// @param _tickLower The lower tick of the range
    /// @param _tickUpper The upper tick of the range
    /// @return amount0 amounts of token0 that can be stored in range
    /// @return amount1 amounts of token1 that can be stored in range
    function getAmountsForTicks(
        IUniswapV3Pool pool,
        uint256 amount0Desired,
        uint256 amount1Desired,
        int24 _tickLower,
        int24 _tickUpper
    ) internal view returns (uint256 amount0, uint256 amount1) {
        uint128 liquidity = getLiquidityForAmounts(
            pool,
            amount0Desired,
            amount1Desired,
            _tickLower,
            _tickUpper
        );

        (amount0, amount1) = getAmountsForLiquidity(
            pool,
            liquidity,
            _tickLower,
            _tickUpper
        );
    }

    /// @dev Common checks for valid tick inputs.
    /// @param tickLower The lower tick of the range
    /// @param tickUpper The upper tick of the range
    function checkRange(int24 tickLower, int24 tickUpper) internal pure {
        require(tickLower < tickUpper, "TLU");
        require(tickLower >= TickMath.MIN_TICK, "TLM");
        require(tickUpper <= TickMath.MAX_TICK, "TUM");
    }

    /// @dev Get imbalanced token
    /// @param amount0Desired The desired amount of token0
    /// @param amount1Desired The desired amount of token1
    /// @param amount0 Amounts of token0 that can be stored in base range
    /// @param amount1 Amounts of token1 that can be stored in base range
    /// @return zeroGreaterOne true if token0 is imbalanced. False if token1 is imbalanced
    function amountsDirection(
        uint256 amount0Desired,
        uint256 amount1Desired,
        uint256 amount0,
        uint256 amount1
    ) internal pure returns (bool zeroGreaterOne) {
        zeroGreaterOne = amount0Desired.sub(amount0).mul(amount1Desired) >
            amount1Desired.sub(amount1).mul(amount0Desired)
            ? true
            : false;
    }
}

File 12 of 36 : UniswapPoolActions.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import "./SafeCastExtended.sol";
import "./UniswapLiquidityManagement.sol";

import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
import "@uniswap/v3-core/contracts/libraries/FullMath.sol";
import "@uniswap/v3-core/contracts/libraries/LowGasSafeMath.sol";

/// @title Liquidity and ticks functions
/// @notice Provides functions for computing liquidity and ticks for token amounts and prices
library UniswapPoolActions {
    using LowGasSafeMath for uint256;
    using SafeCastExtended for uint256;
    using UniswapLiquidityManagement for IUniswapV3Pool;

    function updatePosition(
        IUniswapV3Pool pool,
        int24 tickLower,
        int24 tickUpper
    ) internal returns (uint128 liquidity) {
        (liquidity, , ) = pool.getPositionLiquidity(tickLower, tickUpper);

        if (liquidity > 0) {
            pool.burn(tickLower, tickUpper, 0);
        }
    }

    function burnLiquidity(
        IUniswapV3Pool pool,
        int24 tickLower,
        int24 tickUpper,
        address recipient
    )
        internal
        returns (
            uint256 amount0,
            uint256 amount1,
            uint256 fees0,
            uint256 fees1
        )
    {
        (uint128 liquidity, , ) = pool.getPositionLiquidity(
            tickLower,
            tickUpper
        );
        if (liquidity > 0) {
            (amount0, amount1) = pool.burn(tickLower, tickUpper, liquidity);
            if (amount0 > 0 || amount1 > 0) {
                (uint256 collect0, uint256 collect1) = pool.collect(
                    recipient,
                    tickLower,
                    tickUpper,
                    type(uint128).max,
                    type(uint128).max
                );

                (fees0, fees1) = (collect0.sub(amount0), collect1.sub(amount1));
            }
        }
    }

    function burnUserLiquidity(
        IUniswapV3Pool pool,
        int24 tickLower,
        int24 tickUpper,
        uint256 userSharePercentage,
        address recipient
    ) internal returns (uint256 amount0, uint256 amount1) {
        (uint128 liquidity, , ) = pool.getPositionLiquidity(
            tickLower,
            tickUpper
        );

        uint256 liquidityRemoved = FullMath.mulDiv(
            uint256(liquidity),
            userSharePercentage,
            1e18
        );

        (amount0, amount1) = pool.burn(
            tickLower,
            tickUpper,
            liquidityRemoved.toUint128()
        );

        if (amount0 > 0 || amount1 > 0) {
            (amount0, amount0) = pool.collect(
                recipient,
                tickLower,
                tickUpper,
                amount0.toUint128(),
                amount1.toUint128()
            );
        }
    }

    function mintLiquidity(
        IUniswapV3Pool pool,
        int24 tickLower,
        int24 tickUpper,
        uint256 amount0Desired,
        uint256 amount1Desired
    ) internal returns (uint256 amount0, uint256 amount1) {
        uint128 liquidity = pool.getLiquidityForAmounts(
            amount0Desired,
            amount1Desired,
            tickLower,
            tickUpper
        );

        if (liquidity > 0) {
            (amount0, amount1) = pool.mint(
                address(this),
                tickLower,
                tickUpper,
                liquidity,
                abi.encode(address(this))
            );
        }
    }

    function swapToken(
        IUniswapV3Pool pool,
        address recipient,
        bool zeroForOne,
        int256 amountSpecified
    ) internal {
        (uint160 sqrtPriceX96, , ) = pool.getSqrtRatioX96AndTick();

        uint160 exactSqrtPriceImpact = (sqrtPriceX96 * (1e5 / 2)) / 1e6;

        uint160 sqrtPriceLimitX96 = zeroForOne
            ? sqrtPriceX96 - exactSqrtPriceImpact
            : sqrtPriceX96 + exactSqrtPriceImpact;

        pool.swap(
            recipient,
            zeroForOne,
            amountSpecified,
            sqrtPriceLimitX96,
            abi.encode(zeroForOne)
        );
    }

    function collectPendingFees(
        IUniswapV3Pool pool,
        address recipient,
        int24 tickLower,
        int24 tickUpper
    ) internal returns (uint256 collect0, uint256 collect1) {
        updatePosition(pool, tickLower, tickUpper);

        (collect0, collect1) = pool.collect(
            recipient,
            tickLower,
            tickUpper,
            type(uint128).max,
            type(uint128).max
        );
    }

    function rerangeLiquidity(
        IUniswapV3Pool pool,
        int24 baseThreshold,
        int24 tickSpacing,
        uint256 balance0,
        uint256 balance1
    ) internal returns (int24 tickLower, int24 tickUpper) {
        (tickLower, tickUpper) = pool.getPositionTicks(
            balance0,
            balance1,
            baseThreshold,
            tickSpacing
        );

        mintLiquidity(pool, tickLower, tickUpper, balance0, balance1);
    }
}

File 13 of 36 : ERC20Permit.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.5 <0.8.0;

import "../token/ERC20/ERC20.sol";
import "./IERC20Permit.sol";
import "../cryptography/ECDSA.sol";
import "../utils/Counters.sol";
import "./EIP712.sol";

/**
 * @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * _Available since v3.4._
 */
abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 {
    using Counters for Counters.Counter;

    mapping (address => Counters.Counter) private _nonces;

    // solhint-disable-next-line var-name-mixedcase
    bytes32 private immutable _PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");

    /**
     * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`.
     *
     * It's a good idea to use the same `name` that is defined as the ERC20 token name.
     */
    constructor(string memory name) EIP712(name, "1") {
    }

    /**
     * @dev See {IERC20Permit-permit}.
     */
    function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public virtual override {
        // solhint-disable-next-line not-rely-on-time
        require(block.timestamp <= deadline, "ERC20Permit: expired deadline");

        bytes32 structHash = keccak256(
            abi.encode(
                _PERMIT_TYPEHASH,
                owner,
                spender,
                value,
                _nonces[owner].current(),
                deadline
            )
        );

        bytes32 hash = _hashTypedDataV4(structHash);

        address signer = ECDSA.recover(hash, v, r, s);
        require(signer == owner, "ERC20Permit: invalid signature");

        _nonces[owner].increment();
        _approve(owner, spender, value);
    }

    /**
     * @dev See {IERC20Permit-nonces}.
     */
    function nonces(address owner) public view override returns (uint256) {
        return _nonces[owner].current();
    }

    /**
     * @dev See {IERC20Permit-DOMAIN_SEPARATOR}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view override returns (bytes32) {
        return _domainSeparatorV4();
    }
}

File 14 of 36 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.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 15 of 36 : TickMath.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Math library for computing sqrt prices from ticks and vice versa
/// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports
/// prices between 2**-128 and 2**128
library TickMath {
    /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128
    int24 internal constant MIN_TICK = -887272;
    /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128
    int24 internal constant MAX_TICK = -MIN_TICK;

    /// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK)
    uint160 internal constant MIN_SQRT_RATIO = 4295128739;
    /// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK)
    uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342;

    /// @notice Calculates sqrt(1.0001^tick) * 2^96
    /// @dev Throws if |tick| > max tick
    /// @param tick The input tick for the above formula
    /// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0)
    /// at the given tick
    function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) {
        uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick));
        require(absTick <= uint256(MAX_TICK), 'T');

        uint256 ratio = absTick & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : 0x100000000000000000000000000000000;
        if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128;
        if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128;
        if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128;
        if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128;
        if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128;
        if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128;
        if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128;
        if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128;
        if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128;
        if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128;
        if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128;
        if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128;
        if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128;
        if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128;
        if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128;
        if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128;
        if (absTick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128;
        if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128;
        if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128;

        if (tick > 0) ratio = type(uint256).max / ratio;

        // this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96.
        // we then downcast because we know the result always fits within 160 bits due to our tick input constraint
        // we round up in the division so getTickAtSqrtRatio of the output price is always consistent
        sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1));
    }

    /// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio
    /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may
    /// ever return.
    /// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96
    /// @return tick The greatest tick for which the ratio is less than or equal to the input ratio
    function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) {
        // second inequality must be < because the price can never reach the price at the max tick
        require(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO, 'R');
        uint256 ratio = uint256(sqrtPriceX96) << 32;

        uint256 r = ratio;
        uint256 msb = 0;

        assembly {
            let f := shl(7, gt(r, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
            msb := or(msb, f)
            r := shr(f, r)
        }
        assembly {
            let f := shl(6, gt(r, 0xFFFFFFFFFFFFFFFF))
            msb := or(msb, f)
            r := shr(f, r)
        }
        assembly {
            let f := shl(5, gt(r, 0xFFFFFFFF))
            msb := or(msb, f)
            r := shr(f, r)
        }
        assembly {
            let f := shl(4, gt(r, 0xFFFF))
            msb := or(msb, f)
            r := shr(f, r)
        }
        assembly {
            let f := shl(3, gt(r, 0xFF))
            msb := or(msb, f)
            r := shr(f, r)
        }
        assembly {
            let f := shl(2, gt(r, 0xF))
            msb := or(msb, f)
            r := shr(f, r)
        }
        assembly {
            let f := shl(1, gt(r, 0x3))
            msb := or(msb, f)
            r := shr(f, r)
        }
        assembly {
            let f := gt(r, 0x1)
            msb := or(msb, f)
        }

        if (msb >= 128) r = ratio >> (msb - 127);
        else r = ratio << (127 - msb);

        int256 log_2 = (int256(msb) - 128) << 64;

        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(63, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(62, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(61, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(60, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(59, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(58, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(57, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(56, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(55, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(54, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(53, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(52, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(51, f))
            r := shr(f, r)
        }
        assembly {
            r := shr(127, mul(r, r))
            let f := shr(128, r)
            log_2 := or(log_2, shl(50, f))
        }

        int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number

        int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128);
        int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128);

        tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow;
    }
}

File 16 of 36 : SqrtPriceMath.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity >=0.5.0;

import './LowGasSafeMath.sol';
import './SafeCast.sol';

import './FullMath.sol';
import './UnsafeMath.sol';
import './FixedPoint96.sol';

/// @title Functions based on Q64.96 sqrt price and liquidity
/// @notice Contains the math that uses square root of price as a Q64.96 and liquidity to compute deltas
library SqrtPriceMath {
    using LowGasSafeMath for uint256;
    using SafeCast for uint256;

    /// @notice Gets the next sqrt price given a delta of token0
    /// @dev Always rounds up, because in the exact output case (increasing price) we need to move the price at least
    /// far enough to get the desired output amount, and in the exact input case (decreasing price) we need to move the
    /// price less in order to not send too much output.
    /// The most precise formula for this is liquidity * sqrtPX96 / (liquidity +- amount * sqrtPX96),
    /// if this is impossible because of overflow, we calculate liquidity / (liquidity / sqrtPX96 +- amount).
    /// @param sqrtPX96 The starting price, i.e. before accounting for the token0 delta
    /// @param liquidity The amount of usable liquidity
    /// @param amount How much of token0 to add or remove from virtual reserves
    /// @param add Whether to add or remove the amount of token0
    /// @return The price after adding or removing amount, depending on add
    function getNextSqrtPriceFromAmount0RoundingUp(
        uint160 sqrtPX96,
        uint128 liquidity,
        uint256 amount,
        bool add
    ) internal pure returns (uint160) {
        // we short circuit amount == 0 because the result is otherwise not guaranteed to equal the input price
        if (amount == 0) return sqrtPX96;
        uint256 numerator1 = uint256(liquidity) << FixedPoint96.RESOLUTION;

        if (add) {
            uint256 product;
            if ((product = amount * sqrtPX96) / amount == sqrtPX96) {
                uint256 denominator = numerator1 + product;
                if (denominator >= numerator1)
                    // always fits in 160 bits
                    return uint160(FullMath.mulDivRoundingUp(numerator1, sqrtPX96, denominator));
            }

            return uint160(UnsafeMath.divRoundingUp(numerator1, (numerator1 / sqrtPX96).add(amount)));
        } else {
            uint256 product;
            // if the product overflows, we know the denominator underflows
            // in addition, we must check that the denominator does not underflow
            require((product = amount * sqrtPX96) / amount == sqrtPX96 && numerator1 > product);
            uint256 denominator = numerator1 - product;
            return FullMath.mulDivRoundingUp(numerator1, sqrtPX96, denominator).toUint160();
        }
    }

    /// @notice Gets the next sqrt price given a delta of token1
    /// @dev Always rounds down, because in the exact output case (decreasing price) we need to move the price at least
    /// far enough to get the desired output amount, and in the exact input case (increasing price) we need to move the
    /// price less in order to not send too much output.
    /// The formula we compute is within <1 wei of the lossless version: sqrtPX96 +- amount / liquidity
    /// @param sqrtPX96 The starting price, i.e., before accounting for the token1 delta
    /// @param liquidity The amount of usable liquidity
    /// @param amount How much of token1 to add, or remove, from virtual reserves
    /// @param add Whether to add, or remove, the amount of token1
    /// @return The price after adding or removing `amount`
    function getNextSqrtPriceFromAmount1RoundingDown(
        uint160 sqrtPX96,
        uint128 liquidity,
        uint256 amount,
        bool add
    ) internal pure returns (uint160) {
        // if we're adding (subtracting), rounding down requires rounding the quotient down (up)
        // in both cases, avoid a mulDiv for most inputs
        if (add) {
            uint256 quotient =
                (
                    amount <= type(uint160).max
                        ? (amount << FixedPoint96.RESOLUTION) / liquidity
                        : FullMath.mulDiv(amount, FixedPoint96.Q96, liquidity)
                );

            return uint256(sqrtPX96).add(quotient).toUint160();
        } else {
            uint256 quotient =
                (
                    amount <= type(uint160).max
                        ? UnsafeMath.divRoundingUp(amount << FixedPoint96.RESOLUTION, liquidity)
                        : FullMath.mulDivRoundingUp(amount, FixedPoint96.Q96, liquidity)
                );

            require(sqrtPX96 > quotient);
            // always fits 160 bits
            return uint160(sqrtPX96 - quotient);
        }
    }

    /// @notice Gets the next sqrt price given an input amount of token0 or token1
    /// @dev Throws if price or liquidity are 0, or if the next price is out of bounds
    /// @param sqrtPX96 The starting price, i.e., before accounting for the input amount
    /// @param liquidity The amount of usable liquidity
    /// @param amountIn How much of token0, or token1, is being swapped in
    /// @param zeroForOne Whether the amount in is token0 or token1
    /// @return sqrtQX96 The price after adding the input amount to token0 or token1
    function getNextSqrtPriceFromInput(
        uint160 sqrtPX96,
        uint128 liquidity,
        uint256 amountIn,
        bool zeroForOne
    ) internal pure returns (uint160 sqrtQX96) {
        require(sqrtPX96 > 0);
        require(liquidity > 0);

        // round to make sure that we don't pass the target price
        return
            zeroForOne
                ? getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amountIn, true)
                : getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amountIn, true);
    }

    /// @notice Gets the next sqrt price given an output amount of token0 or token1
    /// @dev Throws if price or liquidity are 0 or the next price is out of bounds
    /// @param sqrtPX96 The starting price before accounting for the output amount
    /// @param liquidity The amount of usable liquidity
    /// @param amountOut How much of token0, or token1, is being swapped out
    /// @param zeroForOne Whether the amount out is token0 or token1
    /// @return sqrtQX96 The price after removing the output amount of token0 or token1
    function getNextSqrtPriceFromOutput(
        uint160 sqrtPX96,
        uint128 liquidity,
        uint256 amountOut,
        bool zeroForOne
    ) internal pure returns (uint160 sqrtQX96) {
        require(sqrtPX96 > 0);
        require(liquidity > 0);

        // round to make sure that we pass the target price
        return
            zeroForOne
                ? getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amountOut, false)
                : getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amountOut, false);
    }

    /// @notice Gets the amount0 delta between two prices
    /// @dev Calculates liquidity / sqrt(lower) - liquidity / sqrt(upper),
    /// i.e. liquidity * (sqrt(upper) - sqrt(lower)) / (sqrt(upper) * sqrt(lower))
    /// @param sqrtRatioAX96 A sqrt price
    /// @param sqrtRatioBX96 Another sqrt price
    /// @param liquidity The amount of usable liquidity
    /// @param roundUp Whether to round the amount up or down
    /// @return amount0 Amount of token0 required to cover a position of size liquidity between the two passed prices
    function getAmount0Delta(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint128 liquidity,
        bool roundUp
    ) internal pure returns (uint256 amount0) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

        uint256 numerator1 = uint256(liquidity) << FixedPoint96.RESOLUTION;
        uint256 numerator2 = sqrtRatioBX96 - sqrtRatioAX96;

        require(sqrtRatioAX96 > 0);

        return
            roundUp
                ? UnsafeMath.divRoundingUp(
                    FullMath.mulDivRoundingUp(numerator1, numerator2, sqrtRatioBX96),
                    sqrtRatioAX96
                )
                : FullMath.mulDiv(numerator1, numerator2, sqrtRatioBX96) / sqrtRatioAX96;
    }

    /// @notice Gets the amount1 delta between two prices
    /// @dev Calculates liquidity * (sqrt(upper) - sqrt(lower))
    /// @param sqrtRatioAX96 A sqrt price
    /// @param sqrtRatioBX96 Another sqrt price
    /// @param liquidity The amount of usable liquidity
    /// @param roundUp Whether to round the amount up, or down
    /// @return amount1 Amount of token1 required to cover a position of size liquidity between the two passed prices
    function getAmount1Delta(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint128 liquidity,
        bool roundUp
    ) internal pure returns (uint256 amount1) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

        return
            roundUp
                ? FullMath.mulDivRoundingUp(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96)
                : FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96);
    }

    /// @notice Helper that gets signed token0 delta
    /// @param sqrtRatioAX96 A sqrt price
    /// @param sqrtRatioBX96 Another sqrt price
    /// @param liquidity The change in liquidity for which to compute the amount0 delta
    /// @return amount0 Amount of token0 corresponding to the passed liquidityDelta between the two prices
    function getAmount0Delta(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        int128 liquidity
    ) internal pure returns (int256 amount0) {
        return
            liquidity < 0
                ? -getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(-liquidity), false).toInt256()
                : getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(liquidity), true).toInt256();
    }

    /// @notice Helper that gets signed token1 delta
    /// @param sqrtRatioAX96 A sqrt price
    /// @param sqrtRatioBX96 Another sqrt price
    /// @param liquidity The change in liquidity for which to compute the amount1 delta
    /// @return amount1 Amount of token1 corresponding to the passed liquidityDelta between the two prices
    function getAmount1Delta(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        int128 liquidity
    ) internal pure returns (int256 amount1) {
        return
            liquidity < 0
                ? -getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(-liquidity), false).toInt256()
                : getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(liquidity), true).toInt256();
    }
}

File 17 of 36 : PositionKey.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

library PositionKey {
    /// @dev Returns the key of the position in the core library
    function compute(
        address owner,
        int24 tickLower,
        int24 tickUpper
    ) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked(owner, tickLower, tickUpper));
    }
}

File 18 of 36 : LiquidityAmounts.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import '@uniswap/v3-core/contracts/libraries/FullMath.sol';
import '@uniswap/v3-core/contracts/libraries/FixedPoint96.sol';

/// @title Liquidity amount functions
/// @notice Provides functions for computing liquidity amounts from token amounts and prices
library LiquidityAmounts {
    /// @notice Downcasts uint256 to uint128
    /// @param x The uint258 to be downcasted
    /// @return y The passed value, downcasted to uint128
    function toUint128(uint256 x) private pure returns (uint128 y) {
        require((y = uint128(x)) == x);
    }

    /// @notice Computes the amount of liquidity received for a given amount of token0 and price range
    /// @dev Calculates amount0 * (sqrt(upper) * sqrt(lower)) / (sqrt(upper) - sqrt(lower))
    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
    /// @param amount0 The amount0 being sent in
    /// @return liquidity The amount of returned liquidity
    function getLiquidityForAmount0(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint256 amount0
    ) internal pure returns (uint128 liquidity) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
        uint256 intermediate = FullMath.mulDiv(sqrtRatioAX96, sqrtRatioBX96, FixedPoint96.Q96);
        return toUint128(FullMath.mulDiv(amount0, intermediate, sqrtRatioBX96 - sqrtRatioAX96));
    }

    /// @notice Computes the amount of liquidity received for a given amount of token1 and price range
    /// @dev Calculates amount1 / (sqrt(upper) - sqrt(lower)).
    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
    /// @param amount1 The amount1 being sent in
    /// @return liquidity The amount of returned liquidity
    function getLiquidityForAmount1(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint256 amount1
    ) internal pure returns (uint128 liquidity) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
        return toUint128(FullMath.mulDiv(amount1, FixedPoint96.Q96, sqrtRatioBX96 - sqrtRatioAX96));
    }

    /// @notice Computes the maximum amount of liquidity received for a given amount of token0, token1, the current
    /// pool prices and the prices at the tick boundaries
    /// @param sqrtRatioX96 A sqrt price representing the current pool prices
    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
    /// @param amount0 The amount of token0 being sent in
    /// @param amount1 The amount of token1 being sent in
    /// @return liquidity The maximum amount of liquidity received
    function getLiquidityForAmounts(
        uint160 sqrtRatioX96,
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint256 amount0,
        uint256 amount1
    ) internal pure returns (uint128 liquidity) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

        if (sqrtRatioX96 <= sqrtRatioAX96) {
            liquidity = getLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, amount0);
        } else if (sqrtRatioX96 < sqrtRatioBX96) {
            uint128 liquidity0 = getLiquidityForAmount0(sqrtRatioX96, sqrtRatioBX96, amount0);
            uint128 liquidity1 = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioX96, amount1);

            liquidity = liquidity0 < liquidity1 ? liquidity0 : liquidity1;
        } else {
            liquidity = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1);
        }
    }

    /// @notice Computes the amount of token0 for a given amount of liquidity and a price range
    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
    /// @param liquidity The liquidity being valued
    /// @return amount0 The amount of token0
    function getAmount0ForLiquidity(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint128 liquidity
    ) internal pure returns (uint256 amount0) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

        return
            FullMath.mulDiv(
                uint256(liquidity) << FixedPoint96.RESOLUTION,
                sqrtRatioBX96 - sqrtRatioAX96,
                sqrtRatioBX96
            ) / sqrtRatioAX96;
    }

    /// @notice Computes the amount of token1 for a given amount of liquidity and a price range
    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
    /// @param liquidity The liquidity being valued
    /// @return amount1 The amount of token1
    function getAmount1ForLiquidity(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint128 liquidity
    ) internal pure returns (uint256 amount1) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

        return FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96);
    }

    /// @notice Computes the token0 and token1 value for a given amount of liquidity, the current
    /// pool prices and the prices at the tick boundaries
    /// @param sqrtRatioX96 A sqrt price representing the current pool prices
    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
    /// @param liquidity The liquidity being valued
    /// @return amount0 The amount of token0
    /// @return amount1 The amount of token1
    function getAmountsForLiquidity(
        uint160 sqrtRatioX96,
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint128 liquidity
    ) internal pure returns (uint256 amount0, uint256 amount1) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

        if (sqrtRatioX96 <= sqrtRatioAX96) {
            amount0 = getAmount0ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity);
        } else if (sqrtRatioX96 < sqrtRatioBX96) {
            amount0 = getAmount0ForLiquidity(sqrtRatioX96, sqrtRatioBX96, liquidity);
            amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioX96, liquidity);
        } else {
            amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity);
        }
    }
}

File 19 of 36 : SafeCastExtended.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

/**
 * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 *
 * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
 * all math on `uint256` and `int256` and then downcasting.
 */
library SafeCastExtended {
    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        require(value < 2**128, "SafeCast: value doesn't fit in 128 bits");
        return uint128(value);
    }

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

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

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

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

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

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

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

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

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

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

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

File 20 of 36 : FullMath.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.0;

/// @title Contains 512-bit math functions
/// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision
/// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits
library FullMath {
    /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
    /// @param a The multiplicand
    /// @param b The multiplier
    /// @param denominator The divisor
    /// @return result The 256-bit result
    /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv
    function mulDiv(
        uint256 a,
        uint256 b,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        // 512-bit multiply [prod1 prod0] = a * b
        // Compute the product mod 2**256 and mod 2**256 - 1
        // then use the Chinese Remainder Theorem to reconstruct
        // the 512 bit result. The result is stored in two 256
        // variables such that product = prod1 * 2**256 + prod0
        uint256 prod0; // Least significant 256 bits of the product
        uint256 prod1; // Most significant 256 bits of the product
        assembly {
            let mm := mulmod(a, b, not(0))
            prod0 := mul(a, b)
            prod1 := sub(sub(mm, prod0), lt(mm, prod0))
        }

        // Handle non-overflow cases, 256 by 256 division
        if (prod1 == 0) {
            require(denominator > 0);
            assembly {
                result := div(prod0, denominator)
            }
            return result;
        }

        // Make sure the result is less than 2**256.
        // Also prevents denominator == 0
        require(denominator > prod1);

        ///////////////////////////////////////////////
        // 512 by 256 division.
        ///////////////////////////////////////////////

        // Make division exact by subtracting the remainder from [prod1 prod0]
        // Compute remainder using mulmod
        uint256 remainder;
        assembly {
            remainder := mulmod(a, b, denominator)
        }
        // Subtract 256 bit number from 512 bit number
        assembly {
            prod1 := sub(prod1, gt(remainder, prod0))
            prod0 := sub(prod0, remainder)
        }

        // Factor powers of two out of denominator
        // Compute largest power of two divisor of denominator.
        // Always >= 1.
        uint256 twos = -denominator & denominator;
        // Divide denominator by power of two
        assembly {
            denominator := div(denominator, twos)
        }

        // Divide [prod1 prod0] by the factors of two
        assembly {
            prod0 := div(prod0, twos)
        }
        // Shift in bits from prod1 into prod0. For this we need
        // to flip `twos` such that it is 2**256 / twos.
        // If twos is zero, then it becomes one
        assembly {
            twos := add(div(sub(0, twos), twos), 1)
        }
        prod0 |= prod1 * twos;

        // Invert denominator mod 2**256
        // Now that denominator is an odd number, it has an inverse
        // modulo 2**256 such that denominator * inv = 1 mod 2**256.
        // Compute the inverse by starting with a seed that is correct
        // correct for four bits. That is, denominator * inv = 1 mod 2**4
        uint256 inv = (3 * denominator) ^ 2;
        // Now use Newton-Raphson iteration to improve the precision.
        // Thanks to Hensel's lifting lemma, this also works in modular
        // arithmetic, doubling the correct bits in each step.
        inv *= 2 - denominator * inv; // inverse mod 2**8
        inv *= 2 - denominator * inv; // inverse mod 2**16
        inv *= 2 - denominator * inv; // inverse mod 2**32
        inv *= 2 - denominator * inv; // inverse mod 2**64
        inv *= 2 - denominator * inv; // inverse mod 2**128
        inv *= 2 - denominator * inv; // inverse mod 2**256

        // Because the division is now exact we can divide by multiplying
        // with the modular inverse of denominator. This will give us the
        // correct result modulo 2**256. Since the precoditions guarantee
        // that the outcome is less than 2**256, this is the final result.
        // We don't need to compute the high bits of the result and prod1
        // is no longer required.
        result = prod0 * inv;
        return result;
    }

    /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
    /// @param a The multiplicand
    /// @param b The multiplier
    /// @param denominator The divisor
    /// @return result The 256-bit result
    function mulDivRoundingUp(
        uint256 a,
        uint256 b,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        result = mulDiv(a, b, denominator);
        if (mulmod(a, b, denominator) > 0) {
            require(result < type(uint256).max);
            result++;
        }
    }
}

File 21 of 36 : LowGasSafeMath.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.0;

/// @title Optimized overflow and underflow safe math operations
/// @notice Contains methods for doing math operations that revert on overflow or underflow for minimal gas cost
library LowGasSafeMath {
    /// @notice Returns x + y, reverts if sum overflows uint256
    /// @param x The augend
    /// @param y The addend
    /// @return z The sum of x and y
    function add(uint256 x, uint256 y) internal pure returns (uint256 z) {
        require((z = x + y) >= x);
    }

    /// @notice Returns x - y, reverts if underflows
    /// @param x The minuend
    /// @param y The subtrahend
    /// @return z The difference of x and y
    function sub(uint256 x, uint256 y) internal pure returns (uint256 z) {
        require((z = x - y) <= x);
    }

    /// @notice Returns x * y, reverts if overflows
    /// @param x The multiplicand
    /// @param y The multiplier
    /// @return z The product of x and y
    function mul(uint256 x, uint256 y) internal pure returns (uint256 z) {
        require(x == 0 || (z = x * y) / x == y);
    }

    /// @notice Returns x + y, reverts if overflows or underflows
    /// @param x The augend
    /// @param y The addend
    /// @return z The sum of x and y
    function add(int256 x, int256 y) internal pure returns (int256 z) {
        require((z = x + y) >= x == (y >= 0));
    }

    /// @notice Returns x - y, reverts if overflows or underflows
    /// @param x The minuend
    /// @param y The subtrahend
    /// @return z The difference of x and y
    function sub(int256 x, int256 y) internal pure returns (int256 z) {
        require((z = x - y) <= x == (y >= 0));
    }
}

File 22 of 36 : SafeCast.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Safe casting methods
/// @notice Contains methods for safely casting between types
library SafeCast {
    /// @notice Cast a uint256 to a uint160, revert on overflow
    /// @param y The uint256 to be downcasted
    /// @return z The downcasted integer, now type uint160
    function toUint160(uint256 y) internal pure returns (uint160 z) {
        require((z = uint160(y)) == y);
    }

    /// @notice Cast a int256 to a int128, revert on overflow or underflow
    /// @param y The int256 to be downcasted
    /// @return z The downcasted integer, now type int128
    function toInt128(int256 y) internal pure returns (int128 z) {
        require((z = int128(y)) == y);
    }

    /// @notice Cast a uint256 to a int256, revert on overflow
    /// @param y The uint256 to be casted
    /// @return z The casted integer, now type int256
    function toInt256(uint256 y) internal pure returns (int256 z) {
        require(y < 2**255);
        z = int256(y);
    }
}

File 23 of 36 : UnsafeMath.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Math functions that do not check inputs or outputs
/// @notice Contains methods that perform common math functions but do not do any overflow or underflow checks
library UnsafeMath {
    /// @notice Returns ceil(x / y)
    /// @dev division by 0 has unspecified behavior, and must be checked externally
    /// @param x The dividend
    /// @param y The divisor
    /// @return z The quotient, ceil(x / y)
    function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
        assembly {
            z := add(div(x, y), gt(mod(x, y), 0))
        }
    }
}

File 24 of 36 : FixedPoint96.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.4.0;

/// @title FixedPoint96
/// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format)
/// @dev Used in SqrtPriceMath.sol
library FixedPoint96 {
    uint8 internal constant RESOLUTION = 96;
    uint256 internal constant Q96 = 0x1000000000000000000000000;
}

File 25 of 36 : IUniswapV3PoolImmutables.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that never changes
/// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values
interface IUniswapV3PoolImmutables {
    /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface
    /// @return The contract address
    function factory() external view returns (address);

    /// @notice The first of the two tokens of the pool, sorted by address
    /// @return The token contract address
    function token0() external view returns (address);

    /// @notice The second of the two tokens of the pool, sorted by address
    /// @return The token contract address
    function token1() external view returns (address);

    /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6
    /// @return The fee
    function fee() external view returns (uint24);

    /// @notice The pool tick spacing
    /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive
    /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ...
    /// This value is an int24 to avoid casting even though it is always positive.
    /// @return The tick spacing
    function tickSpacing() external view returns (int24);

    /// @notice The maximum amount of position liquidity that can use any tick in the range
    /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and
    /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool
    /// @return The max amount of liquidity per tick
    function maxLiquidityPerTick() external view returns (uint128);
}

File 26 of 36 : IUniswapV3PoolState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that can change
/// @notice These methods compose the pool's state, and can change with any frequency including multiple times
/// per transaction
interface IUniswapV3PoolState {
    /// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas
    /// when accessed externally.
    /// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value
    /// tick The current tick of the pool, i.e. according to the last tick transition that was run.
    /// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick
    /// boundary.
    /// observationIndex The index of the last oracle observation that was written,
    /// observationCardinality The current maximum number of observations stored in the pool,
    /// observationCardinalityNext The next maximum number of observations, to be updated when the observation.
    /// feeProtocol The protocol fee for both tokens of the pool.
    /// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0
    /// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee.
    /// unlocked Whether the pool is currently locked to reentrancy
    function slot0()
        external
        view
        returns (
            uint160 sqrtPriceX96,
            int24 tick,
            uint16 observationIndex,
            uint16 observationCardinality,
            uint16 observationCardinalityNext,
            uint8 feeProtocol,
            bool unlocked
        );

    /// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool
    /// @dev This value can overflow the uint256
    function feeGrowthGlobal0X128() external view returns (uint256);

    /// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool
    /// @dev This value can overflow the uint256
    function feeGrowthGlobal1X128() external view returns (uint256);

    /// @notice The amounts of token0 and token1 that are owed to the protocol
    /// @dev Protocol fees will never exceed uint128 max in either token
    function protocolFees() external view returns (uint128 token0, uint128 token1);

    /// @notice The currently in range liquidity available to the pool
    /// @dev This value has no relationship to the total liquidity across all ticks
    function liquidity() external view returns (uint128);

    /// @notice Look up information about a specific tick in the pool
    /// @param tick The tick to look up
    /// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or
    /// tick upper,
    /// liquidityNet how much liquidity changes when the pool price crosses the tick,
    /// feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0,
    /// feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1,
    /// tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick
    /// secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick,
    /// secondsOutside the seconds spent on the other side of the tick from the current tick,
    /// initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false.
    /// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0.
    /// In addition, these values are only relative and must be used only in comparison to previous snapshots for
    /// a specific position.
    function ticks(int24 tick)
        external
        view
        returns (
            uint128 liquidityGross,
            int128 liquidityNet,
            uint256 feeGrowthOutside0X128,
            uint256 feeGrowthOutside1X128,
            int56 tickCumulativeOutside,
            uint160 secondsPerLiquidityOutsideX128,
            uint32 secondsOutside,
            bool initialized
        );

    /// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information
    function tickBitmap(int16 wordPosition) external view returns (uint256);

    /// @notice Returns the information about a position by the position's key
    /// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper
    /// @return _liquidity The amount of liquidity in the position,
    /// Returns feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke,
    /// Returns feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke,
    /// Returns tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke,
    /// Returns tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke
    function positions(bytes32 key)
        external
        view
        returns (
            uint128 _liquidity,
            uint256 feeGrowthInside0LastX128,
            uint256 feeGrowthInside1LastX128,
            uint128 tokensOwed0,
            uint128 tokensOwed1
        );

    /// @notice Returns data about a specific observation index
    /// @param index The element of the observations array to fetch
    /// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time
    /// ago, rather than at a specific index in the array.
    /// @return blockTimestamp The timestamp of the observation,
    /// Returns tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp,
    /// Returns secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp,
    /// Returns initialized whether the observation has been initialized and the values are safe to use
    function observations(uint256 index)
        external
        view
        returns (
            uint32 blockTimestamp,
            int56 tickCumulative,
            uint160 secondsPerLiquidityCumulativeX128,
            bool initialized
        );
}

File 27 of 36 : IUniswapV3PoolDerivedState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that is not stored
/// @notice Contains view functions to provide information about the pool that is computed rather than stored on the
/// blockchain. The functions here may have variable gas costs.
interface IUniswapV3PoolDerivedState {
    /// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp
    /// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing
    /// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick,
    /// you must call it with secondsAgos = [3600, 0].
    /// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in
    /// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.
    /// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned
    /// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp
    /// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block
    /// timestamp
    function observe(uint32[] calldata secondsAgos)
        external
        view
        returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);

    /// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range
    /// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed.
    /// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first
    /// snapshot is taken and the second snapshot is taken.
    /// @param tickLower The lower tick of the range
    /// @param tickUpper The upper tick of the range
    /// @return tickCumulativeInside The snapshot of the tick accumulator for the range
    /// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range
    /// @return secondsInside The snapshot of seconds per liquidity for the range
    function snapshotCumulativesInside(int24 tickLower, int24 tickUpper)
        external
        view
        returns (
            int56 tickCumulativeInside,
            uint160 secondsPerLiquidityInsideX128,
            uint32 secondsInside
        );
}

File 28 of 36 : IUniswapV3PoolActions.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Permissionless pool actions
/// @notice Contains pool methods that can be called by anyone
interface IUniswapV3PoolActions {
    /// @notice Sets the initial price for the pool
    /// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
    /// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96
    function initialize(uint160 sqrtPriceX96) external;

    /// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
    /// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback
    /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
    /// on tickLower, tickUpper, the amount of liquidity, and the current price.
    /// @param recipient The address for which the liquidity will be created
    /// @param tickLower The lower tick of the position in which to add liquidity
    /// @param tickUpper The upper tick of the position in which to add liquidity
    /// @param amount The amount of liquidity to mint
    /// @param data Any data that should be passed through to the callback
    /// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
    /// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
    function mint(
        address recipient,
        int24 tickLower,
        int24 tickUpper,
        uint128 amount,
        bytes calldata data
    ) external returns (uint256 amount0, uint256 amount1);

    /// @notice Collects tokens owed to a position
    /// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
    /// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
    /// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
    /// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
    /// @param recipient The address which should receive the fees collected
    /// @param tickLower The lower tick of the position for which to collect fees
    /// @param tickUpper The upper tick of the position for which to collect fees
    /// @param amount0Requested How much token0 should be withdrawn from the fees owed
    /// @param amount1Requested How much token1 should be withdrawn from the fees owed
    /// @return amount0 The amount of fees collected in token0
    /// @return amount1 The amount of fees collected in token1
    function collect(
        address recipient,
        int24 tickLower,
        int24 tickUpper,
        uint128 amount0Requested,
        uint128 amount1Requested
    ) external returns (uint128 amount0, uint128 amount1);

    /// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
    /// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
    /// @dev Fees must be collected separately via a call to #collect
    /// @param tickLower The lower tick of the position for which to burn liquidity
    /// @param tickUpper The upper tick of the position for which to burn liquidity
    /// @param amount How much liquidity to burn
    /// @return amount0 The amount of token0 sent to the recipient
    /// @return amount1 The amount of token1 sent to the recipient
    function burn(
        int24 tickLower,
        int24 tickUpper,
        uint128 amount
    ) external returns (uint256 amount0, uint256 amount1);

    /// @notice Swap token0 for token1, or token1 for token0
    /// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
    /// @param recipient The address to receive the output of the swap
    /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
    /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
    /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
    /// value after the swap. If one for zero, the price cannot be greater than this value after the swap
    /// @param data Any data to be passed through to the callback
    /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
    /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
    function swap(
        address recipient,
        bool zeroForOne,
        int256 amountSpecified,
        uint160 sqrtPriceLimitX96,
        bytes calldata data
    ) external returns (int256 amount0, int256 amount1);

    /// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
    /// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback
    /// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
    /// with 0 amount{0,1} and sending the donation amount(s) from the callback
    /// @param recipient The address which will receive the token0 and token1 amounts
    /// @param amount0 The amount of token0 to send
    /// @param amount1 The amount of token1 to send
    /// @param data Any data to be passed through to the callback
    function flash(
        address recipient,
        uint256 amount0,
        uint256 amount1,
        bytes calldata data
    ) external;

    /// @notice Increase the maximum number of price and liquidity observations that this pool will store
    /// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
    /// the input observationCardinalityNext.
    /// @param observationCardinalityNext The desired minimum number of observations for the pool to store
    function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
}

File 29 of 36 : IUniswapV3PoolOwnerActions.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Permissioned pool actions
/// @notice Contains pool methods that may only be called by the factory owner
interface IUniswapV3PoolOwnerActions {
    /// @notice Set the denominator of the protocol's % share of the fees
    /// @param feeProtocol0 new protocol fee for token0 of the pool
    /// @param feeProtocol1 new protocol fee for token1 of the pool
    function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external;

    /// @notice Collect the protocol fee accrued to the pool
    /// @param recipient The address to which collected protocol fees should be sent
    /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1
    /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0
    /// @return amount0 The protocol fee collected in token0
    /// @return amount1 The protocol fee collected in token1
    function collectProtocol(
        address recipient,
        uint128 amount0Requested,
        uint128 amount1Requested
    ) external returns (uint128 amount0, uint128 amount1);
}

File 30 of 36 : IUniswapV3PoolEvents.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Events emitted by a pool
/// @notice Contains all events emitted by the pool
interface IUniswapV3PoolEvents {
    /// @notice Emitted exactly once by a pool when #initialize is first called on the pool
    /// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize
    /// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96
    /// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool
    event Initialize(uint160 sqrtPriceX96, int24 tick);

    /// @notice Emitted when liquidity is minted for a given position
    /// @param sender The address that minted the liquidity
    /// @param owner The owner of the position and recipient of any minted liquidity
    /// @param tickLower The lower tick of the position
    /// @param tickUpper The upper tick of the position
    /// @param amount The amount of liquidity minted to the position range
    /// @param amount0 How much token0 was required for the minted liquidity
    /// @param amount1 How much token1 was required for the minted liquidity
    event Mint(
        address sender,
        address indexed owner,
        int24 indexed tickLower,
        int24 indexed tickUpper,
        uint128 amount,
        uint256 amount0,
        uint256 amount1
    );

    /// @notice Emitted when fees are collected by the owner of a position
    /// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees
    /// @param owner The owner of the position for which fees are collected
    /// @param tickLower The lower tick of the position
    /// @param tickUpper The upper tick of the position
    /// @param amount0 The amount of token0 fees collected
    /// @param amount1 The amount of token1 fees collected
    event Collect(
        address indexed owner,
        address recipient,
        int24 indexed tickLower,
        int24 indexed tickUpper,
        uint128 amount0,
        uint128 amount1
    );

    /// @notice Emitted when a position's liquidity is removed
    /// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect
    /// @param owner The owner of the position for which liquidity is removed
    /// @param tickLower The lower tick of the position
    /// @param tickUpper The upper tick of the position
    /// @param amount The amount of liquidity to remove
    /// @param amount0 The amount of token0 withdrawn
    /// @param amount1 The amount of token1 withdrawn
    event Burn(
        address indexed owner,
        int24 indexed tickLower,
        int24 indexed tickUpper,
        uint128 amount,
        uint256 amount0,
        uint256 amount1
    );

    /// @notice Emitted by the pool for any swaps between token0 and token1
    /// @param sender The address that initiated the swap call, and that received the callback
    /// @param recipient The address that received the output of the swap
    /// @param amount0 The delta of the token0 balance of the pool
    /// @param amount1 The delta of the token1 balance of the pool
    /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96
    /// @param liquidity The liquidity of the pool after the swap
    /// @param tick The log base 1.0001 of price of the pool after the swap
    event Swap(
        address indexed sender,
        address indexed recipient,
        int256 amount0,
        int256 amount1,
        uint160 sqrtPriceX96,
        uint128 liquidity,
        int24 tick
    );

    /// @notice Emitted by the pool for any flashes of token0/token1
    /// @param sender The address that initiated the swap call, and that received the callback
    /// @param recipient The address that received the tokens from flash
    /// @param amount0 The amount of token0 that was flashed
    /// @param amount1 The amount of token1 that was flashed
    /// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee
    /// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee
    event Flash(
        address indexed sender,
        address indexed recipient,
        uint256 amount0,
        uint256 amount1,
        uint256 paid0,
        uint256 paid1
    );

    /// @notice Emitted by the pool for increases to the number of observations that can be stored
    /// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index
    /// just before a mint/swap/burn.
    /// @param observationCardinalityNextOld The previous value of the next observation cardinality
    /// @param observationCardinalityNextNew The updated value of the next observation cardinality
    event IncreaseObservationCardinalityNext(
        uint16 observationCardinalityNextOld,
        uint16 observationCardinalityNextNew
    );

    /// @notice Emitted when the protocol fee is changed by the pool
    /// @param feeProtocol0Old The previous value of the token0 protocol fee
    /// @param feeProtocol1Old The previous value of the token1 protocol fee
    /// @param feeProtocol0New The updated value of the token0 protocol fee
    /// @param feeProtocol1New The updated value of the token1 protocol fee
    event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New);

    /// @notice Emitted when the collected protocol fees are withdrawn by the factory owner
    /// @param sender The address that collects the protocol fees
    /// @param recipient The address that receives the collected protocol fees
    /// @param amount0 The amount of token0 protocol fees that is withdrawn
    /// @param amount0 The amount of token1 protocol fees that is withdrawn
    event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1);
}

File 31 of 36 : IERC20Permit.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over `owner`'s tokens,
     * given `owner`'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for `permit`, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

File 32 of 36 : ECDSA.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSA {
    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        // Check the signature length
        if (signature.length != 65) {
            revert("ECDSA: invalid signature length");
        }

        // Divide the signature in r, s and v variables
        bytes32 r;
        bytes32 s;
        uint8 v;

        // ecrecover takes the signature parameters, and the only way to get them
        // currently is to use assembly.
        // solhint-disable-next-line no-inline-assembly
        assembly {
            r := mload(add(signature, 0x20))
            s := mload(add(signature, 0x40))
            v := byte(0, mload(add(signature, 0x60)))
        }

        return recover(hash, v, r, s);
    }

    /**
     * @dev Overload of {ECDSA-recover-bytes32-bytes-} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        require(uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, "ECDSA: invalid signature 's' value");
        require(v == 27 || v == 28, "ECDSA: invalid signature 'v' value");

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        require(signer != address(0), "ECDSA: invalid signature");

        return signer;
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from a `hash`. This
     * replicates the behavior of the
     * https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign[`eth_sign`]
     * JSON-RPC method.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
        // 32 is the length in bytes of hash,
        // enforced by the type signature above
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
    }
}

File 33 of 36 : Counters.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

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

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

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

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

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

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

File 34 of 36 : EIP712.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
 *
 * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
 * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
 * they need in their contracts using a combination of `abi.encode` and `keccak256`.
 *
 * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
 * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
 * ({_hashTypedDataV4}).
 *
 * The implementation of the domain separator was designed to be as efficient as possible while still properly updating
 * the chain id to protect against replay attacks on an eventual fork of the chain.
 *
 * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
 * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
 *
 * _Available since v3.4._
 */
abstract contract EIP712 {
    /* solhint-disable var-name-mixedcase */
    // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
    // invalidate the cached domain separator if the chain id changes.
    bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;
    uint256 private immutable _CACHED_CHAIN_ID;

    bytes32 private immutable _HASHED_NAME;
    bytes32 private immutable _HASHED_VERSION;
    bytes32 private immutable _TYPE_HASH;
    /* solhint-enable var-name-mixedcase */

    /**
     * @dev Initializes the domain separator and parameter caches.
     *
     * The meaning of `name` and `version` is specified in
     * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
     *
     * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
     * - `version`: the current major version of the signing domain.
     *
     * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
     * contract upgrade].
     */
    constructor(string memory name, string memory version) {
        bytes32 hashedName = keccak256(bytes(name));
        bytes32 hashedVersion = keccak256(bytes(version));
        bytes32 typeHash = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
        _HASHED_NAME = hashedName;
        _HASHED_VERSION = hashedVersion;
        _CACHED_CHAIN_ID = _getChainId();
        _CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion);
        _TYPE_HASH = typeHash;
    }

    /**
     * @dev Returns the domain separator for the current chain.
     */
    function _domainSeparatorV4() internal view virtual returns (bytes32) {
        if (_getChainId() == _CACHED_CHAIN_ID) {
            return _CACHED_DOMAIN_SEPARATOR;
        } else {
            return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION);
        }
    }

    function _buildDomainSeparator(bytes32 typeHash, bytes32 name, bytes32 version) private view returns (bytes32) {
        return keccak256(
            abi.encode(
                typeHash,
                name,
                version,
                _getChainId(),
                address(this)
            )
        );
    }

    /**
     * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
     * function returns the hash of the fully encoded EIP712 message for this domain.
     *
     * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
     *
     * ```solidity
     * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
     *     keccak256("Mail(address to,string contents)"),
     *     mailTo,
     *     keccak256(bytes(mailContents))
     * )));
     * address signer = ECDSA.recover(digest, signature);
     * ```
     */
    function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x01", _domainSeparatorV4(), structHash));
    }

    function _getChainId() private view returns (uint256 chainId) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        // solhint-disable-next-line no-inline-assembly
        assembly {
            chainId := chainid()
        }
    }
}

File 35 of 36 : Context.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

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

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

pragma solidity ^0.7.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

Settings
{
  "metadata": {
    "bytecodeHash": "none"
  },
  "optimizer": {
    "enabled": true,
    "runs": 10
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_uniswapFactory","type":"address"},{"internalType":"address","name":"_governance","type":"address"},{"internalType":"address","name":"_uniStrategy","type":"address"},{"internalType":"address","name":"_indexFund","type":"address"},{"internalType":"address","name":"_WETH","type":"address"},{"internalType":"uint8","name":"percentage","type":"uint8"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_oldGovernance","type":"address"},{"indexed":true,"internalType":"address","name":"_newGovernance","type":"address"}],"name":"GovernanceChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_tokenA","type":"address"},{"indexed":true,"internalType":"address","name":"_tokenB","type":"address"},{"indexed":false,"internalType":"uint24","name":"_fee","type":"uint24"},{"indexed":true,"internalType":"address","name":"_vault","type":"address"}],"name":"VaultCreated","type":"event"},{"inputs":[{"internalType":"address","name":"_tokenA","type":"address"},{"internalType":"address","name":"_tokenB","type":"address"},{"internalType":"uint24","name":"_fee","type":"uint24"},{"internalType":"uint160","name":"_sqrtPriceX96","type":"uint160"},{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"}],"name":"createVault","outputs":[{"internalType":"address","name":"_vault","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getUnipilotDetails","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint8","name":"","type":"uint8"},{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isWhitelist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_newGovernance","type":"address"}],"name":"setGovernance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_strategy","type":"address"},{"internalType":"address","name":"_indexFund","type":"address"},{"internalType":"uint8","name":"_indexFundPercentage","type":"uint8"}],"name":"setUnipilotDetails","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"toggleWhitelistAccount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint24","name":"","type":"uint24"}],"name":"vaults","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

608060405234801561001057600080fd5b50604051615ed8380380615ed8833981810160405260c081101561003357600080fd5b508051602082015160408301516060840151608085015160a090950151600080546001600160a01b039586166001600160a01b03199182161790915560018054948616948216949094179093556004805495851695841695909517909455600280549184169183169190911790556003805460ff909416600160a81b0260ff60a81b1993909516939091169290921716919091179055615e00806100d86000396000f3fe60806040523480156200001157600080fd5b5060043610620000765760003560e01c8063284c8acd146200007b57806338d7728014620000d65780633f1e478b14620001205780639ba49207146200015f578063ab033ea91462000188578063beb905d414620001b1578063c683630d146200030e575b600080fd5b620000ba600480360360608110156200009357600080fd5b5080356001600160a01b03908116916020810135909116906040013562ffffff166200034b565b604080516001600160a01b039092168252519081900360200190f35b620000e062000377565b604080516001600160a01b0396871681529486166020860152929094168383015260ff908116606084015292909216608082015290519081900360a00190f35b6200015d600480360360608110156200013857600080fd5b5080356001600160a01b03908116916020810135909116906040013560ff16620003ae565b005b6200015d600480360360208110156200017757600080fd5b50356001600160a01b031662000416565b6200015d60048036036020811015620001a057600080fd5b50356001600160a01b031662000457565b620000ba600480360360c0811015620001c957600080fd5b6001600160a01b038235811692602081013582169262ffffff60408301351692606083013516919081019060a081016080820135600160201b8111156200020f57600080fd5b8201836020820111156200022257600080fd5b803590602001918460018302840111600160201b831117156200024457600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295949360208101935035915050600160201b8111156200029757600080fd5b820183602082011115620002aa57600080fd5b803590602001918460018302840111600160201b83111715620002cc57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550620004de945050505050565b62000337600480360360208110156200032657600080fd5b50356001600160a01b031662000a5a565b604080519115158252519081900360200190f35b60066020908152600093845260408085208252928452828420905282529020546001600160a01b031681565b6000546001546002546003546001600160a01b0393841694928416939091169160ff600160a81b8304811692600160a01b90041690565b6000546001600160a01b03163314620003c657600080fd5b600180546001600160a01b039485166001600160a01b03199182161790915560028054939094169216919091179091556003805460ff909216600160a81b0260ff60a81b19909216919091179055565b6000546001600160a01b031633146200042e57600080fd5b6001600160a01b03166000908152600560205260409020805460ff19811660ff90911615179055565b6000546001600160a01b031633146200046f57600080fd5b6001600160a01b0381166200048357600080fd5b600080546040516001600160a01b03808516939216917f3aaaebeb4821d6a7e5c77ece53cff0afcc56c82add2c978dbbb7f73e84cbcfd291a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b600080546001600160a01b03163314620004f757600080fd5b856001600160a01b0316876001600160a01b031614156200051757600080fd5b600080876001600160a01b0316896001600160a01b0316106200053c5787896200053f565b88885b6001600160a01b0380831660009081526006602090815260408083208486168452825280832062ffffff8e16845290915290205492945090925016156200058557600080fd5b6004805460408051630b4c774160e11b81526001600160a01b0386811694820194909452848416602482015262ffffff8b166044820152905160009390921691631698ee8291606480820192602092909190829003018186803b158015620005ec57600080fd5b505afa15801562000601573d6000803e3d6000fd5b505050506040513d60208110156200061857600080fd5b505190506001600160a01b0381166200072957600480546040805163a167129560e01b81526001600160a01b0387811694820194909452858416602482015262ffffff8c1660448201529051929091169163a1671295916064808201926020929091908290030181600087803b1580156200069257600080fd5b505af1158015620006a7573d6000803e3d6000fd5b505050506040513d6020811015620006be57600080fd5b50516040805163f637731d60e01b81526001600160a01b038a8116600483015291519293509083169163f637731d9160248082019260009290919082900301818387803b1580156200070f57600080fd5b505af115801562000724573d6000803e3d6000fd5b505050505b6040805160608c811b6001600160601b0319908116602080850191909152918d901b16603483015260e88b901b6001600160e81b03191660488301528251808303602b018152604b9092019283905281519101206003546000549192849230926001600160a01b03908116929116908b908b90620007a79062000a6f565b80876001600160a01b03168152602001866001600160a01b03168152602001856001600160a01b03168152602001846001600160a01b031681526020018060200180602001838103835285818151815260200191508051906020019080838360005b838110156200082357818101518382015260200162000809565b50505050905090810190601f168015620008515780820380516001836020036101000a031916815260200191505b50838103825284518152845160209182019186019080838360005b83811015620008865781810151838201526020016200086c565b50505050905090810190601f168015620008b45780820380516001836020036101000a031916815260200191505b50985050505050505050508190604051809103906000f5905080158015620008e0573d6000803e3d6000fd5b5093508360066000856001600160a01b03166001600160a01b031681526020019081526020016000206000846001600160a01b03166001600160a01b0316815260200190815260200160002060008a62ffffff1662ffffff16815260200190815260200160002060006101000a8154816001600160a01b0302191690836001600160a01b031602179055508360066000846001600160a01b03166001600160a01b031681526020019081526020016000206000856001600160a01b03166001600160a01b0316815260200190815260200160002060008a62ffffff1662ffffff16815260200190815260200160002060006101000a8154816001600160a01b0302191690836001600160a01b03160217905550836001600160a01b0316826001600160a01b0316846001600160a01b03167faf0c778584d4b20d9768e68ed24ede73b034bc5747a377a69f1db53ff3933def8b604051808262ffffff16815260200191505060405180910390a45050509695505050505050565b60056020526000908152604090205460ff1681565b6153768062000a7e8339019056fe6101406040527f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c961012052600c80546001600160e01b0363ffffffff60c01b1963ffffffff60a01b19909216600160a01b1791909116600160c01b1716600160e01b1790553480156200007157600080fd5b50604051620053763803806200537683398101604081905262000094916200061c565b8180604051806040016040528060018152602001603160f81b81525084848160039080519060200190620000ca92919062000494565b508051620000e090600490602084019062000494565b50506005805460ff1916601217905550815160208084019190912082519183019190912060c082905260e08190527f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f620001396200042c565b60a0526200014981848462000430565b608052610100525050600c80546001600160a01b03808a166001600160a01b031992831617909255600b80548b8416908316179055600a80548c84169216919091179081905560408051630dfe168160e01b81529051919092169450630dfe1681935060048083019350602092829003018186803b158015620001cb57600080fd5b505afa158015620001e0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620002069190620005f8565b600780546001600160a01b0319166001600160a01b03928316179055600a546040805163d21220a760e01b81529051919092169163d21220a7916004808301926020929190829003018186803b1580156200026057600080fd5b505afa15801562000275573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200029b9190620005f8565b600880546001600160a01b0319166001600160a01b03928316179055600a546040805163ddca3f4360e01b81529051919092169163ddca3f43916004808301926020929190829003018186803b158015620002f557600080fd5b505afa1580156200030a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620003309190620006f0565b600860146101000a81548162ffffff021916908362ffffff160217905550600a60009054906101000a90046001600160a01b03166001600160a01b031663d0c93a7c6040518163ffffffff1660e01b815260040160206040518083038186803b1580156200039d57600080fd5b505afa158015620003b2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620003d89190620006cd565b6008805460029290920b62ffffff16600160b81b0262ffffff60b81b1990921691909117905550506001600160a01b03166000908152600d60205260409020805460ff191660011790555062000715915050565b4690565b60008383836200043f6200042c565b3060405160200180868152602001858152602001848152602001838152602001826001600160a01b03168152602001955050505050506040516020818303038152906040528051906020012090509392505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282620004cc576000855562000517565b82601f10620004e757805160ff191683800117855562000517565b8280016001018555821562000517579182015b8281111562000517578251825591602001919060010190620004fa565b506200052592915062000529565b5090565b5b808211156200052557600081556001016200052a565b80516001600160a01b03811681146200055857600080fd5b919050565b600082601f8301126200056e578081fd5b81516001600160401b03808211156200058357fe5b6040516020601f8401601f1916820181018381118382101715620005a357fe5b6040528382528584018101871015620005ba578485fd5b8492505b83831015620005dd5785830181015182840182015291820191620005be565b83831115620005ee57848185840101525b5095945050505050565b6000602082840312156200060a578081fd5b620006158262000540565b9392505050565b60008060008060008060c0878903121562000635578182fd5b620006408762000540565b9550620006506020880162000540565b9450620006606040880162000540565b9350620006706060880162000540565b60808801519093506001600160401b03808211156200068d578384fd5b6200069b8a838b016200055d565b935060a0890151915080821115620006b1578283fd5b50620006c089828a016200055d565b9150509295509295509295565b600060208284031215620006df578081fd5b81518060020b811462000615578182fd5b60006020828403121562000702578081fd5b815162ffffff8116811462000615578182fd5b60805160a05160c05160e0516101005161012051614c176200075f60003980610fb152508061224e52508061229052508061226f5250806121f55250806122255250614c176000f3fe60806040526004361061013f5760003560e01c8062ebf5dd1461014857806306fdde031461017f578063095ea7b3146101a157806318160ddd146101ce57806323b872dd146101f0578063313ce567146102105780633644e5151461023257806339509351146102475780633fe529f014610267578063631f81ae146102875780636d70f7ae146102a757806370a08231146102c75780637ecebe00146102e75780637f98aa71146103075780638dbdbe6d1461032c57806395d89b411461034e578063a457c2d714610363578063a9059cbb14610383578063ac2dc562146103a3578063c8696232146103c8578063d3487997146103ef578063d505accf1461040f578063dd62ed3e1461042f578063e1c7392a1461044f578063eb3221b414610464578063fa02165614610479578063fa461e331461048e57610146565b3661014657005b005b34801561015457600080fd5b506101686101633660046147de565b6104ae565b604051610176929190614985565b60405180910390f35b34801561018b57600080fd5b50610194610742565b6040516101769190614932565b3480156101ad57600080fd5b506101c16101bc3660046146f2565b6107d9565b60405161017691906148e1565b3480156101da57600080fd5b506101e36107f7565b6040516101769190614904565b3480156101fc57600080fd5b506101c161020b366004614642565b6107fd565b34801561021c57600080fd5b50610225610885565b60405161017691906149f8565b34801561023e57600080fd5b506101e361088e565b34801561025357600080fd5b506101c16102623660046146f2565b61089d565b34801561027357600080fd5b5061014661028236600461457a565b6108eb565b34801561029357600080fd5b506101466102a236600461457a565b610943565b3480156102b357600080fd5b506101c16102c236600461457a565b610ad1565b3480156102d357600080fd5b506101e36102e236600461457a565b610af3565b3480156102f357600080fd5b506101e361030236600461457a565b610b0e565b34801561031357600080fd5b5061031c610b2f565b6040516101769493929190614898565b61033f61033a36600461481f565b610b5c565b60405161017693929190614993565b34801561035a57600080fd5b50610194610d53565b34801561036f57600080fd5b506101c161037e3660046146f2565b610db4565b34801561038f57600080fd5b506101c161039e3660046146f2565b610e1c565b3480156103af57600080fd5b506103b8610e30565b604051610176949392919061490d565b3480156103d457600080fd5b506103dd610e59565b604051610176969594939291906149c4565b3480156103fb57600080fd5b5061014661040a36600461484c565b610ee5565b34801561041b57600080fd5b5061014661042a366004614682565b610f42565b34801561043b57600080fd5b506101e361044a366004614596565b6110f9565b34801561045b57600080fd5b50610146611124565b34801561047057600080fd5b5061014661121f565b34801561048557600080fd5b50610146611315565b34801561049a57600080fd5b506101466104a9366004614776565b61171b565b600080600c60189054906101000a900463ffffffff1663ffffffff166001146104d657600080fd5b600c805463ffffffff60c01b1916600160c11b179055846104f657600080fd5b60006105006107f7565b600c54909150600160a01b900463ffffffff16600114156105a657600061053087670de0b6b3a764000084611786565b600954600a5491925061055d916001600160a01b031690600281810b9163010000009004900b8430611835565b600954600a549296509094506000918291610592916001600160a01b0316903090600281810b9163010000009004900b611a02565b915091506105a260008383611ac9565b5050505b60006105c46105bd856105b7611b62565b90611be3565b8884611786565b905060006105de6105d7856105b7611bf3565b8985611786565b90506105ea8583611c24565b94506105f68482611c24565b935084156106185760075461061890879089906001600160a01b031688611c34565b83156106385760085461063890879089906001600160a01b031687611c34565b6106423389611cd5565b866001600160a01b03167f02f25270a4d87bea75db541cdfe559334a275b4a233520ed6c0a2429667cca9489878760405161067f93929190614993565b60405180910390a2600c54600160a01b900463ffffffff166001141561071f5760095460009081906106df90600281810b9163010000009004900b6106c2611b62565b6106ca611bf3565b600a546001600160a01b031693929190611dbf565b915091507f2fb985eb745b9e89bb1ab82e0f8ceb6bf94d4d60aed7e8196540c50161a5fe918282604051610714929190614985565b60405180910390a150505b5050600c805463ffffffff60c01b1916600160c01b179055509094909350915050565b60038054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156107ce5780601f106107a3576101008083540402835291602001916107ce565b820191906000526020600020905b8154815290600101906020018083116107b157829003601f168201915b505050505090505b90565b60006107ed6107e6611f21565b8484611f25565b5060015b92915050565b60025490565b600061080a848484612011565b61087a84610816611f21565b61087585604051806060016040528060288152602001614b34602891396001600160a01b038a16600090815260016020526040812090610854611f21565b6001600160a01b03168152602081019190915260400160002054919061215a565b611f25565b5060015b9392505050565b60055460ff1690565b60006108986121f1565b905090565b60006107ed6108aa611f21565b8461087585600160006108bb611f21565b6001600160a01b03908116825260208083019390935260409182016000908120918c1681529252902054906122bb565b60006108f5612313565b505050509050806001600160a01b0316336001600160a01b03161461091957600080fd5b506001600160a01b03166000908152600d60205260409020805460ff19811660ff90911615179055565b336000908152600d602052604090205460ff1661095f57600080fd5b600b5460405163c683630d60e01b81526001600160a01b039091169063c683630d9061098f908490600401614884565b60206040518083038186803b1580156109a757600080fd5b505afa1580156109bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109df9190614739565b6109e857600080fd5b600954600a54600091829182918291610a1c916001600160a01b0390911690600281810b9163010000009004900b886123b2565b9350935093509350306001600160a01b0316856001600160a01b031614610a7657600754610a5c906001600160a01b03163087610a57611b62565b612566565b600854610a76906001600160a01b03163087610a57611bf3565b600c805463ffffffff60a01b1916600160a11b1790556040517f0b807fda608508350274d5da730325b52bb86f7ba43085d327059ed4b2fc840490610ac29086908690869086906149a9565b60405180910390a15050505050565b6001600160a01b0381166000908152600d602052604090205460ff165b919050565b6001600160a01b031660009081526020819052604090205490565b6001600160a01b03811660009081526006602052604081206107f1906126a3565b600754600854600a546001600160a01b039283169383831693600160a01b90930462ffffff169290911690565b6000806000600c60189054906101000a900463ffffffff1663ffffffff16600114610b8657600080fd5b600c805463ffffffff60c01b1916600160c11b1790558515801590610bab5750600085115b610bb457600080fd5b6000610bbe611f21565b9050610c4860018888610bcf611b62565b610bd7611bf3565b610bdf6107f7565b60408051608081018252600954600281810b810b810b835263010000008204810b810b810b6020840152600160301b8204810b810b810b93830193909352600160481b9004820b820b90910b6060820152600a546001600160a01b0316969594939291906126a7565b6007549296509094509250610c68906001600160a01b0316823086612566565b600854610c80906001600160a01b0316823085612566565b600c54600160a01b900463ffffffff1660011415610cc757600954600a54610cc4916001600160a01b0390911690600281810b9163010000009004900b8686611dbf565b50505b4715610cd757610cd73347612743565b610ce18585612837565b846001600160a01b0316816001600160a01b03167f4e2ca0515ed1aef1395f66b5303bb5d6f1bf9d61a353fa53f73f8ac9973fa9f6858588604051610d2893929190614993565b60405180910390a350600c805463ffffffff60c01b1916600160c01b17905591959094509092509050565b60048054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156107ce5780601f106107a3576101008083540402835291602001916107ce565b60006107ed610dc1611f21565b8461087585604051806060016040528060258152602001614be66025913960016000610deb611f21565b6001600160a01b03908116825260208083019390935260409182016000908120918d1681529252902054919061215a565b60006107ed610e29611f21565b8484612011565b600954600281810b9163010000008104820b91600160301b8204810b91600160481b9004900b84565b60408051608081018252600954600281810b810b810b835263010000008204810b810b810b6020840152600160301b8204810b810b810b93830193909352600160481b9004820b820b90910b6060820152600a5460009182918291829182918291610ed2916001600160a01b0390911690600190612915565b949b939a50919850965094509092509050565b610eed6129ac565b336000610efc8385018561457a565b90508515610f1c57600754610f1c906001600160a01b0316828489612566565b8415610f3a57600854610f3a906001600160a01b0316828488612566565b505050505050565b83421115610f97576040805162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e65000000604482015290519081900360640190fd5b6001600160a01b03871660009081526006602052604081207f000000000000000000000000000000000000000000000000000000000000000090899089908990610fe0906126a3565b8960405160200180878152602001866001600160a01b03168152602001856001600160a01b0316815260200184815260200183815260200182815260200196505050505050506040516020818303038152906040528051906020012090506000611049826129c5565b9050600061105982878787612a11565b9050896001600160a01b0316816001600160a01b0316146110c1576040805162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e61747572650000604482015290519081900360640190fd5b6001600160a01b038a1660009081526006602052604090206110e290612b82565b6110ed8a8a8a611f25565b50505050505050505050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b600061112e612313565b505050509050806001600160a01b0316336001600160a01b03161461115257600080fd5b600c54600160e01b900463ffffffff1660011461116e57600080fd5b600c80546001600160e01b0316600160e11b179055600854600160b81b900460020b600061119a612b8b565b600a5490830291506000906111b7906001600160a01b0316612c24565b5091505060006111c78285612ca6565b6009805462ffffff1916858303600290810b62ffffff9081169290921765ffffff00000019166301000000858901830b93909316830217928390559293506112189282810b9291909104900b612cf2565b5050505050565b336000908152600d602052604090205460ff1661123b57600080fd5b600c805463ffffffff60a01b1916600160a01b179055600954600a546000918291611281916001600160a01b0390911690600281810b9163010000009004900b306123b2565b93509350505061129360018383611ac9565b600061129d612b8b565b600854600160b81b900460020b90810291506112da9082906112bd611b62565b6112c5611bf3565b600a546001600160a01b031693929190612dbb565b60098054600293840b62ffffff90811662ffffff199490950b1663010000000265ffffff000000199091161791909116919091179055505050565b336000908152600d602052604090205460ff1661133157600080fd5b600061133b612313565b5050600a5460405163051bb83360e01b81529294506001600160a01b03808616945063051bb833936113739350911690600401614884565b60006040518083038186803b15801561138b57600080fd5b505afa15801561139f573d6000803e3d6000fd5b5050600c805463ffffffff60a01b1916600160a01b179055506113c2905061449f565b600954600a546000916113ed916001600160a01b031690600281810b9163010000009004900b612de6565b5050600954600a5491925061141b916001600160a01b031690600281810b9163010000009004900b306123b2565b6020860181905281865260c086019290925260a085019290925261144191600191611ac9565b600061144b612b8b565b600854600a54600160b81b90910460020b919091029150611474906001600160a01b0316612c24565b50600290810b810b6040860181905260085461149d935090918491600160b81b9004900b612e84565b600290810b810b608086015290810b900b60608401526001600160801b038216158015906114d9575060a083015115806114d9575060c0830151155b15611547576000808460a00151116114f25760006114f5565b60015b90506000816115145761150f8560c0015160326064611786565b611525565b6115258560a0015160326064611786565b600a54909150611540906001600160a01b0316308484612ea1565b505061166b565b61154f611b62565b60a084015261155c611bf3565b60c0840181905260a084015160608501516080860151600a5461158d946001600160a01b039091169392909161301d565b6001600160801b031660e0840181905260608401516080850151600a546115c1936001600160a01b039091169290916130b1565b6101208501819052610100850182905260a085015160c08601516115e9939192909190613148565b151561014084018190526116245761161f6116168461012001518560c00151611be390919063ffffffff16565b60326064611786565b611643565b6116436116168461010001518560a00151611be390919063ffffffff16565b6101608401819052610140840151600a5461166b926001600160a01b03909116913091612ea1565b611673611b62565b60a0840152611680611bf3565b60c0840181905260a0840151600854600a546116b4936001600160a01b0390911692918590600160b81b900460020b613183565b6009805465ffffff00000019166301000000600293840b62ffffff90811682029290921762ffffff191694840b91909116939093179081905560a086015160c0870151600a54610f3a956001600160a01b039091169484810b9491909104900b9190611dbf565b6117236129ac565b60008413806117325750600083135b61173b57600080fd5b60006117498284018461471d565b9050801561176e57600754611769906001600160a01b0316303388612566565b611218565b600854611218906001600160a01b0316303387612566565b60008080600019858709868602925082811090839003039050806117bc57600084116117b157600080fd5b50829004905061087e565b8084116117c857600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b6000808061184d6001600160a01b0389168888612de6565b50509050600061186f826001600160801b031687670de0b6b3a7640000611786565b9050886001600160a01b031663a34123a7898961188b8561338b565b6040518463ffffffff1660e01b8152600401808460020b81526020018360020b8152602001826001600160801b0316815260200193505050506040805180830381600087803b1580156118dd57600080fd5b505af11580156118f1573d6000803e3d6000fd5b505050506040513d604081101561190757600080fd5b5080516020909101519094509250831515806119235750600083115b156119f657886001600160a01b0316634f1eb3d8868a8a6119438961338b565b61194c8961338b565b6040518663ffffffff1660e01b815260040180866001600160a01b031681526020018560020b81526020018460020b8152602001836001600160801b03168152602001826001600160801b03168152602001955050505050506040805180830381600087803b1580156119be57600080fd5b505af11580156119d2573d6000803e3d6000fd5b505050506040513d60408110156119e857600080fd5b50516001600160801b031693505b50509550959350505050565b600080611a108685856133d3565b50604080516309e3d67b60e31b81526001600160a01b038781166004830152600287810b602484015286900b60448301526001600160801b03606483018190526084830152825190891692634f1eb3d89260a480820193918290030181600087803b158015611a7e57600080fd5b505af1158015611a92573d6000803e3d6000fd5b505050506040513d6040811015611aa857600080fd5b5080516020909101516001600160801b039182169891169650945050505050565b600080611ad4612313565b509350935050506000841115611b0957600754611b09906001600160a01b031683611b048760ff86166064611786565b61348c565b8215611b2f57600854611b2f906001600160a01b031683611b048660ff86166064611786565b7ff8994d9c768d599c5c6e92d52cd9cc24762cd773384c7a4612796773c56a86a6858585604051610ac2939291906148ec565b6007546040516370a0823160e01b81526000916001600160a01b0316906370a0823190611b93903090600401614884565b60206040518083038186803b158015611bab57600080fd5b505afa158015611bbf573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061089891906147c6565b808203828111156107f157600080fd5b6008546040516370a0823160e01b81526000916001600160a01b0316906370a0823190611b93903090600401614884565b808201828110156107f157600080fd5b838015611c4e5750600c546001600160a01b038381169116145b15611cc457600c54604051632e1a7d4d60e01b81526001600160a01b0390911690632e1a7d4d90611c83908490600401614904565b600060405180830381600087803b158015611c9d57600080fd5b505af1158015611cb1573d6000803e3d6000fd5b50505050611cbf8382612743565b611ccf565b611ccf82848361348c565b50505050565b6001600160a01b038216611d1a5760405162461bcd60e51b8152600401808060200182810382526021815260200180614b7c6021913960400191505060405180910390fd5b611d2682600083612832565b611d6381604051806060016040528060228152602001614a5f602291396001600160a01b038516600090815260208190526040902054919061215a565b6001600160a01b038316600090815260208190526040902055600254611d8990826135d3565b6002556040805182815290516000916001600160a01b03851691600080516020614b5c8339815191529181900360200190a35050565b60008080611dd96001600160a01b03891686868a8a61301d565b90506001600160801b03811615611f16576040805130602080830182905283518084038201815283850194859052633c8a7d8d60e01b9094526044830182815260028c810b60648601528b900b60848501526001600160801b03861660a485015260a060c48501908152855160e486015285516001600160a01b038f1696633c8a7d8d968f958f958b959394909392610104019185019080838360005b83811015611e8e578181015183820152602001611e76565b50505050905090810190601f168015611ebb5780820380516001836020036101000a031916815260200191505b5096505050505050506040805180830381600087803b158015611edd57600080fd5b505af1158015611ef1573d6000803e3d6000fd5b505050506040513d6040811015611f0757600080fd5b50805160209091015190935091505b509550959350505050565b3390565b6001600160a01b038316611f6a5760405162461bcd60e51b8152600401808060200182810382526024815260200180614bc26024913960400191505060405180910390fd5b6001600160a01b038216611faf5760405162461bcd60e51b8152600401808060200182810382526022815260200180614a816022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b0383166120565760405162461bcd60e51b8152600401808060200182810382526025815260200180614b9d6025913960400191505060405180910390fd5b6001600160a01b03821661209b5760405162461bcd60e51b8152600401808060200182810382526023815260200180614a3c6023913960400191505060405180910390fd5b6120a6838383612832565b6120e381604051806060016040528060268152602001614aa3602691396001600160a01b038616600090815260208190526040902054919061215a565b6001600160a01b03808516600090815260208190526040808220939093559084168152205461211290826122bb565b6001600160a01b03808416600081815260208181526040918290209490945580518581529051919392871692600080516020614b5c83398151915292918290030190a3505050565b600081848411156121e95760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156121ae578181015183820152602001612196565b50505050905090810190601f1680156121db5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b60007f000000000000000000000000000000000000000000000000000000000000000061221c613630565b141561224957507f00000000000000000000000000000000000000000000000000000000000000006107d6565b6122b47f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000613634565b90506107d6565b60008282018381101561087e576040805162461bcd60e51b815260206004820152601b60248201527a536166654d6174683a206164646974696f6e206f766572666c6f7760281b604482015290519081900360640190fd5b6000806000806000600b60009054906101000a90046001600160a01b03166001600160a01b03166338d772806040518163ffffffff1660e01b815260040160a06040518083038186803b15801561236957600080fd5b505afa15801561237d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123a191906145ce565b945094509450945094509091929394565b6000808080806123cc6001600160a01b038a168989612de6565b50909150506001600160801b0381161561255a576040805163a34123a760e01b815260028a810b600483015289900b60248201526001600160801b038316604482015281516001600160a01b038c169263a34123a792606480820193918290030181600087803b15801561243f57600080fd5b505af1158015612453573d6000803e3d6000fd5b505050506040513d604081101561246957600080fd5b5080516020909101519095509350841515806124855750600084115b1561255a57604080516309e3d67b60e31b81526001600160a01b03888116600483015260028b810b60248401528a900b60448301526001600160801b0360648301819052608483015282516000938493928e1692634f1eb3d89260a4808301939282900301818787803b1580156124fb57600080fd5b505af115801561250f573d6000803e3d6000fd5b505050506040513d604081101561252557600080fd5b5080516020909101516001600160801b0391821693501690506125488288611be3565b6125528288611be3565b909550935050505b50945094509450949050565b600c546001600160a01b0385811691161480156125835750804710155b1561267b57600c60009054906101000a90046001600160a01b03166001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b1580156125d857600080fd5b505af11580156125ec573d6000803e3d6000fd5b5050600c5460405163a9059cbb60e01b81526001600160a01b03909116935063a9059cbb92506126239150859085906004016148c8565b602060405180830381600087803b15801561263d57600080fd5b505af1158015612651573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126759190614739565b50611ccf565b6001600160a01b03831630141561269757611cbf84838361348c565b611ccf84848484613696565b5490565b60008060008060008060006126bd8f8f8a612915565b5050935093509350935060006126e68c6126e08588611c2490919063ffffffff16565b90611c24565b905060006126f88c6126e08786611c24565b90508a158061270657508115155b8061271057508015155b61271657fe5b6127238f8f84848f6137e6565b809950819a50829b50505050505050505050985098509895505050505050565b604080516000808252602082019092526001600160a01b0384169083906040518082805190602001908083835b6020831061278f5780518252601f199092019160209182019101612770565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d80600081146127f1576040519150601f19603f3d011682016040523d82523d6000602084013e6127f6565b606091505b5050905080612832576040805162461bcd60e51b815260206004820152600360248201526253544560e81b604482015290519081900360640190fd5b505050565b6001600160a01b038216612892576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b61289e60008383612832565b6002546128ab90826122bb565b6002556001600160a01b0382166000908152602081905260409020546128d190826122bb565b6001600160a01b038316600081815260208181526040808320949094558351858152935192939192600080516020614b5c8339815191529281900390910190a35050565b600080600080600080612931898860000151896020015161387a565b939950919750955093509150876129a057600080600080600061295d8e8d604001518e6060015161387a565b9398509196509450925090506129738b86611c24565b9a5061297f8a85611c24565b995061298b8984611c24565b98506129978883611c24565b97509450505050505b93975093979195509350565b600a546001600160a01b031633146129c357600080fd5b565b60006129cf6121f1565b82604051602001808061190160f01b81525060020183815260200182815260200192505050604051602081830303815290604052805190602001209050919050565b60006fa2a8918ca85bafe22016d0b997e4df60600160ff1b03821115612a685760405162461bcd60e51b8152600401808060200182810382526022815260200180614af06022913960400191505060405180910390fd5b8360ff16601b1480612a7d57508360ff16601c145b612ab85760405162461bcd60e51b8152600401808060200182810382526022815260200180614b126022913960400191505060405180910390fd5b600060018686868660405160008152602001604052604051808581526020018460ff1681526020018381526020018281526020019450505050506020604051602081039080840390855afa158015612b14573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116612b77576040805162461bcd60e51b815260206004820152601860248201527745434453413a20696e76616c6964207369676e617475726560401b604482015290519081900360640190fd5b90505b949350505050565b80546001019055565b600080612b96612313565b5050600a54604051630737687360e21b81529294506001600160a01b038086169450631cdda1cc93612bce9350911690600401614884565b60206040518083038186803b158015612be657600080fd5b505afa158015612bfa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c1e9190614755565b91505090565b6000806000836001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e06040518083038186803b158015612c6257600080fd5b505afa158015612c76573d6000803e3d6000fd5b505050506040513d60e0811015612c8c57600080fd5b508051602082015160609092015190969195509350915050565b6000808260020b8460020b81612cb857fe5b05905060008460020b128015612cdf57508260020b8460020b81612cd857fe5b0760020b15155b15612ce957600019015b90910292915050565b8060020b8260020b12612d32576040805162461bcd60e51b8152602060048201526003602482015262544c5560e81b604482015290519081900360640190fd5b620d89e719600283900b1215612d75576040805162461bcd60e51b8152602060048201526003602482015262544c4d60e81b604482015290519081900360640190fd5b620d89e8600282900b1315612db7576040805162461bcd60e51b815260206004820152600360248201526254554d60e81b604482015290519081900360640190fd5b5050565b600080612dd46001600160a01b03881685858989613183565b90925090506119f68783838787611dbf565b600080600080612df73087876138bf565b9050866001600160a01b031663514ea4bf826040518263ffffffff1660e01b81526004018082815260200191505060a06040518083038186803b158015612e3d57600080fd5b505afa158015612e51573d6000803e3d6000fd5b505050506040513d60a0811015612e6757600080fd5b508051606082015160809092015190999198509650945050505050565b6000806000612e938685612ca6565b858103979501955050505050565b6000612eb5856001600160a01b0316612c24565b505090506000620f42408261c350026001600160a01b031681612ed457fe5b049050600084612ee657818301612eea565b8183035b9050866001600160a01b031663128acb08878787858a6040516020018082151581526020019150506040516020818303038152906040526040518663ffffffff1660e01b815260040180866001600160a01b031681526020018515158152602001848152602001836001600160a01b0316815260200180602001828103825283818151815260200191508051906020019080838360005b83811015612f99578181015183820152602001612f81565b50505050905090810190601f168015612fc65780820380516001836020036101000a031916815260200191505b5096505050505050506040805180830381600087803b158015612fe857600080fd5b505af1158015612ffc573d6000803e3d6000fd5b505050506040513d604081101561301257600080fd5b505050505050505050565b600080866001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e06040518083038186803b15801561305957600080fd5b505afa15801561306d573d6000803e3d6000fd5b505050506040513d60e081101561308357600080fd5b505190506130a48161309486613910565b61309d86613910565b8989613c37565b9150505b95945050505050565b6000806000866001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e06040518083038186803b1580156130ef57600080fd5b505afa158015613103573d6000803e3d6000fd5b505050506040513d60e081101561311957600080fd5b505190506131398161312a87613910565b61313387613910565b89613cf9565b92509250505b94509492505050565b600061315e856131588685611be3565b90613d94565b61316c856131588887611be3565b116131785760006130a8565b600195945050505050565b60008060006040518060e00160405280888152602001878152602001600081526020016000815260200160006001600160801b03168152602001600060020b8152602001600060020b8152509050600080896001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e06040518083038186803b15801561320d57600080fd5b505afa158015613221573d6000803e3d6000fd5b505050506040513d60e081101561323757600080fd5b5080516020909101519092509050613250818888612e84565b600290810b810b60c0860181905291810b900b60a085018190528451602086015161327d938e9390613db8565b606085018190526040850182905260a085015160c08601516132a4938e939092909161301d565b6001600160801b0316608084015282516020840151604085015160608601516000936132d39390929091613148565b905080156133185760006132f284866080015187600001516000613de7565b905061330661330082613ecf565b89612ca6565b600290810b900b60c08601525061334b565b600061332f848660800151876020015160006141ba565b905061333d61330082613ecf565b600290810b900b60a0860152505b61335d8460a001518560c00151612cf2565b61336b8460a0015188612ca6565b955061337b8460c0015188612ca6565b9450505050509550959350505050565b6000600160801b82106133cf5760405162461bcd60e51b8152600401808060200182810382526027815260200180614ac96027913960400191505060405180910390fd5b5090565b60006133e96001600160a01b0385168484612de6565b50909150506001600160801b0381161561087e57836001600160a01b031663a34123a7848460006040518463ffffffff1660e01b8152600401808460020b81526020018360020b815260200182815260200193505050506040805180830381600087803b15801561345957600080fd5b505af115801561346d573d6000803e3d6000fd5b505050506040513d604081101561348357600080fd5b50509392505050565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b1781529251825160009485949389169392918291908083835b602083106135085780518252601f1990920191602091820191016134e9565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d806000811461356a576040519150601f19603f3d011682016040523d82523d6000602084013e61356f565b606091505b509150915081801561359d57508051158061359d575080806020019051602081101561359a57600080fd5b50515b611218576040805162461bcd60e51b815260206004820152600260248201526114d560f21b604482015290519081900360640190fd5b60008282111561362a576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b4690565b6000838383613641613630565b3060405160200180868152602001858152602001848152602001838152602001826001600160a01b03168152602001955050505050506040516020818303038152906040528051906020012090509392505050565b604080516001600160a01b0385811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180516001600160e01b03166323b872dd60e01b178152925182516000948594938a169392918291908083835b6020831061371a5780518252601f1990920191602091820191016136fb565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d806000811461377c576040519150601f19603f3d011682016040523d82523d6000602084013e613781565b606091505b50915091508180156137af5750805115806137af57508080602001905160208110156137ac57600080fd5b50515b610f3a576040805162461bcd60e51b815260206004820152600360248201526229aa2360e91b604482015290519081900360640190fd5b600080808361380a5750869050858082116138015780613803565b815b925061386f565b8561381c575085613803818587611786565b8461382f57879150613803828588611786565b61383a878787611786565b915087821015613851575085613803818587611786565b87915061385f828688611786565b905061386c828588611786565b92505b955095509592505050565b600080600080600061388d8888886133d3565b90506001600160801b038116156138b4576138a9888888614296565b929750909550935091505b939792965093509350565b6040805160609490941b6001600160601b031916602080860191909152600293840b60e890811b60348701529290930b90911b60378401528051808403601a018152603a9093019052815191012090565b60008060008360020b12613927578260020b61392f565b8260020b6000035b9050620d89e881111561396d576040805162461bcd60e51b81526020600482015260016024820152601560fa1b604482015290519081900360640190fd5b60006001821661398157600160801b613993565b6ffffcb933bd6fad37aa2d162d1a5940015b6001600160881b0316905060028216156139bd576ffff97272373d413259a46990580e213a0260801c5b60048216156139dc576ffff2e50f5f656932ef12357cf3c7fdcc0260801c5b60088216156139fb576fffe5caca7e10e4e61c3624eaa0941cd00260801c5b6010821615613a1a576fffcb9843d60f6159c9db58835c9266440260801c5b6020821615613a39576fff973b41fa98c081472e6896dfb254c00260801c5b6040821615613a58576fff2ea16466c96a3843ec78b326b528610260801c5b6080821615613a77576ffe5dee046a99a2a811c461f1969c30530260801c5b610100821615613a97576ffcbe86c7900a88aedcffc83b479aa3a40260801c5b610200821615613ab7576ff987a7253ac413176f2b074cf7815e540260801c5b610400821615613ad7576ff3392b0822b70005940c7a398e4b70f30260801c5b610800821615613af7576fe7159475a2c29b7443b29c7fa6e889d90260801c5b611000821615613b17576fd097f3bdfd2022b8845ad8f792aa58250260801c5b612000821615613b37576fa9f746462d870fdf8a65dc1f90e061e50260801c5b614000821615613b57576f70d869a156d2a1b890bb3df62baf32f70260801c5b618000821615613b77576f31be135f97d08fd981231505542fcfa60260801c5b62010000821615613b98576f09aa508b5b7a84e1c677de54f3e99bc90260801c5b62020000821615613bb8576e5d6af8dedb81196699c329225ee6040260801c5b62040000821615613bd7576d2216e584f5fa1ea926041bedfe980260801c5b62080000821615613bf4576b048a170391f7dc42444e8fa20260801c5b60008460020b1315613c0f578060001981613c0b57fe5b0490505b600160201b810615613c22576001613c25565b60005b60ff16602082901c0192505050919050565b6000836001600160a01b0316856001600160a01b03161115613c57579293925b846001600160a01b0316866001600160a01b031611613c8257613c7b8585856142e2565b90506130a8565b836001600160a01b0316866001600160a01b03161015613ce4576000613ca98786866142e2565b90506000613cb8878986614345565b9050806001600160801b0316826001600160801b031610613cd95780613cdb565b815b925050506130a8565b613cef858584614345565b9695505050505050565b600080836001600160a01b0316856001600160a01b03161115613d1a579293925b846001600160a01b0316866001600160a01b031611613d4557613d3e858585614382565b915061313f565b836001600160a01b0316866001600160a01b03161015613d7e57613d6a868585614382565b9150613d778587856143eb565b905061313f565b613d898585856143eb565b905094509492505050565b6000821580613daf57505081810281838281613dac57fe5b04145b6107f157600080fd5b6000806000613dca888888888861301d565b9050613dd8888287876130b1565b90999098509650505050505050565b600082613df5575083612b7a565b600160601b600160e01b03606085901b168215613e83576001600160a01b03861684810290858281613e2357fe5b041415613e5457818101828110613e5257613e4883896001600160a01b03168361442e565b9350505050612b7a565b505b613e7a82613e75878a6001600160a01b03168681613e6e57fe5b0490611c24565b614468565b92505050612b7a565b6001600160a01b03861684810290858281613e9a57fe5b04148015613ea757508082115b613eb057600080fd5b808203613e48613eca846001600160a01b038b168461442e565b614473565b60006401000276a36001600160a01b03831610801590613f0b575073fffd8963efd1fc6a506488495d951d5263988d266001600160a01b038316105b613f40576040805162461bcd60e51b81526020600482015260016024820152602960f91b604482015290519081900360640190fd5b600160201b600160c01b03602083901b166001600160801b03811160071b81811c6001600160401b03811160061b90811c63ffffffff811160051b90811c61ffff811160041b90811c60ff8111600390811b91821c600f811160021b90811c918211600190811b92831c97908811961790941790921717909117171760808110613fd257607f810383901c9150613fdc565b80607f0383901b91505b908002607f81811c60ff83811c9190911c800280831c81831c1c800280841c81841c1c800280851c81851c1c800280861c81861c1c800280871c81871c1c800280881c81881c1c800280891c81891c1c8002808a1c818a1c1c8002808b1c818b1c1c8002808c1c818c1c1c8002808d1c818d1c1c8002808e1c9c81901c9c909c1c80029c8d901c9e9d607f198f0160401b60c09190911c6001603f1b161760c19b909b1c6001603e1b169a909a1760c29990991c6001603d1b169890981760c39790971c6001603c1b169690961760c49590951c6001603b1b169490941760c59390931c6001603a1b169290921760c69190911c600160391b161760c79190911c600160381b161760c89190911c600160371b161760c99190911c600160361b161760ca9190911c600160351b161760cb9190911c600160341b161760cc9190911c600160331b161760cd9190911c600160321b1617693627a301d71055774c8581026f028f6481ab7f045a5af012a19d003aa9198101608090811d906fdb2df09e81959a81455e260799a0632f8301901d600281810b9083900b146141ab57886001600160a01b031661418f82613910565b6001600160a01b031611156141a457816141a6565b805b6141ad565b815b9998505050505050505050565b600081156142285760006001600160a01b038411156141f0576141eb84600160601b876001600160801b0316611786565b614208565b6001600160801b038516606085901b8161420657fe5b045b9050614220613eca6001600160a01b03881683611c24565b915050612b7a565b60006001600160a01b038411156142565761425184600160601b876001600160801b031661442e565b61426d565b61426d606085901b6001600160801b038716614468565b905080866001600160a01b03161161428457600080fd5b6001600160a01b038616039050612b7a565b60008060008060008060006142ac8a8a8a612de6565b9250925092506000806142c18c868d8d6130b1565b9099509750506001600160801b039283169550501691505093509350935093565b6000826001600160a01b0316846001600160a01b03161115614302579192915b6000614325856001600160a01b0316856001600160a01b0316600160601b611786565b90506130a861434084838888036001600160a01b0316611786565b614489565b6000826001600160a01b0316846001600160a01b03161115614365579192915b612b7a61434083600160601b8787036001600160a01b0316611786565b6000826001600160a01b0316846001600160a01b031611156143a2579192915b836001600160a01b03166143db606060ff16846001600160801b0316901b8686036001600160a01b0316866001600160a01b0316611786565b816143e257fe5b04949350505050565b6000826001600160a01b0316846001600160a01b0316111561440b579192915b612b7a826001600160801b03168585036001600160a01b0316600160601b611786565b600061443b848484611786565b90506000828061444757fe5b848609111561087e57600019811061445e57600080fd5b6001019392505050565b808204910615150190565b806001600160a01b0381168114610aee57600080fd5b806001600160801b0381168114610aee57600080fd5b604051806101c001604052806000815260200160008152602001600060020b8152602001600060020b8152602001600060020b8152602001600081526020016000815260200160006001600160801b0316815260200160008152602001600081526020016000151581526020016000815260200160006001600160a01b0316815260200160006001600160a01b031681525090565b60008083601f840112614545578182fd5b5081356001600160401b0381111561455b578182fd5b60208301915083602082850101111561457357600080fd5b9250929050565b60006020828403121561458b578081fd5b813561087e81614a06565b600080604083850312156145a8578081fd5b82356145b381614a06565b915060208301356145c381614a06565b809150509250929050565b600080600080600060a086880312156145e5578081fd5b85516145f081614a06565b602087015190955061460181614a06565b604087015190945061461281614a06565b606087015190935061462381614a2c565b608087015190925061463481614a2c565b809150509295509295909350565b600080600060608486031215614656578283fd5b833561466181614a06565b9250602084013561467181614a06565b929592945050506040919091013590565b600080600080600080600060e0888a03121561469c578182fd5b87356146a781614a06565b965060208801356146b781614a06565b9550604088013594506060880135935060808801356146d581614a2c565b9699959850939692959460a0840135945060c09093013592915050565b60008060408385031215614704578182fd5b823561470f81614a06565b946020939093013593505050565b60006020828403121561472e578081fd5b813561087e81614a1e565b60006020828403121561474a578081fd5b815161087e81614a1e565b600060208284031215614766578081fd5b81518060020b811461087e578182fd5b6000806000806060858703121561478b578081fd5b843593506020850135925060408501356001600160401b038111156147ae578182fd5b6147ba87828801614534565b95989497509550505050565b6000602082840312156147d7578081fd5b5051919050565b6000806000606084860312156147f2578081fd5b83359250602084013561480481614a06565b9150604084013561481481614a1e565b809150509250925092565b600080600060608486031215614833578081fd5b8335925060208401359150604084013561481481614a06565b60008060008060608587031215614861578182fd5b843593506020850135925060408501356001600160401b038111156147ae578283fd5b6001600160a01b0391909116815260200190565b6001600160a01b039485168152928416602084015262ffffff919091166040830152909116606082015260800190565b6001600160a01b03929092168252602082015260400190565b901515815260200190565b92151583526020830191909152604082015260600190565b90815260200190565b600294850b815292840b602084015290830b604083015290910b606082015260800190565b6000602080835283518082850152825b8181101561495e57858101830151858201604001528201614942565b8181111561496f5783604083870101525b50601f01601f1916929092016040019392505050565b918252602082015260400190565b9283526020830191909152604082015260600190565b93845260208401929092526040830152606082015260800190565b9586526020860194909452604085019290925260608401526001600160801b0390811660808401521660a082015260c00190565b60ff91909116815260200190565b6001600160a01b0381168114614a1b57600080fd5b50565b8015158114614a1b57600080fd5b60ff81168114614a1b57600080fdfe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e636545524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636553616665436173743a2076616c756520646f65736e27742066697420696e20313238206269747345434453413a20696e76616c6964207369676e6174757265202773272076616c756545434453413a20696e76616c6964207369676e6174757265202776272076616c756545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef45524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa164736f6c6343000706000aa164736f6c6343000706000a0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f9840000000000000000000000001e3881227010c8dcdfa2f11833d3d70a00893f94000000000000000000000000b7f7c5cea2b8b6138ea3f669b2094b27de2ec8d400000000000000000000000095477f96f78ec38916b5457030387d844e886ab3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000a

Deployed Bytecode

0x60806040523480156200001157600080fd5b5060043610620000765760003560e01c8063284c8acd146200007b57806338d7728014620000d65780633f1e478b14620001205780639ba49207146200015f578063ab033ea91462000188578063beb905d414620001b1578063c683630d146200030e575b600080fd5b620000ba600480360360608110156200009357600080fd5b5080356001600160a01b03908116916020810135909116906040013562ffffff166200034b565b604080516001600160a01b039092168252519081900360200190f35b620000e062000377565b604080516001600160a01b0396871681529486166020860152929094168383015260ff908116606084015292909216608082015290519081900360a00190f35b6200015d600480360360608110156200013857600080fd5b5080356001600160a01b03908116916020810135909116906040013560ff16620003ae565b005b6200015d600480360360208110156200017757600080fd5b50356001600160a01b031662000416565b6200015d60048036036020811015620001a057600080fd5b50356001600160a01b031662000457565b620000ba600480360360c0811015620001c957600080fd5b6001600160a01b038235811692602081013582169262ffffff60408301351692606083013516919081019060a081016080820135600160201b8111156200020f57600080fd5b8201836020820111156200022257600080fd5b803590602001918460018302840111600160201b831117156200024457600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295949360208101935035915050600160201b8111156200029757600080fd5b820183602082011115620002aa57600080fd5b803590602001918460018302840111600160201b83111715620002cc57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550620004de945050505050565b62000337600480360360208110156200032657600080fd5b50356001600160a01b031662000a5a565b604080519115158252519081900360200190f35b60066020908152600093845260408085208252928452828420905282529020546001600160a01b031681565b6000546001546002546003546001600160a01b0393841694928416939091169160ff600160a81b8304811692600160a01b90041690565b6000546001600160a01b03163314620003c657600080fd5b600180546001600160a01b039485166001600160a01b03199182161790915560028054939094169216919091179091556003805460ff909216600160a81b0260ff60a81b19909216919091179055565b6000546001600160a01b031633146200042e57600080fd5b6001600160a01b03166000908152600560205260409020805460ff19811660ff90911615179055565b6000546001600160a01b031633146200046f57600080fd5b6001600160a01b0381166200048357600080fd5b600080546040516001600160a01b03808516939216917f3aaaebeb4821d6a7e5c77ece53cff0afcc56c82add2c978dbbb7f73e84cbcfd291a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b600080546001600160a01b03163314620004f757600080fd5b856001600160a01b0316876001600160a01b031614156200051757600080fd5b600080876001600160a01b0316896001600160a01b0316106200053c5787896200053f565b88885b6001600160a01b0380831660009081526006602090815260408083208486168452825280832062ffffff8e16845290915290205492945090925016156200058557600080fd5b6004805460408051630b4c774160e11b81526001600160a01b0386811694820194909452848416602482015262ffffff8b166044820152905160009390921691631698ee8291606480820192602092909190829003018186803b158015620005ec57600080fd5b505afa15801562000601573d6000803e3d6000fd5b505050506040513d60208110156200061857600080fd5b505190506001600160a01b0381166200072957600480546040805163a167129560e01b81526001600160a01b0387811694820194909452858416602482015262ffffff8c1660448201529051929091169163a1671295916064808201926020929091908290030181600087803b1580156200069257600080fd5b505af1158015620006a7573d6000803e3d6000fd5b505050506040513d6020811015620006be57600080fd5b50516040805163f637731d60e01b81526001600160a01b038a8116600483015291519293509083169163f637731d9160248082019260009290919082900301818387803b1580156200070f57600080fd5b505af115801562000724573d6000803e3d6000fd5b505050505b6040805160608c811b6001600160601b0319908116602080850191909152918d901b16603483015260e88b901b6001600160e81b03191660488301528251808303602b018152604b9092019283905281519101206003546000549192849230926001600160a01b03908116929116908b908b90620007a79062000a6f565b80876001600160a01b03168152602001866001600160a01b03168152602001856001600160a01b03168152602001846001600160a01b031681526020018060200180602001838103835285818151815260200191508051906020019080838360005b838110156200082357818101518382015260200162000809565b50505050905090810190601f168015620008515780820380516001836020036101000a031916815260200191505b50838103825284518152845160209182019186019080838360005b83811015620008865781810151838201526020016200086c565b50505050905090810190601f168015620008b45780820380516001836020036101000a031916815260200191505b50985050505050505050508190604051809103906000f5905080158015620008e0573d6000803e3d6000fd5b5093508360066000856001600160a01b03166001600160a01b031681526020019081526020016000206000846001600160a01b03166001600160a01b0316815260200190815260200160002060008a62ffffff1662ffffff16815260200190815260200160002060006101000a8154816001600160a01b0302191690836001600160a01b031602179055508360066000846001600160a01b03166001600160a01b031681526020019081526020016000206000856001600160a01b03166001600160a01b0316815260200190815260200160002060008a62ffffff1662ffffff16815260200190815260200160002060006101000a8154816001600160a01b0302191690836001600160a01b03160217905550836001600160a01b0316826001600160a01b0316846001600160a01b03167faf0c778584d4b20d9768e68ed24ede73b034bc5747a377a69f1db53ff3933def8b604051808262ffffff16815260200191505060405180910390a45050509695505050505050565b60056020526000908152604090205460ff1681565b6153768062000a7e8339019056fe6101406040527f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c961012052600c80546001600160e01b0363ffffffff60c01b1963ffffffff60a01b19909216600160a01b1791909116600160c01b1716600160e01b1790553480156200007157600080fd5b50604051620053763803806200537683398101604081905262000094916200061c565b8180604051806040016040528060018152602001603160f81b81525084848160039080519060200190620000ca92919062000494565b508051620000e090600490602084019062000494565b50506005805460ff1916601217905550815160208084019190912082519183019190912060c082905260e08190527f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f620001396200042c565b60a0526200014981848462000430565b608052610100525050600c80546001600160a01b03808a166001600160a01b031992831617909255600b80548b8416908316179055600a80548c84169216919091179081905560408051630dfe168160e01b81529051919092169450630dfe1681935060048083019350602092829003018186803b158015620001cb57600080fd5b505afa158015620001e0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620002069190620005f8565b600780546001600160a01b0319166001600160a01b03928316179055600a546040805163d21220a760e01b81529051919092169163d21220a7916004808301926020929190829003018186803b1580156200026057600080fd5b505afa15801562000275573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200029b9190620005f8565b600880546001600160a01b0319166001600160a01b03928316179055600a546040805163ddca3f4360e01b81529051919092169163ddca3f43916004808301926020929190829003018186803b158015620002f557600080fd5b505afa1580156200030a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620003309190620006f0565b600860146101000a81548162ffffff021916908362ffffff160217905550600a60009054906101000a90046001600160a01b03166001600160a01b031663d0c93a7c6040518163ffffffff1660e01b815260040160206040518083038186803b1580156200039d57600080fd5b505afa158015620003b2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620003d89190620006cd565b6008805460029290920b62ffffff16600160b81b0262ffffff60b81b1990921691909117905550506001600160a01b03166000908152600d60205260409020805460ff191660011790555062000715915050565b4690565b60008383836200043f6200042c565b3060405160200180868152602001858152602001848152602001838152602001826001600160a01b03168152602001955050505050506040516020818303038152906040528051906020012090509392505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282620004cc576000855562000517565b82601f10620004e757805160ff191683800117855562000517565b8280016001018555821562000517579182015b8281111562000517578251825591602001919060010190620004fa565b506200052592915062000529565b5090565b5b808211156200052557600081556001016200052a565b80516001600160a01b03811681146200055857600080fd5b919050565b600082601f8301126200056e578081fd5b81516001600160401b03808211156200058357fe5b6040516020601f8401601f1916820181018381118382101715620005a357fe5b6040528382528584018101871015620005ba578485fd5b8492505b83831015620005dd5785830181015182840182015291820191620005be565b83831115620005ee57848185840101525b5095945050505050565b6000602082840312156200060a578081fd5b620006158262000540565b9392505050565b60008060008060008060c0878903121562000635578182fd5b620006408762000540565b9550620006506020880162000540565b9450620006606040880162000540565b9350620006706060880162000540565b60808801519093506001600160401b03808211156200068d578384fd5b6200069b8a838b016200055d565b935060a0890151915080821115620006b1578283fd5b50620006c089828a016200055d565b9150509295509295509295565b600060208284031215620006df578081fd5b81518060020b811462000615578182fd5b60006020828403121562000702578081fd5b815162ffffff8116811462000615578182fd5b60805160a05160c05160e0516101005161012051614c176200075f60003980610fb152508061224e52508061229052508061226f5250806121f55250806122255250614c176000f3fe60806040526004361061013f5760003560e01c8062ebf5dd1461014857806306fdde031461017f578063095ea7b3146101a157806318160ddd146101ce57806323b872dd146101f0578063313ce567146102105780633644e5151461023257806339509351146102475780633fe529f014610267578063631f81ae146102875780636d70f7ae146102a757806370a08231146102c75780637ecebe00146102e75780637f98aa71146103075780638dbdbe6d1461032c57806395d89b411461034e578063a457c2d714610363578063a9059cbb14610383578063ac2dc562146103a3578063c8696232146103c8578063d3487997146103ef578063d505accf1461040f578063dd62ed3e1461042f578063e1c7392a1461044f578063eb3221b414610464578063fa02165614610479578063fa461e331461048e57610146565b3661014657005b005b34801561015457600080fd5b506101686101633660046147de565b6104ae565b604051610176929190614985565b60405180910390f35b34801561018b57600080fd5b50610194610742565b6040516101769190614932565b3480156101ad57600080fd5b506101c16101bc3660046146f2565b6107d9565b60405161017691906148e1565b3480156101da57600080fd5b506101e36107f7565b6040516101769190614904565b3480156101fc57600080fd5b506101c161020b366004614642565b6107fd565b34801561021c57600080fd5b50610225610885565b60405161017691906149f8565b34801561023e57600080fd5b506101e361088e565b34801561025357600080fd5b506101c16102623660046146f2565b61089d565b34801561027357600080fd5b5061014661028236600461457a565b6108eb565b34801561029357600080fd5b506101466102a236600461457a565b610943565b3480156102b357600080fd5b506101c16102c236600461457a565b610ad1565b3480156102d357600080fd5b506101e36102e236600461457a565b610af3565b3480156102f357600080fd5b506101e361030236600461457a565b610b0e565b34801561031357600080fd5b5061031c610b2f565b6040516101769493929190614898565b61033f61033a36600461481f565b610b5c565b60405161017693929190614993565b34801561035a57600080fd5b50610194610d53565b34801561036f57600080fd5b506101c161037e3660046146f2565b610db4565b34801561038f57600080fd5b506101c161039e3660046146f2565b610e1c565b3480156103af57600080fd5b506103b8610e30565b604051610176949392919061490d565b3480156103d457600080fd5b506103dd610e59565b604051610176969594939291906149c4565b3480156103fb57600080fd5b5061014661040a36600461484c565b610ee5565b34801561041b57600080fd5b5061014661042a366004614682565b610f42565b34801561043b57600080fd5b506101e361044a366004614596565b6110f9565b34801561045b57600080fd5b50610146611124565b34801561047057600080fd5b5061014661121f565b34801561048557600080fd5b50610146611315565b34801561049a57600080fd5b506101466104a9366004614776565b61171b565b600080600c60189054906101000a900463ffffffff1663ffffffff166001146104d657600080fd5b600c805463ffffffff60c01b1916600160c11b179055846104f657600080fd5b60006105006107f7565b600c54909150600160a01b900463ffffffff16600114156105a657600061053087670de0b6b3a764000084611786565b600954600a5491925061055d916001600160a01b031690600281810b9163010000009004900b8430611835565b600954600a549296509094506000918291610592916001600160a01b0316903090600281810b9163010000009004900b611a02565b915091506105a260008383611ac9565b5050505b60006105c46105bd856105b7611b62565b90611be3565b8884611786565b905060006105de6105d7856105b7611bf3565b8985611786565b90506105ea8583611c24565b94506105f68482611c24565b935084156106185760075461061890879089906001600160a01b031688611c34565b83156106385760085461063890879089906001600160a01b031687611c34565b6106423389611cd5565b866001600160a01b03167f02f25270a4d87bea75db541cdfe559334a275b4a233520ed6c0a2429667cca9489878760405161067f93929190614993565b60405180910390a2600c54600160a01b900463ffffffff166001141561071f5760095460009081906106df90600281810b9163010000009004900b6106c2611b62565b6106ca611bf3565b600a546001600160a01b031693929190611dbf565b915091507f2fb985eb745b9e89bb1ab82e0f8ceb6bf94d4d60aed7e8196540c50161a5fe918282604051610714929190614985565b60405180910390a150505b5050600c805463ffffffff60c01b1916600160c01b179055509094909350915050565b60038054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156107ce5780601f106107a3576101008083540402835291602001916107ce565b820191906000526020600020905b8154815290600101906020018083116107b157829003601f168201915b505050505090505b90565b60006107ed6107e6611f21565b8484611f25565b5060015b92915050565b60025490565b600061080a848484612011565b61087a84610816611f21565b61087585604051806060016040528060288152602001614b34602891396001600160a01b038a16600090815260016020526040812090610854611f21565b6001600160a01b03168152602081019190915260400160002054919061215a565b611f25565b5060015b9392505050565b60055460ff1690565b60006108986121f1565b905090565b60006107ed6108aa611f21565b8461087585600160006108bb611f21565b6001600160a01b03908116825260208083019390935260409182016000908120918c1681529252902054906122bb565b60006108f5612313565b505050509050806001600160a01b0316336001600160a01b03161461091957600080fd5b506001600160a01b03166000908152600d60205260409020805460ff19811660ff90911615179055565b336000908152600d602052604090205460ff1661095f57600080fd5b600b5460405163c683630d60e01b81526001600160a01b039091169063c683630d9061098f908490600401614884565b60206040518083038186803b1580156109a757600080fd5b505afa1580156109bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109df9190614739565b6109e857600080fd5b600954600a54600091829182918291610a1c916001600160a01b0390911690600281810b9163010000009004900b886123b2565b9350935093509350306001600160a01b0316856001600160a01b031614610a7657600754610a5c906001600160a01b03163087610a57611b62565b612566565b600854610a76906001600160a01b03163087610a57611bf3565b600c805463ffffffff60a01b1916600160a11b1790556040517f0b807fda608508350274d5da730325b52bb86f7ba43085d327059ed4b2fc840490610ac29086908690869086906149a9565b60405180910390a15050505050565b6001600160a01b0381166000908152600d602052604090205460ff165b919050565b6001600160a01b031660009081526020819052604090205490565b6001600160a01b03811660009081526006602052604081206107f1906126a3565b600754600854600a546001600160a01b039283169383831693600160a01b90930462ffffff169290911690565b6000806000600c60189054906101000a900463ffffffff1663ffffffff16600114610b8657600080fd5b600c805463ffffffff60c01b1916600160c11b1790558515801590610bab5750600085115b610bb457600080fd5b6000610bbe611f21565b9050610c4860018888610bcf611b62565b610bd7611bf3565b610bdf6107f7565b60408051608081018252600954600281810b810b810b835263010000008204810b810b810b6020840152600160301b8204810b810b810b93830193909352600160481b9004820b820b90910b6060820152600a546001600160a01b0316969594939291906126a7565b6007549296509094509250610c68906001600160a01b0316823086612566565b600854610c80906001600160a01b0316823085612566565b600c54600160a01b900463ffffffff1660011415610cc757600954600a54610cc4916001600160a01b0390911690600281810b9163010000009004900b8686611dbf565b50505b4715610cd757610cd73347612743565b610ce18585612837565b846001600160a01b0316816001600160a01b03167f4e2ca0515ed1aef1395f66b5303bb5d6f1bf9d61a353fa53f73f8ac9973fa9f6858588604051610d2893929190614993565b60405180910390a350600c805463ffffffff60c01b1916600160c01b17905591959094509092509050565b60048054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156107ce5780601f106107a3576101008083540402835291602001916107ce565b60006107ed610dc1611f21565b8461087585604051806060016040528060258152602001614be66025913960016000610deb611f21565b6001600160a01b03908116825260208083019390935260409182016000908120918d1681529252902054919061215a565b60006107ed610e29611f21565b8484612011565b600954600281810b9163010000008104820b91600160301b8204810b91600160481b9004900b84565b60408051608081018252600954600281810b810b810b835263010000008204810b810b810b6020840152600160301b8204810b810b810b93830193909352600160481b9004820b820b90910b6060820152600a5460009182918291829182918291610ed2916001600160a01b0390911690600190612915565b949b939a50919850965094509092509050565b610eed6129ac565b336000610efc8385018561457a565b90508515610f1c57600754610f1c906001600160a01b0316828489612566565b8415610f3a57600854610f3a906001600160a01b0316828488612566565b505050505050565b83421115610f97576040805162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e65000000604482015290519081900360640190fd5b6001600160a01b03871660009081526006602052604081207f000000000000000000000000000000000000000000000000000000000000000090899089908990610fe0906126a3565b8960405160200180878152602001866001600160a01b03168152602001856001600160a01b0316815260200184815260200183815260200182815260200196505050505050506040516020818303038152906040528051906020012090506000611049826129c5565b9050600061105982878787612a11565b9050896001600160a01b0316816001600160a01b0316146110c1576040805162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e61747572650000604482015290519081900360640190fd5b6001600160a01b038a1660009081526006602052604090206110e290612b82565b6110ed8a8a8a611f25565b50505050505050505050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b600061112e612313565b505050509050806001600160a01b0316336001600160a01b03161461115257600080fd5b600c54600160e01b900463ffffffff1660011461116e57600080fd5b600c80546001600160e01b0316600160e11b179055600854600160b81b900460020b600061119a612b8b565b600a5490830291506000906111b7906001600160a01b0316612c24565b5091505060006111c78285612ca6565b6009805462ffffff1916858303600290810b62ffffff9081169290921765ffffff00000019166301000000858901830b93909316830217928390559293506112189282810b9291909104900b612cf2565b5050505050565b336000908152600d602052604090205460ff1661123b57600080fd5b600c805463ffffffff60a01b1916600160a01b179055600954600a546000918291611281916001600160a01b0390911690600281810b9163010000009004900b306123b2565b93509350505061129360018383611ac9565b600061129d612b8b565b600854600160b81b900460020b90810291506112da9082906112bd611b62565b6112c5611bf3565b600a546001600160a01b031693929190612dbb565b60098054600293840b62ffffff90811662ffffff199490950b1663010000000265ffffff000000199091161791909116919091179055505050565b336000908152600d602052604090205460ff1661133157600080fd5b600061133b612313565b5050600a5460405163051bb83360e01b81529294506001600160a01b03808616945063051bb833936113739350911690600401614884565b60006040518083038186803b15801561138b57600080fd5b505afa15801561139f573d6000803e3d6000fd5b5050600c805463ffffffff60a01b1916600160a01b179055506113c2905061449f565b600954600a546000916113ed916001600160a01b031690600281810b9163010000009004900b612de6565b5050600954600a5491925061141b916001600160a01b031690600281810b9163010000009004900b306123b2565b6020860181905281865260c086019290925260a085019290925261144191600191611ac9565b600061144b612b8b565b600854600a54600160b81b90910460020b919091029150611474906001600160a01b0316612c24565b50600290810b810b6040860181905260085461149d935090918491600160b81b9004900b612e84565b600290810b810b608086015290810b900b60608401526001600160801b038216158015906114d9575060a083015115806114d9575060c0830151155b15611547576000808460a00151116114f25760006114f5565b60015b90506000816115145761150f8560c0015160326064611786565b611525565b6115258560a0015160326064611786565b600a54909150611540906001600160a01b0316308484612ea1565b505061166b565b61154f611b62565b60a084015261155c611bf3565b60c0840181905260a084015160608501516080860151600a5461158d946001600160a01b039091169392909161301d565b6001600160801b031660e0840181905260608401516080850151600a546115c1936001600160a01b039091169290916130b1565b6101208501819052610100850182905260a085015160c08601516115e9939192909190613148565b151561014084018190526116245761161f6116168461012001518560c00151611be390919063ffffffff16565b60326064611786565b611643565b6116436116168461010001518560a00151611be390919063ffffffff16565b6101608401819052610140840151600a5461166b926001600160a01b03909116913091612ea1565b611673611b62565b60a0840152611680611bf3565b60c0840181905260a0840151600854600a546116b4936001600160a01b0390911692918590600160b81b900460020b613183565b6009805465ffffff00000019166301000000600293840b62ffffff90811682029290921762ffffff191694840b91909116939093179081905560a086015160c0870151600a54610f3a956001600160a01b039091169484810b9491909104900b9190611dbf565b6117236129ac565b60008413806117325750600083135b61173b57600080fd5b60006117498284018461471d565b9050801561176e57600754611769906001600160a01b0316303388612566565b611218565b600854611218906001600160a01b0316303387612566565b60008080600019858709868602925082811090839003039050806117bc57600084116117b157600080fd5b50829004905061087e565b8084116117c857600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b6000808061184d6001600160a01b0389168888612de6565b50509050600061186f826001600160801b031687670de0b6b3a7640000611786565b9050886001600160a01b031663a34123a7898961188b8561338b565b6040518463ffffffff1660e01b8152600401808460020b81526020018360020b8152602001826001600160801b0316815260200193505050506040805180830381600087803b1580156118dd57600080fd5b505af11580156118f1573d6000803e3d6000fd5b505050506040513d604081101561190757600080fd5b5080516020909101519094509250831515806119235750600083115b156119f657886001600160a01b0316634f1eb3d8868a8a6119438961338b565b61194c8961338b565b6040518663ffffffff1660e01b815260040180866001600160a01b031681526020018560020b81526020018460020b8152602001836001600160801b03168152602001826001600160801b03168152602001955050505050506040805180830381600087803b1580156119be57600080fd5b505af11580156119d2573d6000803e3d6000fd5b505050506040513d60408110156119e857600080fd5b50516001600160801b031693505b50509550959350505050565b600080611a108685856133d3565b50604080516309e3d67b60e31b81526001600160a01b038781166004830152600287810b602484015286900b60448301526001600160801b03606483018190526084830152825190891692634f1eb3d89260a480820193918290030181600087803b158015611a7e57600080fd5b505af1158015611a92573d6000803e3d6000fd5b505050506040513d6040811015611aa857600080fd5b5080516020909101516001600160801b039182169891169650945050505050565b600080611ad4612313565b509350935050506000841115611b0957600754611b09906001600160a01b031683611b048760ff86166064611786565b61348c565b8215611b2f57600854611b2f906001600160a01b031683611b048660ff86166064611786565b7ff8994d9c768d599c5c6e92d52cd9cc24762cd773384c7a4612796773c56a86a6858585604051610ac2939291906148ec565b6007546040516370a0823160e01b81526000916001600160a01b0316906370a0823190611b93903090600401614884565b60206040518083038186803b158015611bab57600080fd5b505afa158015611bbf573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061089891906147c6565b808203828111156107f157600080fd5b6008546040516370a0823160e01b81526000916001600160a01b0316906370a0823190611b93903090600401614884565b808201828110156107f157600080fd5b838015611c4e5750600c546001600160a01b038381169116145b15611cc457600c54604051632e1a7d4d60e01b81526001600160a01b0390911690632e1a7d4d90611c83908490600401614904565b600060405180830381600087803b158015611c9d57600080fd5b505af1158015611cb1573d6000803e3d6000fd5b50505050611cbf8382612743565b611ccf565b611ccf82848361348c565b50505050565b6001600160a01b038216611d1a5760405162461bcd60e51b8152600401808060200182810382526021815260200180614b7c6021913960400191505060405180910390fd5b611d2682600083612832565b611d6381604051806060016040528060228152602001614a5f602291396001600160a01b038516600090815260208190526040902054919061215a565b6001600160a01b038316600090815260208190526040902055600254611d8990826135d3565b6002556040805182815290516000916001600160a01b03851691600080516020614b5c8339815191529181900360200190a35050565b60008080611dd96001600160a01b03891686868a8a61301d565b90506001600160801b03811615611f16576040805130602080830182905283518084038201815283850194859052633c8a7d8d60e01b9094526044830182815260028c810b60648601528b900b60848501526001600160801b03861660a485015260a060c48501908152855160e486015285516001600160a01b038f1696633c8a7d8d968f958f958b959394909392610104019185019080838360005b83811015611e8e578181015183820152602001611e76565b50505050905090810190601f168015611ebb5780820380516001836020036101000a031916815260200191505b5096505050505050506040805180830381600087803b158015611edd57600080fd5b505af1158015611ef1573d6000803e3d6000fd5b505050506040513d6040811015611f0757600080fd5b50805160209091015190935091505b509550959350505050565b3390565b6001600160a01b038316611f6a5760405162461bcd60e51b8152600401808060200182810382526024815260200180614bc26024913960400191505060405180910390fd5b6001600160a01b038216611faf5760405162461bcd60e51b8152600401808060200182810382526022815260200180614a816022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b0383166120565760405162461bcd60e51b8152600401808060200182810382526025815260200180614b9d6025913960400191505060405180910390fd5b6001600160a01b03821661209b5760405162461bcd60e51b8152600401808060200182810382526023815260200180614a3c6023913960400191505060405180910390fd5b6120a6838383612832565b6120e381604051806060016040528060268152602001614aa3602691396001600160a01b038616600090815260208190526040902054919061215a565b6001600160a01b03808516600090815260208190526040808220939093559084168152205461211290826122bb565b6001600160a01b03808416600081815260208181526040918290209490945580518581529051919392871692600080516020614b5c83398151915292918290030190a3505050565b600081848411156121e95760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156121ae578181015183820152602001612196565b50505050905090810190601f1680156121db5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b60007f000000000000000000000000000000000000000000000000000000000000000061221c613630565b141561224957507f00000000000000000000000000000000000000000000000000000000000000006107d6565b6122b47f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000613634565b90506107d6565b60008282018381101561087e576040805162461bcd60e51b815260206004820152601b60248201527a536166654d6174683a206164646974696f6e206f766572666c6f7760281b604482015290519081900360640190fd5b6000806000806000600b60009054906101000a90046001600160a01b03166001600160a01b03166338d772806040518163ffffffff1660e01b815260040160a06040518083038186803b15801561236957600080fd5b505afa15801561237d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123a191906145ce565b945094509450945094509091929394565b6000808080806123cc6001600160a01b038a168989612de6565b50909150506001600160801b0381161561255a576040805163a34123a760e01b815260028a810b600483015289900b60248201526001600160801b038316604482015281516001600160a01b038c169263a34123a792606480820193918290030181600087803b15801561243f57600080fd5b505af1158015612453573d6000803e3d6000fd5b505050506040513d604081101561246957600080fd5b5080516020909101519095509350841515806124855750600084115b1561255a57604080516309e3d67b60e31b81526001600160a01b03888116600483015260028b810b60248401528a900b60448301526001600160801b0360648301819052608483015282516000938493928e1692634f1eb3d89260a4808301939282900301818787803b1580156124fb57600080fd5b505af115801561250f573d6000803e3d6000fd5b505050506040513d604081101561252557600080fd5b5080516020909101516001600160801b0391821693501690506125488288611be3565b6125528288611be3565b909550935050505b50945094509450949050565b600c546001600160a01b0385811691161480156125835750804710155b1561267b57600c60009054906101000a90046001600160a01b03166001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b1580156125d857600080fd5b505af11580156125ec573d6000803e3d6000fd5b5050600c5460405163a9059cbb60e01b81526001600160a01b03909116935063a9059cbb92506126239150859085906004016148c8565b602060405180830381600087803b15801561263d57600080fd5b505af1158015612651573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126759190614739565b50611ccf565b6001600160a01b03831630141561269757611cbf84838361348c565b611ccf84848484613696565b5490565b60008060008060008060006126bd8f8f8a612915565b5050935093509350935060006126e68c6126e08588611c2490919063ffffffff16565b90611c24565b905060006126f88c6126e08786611c24565b90508a158061270657508115155b8061271057508015155b61271657fe5b6127238f8f84848f6137e6565b809950819a50829b50505050505050505050985098509895505050505050565b604080516000808252602082019092526001600160a01b0384169083906040518082805190602001908083835b6020831061278f5780518252601f199092019160209182019101612770565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d80600081146127f1576040519150601f19603f3d011682016040523d82523d6000602084013e6127f6565b606091505b5050905080612832576040805162461bcd60e51b815260206004820152600360248201526253544560e81b604482015290519081900360640190fd5b505050565b6001600160a01b038216612892576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b61289e60008383612832565b6002546128ab90826122bb565b6002556001600160a01b0382166000908152602081905260409020546128d190826122bb565b6001600160a01b038316600081815260208181526040808320949094558351858152935192939192600080516020614b5c8339815191529281900390910190a35050565b600080600080600080612931898860000151896020015161387a565b939950919750955093509150876129a057600080600080600061295d8e8d604001518e6060015161387a565b9398509196509450925090506129738b86611c24565b9a5061297f8a85611c24565b995061298b8984611c24565b98506129978883611c24565b97509450505050505b93975093979195509350565b600a546001600160a01b031633146129c357600080fd5b565b60006129cf6121f1565b82604051602001808061190160f01b81525060020183815260200182815260200192505050604051602081830303815290604052805190602001209050919050565b60006fa2a8918ca85bafe22016d0b997e4df60600160ff1b03821115612a685760405162461bcd60e51b8152600401808060200182810382526022815260200180614af06022913960400191505060405180910390fd5b8360ff16601b1480612a7d57508360ff16601c145b612ab85760405162461bcd60e51b8152600401808060200182810382526022815260200180614b126022913960400191505060405180910390fd5b600060018686868660405160008152602001604052604051808581526020018460ff1681526020018381526020018281526020019450505050506020604051602081039080840390855afa158015612b14573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116612b77576040805162461bcd60e51b815260206004820152601860248201527745434453413a20696e76616c6964207369676e617475726560401b604482015290519081900360640190fd5b90505b949350505050565b80546001019055565b600080612b96612313565b5050600a54604051630737687360e21b81529294506001600160a01b038086169450631cdda1cc93612bce9350911690600401614884565b60206040518083038186803b158015612be657600080fd5b505afa158015612bfa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c1e9190614755565b91505090565b6000806000836001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e06040518083038186803b158015612c6257600080fd5b505afa158015612c76573d6000803e3d6000fd5b505050506040513d60e0811015612c8c57600080fd5b508051602082015160609092015190969195509350915050565b6000808260020b8460020b81612cb857fe5b05905060008460020b128015612cdf57508260020b8460020b81612cd857fe5b0760020b15155b15612ce957600019015b90910292915050565b8060020b8260020b12612d32576040805162461bcd60e51b8152602060048201526003602482015262544c5560e81b604482015290519081900360640190fd5b620d89e719600283900b1215612d75576040805162461bcd60e51b8152602060048201526003602482015262544c4d60e81b604482015290519081900360640190fd5b620d89e8600282900b1315612db7576040805162461bcd60e51b815260206004820152600360248201526254554d60e81b604482015290519081900360640190fd5b5050565b600080612dd46001600160a01b03881685858989613183565b90925090506119f68783838787611dbf565b600080600080612df73087876138bf565b9050866001600160a01b031663514ea4bf826040518263ffffffff1660e01b81526004018082815260200191505060a06040518083038186803b158015612e3d57600080fd5b505afa158015612e51573d6000803e3d6000fd5b505050506040513d60a0811015612e6757600080fd5b508051606082015160809092015190999198509650945050505050565b6000806000612e938685612ca6565b858103979501955050505050565b6000612eb5856001600160a01b0316612c24565b505090506000620f42408261c350026001600160a01b031681612ed457fe5b049050600084612ee657818301612eea565b8183035b9050866001600160a01b031663128acb08878787858a6040516020018082151581526020019150506040516020818303038152906040526040518663ffffffff1660e01b815260040180866001600160a01b031681526020018515158152602001848152602001836001600160a01b0316815260200180602001828103825283818151815260200191508051906020019080838360005b83811015612f99578181015183820152602001612f81565b50505050905090810190601f168015612fc65780820380516001836020036101000a031916815260200191505b5096505050505050506040805180830381600087803b158015612fe857600080fd5b505af1158015612ffc573d6000803e3d6000fd5b505050506040513d604081101561301257600080fd5b505050505050505050565b600080866001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e06040518083038186803b15801561305957600080fd5b505afa15801561306d573d6000803e3d6000fd5b505050506040513d60e081101561308357600080fd5b505190506130a48161309486613910565b61309d86613910565b8989613c37565b9150505b95945050505050565b6000806000866001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e06040518083038186803b1580156130ef57600080fd5b505afa158015613103573d6000803e3d6000fd5b505050506040513d60e081101561311957600080fd5b505190506131398161312a87613910565b61313387613910565b89613cf9565b92509250505b94509492505050565b600061315e856131588685611be3565b90613d94565b61316c856131588887611be3565b116131785760006130a8565b600195945050505050565b60008060006040518060e00160405280888152602001878152602001600081526020016000815260200160006001600160801b03168152602001600060020b8152602001600060020b8152509050600080896001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e06040518083038186803b15801561320d57600080fd5b505afa158015613221573d6000803e3d6000fd5b505050506040513d60e081101561323757600080fd5b5080516020909101519092509050613250818888612e84565b600290810b810b60c0860181905291810b900b60a085018190528451602086015161327d938e9390613db8565b606085018190526040850182905260a085015160c08601516132a4938e939092909161301d565b6001600160801b0316608084015282516020840151604085015160608601516000936132d39390929091613148565b905080156133185760006132f284866080015187600001516000613de7565b905061330661330082613ecf565b89612ca6565b600290810b900b60c08601525061334b565b600061332f848660800151876020015160006141ba565b905061333d61330082613ecf565b600290810b900b60a0860152505b61335d8460a001518560c00151612cf2565b61336b8460a0015188612ca6565b955061337b8460c0015188612ca6565b9450505050509550959350505050565b6000600160801b82106133cf5760405162461bcd60e51b8152600401808060200182810382526027815260200180614ac96027913960400191505060405180910390fd5b5090565b60006133e96001600160a01b0385168484612de6565b50909150506001600160801b0381161561087e57836001600160a01b031663a34123a7848460006040518463ffffffff1660e01b8152600401808460020b81526020018360020b815260200182815260200193505050506040805180830381600087803b15801561345957600080fd5b505af115801561346d573d6000803e3d6000fd5b505050506040513d604081101561348357600080fd5b50509392505050565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b1781529251825160009485949389169392918291908083835b602083106135085780518252601f1990920191602091820191016134e9565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d806000811461356a576040519150601f19603f3d011682016040523d82523d6000602084013e61356f565b606091505b509150915081801561359d57508051158061359d575080806020019051602081101561359a57600080fd5b50515b611218576040805162461bcd60e51b815260206004820152600260248201526114d560f21b604482015290519081900360640190fd5b60008282111561362a576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b4690565b6000838383613641613630565b3060405160200180868152602001858152602001848152602001838152602001826001600160a01b03168152602001955050505050506040516020818303038152906040528051906020012090509392505050565b604080516001600160a01b0385811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180516001600160e01b03166323b872dd60e01b178152925182516000948594938a169392918291908083835b6020831061371a5780518252601f1990920191602091820191016136fb565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d806000811461377c576040519150601f19603f3d011682016040523d82523d6000602084013e613781565b606091505b50915091508180156137af5750805115806137af57508080602001905160208110156137ac57600080fd5b50515b610f3a576040805162461bcd60e51b815260206004820152600360248201526229aa2360e91b604482015290519081900360640190fd5b600080808361380a5750869050858082116138015780613803565b815b925061386f565b8561381c575085613803818587611786565b8461382f57879150613803828588611786565b61383a878787611786565b915087821015613851575085613803818587611786565b87915061385f828688611786565b905061386c828588611786565b92505b955095509592505050565b600080600080600061388d8888886133d3565b90506001600160801b038116156138b4576138a9888888614296565b929750909550935091505b939792965093509350565b6040805160609490941b6001600160601b031916602080860191909152600293840b60e890811b60348701529290930b90911b60378401528051808403601a018152603a9093019052815191012090565b60008060008360020b12613927578260020b61392f565b8260020b6000035b9050620d89e881111561396d576040805162461bcd60e51b81526020600482015260016024820152601560fa1b604482015290519081900360640190fd5b60006001821661398157600160801b613993565b6ffffcb933bd6fad37aa2d162d1a5940015b6001600160881b0316905060028216156139bd576ffff97272373d413259a46990580e213a0260801c5b60048216156139dc576ffff2e50f5f656932ef12357cf3c7fdcc0260801c5b60088216156139fb576fffe5caca7e10e4e61c3624eaa0941cd00260801c5b6010821615613a1a576fffcb9843d60f6159c9db58835c9266440260801c5b6020821615613a39576fff973b41fa98c081472e6896dfb254c00260801c5b6040821615613a58576fff2ea16466c96a3843ec78b326b528610260801c5b6080821615613a77576ffe5dee046a99a2a811c461f1969c30530260801c5b610100821615613a97576ffcbe86c7900a88aedcffc83b479aa3a40260801c5b610200821615613ab7576ff987a7253ac413176f2b074cf7815e540260801c5b610400821615613ad7576ff3392b0822b70005940c7a398e4b70f30260801c5b610800821615613af7576fe7159475a2c29b7443b29c7fa6e889d90260801c5b611000821615613b17576fd097f3bdfd2022b8845ad8f792aa58250260801c5b612000821615613b37576fa9f746462d870fdf8a65dc1f90e061e50260801c5b614000821615613b57576f70d869a156d2a1b890bb3df62baf32f70260801c5b618000821615613b77576f31be135f97d08fd981231505542fcfa60260801c5b62010000821615613b98576f09aa508b5b7a84e1c677de54f3e99bc90260801c5b62020000821615613bb8576e5d6af8dedb81196699c329225ee6040260801c5b62040000821615613bd7576d2216e584f5fa1ea926041bedfe980260801c5b62080000821615613bf4576b048a170391f7dc42444e8fa20260801c5b60008460020b1315613c0f578060001981613c0b57fe5b0490505b600160201b810615613c22576001613c25565b60005b60ff16602082901c0192505050919050565b6000836001600160a01b0316856001600160a01b03161115613c57579293925b846001600160a01b0316866001600160a01b031611613c8257613c7b8585856142e2565b90506130a8565b836001600160a01b0316866001600160a01b03161015613ce4576000613ca98786866142e2565b90506000613cb8878986614345565b9050806001600160801b0316826001600160801b031610613cd95780613cdb565b815b925050506130a8565b613cef858584614345565b9695505050505050565b600080836001600160a01b0316856001600160a01b03161115613d1a579293925b846001600160a01b0316866001600160a01b031611613d4557613d3e858585614382565b915061313f565b836001600160a01b0316866001600160a01b03161015613d7e57613d6a868585614382565b9150613d778587856143eb565b905061313f565b613d898585856143eb565b905094509492505050565b6000821580613daf57505081810281838281613dac57fe5b04145b6107f157600080fd5b6000806000613dca888888888861301d565b9050613dd8888287876130b1565b90999098509650505050505050565b600082613df5575083612b7a565b600160601b600160e01b03606085901b168215613e83576001600160a01b03861684810290858281613e2357fe5b041415613e5457818101828110613e5257613e4883896001600160a01b03168361442e565b9350505050612b7a565b505b613e7a82613e75878a6001600160a01b03168681613e6e57fe5b0490611c24565b614468565b92505050612b7a565b6001600160a01b03861684810290858281613e9a57fe5b04148015613ea757508082115b613eb057600080fd5b808203613e48613eca846001600160a01b038b168461442e565b614473565b60006401000276a36001600160a01b03831610801590613f0b575073fffd8963efd1fc6a506488495d951d5263988d266001600160a01b038316105b613f40576040805162461bcd60e51b81526020600482015260016024820152602960f91b604482015290519081900360640190fd5b600160201b600160c01b03602083901b166001600160801b03811160071b81811c6001600160401b03811160061b90811c63ffffffff811160051b90811c61ffff811160041b90811c60ff8111600390811b91821c600f811160021b90811c918211600190811b92831c97908811961790941790921717909117171760808110613fd257607f810383901c9150613fdc565b80607f0383901b91505b908002607f81811c60ff83811c9190911c800280831c81831c1c800280841c81841c1c800280851c81851c1c800280861c81861c1c800280871c81871c1c800280881c81881c1c800280891c81891c1c8002808a1c818a1c1c8002808b1c818b1c1c8002808c1c818c1c1c8002808d1c818d1c1c8002808e1c9c81901c9c909c1c80029c8d901c9e9d607f198f0160401b60c09190911c6001603f1b161760c19b909b1c6001603e1b169a909a1760c29990991c6001603d1b169890981760c39790971c6001603c1b169690961760c49590951c6001603b1b169490941760c59390931c6001603a1b169290921760c69190911c600160391b161760c79190911c600160381b161760c89190911c600160371b161760c99190911c600160361b161760ca9190911c600160351b161760cb9190911c600160341b161760cc9190911c600160331b161760cd9190911c600160321b1617693627a301d71055774c8581026f028f6481ab7f045a5af012a19d003aa9198101608090811d906fdb2df09e81959a81455e260799a0632f8301901d600281810b9083900b146141ab57886001600160a01b031661418f82613910565b6001600160a01b031611156141a457816141a6565b805b6141ad565b815b9998505050505050505050565b600081156142285760006001600160a01b038411156141f0576141eb84600160601b876001600160801b0316611786565b614208565b6001600160801b038516606085901b8161420657fe5b045b9050614220613eca6001600160a01b03881683611c24565b915050612b7a565b60006001600160a01b038411156142565761425184600160601b876001600160801b031661442e565b61426d565b61426d606085901b6001600160801b038716614468565b905080866001600160a01b03161161428457600080fd5b6001600160a01b038616039050612b7a565b60008060008060008060006142ac8a8a8a612de6565b9250925092506000806142c18c868d8d6130b1565b9099509750506001600160801b039283169550501691505093509350935093565b6000826001600160a01b0316846001600160a01b03161115614302579192915b6000614325856001600160a01b0316856001600160a01b0316600160601b611786565b90506130a861434084838888036001600160a01b0316611786565b614489565b6000826001600160a01b0316846001600160a01b03161115614365579192915b612b7a61434083600160601b8787036001600160a01b0316611786565b6000826001600160a01b0316846001600160a01b031611156143a2579192915b836001600160a01b03166143db606060ff16846001600160801b0316901b8686036001600160a01b0316866001600160a01b0316611786565b816143e257fe5b04949350505050565b6000826001600160a01b0316846001600160a01b0316111561440b579192915b612b7a826001600160801b03168585036001600160a01b0316600160601b611786565b600061443b848484611786565b90506000828061444757fe5b848609111561087e57600019811061445e57600080fd5b6001019392505050565b808204910615150190565b806001600160a01b0381168114610aee57600080fd5b806001600160801b0381168114610aee57600080fd5b604051806101c001604052806000815260200160008152602001600060020b8152602001600060020b8152602001600060020b8152602001600081526020016000815260200160006001600160801b0316815260200160008152602001600081526020016000151581526020016000815260200160006001600160a01b0316815260200160006001600160a01b031681525090565b60008083601f840112614545578182fd5b5081356001600160401b0381111561455b578182fd5b60208301915083602082850101111561457357600080fd5b9250929050565b60006020828403121561458b578081fd5b813561087e81614a06565b600080604083850312156145a8578081fd5b82356145b381614a06565b915060208301356145c381614a06565b809150509250929050565b600080600080600060a086880312156145e5578081fd5b85516145f081614a06565b602087015190955061460181614a06565b604087015190945061461281614a06565b606087015190935061462381614a2c565b608087015190925061463481614a2c565b809150509295509295909350565b600080600060608486031215614656578283fd5b833561466181614a06565b9250602084013561467181614a06565b929592945050506040919091013590565b600080600080600080600060e0888a03121561469c578182fd5b87356146a781614a06565b965060208801356146b781614a06565b9550604088013594506060880135935060808801356146d581614a2c565b9699959850939692959460a0840135945060c09093013592915050565b60008060408385031215614704578182fd5b823561470f81614a06565b946020939093013593505050565b60006020828403121561472e578081fd5b813561087e81614a1e565b60006020828403121561474a578081fd5b815161087e81614a1e565b600060208284031215614766578081fd5b81518060020b811461087e578182fd5b6000806000806060858703121561478b578081fd5b843593506020850135925060408501356001600160401b038111156147ae578182fd5b6147ba87828801614534565b95989497509550505050565b6000602082840312156147d7578081fd5b5051919050565b6000806000606084860312156147f2578081fd5b83359250602084013561480481614a06565b9150604084013561481481614a1e565b809150509250925092565b600080600060608486031215614833578081fd5b8335925060208401359150604084013561481481614a06565b60008060008060608587031215614861578182fd5b843593506020850135925060408501356001600160401b038111156147ae578283fd5b6001600160a01b0391909116815260200190565b6001600160a01b039485168152928416602084015262ffffff919091166040830152909116606082015260800190565b6001600160a01b03929092168252602082015260400190565b901515815260200190565b92151583526020830191909152604082015260600190565b90815260200190565b600294850b815292840b602084015290830b604083015290910b606082015260800190565b6000602080835283518082850152825b8181101561495e57858101830151858201604001528201614942565b8181111561496f5783604083870101525b50601f01601f1916929092016040019392505050565b918252602082015260400190565b9283526020830191909152604082015260600190565b93845260208401929092526040830152606082015260800190565b9586526020860194909452604085019290925260608401526001600160801b0390811660808401521660a082015260c00190565b60ff91909116815260200190565b6001600160a01b0381168114614a1b57600080fd5b50565b8015158114614a1b57600080fd5b60ff81168114614a1b57600080fdfe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e636545524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636553616665436173743a2076616c756520646f65736e27742066697420696e20313238206269747345434453413a20696e76616c6964207369676e6174757265202773272076616c756545434453413a20696e76616c6964207369676e6174757265202776272076616c756545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef45524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa164736f6c6343000706000aa164736f6c6343000706000a

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

0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f9840000000000000000000000001e3881227010c8dcdfa2f11833d3d70a00893f94000000000000000000000000b7f7c5cea2b8b6138ea3f669b2094b27de2ec8d400000000000000000000000095477f96f78ec38916b5457030387d844e886ab3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000a

-----Decoded View---------------
Arg [0] : _uniswapFactory (address): 0x1F98431c8aD98523631AE4a59f267346ea31F984
Arg [1] : _governance (address): 0x1E3881227010c8DcDFa2F11833D3d70A00893f94
Arg [2] : _uniStrategy (address): 0xB7f7c5cea2b8b6138Ea3f669B2094B27dE2ec8d4
Arg [3] : _indexFund (address): 0x95477F96F78EC38916B5457030387D844E886ab3
Arg [4] : _WETH (address): 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
Arg [5] : percentage (uint8): 10

-----Encoded View---------------
6 Constructor Arguments found :
Arg [0] : 0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f984
Arg [1] : 0000000000000000000000001e3881227010c8dcdfa2f11833d3d70a00893f94
Arg [2] : 000000000000000000000000b7f7c5cea2b8b6138ea3f669b2094b27de2ec8d4
Arg [3] : 00000000000000000000000095477f96f78ec38916b5457030387d844e886ab3
Arg [4] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Arg [5] : 000000000000000000000000000000000000000000000000000000000000000a


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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