ETH Price: $2,680.55 (-0.55%)

Contract

0x15F5471803E9f0c56C969FffA0e240901F09583D
 
Transaction Hash
Method
Block
From
To
Mint205597472024-08-19 2:39:2340 days ago1724035163IN
0x15F54718...01F09583D
0 ETH0.000607011.12679156
Collect205596972024-08-19 2:29:1140 days ago1724034551IN
0x15F54718...01F09583D
0 ETH0.000239691.28101279
Collect205596922024-08-19 2:28:1140 days ago1724034491IN
0x15F54718...01F09583D
0 ETH0.000258591.38202903
Mint186100422023-11-20 2:32:47313 days ago1700447567IN
0x15F54718...01F09583D
0 ETH0.0100362318.62479949
Exact Input186100232023-11-20 2:28:59313 days ago1700447339IN
0x15F54718...01F09583D
0 ETH0.0033673920.16310194
Exact Input186100042023-11-20 2:25:11313 days ago1700447111IN
0x15F54718...01F09583D
0 ETH0.002836720.21809932
Multicall186099902023-11-20 2:22:11313 days ago1700446931IN
0x15F54718...01F09583D
0 ETH0.0051606721.55518947
Collect186099652023-11-20 2:16:59313 days ago1700446619IN
0x15F54718...01F09583D
0 ETH0.0041029721.92788319
Mint174681132023-06-13 2:28:47473 days ago1686623327IN
0x15F54718...01F09583D
0 ETH0.0074241315.13012044
Collect174481902023-06-10 7:07:23476 days ago1686380843IN
0x15F54718...01F09583D
0 ETH0.0047527823.2738005
Mint154602262022-09-02 16:32:11757 days ago1662136331IN
0x15F54718...01F09583D
0 ETH0.0092285816.73312986
Multicall154502582022-09-01 2:29:52758 days ago1661999392IN
0x15F54718...01F09583D
0 ETH0.0038614214.96780177
Mint152998672022-08-08 6:02:42782 days ago1659938562IN
0x15F54718...01F09583D
0 ETH0.0055206910.01156602
Exact Input152998492022-08-08 5:58:33782 days ago1659938313IN
0x15F54718...01F09583D
0 ETH0.0016177210.71674186
Multicall152998252022-08-08 5:52:32782 days ago1659937952IN
0x15F54718...01F09583D
0 ETH0.0026035210.53308734
Mint152510912022-07-31 15:36:07790 days ago1659281767IN
0x15F54718...01F09583D
0 ETH0.004505778.17270331
Multicall152510652022-07-31 15:30:50790 days ago1659281450IN
0x15F54718...01F09583D
0 ETH0.002017238.15815572
Mint151719712022-07-19 8:29:19802 days ago1658219359IN
0x15F54718...01F09583D
0 ETH0.0064596311.71191655
Multicall151719452022-07-19 8:24:31802 days ago1658219071IN
0x15F54718...01F09583D
0 ETH0.0034569313.51190264
Mint150394752022-06-28 11:40:43823 days ago1656416443IN
0x15F54718...01F09583D
0 ETH0.0126672721.25434768
Exact Output150394642022-06-28 11:37:44823 days ago1656416264IN
0x15F54718...01F09583D
0 ETH0.0035974522.45366908
Multicall150394452022-06-28 11:32:52823 days ago1656415972IN
0x15F54718...01F09583D
0 ETH0.0044470117.99042646
Mint149939772022-06-20 1:50:26831 days ago1655689826IN
0x15F54718...01F09583D
0 ETH0.0070842412.84895156
Exact Output149939552022-06-20 1:46:25831 days ago1655689585IN
0x15F54718...01F09583D
0 ETH0.003090719.28967423
Multicall149939192022-06-20 1:37:53831 days ago1655689073IN
0x15F54718...01F09583D
0 ETH0.0045955517.60592594
View all transactions

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Similar Match Source Code
This contract matches the deployed Bytecode of the Source Code for Contract 0x9DcD6310...8C1B9D642
The constructor portion of the code might be different and could alter the actual behaviour of the contract

Contract Name:
AutoLiquidity

Compiler Version
v0.7.6+commit.7338295f

Optimization Enabled:
Yes with 200 runs

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

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

import "../interfaces/IVault.sol";
import "../libraries/EnumerableSetExtends.sol";
import "../libraries/ERC20Extends.sol";
import "../libraries/UniV3PMExtends.sol";
import "../storage/SmartPoolStorage.sol";
import "./UniV3Liquidity.sol";

pragma abicoder v2;
/// @title Position Management
/// @notice Provide asset operation functions, allow authorized identities to perform asset operations, and achieve the purpose of increasing the net value of the Vault
contract AutoLiquidity is UniV3Liquidity, ReentrancyGuard {

    using SafeMath for uint256;
    using SafeERC20 for IERC20;
    using EnumerableSetExtends for EnumerableSetExtends.UintSet;
    using EnumerableSetExtends for EnumerableSetExtends.AddressSet;
    using UniV3SwapExtends for mapping(address => mapping(address => bytes));

    //Vault purchase and redemption token
    IERC20 public ioToken;
    //Vault contract address
    IVault public vault;
    //Underlying asset
    EnumerableSetExtends.AddressSet internal underlyings;

    event TakeFee(SmartPoolStorage.FeeType ft, address token, address rewards, uint256 fee);

    /// @notice Binding vaults and subscription redemption token
    /// @dev Only bind once and cannot be modified
    /// @param _vault Vault address
    /// @param _ioToken Subscription and redemption token
    function bind(address _vault, address _ioToken) external onlyGovernance {
        vault = IVault(_vault);
        ioToken = IERC20(_ioToken);
    }

    //Only allow vault contract access
    modifier onlyVault() {
        require(extAuthorize(), "!vault");
        _;
    }

    /// @notice ext authorize
    function extAuthorize() internal override view returns (bool){
        return msg.sender == address(vault);
    }

    /// @notice in work tokenId array
    /// @dev read in works NFT array
    /// @return tokenIds NFT array
    function worksPos() public view returns (uint256[] memory tokenIds){
        uint256 length = works.length();
        tokenIds = new uint256[](length);
        for (uint256 i = 0; i < length; i++) {
            tokenIds[i] = works.at(i);
        }
    }

    /// @notice in underlyings token address array
    /// @dev read in underlyings token address array
    /// @return tokens address array
    function getUnderlyings() public view returns (address[] memory tokens){
        uint256 length = underlyings.length();
        tokens = new address[](length);
        for (uint256 i = 0; i < underlyings.length(); i++) {
            tokens[i] = underlyings.at(i);
        }
    }


    /// @notice Set the underlying asset token address
    /// @dev Only allow the governance identity to set the underlying asset token address
    /// @param ts The underlying asset token address array to be added
    function setUnderlyings(address[] memory ts) public onlyGovernance {
        for (uint256 i = 0; i < ts.length; i++) {
            if (!underlyings.contains(ts[i])) {
                underlyings.add(ts[i]);
            }
        }
    }

    /// @notice Delete the underlying asset token address
    /// @dev Only allow the governance identity to delete the underlying asset token address
    /// @param ts The underlying asset token address array to be deleted
    function removeUnderlyings(address[] memory ts) public onlyGovernance {
        for (uint256 i = 0; i < ts.length; i++) {
            if (underlyings.contains(ts[i])) {
                underlyings.remove(ts[i]);
            }
        }
    }

    /// @notice swap after handle
    /// @param tokenOut token address
    /// @param amountOut token amount
    function swapAfter(
        address tokenOut,
        uint256 amountOut) internal override {
        uint256 fee = vault.calcRatioFee(SmartPoolStorage.FeeType.TURNOVER_FEE, amountOut);
        if (fee > 0) {
            address rewards = getRewards();
            IERC20(tokenOut).safeTransfer(rewards, fee);
            emit TakeFee(SmartPoolStorage.FeeType.TURNOVER_FEE, tokenOut, rewards, fee);
        }
    }

    /// @notice collect after handle
    /// @param token0 token address
    /// @param token1 token address
    /// @param amount0 token amount
    /// @param amount1 token amount
    function collectAfter(
        address token0,
        address token1,
        uint256 amount0,
        uint256 amount1) internal override {
        uint256 fee0 = vault.calcRatioFee(SmartPoolStorage.FeeType.TURNOVER_FEE, amount0);
        uint256 fee1 = vault.calcRatioFee(SmartPoolStorage.FeeType.TURNOVER_FEE, amount1);
        address rewards = getRewards();
        if (fee0 > 0) {
            IERC20(token0).safeTransfer(rewards, fee0);
            emit TakeFee(SmartPoolStorage.FeeType.TURNOVER_FEE, token0, rewards, fee0);
        }
        if (fee1 > 0) {
            IERC20(token1).safeTransfer(rewards, fee1);
            emit TakeFee(SmartPoolStorage.FeeType.TURNOVER_FEE, token1, rewards, fee1);
        }
    }

    /// @notice Asset transfer used to upgrade the contract
    /// @param to address
    function withdrawAll(address to) external onlyGovernance {
        for (uint256 i = 0; i < underlyings.length(); i++) {
            IERC20 token = IERC20(underlyings.at(i));
            uint256 balance = token.balanceOf(address(this));
            if (balance > 0) {
                token.safeTransfer(to, balance);
            }
        }
    }

    /// @notice Withdraw asset
    /// @dev Only vault contract can withdraw asset
    /// @param outputToken output token address
    /// @param to Withdraw address
    /// @param amount Withdraw amount
    /// @param scale Withdraw percentage
    function withdraw(address outputToken, address to, uint256 amount, uint256 scale) external nonReentrant onlyVault {
        IERC20 ot = IERC20(outputToken);
        uint256 surplusAmount = ot.balanceOf(address(this));
        if (surplusAmount < amount) {
            uint256[] memory underlyingAmounts = releaseUnderlying(scale);
            for (uint256 i = 0; i < underlyingAmounts.length; i++) {
                address token = underlyings.at(i);
                if (token != outputToken && underlyingAmounts[i] > 0) {
                    exactInput(token, outputToken, underlyingAmounts[i], 0);
                }
            }
        }
        surplusAmount = ot.balanceOf(address(this));
        if (surplusAmount < amount) {
            amount = surplusAmount;
        }
        ot.safeTransfer(to, amount);
    }

    /// @notice Withdraw underlying asset
    /// @dev Only vault contract can withdraw underlying asset
    /// @param to Withdraw address
    /// @param scale Withdraw percentage
    function withdrawOfUnderlying(address to, uint256 scale) external nonReentrant onlyVault {
        uint256[] memory underlyingAmounts = releaseUnderlying(scale);
        for (uint256 i = 0; i < underlyingAmounts.length; i++) {
            if(underlyingAmounts[i]>0){
                IERC20(underlyings.at(i)).safeTransfer(to, underlyingAmounts[i]);
            }
        }
    }

    /// @notice Calculate the number of assets
    /// @dev release liquidity by provided scale
    /// @param scale Scale of the liquidity
    function releaseUnderlying(uint256 scale) internal returns (uint256[] memory underlyingAmounts){
        uint256 length = underlyings.length();
        underlyingAmounts = new uint256[](length);
        uint256[] memory freeBalances = new uint256[](length);
        for (uint256 i = 0; i < length; i++) {
            address token = underlyings.at(i);
            uint256 balance = IERC20(token).balanceOf(address(this));
            freeBalances[i] = balance;
            underlyingAmounts[i] = balance.mul(scale).div(1e18);
        }
        uint256[] memory decreaseAmounts = _decreaseLiquidityByScale(scale);
        for (uint256 i = 0; i < length; i++) {
            address token = underlyings.at(i);
            uint256 balance = IERC20(token).balanceOf(address(this));
            uint256 feeAmount = balance.sub(freeBalances[i].add(decreaseAmounts[i]));
            underlyingAmounts[i] = underlyingAmounts[i].add(decreaseAmounts[i]).add(feeAmount.mul(scale).div(1e18));
        }
    }

    /// @notice Decrease liquidity by scale
    /// @dev Decrease liquidity by provided scale
    /// @param scale Scale of the liquidity
    function _decreaseLiquidityByScale(uint256 scale) internal returns (uint256[] memory decreaseAmounts){
        uint256 length = works.length();
        decreaseAmounts = new uint256[](underlyings.length());
        for (uint256 i = 0; i < length; i++) {
            uint256 tokenId = works.at(i);
            (
            ,
            ,
            address token0,
            address token1,
            ,
            ,
            ,
            uint128 liquidity,
            ,
            ,
            ,
            ) = UniV3PMExtends.PM.positions(tokenId);
            if (liquidity > 0) {
                uint256 _decreaseLiquidity = uint256(liquidity).mul(scale).div(1e18);
                (uint256 amount0, uint256 amount1) = decreaseLiquidity(tokenId, uint128(_decreaseLiquidity), 0, 0);
                uint256 token0Index = underlyings.indexOf(token0) - 1;
                uint256 token1Index = underlyings.indexOf(token1) - 1;
                decreaseAmounts[token0Index] = amount0.add(decreaseAmounts[token0Index]);
                decreaseAmounts[token1Index] = amount1.add(decreaseAmounts[token1Index]);
                collect(tokenId, type(uint128).max, type(uint128).max);
            }
        }
    }

    /// @notice Total asset
    /// @dev This function calculates the net worth or AUM
    /// @return Total asset
    function assets() public view returns (uint256){
        uint256 total = idleAssets();
        total = total.add(liquidityAssets());
        return total;
    }

    /// @notice idle asset
    /// @dev This function calculates idle asset
    /// @return idle asset
    function idleAssets() public view returns (uint256){
        uint256 total;
        for (uint256 i = 0; i < underlyings.length(); i++) {
            address token = underlyings.at(i);
            uint256 balance = IERC20(token).balanceOf(address(this));
            if (token == address(ioToken)) {
                total = total.add(balance);
            } else {
                uint256 _estimateAmountOut = estimateAmountOut(token, address(ioToken), balance);
                total = total.add(_estimateAmountOut);
            }
        }
        return total;
    }

    /// @notice at work liquidity asset
    /// @dev This function calculates liquidity asset
    /// @return liquidity asset
    function liquidityAssets() public view returns (uint256){
        uint256 total;
        address ioTokenAddr = address(ioToken);
        uint256 length = works.length();
        for (uint256 i = 0; i < length; i++) {
            uint256 tokenId = works.at(i);
            total = total.add(calcLiquidityAssets(tokenId, ioTokenAddr));
        }
        return total;
    }
}

