ETH Price: $3,731.29 (+18.45%)
Gas: 15 Gwei

Contract

0xE9Cf1FD8d9D804Ef3Ce6754776144B86c93EfB8d
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Value
Create Fund139167252022-01-01 2:03:45871 days ago1641002625IN
0xE9Cf1FD8...6c93EfB8d
0 ETH0.2532665660.77300158
Create Fund139160782021-12-31 23:41:58871 days ago1640994118IN
0xE9Cf1FD8...6c93EfB8d
0 ETH0.3000959572.01002741
Create Fund138409422021-12-20 8:22:22883 days ago1639988542IN
0xE9Cf1FD8...6c93EfB8d
0 ETH0.1436729735
Create Fund138409422021-12-20 8:22:22883 days ago1639988542IN
0xE9Cf1FD8...6c93EfB8d
0 ETH0.1440766935
0x61010060138086942021-12-15 8:40:40888 days ago1639557640IN
 Create: HotPotV3FundFactory
0 ETH0.2218610444.61087758

Latest 4 internal transactions

Advanced mode:
Parent Transaction Hash Block From To Value
139167252022-01-01 2:03:45871 days ago1641002625
0xE9Cf1FD8...6c93EfB8d
 Contract Creation0 ETH
139160782021-12-31 23:41:58871 days ago1640994118
0xE9Cf1FD8...6c93EfB8d
 Contract Creation0 ETH
138409422021-12-20 8:22:22883 days ago1639988542
0xE9Cf1FD8...6c93EfB8d
 Contract Creation0 ETH
138409422021-12-20 8:22:22883 days ago1639988542
0xE9Cf1FD8...6c93EfB8d
 Contract Creation0 ETH
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
HotPotV3FundFactory

Compiler Version
v0.7.6+commit.7338295f

Optimization Enabled:
Yes with 800 runs

Other Settings:
default evmVersion, None license
File 1 of 49 : HotPotV3FundFactory.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;

import './interfaces/IHotPotV3FundFactory.sol';
import './interfaces/IHotPotV3FundController.sol';
import './HotPotV3FundDeployer.sol';

/// @title The interface for the HotPotFunds V3 Factory
/// @notice The HotPotV3Funds Factory facilitates creation of HotPot V3 fund
contract HotPotV3FundFactory is IHotPotV3FundFactory, HotPotV3FundDeployer {
    /// @inheritdoc IHotPotV3FundFactory
    address public override immutable WETH9;
    /// @inheritdoc IHotPotV3FundFactory
    address public override immutable uniV3Factory;
    /// @inheritdoc IHotPotV3FundFactory
    address public override immutable uniV3Router;
    /// @inheritdoc IHotPotV3FundFactory
    address public override immutable controller;
    mapping(bytes32 => address) private _fund;

    constructor(
        address _controller, 
        address _weth9,
        address _uniV3Factory, 
        address _uniV3Router
    ){
        require(_controller != address(0));
        require(_weth9 != address(0));
        require(_uniV3Factory != address(0));
        require(_uniV3Router != address(0));

        controller = _controller;
        WETH9 = _weth9;
        uniV3Factory = _uniV3Factory;
        uniV3Router = _uniV3Router;
    }

    /// @inheritdoc IHotPotV3FundFactory
    function getFund(address manager, address token, uint lockPeriod, uint baseLine, uint managerFee) external view override returns (address fund){
        return _fund[keccak256(abi.encode(manager, token, lockPeriod, baseLine, managerFee))];
    }
    
    /// @inheritdoc IHotPotV3FundFactory
    function createFund(address token, bytes calldata descriptor, uint lockPeriod, uint baseLine, uint managerFee) external override returns (address fund){
        bytes32 fundKey = keccak256(abi.encode(msg.sender, token, lockPeriod, baseLine, managerFee));
        require(IHotPotV3FundController(controller).verifiedToken(token));
        require(_fund[fundKey] == address(0));
        require(lockPeriod <= 1095 days);
        require(managerFee <= 45);

        fund = deploy(WETH9, uniV3Factory, uniV3Router, controller, msg.sender, token, descriptor, lockPeriod, baseLine, managerFee);
        _fund[fundKey] = fund;

        emit FundCreated(msg.sender, token, fund);
    }
}

File 2 of 49 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

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

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

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

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

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

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

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

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

File 3 of 49 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

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

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

    uint256 private _status;

    constructor () {
        _status = _NOT_ENTERED;
    }

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

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

        _;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

}

File 6 of 49 : IUniswapV3MintCallback.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Callback for IUniswapV3PoolActions#mint
/// @notice Any contract that calls IUniswapV3PoolActions#mint must implement this interface
interface IUniswapV3MintCallback {
    /// @notice Called to `msg.sender` after minting liquidity to a position from IUniswapV3Pool#mint.
    /// @dev In the implementation you must pay the pool tokens owed for the minted liquidity.
    /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.
    /// @param amount0Owed The amount of token0 due to the pool for the minted liquidity
    /// @param amount1Owed The amount of token1 due to the pool for the minted liquidity
    /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#mint call
    function uniswapV3MintCallback(
        uint256 amount0Owed,
        uint256 amount1Owed,
        bytes calldata data
    ) external;
}

File 7 of 49 : 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 8 of 49 : IUniswapV3PoolActions.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

File 14 of 49 : 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 15 of 49 : 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 16 of 49 : 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 17 of 49 : LowGasSafeMath.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        require(sqrtRatioAX96 > 0);

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

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

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

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

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

File 20 of 49 : 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 21 of 49 : UnsafeMath.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

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

File 22 of 49 : ISwapRouter.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

import '@uniswap/v3-core/contracts/interfaces/callback/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 23 of 49 : 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 24 of 49 : LiquidityAmounts.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