File 2 of 30 : UniV3Liquidity.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "../base/GovIdentity.sol";
import "../interfaces/uniswap-v3/Path.sol";
import "../libraries/EnumerableSetExtends.sol";
import "../libraries/ERC20Extends.sol";
import "../libraries/UniV3SwapExtends.sol";
import "../libraries/UniV3PMExtends.sol";

pragma abicoder v2;
/// @title Position Management
/// @notice Provide asset operation functions, allow authorized identities to perform asset operations, and achieve the purpose of increasing the net value of the fund
contract UniV3Liquidity is GovIdentity {

    using SafeMath for uint256;
    using Path for bytes;
    using EnumerableSetExtends for EnumerableSetExtends.UintSet;
    using UniV3SwapExtends for mapping(address => mapping(address => bytes));

    //Swap route
    mapping(address => mapping(address => bytes)) public swapRoute;
    //Position list
    mapping(bytes32 => uint256) public history;
    //position mapping owner
    mapping(uint256 => address) public positionOwners;
    //available token limit
    mapping(address => mapping(address => uint256)) public tokenLimit;
    //Working positions
    EnumerableSetExtends.UintSet internal works;

    //Swap
    event Swap(address sender, address fromToken, address toToken, uint256 amountIn, uint256 amountOut);
    //Create positoin
    event Mint(address sender, uint256 tokenId, uint128 liquidity);
    //Increase liquidity
    event IncreaseLiquidity(address sender, uint256 tokenId, uint128 liquidity);
    //Decrease liquidity
    event DecreaseLiquidity(address sender, uint256 tokenId, uint128 liquidity);
    //Collect asset
    event Collect(address sender, uint256 tokenId, uint256 amount0, uint256 amount1);

    //Only allow governance, strategy, ext authorize
    modifier onlyAssetsManager() {
        require(
            msg.sender == getGovernance()
            || isAdmin(msg.sender)
            || isStrategist(msg.sender)
            || extAuthorize(), "!AM");
        _;
    }

    //Only position owner
    modifier onlyPositionManager(uint256 tokenId) {
        require(
            msg.sender == getGovernance()
            || isAdmin(msg.sender)
            || positionOwners[tokenId] == msg.sender
            || extAuthorize(), "!PM");
        _;
    }



    /// @notice extend authorize
    function extAuthorize() internal virtual view returns (bool){
        return false;
    }


    /// @notice swap after handle
    function swapAfter(
        address,
        uint256) internal virtual {

    }

    /// @notice collect after handle
    function collectAfter(
        address,
        address,
        uint256,
        uint256) internal virtual {

    }

    /// @notice Check current position
    /// @dev Check the current UniV3 position by pool token ID.
    /// @param pool liquidity pool
    /// @param tickLower Tick lower bound
    /// @param tickUpper Tick upper bound
    /// @return atWork Position status
    /// @return has Check if the position ID exist
    /// @return tokenId Position ID
    function checkPos(
        address pool,
        int24 tickLower,
        int24 tickUpper
    ) public view returns (bool atWork, bool has, uint256 tokenId){
        bytes32 pk = UniV3PMExtends.positionKey(pool, tickLower, tickUpper);
        tokenId = history[pk];
        atWork = works.contains(tokenId);
        has = tokenId > 0 ? true : false;
    }

    /// @notice Update strategist's available token limit
    /// @param strategist strategist's
    /// @param token token address
    /// @param amount limit amount
    function setTokenLimit(address strategist, address token, int256 amount) public onlyAdminOrGovernance {
        if (amount > 0) {
            tokenLimit[strategist][token] += uint256(amount);
        } else {
            tokenLimit[strategist][token] -= uint256(amount);
        }
    }

    /// @notice Authorize UniV3 contract to move vault asset
    /// @dev Only allow governance and admin identities to execute authorized functions to reduce miner fee consumption
    /// @param token Authorized target token
    function safeApproveAll(address token) public virtual onlyAdminOrGovernance {
        ERC20Extends.safeApprove(token, address(UniV3PMExtends.PM), type(uint256).max);
        ERC20Extends.safeApprove(token, address(UniV3SwapExtends.SRT), type(uint256).max);
    }

    /// @notice Multiple functions of the contract can be executed at the same time
    /// @dev Only the assets manager identities are allowed to execute multiple function calls,
    /// and the execution of multiple functions can ensure the consistency of the execution results
    /// @param data Encode data of multiple execution functions
    /// @return results Execution result
    function multicall(bytes[] calldata data) external onlyAssetsManager returns (bytes[] memory results) {
        results = new bytes[](data.length);
        for (uint256 i = 0; i < data.length; i++) {
            (bool success, bytes memory result) = address(this).delegatecall(data[i]);
            if (!success) {
                if (result.length < 68) revert();
                assembly {
                    result := add(result, 0x04)
                }
                revert(abi.decode(result, (string)));
            }
            results[i] = result;
        }
    }


    /// @notice Set asset swap route
    /// @dev Only the governance and admin identity is allowed to set the asset swap path, and the firstToken and lastToken contained in the path will be used as the underlying asset token address by default
    /// @param path Swap path byte code
    function settingSwapRoute(bytes memory path) external onlyAdminOrGovernance {
        require(path.valid(), 'path is not valid');
        address fromToken = path.getFirstAddress();
        address toToken = path.getLastAddress();
        swapRoute[fromToken][toToken] = path;
    }

    /// @notice Estimated to obtain the target token amount
    /// @dev Only allow the asset transaction path that has been set to be estimated
    /// @param from Source token address
    /// @param to Target token address
    /// @param amountIn Source token amount
    /// @return amountOut Target token amount
    function estimateAmountOut(
        address from,
        address to,
        uint256 amountIn
    ) public view returns (uint256 amountOut){
        return swapRoute.estimateAmountOut(from, to, amountIn);
    }

    /// @notice Estimate the amount of source tokens that need to be provided
    /// @dev Only allow the governance identity to set the underlying asset token address
    /// @param from Source token address
    /// @param to Target token address
    /// @param amountOut Expect to get the target token amount
    /// @return amountIn Source token amount
    function estimateAmountIn(
        address from,
        address to,
        uint256 amountOut
    ) public view returns (uint256 amountIn){
        return swapRoute.estimateAmountIn(from, to, amountOut);
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another token
    /// @dev Initiate a transaction with a known input amount and return the output amount
    /// @param tokenIn Token in address
    /// @param tokenOut Token out address
    /// @param amountIn Token in amount
    /// @param amountOutMinimum Expected to get minimum token out amount
    /// @return amountOut Token out amount
    function exactInput(
        address tokenIn,
        address tokenOut,
        uint256 amountIn,
        uint256 amountOutMinimum
    ) public onlyAssetsManager returns (uint256 amountOut) {
        bool _isStrategist = isStrategist(msg.sender);
        if (_isStrategist) {
            require(tokenLimit[msg.sender][tokenIn] >= amountIn, '!check limit');
        }
        amountOut = swapRoute.exactInput(tokenIn, tokenOut, amountIn, address(this), amountOutMinimum);
        if (_isStrategist) {
            tokenLimit[msg.sender][tokenIn] -= amountIn;
            tokenLimit[msg.sender][tokenOut] += amountOut;
        }
        swapAfter(tokenOut, amountOut);
        emit Swap(msg.sender, tokenIn, tokenOut, amountIn, amountOut);
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another token
    /// @dev Initiate a transaction with a known output amount and return the input amount
    /// @param tokenIn Token in address
    /// @param tokenOut Token out address
    /// @param amountOut Token out amount
    /// @param amountInMaximum Expect to input the maximum amount of tokens
    /// @return amountIn Token in amount
    function exactOutput(
        address tokenIn,
        address tokenOut,
        uint256 amountOut,
        uint256 amountInMaximum
    ) public onlyAssetsManager returns (uint256 amountIn) {
        amountIn = swapRoute.exactOutput(tokenIn, tokenOut, address(this), amountOut, amountInMaximum);
        if (isStrategist(msg.sender)) {
            require(tokenLimit[msg.sender][tokenIn] >= amountIn, '!check limit');
            tokenLimit[msg.sender][tokenIn] -= amountIn;
            tokenLimit[msg.sender][tokenOut] += amountOut;
        }
        swapAfter(tokenOut, amountOut);
        emit Swap(msg.sender, tokenIn, tokenOut, amountIn, amountOut);
    }

    /// @notice Create position
    /// @dev Repeated creation of the same position will cause an error, you need to change tickLower Or tickUpper
    /// @param token0 Liquidity pool token 0 contract address
    /// @param token1 Liquidity pool token 1 contract address
    /// @param fee Target liquidity pool rate
    /// @param tickLower Expect to place the lower price boundary of the target liquidity pool
    /// @param tickUpper Expect to place the upper price boundary of the target liquidity pool
    /// @param amount0Desired Desired token 0 amount
    /// @param amount1Desired Desired token 1 amount
    function mint(
        address token0,
        address token1,
        uint24 fee,
        int24 tickLower,
        int24 tickUpper,
        uint256 amount0Desired,
        uint256 amount1Desired
    ) public onlyAssetsManager
    {
        bool _isStrategist = isStrategist(msg.sender);
        if (_isStrategist) {
            require(tokenLimit[msg.sender][token0] >= amount0Desired, '!check limit');
            require(tokenLimit[msg.sender][token1] >= amount1Desired, '!check limit');
        }
        (
        uint256 tokenId,
        uint128 liquidity,
        uint256 amount0,
        uint256 amount1
        ) = UniV3PMExtends.PM.mint(INonfungiblePositionManager.MintParams({
        token0 : token0,
        token1 : token1,
        fee : fee,
        tickLower : tickLower,
        tickUpper : tickUpper,
        amount0Desired : amount0Desired,
        amount1Desired : amount1Desired,
        amount0Min : 0,
        amount1Min : 0,
        recipient : address(this),
        deadline : block.timestamp
        }));
        if (_isStrategist) {
            tokenLimit[msg.sender][token0] -= amount0;
            tokenLimit[msg.sender][token1] -= amount1;
        }
        address pool = UniV3PMExtends.getPool(tokenId);
        bytes32 pk = UniV3PMExtends.positionKey(pool, tickLower, tickUpper);
        history[pk] = tokenId;
        positionOwners[tokenId] = msg.sender;
        works.add(tokenId);
        emit Mint(msg.sender, tokenId, liquidity);
    }

    /// @notice Increase liquidity
    /// @dev Use checkPos to check the position ID
    /// @param tokenId Position ID
    /// @param amount0 Desired Desired token 0 amount
    /// @param amount1 Desired Desired token 1 amount
    /// @param amount0Min Minimum token 0 amount
    /// @param amount1Min Minimum token 1 amount
    /// @return liquidity The amount of liquidity
    /// @return amount0 Actual token 0 amount being added
    /// @return amount1 Actual token 1 amount being added
    function increaseLiquidity(
        uint256 tokenId,
        uint256 amount0Desired,
        uint256 amount1Desired,
        uint256 amount0Min,
        uint256 amount1Min
    ) public onlyPositionManager(tokenId) returns (
        uint128 liquidity,
        uint256 amount0,
        uint256 amount1
    ){
        (
        ,
        ,
        address token0,
        address token1,
        ,
        ,
        ,
        ,
        ,
        ,
        ,

        ) = UniV3PMExtends.PM.positions(tokenId);
        address po = positionOwners[tokenId];
        if (isStrategist(po)) {
            require(tokenLimit[po][token0] >= amount0Desired, '!check limit');
            require(tokenLimit[po][token1] >= amount1Desired, '!check limit');
        }
        (liquidity, amount0, amount1) = UniV3PMExtends.PM.increaseLiquidity(INonfungiblePositionManager.IncreaseLiquidityParams({
        tokenId : tokenId,
        amount0Desired : amount0Desired,
        amount1Desired : amount1Desired,
        amount0Min : amount0Min,
        amount1Min : amount1Min,
        deadline : block.timestamp
        }));
        if (isStrategist(po)) {
            tokenLimit[po][token0] -= amount0;
            tokenLimit[po][token1] -= amount1;
        }
        if (!works.contains(tokenId)) {
            works.add(tokenId);
        }
        emit IncreaseLiquidity(msg.sender, tokenId, liquidity);
    }

    /// @notice Decrease liquidity
    /// @dev Use checkPos to query the position ID
    /// @param tokenId Position ID
    /// @param liquidity Expected reduction amount of liquidity
    /// @param amount0Min Minimum amount of token 0 to be reduced
    /// @param amount1Min Minimum amount of token 1 to be reduced
    /// @return amount0 Actual amount of token 0 being reduced
    /// @return amount1 Actual amount of token 1 being reduced
    function decreaseLiquidity(
        uint256 tokenId,
        uint128 liquidity,
        uint256 amount0Min,
        uint256 amount1Min
    ) public onlyPositionManager(tokenId) returns (uint256 amount0, uint256 amount1){
        (amount0, amount1) = UniV3PMExtends.PM.decreaseLiquidity(INonfungiblePositionManager.DecreaseLiquidityParams({
        tokenId : tokenId,
        liquidity : liquidity,
        amount0Min : amount0Min,
        amount1Min : amount1Min,
        deadline : block.timestamp
        }));
        emit DecreaseLiquidity(msg.sender, tokenId, liquidity);
    }

    /// @notice Collect position asset
    /// @dev Use checkPos to check the position ID
    /// @param tokenId Position ID
    /// @param amount0Max Maximum amount of token 0 to be collected
    /// @param amount1Max Maximum amount of token 1 to be collected
    /// @return amount0 Actual amount of token 0 being collected
    /// @return amount1 Actual amount of token 1 being collected
    function collect(
        uint256 tokenId,
        uint128 amount0Max,
        uint128 amount1Max
    ) public onlyPositionManager(tokenId) returns (uint256 amount0, uint256 amount1){
        (amount0, amount1) = UniV3PMExtends.PM.collect(INonfungiblePositionManager.CollectParams({
        tokenId : tokenId,
        recipient : address(this),
        amount0Max : amount0Max,
        amount1Max : amount1Max
        }));
        (
        ,
        ,
        address token0,
        address token1,
        ,
        ,
        ,
        uint128 liquidity,
        ,
        ,
        ,
        ) = UniV3PMExtends.PM.positions(tokenId);
        address po = positionOwners[tokenId];
        if (isStrategist(po)) {
            tokenLimit[po][token0] += amount0;
            tokenLimit[po][token1] += amount1;
        }
        if (liquidity == 0) {
            works.remove(tokenId);
        }
        collectAfter(token0, token1, amount0, amount1);
        emit Collect(msg.sender, tokenId, amount0, amount1);
    }

    /// @notice calc tokenId asset
    /// @dev This function calc tokenId asset
    /// @return tokenId asset
    function calcLiquidityAssets(uint256 tokenId, address toToken) internal view returns (uint256) {
        (
        ,
        ,
        address token0,
        address token1,
        uint24 fee,
        int24 tickLower,
        int24 tickUpper,
        uint128 liquidity,
        ,
        ,
        ,
        ) = UniV3PMExtends.PM.positions(tokenId);
        (uint256 amount0, uint256 amount1) = UniV3PMExtends.getAmountsForLiquidity(
            token0, token1, fee, tickLower, tickUpper, liquidity);
        (uint256 fee0, uint256 fee1) = UniV3PMExtends.getFeesForLiquidity(tokenId);
        (amount0, amount1) = (amount0.add(fee0), amount1.add(fee1));
        uint256 total;
        if (token0 == toToken) {
            total = amount0;
        } else {
            uint256 _estimateAmountOut = swapRoute.estimateAmountOut(token0, toToken, amount0);
            total = _estimateAmountOut;
        }
        if (token1 == toToken) {
            total = total.add(amount1);
        } else {
            uint256 _estimateAmountOut = swapRoute.estimateAmountOut(token1, toToken, amount1);
            total = total.add(_estimateAmountOut);
        }
        return total;
    }


}

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

library SmartPoolStorage {

    bytes32 public constant sSlot = keccak256("SmartPoolStorage.storage.location");

    struct Storage {
        mapping(FeeType => Fee) fees;
        mapping(address => uint256) nets;
        address token;
        address am;
        address weth;
        uint256 cap;
        uint256 lup;
        bool suspend;
        bool allowJoin;
        bool allowExit;
    }

    struct Fee {
        uint256 ratio;
        uint256 denominator;
        uint256 lastTimestamp;
        uint256 minLine;
    }

    enum FeeType{
        JOIN_FEE, EXIT_FEE, MANAGEMENT_FEE, PERFORMANCE_FEE,TURNOVER_FEE
    }

    function load() internal pure returns (Storage storage s) {
        bytes32 loc = sSlot;
        assembly {
            s.slot := loc
        }
    }
}

File 4 of 30 : UniV3PMExtends.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;

import "../interfaces/uniswap-v3/INonfungiblePositionManager.sol";
import "../interfaces/uniswap-v3/IUniswapV3Pool.sol";
import "../interfaces/uniswap-v3/TickMath.sol";
import "../interfaces/uniswap-v3/LiquidityAmounts.sol";
import "../interfaces/uniswap-v3/FixedPoint128.sol";
import "../interfaces/uniswap-v3/PoolAddress.sol";


/// @title UniV3 extends libraries
/// @notice libraries
library UniV3PMExtends {

    //Nonfungible Position Manager
    INonfungiblePositionManager constant internal PM = INonfungiblePositionManager(0xC36442b4a4522E871399CD717aBDD847Ab11FE88);

    /// @notice Position id
    /// @dev Position ID
    /// @param addr any address
    /// @param tickLower Tick lower price bound
    /// @param tickUpper Tick upper price bound
    /// @return ABI encode
    function positionKey(
        address addr,
        int24 tickLower,
        int24 tickUpper
    ) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked(addr, tickLower, tickUpper));
    }

    /// @notice get pool by tokenId
    /// @param tokenId position Id
    function getPool(uint256 tokenId) internal view returns (address){
        (
        ,
        ,
        address token0,
        address token1,
        uint24 fee,
        ,
        ,
        ,
        ,
        ,
        ,
        ) = PM.positions(tokenId);
        return PoolAddress.getPool(token0, token1, fee);
    }

    /// @notice Calculate the number of redeemable tokens based on the amount of liquidity
    /// @dev Used when redeeming liquidity
    /// @param token0 Token 0 address
    /// @param token1 Token 1 address
    /// @param fee Fee rate
    /// @param tickLower Tick lower price bound
    /// @param tickUpper Tick upper price bound
    /// @param liquidity Liquidity amount
    /// @return amount0 Token 0 amount
    /// @return amount1 Token 1 amount
    function getAmountsForLiquidity(
        address token0,
        address token1,
        uint24 fee,
        int24 tickLower,
        int24 tickUpper,
        uint128 liquidity
    ) internal view returns (uint256 amount0, uint256 amount1) {
        (uint160 sqrtPriceX96,,,,,,) = IUniswapV3Pool(PoolAddress.getPool(token0, token1, fee)).slot0();
        uint160 sqrtRatioAX96 = TickMath.getSqrtRatioAtTick(tickLower);
        uint160 sqrtRatioBX96 = TickMath.getSqrtRatioAtTick(tickUpper);
        (amount0, amount1) = LiquidityAmounts.getAmountsForLiquidity(
            sqrtPriceX96,
            sqrtRatioAX96,
            sqrtRatioBX96,
            liquidity
        );
    }

    ///@notice Calculate unreceived handling fees for liquid positions
    /// @param tokenId Position ID
    /// @return fee0 Token 0 fee amount
    /// @return fee1 Token 1 fee amount
    function getFeesForLiquidity(
        uint256 tokenId
    ) internal view returns (uint256 fee0, uint256 fee1){
        (
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        uint128 liquidity,
        uint256 feeGrowthInside0LastX128,
        uint256 feeGrowthInside1LastX128,
        uint128 tokensOwed0,
        uint128 tokensOwed1
        ) = PM.positions(tokenId);
        (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128) = getFeeGrowthInside(tokenId);
        fee0 = tokensOwed0 + FullMath.mulDiv(
            feeGrowthInside0X128 - feeGrowthInside0LastX128,
            liquidity,
            FixedPoint128.Q128
        );
        fee1 = tokensOwed1 + FullMath.mulDiv(
            feeGrowthInside1X128 - feeGrowthInside1LastX128,
            liquidity,
            FixedPoint128.Q128
        );
    }

    /// @notice Retrieves fee growth data
    function getFeeGrowthInside(
        uint256 tokenId
    ) internal view returns (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128) {
        (
        ,
        ,
        ,
        ,
        ,
        int24 tickLower,
        int24 tickUpper,
        ,
        ,
        ,
        ,
        ) = PM.positions(tokenId);
        IUniswapV3Pool pool = IUniswapV3Pool(getPool(tokenId));
        (,int24 tickCurrent,,,,,) = pool.slot0();
        uint256 feeGrowthGlobal0X128 = pool.feeGrowthGlobal0X128();
        uint256 feeGrowthGlobal1X128 = pool.feeGrowthGlobal1X128();

        (
        ,
        ,
        uint256 lowerFeeGrowthOutside0X128,
        uint256 lowerFeeGrowthOutside1X128,
        ,
        ,
        ,
        ) = pool.ticks(tickLower);

        (
        ,
        ,
        uint256 upperFeeGrowthOutside0X128,
        uint256 upperFeeGrowthOutside1X128,
        ,
        ,
        ,
        ) = pool.ticks(tickUpper);

        // calculate fee growth below
        uint256 feeGrowthBelow0X128;
        uint256 feeGrowthBelow1X128;
        if (tickCurrent >= tickLower) {
            feeGrowthBelow0X128 = lowerFeeGrowthOutside0X128;
            feeGrowthBelow1X128 = lowerFeeGrowthOutside1X128;
        } else {
            feeGrowthBelow0X128 = feeGrowthGlobal0X128 - lowerFeeGrowthOutside0X128;
            feeGrowthBelow1X128 = feeGrowthGlobal1X128 - lowerFeeGrowthOutside1X128;
        }

        // calculate fee growth above
        uint256 feeGrowthAbove0X128;
        uint256 feeGrowthAbove1X128;
        if (tickCurrent < tickUpper) {
            feeGrowthAbove0X128 = upperFeeGrowthOutside0X128;
            feeGrowthAbove1X128 = upperFeeGrowthOutside1X128;
        } else {
            feeGrowthAbove0X128 = feeGrowthGlobal0X128 - upperFeeGrowthOutside0X128;
            feeGrowthAbove1X128 = feeGrowthGlobal1X128 - upperFeeGrowthOutside1X128;
        }

        feeGrowthInside0X128 = feeGrowthGlobal0X128 - feeGrowthBelow0X128 - feeGrowthAbove0X128;
        feeGrowthInside1X128 = feeGrowthGlobal1X128 - feeGrowthBelow1X128 - feeGrowthAbove1X128;
    }
}

File 5 of 30 : ERC20Extends.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;

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

/// @title ERC20 extends libraries
/// @notice libraries
library ERC20Extends {

    using SafeERC20 for IERC20;

    /// @notice Safe approve
    /// @dev Avoid errors that occur in some ERC20 token authorization restrictions
    /// @param token Approval token address
    /// @param to Approval address
    /// @param amount Approval amount
    function safeApprove(address token, address to, uint256 amount) internal {
        IERC20 tokenErc20 = IERC20(token);
        uint256 allowance = tokenErc20.allowance(address(this), to);
        if (allowance < amount) {
            if (allowance > 0) {
                tokenErc20.safeApprove(to, 0);
            }
            tokenErc20.safeApprove(to, amount);
        }
    }
}

File 6 of 30 : EnumerableSetExtends.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

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

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

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

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

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

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

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

            bytes32 lastvalue = set._values[lastIndex];

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

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

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

            return true;
        } else {
            return false;
        }
    }

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

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

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

    /**
     * @dev Returns The index position of the value
     */
    function _indexOf(Set storage set, bytes32 value) private view returns (uint256) {
        return set._indexes[value];
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

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

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

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

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

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

    /**
     * @dev Returns The index position of the value
     */
    function indexOf(Bytes32Set storage set, bytes32 value) internal view returns (uint256) {
        return _indexOf(set._inner, value);
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

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

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

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

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

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

    /**
     * @dev Returns The index position of the value
     */
    function indexOf(AddressSet storage set, address value) internal view returns (uint256) {
        return _indexOf(set._inner, bytes32(uint256(value)));
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

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

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

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

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

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

    /**
     * @dev Returns The index position of the value
     */
    function indexOf(UintSet storage set, uint256 value) internal view returns (uint256) {
        return _indexOf(set._inner, bytes32(value));
    }
}

File 7 of 30 : IVault.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;
import "../storage/SmartPoolStorage.sol";
pragma abicoder v2;

/// @title Vault - the vault interface
/// @notice This contract extends ERC20, defines basic vault functions and rewrites ERC20 transferFrom function
interface IVault {

    /// @notice Vault cap
    /// @dev The max number of vault to be issued
    /// @return Max vault cap
    function getCap() external view returns (uint256);

    /// @notice Get fee by type
    /// @dev (0=JOIN_FEE,1=EXIT_FEE,2=MANAGEMENT_FEE,3=PERFORMANCE_FEE,4=TURNOVER_FEE)
    /// @param ft Fee type
    function getFee(SmartPoolStorage.FeeType ft) external view returns (SmartPoolStorage.Fee memory);

    /// @notice Calculate the fee by ratio
    /// @dev This is used to calculate join and redeem fee
    /// @param ft Fee type
    /// @param vaultAmount vault amount
    function calcRatioFee(SmartPoolStorage.FeeType ft, uint256 vaultAmount) external view returns (uint256);


    /// @notice The net worth of the vault from the time the last fee collected
    /// @dev This is used to calculate the performance fee
    /// @param account Account address
    /// @return The net worth of the vault
    function accountNetValue(address account) external view returns (uint256);

    /// @notice The current vault net worth
    /// @dev This is used to update and calculate account net worth
    /// @return The net worth of the vault
    function globalNetValue() external view returns (uint256);

    /// @notice Convert vault amount to cash amount
    /// @dev This converts the user vault amount to cash amount when a user redeems the vault
    /// @param vaultAmount Redeem vault amount
    /// @return Cash amount
    function convertToCash(uint256 vaultAmount) external view returns (uint256);

    /// @notice Convert cash amount to share amount
    /// @dev This converts cash amount to share amount when a user buys the vault
    /// @param cashAmount Join cash amount
    /// @return share amount
    function convertToShare(uint256 cashAmount) external view returns (uint256);

    /// @notice Vault token address for joining and redeeming
    /// @dev This is address is created when the vault is first created.
    /// @return Vault token address
    function ioToken() external view returns (address);

    /// @notice Vault mangement contract address
    /// @dev The vault management contract address is bind to the vault when the vault is created
    /// @return Vault management contract address
    function AM() external view returns (address);

    /// @notice Vault total asset
    /// @dev This calculates vault net worth or AUM
    /// @return Vault total asset
    function assets()external view returns(uint256);

}

File 8 of 30 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

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

    uint256 private _status;

    constructor () internal {
        _status = _NOT_ENTERED;
    }

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

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

        _;

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

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

pragma solidity >=0.6.0 <0.8.0;

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

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

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

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

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

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

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

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

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

File 10 of 30 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

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

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

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

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

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

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

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

File 11 of 30 : UniV3SwapExtends.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;

import "@openzeppelin/contracts/math/SafeMath.sol";

import "../interfaces/uniswap-v3/ISwapRouter.sol";
import "../interfaces/uniswap-v3/IUniswapV3Pool.sol";
import "../interfaces/uniswap-v3/PoolAddress.sol";
import "../interfaces/uniswap-v3/Path.sol";

import "./SafeMathExtends.sol";

pragma abicoder v2;

/// @title UniV3 Swap extends libraries
/// @notice libraries
library UniV3SwapExtends {

    using Path for bytes;
    using SafeMath for uint256;
    using SafeMathExtends for uint256;

    //x96
    uint256 constant internal x96 = 2 ** 96;

    //fee denominator
    uint256 constant internal denominator = 1000000;

    //Swap Router
    ISwapRouter constant internal SRT = ISwapRouter(0xE592427A0AEce92De3Edee1F18E0157C05861564);

    /// @notice Estimated to obtain the target token amount
    /// @dev Only allow the asset transaction path that has been set to be estimated
    /// @param self Mapping path
    /// @param from Source token address
    /// @param to Target token address
    /// @param amountIn Source token amount
    /// @return amountOut Target token amount
    function estimateAmountOut(
        mapping(address => mapping(address => bytes)) storage self,
        address from,
        address to,
        uint256 amountIn
    ) internal view returns (uint256 amountOut){
        if (amountIn == 0) {return 0;}
        bytes memory path = self[from][to];
        amountOut = amountIn;
        while (true) {
            (address fromToken, address toToken, uint24 fee) = path.getFirstPool().decodeFirstPool();
            address _pool = PoolAddress.getPool(fromToken, toToken, fee);
            (uint160 sqrtPriceX96,,,,,,) = IUniswapV3Pool(_pool).slot0();
            address token0 = fromToken < toToken ? fromToken : toToken;
            amountOut = amountOut.mul(denominator.sub(uint256(fee))).div(denominator);
            if (token0 == toToken) {
                amountOut = amountOut.sqrt().mul(x96).div(sqrtPriceX96) ** 2;
            } else {
                amountOut = amountOut.sqrt().mul(sqrtPriceX96).div(x96) ** 2;
            }
            bool hasMultiplePools = path.hasMultiplePools();
            if (hasMultiplePools) {
                path = path.skipToken();
            } else {
                break;
            }
        }
    }

    /// @notice Estimate the amount of source tokens that need to be provided
    /// @dev Only allow the governance identity to set the underlying asset token address
    /// @param self Mapping path
    /// @param from Source token address
    /// @param to Target token address
    /// @param amountOut Expected target token amount
    /// @return amountIn Source token amount
    function estimateAmountIn(
        mapping(address => mapping(address => bytes)) storage self,
        address from,
        address to,
        uint256 amountOut
    ) internal view returns (uint256 amountIn){
        if (amountOut == 0) {return 0;}
        bytes memory path = self[from][to];
        amountIn = amountOut;
        while (true) {
            (address fromToken, address toToken, uint24 fee) = path.getFirstPool().decodeFirstPool();
            address _pool = PoolAddress.getPool(fromToken, toToken, fee);
            (uint160 sqrtPriceX96,,,,,,) = IUniswapV3Pool(_pool).slot0();
            address token0 = fromToken < toToken ? fromToken : toToken;
            if (token0 == toToken) {
                amountIn = amountIn.sqrt().mul(sqrtPriceX96).div(x96) ** 2;
            } else {
                amountIn = amountIn.sqrt().mul(x96).div(sqrtPriceX96) ** 2;
            }
            amountIn = amountIn.mul(denominator).div(denominator.sub(uint256(fee)));
            bool hasMultiplePools = path.hasMultiplePools();
            if (hasMultiplePools) {
                path = path.skipToken();
            } else {
                break;
            }
        }
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another token
    /// @dev Initiate a transaction with a known input amount and return the output amount
    /// @param self Mapping path
    /// @param from Input token address
    /// @param to Output token address
    /// @param amountIn Token in amount
    /// @param recipient Recipient address
    /// @param amountOutMinimum Expected to get minimum token out amount
    /// @return Token out amount
    function exactInput(
        mapping(address => mapping(address => bytes)) storage self,
        address from,
        address to,
        uint256 amountIn,
        address recipient,
        uint256 amountOutMinimum
    ) internal returns (uint256){
        bytes memory path = self[from][to];
        return SRT.exactInput(
            ISwapRouter.ExactInputParams({
        path : path,
        recipient : recipient,
        deadline : block.timestamp,
        amountIn : amountIn,
        amountOutMinimum : amountOutMinimum
        }));
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another token
    /// @dev Initiate a transaction with a known output amount and return the input amount
    /// @param self Mapping path
    /// @param from Input token address
    /// @param to Output token address
    /// @param recipient Recipient address
    /// @param amountOut Token out amount
    /// @param amountInMaximum Expect to input the maximum amount of tokens
    /// @return Token in amount
    function exactOutput(
        mapping(address => mapping(address => bytes)) storage self,
        address from,
        address to,
        address recipient,
        uint256 amountOut,
        uint256 amountInMaximum
    ) internal returns (uint256){
        bytes memory path = self[to][from];
        return SRT.exactOutput(
            ISwapRouter.ExactOutputParams({
        path : path,
        recipient : recipient,
        deadline : block.timestamp,
        amountOut : amountOut,
        amountInMaximum : amountInMaximum
        }));
    }
}

File 12 of 30 : Path.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.6.0;

import './BytesLib.sol';

/// @title Functions for manipulating path data for multihop swaps
library Path {
    using BytesLib for bytes;

    /// @dev The length of the bytes encoded address
    uint256 private constant ADDR_SIZE = 20;
    /// @dev The length of the bytes encoded fee
    uint256 private constant FEE_SIZE = 3;

    /// @dev The offset of a single token address and pool fee
    uint256 private constant NEXT_OFFSET = ADDR_SIZE + FEE_SIZE;
    /// @dev The offset of an encoded pool key
    uint256 private constant POP_OFFSET = NEXT_OFFSET + ADDR_SIZE;
    /// @dev The minimum length of an encoding that contains 2 or more pools
    uint256 private constant MULTIPLE_POOLS_MIN_LENGTH = POP_OFFSET + NEXT_OFFSET;

    /// @notice Check the legitimacy of the path
    /// @param path The encoded swap path
    /// @return Legal path
    function valid(bytes memory path)internal pure returns(bool) {
        return path.length>=POP_OFFSET;
    }

    /// @notice Returns true iff the path contains two or more pools
    /// @param path The encoded swap path
    /// @return True if path contains two or more pools, otherwise false
    function hasMultiplePools(bytes memory path) internal pure returns (bool) {
        return path.length >= MULTIPLE_POOLS_MIN_LENGTH;
    }

    /// @notice Decodes the first pool in path
    /// @param path The bytes encoded swap path
    /// @return tokenA The first token of the given pool
    /// @return tokenB The second token of the given pool
    /// @return fee The fee level of the pool
    function decodeFirstPool(bytes memory path)
        internal
        pure
        returns (
            address tokenA,
            address tokenB,
            uint24 fee
        )
    {
        tokenA = path.toAddress(0);
        fee = path.toUint24(ADDR_SIZE);
        tokenB = path.toAddress(NEXT_OFFSET);
    }

    /// @notice Gets the segment corresponding to the first pool in the path
    /// @param path The bytes encoded swap path
    /// @return The segment containing all data necessary to target the first pool in the path
    function getFirstPool(bytes memory path) internal pure returns (bytes memory) {
        return path.slice(0, POP_OFFSET);
    }

    /// @notice Gets the segment corresponding to the last pool in the path
    /// @param path The bytes encoded swap path
    /// @return The segment containing all data necessary to target the last pool in the path
    function getLastPool(bytes memory path) internal pure returns (bytes memory) {
        if(path.length==POP_OFFSET){
            return path;
        }else{
            return path.slice(path.length-POP_OFFSET, path.length);
        }
    }

    /// @notice Gets the first address of the path
    /// @param path The encoded swap path
    /// @return address
    function getFirstAddress(bytes memory path)internal pure returns(address){
        return path.toAddress(0);
    }

    /// @notice Gets the last address of the path
    /// @param path The encoded swap path
    /// @return address
    function getLastAddress(bytes memory path)internal pure returns(address){
        return path.toAddress(path.length-ADDR_SIZE);
    }

    /// @notice Skips a token + fee element from the buffer and returns the remainder
    /// @param path The swap path
    /// @return The remaining token + fee elements in the path
    function skipToken(bytes memory path) internal pure returns (bytes memory) {
        return path.slice(NEXT_OFFSET, path.length - NEXT_OFFSET);
    }
}

File 13 of 30 : GovIdentity.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;

import "../storage/GovIdentityStorage.sol";

/// @title manager role
/// @notice provide a unified identity address pool
contract GovIdentity {

    constructor() {
        _init();
    }

    function _init() internal{
        GovIdentityStorage.Identity storage identity= GovIdentityStorage.load();
        identity.governance = msg.sender;
        identity.rewards = msg.sender;
        identity.strategist[msg.sender]=true;
        identity.admin[msg.sender]=true;
    }

    modifier onlyAdmin() {
        GovIdentityStorage.Identity storage identity= GovIdentityStorage.load();
        require(isAdmin(msg.sender), "!admin");
        _;
    }

    modifier onlyStrategist() {
        require(isStrategist(msg.sender), "!strategist");
        _;
    }

    modifier onlyGovernance() {
        GovIdentityStorage.Identity storage identity= GovIdentityStorage.load();
        require(msg.sender == identity.governance, "!governance");
        _;
    }

    modifier onlyStrategistOrGovernance() {
        GovIdentityStorage.Identity storage identity= GovIdentityStorage.load();
        require(identity.strategist[msg.sender] || msg.sender == identity.governance, "!governance and !strategist");
        _;
    }

    modifier onlyAdminOrGovernance() {
        GovIdentityStorage.Identity storage identity= GovIdentityStorage.load();
        require(identity.admin[msg.sender] || msg.sender == identity.governance, "!governance and !admin");
        _;
    }

    function setGovernance(address _governance) public onlyGovernance{
        GovIdentityStorage.Identity storage identity= GovIdentityStorage.load();
        identity.governance = _governance;
    }

    function setRewards(address _rewards) public onlyGovernance{
        GovIdentityStorage.Identity storage identity= GovIdentityStorage.load();
        identity.rewards = _rewards;
    }

    function setStrategist(address _strategist,bool enable) public onlyGovernance{
        GovIdentityStorage.Identity storage identity= GovIdentityStorage.load();
        identity.strategist[_strategist]=enable;
    }

    function setAdmin(address _admin,bool enable) public onlyGovernance{
        GovIdentityStorage.Identity storage identity= GovIdentityStorage.load();
        identity.admin[_admin]=enable;
    }

    function getGovernance() public view returns(address){
        GovIdentityStorage.Identity storage identity= GovIdentityStorage.load();
        return identity.governance;
    }

    function getRewards() public view returns(address){
        GovIdentityStorage.Identity storage identity= GovIdentityStorage.load();
        return identity.rewards ;
    }

    function isStrategist(address _strategist) public view returns(bool){
        GovIdentityStorage.Identity storage identity= GovIdentityStorage.load();
        return identity.strategist[_strategist];
    }

    function isAdmin(address _admin) public view returns(bool){
        GovIdentityStorage.Identity storage identity= GovIdentityStorage.load();
        return identity.admin[_admin];
    }


}

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

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library 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;
    }
}

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

/// @title Provides functions for deriving a pool address from the factory, tokens, and the fee
library PoolAddress {
    bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54;

    //Uniswap V3 Factory
    address constant private factory = address(0x1F98431c8aD98523631AE4a59f267346ea31F984);

    /// @notice The identifying key of the pool
    struct PoolKey {
        address token0;
        address token1;
        uint24 fee;
    }

    /// @dev Returns the pool for the given token pair and fee. The pool contract may or may not exist.
    function getPool(
        address tokenA,
        address tokenB,
        uint24 fee
    ) internal pure returns (address) {
        return computeAddress(getPoolKey(tokenA, tokenB, fee));
    }

    /// @notice Returns PoolKey: the ordered tokens with the matched fee levels
    /// @param tokenA The first token of a pool, unsorted
    /// @param tokenB The second token of a pool, unsorted
    /// @param fee The fee level of the pool
    /// @return Poolkey The pool details with ordered token0 and token1 assignments
    function getPoolKey(
        address tokenA,
        address tokenB,
        uint24 fee
    ) internal pure returns (PoolKey memory) {
        if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA);
        return PoolKey({token0 : tokenA, token1 : tokenB, fee : fee});
    }

    /// @notice Deterministically computes the pool address given the factory and PoolKey
    /// @param key The PoolKey
    /// @return pool The contract address of the V3 pool
    function computeAddress(PoolKey memory key) internal pure returns (address pool) {
        require(key.token0 < key.token1);
        pool = address(
            uint256(
                keccak256(
                    abi.encodePacked(
                        hex'ff',
                        factory,
                        keccak256(abi.encode(key.token0, key.token1, key.fee)),
                        POOL_INIT_CODE_HASH
                    )
                )
            )
        );
    }
}

File 16 of 30 : FixedPoint128.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.4.0;

/// @title FixedPoint128
/// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format)
library FixedPoint128 {
    uint256 internal constant Q128 = 0x100000000000000000000000000000000;
}

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

import './FullMath.sol';
import './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 18 of 30 : 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 19 of 30 : IUniswapV3Pool.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0;

/// @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 {

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


}

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

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