File 25 of 49 : 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 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 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 26 of 49 : 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;

    /// @notice The identifying key of the pool
    struct PoolKey {
        address token0;
        address token1;
        uint24 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 factory The Uniswap V3 factory contract address
    /// @param key The PoolKey
    /// @return pool The contract address of the V3 pool
    function computeAddress(address factory, 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 27 of 49 : PositionKey.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

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

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

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

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

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

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

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

File 29 of 49 : HotPotV3Fund.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.7.6;
pragma abicoder v2;

import '@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3MintCallback.sol';
import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol';
import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol';
import '@uniswap/v3-core/contracts/libraries/TickMath.sol';
import '@uniswap/v3-core/contracts/libraries/FullMath.sol';
import '@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol';
import '@uniswap/v3-periphery/contracts/libraries/LiquidityAmounts.sol';
import '@uniswap/v3-periphery/contracts/libraries/PositionKey.sol';
import '@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol';
import '@openzeppelin/contracts/utils/ReentrancyGuard.sol';
import './interfaces/IHotPotV3FundDeployer.sol';
import './interfaces/IHotPotV3Fund.sol';
import './interfaces/external/IWETH9.sol';
import './base/HotPotV3FundERC20.sol';
import './libraries/Position.sol';
import './libraries/Array2D.sol';

contract HotPotV3Fund is HotPotV3FundERC20, IHotPotV3Fund, IUniswapV3MintCallback, ReentrancyGuard {
    using LowGasSafeMath for uint;
    using SafeCast for int256;
    using Path for bytes;
    using Position for Position.Info;
    using Position for Position.Info[];
    using Array2D for uint[][];

    uint public override depositDeadline = 2**256-1;
    uint public override immutable lockPeriod;
    uint public override immutable baseLine;
    uint public override immutable managerFee;
    uint constant FEE = 5;

    address immutable WETH9;
    address immutable uniV3Factory;
    address immutable uniV3Router;

    address public override immutable controller;
    address public override immutable manager;
    address public override immutable token;
    bytes public override descriptor;

    uint public override totalInvestment;

    /// @inheritdoc IHotPotV3FundState
    mapping (address => uint) override public investmentOf;

    /// @inheritdoc IHotPotV3FundState
    mapping(address => bytes) public override buyPath;
    /// @inheritdoc IHotPotV3FundState
    mapping(address => bytes) public override sellPath;
    /// @inheritdoc IHotPotV3FundState
    mapping(address => uint) public override lastDepositTime;

    /// @inheritdoc IHotPotV3FundState
    address[] public override pools;
    /// @inheritdoc IHotPotV3FundState
    Position.Info[][] public override positions;

    modifier onlyController() {
        require(msg.sender == controller, "OCC");
        _;
    }

    modifier checkDeadline(uint deadline) {
        require(block.timestamp <= deadline, 'CDL');
        _;
    }

    constructor () {
        address _token;
        address _uniV3Router;
        (WETH9, uniV3Factory, _uniV3Router, controller, manager, _token, descriptor, lockPeriod, baseLine, managerFee) = IHotPotV3FundDeployer(msg.sender).parameters();
        token = _token;
        uniV3Router = _uniV3Router;

        //approve for add liquidity and swap. 2**256-1 never used up.
        TransferHelper.safeApprove(_token, _uniV3Router, 2**256-1);
    }

    /// @inheritdoc IHotPotV3FundUserActions
    function deposit(uint amount) external override returns(uint share) {
        require(amount > 0, "DAZ");
        uint total_assets = totalAssets();
        TransferHelper.safeTransferFrom(token, msg.sender, address(this), amount);

        return _deposit(amount, total_assets);
    }

    function _deposit(uint amount, uint total_assets) internal returns(uint share) {
        require(block.timestamp <= depositDeadline, "DL");
        if(totalSupply == 0)
            share = amount;
        else
            share =  FullMath.mulDiv(amount, totalSupply, total_assets);

        lastDepositTime[msg.sender] = block.timestamp;
        investmentOf[msg.sender] = investmentOf[msg.sender].add(amount);
        totalInvestment = totalInvestment.add(amount);
        _mint(msg.sender, share);
        emit Deposit(msg.sender, amount, share);
    }

    receive() external payable {
        //当前是WETH9基金
        if(token == WETH9){
            // 普通用户发起的转账ETH,认为是deposit
            if(msg.sender != WETH9 && msg.value > 0){
                uint totals = totalAssets();
                IWETH9(WETH9).deposit{value: address(this).balance}();
                _deposit(msg.value, totals);
            } //else 接收WETH9向合约转账ETH
        }
        // 不是WETH基金, 不接受ETH转账
        else revert();
    }

    /// @inheritdoc IHotPotV3FundUserActions
    function withdraw(uint share, uint amountMin, uint deadline) external override checkDeadline(deadline) nonReentrant returns(uint amount) {
        uint balance = balanceOf[msg.sender];
        require(share > 0 && share <= balance, "ISA");
        require(block.timestamp > lastDepositTime[msg.sender].add(lockPeriod), "LKP");
        uint investment = FullMath.mulDiv(investmentOf[msg.sender], share, balance);

        address fToken = token;
        // 构造amounts数组
        uint value = IERC20(fToken).balanceOf(address(this));
        uint _totalAssets = value;
        uint[][] memory amounts = new uint[][](pools.length);
        for(uint i=0; i<pools.length; i++){
            uint _amount;
            (_amount, amounts[i]) = _assetsOfPool(i);
            _totalAssets = _totalAssets.add(_amount);
        }

        amount = FullMath.mulDiv(_totalAssets, share, totalSupply);
        // 从大到小从头寸中撤资.
        if(amount > value) {
            uint remainingAmount = amount.sub(value);
            while(true) {
                // 取最大的头寸索引号
                (uint poolIndex, uint positionIndex, uint desirableAmount) = amounts.max();
                if(desirableAmount == 0) break;

                if(remainingAmount <= desirableAmount){
                    positions[poolIndex][positionIndex].subLiquidity(Position.SubParams({
                        proportionX128: FullMath.mulDiv(remainingAmount, 100 << 128, desirableAmount),
                        pool: pools[poolIndex],
                        token: fToken,
                        uniV3Router: uniV3Router,
                        uniV3Factory: uniV3Factory,
                        maxSqrtSlippage: 10001,
                        maxPriceImpact: 10001
                    }), sellPath);
                    break;
                }
                else {
                    positions[poolIndex][positionIndex].subLiquidity(Position.SubParams({
                            proportionX128: 100 << 128,
                            pool: pools[poolIndex],
                            token: fToken,
                            uniV3Router: uniV3Router,
                            uniV3Factory: uniV3Factory,
                            maxSqrtSlippage: 10001,
                            maxPriceImpact: 10001
                        }), sellPath);
                    remainingAmount = remainingAmount.sub(desirableAmount);
                    amounts[poolIndex][positionIndex] = 0;
                }
            }
            /// @dev 从流动池中撤资时,按比例撤流动性, 同时tokensOwed已全部提取,所以此时的基金本币余额会超过用户可提金额.
            value = IERC20(fToken).balanceOf(address(this));
            // 如果计算值比实际取出值大
            if(amount > value)
                amount = value;
            // 如果是最后一个人withdraw
            else if(totalSupply == share)
                amount = value;
        }
        require(amount >= amountMin, 'PSC');

        uint baseAmount = investment.add(investment.mul(baseLine) / 100);
        // 处理基金经理分成和基金分成
        if(amount > baseAmount) {
            uint _manager_fee = (amount.sub(baseAmount)).mul(managerFee) / 100;
            uint _fee = (amount.sub(baseAmount)).mul(FEE) / 100;
            TransferHelper.safeTransfer(fToken, manager, _manager_fee);
            TransferHelper.safeTransfer(fToken, controller, _fee);
            amount = amount.sub(_fee).sub(_manager_fee);
        }
        else if(amount < investment)// 保留亏损的本金
            investment = amount;

        // 处理转账
        investmentOf[msg.sender] = investmentOf[msg.sender].sub(investment);
        totalInvestment = totalInvestment.sub(investment);
        _burn(msg.sender, share);

        if(fToken == WETH9){
            IWETH9(WETH9).withdraw(amount);
            TransferHelper.safeTransferETH(msg.sender, amount);
        } else {
            TransferHelper.safeTransfer(fToken, msg.sender, amount);
        }

        emit Withdraw(msg.sender, amount, share);
    }

    /// @inheritdoc IHotPotV3FundState
    function poolsLength() external override view returns(uint){
        return pools.length;
    }

    /// @inheritdoc IHotPotV3FundState
    function positionsLength(uint poolIndex) external override view returns(uint){
        return positions[poolIndex].length;
    }

    /// @inheritdoc IHotPotV3FundManagerActions
    function setDescriptor(bytes calldata _descriptor) external override onlyController{
        require(_descriptor.length > 0, "DES");
        descriptor = _descriptor;
        emit SetDescriptor(_descriptor);
    }

    /// @inheritdoc IHotPotV3FundManagerActions
    function setDepositDeadline(uint deadline) external override onlyController{
        require(block.timestamp < deadline, "DL");
        depositDeadline = deadline;
        emit SetDeadline(deadline);
    }

    /// @inheritdoc IHotPotV3FundManagerActions
    function setPath(
        address distToken,
        bytes calldata buy,
        bytes calldata sell
    ) external override onlyController{
        // 要修改sellPath, 需要先清空相关pool头寸资产
        if(sellPath[distToken].length > 0){
            for(uint i = 0; i < pools.length; i++){
                IUniswapV3Pool pool = IUniswapV3Pool(pools[i]);
                if(pool.token0() == distToken || pool.token1() == distToken){
                    (uint amount,) = _assetsOfPool(i);
                    require(amount == 0, "AZ");
                }
            }
        }
        TransferHelper.safeApprove(distToken, uniV3Router, 0);
        TransferHelper.safeApprove(distToken, uniV3Router, 2**256-1);
        buyPath[distToken] = buy;
        sellPath[distToken] = sell;
        emit SetPath(distToken, buy);
    }

    /// @inheritdoc IUniswapV3MintCallback
    function uniswapV3MintCallback(
        uint256 amount0Owed,
        uint256 amount1Owed,
        bytes calldata data
    ) external override {
        address pool = pools[abi.decode(data, (uint))];
        require(msg.sender == pool, "MQE");

        // 转账给pool
        if (amount0Owed > 0) TransferHelper.safeTransfer(IUniswapV3Pool(pool).token0(), msg.sender, amount0Owed);
        if (amount1Owed > 0) TransferHelper.safeTransfer(IUniswapV3Pool(pool).token1(), msg.sender, amount1Owed);
    }

    /// @inheritdoc IHotPotV3FundManagerActions
    function init(
        address token0,
        address token1,
        uint24 fee,
        int24 tickLower,
        int24 tickUpper,
        uint amount,
        uint32 maxPIS
    ) external override onlyController returns(uint128 liquidity){
        // 1、检查pool是否有效
        require(tickLower < tickUpper, "ITV");
        require(token0 < token1, "ITV");
        address pool = IUniswapV3Factory(uniV3Factory).getPool(token0, token1, fee);
        require(pool != address(0), "ITF");
        int24 tickspacing = IUniswapV3Pool(pool).tickSpacing();
        require(tickLower % tickspacing == 0, "TLV");
        require(tickUpper % tickspacing == 0, "TUV");

        // 2、添加流动池
        bool hasPool = false;
        uint poolIndex;
        for(uint i = 0; i < pools.length; i++){
            // 存在相同的流动池
            if(pools[i] == pool) {
                hasPool = true;
                poolIndex = i;
                for(uint positionIndex = 0; positionIndex < positions[i].length; positionIndex++) {
                    // 存在相同的头寸, 退出
                    if(positions[i][positionIndex].tickLower == tickLower)
                        if(positions[i][positionIndex].tickUpper == tickUpper)
                            revert();
                }
                break;
            }
        }
        if(!hasPool) {
            pools.push(pool);
            positions.push();
            poolIndex = pools.length - 1;
        }

        //3、新增头寸
        positions[poolIndex].push(Position.Info({
            isEmpty: true,
            tickLower: tickLower,
            tickUpper: tickUpper
        }));

        //4、投资
        if(amount > 0){
            address fToken = token;
            require(IERC20(fToken).balanceOf(address(this)) >= amount, "ATL");
            Position.Info storage position = positions[poolIndex][positions[poolIndex].length - 1];
            liquidity = position.addLiquidity(Position.AddParams({
                poolIndex: poolIndex,
                pool: pool,
                amount: amount,
                amount0Max: 0,
                amount1Max: 0,
                token: fToken,
                uniV3Router: uniV3Router,
                uniV3Factory: uniV3Factory,
                maxSqrtSlippage: maxPIS & 0xffff,
                maxPriceImpact: maxPIS >> 16
            }), sellPath, buyPath);
        }

        emit Init(poolIndex, positions[poolIndex].length - 1, amount);
    }

    /// @inheritdoc IHotPotV3FundManagerActions
    function add(
        uint poolIndex,
        uint positionIndex,
        uint amount,
        bool collect,
        uint32 maxPIS
    ) external override onlyController returns(uint128 liquidity){
        require(IERC20(token).balanceOf(address(this)) >= amount, "ATL");
        require(poolIndex < pools.length, "IPL");
        require(positionIndex < positions[poolIndex].length, "IPS");

        uint amount0Max;
        uint amount1Max;
        Position.Info storage position = positions[poolIndex][positionIndex];
        address pool = pools[poolIndex];
        // 需要复投?
        if(collect) (amount0Max, amount1Max) = position.burnAndCollect(pool, 0);

        liquidity = position.addLiquidity(Position.AddParams({
            poolIndex: poolIndex,
            pool: pool,
            amount: amount,
            amount0Max: amount0Max,
            amount1Max: amount1Max,
            token: token,
            uniV3Router: uniV3Router,
            uniV3Factory: uniV3Factory,
            maxSqrtSlippage: maxPIS & 0xffff,
            maxPriceImpact: maxPIS >> 16
        }), sellPath, buyPath);
        emit Add(poolIndex, positionIndex, amount, collect);
    }

    /// @inheritdoc IHotPotV3FundManagerActions
    function sub(
        uint poolIndex,
        uint positionIndex,
        uint proportionX128,
        uint32 maxPIS
    ) external override onlyController returns(uint amount){
        require(poolIndex < pools.length, "IPL");
        require(positionIndex < positions[poolIndex].length, "IPS");

        amount = positions[poolIndex][positionIndex].subLiquidity(Position.SubParams({
            proportionX128: proportionX128,
            pool: pools[poolIndex],
            token: token,
            uniV3Router: uniV3Router,
            uniV3Factory: uniV3Factory,
            maxSqrtSlippage: maxPIS & 0xffff,
            maxPriceImpact: maxPIS >> 16
        }), sellPath);
        emit Sub(poolIndex, positionIndex, proportionX128);
    }

    /// @inheritdoc IHotPotV3FundManagerActions
    function move(
        uint poolIndex,
        uint subIndex,
        uint addIndex,
        uint proportionX128,
        uint32 maxPIS
    ) external override onlyController returns(uint128 liquidity){
        require(poolIndex < pools.length, "IPL");
        require(subIndex < positions[poolIndex].length, "ISI");
        require(addIndex < positions[poolIndex].length, "IAI");

        // 移除
        (uint amount0Max, uint amount1Max) = positions[poolIndex][subIndex]
            .burnAndCollect(pools[poolIndex], proportionX128);

        // 添加
        liquidity = positions[poolIndex][addIndex].addLiquidity(Position.AddParams({
            poolIndex: poolIndex,
            pool: pools[poolIndex],
            amount: 0,
            amount0Max: amount0Max,
            amount1Max: amount1Max,
            token: token,
            uniV3Router: uniV3Router,
            uniV3Factory: uniV3Factory,
            maxSqrtSlippage: maxPIS & 0xffff,
            maxPriceImpact: maxPIS >> 16
        }), sellPath, buyPath);
        emit Move(poolIndex, subIndex, addIndex, proportionX128);
    }

    /// @inheritdoc IHotPotV3FundState
    function assetsOfPosition(uint poolIndex, uint positionIndex) public override view returns (uint amount) {
        return positions[poolIndex][positionIndex].assets(pools[poolIndex], token, sellPath, uniV3Factory);
    }

    /// @inheritdoc IHotPotV3FundState
    function assetsOfPool(uint poolIndex) public view override returns (uint amount) {
        (amount, ) = _assetsOfPool(poolIndex);
    }

    /// @inheritdoc IHotPotV3FundState
    function totalAssets() public view override returns (uint amount) {
        amount = IERC20(token).balanceOf(address(this));
        for(uint i = 0; i < pools.length; i++){
            uint _amount;
            (_amount, ) = _assetsOfPool(i);
            amount = amount.add(_amount);
        }
    }

    function _assetsOfPool(uint poolIndex) internal view returns (uint amount, uint[] memory) {
        return positions[poolIndex].assetsOfPool(pools[poolIndex], token, sellPath, uniV3Factory);
    }
}

File 30 of 49 : HotPotV3FundDeployer.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;

import './interfaces/IHotPotV3FundDeployer.sol';
import './HotPotV3Fund.sol';

contract HotPotV3FundDeployer is IHotPotV3FundDeployer {
    struct Parameters {
        address WETH9;
        address uniswapV3Factory;
        address uniswapV3Router;
        address controller;
        address manager;
        address token;
        bytes descriptor;
        uint lockPeriod;
        uint baseLine;
        uint managerFee;
    }

    /// @inheritdoc IHotPotV3FundDeployer
    Parameters public override parameters;

    /// @dev Deploys a fund with the given parameters by transiently setting the parameters storage slot and then
    /// clearing it after deploying the fund.
    /// @param controller The controller address
    /// @param manager The manager address of this fund
    /// @param token The local token address
    /// @param descriptor bytes string descriptor, the first 32 bytes manager name + next bytes brief description
    /// @param lockPeriod Fund lock up period
    /// @param baseLine Baseline of fund manager fee ratio
    /// @param managerFee When the ROI is greater than the baseline, the fund manager’s fee ratio
    function deploy(
        address WETH9,
        address uniswapV3Factory,
        address uniswapV3Router,
        address controller,
        address manager,
        address token,
        bytes memory descriptor,
        uint lockPeriod,
        uint baseLine,
        uint managerFee
    ) internal returns (address fund) {
        parameters = Parameters({
            WETH9: WETH9,
            uniswapV3Factory: uniswapV3Factory,
            uniswapV3Router: uniswapV3Router,
            controller: controller,
            manager: manager,
            token: token, 
            descriptor: descriptor,
            lockPeriod: lockPeriod,
            baseLine: baseLine,
            managerFee: managerFee
        });

        fund = address(new HotPotV3Fund{salt: keccak256(abi.encode(manager, token, lockPeriod, baseLine, managerFee))}());
        delete parameters;
    }
}

File 32 of 49 : HotPotV3FundERC20.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.7.6;

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


abstract contract HotPotV3FundERC20 is IHotPotV3FundERC20{
    using LowGasSafeMath for uint;

    string public override constant name = 'Hotpot V3';
    string public override constant symbol = 'HPT-V3';
    uint8 public override constant decimals = 18;
    uint public override totalSupply;

    mapping(address => uint) public override balanceOf;
    mapping(address => mapping(address => uint)) public override allowance;

    constructor() {
    }

    function _mint(address to, uint value) internal {
        require(to != address(0), "ERC20: mint to the zero address");

        totalSupply = totalSupply.add(value);
        balanceOf[to] = balanceOf[to].add(value);
        emit Transfer(address(0), to, value);
    }

    function _burn(address from, uint value) internal {
        require(from != address(0), "ERC20: burn from the zero address");

        balanceOf[from] = balanceOf[from].sub(value);
        totalSupply = totalSupply.sub(value);
        emit Transfer(from, address(0), value);
    }

    function _approve(address owner, address spender, uint value) private {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        allowance[owner][spender] = value;
        emit Approval(owner, spender, value);
    }

    function approve(address spender, uint value) external override returns (bool) {
        _approve(msg.sender, spender, value);
        return true;
    }

    function _transfer(address from, address to, uint value) private {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");

        balanceOf[from] = balanceOf[from].sub(value);
        balanceOf[to] = balanceOf[to].add(value);
        emit Transfer(from, to, value);
    }

    function transfer(address to, uint value) external override returns (bool) {
        _transfer(msg.sender, to, value);
        return true;
    }

    function transferFrom(
        address from, 
        address to, 
        uint value
    ) external override returns (bool) {
        allowance[from][msg.sender] = allowance[from][msg.sender].sub(value);
        _transfer(from, to, value);
        return true;
    }
}

File 33 of 49 : IHotPotV3Fund.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import './IHotPotV3FundERC20.sol';
import './fund/IHotPotV3FundEvents.sol';
import './fund/IHotPotV3FundState.sol';
import './fund/IHotPotV3FundUserActions.sol';
import './fund/IHotPotV3FundManagerActions.sol';

/// @title Hotpot V3 基金接口
/// @notice 接口定义分散在多个接口文件
interface IHotPotV3Fund is 
    IHotPotV3FundERC20, 
    IHotPotV3FundEvents, 
    IHotPotV3FundState, 
    IHotPotV3FundUserActions, 
    IHotPotV3FundManagerActions
{    
}

File 34 of 49 : IHotPotV3FundController.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import './controller/IManagerActions.sol';
import './controller/IGovernanceActions.sol';
import './controller/IControllerState.sol';
import './controller/IControllerEvents.sol';

/// @title Hotpot V3 控制合约接口定义.
/// @notice 基金经理和治理均需通过控制合约进行操作.
interface IHotPotV3FundController is IManagerActions, IGovernanceActions, IControllerState, IControllerEvents {
    /// @notice 基金分成全部用于销毁HPT
    /// @dev 任何人都可以调用本函数
    /// @param token 用于销毁时购买HPT的代币类型
    /// @param amount 代币数量
    /// @return burned 销毁数量
    function harvest(address token, uint amount) external returns(uint burned);
}

File 35 of 49 : IHotPotV3FundDeployer.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title An interface for a contract that is capable of deploying Hotpot V3 Funds
/// @notice A contract that constructs a fund must implement this to pass arguments to the fund
/// @dev This is used to avoid having constructor arguments in the fund contract, which results in the init code hash
/// of the fund being constant allowing the CREATE2 address of the fund to be cheaply computed on-chain
interface IHotPotV3FundDeployer {
    /// @notice Get the parameters to be used in constructing the fund, set transiently during fund creation.
    /// @dev Called by the fund constructor to fetch the parameters of the fund
    /// Returns controller The controller address
    /// Returns manager The manager address of this fund
    /// Returns token The local token address
    /// Returns descriptor bytes string descriptor, the first 32 bytes manager name + next bytes brief description
    /// Returns lockPeriod Fund lock up period
    /// Returns baseLine Baseline of fund manager fee ratio
    /// Returns managerFee When the ROI is greater than the baseline, the fund manager’s fee ratio
    function parameters()
        external
        view
        returns (
            address weth9,
            address uniV3Factory,
            address uniswapV3Router,
            address controller,
            address manager,
            address token,
            bytes memory descriptor,
            uint lockPeriod,
            uint baseLine,
            uint managerFee
        );
}

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

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

/// @title Hotpot V3 基金份额代币接口定义
interface IHotPotV3FundERC20 is IERC20{
    function name() external view returns (string memory);
    function symbol() external view returns (string memory);
    function decimals() external view returns (uint8);
}

File 37 of 49 : IHotPotV3FundFactory.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title The interface for the HotPotFunds V3 Factory
/// @notice The HotPotFunds V3 Factory facilitates creation of HotPotFunds V3 funds
interface IHotPotV3FundFactory {
    /// @notice Emitted when a fund is created
    /// @param manager The manager address of fund
    /// @param token Deposit or withdrawal token supported by the fund
    /// @param fund The fund is created
    event FundCreated(
        address indexed manager,
        address indexed token,
        address indexed fund
    );

    /// @notice Returns the address of WETH9
    function WETH9() external view returns (address);

    /// @notice Returns the address of the Uniswap V3 factory
    function uniV3Factory() external view returns (address);

    /// @notice Returns the address of the Uniswap V3 router
    function uniV3Router() external view returns (address);

    /// @notice fund controller
    function controller() external view returns(address);

    /// @notice Returns the fund address for a given manager and a token, or address 0 if it does not exist
    /// @dev a manager+token mapping a fund
    /// @param manager 管理基金的经理地址
    /// @param token 管理的代币
    /// @param lockPeriod 基金锁定期
    /// @param baseLine 基金经理收费基线
    /// @param managerFee 基金记录分成比例
    /// @return fund 基金地址
    function getFund(address manager, address token, uint lockPeriod, uint baseLine, uint managerFee) external view returns (address fund);

    /// @notice Creates a fund for the given manager and token
    /// @param token 管理的token
    /// @param descriptor 基金名称+描述
    /// @param lockPeriod 基金锁定期
    /// @param baseLine 基金经理收费基准线,高于这个比例的收益,用户在提取时才会被收取费用
    /// @param managerFee 当收益大于基准线时,基金经理的收费比例
    /// @return fund 基金地址
    function createFund(address token, bytes calldata descriptor, uint lockPeriod, uint baseLine, uint managerFee) external returns (address fund);
}

File 38 of 49 : IControllerEvents.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title HotPotV3Controller 事件接口定义
interface IControllerEvents {
    /// @notice 当设置受信任token时触发
    event ChangeVerifiedToken(address indexed token, bool isVerified);

    /// @notice 当调用Harvest时触发
    event Harvest(address indexed token, uint amount, uint burned);

    /// @notice 当调用setHarvestPath时触发
    event SetHarvestPath(address indexed token, bytes path);

    /// @notice 当调用setGovernance时触发
    event SetGovernance(address indexed account);

    /// @notice 当调用setMaxSqrtSlippage时触发
    event SetMaxSqrtSlippage(uint sqrtSlippage);

    /// @notice 当调用setMaxPriceImpact时触发
    event SetMaxPriceImpact(uint priceImpact);
}

File 39 of 49 : IControllerState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title HotPotV3Controller 状态变量及只读函数
interface IControllerState {
    /// @notice Returns the address of the Uniswap V3 router
    function uniV3Router() external view returns (address);

    /// @notice Returns the address of the Uniswap V3 facotry
    function uniV3Factory() external view returns (address);

    /// @notice 本项目治理代币HPT的地址
    function hotpot() external view returns (address);

    /// @notice 治理账户地址
    function governance() external view returns (address);

    /// @notice Returns the address of WETH9
    function WETH9() external view returns (address);

    /// @notice 代币是否受信任
    /// @dev The call will revert if the the token argument is address 0.
    /// @param token 要查询的代币地址
    function verifiedToken(address token) external view returns (bool);

    /// @notice harvest时交易路径
    /// @param token 要兑换的代币
    function harvestPath(address token) external view returns (bytes memory);

    /// @notice 获取swap时最大滑点,取值范围为 0-1e4, 计算公式为:MaxSwapSlippage = (1 - (sqrtSlippage/1e4)^2) * 100%
    ///         如设置最大滑点 0.5%, 则 sqrtSlippage 应设置为9974,此时 MaxSwapSlippage = (1-(9974/1e4)^2)*100% = 0.5% 
    function maxSqrtSlippage() external view returns (uint32);

    /// @notice 获取swap时最大价格影响,取值范围为 0-1e4
    function maxPriceImpact() external view returns (uint32);
}

File 40 of 49 : IGovernanceActions.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title 治理操作接口定义
interface IGovernanceActions {
    /// @notice Change governance
    /// @dev This function can only be called by governance
    /// @param account 新的governance地址
    function setGovernance(address account) external;

    /// @notice Set the token to be verified for all fund, vice versa
    /// @dev This function can only be called by governance
    /// @param token 目标代币
    /// @param isVerified 是否受信任
    function setVerifiedToken(address token, bool isVerified) external;

    /// @notice Set the swap path for harvest
    /// @dev This function can only be called by governance
    /// @param token 目标代币
    /// @param path 路径
    function setHarvestPath(address token, bytes calldata path) external;

    /// @notice 设置swap时最大滑点,取值范围为 0-1e4, 计算公式为:MaxSwapSlippage = (1 - (sqrtSlippage/1e4)^2) * 100%
    ///         如设置最大滑点 0.5%, 则 sqrtSlippage 应设置为9974,此时 MaxSwapSlippage = (1-(9974/1e4)^2)*100% = 0.5% 
    /// @dev This function can only be called by governance
    /// @param sqrtSlippage 0-1e4
    function setMaxSqrtSlippage(uint32 sqrtSlippage) external;

    /// @notice Set the max price impact for swap
    /// @dev This function can only be called by governance
    /// @param priceImpact 0-1e4
    function setMaxPriceImpact(uint32 priceImpact) external;
}

File 41 of 49 : IManagerActions.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import '../fund/IHotPotV3FundManagerActions.sol';

/// @title 控制器合约基金经理操作接口定义
interface IManagerActions {
    /// @notice 设置基金描述信息
    /// @dev This function can only be called by manager 
    /// @param _descriptor 描述信息
    function setDescriptor(address fund, bytes calldata _descriptor) external;

    /// @notice 设置基金存入截止时间
    /// @dev This function can only be called by manager 
    /// @param fund 基金地址
    /// @param deadline 最晚存入截止时间
    function setDepositDeadline(address fund, uint deadline) external;

    /// @notice 设置代币交易路径
    /// @dev This function can only be called by manager 
    /// @dev 设置路径时不能修改为0地址,且path路径里的token必须验证是否受信任
    /// @param fund 基金地址
    /// @param distToken 目标代币地址
    /// @param path 符合uniswap v3格式的交易路径
    function setPath(
        address fund, 
        address distToken, 
        bytes memory path
    ) external;

    /// @notice 初始化头寸, 允许投资额为0.
    /// @dev This function can only be called by manager
    /// @param fund 基金地址
    /// @param token0 token0 地址
    /// @param token1 token1 地址
    /// @param fee 手续费率
    /// @param tickLower 价格刻度下届
    /// @param tickUpper 价格刻度上届
    /// @param amount 初始化投入金额,允许为0, 为0表示仅初始化头寸,不作实质性投资
    /// @param deadline 最晚交易时间
    /// @return liquidity 添加的lp数量
    function init(
        address fund,
        address token0,
        address token1,
        uint24 fee,
        int24 tickLower,
        int24 tickUpper,
        uint amount,
        uint deadline
    ) external returns(uint128 liquidity);

    /// @notice 投资指定头寸,可选复投手续费
    /// @dev This function can only be called by manager 
    /// @param fund 基金地址
    /// @param poolIndex 池子索引号
    /// @param positionIndex 头寸索引号
    /// @param amount 投资金额
    /// @param collect 是否收集已产生的手续费并复投
    /// @param deadline 最晚交易时间
    /// @return liquidity 添加的lp数量
    function add(
        address fund,
        uint poolIndex,
        uint positionIndex, 
        uint amount, 
        bool collect,
        uint deadline
    ) external returns(uint128 liquidity);

    /// @notice 撤资指定头寸
    /// @dev This function can only be called by manager 
    /// @param fund 基金地址
    /// @param poolIndex 池子索引号
    /// @param positionIndex 头寸索引号
    /// @param proportionX128 撤资比例,左移128位; 允许为0,为0表示只收集手续费
    /// @param deadline 最晚交易时间
    /// @return amount 撤资获得的基金本币数量
    function sub(
        address fund,
        uint poolIndex,
        uint positionIndex,
        uint proportionX128,
        uint deadline
    ) external returns(uint amount);

    /// @notice 调整头寸投资
    /// @dev This function can only be called by manager 
    /// @param fund 基金地址
    /// @param poolIndex 池子索引号
    /// @param subIndex 要移除的头寸索引号
    /// @param addIndex 要添加的头寸索引号
    /// @param proportionX128 调整比例,左移128位
    /// @param deadline 最晚交易时间
    /// @return liquidity 调整后添加的lp数量
    function move(
        address fund,
        uint poolIndex,
        uint subIndex, 
        uint addIndex,
        uint proportionX128,
        uint deadline
    ) external returns(uint128 liquidity);
}

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

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


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

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

File 43 of 49 : IHotPotV3FundEvents.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Hotpot V3 事件接口定义
interface IHotPotV3FundEvents {
    /// @notice 当存入基金token时,会触发该事件
    event Deposit(address indexed owner, uint amount, uint share);

    /// @notice 当取走基金token时,会触发该事件
    event Withdraw(address indexed owner, uint amount, uint share);

    /// @notice 当调用setDescriptor时触发
    event SetDescriptor(bytes descriptor);

    /// @notice 当调用setDepositDeadline时触发
    event SetDeadline(uint deadline);

    /// @notice 当调用setPath时触发
    event SetPath(address distToken, bytes path);

    /// @notice 当调用init时,会触发该事件
    event Init(uint poolIndex, uint positionIndex, uint amount);

    /// @notice 当调用add时,会触发该事件
    event Add(uint poolIndex, uint positionIndex, uint amount, bool collect);

    /// @notice 当调用sub时,会触发该事件
    event Sub(uint poolIndex, uint positionIndex, uint proportionX128);

    /// @notice 当调用move时,会触发该事件
    event Move(uint poolIndex, uint subIndex, uint addIndex, uint proportionX128);
}

File 44 of 49 : IHotPotV3FundManagerActions.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @notice 基金经理操作接口定义
interface IHotPotV3FundManagerActions {
    /// @notice 设置基金描述信息
    /// @dev This function can only be called by controller 
    /// @param _descriptor 描述信息
    function setDescriptor(bytes calldata _descriptor) external;

    /// @notice 设置基金存入截止时间
    /// @dev This function can only be called by controller 
    /// @param deadline 最晚存入截止时间
    function setDepositDeadline(uint deadline) external;

    /// @notice 设置代币交易路径
    /// @dev This function can only be called by controller 
    /// @dev 设置路径时不能修改为0地址,且path路径里的token必须验证是否受信任
    /// @param distToken 目标代币地址
    /// @param buy 购买路径(本币->distToken)
    /// @param sell 销售路径(distToken->本币)
    function setPath(
        address distToken, 
        bytes calldata buy,
        bytes calldata sell
    ) external;

    /// @notice 初始化头寸, 允许投资额为0.
    /// @dev This function can only be called by controller
    /// @param token0 token0 地址
    /// @param token1 token1 地址
    /// @param fee 手续费率
    /// @param tickLower 价格刻度下届
    /// @param tickUpper 价格刻度上届
    /// @param amount 初始化投入金额,允许为0, 为0表示仅初始化头寸,不作实质性投资
    /// @param maxPIS 最大价格影响和价格滑点
    /// @return liquidity 添加的lp数量
    function init(
        address token0,
        address token1,
        uint24 fee,
        int24 tickLower,
        int24 tickUpper,
        uint amount,
        uint32 maxPIS
    ) external returns(uint128 liquidity);

    /// @notice 投资指定头寸,可选复投手续费
    /// @dev This function can only be called by controller 
    /// @param poolIndex 池子索引号
    /// @param positionIndex 头寸索引号
    /// @param amount 投资金额
    /// @param collect 是否收集已产生的手续费并复投
    /// @param maxPIS 最大价格影响和价格滑点
    /// @return liquidity 添加的lp数量
    function add(
        uint poolIndex, 
        uint positionIndex, 
        uint amount, 
        bool collect,
        uint32 maxPIS
    ) external returns(uint128 liquidity);

    /// @notice 撤资指定头寸
    /// @dev This function can only be called by controller 
    /// @param poolIndex 池子索引号
    /// @param positionIndex 头寸索引号
    /// @param proportionX128 撤资比例,左移128位; 允许为0,为0表示只收集手续费
    /// @param maxPIS 最大价格影响和价格滑点
    /// @return amount 撤资获得的基金本币数量
    function sub(
        uint poolIndex, 
        uint positionIndex, 
        uint proportionX128,
        uint32 maxPIS
    ) external returns(uint amount);

    /// @notice 调整头寸投资
    /// @dev This function can only be called by controller 
    /// @param poolIndex 池子索引号
    /// @param subIndex 要移除的头寸索引号
    /// @param addIndex 要添加的头寸索引号
    /// @param proportionX128 调整比例,左移128位
    /// @param maxPIS 最大价格影响和价格滑点
    /// @return liquidity 调整后添加的lp数量
    function move(
        uint poolIndex,
        uint subIndex, 
        uint addIndex, 
        uint proportionX128, //以前是按LP数量移除,现在改成按总比例移除,这样前端就不用管实际LP是多少了
        uint32 maxPIS
    ) external  returns(uint128 liquidity);
}

File 45 of 49 : IHotPotV3FundState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Hotpot V3 状态变量及只读函数
interface IHotPotV3FundState {
    /// @notice 控制器合约地址
    function controller() external view returns (address);

    /// @notice 基金经理地址
    function manager() external view returns (address);

    /// @notice 基金本币地址
    function token() external view returns (address);

    /// @notice 32 bytes 基金经理 + 任意长度的简要描述
    function descriptor() external view returns (bytes memory);

    /// @notice 基金锁定期
    function lockPeriod() external view returns (uint);

    /// @notice 基金经理收费基线
    function baseLine() external view returns (uint);

    /// @notice 基金经理收费比例
    function managerFee() external view returns (uint);

    /// @notice 基金存入截止时间
    function depositDeadline() external view returns (uint);

    /// @notice 获取最新存入时间
    /// @param account 目标地址
    /// @return 最新存入时间
    function lastDepositTime(address account) external view returns (uint);

    /// @notice 总投入数量
    function totalInvestment() external view returns (uint);

    /// @notice owner的投入数量
    /// @param owner 用户地址
    /// @return 投入本币的数量
    function investmentOf(address owner) external view returns (uint);

    /// @notice 指定头寸的资产数量
    /// @param poolIndex 池子索引号
    /// @param positionIndex 头寸索引号
    /// @return 以本币计价的头寸资产数量
    function assetsOfPosition(uint poolIndex, uint positionIndex) external view returns(uint);

    /// @notice 指定pool的资产数量
    /// @param poolIndex 池子索引号
    /// @return 以本币计价的池子资产数量
    function assetsOfPool(uint poolIndex) external view returns(uint);

    /// @notice 总资产数量
    /// @return 以本币计价的总资产数量
    function totalAssets() external view returns (uint);

    /// @notice 基金本币->目标代币 的购买路径
    /// @param _token 目标代币地址
    /// @return 符合uniswap v3格式的目标代币购买路径
    function buyPath(address _token) external view returns (bytes memory);

    /// @notice 目标代币->基金本币 的购买路径
    /// @param _token 目标代币地址
    /// @return 符合uniswap v3格式的目标代币销售路径
    function sellPath(address _token) external view returns (bytes memory);

    /// @notice 获取池子地址
    /// @param index 池子索引号
    /// @return 池子地址
    function pools(uint index) external view returns(address);

    /// @notice 头寸信息
    /// @dev 由于基金需要遍历头寸,所以用二维动态数组存储头寸
    /// @param poolIndex 池子索引号
    /// @param positionIndex 头寸索引号
    /// @return isEmpty 是否空头寸,tickLower 价格刻度下届,tickUpper 价格刻度上届
    function positions(uint poolIndex, uint positionIndex) 
        external 
        view 
        returns(
            bool isEmpty,
            int24 tickLower,
            int24 tickUpper 
        );

    /// @notice pool数组长度
    function poolsLength() external view returns(uint);

    /// @notice 指定池子的头寸数组长度
    /// @param poolIndex 池子索引号
    /// @return 头寸数组长度
    function positionsLength(uint poolIndex) external view returns(uint);
}

File 46 of 49 : IHotPotV3FundUserActions.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Hotpot V3 用户操作接口定义
/// @notice 存入(deposit)函数适用于ERC20基金; 如果是ETH基金(内部会转换为WETH9),应直接向基金合约转账;
interface IHotPotV3FundUserActions {
    /// @notice 用户存入基金本币
    /// @param amount 存入数量
    /// @return share 用户获得的基金份额
    function deposit(uint amount) external returns(uint share);

    /// @notice 用户取出指定份额的本币
    /// @param share 取出的基金份额数量
    /// @param amountMin 最小提取值
    /// @param deadline 最晚交易时间
    /// @return amount 返回本币数量
    function withdraw(uint share, uint amountMin, uint deadline) external returns(uint amount);
}

File 47 of 49 : Array2D.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity >=0.7.5;
pragma abicoder v2;

library Array2D {
    /// @notice 取二维数组中最大值及索引
    /// @param self 二维数组
    /// @return index1 一维索引
    /// @return index2 二维索引
    /// @return value 最大值
    function max(uint[][] memory self)
        internal
        pure
        returns(
            uint index1, 
            uint index2, 
            uint value
        )
    {
        for(uint i = 0; i < self.length; i++){
            for(uint j = 0; j < self[i].length; j++){
                if(self[i][j] > value){
                    (index1, index2, value) = (i, j, self[i][j]);
                }
            }
        }
    }
}

File 48 of 49 : FixedPoint64.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.4.0;

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

File 49 of 49 : PathPrice.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity >=0.7.5;
pragma abicoder v2;

import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol';
import '@uniswap/v3-core/contracts/libraries/FullMath.sol';
import "@uniswap/v3-core/contracts/libraries/FixedPoint96.sol";
import "@uniswap/v3-core/contracts/libraries/FixedPoint128.sol";
import "./FixedPoint64.sol";
import '@uniswap/v3-core/contracts/libraries/TickMath.sol';
import "@uniswap/v3-periphery/contracts/libraries/PoolAddress.sol";
import "@uniswap/v3-periphery/contracts/libraries/Path.sol";

library PathPrice {
    using Path for bytes;

    /// @notice 获取目标代币当前价格的平方根
    /// @param path 兑换路径
    /// @return sqrtPriceX96 价格的平方根(X 2^96),给定兑换路径的 tokenOut / tokenIn 的价格
    function getSqrtPriceX96(
        bytes memory path, 
        address uniV3Factory
    ) internal view returns (uint sqrtPriceX96){
        require(path.length > 0, "IPL");

        sqrtPriceX96 = FixedPoint96.Q96;
        uint _nextSqrtPriceX96;
        uint32[] memory secondAges = new uint32[](2);
        secondAges[0] = 0;
        secondAges[1] = 1;
        while (true) {
            (address tokenIn, address tokenOut, uint24 fee) = path.decodeFirstPool();
            IUniswapV3Pool pool = IUniswapV3Pool(PoolAddress.computeAddress(uniV3Factory, PoolAddress.getPoolKey(tokenIn, tokenOut, fee)));

            (_nextSqrtPriceX96,,,,,,) = pool.slot0();
            sqrtPriceX96 = tokenIn > tokenOut
                ? FullMath.mulDiv(sqrtPriceX96, FixedPoint96.Q96, _nextSqrtPriceX96)
                : FullMath.mulDiv(sqrtPriceX96, _nextSqrtPriceX96, FixedPoint96.Q96);

            // decide whether to continue or terminate
            if (path.hasMultiplePools())
                path = path.skipToken();
            else 
                break; 
        }
    }

    /// @notice 获取目标代币预言机价格的平方根
    /// @param path 兑换路径
    /// @return sqrtPriceX96Last 预言机价格的平方根(X 2^96),给定兑换路径的 tokenOut / tokenIn 的价格
    function getSqrtPriceX96Last(
        bytes memory path, 
        address uniV3Factory
    ) internal view returns (uint sqrtPriceX96Last){
        require(path.length > 0, "IPL");

        sqrtPriceX96Last = FixedPoint96.Q96;
        uint _nextSqrtPriceX96;
        uint32[] memory secondAges = new uint32[](2);
        secondAges[0] = 0;
        secondAges[1] = 1;
        while (true) {
            (address tokenIn, address tokenOut, uint24 fee) = path.decodeFirstPool();
            IUniswapV3Pool pool = IUniswapV3Pool(PoolAddress.computeAddress(uniV3Factory, PoolAddress.getPoolKey(tokenIn, tokenOut, fee)));

            // sqrtPriceX96Last
            (int56[] memory tickCumulatives,) = pool.observe(secondAges);
            _nextSqrtPriceX96 = TickMath.getSqrtRatioAtTick(int24(tickCumulatives[0] - tickCumulatives[1]));
            sqrtPriceX96Last = tokenIn > tokenOut
                ? FullMath.mulDiv(sqrtPriceX96Last, FixedPoint96.Q96, _nextSqrtPriceX96)
                : FullMath.mulDiv(sqrtPriceX96Last, _nextSqrtPriceX96, FixedPoint96.Q96);

            // decide whether to continue or terminate
            if (path.hasMultiplePools())
                path = path.skipToken();
            else 
                break;
        }
    }

    /// @notice 验证交易滑点是否满足条件
    /// @param path 兑换路径
    /// @param uniV3Factory uniswap v3 factory
    /// @param maxSqrtSlippage 最大滑点,最大值: 1e4
    /// @return 当前价
    function verifySlippage(
        bytes memory path, 
        address uniV3Factory, 
        uint32 maxSqrtSlippage
    ) internal view returns(uint) { 
        uint last = getSqrtPriceX96Last(path, uniV3Factory);
        uint current = getSqrtPriceX96(path, uniV3Factory);
        if(last > current) require(current > FullMath.mulDiv(maxSqrtSlippage, last, 1e4), "VS");
        return current;
    }
}

File 50 of 49 : Position.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity >=0.7.5;
pragma abicoder v2;

import './PathPrice.sol';
import "@uniswap/v3-core/contracts/libraries/FixedPoint128.sol";
import '@uniswap/v3-periphery/contracts/libraries/PositionKey.sol';
import '@uniswap/v3-core/contracts/libraries/LowGasSafeMath.sol';
import '@uniswap/v3-periphery/contracts/libraries/LiquidityAmounts.sol';
import '@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol';
import "@uniswap/v3-core/contracts/libraries/SqrtPriceMath.sol";

library Position {
    using LowGasSafeMath for uint;
    using SafeCast for int256;
    // using Path for bytes;

    uint constant DIVISOR = 100 << 128;

    // info stored for each user's position
    struct Info {
        bool isEmpty;
        int24 tickLower;
        int24 tickUpper;
    }

    /// @notice 计算将t0最大化添加到pool的LP时,需要的t0, t1数量
    /// @dev 计算公式:△x0 = △x /( SPu*(SPc - SPl) / (SPc*(SPu - SPc)) + 1)
    function getAmountsForAmount0(
        uint160 sqrtPriceX96, 
        uint160 sqrtPriceL96,
        uint160 sqrtPriceU96,
        uint deltaX
    ) internal pure returns(uint amount0, uint amount1){
        // 全部是t0
        if(sqrtPriceX96 <= sqrtPriceL96){
            amount0 = deltaX;
        }
        // 部分t0
        else if( sqrtPriceX96 < sqrtPriceU96){
            // a = SPu*(SPc - SPl)
            uint a = FullMath.mulDiv(sqrtPriceU96, sqrtPriceX96 - sqrtPriceL96, FixedPoint64.Q64);
            // b = SPc*(SPu - SPc)
            uint b = FullMath.mulDiv(sqrtPriceX96, sqrtPriceU96 - sqrtPriceX96, FixedPoint64.Q64);
            // △x0 = △x/(a/b +1) = △x*b/(a+b)
            amount0 = FullMath.mulDiv(deltaX, b, a + b);
        }
        // 剩余的转成t1
        if(deltaX > amount0){
            amount1 = FullMath.mulDiv(
                deltaX.sub(amount0), 
                FullMath.mulDiv(sqrtPriceX96, sqrtPriceX96, FixedPoint64.Q64), 
                FixedPoint128.Q128
            );
        }
    }

    /// @notice 计算最小兑换输出值
    /// @param curSqrtPirceX96 当前价
    /// @param maxPriceImpact 最大价格影响
    /// @param amountIn 输入数里
    function getAmountOutMin(
        uint curSqrtPirceX96, 
        uint maxPriceImpact, 
        uint amountIn
    ) internal pure returns(uint amountOutMin){
        amountOutMin = FullMath.mulDiv(
            FullMath.mulDiv(amountIn, FullMath.mulDiv(curSqrtPirceX96, curSqrtPirceX96, FixedPoint64.Q64), FixedPoint128.Q128), 
            1e4 - maxPriceImpact, // maxPriceImpact最大1e4,不会溢出
            1e4);
    }

    struct SwapParams{
        uint amount;
        uint amount0;
        uint amount1;
        uint160 sqrtPriceX96;
        uint160 sqrtRatioAX96;
        uint160 sqrtRatioBX96;
        address token;
        address token0;
        address token1;
        uint24 fee;
        address uniV3Factory;
        address uniV3Router;
        uint32 maxSqrtSlippage;
        uint32 maxPriceImpact;
    }

    /// @notice 根据基金本币数量以及收集的手续费数量, 计算投资指定头寸两种代币的分布.
    function computeSwapAmounts(
        SwapParams memory params,
        mapping(address => bytes) storage buyPath
    ) internal returns(uint amount0Max, uint amount1Max) {
        uint equalAmount0;
        bytes memory buy0Path;
        bytes memory buy1Path;
        uint buy0SqrtPriceX96;
        uint buy1SqrtPriceX96;
        uint amountIn;

        //将基金本币换算成token0
        if(params.amount > 0){
            if(params.token == params.token0){
                buy1Path = buyPath[params.token1];
                buy1SqrtPriceX96 = PathPrice.verifySlippage(buy1Path, params.uniV3Factory, params.maxSqrtSlippage);
                equalAmount0 = params.amount0.add(params.amount);
            } else {
                buy0Path = buyPath[params.token0];
                buy0SqrtPriceX96 = PathPrice.verifySlippage(buy0Path, params.uniV3Factory, params.maxSqrtSlippage);
                if(params.token != params.token1) {
                    buy1Path = buyPath[params.token1];
                    buy1SqrtPriceX96 = PathPrice.verifySlippage(buy1Path, params.uniV3Factory, params.maxSqrtSlippage);
                }
                equalAmount0 = params.amount0.add((FullMath.mulDiv(
                    params.amount,
                    FullMath.mulDiv(buy0SqrtPriceX96, buy0SqrtPriceX96, FixedPoint64.Q64),
                    FixedPoint128.Q128
                )));
            }
        } 
        else  equalAmount0 = params.amount0;

        //将token1换算成token0
        if(params.amount1 > 0){
            equalAmount0 = equalAmount0.add((FullMath.mulDiv(
                params.amount1,
                FixedPoint128.Q128,
                FullMath.mulDiv(params.sqrtPriceX96, params.sqrtPriceX96, FixedPoint64.Q64)
            )));
        }
        require(equalAmount0 > 0, "EIZ");

        // 计算需要的t0、t1数量
        (amount0Max, amount1Max) = getAmountsForAmount0(params.sqrtPriceX96, params.sqrtRatioAX96, params.sqrtRatioBX96, equalAmount0);

        // t0不够,需要补充
        if(amount0Max > params.amount0) {
            //t1也不够,基金本币需要兑换成t0和t1
            if(amount1Max > params.amount1){
                // 基金本币兑换成token0
                if(params.token0 == params.token){
                    amountIn = amount0Max - params.amount0;
                    if(amountIn > params.amount) amountIn = params.amount;
                    amount0Max = params.amount0.add(amountIn);
                } else {
                    amountIn = FullMath.mulDiv(
                        amount0Max - params.amount0,
                        FixedPoint128.Q128,
                        FullMath.mulDiv(buy0SqrtPriceX96, buy0SqrtPriceX96, FixedPoint64.Q64)
                    );
                    if(amountIn > params.amount) amountIn = params.amount;
                    if(amountIn > 0) {
                        uint amountOutMin = getAmountOutMin(buy0SqrtPriceX96, params.maxPriceImpact, amountIn);
                        amount0Max = params.amount0.add(ISwapRouter(params.uniV3Router).exactInput(ISwapRouter.ExactInputParams({
                            path: buy0Path,
                            recipient: address(this),
                            deadline: block.timestamp,
                            amountIn: amountIn,
                            amountOutMinimum: amountOutMin
                        })));
                    } else amount0Max = params.amount0;
                }
                // 基金本币兑换成token1
                if(params.token1 == params.token){
                    amount1Max = params.amount1.add(params.amount.sub(amountIn));
                } else {
                    if(amountIn < params.amount){
                        amountIn = params.amount.sub(amountIn);
                        uint amountOutMin = getAmountOutMin(buy1SqrtPriceX96, params.maxPriceImpact, amountIn);
                        amount1Max = params.amount1.add(ISwapRouter(params.uniV3Router).exactInput(ISwapRouter.ExactInputParams({
                            path: buy1Path,
                            recipient: address(this),
                            deadline: block.timestamp,
                            amountIn: amountIn,
                            amountOutMinimum: amountOutMin
                        })));
                    } 
                    else amount1Max = params.amount1;
                }
            }
            // t1多了,多余的t1需要兑换成t0,基金本币全部兑换成t0
            else {
                // 基金本币全部兑换成t0
                if (params.amount > 0){
                    if(params.token0 == params.token){
                        amount0Max = params.amount0.add(params.amount);
                    } else{
                        uint amountOutMin = getAmountOutMin(buy0SqrtPriceX96, params.maxPriceImpact, params.amount);
                        amount0Max = params.amount0.add(ISwapRouter(params.uniV3Router).exactInput(ISwapRouter.ExactInputParams({
                            path: buy0Path,
                            recipient: address(this),
                            deadline: block.timestamp,
                            amountIn: params.amount,
                            amountOutMinimum: amountOutMin
                        })));
                    }
                } else amount0Max = params.amount0;

                // 多余的t1兑换成t0
                if(params.amount1 > amount1Max) {
                    amountIn = params.amount1.sub(amount1Max);
                    buy0Path = abi.encodePacked(params.token1, params.fee, params.token0);
                    buy0SqrtPriceX96 = FixedPoint96.Q96 * FixedPoint96.Q96 / params.sqrtPriceX96;// 不会出现溢出
                    uint lastSqrtPriceX96 = PathPrice.getSqrtPriceX96Last(buy0Path, params.uniV3Factory);
                    if(lastSqrtPriceX96 > buy0SqrtPriceX96) 
                        require(buy0SqrtPriceX96 > params.maxSqrtSlippage * lastSqrtPriceX96 / 1e4, "VS");// 不会出现溢出
                    uint amountOutMin = getAmountOutMin(buy0SqrtPriceX96, params.maxPriceImpact, amountIn);
                    amount0Max = amount0Max.add(ISwapRouter(params.uniV3Router).exactInput(ISwapRouter.ExactInputParams({
                        path: buy0Path,
                        recipient: address(this),
                        deadline: block.timestamp,
                        amountIn: amountIn,
                        amountOutMinimum: amountOutMin
                    })));
                }
            }
        }
        // t0多了,多余的t0兑换成t1, 基金本币全部兑换成t1
        else {
            // 基金本币全部兑换成t1
            if(params.amount > 0){
                if(params.token1 == params.token){
                    amount1Max = params.amount1.add(params.amount);
                } else {
                    uint amountOutMin = getAmountOutMin(buy1SqrtPriceX96, params.maxPriceImpact, params.amount);
                    amount1Max = params.amount1.add(ISwapRouter(params.uniV3Router).exactInput(ISwapRouter.ExactInputParams({
                        path: buy1Path,
                        recipient: address(this),
                        deadline: block.timestamp,
                        amountIn: params.amount,
                        amountOutMinimum: amountOutMin
                    })));
                }
            } else amount1Max = params.amount1;

            // 多余的t0兑换成t1
            if(params.amount0 > amount0Max){
                amountIn = params.amount0.sub(amount0Max);
                buy1Path = abi.encodePacked(params.token0, params.fee, params.token1);
                buy1SqrtPriceX96 = params.sqrtPriceX96;
                uint lastSqrtPriceX96 = PathPrice.getSqrtPriceX96Last(buy1Path, params.uniV3Factory);
                if(lastSqrtPriceX96 > buy1SqrtPriceX96) 
                    require(buy1SqrtPriceX96 > params.maxSqrtSlippage * lastSqrtPriceX96 / 1e4, "VS");// 不会出现溢出
                uint amountOutMin = getAmountOutMin(buy1SqrtPriceX96, params.maxPriceImpact, amountIn);
                amount1Max = amount1Max.add(ISwapRouter(params.uniV3Router).exactInput(ISwapRouter.ExactInputParams({
                    path: buy1Path,
                    recipient: address(this),
                    deadline: block.timestamp,
                    amountIn: amountIn,
                    amountOutMinimum: amountOutMin
                })));
            }
        }
    }

    struct AddParams {
        // pool信息
        uint poolIndex;
        address pool;
        // 要投入的基金本币和数量
        address token;
        uint amount;
        // 要投入的token0、token1数量
        uint amount0Max;
        uint amount1Max;
        //UNISWAP_V3_ROUTER
        address uniV3Router;
        address uniV3Factory;
        uint32 maxSqrtSlippage;
        uint32 maxPriceImpact;
    }

    /// @notice 添加LP到指定Position
    /// @param self Position.Info
    /// @param params 投资信息
    /// @param sellPath sell token路径
    /// @param buyPath buy token路径
    function addLiquidity(
        Info storage self,
        AddParams memory params,
        mapping(address => bytes) storage sellPath,
        mapping(address => bytes) storage buyPath
    ) public returns(uint128 liquidity) {
        (int24 tickLower, int24 tickUpper) = (self.tickLower, self.tickUpper);

        (uint160 sqrtPriceX96,,,,,,) = IUniswapV3Pool(params.pool).slot0();

        SwapParams memory swapParams = SwapParams({
            amount: params.amount,
            amount0: params.amount0Max,
            amount1: params.amount1Max,
            sqrtPriceX96: sqrtPriceX96,
            sqrtRatioAX96: TickMath.getSqrtRatioAtTick(tickLower),
            sqrtRatioBX96: TickMath.getSqrtRatioAtTick(tickUpper),
            token: params.token,
            token0: IUniswapV3Pool(params.pool).token0(),
            token1: IUniswapV3Pool(params.pool).token1(),
            fee: IUniswapV3Pool(params.pool).fee(),
            uniV3Router: params.uniV3Router,
            uniV3Factory: params.uniV3Factory,
            maxSqrtSlippage: params.maxSqrtSlippage,
            maxPriceImpact: params.maxPriceImpact
        });
        (params.amount0Max,  params.amount1Max) = computeSwapAmounts(swapParams, buyPath);

        //因为滑点,重新加载sqrtPriceX96
        (sqrtPriceX96,,,,,,) = IUniswapV3Pool(params.pool).slot0();

        //推算实际的liquidity
        liquidity = LiquidityAmounts.getLiquidityForAmounts(sqrtPriceX96, swapParams.sqrtRatioAX96, swapParams.sqrtRatioBX96, params.amount0Max, params.amount1Max);

        require(liquidity > 0, "LIZ");
        (uint amount0, uint amount1) = IUniswapV3Pool(params.pool).mint(
            address(this),// LP recipient
            tickLower,
            tickUpper,
            liquidity,
            abi.encode(params.poolIndex)
        );

        //处理没有添加进LP的token余额,兑换回基金本币
        if(amount0 < params.amount0Max){
            if(swapParams.token0 != params.token){
                ISwapRouter(params.uniV3Router).exactInput(ISwapRouter.ExactInputParams({
                    path: sellPath[swapParams.token0],
                    recipient: address(this),
                    deadline: block.timestamp,
                    amountIn: params.amount0Max - amount0,
                    amountOutMinimum: 0
                }));
            }
        }
        if(amount1 < params.amount1Max){
            if(swapParams.token1 != params.token){
                ISwapRouter(params.uniV3Router).exactInput(ISwapRouter.ExactInputParams({
                    path: sellPath[swapParams.token1],
                    recipient: address(this),
                    deadline: block.timestamp,
                    amountIn: params.amount1Max - amount1,
                    amountOutMinimum: 0
                }));
            }
        }

        if(self.isEmpty) self.isEmpty = false;
    }

    /// @notice brun指定头寸的LP,并取回2种代币
    /// @param pool UniswapV3Pool
    /// @param proportionX128 burn所占份额
    /// @return amount0 获得的token0数量
    /// @return amount1 获得的token1数量
    function burnAndCollect(
        Info storage self,
        address pool,
        uint proportionX128
    ) public returns(uint amount0, uint amount1) {
        require(proportionX128 <= DIVISOR, "PTL");

        // 如果是空头寸,直接返回0,0
        if(self.isEmpty == true) return(amount0, amount1);

        int24 tickLower = self.tickLower;
        int24 tickUpper = self.tickUpper;

        IUniswapV3Pool _pool = IUniswapV3Pool(pool);
        if(proportionX128 > 0) {
            (uint sumLP, , , , ) = _pool.positions(PositionKey.compute(address(this), tickLower, tickUpper));
            uint subLP = FullMath.mulDiv(proportionX128, sumLP, DIVISOR);

            _pool.burn(tickLower, tickUpper, uint128(subLP));
            (amount0, amount1) = _pool.collect(address(this), tickLower,  tickUpper, type(uint128).max, type(uint128).max);

            if(sumLP == subLP) self.isEmpty = true;
        }
        //为0表示只提取手续费
        else {
            _pool.burn(tickLower, tickUpper, 0);
            (amount0, amount1) = _pool.collect(address(this), tickLower,  tickUpper, type(uint128).max, type(uint128).max);
        }
    }

    struct SubParams {
        //pool信息
        address pool;
        //基金本币和移除占比
        address token;
        uint proportionX128;
        //UNISWAP_V3_ROUTER
        address uniV3Router;
        address uniV3Factory;
        uint32 maxSqrtSlippage;
        uint32 maxPriceImpact;
    }

    /// @notice 减少指定头寸LP,并取回本金本币
    /// @param self 指定头寸
    /// @param params 流动池和要减去的数量
    /// @return amount 获取的基金本币数量
    function subLiquidity (
        Info storage self,
        SubParams memory params,
        mapping(address => bytes) storage sellPath
    ) public returns(uint amount) {
        address token0 = IUniswapV3Pool(params.pool).token0();
        address token1 = IUniswapV3Pool(params.pool).token1();
        uint sqrtPriceX96;
        uint sqrtPriceX96Last;
        uint amountOutMin;

        // 验证本池子的滑点
        if(params.maxSqrtSlippage <= 1e4){
            // t0到t1的滑点
            (sqrtPriceX96,,,,,,) = IUniswapV3Pool(params.pool).slot0();
            uint32[] memory secondAges = new uint32[](2);
            secondAges[0] = 0;
            secondAges[1] = 1;
            (int56[] memory tickCumulatives,) = IUniswapV3Pool(params.pool).observe(secondAges);
            sqrtPriceX96Last = TickMath.getSqrtRatioAtTick(int24(tickCumulatives[0] - tickCumulatives[1]));
            if(sqrtPriceX96Last > sqrtPriceX96)
                require(sqrtPriceX96 > params.maxSqrtSlippage * sqrtPriceX96Last / 1e4, "VS");// 不会出现溢出
            
            // t1到t0的滑点
            sqrtPriceX96 = FixedPoint96.Q96 * FixedPoint96.Q96 / sqrtPriceX96; // 不会出现溢出
            sqrtPriceX96Last = FixedPoint96.Q96 * FixedPoint96.Q96 / sqrtPriceX96Last; 
            if(sqrtPriceX96Last > sqrtPriceX96)
                require(sqrtPriceX96 > params.maxSqrtSlippage * sqrtPriceX96Last / 1e4, "VS"); // 不会出现溢出
        }

        // burn & collect
        (uint amount0, uint amount1) = burnAndCollect(self, params.pool, params.proportionX128);

        // t0兑换成基金本币
        if(token0 != params.token){
            if(amount0 > 0){
                bytes memory path = sellPath[token0];
                if(params.maxSqrtSlippage <= 1e4) {
                    sqrtPriceX96 = PathPrice.verifySlippage(path, params.uniV3Factory, params.maxSqrtSlippage);
                    amountOutMin = getAmountOutMin(sqrtPriceX96, params.maxPriceImpact, amount0);    
                }
                amount = ISwapRouter(params.uniV3Router).exactInput(ISwapRouter.ExactInputParams({
                    path: path,
                    recipient: address(this),
                    deadline: block.timestamp,
                    amountIn: amount0,
                    amountOutMinimum: amountOutMin
                }));
            }
        }

        // t1兑换成基金本币
        if(token1 != params.token){
            if(amount1 > 0){
                bytes memory path = sellPath[token1];
                if(params.maxSqrtSlippage <= 1e4) {
                    sqrtPriceX96 = PathPrice.verifySlippage(path, params.uniV3Factory, params.maxSqrtSlippage);
                    amountOutMin = getAmountOutMin(sqrtPriceX96, params.maxPriceImpact, amount1);    
                }
                amount = amount.add(ISwapRouter(params.uniV3Router).exactInput(ISwapRouter.ExactInputParams({
                    path: path,
                    recipient: address(this),
                    deadline: block.timestamp,
                    amountIn: amount1,
                    amountOutMinimum: amountOutMin
                })));
            }
        }
    }

    /// @notice 封装成结构体的函数局部变量,避免堆栈过深报错.
    struct AssetsParams {
        address token0;
        address token1;
        uint sqrt0;
        uint sqrt1;
        uint160 sqrtPriceX96;
        int24 tick;
        uint256 feeGrowthGlobal0X128;
        uint256 feeGrowthGlobal1X128;
    }

    /// @notice 获取某个流动池(pool),以基金本币衡量的所有资产
    /// @param  pool 流动池地址
    /// @return amount 资产数量
    function assetsOfPool(
        Info[] storage self,
        address pool,
        address token,
        mapping(address => bytes) storage sellPath,
        address uniV3Factory
    ) public view returns (uint amount, uint[] memory) {
        uint[] memory amounts = new uint[](self.length);
        // 局部变量都是为了减少ssload消耗.
        AssetsParams memory params;
        // 获取两种token的本币价格.
        params.token0 = IUniswapV3Pool(pool).token0();
        params.token1 = IUniswapV3Pool(pool).token1();
        if(params.token0 != token){
            bytes memory path = sellPath[params.token0];
            if(path.length == 0) return(amount, amounts);
            params.sqrt0 = PathPrice.getSqrtPriceX96Last(path, uniV3Factory);
        }
        if(params.token1 != token){
            bytes memory path = sellPath[params.token1];
            if(path.length == 0) return(amount, amounts);
            params.sqrt1 = PathPrice.getSqrtPriceX96Last(path, uniV3Factory);
        }

        (params.sqrtPriceX96, params.tick, , , , , ) = IUniswapV3Pool(pool).slot0();
        params.feeGrowthGlobal0X128 = IUniswapV3Pool(pool).feeGrowthGlobal0X128();
        params.feeGrowthGlobal1X128 = IUniswapV3Pool(pool).feeGrowthGlobal1X128();

        for(uint i=0; i < self.length; i++){
            Position.Info memory position = self[i];
            if(position.isEmpty) continue;
            bytes32 positionKey = keccak256(abi.encodePacked(address(this), position.tickLower, position.tickUpper));
            // 获取token0, token1的资产数量
            (uint256 _amount0, uint256 _amount1) =
                getAssetsOfSinglePosition(
                    AssetsOfSinglePosition({
                        pool: pool,
                        positionKey: positionKey,
                        tickLower: position.tickLower,
                        tickUpper: position.tickUpper,
                        tickCurrent: params.tick,
                        sqrtPriceX96: params.sqrtPriceX96,
                        feeGrowthGlobal0X128: params.feeGrowthGlobal0X128,
                        feeGrowthGlobal1X128: params.feeGrowthGlobal1X128
                    })
                );

            // 计算成本币资产.
            uint _amount;
            if(params.token0 != token){
                _amount = FullMath.mulDiv(
                    _amount0,
                    FullMath.mulDiv(params.sqrt0, params.sqrt0, FixedPoint64.Q64),
                    FixedPoint128.Q128);
            }
            else
                _amount = _amount0;

            if(params.token1 != token){
                _amount = _amount.add(FullMath.mulDiv(
                    _amount1,
                    FullMath.mulDiv(params.sqrt1, params.sqrt1, FixedPoint64.Q64),
                    FixedPoint128.Q128));
            }
            else
                _amount = _amount.add(_amount1);

            amounts[i] = _amount;
            amount = amount.add(_amount);
        }
        return(amount, amounts);
    }

    /// @notice 获取某个头寸,以基金本币衡量的所有资产
    /// @param pool 交易池索引号
    /// @param token 头寸索引号
    /// @return amount 资产数量
    function assets(
        Info storage self,
        address pool,
        address token,
        mapping(address => bytes) storage sellPath,
        address uniV3Factory
    ) public view returns (uint amount) {
        if(self.isEmpty) return 0;

        // 不需要校验 pool 是否存在
        (uint160 sqrtPriceX96, int24 tick, , , , , ) = IUniswapV3Pool(pool).slot0();

        bytes32 positionKey = keccak256(abi.encodePacked(address(this), self.tickLower, self.tickUpper));

        // 获取token0, token1的资产数量
        (uint256 amount0, uint256 amount1) =
            getAssetsOfSinglePosition(
                AssetsOfSinglePosition({
                    pool: pool,
                    positionKey: positionKey,
                    tickLower: self.tickLower,
                    tickUpper: self.tickUpper,
                    tickCurrent: tick,
                    sqrtPriceX96: sqrtPriceX96,
                    feeGrowthGlobal0X128: IUniswapV3Pool(pool).feeGrowthGlobal0X128(),
                    feeGrowthGlobal1X128: IUniswapV3Pool(pool).feeGrowthGlobal1X128()
                })
            );

        // 计算以本币衡量的资产.
        if(amount0 > 0){
            address token0 = IUniswapV3Pool(pool).token0();
            if(token0 != token){
                uint sqrt0 = PathPrice.getSqrtPriceX96Last(sellPath[token0], uniV3Factory);
                amount = FullMath.mulDiv(
                    amount0,
                    FullMath.mulDiv(sqrt0, sqrt0, FixedPoint64.Q64),
                    FixedPoint128.Q128);
            } else
                amount = amount0;
        }
        if(amount1 > 0){
            address token1 = IUniswapV3Pool(pool).token1();
            if(token1 != token){
                uint sqrt1 = PathPrice.getSqrtPriceX96Last(sellPath[token1], uniV3Factory);
                amount = amount.add(FullMath.mulDiv(
                    amount1,
                    FullMath.mulDiv(sqrt1, sqrt1, FixedPoint64.Q64),
                    FixedPoint128.Q128));
            } else
                amount = amount.add(amount1);
        }
    }

    /// @notice 封装成结构体的函数调用参数.
    struct AssetsOfSinglePosition {
        // 交易对地址.
        address pool;
        // 头寸ID
        bytes32 positionKey;
        // 价格刻度下届
        int24 tickLower;
        // 价格刻度上届
        int24 tickUpper;
        // 当前价格刻度
        int24 tickCurrent;
        // 当前价格
        uint160 sqrtPriceX96;
        // 全局手续费变量(token0)
        uint256 feeGrowthGlobal0X128;
        // 全局手续费变量(token1)
        uint256 feeGrowthGlobal1X128;
    }

    /// @notice 获取某个头寸的全部资产,包括未计算进tokensOwed的手续费.
    /// @param params 封装成结构体的函数调用参数.
    /// @return amount0 token0的数量
    /// @return amount1 token1的数量
    function getAssetsOfSinglePosition(AssetsOfSinglePosition memory params)
        internal
        view
        returns (uint256 amount0, uint256 amount1)
    {
        (
            uint128 liquidity,
            uint256 feeGrowthInside0LastX128,
            uint256 feeGrowthInside1LastX128,
            uint128 tokensOwed0,
            uint128 tokensOwed1
        ) = IUniswapV3Pool(params.pool).positions(params.positionKey);

        // 计算未计入tokensOwed的手续费
        (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128) =
            getFeeGrowthInside(
                FeeGrowthInsideParams({
                    pool: params.pool,
                    tickLower: params.tickLower,
                    tickUpper: params.tickUpper,
                    tickCurrent: params.tickCurrent,
                    feeGrowthGlobal0X128: params.feeGrowthGlobal0X128,
                    feeGrowthGlobal1X128: params.feeGrowthGlobal1X128
                })
            );

        // calculate accumulated fees
        amount0 =
            uint256(
                FullMath.mulDiv(
                    feeGrowthInside0X128 - feeGrowthInside0LastX128,
                    liquidity,
                    FixedPoint128.Q128
                )
            );
        amount1 =
            uint256(
                FullMath.mulDiv(
                    feeGrowthInside1X128 - feeGrowthInside1LastX128,
                    liquidity,
                    FixedPoint128.Q128
                )
            );

        // 计算总的手续费.
        // overflow is acceptable, have to withdraw before you hit type(uint128).max fees
        amount0 = amount0.add(tokensOwed0);
        amount1 = amount1.add(tokensOwed1);

        // 计算流动性资产
        if (params.tickCurrent < params.tickLower) {
            // current tick is below the passed range; liquidity can only become in range by crossing from left to
            // right, when we'll need _more_ token0 (it's becoming more valuable) so user must provide it
            amount0 = amount0.add(uint256(
                -SqrtPriceMath.getAmount0Delta(
                    TickMath.getSqrtRatioAtTick(params.tickLower),
                    TickMath.getSqrtRatioAtTick(params.tickUpper),
                    -int256(liquidity).toInt128()
                )
            ));
        } else if (params.tickCurrent < params.tickUpper) {
            // current tick is inside the passed range
            amount0 = amount0.add(uint256(
                -SqrtPriceMath.getAmount0Delta(
                    params.sqrtPriceX96,
                    TickMath.getSqrtRatioAtTick(params.tickUpper),
                    -int256(liquidity).toInt128()
                )
            ));
            amount1 = amount1.add(uint256(
                -SqrtPriceMath.getAmount1Delta(
                    TickMath.getSqrtRatioAtTick(params.tickLower),
                    params.sqrtPriceX96,
                    -int256(liquidity).toInt128()
                )
            ));
        } else {
            // current tick is above the passed range; liquidity can only become in range by crossing from right to
            // left, when we'll need _more_ token1 (it's becoming more valuable) so user must provide it
            amount1 = amount1.add(uint256(
                -SqrtPriceMath.getAmount1Delta(
                    TickMath.getSqrtRatioAtTick(params.tickLower),
                    TickMath.getSqrtRatioAtTick(params.tickUpper),
                    -int256(liquidity).toInt128()
                )
            ));
        }
    }

    /// @notice 封装成结构体的函数调用参数.
    struct FeeGrowthInsideParams {
        // 交易对地址
        address pool;
        // The lower tick boundary of the position
        int24 tickLower;
        // The upper tick boundary of the position
        int24 tickUpper;
        // The current tick
        int24 tickCurrent;
        // The all-time global fee growth, per unit of liquidity, in token0
        uint256 feeGrowthGlobal0X128;
        // The all-time global fee growth, per unit of liquidity, in token1
        uint256 feeGrowthGlobal1X128;
    }

    /// @notice Retrieves fee growth data
    /// @param params 封装成结构体的函数调用参数.
    /// @return feeGrowthInside0X128 The all-time fee growth in token0, per unit of liquidity, inside the position's tick boundaries
    /// @return feeGrowthInside1X128 The all-time fee growth in token1, per unit of liquidity, inside the position's tick boundaries
    function getFeeGrowthInside(FeeGrowthInsideParams memory params)
        internal
        view
        returns (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128)
    {
        IUniswapV3Pool _pool = IUniswapV3Pool (params.pool);
        // calculate fee growth below
        uint256 lower_feeGrowthOutside0X128;
        uint256 lower_feeGrowthOutside1X128;
        ( , , lower_feeGrowthOutside0X128, lower_feeGrowthOutside1X128, , , ,)
            = _pool.ticks(params.tickLower);

        uint256 feeGrowthBelow0X128;
        uint256 feeGrowthBelow1X128;
        if (params.tickCurrent >= params.tickLower) {
            feeGrowthBelow0X128 = lower_feeGrowthOutside0X128;
            feeGrowthBelow1X128 = lower_feeGrowthOutside1X128;
        } else {
            feeGrowthBelow0X128 = params.feeGrowthGlobal0X128 - lower_feeGrowthOutside0X128;
            feeGrowthBelow1X128 = params.feeGrowthGlobal1X128 - lower_feeGrowthOutside1X128;
        }

        // calculate fee growth above
        uint256 upper_feeGrowthOutside0X128;
        uint256 upper_feeGrowthOutside1X128;
        ( , , upper_feeGrowthOutside0X128, upper_feeGrowthOutside1X128, , , , ) =
            _pool.ticks(params.tickUpper);

        uint256 feeGrowthAbove0X128;
        uint256 feeGrowthAbove1X128;
        if (params.tickCurrent < params.tickUpper) {
            feeGrowthAbove0X128 = upper_feeGrowthOutside0X128;
            feeGrowthAbove1X128 = upper_feeGrowthOutside1X128;
        } else {
            feeGrowthAbove0X128 = params.feeGrowthGlobal0X128 - upper_feeGrowthOutside0X128;
            feeGrowthAbove1X128 = params.feeGrowthGlobal1X128 - upper_feeGrowthOutside1X128;
        }

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

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 800
  },
  "evmVersion": "istanbul",
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {
    "contracts/libraries/Position.sol": {
      "Position": "0x39c2c8a21aed056b9549c81ce125886edb57af00"
    }
  }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_controller","type":"address"},{"internalType":"address","name":"_weth9","type":"address"},{"internalType":"address","name":"_uniV3Factory","type":"address"},{"internalType":"address","name":"_uniV3Router","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"manager","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":true,"internalType":"address","name":"fund","type":"address"}],"name":"FundCreated","type":"event"},{"inputs":[],"name":"WETH9","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"controller","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"bytes","name":"descriptor","type":"bytes"},{"internalType":"uint256","name":"lockPeriod","type":"uint256"},{"internalType":"uint256","name":"baseLine","type":"uint256"},{"internalType":"uint256","name":"managerFee","type":"uint256"}],"name":"createFund","outputs":[{"internalType":"address","name":"fund","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"manager","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"lockPeriod","type":"uint256"},{"internalType":"uint256","name":"baseLine","type":"uint256"},{"internalType":"uint256","name":"managerFee","type":"uint256"}],"name":"getFund","outputs":[{"internalType":"address","name":"fund","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"parameters","outputs":[{"internalType":"address","name":"WETH9","type":"address"},{"internalType":"address","name":"uniswapV3Factory","type":"address"},{"internalType":"address","name":"uniswapV3Router","type":"address"},{"internalType":"address","name":"controller","type":"address"},{"internalType":"address","name":"manager","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"bytes","name":"descriptor","type":"bytes"},{"internalType":"uint256","name":"lockPeriod","type":"uint256"},{"internalType":"uint256","name":"baseLine","type":"uint256"},{"internalType":"uint256","name":"managerFee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"uniV3Factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"uniV3Router","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

61010060405234801561001157600080fd5b5060405162005ac938038062005ac9833981016040819052610032916100c9565b6001600160a01b03841661004557600080fd5b6001600160a01b03831661005857600080fd5b6001600160a01b03821661006b57600080fd5b6001600160a01b03811661007e57600080fd5b6001600160601b0319606094851b811660e05292841b831660805290831b821660a05290911b1660c05261011c565b80516001600160a01b03811681146100c457600080fd5b919050565b600080600080608085870312156100de578384fd5b6100e7856100ad565b93506100f5602086016100ad565b9250610103604086016100ad565b9150610111606086016100ad565b905092959194509250565b60805160601c60a05160601c60c05160601c60e05160601c615952620001776000398061020c528061034e528061052a52508061019d528061032d52508061030c528061042852508061017952806102eb52506159526000f3fe60806040523480156200001157600080fd5b5060043610620000885760003560e01c8063634552fa1162000063578063634552fa14620000d0578063705e474b14620000e75780638903573014620000f1578063f77c479114620001135762000088565b8063092d8961146200008d5780634aa4a4fc14620000bc5780635fafa58914620000c6575b600080fd5b620000a46200009e3660046200084b565b6200011d565b604051620000b3919062000961565b60405180910390f35b620000a462000177565b620000a46200019b565b620000a4620000e13660046200089c565b620001bf565b620000a462000426565b620000fb6200044a565b604051620000b39a99989796959493929190620009a6565b620000a462000528565b6000600a600087878787876040516020016200013e95949392919062000975565b60408051808303601f19018152918152815160209283012083529082019290925201600020546001600160a01b03169695505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000803388868686604051602001620001dd95949392919062000975565b60408051601f19818403018152908290528051602090910120632d1cffed60e11b825291506001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690635a39ffda9062000243908b9060040162000961565b60206040518083038186803b1580156200025c57600080fd5b505afa15801562000271573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000297919062000938565b620002a157600080fd5b6000818152600a60205260409020546001600160a01b031615620002c457600080fd5b6305a39a80851115620002d657600080fd5b602d831115620002e557600080fd5b620003b17f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000338d8d8d8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152508f92508e91508d90506200054c565b6000828152600a6020526040808220805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0385811691821790925591519395509092908b169133917f6db07d148a8979a1f36c08142af6e0f291fc45d7cc3c4dccb5fdf76524e36ad19190a4509695505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60008054600180546002805460035460045460055460068054604080516020601f6000199c851615610100029c909c0190931698909804998a0182900482028801820190528887526001600160a01b03998a169a978a16999586169894861697938616969590921694929390918301828280156200050c5780601f10620004e0576101008083540402835291602001916200050c565b820191906000526020600020905b815481529060010190602001808311620004ee57829003601f168201915b505050505090806007015490806008015490806009015490508a565b7f000000000000000000000000000000000000000000000000000000000000000081565b60408051610140810182526001600160a01b03808d168083528c821660208085018290528d84169585018690528c8416606086018190528c851660808701819052948c1660a0870181905260c087018c905260e087018b905261010087018a905261012087018990526000805473ffffffffffffffffffffffffffffffffffffffff19908116909617815560018054871690951790945560028054861690981790975560038054851690911790556004805484169094179093556005805490921690941790558651839162000627916006918a019062000729565b5060e0820151600782015561010082015160088201556101209091015160099091015560405162000665908890889087908790879060200162000975565b604051602081830303815290604052805190602001206040516200068990620007be565b8190604051809103906000f5905080158015620006aa573d6000803e3d6000fd5b506000805473ffffffffffffffffffffffffffffffffffffffff19908116825560018054821690556002805482169055600380548216905560048054821690556005805490911690559091508062000704600682620007cc565b50600060078201819055600882018190556009909101559a9950505050505050505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282620007615760008555620007ac565b82601f106200077c57805160ff1916838001178555620007ac565b82800160010185558215620007ac579182015b82811115620007ac5782518255916020019190600101906200078f565b50620007ba92915062000817565b5090565b614ec18062000a5c83390190565b50805460018160011615610100020316600290046000825580601f10620007f4575062000814565b601f01602090049060005260206000209081019062000814919062000817565b50565b5b80821115620007ba576000815560010162000818565b80356001600160a01b03811681146200084657600080fd5b919050565b600080600080600060a0868803121562000863578081fd5b6200086e866200082e565b94506200087e602087016200082e565b94979496505050506040830135926060810135926080909101359150565b60008060008060008060a08789031215620008b5578081fd5b620008c0876200082e565b9550602087013567ffffffffffffffff80821115620008dd578283fd5b818901915089601f830112620008f1578283fd5b81358181111562000900578384fd5b8a602082850101111562000912578384fd5b979a60209290920199509697604081013597506060810135965060800135945092505050565b6000602082840312156200094a578081fd5b815180151581146200095a578182fd5b9392505050565b6001600160a01b0391909116815260200190565b6001600160a01b03958616815293909416602084015260408301919091526060820152608081019190915260a00190565b60006101406001600160a01b03808e1684526020818e1681860152818d166040860152818c166060860152818b166080860152818a1660a08601528260c08601528851915081838601528392505b8183101562000a1557888301810151858401610160015291820191620009f4565b508082111562000a29578261016082860101525b60e08401969096525050610100810192909252610120820152610160601f909201601f1916010197965050505050505056fe6101a06040526000196004553480156200001857600080fd5b506001600381905550600080336001600160a01b031663890357306040518163ffffffff1660e01b815260040160006040518083038186803b1580156200005e57600080fd5b505afa15801562000073573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526200009d91908101906200034f565b60c081905260a082905260808390528351620000c190600590602087019062000286565b5050505050606091821b6001600160601b03199081166101605292821b83166101405293811b82166101005293841b811660e05282841b8116610180529281901b909216610120529250905062000128828260001962000130602090811b620030e917901c565b5050620004a7565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663095ea7b360e01b1781529251825160009485949389169392918291908083835b60208310620001ae5780518252601f1990920191602091820191016200018d565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d806000811462000212576040519150601f19603f3d011682016040523d82523d6000602084013e62000217565b606091505b5091509150818015620002485750805115806200024857508080602001905160208110156200024557600080fd5b50515b6200027f576040805162461bcd60e51b8152602060048201526002602482015261534160f01b604482015290519081900360640190fd5b5050505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282620002be576000855562000309565b82601f10620002d957805160ff191683800117855562000309565b8280016001018555821562000309579182015b8281111562000309578251825591602001919060010190620002ec565b50620003179291506200031b565b5090565b5b808211156200031757600081556001016200031c565b80516001600160a01b03811681146200034a57600080fd5b919050565b6000806000806000806000806000806101408b8d0312156200036f578586fd5b6200037a8b62000332565b99506200038a60208c0162000332565b98506200039a60408c0162000332565b9750620003aa60608c0162000332565b9650620003ba60808c0162000332565b9550620003ca60a08c0162000332565b60c08c01519095506001600160401b0380821115620003e7578586fd5b818d0191508d601f830112620003fb578586fd5b8151818111156200040857fe5b604051601f8201601f1916810160200183811182821017156200042757fe5b80604052508181528f602083860101111562000441578788fd5b8792505b818310156200046857602083850101516020848301015260208301925062000445565b818311156200047a5787602083830101525b8097505050505060e08b015192506101008b015191506101208b015190509295989b9194979a5092959850565b60805160a05160c05160e05160601c6101005160601c6101205160601c6101405160601c6101605160601c6101805160601c6148ce620005f3600039806102d552806108955280610b3752806112fa52806115cd5280611cb2528061211f52806129b15280612bbc5280612d9d52806130c752806132a552508061147b5280612767525080610d4852806110b552806114aa528061175a528061180b5280612792528061295b5280612fc452806130a3525080610f475280610f73528061133c52806116025280611e11528061233b52806124d15280612bf8525080610b5c528061136b528061163152806118b85280611e40528061236a52806125005280612c2052806132ca5250806102ab528061030e528061034f52806128265280612875525080611fbd528061270b5250806126c4528061307f52508061108652806120b052506148ce6000f3fe6080604052600436106102a45760003560e01c806361603d891161016e578063ac4afa38116100cb578063d8a860811161007f578063f00733c211610064578063f00733c21461083c578063f77c479114610851578063fc0c546a14610866576103d3565b8063d8a86081146107fc578063dd62ed3e1461081c576103d3565b8063b784f8ed116100b0578063b784f8ed1461079c578063befb558f146107bc578063d3487997146107dc576103d3565b8063ac4afa381461075c578063b6b55f251461077c576103d3565b806395d89b4111610122578063a41fe49f11610107578063a41fe49f146106fc578063a5e7148b1461071c578063a9059cbb1461073c576103d3565b806395d89b41146106d25780639c7632fc146106e7576103d3565b80637791ba22116101535780637791ba221461067257806392f1d48d1461069257806395c08f92146106b2576103d3565b806361603d891461063d57806370a0823114610652576103d3565b8063255a23551161021c578063313ce567116101d0578063411bc9df116101b5578063411bc9df146105ce578063481c6a75146105fb5780635a1f02a31461061d576103d3565b8063313ce567146105975780633fd8b02f146105b9576103d3565b80632716ae66116102015780632716ae661461054d57806327328be814610562578063303e74df14610582576103d3565b8063255a2355146104fe5780632675e94b1461051e576103d3565b8063095ea7b311610273578063122b235811610258578063122b2358146104a957806318160ddd146104c957806323b872dd146104de576103d3565b8063095ea7b31461046757806310ea13df14610494576103d3565b806301e1d114146103da5780630252775314610405578063039046501461042557806306fdde0314610445576103d3565b366103d3577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031614156103d357336001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161480159061033c5750600034115b156103ce57600061034b61087b565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db0476040518263ffffffff1660e01b81526004016000604051808303818588803b1580156103a857600080fd5b505af11580156103bc573d6000803e3d6000fd5b50505050506103cb3482610950565b50505b6103d8565b600080fd5b005b3480156103e657600080fd5b506103ef61087b565b6040516103fc919061474f565b60405180910390f35b34801561041157600080fd5b506103ef610420366004613d51565b610a35565b34801561043157600080fd5b506103ef610440366004613fc7565b610a47565b34801561045157600080fd5b5061045a610a59565b6040516103fc91906143a3565b34801561047357600080fd5b50610487610482366004613f10565b610a92565b6040516103fc9190614360565b3480156104a057600080fd5b506103ef610aa9565b3480156104b557600080fd5b506103ef6104c43660046140b1565b610aaf565b3480156104d557600080fd5b506103ef610bdb565b3480156104ea57600080fd5b506104876104f9366004613e50565b610be1565b34801561050a57600080fd5b5061045a610519366004613d51565b610c48565b34801561052a57600080fd5b5061053e6105393660046140b1565b610ce3565b6040516103fc9392919061436b565b34801561055957600080fd5b506103ef610d37565b34801561056e57600080fd5b506103d861057d366004613e90565b610d3d565b34801561058e57600080fd5b5061045a611024565b3480156105a357600080fd5b506105ac61107f565b6040516103fc91906147b4565b3480156105c557600080fd5b506103ef611084565b3480156105da57600080fd5b506105ee6105e93660046141c6565b6110a8565b6040516103fc9190614732565b34801561060757600080fd5b50610610611479565b6040516103fc91906142cc565b34801561062957600080fd5b506103ef610638366004614202565b61149d565b34801561064957600080fd5b506103ef611737565b34801561065e57600080fd5b506103ef61066d366004613d51565b61173d565b34801561067e57600080fd5b506103d861068d366004613f3b565b61174f565b34801561069e57600080fd5b506105ee6106ad366004613dc1565b6117fe565b3480156106be57600080fd5b506103ef6106cd366004613d51565b611f70565b3480156106de57600080fd5b5061045a611f82565b3480156106f357600080fd5b506103ef611fbb565b34801561070857600080fd5b506103ef610717366004614146565b611fdf565b34801561072857600080fd5b506105ee610737366004614171565b61294e565b34801561074857600080fd5b50610487610757366004613f10565b612d34565b34801561076857600080fd5b50610610610777366004613fc7565b612d41565b34801561078857600080fd5b506103ef610797366004613fc7565b612d6b565b3480156107a857600080fd5b506103ef6107b7366004613fc7565b612dd7565b3480156107c857600080fd5b5061045a6107d7366004613d51565b612df8565b3480156107e857600080fd5b506103d86107f73660046140f5565b612e60565b34801561080857600080fd5b506103d8610817366004613fc7565b612fb9565b34801561082857600080fd5b506103ef610837366004613d89565b613060565b34801561084857600080fd5b506103ef61307d565b34801561085d57600080fd5b506106106130a1565b34801561087257600080fd5b506106106130c5565b6040516370a0823160e01b81526000906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a08231906108ca9030906004016142cc565b60206040518083038186803b1580156108e257600080fd5b505afa1580156108f6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061091a9190613fdf565b905060005b600b5481101561094c57600061093482613230565b509050610941838261334f565b92505060010161091f565b5090565b600060045442111561097d5760405162461bcd60e51b8152600401610974906145bf565b60405180910390fd5b60005461098b57508161099b565b610998836000548461335f565b90505b336000908152600a6020908152604080832042905560079091529020546109c2908461334f565b336000908152600760205260409020556006546109df908461334f565b6006556109ec338261340e565b336001600160a01b03167f90890809c654f11d6e72a28fa60149770a0d11ec6c92319d6ceb2bb0a4ea1a158483604051610a27929190614758565b60405180910390a292915050565b600a6020526000908152604090205481565b6000610a5282613230565b5092915050565b6040518060400160405280600981526020017f486f74706f74205633000000000000000000000000000000000000000000000081525081565b6000610a9f3384846134f3565b5060015b92915050565b60065481565b6000600c8381548110610abe57fe5b906000526020600020018281548110610ad357fe5b906000526020600020017339c2c8a21aed056b9549c81ce125886edb57af00632814c89b9091600b8681548110610b0657fe5b6000918252602090912001546040516001600160e01b031960e085901b168152610b8492916001600160a01b0316907f0000000000000000000000000000000000000000000000000000000000000000906009907f000000000000000000000000000000000000000000000000000000000000000090600401614334565b60206040518083038186803b158015610b9c57600080fd5b505af4158015610bb0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bd49190613fdf565b9392505050565b60005481565b6001600160a01b0383166000908152600260209081526040808320338452909152812054610c0f90836135df565b6001600160a01b0385166000908152600260209081526040808320338452909152902055610c3e8484846135ef565b5060019392505050565b60096020908152600091825260409182902080548351601f600260001961010060018616150201909316929092049182018490048402810184019094528084529091830182828015610cdb5780601f10610cb057610100808354040283529160200191610cdb565b820191906000526020600020905b815481529060010190602001808311610cbe57829003601f168201915b505050505081565b600c8281548110610cf357600080fd5b906000526020600020018181548110610d0b57600080fd5b60009182526020909120015460ff811692506101008104600290810b9250640100000000909104900b83565b600b5490565b336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610d855760405162461bcd60e51b81526004016109749061449d565b6001600160a01b0385166000908152600960205260409020546002600019610100600184161502019091160415610f415760005b600b54811015610f3f576000600b8281548110610dd257fe5b9060005260206000200160009054906101000a90046001600160a01b03169050866001600160a01b0316816001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b158015610e3557600080fd5b505afa158015610e49573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e6d9190613d6d565b6001600160a01b03161480610f035750866001600160a01b0316816001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015610ec057600080fd5b505afa158015610ed4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ef89190613d6d565b6001600160a01b0316145b15610f36576000610f1383613230565b5090508015610f345760405162461bcd60e51b815260040161097490614464565b505b50600101610db9565b505b610f6d857f000000000000000000000000000000000000000000000000000000000000000060006130e9565b610f9a857f00000000000000000000000000000000000000000000000000000000000000006000196130e9565b6001600160a01b0385166000908152600860205260409020610fbd908585613c5e565b506001600160a01b0385166000908152600960205260409020610fe1908383613c5e565b507fa4cb5d47d2e811828a599b5866df2cb31519b48ccb3d7782ed17e108e6ac45f785858560405161101593929190614308565b60405180910390a15050505050565b6005805460408051602060026001851615610100026000190190941693909304601f81018490048402820184019092528181529291830182828015610cdb5780601f10610cb057610100808354040283529160200191610cdb565b601281565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146110f25760405162461bcd60e51b81526004016109749061449d565b600b5486106111135760405162461bcd60e51b815260040161097490614511565b600c868154811061112057fe5b600091825260209091200154851061114a5760405162461bcd60e51b8152600401610974906143f0565b600c868154811061115757fe5b60009182526020909120015484106111815760405162461bcd60e51b81526004016109749061452e565b600080600c888154811061119157fe5b9060005260206000200187815481106111a657fe5b906000526020600020017339c2c8a21aed056b9549c81ce125886edb57af00638cdfa6e39091600b8b815481106111d957fe5b6000918252602090912001546040516001600160e01b031960e085901b16815261121292916001600160a01b0316908a906004016145db565b604080518083038186803b15801561122957600080fd5b505af415801561123d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061126191906140d2565b91509150600c888154811061127257fe5b90600052602060002001868154811061128757fe5b906000526020600020017339c2c8a21aed056b9549c81ce125886edb57af00631b980ec090916040518061014001604052808c8152602001600b8d815481106112cc57fe5b9060005260206000200160009054906101000a90046001600160a01b03166001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602001600081526020018681526020018581526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020018861ffff1663ffffffff16815260200160108963ffffffff16901c63ffffffff16815250600960086040518563ffffffff1660e01b81526004016113df94939291906145fa565b60206040518083038186803b1580156113f757600080fd5b505af415801561140b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061142f9190613f97565b92507f6f0e0adc84b4eaecf48a1ccc240419c48c5a8e2c0cfb0fd712f253e1aa3165b1888888886040516114669493929190614799565b60405180910390a1505095945050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146114e75760405162461bcd60e51b81526004016109749061449d565b600b5485106115085760405162461bcd60e51b815260040161097490614511565b600c858154811061151557fe5b600091825260209091200154841061153f5760405162461bcd60e51b81526004016109749061440d565b600c858154811061154c57fe5b90600052602060002001848154811061156157fe5b906000526020600020017339c2c8a21aed056b9549c81ce125886edb57af006378676eda90916040518060e00160405280600b8a8154811061159f57fe5b9060005260206000200160009054906101000a90046001600160a01b03166001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020018781526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020018661ffff1663ffffffff16815260200160108763ffffffff16901c63ffffffff1681525060096040518463ffffffff1660e01b81526004016116a2939291906146b4565b60206040518083038186803b1580156116ba57600080fd5b505af41580156116ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116f29190613fdf565b90507f655a72108c17d19d0a3fc55e6427fd9e9cf68952cd9f716a579c5b326bc088ee85858560405161172793929190614766565b60405180910390a1949350505050565b60045481565b60016020526000908152604090205481565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146117975760405162461bcd60e51b81526004016109749061449d565b806117b45760405162461bcd60e51b81526004016109749061454b565b6117c060058383613c5e565b507fbb8423f49fdfcd80fc58f3e79ce5ba1cba93158ff1670f1a780ce413b127d9d982826040516117f2929190614387565b60405180910390a15050565b6000336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146118485760405162461bcd60e51b81526004016109749061449d565b8360020b8560020b1261186d5760405162461bcd60e51b8152600401610974906143d3565b866001600160a01b0316886001600160a01b03161061189e5760405162461bcd60e51b8152600401610974906143d3565b604051630b4c774160e11b81526000906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690631698ee82906118f1908c908c908c906004016142e0565b60206040518083038186803b15801561190957600080fd5b505afa15801561191d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119419190613d6d565b90506001600160a01b0381166119695760405162461bcd60e51b8152600401610974906144d7565b6000816001600160a01b031663d0c93a7c6040518163ffffffff1660e01b815260040160206040518083038186803b1580156119a457600080fd5b505afa1580156119b8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119dc9190613f7b565b90508060020b8760020b816119ed57fe5b0760020b15611a0e5760405162461bcd60e51b815260040161097490614447565b8060020b8660020b81611a1d57fe5b0760020b15611a3e5760405162461bcd60e51b815260040161097490614480565b600080805b600b54811015611b4f57846001600160a01b0316600b8281548110611a6457fe5b6000918252602090912001546001600160a01b03161415611b47576001925080915060005b600c8281548110611a9657fe5b600091825260209091200154811015611b41578a60020b600c8381548110611aba57fe5b906000526020600020018281548110611acf57fe5b6000918252602090912001546101009004600290810b900b1415611b39578960020b600c8381548110611afe57fe5b906000526020600020018281548110611b1357fe5b6000918252602090912001546401000000009004600290810b900b1415611b3957600080fd5b600101611a89565b50611b4f565b600101611a43565b5081611bc85750600b8054600180820183557f0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01db990910180547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b038716179055600c8054909101815560005254600019015b600c8181548110611bd557fe5b9060005260206000200160405180606001604052806001151581526020018b60020b81526020018a60020b8152509080600181540180825580915050600190039060005260206000200160009091909190915060008201518160000160006101000a81548160ff02191690831515021790555060208201518160000160016101000a81548162ffffff021916908360020b62ffffff16021790555060408201518160000160046101000a81548162ffffff021916908360020b62ffffff16021790555050506000871115611f09576040516370a0823160e01b81527f00000000000000000000000000000000000000000000000000000000000000009088906001600160a01b038316906370a0823190611cf39030906004016142cc565b60206040518083038186803b158015611d0b57600080fd5b505afa158015611d1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d439190613fdf565b1015611d615760405162461bcd60e51b8152600401610974906143b6565b6000600c8381548110611d7057fe5b906000526020600020016001600c8581548110611d8957fe5b90600052602060002001805490500381548110611da257fe5b906000526020600020019050807339c2c8a21aed056b9549c81ce125886edb57af00631b980ec090916040518061014001604052808781526020018a6001600160a01b03168152602001866001600160a01b031681526020018d815260200160008152602001600081526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020018c61ffff1663ffffffff16815260200160108d63ffffffff16901c63ffffffff16815250600960086040518563ffffffff1660e01b8152600401611eb494939291906145fa565b60206040518083038186803b158015611ecc57600080fd5b505af4158015611ee0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f049190613f97565b965050505b7ff1bd4f3fcb4e0b193abc7e4002c0284e25086269a02de2e4c52045a91f647037816001600c8481548110611f3a57fe5b90600052602060002001805490500389604051611f5993929190614766565b60405180910390a150505050979650505050505050565b60076020526000908152604090205481565b6040518060400160405280600681526020017f4850542d5633000000000000000000000000000000000000000000000000000081525081565b7f000000000000000000000000000000000000000000000000000000000000000081565b600081804211156120025760405162461bcd60e51b815260040161097490614568565b6002600354141561205a576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b600260035533600090815260016020526040902054851580159061207e5750808611155b61209a5760405162461bcd60e51b815260040161097490614585565b336000908152600a60205260409020546120d4907f000000000000000000000000000000000000000000000000000000000000000061334f565b42116120f25760405162461bcd60e51b8152600401610974906145a2565b3360009081526007602052604081205461210d90888461335f565b6040516370a0823160e01b81529091507f0000000000000000000000000000000000000000000000000000000000000000906000906001600160a01b038316906370a08231906121619030906004016142cc565b60206040518083038186803b15801561217957600080fd5b505afa15801561218d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121b19190613fdf565b600b54909150819060009067ffffffffffffffff811180156121d257600080fd5b5060405190808252806020026020018201604052801561220657816020015b60608152602001906001900390816121f15790505b50905060005b600b5481101561224f57600061222182613230565b84848151811061222d57fe5b60209081029190910101529050612244848261334f565b93505060010161220c565b5061225d828c60005461335f565b97508288111561269757600061227389856135df565b90505b600080600061228485613727565b925092509250806000141561229b575050506125f9565b80841161242a57600c83815481106122af57fe5b9060005260206000200182815481106122c457fe5b906000526020600020017339c2c8a21aed056b9549c81ce125886edb57af006378676eda90916040518060e00160405280600b888154811061230257fe5b600091825260209182902001546001600160a01b0390811683528e169082015260400161233489601960821b8861335f565b81526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316815260200161271163ffffffff16815260200161271163ffffffff1681525060096040518463ffffffff1660e01b81526004016123d1939291906146b4565b60206040518083038186803b1580156123e957600080fd5b505af41580156123fd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124219190613fdf565b505050506125f9565b600c838154811061243757fe5b90600052602060002001828154811061244c57fe5b906000526020600020017339c2c8a21aed056b9549c81ce125886edb57af006378676eda90916040518060e00160405280600b888154811061248a57fe5b9060005260206000200160009054906101000a90046001600160a01b03166001600160a01b031681526020018c6001600160a01b03168152602001601960821b81526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316815260200161271163ffffffff16815260200161271163ffffffff1681525060096040518463ffffffff1660e01b8152600401612567939291906146b4565b60206040518083038186803b15801561257f57600080fd5b505af4158015612593573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125b79190613fdf565b506125c284826135df565b935060008584815181106125d257fe5b602002602001015183815181106125e557fe5b602002602001018181525050505050612276565b6040516370a0823160e01b81526001600160a01b038616906370a08231906126259030906004016142cc565b60206040518083038186803b15801561263d57600080fd5b505afa158015612651573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126759190613fdf565b93508389111561268757839850612695565b8b6000541415612695578398505b505b898810156126b75760405162461bcd60e51b8152600401610974906144f4565b60006126f860646126e8887f00000000000000000000000000000000000000000000000000000000000000006137d0565b816126ef57fe5b8891900461334f565b9050808911156127d4576000606461273a7f00000000000000000000000000000000000000000000000000000000000000006127348d866135df565b906137d0565b8161274157fe5b0490506000606461275760056127348e876135df565b8161275e57fe5b04905061278c877f0000000000000000000000000000000000000000000000000000000000000000846137f4565b6127b7877f0000000000000000000000000000000000000000000000000000000000000000836137f4565b6127cb826127c58d846135df565b906135df565b9a5050506127e0565b858910156127e0578895505b336000908152600760205260409020546127fa90876135df565b3360009081526007602052604090205560065461281790876135df565b600655612824338d61393b565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316856001600160a01b031614156128eb57604051632e1a7d4d60e01b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690632e1a7d4d906128aa908c9060040161474f565b600060405180830381600087803b1580156128c457600080fd5b505af11580156128d8573d6000803e3d6000fd5b505050506128e6338a613a12565b6128f6565b6128f685338b6137f4565b336001600160a01b03167ff279e6a1f5e320cca91135676d9cb6e44ca8a08c0b88342bcdb1144f6511b5688a8e604051612931929190614758565b60405180910390a250506001600355509498975050505050505050565b6000336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146129985760405162461bcd60e51b81526004016109749061449d565b6040516370a0823160e01b815284906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a08231906129e69030906004016142cc565b60206040518083038186803b1580156129fe57600080fd5b505afa158015612a12573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a369190613fdf565b1015612a545760405162461bcd60e51b8152600401610974906143b6565b600b548610612a755760405162461bcd60e51b815260040161097490614511565b600c8681548110612a8257fe5b6000918252602090912001548510612aac5760405162461bcd60e51b81526004016109749061440d565b6000806000600c8981548110612abe57fe5b906000526020600020018881548110612ad357fe5b9060005260206000200190506000600b8a81548110612aee57fe5b6000918252602090912001546001600160a01b031690508615612b9c57604051638cdfa6e360e01b81527339c2c8a21aed056b9549c81ce125886edb57af0090638cdfa6e390612b4790859085906000906004016145db565b604080518083038186803b158015612b5e57600080fd5b505af4158015612b72573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b9691906140d2565b90945092505b60408051610140810182528b81526001600160a01b0380841660208301527f0000000000000000000000000000000000000000000000000000000000000000811682840152606082018b90526080820187905260a082018690527f0000000000000000000000000000000000000000000000000000000000000000811660c08301527f00000000000000000000000000000000000000000000000000000000000000001660e082015261ffff808916610100830152601089901c166101208201529051626e603b60e61b81527339c2c8a21aed056b9549c81ce125886edb57af0091631b980ec091612c989186916009906008906004016145fa565b60206040518083038186803b158015612cb057600080fd5b505af4158015612cc4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ce89190613f97565b94507fc75c48b830a24feb7c52dd0d3b2d89a606bba5909d3cf2d76312abacef07e3638a8a8a8a604051612d1f949392919061477c565b60405180910390a15050505095945050505050565b6000610a9f3384846135ef565b600b8181548110612d5157600080fd5b6000918252602090912001546001600160a01b0316905081565b6000808211612d8c5760405162461bcd60e51b81526004016109749061442a565b6000612d9661087b565b9050612dc47f0000000000000000000000000000000000000000000000000000000000000000333086613b06565b612dce8382610950565b9150505b919050565b6000600c8281548110612de657fe5b60009182526020909120015492915050565b60086020908152600091825260409182902080548351601f600260001961010060018616150201909316929092049182018490048402810184019094528084529091830182828015610cdb5780601f10610cb057610100808354040283529160200191610cdb565b6000600b612e7083850185613fc7565b81548110612e7a57fe5b6000918252602090912001546001600160a01b03169050338114612eb05760405162461bcd60e51b8152600401610974906144ba565b8415612f3157612f31816001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b158015612ef257600080fd5b505afa158015612f06573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f2a9190613d6d565b33876137f4565b8315612fb257612fb2816001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015612f7357600080fd5b505afa158015612f87573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fab9190613d6d565b33866137f4565b5050505050565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146130015760405162461bcd60e51b81526004016109749061449d565b8042106130205760405162461bcd60e51b8152600401610974906145bf565b60048190556040517fcee41d256aa07bed14f8f31668adfd7ad6a7b4b4c75369954bb1fd311908bc929061305590839061474f565b60405180910390a150565b600260209081526000928352604080842090915290825290205481565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663095ea7b360e01b1781529251825160009485949389169392918291908083835b602083106131655780518252601f199092019160209182019101613146565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146131c7576040519150601f19603f3d011682016040523d82523d6000602084013e6131cc565b606091505b50915091508180156131fa5750805115806131fa57508080602001905160208110156131f757600080fd5b50515b612fb2576040805162461bcd60e51b8152602060048201526002602482015261534160f01b604482015290519081900360640190fd5b60006060600c838154811061324157fe5b906000526020600020017339c2c8a21aed056b9549c81ce125886edb57af0063d4db3deb9091600b868154811061327457fe5b6000918252602090912001546040516001600160e01b031960e085901b1681526132f292916001600160a01b0316907f0000000000000000000000000000000000000000000000000000000000000000906009907f000000000000000000000000000000000000000000000000000000000000000090600401614334565b60006040518083038186803b15801561330a57600080fd5b505af415801561331e573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526133469190810190613ff7565b91509150915091565b80820182811015610aa357600080fd5b6000808060001985870986860292508281109083900303905080613395576000841161338a57600080fd5b508290049050610bd4565b8084116133a157600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b6001600160a01b038216613469576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b600054613476908261334f565b60009081556001600160a01b03831681526001602052604090205461349b908261334f565b6001600160a01b03831660008181526001602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b6001600160a01b0383166135385760405162461bcd60e51b81526004018080602001828103825260248152602001806148756024913960400191505060405180910390fd5b6001600160a01b03821661357d5760405162461bcd60e51b815260040180806020018281038252602281526020018061480d6022913960400191505060405180910390fd5b6001600160a01b03808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b80820382811115610aa357600080fd5b6001600160a01b0383166136345760405162461bcd60e51b81526004018080602001828103825260258152602001806148506025913960400191505060405180910390fd5b6001600160a01b0382166136795760405162461bcd60e51b81526004018080602001828103825260238152602001806147ea6023913960400191505060405180910390fd5b6001600160a01b03831660009081526001602052604090205461369c90826135df565b6001600160a01b0380851660009081526001602052604080822093909355908416815220546136cb908261334f565b6001600160a01b0380841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b60008080805b84518110156137c85760005b85828151811061374557fe5b6020026020010151518110156137bf578286838151811061376257fe5b6020026020010151828151811061377557fe5b602002602001015111156137b757818187848151811061379157fe5b602002602001015183815181106137a457fe5b6020908102919091010151919650945092505b600101613739565b5060010161372d565b509193909250565b60008215806137eb575050818102818382816137e857fe5b04145b610aa357600080fd5b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b1781529251825160009485949389169392918291908083835b602083106138705780518252601f199092019160209182019101613851565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146138d2576040519150601f19603f3d011682016040523d82523d6000602084013e6138d7565b606091505b5091509150818015613905575080511580613905575080806020019051602081101561390257600080fd5b50515b612fb2576040805162461bcd60e51b815260206004820152600260248201526114d560f21b604482015290519081900360640190fd5b6001600160a01b0382166139805760405162461bcd60e51b815260040180806020018281038252602181526020018061482f6021913960400191505060405180910390fd5b6001600160a01b0382166000908152600160205260409020546139a390826135df565b6001600160a01b038316600090815260016020526040812091909155546139ca90826135df565b60009081556040805183815290516001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef919081900360200190a35050565b604080516000808252602082019092526001600160a01b0384169083906040518082805190602001908083835b60208310613a5e5780518252601f199092019160209182019101613a3f565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114613ac0576040519150601f19603f3d011682016040523d82523d6000602084013e613ac5565b606091505b5050905080613b01576040805162461bcd60e51b815260206004820152600360248201526253544560e81b604482015290519081900360640190fd5b505050565b604080516001600160a01b0385811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180516001600160e01b03166323b872dd60e01b178152925182516000948594938a169392918291908083835b60208310613b8a5780518252601f199092019160209182019101613b6b565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114613bec576040519150601f19603f3d011682016040523d82523d6000602084013e613bf1565b606091505b5091509150818015613c1f575080511580613c1f5750808060200190516020811015613c1c57600080fd5b50515b613c56576040805162461bcd60e51b815260206004820152600360248201526229aa2360e91b604482015290519081900360640190fd5b505050505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282613c945760008555613cda565b82601f10613cad5782800160ff19823516178555613cda565b82800160010185558215613cda579182015b82811115613cda578235825591602001919060010190613cbf565b5061094c9291505b8082111561094c5760008155600101613ce2565b60008083601f840112613d07578182fd5b50813567ffffffffffffffff811115613d1e578182fd5b602083019150836020828501011115613d3657600080fd5b9250929050565b803563ffffffff81168114612dd257600080fd5b600060208284031215613d62578081fd5b8135610bd4816147c2565b600060208284031215613d7e578081fd5b8151610bd4816147c2565b60008060408385031215613d9b578081fd5b8235613da6816147c2565b91506020830135613db6816147c2565b809150509250929050565b600080600080600080600060e0888a031215613ddb578283fd5b8735613de6816147c2565b96506020880135613df6816147c2565b9550604088013562ffffff81168114613e0d578384fd5b94506060880135613e1d816147da565b93506080880135613e2d816147da565b925060a08801359150613e4260c08901613d3d565b905092959891949750929550565b600080600060608486031215613e64578283fd5b8335613e6f816147c2565b92506020840135613e7f816147c2565b929592945050506040919091013590565b600080600080600060608688031215613ea7578081fd5b8535613eb2816147c2565b9450602086013567ffffffffffffffff80821115613ece578283fd5b613eda89838a01613cf6565b90965094506040880135915080821115613ef2578283fd5b50613eff88828901613cf6565b969995985093965092949392505050565b60008060408385031215613f22578182fd5b8235613f2d816147c2565b946020939093013593505050565b60008060208385031215613f4d578182fd5b823567ffffffffffffffff811115613f63578283fd5b613f6f85828601613cf6565b90969095509350505050565b600060208284031215613f8c578081fd5b8151610bd4816147da565b600060208284031215613fa8578081fd5b81516fffffffffffffffffffffffffffffffff81168114610bd4578182fd5b600060208284031215613fd8578081fd5b5035919050565b600060208284031215613ff0578081fd5b5051919050565b60008060408385031215614009578182fd5b8251915060208084015167ffffffffffffffff80821115614028578384fd5b818601915086601f83011261403b578384fd5b81518181111561404757fe5b8381026040518582820101818110858211171561406057fe5b604052828152858101935084860182860187018b101561407e578788fd5b8795505b838610156140a0578051855260019590950194938601938601614082565b508096505050505050509250929050565b600080604083850312156140c3578182fd5b50508035926020909101359150565b600080604083850312156140e4578182fd5b505080516020909101519092909150565b6000806000806060858703121561410a578182fd5b8435935060208501359250604085013567ffffffffffffffff81111561412e578283fd5b61413a87828801613cf6565b95989497509550505050565b60008060006060848603121561415a578081fd5b505081359360208301359350604090920135919050565b600080600080600060a08688031215614188578283fd5b853594506020860135935060408601359250606086013580151581146141ac578182fd5b91506141ba60808701613d3d565b90509295509295909350565b600080600080600060a086880312156141dd578283fd5b853594506020860135935060408601359250606086013591506141ba60808701613d3d565b60008060008060808587031215614217578182fd5b84359350602085013592506040850135915061423560608601613d3d565b905092959194509250565b6001600160a01b03169052565b60008284528282602086013780602084860101526020601f19601f85011685010190509392505050565b60008151808452815b8181101561429c57602081850181015186830182015201614280565b818111156142ad5782602083870101525b50601f01601f19169290920160200192915050565b63ffffffff169052565b6001600160a01b0391909116815260200190565b6001600160a01b03938416815291909216602082015262ffffff909116604082015260600190565b60006001600160a01b03851682526040602083015261432b60408301848661424d565b95945050505050565b9485526001600160a01b0393841660208601529183166040850152606084015216608082015260a00190565b901515815260200190565b9215158352600291820b6020840152900b604082015260600190565b60006020825261439b60208301848661424d565b949350505050565b600060208252610bd46020830184614277565b60208082526003908201526210551360ea1b604082015260600190565b60208082526003908201526224aa2b60e91b604082015260600190565b60208082526003908201526249534960e81b604082015260600190565b60208082526003908201526249505360e81b604082015260600190565b6020808252600390820152622220ad60e91b604082015260600190565b6020808252600390820152622a262b60e91b604082015260600190565b60208082526002908201526120ad60f11b604082015260600190565b6020808252600390820152622a2aab60e91b604082015260600190565b6020808252600390820152624f434360e81b604082015260600190565b6020808252600390820152624d514560e81b604082015260600190565b60208082526003908201526224aa2360e91b604082015260600190565b60208082526003908201526250534360e81b604082015260600190565b60208082526003908201526212541360ea1b604082015260600190565b60208082526003908201526249414960e81b604082015260600190565b60208082526003908201526244455360e81b604082015260600190565b60208082526003908201526210d11360ea1b604082015260600190565b60208082526003908201526249534160e81b604082015260600190565b60208082526003908201526204c4b560ec1b604082015260600190565b602080825260029082015261111360f21b604082015260600190565b9283526001600160a01b03919091166020830152604082015260600190565b60006101a08201905085825284516020830152602085015161461f6040840182614240565b5060408501516146326060840182614240565b5060608501516080830152608085015160a083015260a085015160c083015260c085015161466360e0840182614240565b5060e085015161010061467881850183614240565b860151905061012061468c848201836142c2565b860151905061469f6101408401826142c2565b50610160820193909352610180015292915050565b6000610120820190508482526001600160a01b03808551166020840152806020860151166040840152604085015160608401528060608601511660808401528060808601511660a08401525063ffffffff60a08501511660c083015260c084015161472260e08401826142c2565b5082610100830152949350505050565b6fffffffffffffffffffffffffffffffff91909116815260200190565b90815260200190565b918252602082015260400190565b9283526020830191909152604082015260600190565b938452602084019290925260408301521515606082015260800190565b93845260208401929092526040830152606082015260800190565b60ff91909116815260200190565b6001600160a01b03811681146147d757600080fd5b50565b8060020b81146147d757600080fdfe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f2061646472657373a2646970667358221220f18c732d905a9e7b58784336cd0db8dc4703c854a948b4f0ac40e7ad24c16c0464736f6c63430007060033a2646970667358221220086143700af56a017cff6be3f8a8bcbbeac4c8a91059ad0fb0180beef595198364736f6c63430007060033000000000000000000000000b440bd39870a94ba1131c6182ca5fba589d5449e000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f984000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564

Deployed Bytecode

0x60806040523480156200001157600080fd5b5060043610620000885760003560e01c8063634552fa1162000063578063634552fa14620000d0578063705e474b14620000e75780638903573014620000f1578063f77c479114620001135762000088565b8063092d8961146200008d5780634aa4a4fc14620000bc5780635fafa58914620000c6575b600080fd5b620000a46200009e3660046200084b565b6200011d565b604051620000b3919062000961565b60405180910390f35b620000a462000177565b620000a46200019b565b620000a4620000e13660046200089c565b620001bf565b620000a462000426565b620000fb6200044a565b604051620000b39a99989796959493929190620009a6565b620000a462000528565b6000600a600087878787876040516020016200013e95949392919062000975565b60408051808303601f19018152918152815160209283012083529082019290925201600020546001600160a01b03169695505050505050565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b7f000000000000000000000000e592427a0aece92de3edee1f18e0157c0586156481565b6000803388868686604051602001620001dd95949392919062000975565b60408051601f19818403018152908290528051602090910120632d1cffed60e11b825291506001600160a01b037f000000000000000000000000b440bd39870a94ba1131c6182ca5fba589d5449e1690635a39ffda9062000243908b9060040162000961565b60206040518083038186803b1580156200025c57600080fd5b505afa15801562000271573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000297919062000938565b620002a157600080fd5b6000818152600a60205260409020546001600160a01b031615620002c457600080fd5b6305a39a80851115620002d657600080fd5b602d831115620002e557600080fd5b620003b17f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc27f0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f9847f000000000000000000000000e592427a0aece92de3edee1f18e0157c058615647f000000000000000000000000b440bd39870a94ba1131c6182ca5fba589d5449e338d8d8d8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152508f92508e91508d90506200054c565b6000828152600a6020526040808220805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0385811691821790925591519395509092908b169133917f6db07d148a8979a1f36c08142af6e0f291fc45d7cc3c4dccb5fdf76524e36ad19190a4509695505050505050565b7f0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f98481565b60008054600180546002805460035460045460055460068054604080516020601f6000199c851615610100029c909c0190931698909804998a0182900482028801820190528887526001600160a01b03998a169a978a16999586169894861697938616969590921694929390918301828280156200050c5780601f10620004e0576101008083540402835291602001916200050c565b820191906000526020600020905b815481529060010190602001808311620004ee57829003601f168201915b505050505090806007015490806008015490806009015490508a565b7f000000000000000000000000b440bd39870a94ba1131c6182ca5fba589d5449e81565b60408051610140810182526001600160a01b03808d168083528c821660208085018290528d84169585018690528c8416606086018190528c851660808701819052948c1660a0870181905260c087018c905260e087018b905261010087018a905261012087018990526000805473ffffffffffffffffffffffffffffffffffffffff19908116909617815560018054871690951790945560028054861690981790975560038054851690911790556004805484169094179093556005805490921690941790558651839162000627916006918a019062000729565b5060e0820151600782015561010082015160088201556101209091015160099091015560405162000665908890889087908790879060200162000975565b604051602081830303815290604052805190602001206040516200068990620007be565b8190604051809103906000f5905080158015620006aa573d6000803e3d6000fd5b506000805473ffffffffffffffffffffffffffffffffffffffff19908116825560018054821690556002805482169055600380548216905560048054821690556005805490911690559091508062000704600682620007cc565b50600060078201819055600882018190556009909101559a9950505050505050505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282620007615760008555620007ac565b82601f106200077c57805160ff1916838001178555620007ac565b82800160010185558215620007ac579182015b82811115620007ac5782518255916020019190600101906200078f565b50620007ba92915062000817565b5090565b614ec18062000a5c83390190565b50805460018160011615610100020316600290046000825580601f10620007f4575062000814565b601f01602090049060005260206000209081019062000814919062000817565b50565b5b80821115620007ba576000815560010162000818565b80356001600160a01b03811681146200084657600080fd5b919050565b600080600080600060a0868803121562000863578081fd5b6200086e866200082e565b94506200087e602087016200082e565b94979496505050506040830135926060810135926080909101359150565b60008060008060008060a08789031215620008b5578081fd5b620008c0876200082e565b9550602087013567ffffffffffffffff80821115620008dd578283fd5b818901915089601f830112620008f1578283fd5b81358181111562000900578384fd5b8a602082850101111562000912578384fd5b979a60209290920199509697604081013597506060810135965060800135945092505050565b6000602082840312156200094a578081fd5b815180151581146200095a578182fd5b9392505050565b6001600160a01b0391909116815260200190565b6001600160a01b03958616815293909416602084015260408301919091526060820152608081019190915260a00190565b60006101406001600160a01b03808e1684526020818e1681860152818d166040860152818c166060860152818b166080860152818a1660a08601528260c08601528851915081838601528392505b8183101562000a1557888301810151858401610160015291820191620009f4565b508082111562000a29578261016082860101525b60e08401969096525050610100810192909252610120820152610160601f909201601f1916010197965050505050505056fe6101a06040526000196004553480156200001857600080fd5b506001600381905550600080336001600160a01b031663890357306040518163ffffffff1660e01b815260040160006040518083038186803b1580156200005e57600080fd5b505afa15801562000073573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526200009d91908101906200034f565b60c081905260a082905260808390528351620000c190600590602087019062000286565b5050505050606091821b6001600160601b03199081166101605292821b83166101405293811b82166101005293841b811660e05282841b8116610180529281901b909216610120529250905062000128828260001962000130602090811b620030e917901c565b5050620004a7565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663095ea7b360e01b1781529251825160009485949389169392918291908083835b60208310620001ae5780518252601f1990920191602091820191016200018d565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d806000811462000212576040519150601f19603f3d011682016040523d82523d6000602084013e62000217565b606091505b5091509150818015620002485750805115806200024857508080602001905160208110156200024557600080fd5b50515b6200027f576040805162461bcd60e51b8152602060048201526002602482015261534160f01b604482015290519081900360640190fd5b5050505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282620002be576000855562000309565b82601f10620002d957805160ff191683800117855562000309565b8280016001018555821562000309579182015b8281111562000309578251825591602001919060010190620002ec565b50620003179291506200031b565b5090565b5b808211156200031757600081556001016200031c565b80516001600160a01b03811681146200034a57600080fd5b919050565b6000806000806000806000806000806101408b8d0312156200036f578586fd5b6200037a8b62000332565b99506200038a60208c0162000332565b98506200039a60408c0162000332565b9750620003aa60608c0162000332565b9650620003ba60808c0162000332565b9550620003ca60a08c0162000332565b60c08c01519095506001600160401b0380821115620003e7578586fd5b818d0191508d601f830112620003fb578586fd5b8151818111156200040857fe5b604051601f8201601f1916810160200183811182821017156200042757fe5b80604052508181528f602083860101111562000441578788fd5b8792505b818310156200046857602083850101516020848301015260208301925062000445565b818311156200047a5787602083830101525b8097505050505060e08b015192506101008b015191506101208b015190509295989b9194979a5092959850565b60805160a05160c05160e05160601c6101005160601c6101205160601c6101405160601c6101605160601c6101805160601c6148ce620005f3600039806102d552806108955280610b3752806112fa52806115cd5280611cb2528061211f52806129b15280612bbc5280612d9d52806130c752806132a552508061147b5280612767525080610d4852806110b552806114aa528061175a528061180b5280612792528061295b5280612fc452806130a3525080610f475280610f73528061133c52806116025280611e11528061233b52806124d15280612bf8525080610b5c528061136b528061163152806118b85280611e40528061236a52806125005280612c2052806132ca5250806102ab528061030e528061034f52806128265280612875525080611fbd528061270b5250806126c4528061307f52508061108652806120b052506148ce6000f3fe6080604052600436106102a45760003560e01c806361603d891161016e578063ac4afa38116100cb578063d8a860811161007f578063f00733c211610064578063f00733c21461083c578063f77c479114610851578063fc0c546a14610866576103d3565b8063d8a86081146107fc578063dd62ed3e1461081c576103d3565b8063b784f8ed116100b0578063b784f8ed1461079c578063befb558f146107bc578063d3487997146107dc576103d3565b8063ac4afa381461075c578063b6b55f251461077c576103d3565b806395d89b4111610122578063a41fe49f11610107578063a41fe49f146106fc578063a5e7148b1461071c578063a9059cbb1461073c576103d3565b806395d89b41146106d25780639c7632fc146106e7576103d3565b80637791ba22116101535780637791ba221461067257806392f1d48d1461069257806395c08f92146106b2576103d3565b806361603d891461063d57806370a0823114610652576103d3565b8063255a23551161021c578063313ce567116101d0578063411bc9df116101b5578063411bc9df146105ce578063481c6a75146105fb5780635a1f02a31461061d576103d3565b8063313ce567146105975780633fd8b02f146105b9576103d3565b80632716ae66116102015780632716ae661461054d57806327328be814610562578063303e74df14610582576103d3565b8063255a2355146104fe5780632675e94b1461051e576103d3565b8063095ea7b311610273578063122b235811610258578063122b2358146104a957806318160ddd146104c957806323b872dd146104de576103d3565b8063095ea7b31461046757806310ea13df14610494576103d3565b806301e1d114146103da5780630252775314610405578063039046501461042557806306fdde0314610445576103d3565b366103d3577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031614156103d357336001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161480159061033c5750600034115b156103ce57600061034b61087b565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db0476040518263ffffffff1660e01b81526004016000604051808303818588803b1580156103a857600080fd5b505af11580156103bc573d6000803e3d6000fd5b50505050506103cb3482610950565b50505b6103d8565b600080fd5b005b3480156103e657600080fd5b506103ef61087b565b6040516103fc919061474f565b60405180910390f35b34801561041157600080fd5b506103ef610420366004613d51565b610a35565b34801561043157600080fd5b506103ef610440366004613fc7565b610a47565b34801561045157600080fd5b5061045a610a59565b6040516103fc91906143a3565b34801561047357600080fd5b50610487610482366004613f10565b610a92565b6040516103fc9190614360565b3480156104a057600080fd5b506103ef610aa9565b3480156104b557600080fd5b506103ef6104c43660046140b1565b610aaf565b3480156104d557600080fd5b506103ef610bdb565b3480156104ea57600080fd5b506104876104f9366004613e50565b610be1565b34801561050a57600080fd5b5061045a610519366004613d51565b610c48565b34801561052a57600080fd5b5061053e6105393660046140b1565b610ce3565b6040516103fc9392919061436b565b34801561055957600080fd5b506103ef610d37565b34801561056e57600080fd5b506103d861057d366004613e90565b610d3d565b34801561058e57600080fd5b5061045a611024565b3480156105a357600080fd5b506105ac61107f565b6040516103fc91906147b4565b3480156105c557600080fd5b506103ef611084565b3480156105da57600080fd5b506105ee6105e93660046141c6565b6110a8565b6040516103fc9190614732565b34801561060757600080fd5b50610610611479565b6040516103fc91906142cc565b34801561062957600080fd5b506103ef610638366004614202565b61149d565b34801561064957600080fd5b506103ef611737565b34801561065e57600080fd5b506103ef61066d366004613d51565b61173d565b34801561067e57600080fd5b506103d861068d366004613f3b565b61174f565b34801561069e57600080fd5b506105ee6106ad366004613dc1565b6117fe565b3480156106be57600080fd5b506103ef6106cd366004613d51565b611f70565b3480156106de57600080fd5b5061045a611f82565b3480156106f357600080fd5b506103ef611fbb565b34801561070857600080fd5b506103ef610717366004614146565b611fdf565b34801561072857600080fd5b506105ee610737366004614171565b61294e565b34801561074857600080fd5b50610487610757366004613f10565b612d34565b34801561076857600080fd5b50610610610777366004613fc7565b612d41565b34801561078857600080fd5b506103ef610797366004613fc7565b612d6b565b3480156107a857600080fd5b506103ef6107b7366004613fc7565b612dd7565b3480156107c857600080fd5b5061045a6107d7366004613d51565b612df8565b3480156107e857600080fd5b506103d86107f73660046140f5565b612e60565b34801561080857600080fd5b506103d8610817366004613fc7565b612fb9565b34801561082857600080fd5b506103ef610837366004613d89565b613060565b34801561084857600080fd5b506103ef61307d565b34801561085d57600080fd5b506106106130a1565b34801561087257600080fd5b506106106130c5565b6040516370a0823160e01b81526000906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a08231906108ca9030906004016142cc565b60206040518083038186803b1580156108e257600080fd5b505afa1580156108f6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061091a9190613fdf565b905060005b600b5481101561094c57600061093482613230565b509050610941838261334f565b92505060010161091f565b5090565b600060045442111561097d5760405162461bcd60e51b8152600401610974906145bf565b60405180910390fd5b60005461098b57508161099b565b610998836000548461335f565b90505b336000908152600a6020908152604080832042905560079091529020546109c2908461334f565b336000908152600760205260409020556006546109df908461334f565b6006556109ec338261340e565b336001600160a01b03167f90890809c654f11d6e72a28fa60149770a0d11ec6c92319d6ceb2bb0a4ea1a158483604051610a27929190614758565b60405180910390a292915050565b600a6020526000908152604090205481565b6000610a5282613230565b5092915050565b6040518060400160405280600981526020017f486f74706f74205633000000000000000000000000000000000000000000000081525081565b6000610a9f3384846134f3565b5060015b92915050565b60065481565b6000600c8381548110610abe57fe5b906000526020600020018281548110610ad357fe5b906000526020600020017339c2c8a21aed056b9549c81ce125886edb57af00632814c89b9091600b8681548110610b0657fe5b6000918252602090912001546040516001600160e01b031960e085901b168152610b8492916001600160a01b0316907f0000000000000000000000000000000000000000000000000000000000000000906009907f000000000000000000000000000000000000000000000000000000000000000090600401614334565b60206040518083038186803b158015610b9c57600080fd5b505af4158015610bb0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bd49190613fdf565b9392505050565b60005481565b6001600160a01b0383166000908152600260209081526040808320338452909152812054610c0f90836135df565b6001600160a01b0385166000908152600260209081526040808320338452909152902055610c3e8484846135ef565b5060019392505050565b60096020908152600091825260409182902080548351601f600260001961010060018616150201909316929092049182018490048402810184019094528084529091830182828015610cdb5780601f10610cb057610100808354040283529160200191610cdb565b820191906000526020600020905b815481529060010190602001808311610cbe57829003601f168201915b505050505081565b600c8281548110610cf357600080fd5b906000526020600020018181548110610d0b57600080fd5b60009182526020909120015460ff811692506101008104600290810b9250640100000000909104900b83565b600b5490565b336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610d855760405162461bcd60e51b81526004016109749061449d565b6001600160a01b0385166000908152600960205260409020546002600019610100600184161502019091160415610f415760005b600b54811015610f3f576000600b8281548110610dd257fe5b9060005260206000200160009054906101000a90046001600160a01b03169050866001600160a01b0316816001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b158015610e3557600080fd5b505afa158015610e49573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e6d9190613d6d565b6001600160a01b03161480610f035750866001600160a01b0316816001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015610ec057600080fd5b505afa158015610ed4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ef89190613d6d565b6001600160a01b0316145b15610f36576000610f1383613230565b5090508015610f345760405162461bcd60e51b815260040161097490614464565b505b50600101610db9565b505b610f6d857f000000000000000000000000000000000000000000000000000000000000000060006130e9565b610f9a857f00000000000000000000000000000000000000000000000000000000000000006000196130e9565b6001600160a01b0385166000908152600860205260409020610fbd908585613c5e565b506001600160a01b0385166000908152600960205260409020610fe1908383613c5e565b507fa4cb5d47d2e811828a599b5866df2cb31519b48ccb3d7782ed17e108e6ac45f785858560405161101593929190614308565b60405180910390a15050505050565b6005805460408051602060026001851615610100026000190190941693909304601f81018490048402820184019092528181529291830182828015610cdb5780601f10610cb057610100808354040283529160200191610cdb565b601281565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146110f25760405162461bcd60e51b81526004016109749061449d565b600b5486106111135760405162461bcd60e51b815260040161097490614511565b600c868154811061112057fe5b600091825260209091200154851061114a5760405162461bcd60e51b8152600401610974906143f0565b600c868154811061115757fe5b60009182526020909120015484106111815760405162461bcd60e51b81526004016109749061452e565b600080600c888154811061119157fe5b9060005260206000200187815481106111a657fe5b906000526020600020017339c2c8a21aed056b9549c81ce125886edb57af00638cdfa6e39091600b8b815481106111d957fe5b6000918252602090912001546040516001600160e01b031960e085901b16815261121292916001600160a01b0316908a906004016145db565b604080518083038186803b15801561122957600080fd5b505af415801561123d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061126191906140d2565b91509150600c888154811061127257fe5b90600052602060002001868154811061128757fe5b906000526020600020017339c2c8a21aed056b9549c81ce125886edb57af00631b980ec090916040518061014001604052808c8152602001600b8d815481106112cc57fe5b9060005260206000200160009054906101000a90046001600160a01b03166001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602001600081526020018681526020018581526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020018861ffff1663ffffffff16815260200160108963ffffffff16901c63ffffffff16815250600960086040518563ffffffff1660e01b81526004016113df94939291906145fa565b60206040518083038186803b1580156113f757600080fd5b505af415801561140b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061142f9190613f97565b92507f6f0e0adc84b4eaecf48a1ccc240419c48c5a8e2c0cfb0fd712f253e1aa3165b1888888886040516114669493929190614799565b60405180910390a1505095945050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146114e75760405162461bcd60e51b81526004016109749061449d565b600b5485106115085760405162461bcd60e51b815260040161097490614511565b600c858154811061151557fe5b600091825260209091200154841061153f5760405162461bcd60e51b81526004016109749061440d565b600c858154811061154c57fe5b90600052602060002001848154811061156157fe5b906000526020600020017339c2c8a21aed056b9549c81ce125886edb57af006378676eda90916040518060e00160405280600b8a8154811061159f57fe5b9060005260206000200160009054906101000a90046001600160a01b03166001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020018781526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020018661ffff1663ffffffff16815260200160108763ffffffff16901c63ffffffff1681525060096040518463ffffffff1660e01b81526004016116a2939291906146b4565b60206040518083038186803b1580156116ba57600080fd5b505af41580156116ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116f29190613fdf565b90507f655a72108c17d19d0a3fc55e6427fd9e9cf68952cd9f716a579c5b326bc088ee85858560405161172793929190614766565b60405180910390a1949350505050565b60045481565b60016020526000908152604090205481565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146117975760405162461bcd60e51b81526004016109749061449d565b806117b45760405162461bcd60e51b81526004016109749061454b565b6117c060058383613c5e565b507fbb8423f49fdfcd80fc58f3e79ce5ba1cba93158ff1670f1a780ce413b127d9d982826040516117f2929190614387565b60405180910390a15050565b6000336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146118485760405162461bcd60e51b81526004016109749061449d565b8360020b8560020b1261186d5760405162461bcd60e51b8152600401610974906143d3565b866001600160a01b0316886001600160a01b03161061189e5760405162461bcd60e51b8152600401610974906143d3565b604051630b4c774160e11b81526000906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690631698ee82906118f1908c908c908c906004016142e0565b60206040518083038186803b15801561190957600080fd5b505afa15801561191d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119419190613d6d565b90506001600160a01b0381166119695760405162461bcd60e51b8152600401610974906144d7565b6000816001600160a01b031663d0c93a7c6040518163ffffffff1660e01b815260040160206040518083038186803b1580156119a457600080fd5b505afa1580156119b8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119dc9190613f7b565b90508060020b8760020b816119ed57fe5b0760020b15611a0e5760405162461bcd60e51b815260040161097490614447565b8060020b8660020b81611a1d57fe5b0760020b15611a3e5760405162461bcd60e51b815260040161097490614480565b600080805b600b54811015611b4f57846001600160a01b0316600b8281548110611a6457fe5b6000918252602090912001546001600160a01b03161415611b47576001925080915060005b600c8281548110611a9657fe5b600091825260209091200154811015611b41578a60020b600c8381548110611aba57fe5b906000526020600020018281548110611acf57fe5b6000918252602090912001546101009004600290810b900b1415611b39578960020b600c8381548110611afe57fe5b906000526020600020018281548110611b1357fe5b6000918252602090912001546401000000009004600290810b900b1415611b3957600080fd5b600101611a89565b50611b4f565b600101611a43565b5081611bc85750600b8054600180820183557f0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01db990910180547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b038716179055600c8054909101815560005254600019015b600c8181548110611bd557fe5b9060005260206000200160405180606001604052806001151581526020018b60020b81526020018a60020b8152509080600181540180825580915050600190039060005260206000200160009091909190915060008201518160000160006101000a81548160ff02191690831515021790555060208201518160000160016101000a81548162ffffff021916908360020b62ffffff16021790555060408201518160000160046101000a81548162ffffff021916908360020b62ffffff16021790555050506000871115611f09576040516370a0823160e01b81527f00000000000000000000000000000000000000000000000000000000000000009088906001600160a01b038316906370a0823190611cf39030906004016142cc565b60206040518083038186803b158015611d0b57600080fd5b505afa158015611d1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d439190613fdf565b1015611d615760405162461bcd60e51b8152600401610974906143b6565b6000600c8381548110611d7057fe5b906000526020600020016001600c8581548110611d8957fe5b90600052602060002001805490500381548110611da257fe5b906000526020600020019050807339c2c8a21aed056b9549c81ce125886edb57af00631b980ec090916040518061014001604052808781526020018a6001600160a01b03168152602001866001600160a01b031681526020018d815260200160008152602001600081526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020018c61ffff1663ffffffff16815260200160108d63ffffffff16901c63ffffffff16815250600960086040518563ffffffff1660e01b8152600401611eb494939291906145fa565b60206040518083038186803b158015611ecc57600080fd5b505af4158015611ee0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f049190613f97565b965050505b7ff1bd4f3fcb4e0b193abc7e4002c0284e25086269a02de2e4c52045a91f647037816001600c8481548110611f3a57fe5b90600052602060002001805490500389604051611f5993929190614766565b60405180910390a150505050979650505050505050565b60076020526000908152604090205481565b6040518060400160405280600681526020017f4850542d5633000000000000000000000000000000000000000000000000000081525081565b7f000000000000000000000000000000000000000000000000000000000000000081565b600081804211156120025760405162461bcd60e51b815260040161097490614568565b6002600354141561205a576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b600260035533600090815260016020526040902054851580159061207e5750808611155b61209a5760405162461bcd60e51b815260040161097490614585565b336000908152600a60205260409020546120d4907f000000000000000000000000000000000000000000000000000000000000000061334f565b42116120f25760405162461bcd60e51b8152600401610974906145a2565b3360009081526007602052604081205461210d90888461335f565b6040516370a0823160e01b81529091507f0000000000000000000000000000000000000000000000000000000000000000906000906001600160a01b038316906370a08231906121619030906004016142cc565b60206040518083038186803b15801561217957600080fd5b505afa15801561218d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121b19190613fdf565b600b54909150819060009067ffffffffffffffff811180156121d257600080fd5b5060405190808252806020026020018201604052801561220657816020015b60608152602001906001900390816121f15790505b50905060005b600b5481101561224f57600061222182613230565b84848151811061222d57fe5b60209081029190910101529050612244848261334f565b93505060010161220c565b5061225d828c60005461335f565b97508288111561269757600061227389856135df565b90505b600080600061228485613727565b925092509250806000141561229b575050506125f9565b80841161242a57600c83815481106122af57fe5b9060005260206000200182815481106122c457fe5b906000526020600020017339c2c8a21aed056b9549c81ce125886edb57af006378676eda90916040518060e00160405280600b888154811061230257fe5b600091825260209182902001546001600160a01b0390811683528e169082015260400161233489601960821b8861335f565b81526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316815260200161271163ffffffff16815260200161271163ffffffff1681525060096040518463ffffffff1660e01b81526004016123d1939291906146b4565b60206040518083038186803b1580156123e957600080fd5b505af41580156123fd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124219190613fdf565b505050506125f9565b600c838154811061243757fe5b90600052602060002001828154811061244c57fe5b906000526020600020017339c2c8a21aed056b9549c81ce125886edb57af006378676eda90916040518060e00160405280600b888154811061248a57fe5b9060005260206000200160009054906101000a90046001600160a01b03166001600160a01b031681526020018c6001600160a01b03168152602001601960821b81526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316815260200161271163ffffffff16815260200161271163ffffffff1681525060096040518463ffffffff1660e01b8152600401612567939291906146b4565b60206040518083038186803b15801561257f57600080fd5b505af4158015612593573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125b79190613fdf565b506125c284826135df565b935060008584815181106125d257fe5b602002602001015183815181106125e557fe5b602002602001018181525050505050612276565b6040516370a0823160e01b81526001600160a01b038616906370a08231906126259030906004016142cc565b60206040518083038186803b15801561263d57600080fd5b505afa158015612651573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126759190613fdf565b93508389111561268757839850612695565b8b6000541415612695578398505b505b898810156126b75760405162461bcd60e51b8152600401610974906144f4565b60006126f860646126e8887f00000000000000000000000000000000000000000000000000000000000000006137d0565b816126ef57fe5b8891900461334f565b9050808911156127d4576000606461273a7f00000000000000000000000000000000000000000000000000000000000000006127348d866135df565b906137d0565b8161274157fe5b0490506000606461275760056127348e876135df565b8161275e57fe5b04905061278c877f0000000000000000000000000000000000000000000000000000000000000000846137f4565b6127b7877f0000000000000000000000000000000000000000000000000000000000000000836137f4565b6127cb826127c58d846135df565b906135df565b9a5050506127e0565b858910156127e0578895505b336000908152600760205260409020546127fa90876135df565b3360009081526007602052604090205560065461281790876135df565b600655612824338d61393b565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316856001600160a01b031614156128eb57604051632e1a7d4d60e01b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690632e1a7d4d906128aa908c9060040161474f565b600060405180830381600087803b1580156128c457600080fd5b505af11580156128d8573d6000803e3d6000fd5b505050506128e6338a613a12565b6128f6565b6128f685338b6137f4565b336001600160a01b03167ff279e6a1f5e320cca91135676d9cb6e44ca8a08c0b88342bcdb1144f6511b5688a8e604051612931929190614758565b60405180910390a250506001600355509498975050505050505050565b6000336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146129985760405162461bcd60e51b81526004016109749061449d565b6040516370a0823160e01b815284906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a08231906129e69030906004016142cc565b60206040518083038186803b1580156129fe57600080fd5b505afa158015612a12573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a369190613fdf565b1015612a545760405162461bcd60e51b8152600401610974906143b6565b600b548610612a755760405162461bcd60e51b815260040161097490614511565b600c8681548110612a8257fe5b6000918252602090912001548510612aac5760405162461bcd60e51b81526004016109749061440d565b6000806000600c8981548110612abe57fe5b906000526020600020018881548110612ad357fe5b9060005260206000200190506000600b8a81548110612aee57fe5b6000918252602090912001546001600160a01b031690508615612b9c57604051638cdfa6e360e01b81527339c2c8a21aed056b9549c81ce125886edb57af0090638cdfa6e390612b4790859085906000906004016145db565b604080518083038186803b158015612b5e57600080fd5b505af4158015612b72573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b9691906140d2565b90945092505b60408051610140810182528b81526001600160a01b0380841660208301527f0000000000000000000000000000000000000000000000000000000000000000811682840152606082018b90526080820187905260a082018690527f0000000000000000000000000000000000000000000000000000000000000000811660c08301527f00000000000000000000000000000000000000000000000000000000000000001660e082015261ffff808916610100830152601089901c166101208201529051626e603b60e61b81527339c2c8a21aed056b9549c81ce125886edb57af0091631b980ec091612c989186916009906008906004016145fa565b60206040518083038186803b158015612cb057600080fd5b505af4158015612cc4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ce89190613f97565b94507fc75c48b830a24feb7c52dd0d3b2d89a606bba5909d3cf2d76312abacef07e3638a8a8a8a604051612d1f949392919061477c565b60405180910390a15050505095945050505050565b6000610a9f3384846135ef565b600b8181548110612d5157600080fd5b6000918252602090912001546001600160a01b0316905081565b6000808211612d8c5760405162461bcd60e51b81526004016109749061442a565b6000612d9661087b565b9050612dc47f0000000000000000000000000000000000000000000000000000000000000000333086613b06565b612dce8382610950565b9150505b919050565b6000600c8281548110612de657fe5b60009182526020909120015492915050565b60086020908152600091825260409182902080548351601f600260001961010060018616150201909316929092049182018490048402810184019094528084529091830182828015610cdb5780601f10610cb057610100808354040283529160200191610cdb565b6000600b612e7083850185613fc7565b81548110612e7a57fe5b6000918252602090912001546001600160a01b03169050338114612eb05760405162461bcd60e51b8152600401610974906144ba565b8415612f3157612f31816001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b158015612ef257600080fd5b505afa158015612f06573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f2a9190613d6d565b33876137f4565b8315612fb257612fb2816001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015612f7357600080fd5b505afa158015612f87573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fab9190613d6d565b33866137f4565b5050505050565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146130015760405162461bcd60e51b81526004016109749061449d565b8042106130205760405162461bcd60e51b8152600401610974906145bf565b60048190556040517fcee41d256aa07bed14f8f31668adfd7ad6a7b4b4c75369954bb1fd311908bc929061305590839061474f565b60405180910390a150565b600260209081526000928352604080842090915290825290205481565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663095ea7b360e01b1781529251825160009485949389169392918291908083835b602083106131655780518252601f199092019160209182019101613146565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146131c7576040519150601f19603f3d011682016040523d82523d6000602084013e6131cc565b606091505b50915091508180156131fa5750805115806131fa57508080602001905160208110156131f757600080fd5b50515b612fb2576040805162461bcd60e51b8152602060048201526002602482015261534160f01b604482015290519081900360640190fd5b60006060600c838154811061324157fe5b906000526020600020017339c2c8a21aed056b9549c81ce125886edb57af0063d4db3deb9091600b868154811061327457fe5b6000918252602090912001546040516001600160e01b031960e085901b1681526132f292916001600160a01b0316907f0000000000000000000000000000000000000000000000000000000000000000906009907f000000000000000000000000000000000000000000000000000000000000000090600401614334565b60006040518083038186803b15801561330a57600080fd5b505af415801561331e573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526133469190810190613ff7565b91509150915091565b80820182811015610aa357600080fd5b6000808060001985870986860292508281109083900303905080613395576000841161338a57600080fd5b508290049050610bd4565b8084116133a157600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b6001600160a01b038216613469576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b600054613476908261334f565b60009081556001600160a01b03831681526001602052604090205461349b908261334f565b6001600160a01b03831660008181526001602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b6001600160a01b0383166135385760405162461bcd60e51b81526004018080602001828103825260248152602001806148756024913960400191505060405180910390fd5b6001600160a01b03821661357d5760405162461bcd60e51b815260040180806020018281038252602281526020018061480d6022913960400191505060405180910390fd5b6001600160a01b03808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b80820382811115610aa357600080fd5b6001600160a01b0383166136345760405162461bcd60e51b81526004018080602001828103825260258152602001806148506025913960400191505060405180910390fd5b6001600160a01b0382166136795760405162461bcd60e51b81526004018080602001828103825260238152602001806147ea6023913960400191505060405180910390fd5b6001600160a01b03831660009081526001602052604090205461369c90826135df565b6001600160a01b0380851660009081526001602052604080822093909355908416815220546136cb908261334f565b6001600160a01b0380841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b60008080805b84518110156137c85760005b85828151811061374557fe5b6020026020010151518110156137bf578286838151811061376257fe5b6020026020010151828151811061377557fe5b602002602001015111156137b757818187848151811061379157fe5b602002602001015183815181106137a457fe5b6020908102919091010151919650945092505b600101613739565b5060010161372d565b509193909250565b60008215806137eb575050818102818382816137e857fe5b04145b610aa357600080fd5b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b1781529251825160009485949389169392918291908083835b602083106138705780518252601f199092019160209182019101613851565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146138d2576040519150601f19603f3d011682016040523d82523d6000602084013e6138d7565b606091505b5091509150818015613905575080511580613905575080806020019051602081101561390257600080fd5b50515b612fb2576040805162461bcd60e51b815260206004820152600260248201526114d560f21b604482015290519081900360640190fd5b6001600160a01b0382166139805760405162461bcd60e51b815260040180806020018281038252602181526020018061482f6021913960400191505060405180910390fd5b6001600160a01b0382166000908152600160205260409020546139a390826135df565b6001600160a01b038316600090815260016020526040812091909155546139ca90826135df565b60009081556040805183815290516001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef919081900360200190a35050565b604080516000808252602082019092526001600160a01b0384169083906040518082805190602001908083835b60208310613a5e5780518252601f199092019160209182019101613a3f565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114613ac0576040519150601f19603f3d011682016040523d82523d6000602084013e613ac5565b606091505b5050905080613b01576040805162461bcd60e51b815260206004820152600360248201526253544560e81b604482015290519081900360640190fd5b505050565b604080516001600160a01b0385811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180516001600160e01b03166323b872dd60e01b178152925182516000948594938a169392918291908083835b60208310613b8a5780518252601f199092019160209182019101613b6b565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114613bec576040519150601f19603f3d011682016040523d82523d6000602084013e613bf1565b606091505b5091509150818015613c1f575080511580613c1f5750808060200190516020811015613c1c57600080fd5b50515b613c56576040805162461bcd60e51b815260206004820152600360248201526229aa2360e91b604482015290519081900360640190fd5b505050505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282613c945760008555613cda565b82601f10613cad5782800160ff19823516178555613cda565b82800160010185558215613cda579182015b82811115613cda578235825591602001919060010190613cbf565b5061094c9291505b8082111561094c5760008155600101613ce2565b60008083601f840112613d07578182fd5b50813567ffffffffffffffff811115613d1e578182fd5b602083019150836020828501011115613d3657600080fd5b9250929050565b803563ffffffff81168114612dd257600080fd5b600060208284031215613d62578081fd5b8135610bd4816147c2565b600060208284031215613d7e578081fd5b8151610bd4816147c2565b60008060408385031215613d9b578081fd5b8235613da6816147c2565b91506020830135613db6816147c2565b809150509250929050565b600080600080600080600060e0888a031215613ddb578283fd5b8735613de6816147c2565b96506020880135613df6816147c2565b9550604088013562ffffff81168114613e0d578384fd5b94506060880135613e1d816147da565b93506080880135613e2d816147da565b925060a08801359150613e4260c08901613d3d565b905092959891949750929550565b600080600060608486031215613e64578283fd5b8335613e6f816147c2565b92506020840135613e7f816147c2565b929592945050506040919091013590565b600080600080600060608688031215613ea7578081fd5b8535613eb2816147c2565b9450602086013567ffffffffffffffff80821115613ece578283fd5b613eda89838a01613cf6565b90965094506040880135915080821115613ef2578283fd5b50613eff88828901613cf6565b969995985093965092949392505050565b60008060408385031215613f22578182fd5b8235613f2d816147c2565b946020939093013593505050565b60008060208385031215613f4d578182fd5b823567ffffffffffffffff811115613f63578283fd5b613f6f85828601613cf6565b90969095509350505050565b600060208284031215613f8c578081fd5b8151610bd4816147da565b600060208284031215613fa8578081fd5b81516fffffffffffffffffffffffffffffffff81168114610bd4578182fd5b600060208284031215613fd8578081fd5b5035919050565b600060208284031215613ff0578081fd5b5051919050565b60008060408385031215614009578182fd5b8251915060208084015167ffffffffffffffff80821115614028578384fd5b818601915086601f83011261403b578384fd5b81518181111561404757fe5b8381026040518582820101818110858211171561406057fe5b604052828152858101935084860182860187018b101561407e578788fd5b8795505b838610156140a0578051855260019590950194938601938601614082565b508096505050505050509250929050565b600080604083850312156140c3578182fd5b50508035926020909101359150565b600080604083850312156140e4578182fd5b505080516020909101519092909150565b6000806000806060858703121561410a578182fd5b8435935060208501359250604085013567ffffffffffffffff81111561412e578283fd5b61413a87828801613cf6565b95989497509550505050565b60008060006060848603121561415a578081fd5b505081359360208301359350604090920135919050565b600080600080600060a08688031215614188578283fd5b853594506020860135935060408601359250606086013580151581146141ac578182fd5b91506141ba60808701613d3d565b90509295509295909350565b600080600080600060a086880312156141dd578283fd5b853594506020860135935060408601359250606086013591506141ba60808701613d3d565b60008060008060808587031215614217578182fd5b84359350602085013592506040850135915061423560608601613d3d565b905092959194509250565b6001600160a01b03169052565b60008284528282602086013780602084860101526020601f19601f85011685010190509392505050565b60008151808452815b8181101561429c57602081850181015186830182015201614280565b818111156142ad5782602083870101525b50601f01601f19169290920160200192915050565b63ffffffff169052565b6001600160a01b0391909116815260200190565b6001600160a01b03938416815291909216602082015262ffffff909116604082015260600190565b60006001600160a01b03851682526040602083015261432b60408301848661424d565b95945050505050565b9485526001600160a01b0393841660208601529183166040850152606084015216608082015260a00190565b901515815260200190565b9215158352600291820b6020840152900b604082015260600190565b60006020825261439b60208301848661424d565b949350505050565b600060208252610bd46020830184614277565b60208082526003908201526210551360ea1b604082015260600190565b60208082526003908201526224aa2b60e91b604082015260600190565b60208082526003908201526249534960e81b604082015260600190565b60208082526003908201526249505360e81b604082015260600190565b6020808252600390820152622220ad60e91b604082015260600190565b6020808252600390820152622a262b60e91b604082015260600190565b60208082526002908201526120ad60f11b604082015260600190565b6020808252600390820152622a2aab60e91b604082015260600190565b6020808252600390820152624f434360e81b604082015260600190565b6020808252600390820152624d514560e81b604082015260600190565b60208082526003908201526224aa2360e91b604082015260600190565b60208082526003908201526250534360e81b604082015260600190565b60208082526003908201526212541360ea1b604082015260600190565b60208082526003908201526249414960e81b604082015260600190565b60208082526003908201526244455360e81b604082015260600190565b60208082526003908201526210d11360ea1b604082015260600190565b60208082526003908201526249534160e81b604082015260600190565b60208082526003908201526204c4b560ec1b604082015260600190565b602080825260029082015261111360f21b604082015260600190565b9283526001600160a01b03919091166020830152604082015260600190565b60006101a08201905085825284516020830152602085015161461f6040840182614240565b5060408501516146326060840182614240565b5060608501516080830152608085015160a083015260a085015160c083015260c085015161466360e0840182614240565b5060e085015161010061467881850183614240565b860151905061012061468c848201836142c2565b860151905061469f6101408401826142c2565b50610160820193909352610180015292915050565b6000610120820190508482526001600160a01b03808551166020840152806020860151166040840152604085015160608401528060608601511660808401528060808601511660a08401525063ffffffff60a08501511660c083015260c084015161472260e08401826142c2565b5082610100830152949350505050565b6fffffffffffffffffffffffffffffffff91909116815260200190565b90815260200190565b918252602082015260400190565b9283526020830191909152604082015260600190565b938452602084019290925260408301521515606082015260800190565b93845260208401929092526040830152606082015260800190565b60ff91909116815260200190565b6001600160a01b03811681146147d757600080fd5b50565b8060020b81146147d757600080fdfe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f2061646472657373a2646970667358221220f18c732d905a9e7b58784336cd0db8dc4703c854a948b4f0ac40e7ad24c16c0464736f6c63430007060033a2646970667358221220086143700af56a017cff6be3f8a8bcbbeac4c8a91059ad0fb0180beef595198364736f6c63430007060033

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

000000000000000000000000b440bd39870a94ba1131c6182ca5fba589d5449e000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f984000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564

-----Decoded View---------------
Arg [0] : _controller (address): 0xB440bd39870A94ba1131C6182Ca5Fba589d5449e
Arg [1] : _weth9 (address): 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
Arg [2] : _uniV3Factory (address): 0x1F98431c8aD98523631AE4a59f267346ea31F984
Arg [3] : _uniV3Router (address): 0xE592427A0AEce92De3Edee1F18E0157C05861564

-----Encoded View---------------
4 Constructor Arguments found :
Arg [0] : 000000000000000000000000b440bd39870a94ba1131c6182ca5fba589d5449e
Arg [1] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Arg [2] : 0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f984
Arg [3] : 000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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