pragma experimental ABIEncoderV2;
interface INonfungiblePositionManager is IERC721
{
    /// @notice Returns the position information associated with a given token ID.
    /// @dev Throws if the token ID is not valid.
    /// @param tokenId The ID of the token that represents the position
    /// @return nonce The nonce for permits
    /// @return operator The address that is approved for spending
    /// @return token0 The address of the token0 for a specific pool
    /// @return token1 The address of the token1 for a specific pool
    /// @return fee The fee associated with the pool
    /// @return tickLower The lower end of the tick range for the position
    /// @return tickUpper The higher end of the tick range for the position
    /// @return liquidity The liquidity of the position
    /// @return feeGrowthInside0LastX128 The fee growth of token0 as of the last action on the individual position
    /// @return feeGrowthInside1LastX128 The fee growth of token1 as of the last action on the individual position
    /// @return tokensOwed0 The uncollected amount of token0 owed to the position as of the last computation
    /// @return tokensOwed1 The uncollected amount of token1 owed to the position as of the last computation
    function positions(uint256 tokenId)
    external
    view
    returns (
        uint96 nonce,
        address operator,
        address token0,
        address token1,
        uint24 fee,
        int24 tickLower,
        int24 tickUpper,
        uint128 liquidity,
        uint256 feeGrowthInside0LastX128,
        uint256 feeGrowthInside1LastX128,
        uint128 tokensOwed0,
        uint128 tokensOwed1
    );

    struct MintParams {
        address token0;
        address token1;
        uint24 fee;
        int24 tickLower;
        int24 tickUpper;
        uint256 amount0Desired;
        uint256 amount1Desired;
        uint256 amount0Min;
        uint256 amount1Min;
        address recipient;
        uint256 deadline;
    }

    /// @notice Creates a new position wrapped in a NFT
    /// @dev Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized
    /// a method does not exist, i.e. the pool is assumed to be initialized.
    /// @param params The params necessary to mint a position, encoded as `MintParams` in calldata
    /// @return tokenId The ID of the token that represents the minted position
    /// @return liquidity The amount of liquidity for this position
    /// @return amount0 The amount of token0
    /// @return amount1 The amount of token1
    function mint(MintParams calldata params)
    external
    payable
    returns (
        uint256 tokenId,
        uint128 liquidity,
        uint256 amount0,
        uint256 amount1
    );

    struct IncreaseLiquidityParams {
        uint256 tokenId;
        uint256 amount0Desired;
        uint256 amount1Desired;
        uint256 amount0Min;
        uint256 amount1Min;
        uint256 deadline;
    }

    /// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender`
    /// @param params tokenId The ID of the token for which liquidity is being increased,
    /// amount0Desired The desired amount of token0 to be spent,
    /// amount1Desired The desired amount of token1 to be spent,
    /// amount0Min The minimum amount of token0 to spend, which serves as a slippage check,
    /// amount1Min The minimum amount of token1 to spend, which serves as a slippage check,
    /// deadline The time by which the transaction must be included to effect the change
    /// @return liquidity The new liquidity amount as a result of the increase
    /// @return amount0 The amount of token0 to acheive resulting liquidity
    /// @return amount1 The amount of token1 to acheive resulting liquidity
    function increaseLiquidity(IncreaseLiquidityParams calldata params)
    external
    payable
    returns (
        uint128 liquidity,
        uint256 amount0,
        uint256 amount1
    );

    struct DecreaseLiquidityParams {
        uint256 tokenId;
        uint128 liquidity;
        uint256 amount0Min;
        uint256 amount1Min;
        uint256 deadline;
    }

    /// @notice Decreases the amount of liquidity in a position and accounts it to the position
    /// @param params tokenId The ID of the token for which liquidity is being decreased,
    /// amount The amount by which liquidity will be decreased,
    /// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,
    /// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,
    /// deadline The time by which the transaction must be included to effect the change
    /// @return amount0 The amount of token0 accounted to the position's tokens owed
    /// @return amount1 The amount of token1 accounted to the position's tokens owed
    function decreaseLiquidity(DecreaseLiquidityParams calldata params)
    external
    payable
    returns (uint256 amount0, uint256 amount1);

    struct CollectParams {
        uint256 tokenId;
        address recipient;
        uint128 amount0Max;
        uint128 amount1Max;
    }

    /// @notice Collects up to a maximum amount of fees owed to a specific position to the recipient
    /// @param params tokenId The ID of the NFT for which tokens are being collected,
    /// recipient The account that should receive the tokens,
    /// amount0Max The maximum amount of token0 to collect,
    /// amount1Max The maximum amount of token1 to collect
    /// @return amount0 The amount of fees collected in token0
    /// @return amount1 The amount of fees collected in token1
    function collect(CollectParams calldata params) external payable returns (uint256 amount0, uint256 amount1);

    /// @notice Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens
    /// must be collected first.
    /// @param tokenId The ID of the token that is being burned
    function burn(uint256 tokenId) external payable;
}

File 21 of 30 : Address.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

File 22 of 30 : SafeMathExtends.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;

// a library for performing various math operations

library SafeMathExtends {

    uint256 internal constant BONE = 10 ** 18;

    // Add two numbers together checking for overflows
    function badd(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "ERR_ADD_OVERFLOW");
        return c;
    }

    // subtract two numbers and return diffecerence when it underflows
    function bsubSign(uint256 a, uint256 b) internal pure returns (uint256, bool) {
        if (a >= b) {
            return (a - b, false);
        } else {
            return (b - a, true);
        }
    }

    // Subtract two numbers checking for underflows
    function bsub(uint256 a, uint256 b) internal pure returns (uint256) {
        (uint256 c, bool flag) = bsubSign(a, b);
        require(!flag, "ERR_SUB_UNDERFLOW");
        return c;
    }

    // Multiply two 18 decimals numbers
    function bmul(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c0 = a * b;
        require(a == 0 || c0 / a == b, "ERR_MUL_OVERFLOW");
        uint256 c1 = c0 + (BONE / 2);
        require(c1 >= c0, "ERR_MUL_OVERFLOW");
        uint256 c2 = c1 / BONE;
        return c2;
    }

    // Divide two 18 decimals numbers
    function bdiv(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b != 0, "ERR_DIV_ZERO");
        uint256 c0 = a * BONE;
        require(a == 0 || c0 / a == BONE, "ERR_DIV_INTERNAL");
        // bmul overflow
        uint256 c1 = c0 + (b / 2);
        require(c1 >= c0, "ERR_DIV_INTERNAL");
        //  badd require
        uint256 c2 = c1 / b;
        return c2;
    }

    function min(uint x, uint y) internal pure returns (uint z) {
        z = x < y ? x : y;
    }

    // babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method)
    function sqrt(uint y) internal pure returns (uint z) {
        if (y > 3) {
            z = y;
            uint x = y / 2 + 1;
            while (x < z) {
                z = x;
                x = (y / x + x) / 2;
            }
        } else if (y != 0) {
            z = 1;
        }
    }
}

File 23 of 30 : ISwapRouter.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
pragma experimental ABIEncoderV2;

import './IUniswapV3SwapCallback.sol';

/// @title Router token swapping functionality
/// @notice Functions for swapping tokens via Uniswap V3
interface ISwapRouter is IUniswapV3SwapCallback {
    struct ExactInputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);

    struct ExactInputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);

    struct ExactOutputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);

    struct ExactOutputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
}

File 24 of 30 : BytesLib.sol
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * @title Solidity Bytes Arrays Utils
 * @author Gonçalo Sá <[email protected]>
 *
 * @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity.
 *      The library lets you concatenate, slice and type cast bytes arrays both in memory and storage.
 */
pragma solidity >=0.5.0 <=0.8.0;

library BytesLib {
    function slice(
        bytes memory _bytes,
        uint256 _start,
        uint256 _length
    ) internal pure returns (bytes memory) {
        require(_length + 31 >= _length, 'slice_overflow');
        require(_start + _length >= _start, 'slice_overflow');
        require(_bytes.length >= _start + _length, 'slice_outOfBounds');

        bytes memory tempBytes;

        assembly {
            switch iszero(_length)
                case 0 {
                    // Get a location of some free memory and store it in tempBytes as
                    // Solidity does for memory variables.
                    tempBytes := mload(0x40)

                    // The first word of the slice result is potentially a partial
                    // word read from the original array. To read it, we calculate
                    // the length of that partial word and start copying that many
                    // bytes into the array. The first word we copy will start with
                    // data we don't care about, but the last `lengthmod` bytes will
                    // land at the beginning of the contents of the new array. When
                    // we're done copying, we overwrite the full first word with
                    // the actual length of the slice.
                    let lengthmod := and(_length, 31)

                    // The multiplication in the next line is necessary
                    // because when slicing multiples of 32 bytes (lengthmod == 0)
                    // the following copy loop was copying the origin's length
                    // and then ending prematurely not copying everything it should.
                    let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod)))
                    let end := add(mc, _length)

                    for {
                        // The multiplication in the next line has the same exact purpose
                        // as the one above.
                        let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start)
                    } lt(mc, end) {
                        mc := add(mc, 0x20)
                        cc := add(cc, 0x20)
                    } {
                        mstore(mc, mload(cc))
                    }

                    mstore(tempBytes, _length)

                    //update free-memory pointer
                    //allocating the array padded to 32 bytes like the compiler does now
                    mstore(0x40, and(add(mc, 31), not(31)))
                }
                //if we want a zero-length slice let's just return a zero-length array
                default {
                    tempBytes := mload(0x40)
                    //zero out the 32 bytes slice we are about to return
                    //we need to do it because Solidity does not garbage collect
                    mstore(tempBytes, 0)

                    mstore(0x40, add(tempBytes, 0x20))
                }
        }

        return tempBytes;
    }

    function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) {
        require(_start + 20 >= _start, 'toAddress_overflow');
        require(_bytes.length >= _start + 20, 'toAddress_outOfBounds');
        address tempAddress;

        assembly {
            tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000)
        }

        return tempAddress;
    }

    function toUint24(bytes memory _bytes, uint256 _start) internal pure returns (uint24) {
        require(_start + 3 >= _start, 'toUint24_overflow');
        require(_bytes.length >= _start + 3, 'toUint24_outOfBounds');
        uint24 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x3), _start))
        }

        return tempUint;
    }
}

File 25 of 30 : 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 26 of 30 : 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 27 of 30 : IERC721.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

File 28 of 30 : GovIdentityStorage.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;

library GovIdentityStorage {

  bytes32 public constant govSlot = keccak256("GovIdentityStorage.storage.location");

  struct Identity{
    address governance;
    address rewards;
    mapping(address=>bool) strategist;
    mapping(address=>bool) admin;
  }

  function load() internal pure returns (Identity storage gov) {
    bytes32 loc = govSlot;
    assembly {
      gov.slot := loc
    }
  }
}

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

/// @title Callback for IUniswapV3PoolActions#swap
/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface
interface IUniswapV3SwapCallback {
    /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.
    /// @dev In the implementation you must pay the pool tokens owed for the swap.
    /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.
    /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
    /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token0 to the pool.
    /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token1 to the pool.
    /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call
    function uniswapV3SwapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes calldata data
    ) external;
}

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

pragma solidity >=0.6.0 <0.8.0;

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

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

Contract Security Audit

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"Collect","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"liquidity","type":"uint128"}],"name":"DecreaseLiquidity","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"liquidity","type":"uint128"}],"name":"IncreaseLiquidity","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"liquidity","type":"uint128"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"address","name":"fromToken","type":"address"},{"indexed":false,"internalType":"address","name":"toToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountOut","type":"uint256"}],"name":"Swap","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"enum SmartPoolStorage.FeeType","name":"ft","type":"uint8"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"address","name":"rewards","type":"address"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"TakeFee","type":"event"},{"inputs":[],"name":"assets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_vault","type":"address"},{"internalType":"address","name":"_ioToken","type":"address"}],"name":"bind","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pool","type":"address"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"}],"name":"checkPos","outputs":[{"internalType":"bool","name":"atWork","type":"bool"},{"internalType":"bool","name":"has","type":"bool"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint128","name":"amount0Max","type":"uint128"},{"internalType":"uint128","name":"amount1Max","type":"uint128"}],"name":"collect","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"}],"name":"decreaseLiquidity","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amountOut","type":"uint256"}],"name":"estimateAmountIn","outputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"}],"name":"estimateAmountOut","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMinimum","type":"uint256"}],"name":"exactInput","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint256","name":"amountInMaximum","type":"uint256"}],"name":"exactOutput","outputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getGovernance","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRewards","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getUnderlyings","outputs":[{"internalType":"address[]","name":"tokens","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"history","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"idleAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"amount0Desired","type":"uint256"},{"internalType":"uint256","name":"amount1Desired","type":"uint256"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"}],"name":"increaseLiquidity","outputs":[{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"ioToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_admin","type":"address"}],"name":"isAdmin","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_strategist","type":"address"}],"name":"isStrategist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"liquidityAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"uint256","name":"amount0Desired","type":"uint256"},{"internalType":"uint256","name":"amount1Desired","type":"uint256"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"positionOwners","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"ts","type":"address[]"}],"name":"removeUnderlyings","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"safeApproveAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_admin","type":"address"},{"internalType":"bool","name":"enable","type":"bool"}],"name":"setAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_governance","type":"address"}],"name":"setGovernance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_rewards","type":"address"}],"name":"setRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_strategist","type":"address"},{"internalType":"bool","name":"enable","type":"bool"}],"name":"setStrategist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"strategist","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"int256","name":"amount","type":"int256"}],"name":"setTokenLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"ts","type":"address[]"}],"name":"setUnderlyings","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"path","type":"bytes"}],"name":"settingSwapRoute","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"swapRoute","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"tokenLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vault","outputs":[{"internalType":"contract IVault","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"outputToken","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"scale","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"withdrawAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"scale","type":"uint256"}],"name":"withdrawOfUnderlying","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"worksPos","outputs":[{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"stateMutability":"view","type":"function"}]

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106102325760003560e01c80638e5f597711610130578063c691b0a1116100b8578063ed26bceb1161007c578063ed26bceb146104d5578063f2055297146104e8578063f65baefa14610508578063fa09e6301461051d578063fbfa77cf1461053057610232565b8063c691b0a114610472578063d1ec9f1414610494578063dbcea0a8146104a7578063e16b03a3146104ba578063ec38a862146104c257610232565b8063ab033ea9116100ff578063ab033ea914610406578063ac9650d814610419578063adb9aa3714610439578063b9e0a2911461044c578063bcd9b38c1461045f57610232565b80638e5f5977146103ba5780639854211b146103cd5780639e5f76a9146103e0578063aa8d348e146103f357610232565b80634b0bddd2116101be5780637428f580116101825780637428f580146103565780637bfe950c14610369578063807f77381461037c5780638157f72f1461039d57806381f47c6f146103b257610232565b80634b0bddd2146103025780634c341e131461031557806362474ea1146103285780636734faee1461033b57806371a973051461034e57610232565b806324d7806c1161020557806324d7806c146102aa578063289b3c0d146102ca5780632979da0b146102d257806331241492146102da57806345ed5569146102ef57610232565b80630572b0cc14610237578063131ba910146102555780631ab1fb191461027557806322d59b8a14610288575b600080fd5b61023f610538565b60405161024c91906156bb565b60405180910390f35b61026861026336600461504f565b610556565b60405161024c9190615b15565b61026861028336600461504f565b6106bd565b61029b6102963660046150c1565b61080f565b60405161024c93929190615843565b6102bd6102b8366004614f39565b61085e565b60405161024c9190615838565b61023f610891565b6102686108ac565b6102ed6102e8366004615136565b61090c565b005b6102ed6102fd366004614f8d565b6109d2565b6102ed610310366004615094565b610abe565b6102ed610323366004615094565b610b52565b61023f610336366004615250565b610be6565b6102bd610349366004614f39565b610c01565b610268610c33565b6102ed610364366004615136565b610c58565b6102ed61037736600461504f565b610d02565b61038f61038a36600461542d565b610f49565b60405161024c929190615b1e565b6103a56111f9565b60405161024c9190615800565b61023f611286565b61038f6103c8366004615463565b611295565b6102686103db366004614f55565b61140f565b6102686103ee366004614f8d565b61142c565b6102ed61040136600461510b565b611444565b6102ed610414366004614f39565b611549565b61042c6104273660046151e2565b6115cf565b60405161024c91906157a0565b610268610447366004614f8d565b611772565b6102ed61045a366004614fcd565b611780565b6102ed61046d366004615268565b611ae4565b6104856104803660046154ea565b611be0565b60405161024c93929190615af4565b6102ed6104a2366004614f55565b611f26565b6102ed6104b5366004614f39565b611fae565b610268612074565b6102ed6104d0366004614f39565b61217d565b6102686104e3366004615250565b612206565b6104fb6104f6366004614f55565b612218565b60405161024c919061585b565b6105106122b9565b60405161024c9190615753565b6102ed61052b366004614f39565b612357565b61023f612477565b600080610543612486565b600101546001600160a01b031691505090565b6000610560610891565b6001600160a01b0316336001600160a01b0316148061058357506105833361085e565b80610592575061059233610c01565b806105a057506105a06124aa565b6105c55760405162461bcd60e51b81526004016105bc9061594c565b60405180910390fd5b60006105d033610c01565b9050801561061b573360009081526003602090815260408083206001600160a01b038a16845290915290205484111561061b5760405162461bcd60e51b81526004016105bc906158be565b61062a600087878730886124bb565b9150801561066b573360009081526003602090815260408083206001600160a01b038a81168552925280832080548890039055908716825290208054830190555b610675858361262e565b7fcd3829a3813dc3cdd188fd3d01dcf3268c16be2fdd2dd21d0665418816e4606233878787866040516106ac9594939291906156cf565b60405180910390a150949350505050565b60006106c7610891565b6001600160a01b0316336001600160a01b031614806106ea57506106ea3361085e565b806106f957506106f933610c01565b8061070757506107076124aa565b6107235760405162461bcd60e51b81526004016105bc9061594c565b6107326000868630878761271d565b905061073d33610c01565b156107be573360009081526003602090815260408083206001600160a01b03891684529091529020548111156107855760405162461bcd60e51b81526004016105bc906158be565b3360009081526003602090815260408083206001600160a01b038981168552925280832080548590039055908616825290208054840190555b6107c8848461262e565b7fcd3829a3813dc3cdd188fd3d01dcf3268c16be2fdd2dd21d0665418816e4606233868684876040516107ff9594939291906156cf565b60405180910390a1949350505050565b600080600080610820878787612832565b6000818152600160205260409020549250905061083e600483612888565b93506000821161084f576000610852565b60015b92505093509350939050565b600080610869612486565b6001600160a01b03841660009081526003909101602052604090205460ff169150505b919050565b60008061089c612486565b546001600160a01b031691505090565b60075460009081906001600160a01b0316816108c8600461289d565b905060005b818110156109035760006108e26004836128a8565b90506108f86108f182866128b4565b8690612a42565b9450506001016108cd565b50919250505090565b6000610916612486565b80549091506001600160a01b03163314610965576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b60005b82518110156109cd5761099883828151811061098057fe5b60200260200101516009612a9c90919063ffffffff16565b6109c5576109c38382815181106109ab57fe5b60200260200101516009612ab190919063ffffffff16565b505b600101610968565b505050565b60006109dc612486565b33600090815260038201602052604090205490915060ff1680610a08575080546001600160a01b031633145b610a52576040805162461bcd60e51b815260206004820152601660248201527510b3b7bb32b93730b731b29030b7321010b0b236b4b760511b604482015290519081900360640190fd5b6000821315610a8b576001600160a01b038085166000908152600360209081526040808320938716835292905220805483019055610ab8565b6001600160a01b038085166000908152600360209081526040808320938716835292905220805483900390555b50505050565b6000610ac8612486565b80549091506001600160a01b03163314610b17576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b6000610b21612486565b6001600160a01b03949094166000908152600390940160205250506040909120805460ff1916911515919091179055565b6000610b5c612486565b80549091506001600160a01b03163314610bab576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b6000610bb5612486565b6001600160a01b03949094166000908152600290940160205250506040909120805460ff1916911515919091179055565b6002602052600090815260409020546001600160a01b031681565b600080610c0c612486565b6001600160a01b03841660009081526002909101602052604090205460ff16915050919050565b600080610c3e612074565b9050610c52610c4b6108ac565b8290612a42565b91505090565b6000610c62612486565b80549091506001600160a01b03163314610cb1576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b60005b82518110156109cd57610ccc83828151811061098057fe5b15610cfa57610cf8838281518110610ce057fe5b60200260200101516009612ac690919063ffffffff16565b505b600101610cb4565b60026006541415610d5a576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b6002600655610d676124aa565b610d835760405162461bcd60e51b81526004016105bc9061592c565b6040516370a0823160e01b815284906000906001600160a01b038316906370a0823190610db49030906004016156bb565b60206040518083038186803b158015610dcc57600080fd5b505afa158015610de0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e049190615415565b905083811015610e9e576000610e1984612adb565b905060005b8151811015610e9b576000610e346009836128a8565b9050886001600160a01b0316816001600160a01b031614158015610e6b57506000838381518110610e6157fe5b6020026020010151115b15610e9257610e90818a858581518110610e8157fe5b60200260200101516000610556565b505b50600101610e1e565b50505b6040516370a0823160e01b81526001600160a01b038316906370a0823190610eca9030906004016156bb565b60206040518083038186803b158015610ee257600080fd5b505afa158015610ef6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f1a9190615415565b905083811015610f28578093505b610f3c6001600160a01b0383168686612dbe565b5050600160065550505050565b60008084610f55610891565b6001600160a01b0316336001600160a01b03161480610f785750610f783361085e565b80610f9957506000818152600260205260409020546001600160a01b031633145b80610fa75750610fa76124aa565b610fc35760405162461bcd60e51b81526004016105bc9061590f565b604080516080810182528781523060208201526001600160801b038088168284015286166060820152905163fc6f786560e01b815273c36442b4a4522e871399cd717abdd847ab11fe889163fc6f7865916110219190600401615969565b6040805180830381600087803b15801561103a57600080fd5b505af115801561104e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061107291906154c7565b60405163133f757160e31b815291945092506000908190819073c36442b4a4522e871399cd717abdd847ab11fe88906399fbab88906110b5908c90600401615b15565b6101806040518083038186803b1580156110ce57600080fd5b505afa1580156110e2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111069190615524565b5050505097505050509450945050506000600260008b815260200190815260200160002060009054906101000a90046001600160a01b0316905061114981610c01565b15611188576001600160a01b038181166000908152600360209081526040808320888516845290915280822080548b0190559185168152208054870190555b6001600160801b0382166111a3576111a160048b612e10565b505b6111af84848989612e1c565b7fde5e3abbba77c313e4f5881ab0685bbbbb54f38b5cfbdd6230e88642a5df29f1338b89896040516111e4949392919061572d565b60405180910390a15050505050935093915050565b60606000611207600461289d565b9050806001600160401b038111801561121f57600080fd5b50604051908082528060200260200182016040528015611249578160200160208202803683370190505b50915060005b81811015611281576112626004826128a8565b83828151811061126e57fe5b602090810291909101015260010161124f565b505090565b6007546001600160a01b031681565b600080856112a1610891565b6001600160a01b0316336001600160a01b031614806112c457506112c43361085e565b806112e557506000818152600260205260409020546001600160a01b031633145b806112f357506112f36124aa565b61130f5760405162461bcd60e51b81526004016105bc9061590f565b6040805160a0810182528881526001600160801b0388166020820152808201879052606081018690524260808201529051630624e65f60e11b815273c36442b4a4522e871399cd717abdd847ab11fe8891630c49ccbe9161137391906004016159ac565b6040805180830381600087803b15801561138c57600080fd5b505af11580156113a0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113c491906154c7565b60405191945092507f6693689f64043eabb83a49d6923e3f02afb22e2e1fe43fde0eea8e76e9944165906113fd9033908a908a90615703565b60405180910390a15094509492505050565b600360209081526000928352604080842090915290825290205481565b600061143a81858585612ff0565b90505b9392505050565b6002600654141561149c576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b60026006556114a96124aa565b6114c55760405162461bcd60e51b81526004016105bc9061592c565b60006114d082612adb565b905060005b815181101561153e5760008282815181106114ec57fe5b60200260200101511115611536576115368483838151811061150a57fe5b60200260200101516115268460096128a890919063ffffffff16565b6001600160a01b03169190612dbe565b6001016114d5565b505060016006555050565b6000611553612486565b80549091506001600160a01b031633146115a2576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b60006115ac612486565b80546001600160a01b0319166001600160a01b0394909416939093179092555050565b60606115d9610891565b6001600160a01b0316336001600160a01b031614806115fc57506115fc3361085e565b8061160b575061160b33610c01565b8061161957506116196124aa565b6116355760405162461bcd60e51b81526004016105bc9061594c565b816001600160401b038111801561164b57600080fd5b5060405190808252806020026020018201604052801561167f57816020015b606081526020019060019003908161166a5790505b50905060005b8281101561176b576000803086868581811061169d57fe5b90506020028101906116af9190615b2c565b6040516116bd9291906156ab565b600060405180830381855af49150503d80600081146116f8576040519150601f19603f3d011682016040523d82523d6000602084013e6116fd565b606091505b5091509150816117495760448151101561171657600080fd5b6004810190508080602001905181019061173091906152e0565b60405162461bcd60e51b81526004016105bc919061585b565b8084848151811061175657fe5b60209081029190910101525050600101611685565b5092915050565b600061143a8185858561324f565b611788610891565b6001600160a01b0316336001600160a01b031614806117ab57506117ab3361085e565b806117ba57506117ba33610c01565b806117c857506117c86124aa565b6117e45760405162461bcd60e51b81526004016105bc9061594c565b60006117ef33610c01565b9050801561187d573360009081526003602090815260408083206001600160a01b038c16845290915290205483111561183a5760405162461bcd60e51b81526004016105bc906158be565b3360009081526003602090815260408083206001600160a01b038b16845290915290205482111561187d5760405162461bcd60e51b81526004016105bc906158be565b60008060008073c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b031663883164566040518061016001604052808f6001600160a01b031681526020018e6001600160a01b031681526020018d62ffffff1681526020018c60020b81526020018b60020b81526020018a81526020018981526020016000815260200160008152602001306001600160a01b03168152602001428152506040518263ffffffff1660e01b81526004016119369190615a46565b608060405180830381600087803b15801561195057600080fd5b505af1158015611964573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611988919061548a565b93509350935093508415611a43578160036000336001600160a01b03166001600160a01b0316815260200190815260200160002060008e6001600160a01b03166001600160a01b03168152602001908152602001600020600082825403925050819055508060036000336001600160a01b03166001600160a01b0316815260200190815260200160002060008d6001600160a01b03166001600160a01b03168152602001908152602001600020600082825403925050819055505b6000611a4e8561348a565b90506000611a5d828c8c612832565b60008181526001602090815260408083208a90558983526002909152902080546001600160a01b031916331790559050611a98600487613541565b507fa049a7b0db25fd4a447d4a72385802f52641ca5797b84688137edbe240b2a57f338787604051611acc93929190615703565b60405180910390a15050505050505050505050505050565b6000611aee612486565b33600090815260038201602052604090205490915060ff1680611b1a575080546001600160a01b031633145b611b64576040805162461bcd60e51b815260206004820152601660248201527510b3b7bb32b93730b731b29030b7321010b0b236b4b760511b604482015290519081900360640190fd5b611b6d8261354d565b611b895760405162461bcd60e51b81526004016105bc906158e4565b6000611b9483613555565b90506000611ba184613561565b6001600160a01b0380841660009081526020818152604080832093851683529281529190208651929350611bd9929091870190614e3a565b5050505050565b600080600087611bee610891565b6001600160a01b0316336001600160a01b03161480611c115750611c113361085e565b80611c3257506000818152600260205260409020546001600160a01b031633145b80611c405750611c406124aa565b611c5c5760405162461bcd60e51b81526004016105bc9061590f565b60405163133f757160e31b8152600090819073c36442b4a4522e871399cd717abdd847ab11fe88906399fbab8890611c98908e90600401615b15565b6101806040518083038186803b158015611cb157600080fd5b505afa158015611cc5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ce99190615524565b50505050505050509350935050506000600260008d815260200190815260200160002060009054906101000a90046001600160a01b03169050611d2b81610c01565b15611dba576001600160a01b038082166000908152600360209081526040808320938716835292905220548b1115611d755760405162461bcd60e51b81526004016105bc906158be565b6001600160a01b038082166000908152600360209081526040808320938616835292905220548a1115611dba5760405162461bcd60e51b81526004016105bc906158be565b6040805160c0810182528d8152602081018d90528082018c9052606081018b9052608081018a90524260a0820152905163219f5d1760e01b815273c36442b4a4522e871399cd717abdd847ab11fe889163219f5d1791611e1d9190600401615a02565b606060405180830381600087803b158015611e3757600080fd5b505af1158015611e4b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e6f9190615349565b91985096509450611e7f81610c01565b15611ec0576001600160a01b038181166000908152600360209081526040808320878516845290915280822080548a90039055918416815220805486900390555b611ecb60048d612888565b611edc57611eda60048d613541565b505b7fcdabc26646509227c74ca625354a7b8160cd6a2a5476fc559e0d3e87652e5233338d89604051611f0f93929190615703565b60405180910390a150505050955095509592505050565b6000611f30612486565b80549091506001600160a01b03163314611f7f576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b50600880546001600160a01b039384166001600160a01b03199182161790915560078054929093169116179055565b6000611fb8612486565b33600090815260038201602052604090205490915060ff1680611fe4575080546001600160a01b031633145b61202e576040805162461bcd60e51b815260206004820152601660248201527510b3b7bb32b93730b731b29030b7321010b0b236b4b760511b604482015290519081900360640190fd5b61204f8273c36442b4a4522e871399cd717abdd847ab11fe8860001961357a565b6120708273e592427a0aece92de3edee1f18e0157c0586156460001961357a565b5050565b60008060005b612084600961289d565b8110156121775760006120986009836128a8565b90506000816001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016120c891906156bb565b60206040518083038186803b1580156120e057600080fd5b505afa1580156120f4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121189190615415565b6007549091506001600160a01b03838116911614156121425761213b8482612a42565b935061216d565b60075460009061215d9084906001600160a01b03168461142c565b90506121698582612a42565b9450505b505060010161207a565b50905090565b6000612187612486565b80549091506001600160a01b031633146121d6576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b60006121e0612486565b60010180546001600160a01b0319166001600160a01b0394909416939093179092555050565b60016020526000908152604090205481565b60006020818152928152604080822084529181528190208054825160026001831615610100026000190190921691909104601f8101859004850282018501909352828152929091908301828280156122b15780601f10612286576101008083540402835291602001916122b1565b820191906000526020600020905b81548152906001019060200180831161229457829003601f168201915b505050505081565b606060006122c7600961289d565b9050806001600160401b03811180156122df57600080fd5b50604051908082528060200260200182016040528015612309578160200160208202803683370190505b50915060005b612319600961289d565b8110156112815761232b6009826128a8565b83828151811061233757fe5b6001600160a01b039092166020928302919091019091015260010161230f565b6000612361612486565b80549091506001600160a01b031633146123b0576040805162461bcd60e51b815260206004820152600b60248201526a21676f7665726e616e636560a81b604482015290519081900360640190fd5b60005b6123bd600961289d565b8110156109cd5760006123d16009836128a8565b90506000816001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161240191906156bb565b60206040518083038186803b15801561241957600080fd5b505afa15801561242d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124519190615415565b9050801561246d5761246d6001600160a01b0383168683612dbe565b50506001016123b3565b6008546001600160a01b031681565b7fcb55949ab430320d1d890f811b8ef71f5738a7b79732c8a303f07d66f65bfcfa90565b6008546001600160a01b0316331490565b6001600160a01b0385811660009081526020888152604080832093881683529281528282208054845160026001831615610100026000190190921691909104601f810184900484028201840190955284815292938493928301828280156125635780601f1061253857610100808354040283529160200191612563565b820191906000526020600020905b81548152906001019060200180831161254657829003601f168201915b50506040805160a0810182528581526001600160a01b038a1660208201524281830152606081018b905260808101899052905163c04b8d5960e01b815294955073e592427a0aece92de3edee1f18e0157c058615649463c04b8d5994506125d093509091506004016159ef565b602060405180830381600087803b1580156125ea57600080fd5b505af11580156125fe573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126229190615415565b98975050505050505050565b600854604051636d2227e960e11b81526000916001600160a01b03169063da444fd29061266190600490869082016158a3565b60206040518083038186803b15801561267957600080fd5b505afa15801561268d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126b19190615415565b905080156109cd5760006126c3610538565b90506126d96001600160a01b0385168284612dbe565b7f23f1130767a74e11f5c444c8cc04e3e1fd5dd7c70d95202b6a248d3f14f0751f600485838560405161270f949392919061586e565b60405180910390a150505050565b6001600160a01b0384811660009081526020888152604080832093891683529281528282208054845160026001831615610100026000190190921691909104601f810184900484028201840190955284815292938493928301828280156127c55780601f1061279a576101008083540402835291602001916127c5565b820191906000526020600020905b8154815290600101906020018083116127a857829003601f168201915b50506040805160a0810182528581526001600160a01b038b1660208201524281830152606081018a9052608081018990529051631e51809360e31b815294955073e592427a0aece92de3edee1f18e0157c058615649463f28c049894506125d093509091506004016159ef565b6040805160609490941b6bffffffffffffffffffffffff1916602080860191909152600293840b60e890811b60348701529290930b90911b60378401528051808403601a018152603a9093019052815191012090565b60006128948383613634565b90505b92915050565b60006128978261364c565b60006128948383613650565b600080600080600080600073c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b03166399fbab888a6040518263ffffffff1660e01b81526004016128ff9190615b15565b6101806040518083038186803b15801561291857600080fd5b505afa15801561292c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129509190615524565b5050505097509750975097509750975050506000806129738888888888886136b4565b915091506000806129838d613762565b90925090506129928483612a42565b61299c8483612a42565b909450925060006001600160a01b038b8116908e1614156129be5750836129dc565b60006129d88c8f886000612ff0909392919063ffffffff16565b9150505b8c6001600160a01b03168a6001600160a01b03161415612a0757612a008185612a42565b9050612a31565b6000612a218b8f876000612ff0909392919063ffffffff16565b9050612a2d8282612a42565b9150505b9d9c50505050505050505050505050565b600082820183811015612894576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b6000612894836001600160a01b038416613634565b6000612894836001600160a01b038416613887565b6000612894836001600160a01b0384166138d1565b60606000612ae9600961289d565b9050806001600160401b0381118015612b0157600080fd5b50604051908082528060200260200182016040528015612b2b578160200160208202803683370190505b5091506000816001600160401b0381118015612b4657600080fd5b50604051908082528060200260200182016040528015612b70578160200160208202803683370190505b50905060005b82811015612c62576000612b8b6009836128a8565b90506000816001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401612bbb91906156bb565b60206040518083038186803b158015612bd357600080fd5b505afa158015612be7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c0b9190615415565b905080848481518110612c1a57fe5b6020908102919091010152612c41670de0b6b3a7640000612c3b838a613997565b906139f0565b868481518110612c4d57fe5b60209081029190910101525050600101612b76565b506000612c6e85613a57565b905060005b83811015612db5576000612c886009836128a8565b90506000816001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401612cb891906156bb565b60206040518083038186803b158015612cd057600080fd5b505afa158015612ce4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d089190615415565b90506000612d4f612d48868681518110612d1e57fe5b6020026020010151888781518110612d3257fe5b6020026020010151612a4290919063ffffffff16565b8390613c8d565b9050612d93612d6a670de0b6b3a7640000612c3b848d613997565b612d8d878781518110612d7957fe5b60200260200101518b8881518110612d3257fe5b90612a42565b888581518110612d9f57fe5b6020908102919091010152505050600101612c73565b50505050919050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526109cd908490613cea565b600061289483836138d1565b600854604051636d2227e960e11b81526000916001600160a01b03169063da444fd290612e4f90600490879082016158a3565b60206040518083038186803b158015612e6757600080fd5b505afa158015612e7b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e9f9190615415565b600854604051636d2227e960e11b81529192506000916001600160a01b039091169063da444fd290612ed790600490879082016158a3565b60206040518083038186803b158015612eef57600080fd5b505afa158015612f03573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f279190615415565b90506000612f33610538565b90508215612f8e57612f4f6001600160a01b0388168285612dbe565b7f23f1130767a74e11f5c444c8cc04e3e1fd5dd7c70d95202b6a248d3f14f0751f6004888386604051612f85949392919061586e565b60405180910390a15b8115612fe757612fa86001600160a01b0387168284612dbe565b7f23f1130767a74e11f5c444c8cc04e3e1fd5dd7c70d95202b6a248d3f14f0751f6004878385604051612fde949392919061586e565b60405180910390a15b50505050505050565b600081612fff57506000613247565b6001600160a01b0384811660009081526020878152604080832093871683529281528282208054845160026001831615610100026000190190921691909104601f8101849004840282018401909552848152929390918301828280156130a65780601f1061307b576101008083540402835291602001916130a6565b820191906000526020600020905b81548152906001019060200180831161308957829003601f168201915b505050505090508291505b60008060006130c76130c285613d9b565b613daa565b92509250925060006130da848484613ddb565b90506000816001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e06040518083038186803b15801561311757600080fd5b505afa15801561312b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061314f919061537f565b50505050505090506000846001600160a01b0316866001600160a01b031610613178578461317a565b855b905061319c620f4240612c3b6131958262ffffff8916613c8d565b8b90613997565b9750846001600160a01b0316816001600160a01b031614156131e65760026131de836001600160a01b0316612c3b600160601b6131d88d613df0565b90613997565b0a975061320a565b6002613206600160601b612c3b856001600160a01b03166131d88d613df0565b0a97505b600061321588613e41565b9050801561322d5761322688613e49565b9750613239565b50505050505050613245565b505050505050506130b1565b505b949350505050565b60008161325e57506000613247565b6001600160a01b0384811660009081526020878152604080832093871683529281528282208054845160026001831615610100026000190190921691909104601f8101849004840282018401909552848152929390918301828280156133055780601f106132da57610100808354040283529160200191613305565b820191906000526020600020905b8154815290600101906020018083116132e857829003601f168201915b505050505090508291505b60008060006133216130c285613d9b565b9250925092506000613334848484613ddb565b90506000816001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e06040518083038186803b15801561337157600080fd5b505afa158015613385573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133a9919061537f565b50505050505090506000846001600160a01b0316866001600160a01b0316106133d257846133d4565b855b9050846001600160a01b0316816001600160a01b03161415613418576002613410600160601b612c3b856001600160a01b03166131d88d613df0565b0a975061343c565b6002613438836001600160a01b0316612c3b600160601b6131d88d613df0565b0a97505b61345e613451620f424062ffffff8716613c8d565b612c3b8a620f4240613997565b9750600061346b88613e41565b9050801561322d5761347c88613e49565b975050505050505050613310565b60008060008073c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b03166399fbab88866040518263ffffffff1660e01b8152600401808281526020019150506101806040518083038186803b1580156134e957600080fd5b505afa1580156134fd573d6000803e3d6000fd5b505050506040513d61018081101561351457600080fd5b50604081015160608201516080909201519094509092509050613538838383613ddb565b95945050505050565b60006128948383613887565b51602b111590565b60006128978282613e60565b6000612897601483510383613e6090919063ffffffff16565b60408051636eb1769f60e11b81523060048201526001600160a01b038481166024830152915185926000929084169163dd62ed3e91604480820192602092909190829003018186803b1580156135cf57600080fd5b505afa1580156135e3573d6000803e3d6000fd5b505050506040513d60208110156135f957600080fd5b5051905082811015611bd9578015613620576136206001600160a01b038316856000613f10565b611bd96001600160a01b0383168585613f10565b60009081526001919091016020526040902054151590565b5490565b815460009082106136925760405162461bcd60e51b8152600401808060200182810382526022815260200180615c436022913960400191505060405180910390fd5b8260000182815481106136a157fe5b9060005260206000200154905092915050565b60008060006136c4898989613ddb565b6001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e06040518083038186803b1580156136fc57600080fd5b505afa158015613710573d6000803e3d6000fd5b505050506040513d60e081101561372657600080fd5b50519050600061373587614023565b9050600061374287614023565b905061375083838389614355565b909c909b509950505050505050505050565b600080600080600080600073c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b03166399fbab88896040518263ffffffff1660e01b8152600401808281526020019150506101806040518083038186803b1580156137c657600080fd5b505afa1580156137da573d6000803e3d6000fd5b505050506040513d6101808110156137f157600080fd5b5060e081015161010082015161012083015161014084015161016090940151929850909650945090925090506000806138298a6143f1565b91509150613847868303886001600160801b0316600160801b61476b565b846001600160801b031601985061386e858203886001600160801b0316600160801b61476b565b836001600160801b031601975050505050505050915091565b60006138938383613634565b6138c957508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155612897565b506000612897565b6000818152600183016020526040812054801561398d578354600019808301919081019060009087908390811061390457fe5b906000526020600020015490508087600001848154811061392157fe5b60009182526020808320909101929092558281526001898101909252604090209084019055865487908061395157fe5b60019003818190600052602060002001600090559055866001016000878152602001908152602001600020600090556001945050505050612897565b6000915050612897565b6000826139a657506000612897565b828202828482816139b357fe5b04146128945760405162461bcd60e51b8152600401808060200182810382526021815260200180615c8b6021913960400191505060405180910390fd5b6000808211613a46576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b818381613a4f57fe5b049392505050565b60606000613a65600461289d565b9050613a71600961289d565b6001600160401b0381118015613a8657600080fd5b50604051908082528060200260200182016040528015613ab0578160200160208202803683370190505b50915060005b81811015613c86576000613acb6004836128a8565b9050600080600073c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b03166399fbab88856040518263ffffffff1660e01b8152600401613b129190615b15565b6101806040518083038186803b158015613b2b57600080fd5b505afa158015613b3f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b639190615524565b5050505097505050509450945050506000816001600160801b03161115613c76576000613ba5670de0b6b3a7640000612c3b6001600160801b0385168c613997565b9050600080613bb78784600080611295565b909250905060006001613bcb60098961481a565b03905060006001613bdd60098961481a565b039050613c068c8381518110613bef57fe5b602002602001015185612a4290919063ffffffff16565b8c8381518110613c1257fe5b602002602001018181525050613c448c8281518110613c2d57fe5b602002602001015184612a4290919063ffffffff16565b8c8281518110613c5057fe5b602002602001018181525050613c6e896001600160801b0380610f49565b505050505050505b505060019092019150613ab69050565b5050919050565b600082821115613ce4576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b6000613d3f826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661482f9092919063ffffffff16565b8051909150156109cd57808060200190516020811015613d5e57600080fd5b50516109cd5760405162461bcd60e51b815260040180806020018281038252602a815260200180615cac602a913960400191505060405180910390fd5b6060612897826000602b61483e565b60008080613db88482613e60565b9250613dc584601461498e565b9050613dd2846017613e60565b91509193909250565b600061143a613deb858585614a35565b614a8b565b60006003821115613e33575080600160028204015b81811015613e2d57809150600281828581613e1c57fe5b040181613e2557fe5b049050613e05565b5061088c565b811561088c57506001919050565b516042111590565b80516060906128979083906017906016190161483e565b600081826014011015613eaf576040805162461bcd60e51b8152602060048201526012602482015271746f416464726573735f6f766572666c6f7760701b604482015290519081900360640190fd5b8160140183511015613f00576040805162461bcd60e51b8152602060048201526015602482015274746f416464726573735f6f75744f66426f756e647360581b604482015290519081900360640190fd5b500160200151600160601b900490565b801580613f96575060408051636eb1769f60e11b81523060048201526001600160a01b03848116602483015291519185169163dd62ed3e91604480820192602092909190829003018186803b158015613f6857600080fd5b505afa158015613f7c573d6000803e3d6000fd5b505050506040513d6020811015613f9257600080fd5b5051155b613fd15760405162461bcd60e51b8152600401808060200182810382526036815260200180615cd66036913960400191505060405180910390fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b1790526109cd908490613cea565b60008060008360020b1261403a578260020b614042565b8260020b6000035b9050620d89e8811115614080576040805162461bcd60e51b81526020600482015260016024820152601560fa1b604482015290519081900360640190fd5b60006001821661409457600160801b6140a6565b6ffffcb933bd6fad37aa2d162d1a5940015b70ffffffffffffffffffffffffffffffffff16905060028216156140da576ffff97272373d413259a46990580e213a0260801c5b60048216156140f9576ffff2e50f5f656932ef12357cf3c7fdcc0260801c5b6008821615614118576fffe5caca7e10e4e61c3624eaa0941cd00260801c5b6010821615614137576fffcb9843d60f6159c9db58835c9266440260801c5b6020821615614156576fff973b41fa98c081472e6896dfb254c00260801c5b6040821615614175576fff2ea16466c96a3843ec78b326b528610260801c5b6080821615614194576ffe5dee046a99a2a811c461f1969c30530260801c5b6101008216156141b4576ffcbe86c7900a88aedcffc83b479aa3a40260801c5b6102008216156141d4576ff987a7253ac413176f2b074cf7815e540260801c5b6104008216156141f4576ff3392b0822b70005940c7a398e4b70f30260801c5b610800821615614214576fe7159475a2c29b7443b29c7fa6e889d90260801c5b611000821615614234576fd097f3bdfd2022b8845ad8f792aa58250260801c5b612000821615614254576fa9f746462d870fdf8a65dc1f90e061e50260801c5b614000821615614274576f70d869a156d2a1b890bb3df62baf32f70260801c5b618000821615614294576f31be135f97d08fd981231505542fcfa60260801c5b620100008216156142b5576f09aa508b5b7a84e1c677de54f3e99bc90260801c5b620200008216156142d5576e5d6af8dedb81196699c329225ee6040260801c5b620400008216156142f4576d2216e584f5fa1ea926041bedfe980260801c5b62080000821615614311576b048a170391f7dc42444e8fa20260801c5b60008460020b131561432c57806000198161432857fe5b0490505b640100000000810615614340576001614343565b60005b60ff16602082901c0192505050919050565b600080836001600160a01b0316856001600160a01b03161115614376579293925b846001600160a01b0316866001600160a01b0316116143a15761439a858585614b73565b91506143e8565b836001600160a01b0316866001600160a01b031610156143da576143c6868585614b73565b91506143d3858785614bdc565b90506143e8565b6143e5858585614bdc565b90505b94509492505050565b60008060008073c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b03166399fbab88866040518263ffffffff1660e01b8152600401808281526020019150506101806040518083038186803b15801561445057600080fd5b505afa158015614464573d6000803e3d6000fd5b505050506040513d61018081101561447b57600080fd5b5060a081015160c090910151909250905060006144978661348a565b90506000816001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e06040518083038186803b1580156144d457600080fd5b505afa1580156144e8573d6000803e3d6000fd5b505050506040513d60e08110156144fe57600080fd5b506020908101516040805163f305839960e01b815290519193506000926001600160a01b0386169263f3058399926004808201939291829003018186803b15801561454857600080fd5b505afa15801561455c573d6000803e3d6000fd5b505050506040513d602081101561457257600080fd5b505160408051634614131960e01b815290519192506000916001600160a01b038616916346141319916004808301926020929190829003018186803b1580156145ba57600080fd5b505afa1580156145ce573d6000803e3d6000fd5b505050506040513d60208110156145e457600080fd5b50516040805163f30dba9360e01b8152600289900b6004820152905191925060009182916001600160a01b0388169163f30dba939160248082019261010092909190829003018186803b15801561463a57600080fd5b505afa15801561464e573d6000803e3d6000fd5b505050506040513d61010081101561466557600080fd5b50604080820151606090920151815163f30dba9360e01b815260028b900b60048201529151929450925060009182916001600160a01b038a169163f30dba939160248082019261010092909190829003018186803b1580156146c657600080fd5b505afa1580156146da573d6000803e3d6000fd5b505050506040513d6101008110156146f157600080fd5b506040810151606090910151909250905060008060028c810b908a900b1261471d575084905083614726565b50508386038386035b6000808c60020b8b60020b121561474157508490508361474a565b50508388038388035b81848b03039f5080838a03039e505050505050505050505050505050915091565b60008080600019858709868602925082811090839003039050806147a1576000841161479657600080fd5b50829004905061143d565b8084116147ad57600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b6000612894836001600160a01b038416614c1f565b606061143a8484600085614c35565b60608182601f011015614889576040805162461bcd60e51b815260206004820152600e60248201526d736c6963655f6f766572666c6f7760901b604482015290519081900360640190fd5b8282840110156148d1576040805162461bcd60e51b815260206004820152600e60248201526d736c6963655f6f766572666c6f7760901b604482015290519081900360640190fd5b8183018451101561491d576040805162461bcd60e51b8152602060048201526011602482015270736c6963655f6f75744f66426f756e647360781b604482015290519081900360640190fd5b60608215801561493c5760405191506000825260208201604052613245565b6040519150601f8416801560200281840101858101878315602002848b0101015b8183101561497557805183526020928301920161495d565b5050858452601f01601f19166040525050949350505050565b6000818260030110156149dc576040805162461bcd60e51b8152602060048201526011602482015270746f55696e7432345f6f766572666c6f7760781b604482015290519081900360640190fd5b8160030183511015614a2c576040805162461bcd60e51b8152602060048201526014602482015273746f55696e7432345f6f75744f66426f756e647360601b604482015290519081900360640190fd5b50016003015190565b614a3d614ec6565b826001600160a01b0316846001600160a01b03161115614a5b579192915b50604080516060810182526001600160a01b03948516815292909316602083015262ffffff169181019190915290565b600081602001516001600160a01b031682600001516001600160a01b031610614ab357600080fd5b50805160208083015160409384015184516001600160a01b0394851681850152939091168385015262ffffff16606080840191909152835180840390910181526080830184528051908201206001600160f81b031960a08401527307e610c722b66148d8c6b92967c99cd1ba8c7e6160621b60a184015260b58301527fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b5460d5808401919091528351808403909101815260f5909201909252805191012090565b6000826001600160a01b0316846001600160a01b03161115614b93579192915b836001600160a01b0316614bcc606060ff16846001600160801b0316901b8686036001600160a01b0316866001600160a01b031661476b565b81614bd357fe5b04949350505050565b6000826001600160a01b0316846001600160a01b03161115614bfc579192915b61143a826001600160801b03168585036001600160a01b0316600160601b61476b565b6000908152600191909101602052604090205490565b606082471015614c765760405162461bcd60e51b8152600401808060200182810382526026815260200180615c656026913960400191505060405180910390fd5b614c7f85614d90565b614cd0576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b600080866001600160a01b031685876040518082805190602001908083835b60208310614d0e5780518252601f199092019160209182019101614cef565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114614d70576040519150601f19603f3d011682016040523d82523d6000602084013e614d75565b606091505b5091509150614d85828286614d96565b979650505050505050565b3b151590565b60608315614da557508161143d565b825115614db55782518084602001fd5b8160405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015614dff578181015183820152602001614de7565b50505050905090810190601f168015614e2c5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b828054600181600116156101000203166002900490600052602060002090601f016020900481019282614e705760008555614eb6565b82601f10614e8957805160ff1916838001178555614eb6565b82800160010185558215614eb6579182015b82811115614eb6578251825591602001919060010190614e9b565b50614ec2929150614ee6565b5090565b604080516060810182526000808252602082018190529181019190915290565b5b80821115614ec25760008155600101614ee7565b805161088c81615be7565b805161088c81615c0d565b805161088c81615c1c565b805161ffff8116811461088c57600080fd5b805161088c81615c31565b600060208284031215614f4a578081fd5b813561289481615be7565b60008060408385031215614f67578081fd5b8235614f7281615be7565b91506020830135614f8281615be7565b809150509250929050565b600080600060608486031215614fa1578081fd5b8335614fac81615be7565b92506020840135614fbc81615be7565b929592945050506040919091013590565b600080600080600080600060e0888a031215614fe7578283fd5b8735614ff281615be7565b9650602088013561500281615be7565b9550604088013561501281615c31565b9450606088013561502281615c0d565b9350608088013561503281615c0d565b9699959850939692959460a0840135945060c09093013592915050565b60008060008060808587031215615064578182fd5b843561506f81615be7565b9350602085013561507f81615be7565b93969395505050506040820135916060013590565b600080604083850312156150a6578182fd5b82356150b181615be7565b91506020830135614f8281615bff565b6000806000606084860312156150d5578081fd5b83356150e081615be7565b925060208401356150f081615c0d565b9150604084013561510081615c0d565b809150509250925092565b6000806040838503121561511d578182fd5b823561512881615be7565b946020939093013593505050565b60006020808385031215615148578182fd5b82356001600160401b038082111561515e578384fd5b818501915085601f830112615171578384fd5b81358181111561517d57fe5b838102915061518d848301615b77565b8181528481019084860184860187018a10156151a7578788fd5b8795505b838610156151d557803594506151c085615be7565b848352600195909501949186019186016151ab565b5098975050505050505050565b600080602083850312156151f4578182fd5b82356001600160401b038082111561520a578384fd5b818501915085601f83011261521d578384fd5b81358181111561522b578485fd5b866020808302850101111561523e578485fd5b60209290920196919550909350505050565b600060208284031215615261578081fd5b5035919050565b600060208284031215615279578081fd5b81356001600160401b0381111561528e578182fd5b8201601f8101841361529e578182fd5b80356152b16152ac82615b9a565b615b77565b8181528560208385010111156152c5578384fd5b81602084016020830137908101602001929092525092915050565b6000602082840312156152f1578081fd5b81516001600160401b03811115615306578182fd5b8201601f81018413615316578182fd5b80516153246152ac82615b9a565b818152856020838501011115615338578384fd5b613538826020830160208601615bbb565b60008060006060848603121561535d578081fd5b835161536881615c1c565b602085015160409095015190969495509392505050565b600080600080600080600060e0888a031215615399578081fd5b87516153a481615be7565b60208901519097506153b581615c0d565b95506153c360408901614f1c565b94506153d160608901614f1c565b93506153df60808901614f1c565b925060a088015160ff811681146153f4578182fd5b60c089015190925061540581615bff565b8091505092959891949750929550565b600060208284031215615426578081fd5b5051919050565b600080600060608486031215615441578081fd5b83359250602084013561545381615c1c565b9150604084013561510081615c1c565b60008060008060808587031215615478578182fd5b84359350602085013561507f81615c1c565b6000806000806080858703121561549f578182fd5b8451935060208501516154b181615c1c565b6040860151606090960151949790965092505050565b600080604083850312156154d9578182fd5b505080516020909101519092909150565b600080600080600060a08688031215615501578283fd5b505083359560208501359550604085013594606081013594506080013592509050565b6000806000806000806000806000806000806101808d8f031215615546578586fd5b8c516bffffffffffffffffffffffff81168114615561578687fd5b9b5061556f60208e01614efb565b9a5061557d60408e01614efb565b995061558b60608e01614efb565b985061559960808e01614f2e565b97506155a760a08e01614f06565b96506155b560c08e01614f06565b95506155c360e08e01614f11565b94506101008d015193506101208d015192506155e26101408e01614f11565b91506155f16101608e01614f11565b90509295989b509295989b509295989b565b6001600160a01b03169052565b60008151808452615628816020860160208601615bbb565b601f01601f19169290920160200192915050565b6005811061564657fe5b9052565b60020b9052565b6000815160a0845261566660a0850182615610565b6020848101516001600160a01b031690860152604080850151908601526060808501519086015260809384015193909401929092525090919050565b62ffffff169052565b6000828483379101908152919050565b6001600160a01b0391909116815260200190565b6001600160a01b03958616815293851660208501529190931660408301526060820192909252608081019190915260a00190565b6001600160a01b0393909316835260208301919091526001600160801b0316604082015260600190565b6001600160a01b0394909416845260208401929092526040830152606082015260800190565b6020808252825182820181905260009190848201906040850190845b818110156157945783516001600160a01b03168352928401929184019160010161576f565b50909695505050505050565b6000602080830181845280855180835260408601915060408482028701019250838701855b828110156157f357603f198886030184526157e1858351615610565b945092850192908501906001016157c5565b5092979650505050505050565b6020808252825182820181905260009190848201906040850190845b818110156157945783518352928401929184019160010161581c565b901515815260200190565b92151583529015156020830152604082015260600190565b6000602082526128946020830184615610565b6080810161587c828761563c565b6001600160a01b039485166020830152929093166040840152606090920191909152919050565b604081016158b1828561563c565b8260208301529392505050565b6020808252600c908201526b0858da1958dac81b1a5b5a5d60a21b604082015260600190565b6020808252601190820152701c185d1a081a5cc81b9bdd081d985b1a59607a1b604082015260600190565b60208082526003908201526221504d60e81b604082015260600190565b602080825260069082015265085d985d5b1d60d21b604082015260600190565b60208082526003908201526221414d60e81b604082015260600190565b815181526020808301516001600160a01b0316908201526040808301516001600160801b0390811691830191909152606092830151169181019190915260800190565b600060a082019050825182526001600160801b03602084015116602083015260408301516040830152606083015160608301526080830151608083015292915050565b6000602082526128946020830184615651565b600060c082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015292915050565b600061016082019050615a5a828451615603565b6020830151615a6c6020840182615603565b506040830151615a7f60408401826156a2565b506060830151615a92606084018261564a565b506080830151615aa5608084018261564a565b5060a083015160a083015260c083015160c083015260e083015160e083015261010080840151818401525061012080840151615ae382850182615603565b505061014092830151919092015290565b6001600160801b039390931683526020830191909152604082015260600190565b90815260200190565b918252602082015260400190565b6000808335601e19843603018112615b42578283fd5b8301803591506001600160401b03821115615b5b578283fd5b602001915036819003821315615b7057600080fd5b9250929050565b6040518181016001600160401b0381118282101715615b9257fe5b604052919050565b60006001600160401b03821115615bad57fe5b50601f01601f191660200190565b60005b83811015615bd6578181015183820152602001615bbe565b83811115610ab85750506000910152565b6001600160a01b0381168114615bfc57600080fd5b50565b8015158114615bfc57600080fd5b8060020b8114615bfc57600080fd5b6001600160801b0381168114615bfc57600080fd5b62ffffff81168114615bfc57600080fdfe456e756d657261626c655365743a20696e646578206f7574206f6620626f756e6473416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f775361666545524332303a204552433230206f7065726174696f6e20646964206e6f7420737563636565645361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f20746f206e6f6e2d7a65726f20616c6c6f77616e6365a2646970667358221220259d602882195888ce1bc3ae7f7d1cffc1a092abd38481e21f37c844fedee20964736f6c63430007060033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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