ETH Price: $2,956.41 (+0.99%)

Contract

0x0964B7A10631f2139dcf2e0aa1b621F97a19e998

Overview

ETH Balance

0 ETH

ETH Value

$0.00

Token Holdings

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Block
From
To
Move Range4244159932026-01-23 15:00:4722 hrs ago1769180447IN
0x0964B7A1...97a19e998
0 ETH0.000012630.02018
Increase Liquidi...4243214902026-01-23 8:27:5529 hrs ago1769156875IN
0x0964B7A1...97a19e998
0 ETH0.000006890.020116
Create Position4240534682026-01-22 13:50:3147 hrs ago1769089831IN
0x0964B7A1...97a19e998
0 ETH0.000012350.020034
Create Position4240530172026-01-22 13:48:4047 hrs ago1769089720IN
0x0964B7A1...97a19e998
0 ETH0.000011360.020106
Claim Fees4240515772026-01-22 13:42:4147 hrs ago1769089361IN
0x0964B7A1...97a19e998
0 ETH0.000004360.020052
Claim Fees4240514982026-01-22 13:42:2147 hrs ago1769089341IN
0x0964B7A1...97a19e998
0 ETH0.000004290.020148
Create Position4240171612026-01-22 11:19:342 days ago1769080774IN
0x0964B7A1...97a19e998
0 ETH0.000010070.02
Claim Fees4239878082026-01-22 9:17:232 days ago1769073443IN
0x0964B7A1...97a19e998
0 ETH0.000005850.020022
Withdraw4237106142026-01-21 14:02:332 days ago1769004153IN
0x0964B7A1...97a19e998
0 ETH0.00000490.02
Claim Fees4237104182026-01-21 14:01:462 days ago1769004106IN
0x0964B7A1...97a19e998
0 ETH0.000005380.020204
Withdraw4237102402026-01-21 14:01:012 days ago1769004061IN
0x0964B7A1...97a19e998
0 ETH0.000007040.020148
Create Position4236674792026-01-21 11:03:263 days ago1768993406IN
0x0964B7A1...97a19e998
0 ETH0.000011270.021742
Move Range4234296982026-01-20 18:33:213 days ago1768934001IN
0x0964B7A1...97a19e998
0 ETH0.000012320.020012
Claim Fees4234109942026-01-20 17:15:363 days ago1768929336IN
0x0964B7A1...97a19e998
0 ETH0.000004470.020116
Create Position4232601712026-01-20 6:49:134 days ago1768891753IN
0x0964B7A1...97a19e998
0 ETH0.000012580.02001
Claim Fees4229786292026-01-19 11:15:545 days ago1768821354IN
0x0964B7A1...97a19e998
0 ETH0.000005190.020072
Move Range4229735692026-01-19 10:54:545 days ago1768820094IN
0x0964B7A1...97a19e998
0 ETH0.00001220.020046
Claim Fees4228979432026-01-19 5:40:185 days ago1768801218IN
0x0964B7A1...97a19e998
0 ETH0.000004320.020046
Claim Fees4228860162026-01-19 4:50:385 days ago1768798238IN
0x0964B7A1...97a19e998
0 ETH0.000005480.020024
Withdraw4221630882026-01-17 2:34:377 days ago1768617277IN
0x0964B7A1...97a19e998
0 ETH0.00000130.02
Withdraw4221622712026-01-17 2:31:127 days ago1768617072IN
0x0964B7A1...97a19e998
0 ETH0.000006420.020026
Withdraw4221622032026-01-17 2:30:567 days ago1768617056IN
0x0964B7A1...97a19e998
0 ETH0.000006410.02
Withdraw4221621552026-01-17 2:30:447 days ago1768617044IN
0x0964B7A1...97a19e998
0 ETH0.000006410.02
Claim Fees4221478142026-01-17 1:30:537 days ago1768613453IN
0x0964B7A1...97a19e998
0 ETH0.000004510.020046
Compound Fees4219577612026-01-16 12:18:558 days ago1768565935IN
0x0964B7A1...97a19e998
0 ETH0.000007640.020056
View all transactions

Parent Transaction Hash Block From To
View All Internal Transactions

Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
LPManager

Compiler Version
v0.8.30+commit.73712a01

Optimization Enabled:
Yes with 200 runs

Other Settings:
cancun EvmVersion
File 1 of 32 : LPManager.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;

import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {IUniswapV3SwapCallback} from "@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol";
import {TickMath} from "@uniswap/v3-core/contracts/libraries/TickMath.sol";
import {IUniswapV3Pool} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
import {INonfungiblePositionManager} from "@uniswap/v3-periphery/contracts/interfaces/INonfungiblePositionManager.sol";
import {IProtocolFeeCollector} from "./interfaces/IProtocolFeeCollector.sol";
import {IUniswapV3Factory} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol";
import {FullMath} from "@uniswap/v3-core/contracts/libraries/FullMath.sol";
import {FixedPoint96} from "@uniswap/v3-core/contracts/libraries/FixedPoint96.sol";
import {FixedPoint128} from "@uniswap/v3-core/contracts/libraries/FixedPoint128.sol";

/**
 * @title LPManager
 * @notice High-level helper contract for managing Uniswap V3 liquidity positions.
 * @dev Wraps common flows: create a position, claim fees (optionally in a single token),
 *      compound fees back into the position, increase liquidity with auto-rebalancing of inputs,
 *      migrate a position range, and withdraw in one or two tokens.
 *
 *      Key behavior and assumptions:
 *      - The contract is a helper: the NFT remains owned by the user; approvals are required
 *        for both the Uniswap `positionManager` and ERC20 tokens.
 *      - Protocol fees are charged via an external `protocolFeeCollector` and may differ by flow:
 *          • createPosition/_openPosition: FeeType.LIQUIDITY on provided amounts
 *          • increaseLiquidity:         FeeType.DEPOSIT on added amounts
 *          • compoundFees:              FeeType.FEES on accrued rewards only
 *          • withdraw/moveRange:        FeeType.LIQUIDITY on withdrawn outputs
 *      - Some flows perform swaps to rebalance inputs. Swaps use conservative price limits when
 *        rebalancing to avoid crossing the range unexpectedly.
 */
contract LPManager is IUniswapV3SwapCallback {
    using SafeERC20 for IERC20Metadata;

    enum TransferInfoInToken {
        BOTH,
        TOKEN0,
        TOKEN1
    }

    struct PoolInfo {
        /// @notice Address of the Uniswap V3 pool contract
        address pool;
        /// @notice Address of token0 for the pool
        address token0;
        /// @notice Address of token1 for the pool
        address token1;
        /// @notice Pool fee tier in hundredths of a bip, e.g. 500, 3000, 10000
        uint24 fee;
    }

    struct PositionContext {
        PoolInfo poolInfo;
        /// @notice Lower tick bound of the position
        int24 tickLower;
        /// @notice Upper tick bound of the position
        int24 tickUpper;
    }

    struct RawPositionData {
        /// @notice Position token0
        address token0;
        /// @notice Position token1
        address token1;
        /// @notice Pool fee tier
        uint24 fee;
        /// @notice Lower tick bound of the position
        int24 tickLower;
        /// @notice Upper tick bound of the position
        int24 tickUpper;
        /// @notice Current liquidity of the position
        uint128 liquidity;
        /// @notice Fee growth inside last snapshot for token0 (Q128.128)
        uint256 feeGrowthInside0LastX128;
        /// @notice Fee growth inside last snapshot for token1 (Q128.128)
        uint256 feeGrowthInside1LastX128;
        /// @notice Accrued but uncollected token0 (per Uniswap positions storage)
        uint128 claimedFee0;
        /// @notice Accrued but uncollected token1 (per Uniswap positions storage)
        uint128 claimedFee1;
    }

    struct Position {
        /// @notice Pool address for this position
        address pool;
        /// @notice Pool fee tier
        uint24 fee;
        /// @notice token0 address
        address token0;
        /// @notice token1 address
        address token1;
        /// @notice Current position liquidity
        uint128 liquidity;
        /// @notice Calculated up-to-date unclaimed fee in token0
        uint256 unclaimedFee0;
        /// @notice Calculated up-to-date unclaimed fee in token1
        uint256 unclaimedFee1;
        /// @notice Previously accounted claimed token0 (tokensOwed0 in Uniswap storage)
        uint128 claimedFee0;
        /// @notice Previously accounted claimed token1 (tokensOwed1 in Uniswap storage)
        uint128 claimedFee1;
        /// @notice Lower tick bound
        int24 tickLower;
        /// @notice Upper tick bound
        int24 tickUpper;
        /// @notice Current human-readable price (token1 per token0) adjusted by decimals
        uint256 price;
    }

    struct Prices {
        /// @notice Current sqrt price Q96 of the pool
        uint160 current;
        /// @notice Lower sqrt price bound Q96 of the position
        uint160 lower;
        /// @notice Upper sqrt price bound Q96 of the position
        uint160 upper;
    }

    /*=========== Events ============*/

    /// @notice Emitted when a position is created
    /// @param positionId Newly minted position NFT id
    /// @param liquidity Minted liquidity value
    /// @param amount0 Actual amount of token0 supplied
    /// @param amount1 Actual amount of token1 supplied
    /// @param tickLower Lower tick boundary
    /// @param tickUpper Upper tick boundary
    /// @param sqrtPriceX96 Current pool sqrt price (Q96) at creation
    event PositionCreated(
        uint256 indexed positionId,
        uint128 liquidity,
        uint256 amount0,
        uint256 amount1,
        int24 tickLower,
        int24 tickUpper,
        uint256 sqrtPriceX96
    );
    /// @notice Emitted after fees are claimed in both tokens
    event ClaimedFees(uint256 indexed positionId, uint256 amount0, uint256 amount1);
    /// @notice Emitted after fees are claimed in a single token (with internal swap)
    event ClaimedFeesInToken(uint256 indexed positionId, address indexed token, uint256 amount);
    /// @notice Emitted after compounding fees back into the position
    event CompoundedFees(uint256 indexed positionId, uint256 amountToken0, uint256 amountToken1);
    /// @notice Emitted after increasing liquidity
    event LiquidityIncreased(uint256 indexed positionId, uint256 amountToken0, uint256 amountToken1);
    /// @notice Emitted after moving the range (migrating liquidity) to a new position
    event RangeMoved(
        uint256 indexed positionId,
        uint256 indexed oldPositionId,
        int24 tickLower,
        int24 tickUpper,
        uint256 amount0,
        uint256 amount1
    );
    /// @notice Emitted after withdrawing to a single token
    event WithdrawnSingleToken(
        uint256 indexed positionId, address tokenOut, uint256 amount, uint256 amount0, uint256 amount1
    );
    /// @notice Emitted after withdrawing both tokens
    event WithdrawnBothTokens(
        uint256 indexed positionId, address token0, address token1, uint256 amount0, uint256 amount1
    );

    /* ============ Errors ============ */

    /// @notice Thrown when resulting liquidity is less than the user-provided minimum
    error LiquidityLessThanMin();
    /// @notice Thrown when token0 output is less than the user-provided minimum
    error Amount0LessThanMin();
    /// @notice Thrown when token1 output is less than the user-provided minimum
    error Amount1LessThanMin();
    /// @notice Thrown when output amount is less than the user-provided minimum
    error AmountLessThanMin();
    /// @notice Thrown when provided tokenOut is not a token of the pool
    error InvalidTokenOut();
    /// @notice Thrown by swap callback when deltas are invalid (no payment due)
    error InvalidSwapCallbackDeltas();
    /// @notice Thrown by swap callback when the caller is not the expected pool
    error InvalidSwapCallbackCaller();
    /// @notice Thrown when msg.sender is not the owner of the specified position
    error NotPositionOwner();

    /* ============ CONSTANTS ============ */

    /// @notice Precision for calculations expressed in basis points (1e4 = 100%)
    uint32 public constant PRECISION = 1e4;

    /* ============ IMMUTABLE VARIABLES ============ */

    INonfungiblePositionManager public immutable positionManager;
    IProtocolFeeCollector public immutable protocolFeeCollector;
    IUniswapV3Factory public immutable factory;

    /* ============ CONSTRUCTOR ============ */

    constructor(INonfungiblePositionManager _positionManager, IProtocolFeeCollector _protocolFeeCollector) {
        positionManager = _positionManager;
        protocolFeeCollector = _protocolFeeCollector;
        factory = IUniswapV3Factory(_positionManager.factory());
    }

    /// @notice Restricts a call to the owner of `positionId` in the Uniswap position manager
    /// @dev Reads the owner from `positionManager.ownerOf(positionId)` and reverts otherwise
    modifier onlyPositionOwner(uint256 positionId) {
        require(positionManager.ownerOf(positionId) == msg.sender, NotPositionOwner());
        _;
    }

    /* ============ VIEW FUNCTIONS ============ */

    /**
     * @notice Returns a comprehensive snapshot of a position including live unclaimed fees and current price
     * @param positionId The Uniswap V3 position token id
     * @return position Populated struct with pool, tokens, liquidity, unclaimed/claimed fees and price
     */
    function getPosition(uint256 positionId) external view returns (Position memory position) {
        RawPositionData memory rawData = _getRawPositionData(positionId);
        address poolAddress = _getPool(rawData.token0, rawData.token1, rawData.fee);
        (uint256 unclaimedFee0, uint256 unclaimedFee1) = _calculateUnclaimedFees(
            poolAddress,
            rawData.tickLower,
            rawData.tickUpper,
            rawData.liquidity,
            rawData.feeGrowthInside0LastX128,
            rawData.feeGrowthInside1LastX128
        );

        position = Position({
            pool: poolAddress,
            fee: rawData.fee,
            token0: rawData.token0,
            token1: rawData.token1,
            liquidity: rawData.liquidity,
            unclaimedFee0: unclaimedFee0,
            unclaimedFee1: unclaimedFee1,
            claimedFee0: rawData.claimedFee0,
            claimedFee1: rawData.claimedFee1,
            tickLower: rawData.tickLower,
            tickUpper: rawData.tickUpper,
            price: _getPriceFromPool(poolAddress, rawData.token0, rawData.token1)
        });
    }

    /**
     * @notice Returns current sqrt price Q96 for the given pool
     * @param pool Pool address
     * @return sqrtPriceX96 Current sqrt price in Q96 format
     */
    function getCurrentSqrtPriceX96(address pool) public view returns (uint256 sqrtPriceX96) {
        (sqrtPriceX96,,,,,,) = IUniswapV3Pool(pool).slot0();
        return uint256(sqrtPriceX96);
    }

    /**
     * @notice Returns basic pool information (addresses of tokens and fee tier)
     * @param poolAddress Address of the Uniswap V3 pool
     * @return PoolInfo Struct with pool address, token0, token1, and fee
     */
    function getPoolInfo(address poolAddress) public view returns (PoolInfo memory) {
        return PoolInfo({
            pool: poolAddress,
            token0: IUniswapV3Pool(poolAddress).token0(),
            token1: IUniswapV3Pool(poolAddress).token1(),
            fee: IUniswapV3Pool(poolAddress).fee()
        });
    }

    /* ============ EXTERNAL FUNCTIONS ============ */

    /**
     * @notice Creates a new Uniswap V3 position with best-effort input rebalancing to maximize liquidity
     * @dev Pulls tokens from `msg.sender`, applies protocol LIQUIDITY fee on inputs, then rebalances via bounded
     *      swaps and mints the position. Any unused tokens are returned to `msg.sender`.
     *      Reverts if minted liquidity is less than `minLiquidity`.
     * @param poolAddress Target pool address
     * @param amountIn0 Amount of token0 to supply (before protocol fee)
     * @param amountIn1 Amount of token1 to supply (before protocol fee)
     * @param tickLower Lower tick bound
     * @param tickUpper Upper tick bound
     * @param recipient NFT recipient
     * @param minLiquidity Minimal acceptable liquidity minted
     * @return positionId New NFT id
     * @return liquidity Minted liquidity
     * @return amount0 Actual amount of token0 used
     * @return amount1 Actual amount of token1 used
     */
    function createPosition(
        address poolAddress,
        uint256 amountIn0,
        uint256 amountIn1,
        int24 tickLower,
        int24 tickUpper,
        address recipient,
        uint256 minLiquidity
    ) public returns (uint256 positionId, uint128 liquidity, uint256 amount0, uint256 amount1) {
        PoolInfo memory poolInfo = getPoolInfo(poolAddress);

        if (amountIn0 > 0) {
            IERC20Metadata(poolInfo.token0).safeTransferFrom(msg.sender, address(this), amountIn0);
        }
        if (amountIn1 > 0) {
            IERC20Metadata(poolInfo.token1).safeTransferFrom(msg.sender, address(this), amountIn1);
        }

        PositionContext memory ctx = PositionContext({poolInfo: poolInfo, tickLower: tickLower, tickUpper: tickUpper});
        (positionId, liquidity, amount0, amount1) = _openPosition(ctx, amountIn0, amountIn1, recipient, minLiquidity);
        emit PositionCreated(
            positionId, liquidity, amount0, amount1, tickLower, tickUpper, getCurrentSqrtPriceX96(poolInfo.pool)
        );
    }

    /**
     * @notice Claims all accrued fees for a position in both tokens
     * @dev Applies protocol FEES fee on the claimed rewards, then transfers both tokens to `recipient`.
     *      Reverts if caller is not the position owner.
     * @param positionId Position id
     * @param recipient Receiver of the claimed fees
     * @param minAmountOut0 Minimal acceptable token0 amount (post-fee)
     * @param minAmountOut1 Minimal acceptable token1 amount (post-fee)
     */
    function claimFees(uint256 positionId, address recipient, uint256 minAmountOut0, uint256 minAmountOut1)
        external
        returns (uint256 amount0, uint256 amount1)
    {
        (amount0, amount1) = _claimFees(positionId, recipient, TransferInfoInToken.BOTH);
        require(amount0 >= minAmountOut0, Amount0LessThanMin());
        require(amount1 >= minAmountOut1, Amount1LessThanMin());
        emit ClaimedFees(positionId, amount0, amount1);
    }

    /**
     * @notice Claims all accrued fees for a position and swaps them into a single token
     * @dev Applies protocol FEES fee, then performs an internal swap in the pool for the non-selected token.
     *      The final `amountOut` is post-fee and post-swap. Reverts if caller is not the position owner
     *      or if `tokenOut` is neither token0 nor token1 of the pool.
     * @param positionId Position id
     * @param recipient Receiver of the claimed fees
     * @param tokenOut Desired output token (must be pool token0 or token1)
     * @param minAmountOut Minimal acceptable output amount (post-fee and post-swap)
     */
    function claimFees(uint256 positionId, address recipient, address tokenOut, uint256 minAmountOut)
        external
        returns (uint256 amountOut)
    {
        (PoolInfo memory poolInfo) = _getPoolInfoById(positionId);
        require(tokenOut == poolInfo.token0 || tokenOut == poolInfo.token1, InvalidTokenOut());

        (uint256 amount0, uint256 amount1) = _claimFees(
            positionId, recipient, tokenOut == poolInfo.token0 ? TransferInfoInToken.TOKEN0 : TransferInfoInToken.TOKEN1
        );
        amountOut = amount0 == 0 ? amount1 : amount0;
        require(amountOut >= minAmountOut, AmountLessThanMin());
        emit ClaimedFeesInToken(positionId, tokenOut, amountOut);
    }

    /**
     * @notice Adds liquidity to an existing position using input auto-rebalancing
     * @dev Pulls tokens from `msg.sender`, applies protocol DEPOSIT fee, rebalances and increases liquidity.
     *      Any unused tokens are returned to `msg.sender`. Reverts if resulting liquidity increase is
     *      less than `minLiquidity`.
     * @param positionId Position id
     * @param amountIn0 Amount of token0 to add (before protocol fee)
     * @param amountIn1 Amount of token1 to add (before protocol fee)
     * @param minLiquidity Minimal acceptable liquidity increase
     */
    function increaseLiquidity(uint256 positionId, uint256 amountIn0, uint256 amountIn1, uint128 minLiquidity)
        external
        returns (uint128 liquidity, uint256 added0, uint256 added1)
    {
        PositionContext memory ctx = _getPositionContext(positionId);

        if (amountIn0 > 0) {
            IERC20Metadata(ctx.poolInfo.token0).safeTransferFrom(msg.sender, address(this), amountIn0);
            amountIn0 = _collectProtocolFee(ctx.poolInfo.token0, amountIn0, IProtocolFeeCollector.FeeType.DEPOSIT);
        }
        if (amountIn1 > 0) {
            IERC20Metadata(ctx.poolInfo.token1).safeTransferFrom(msg.sender, address(this), amountIn1);
            amountIn1 = _collectProtocolFee(ctx.poolInfo.token1, amountIn1, IProtocolFeeCollector.FeeType.DEPOSIT);
        }

        (liquidity, added0, added1) = _increaseLiquidity(positionId, ctx, amountIn0, amountIn1, minLiquidity);

        emit LiquidityIncreased(positionId, added0, added1);
    }

    /**
     * @notice Compounds currently accrued fees back into the same position using auto-rebalancing
     * @dev Only callable by the position owner. Collects pending fees, applies protocol FEES fee,
     *      rebalances and increases liquidity on the same position.
     * @param positionId Position id
     * @param minLiquidity Minimal acceptable liquidity increase
     */
    function compoundFees(uint256 positionId, uint128 minLiquidity)
        external
        onlyPositionOwner(positionId)
        returns (uint128 liquidity, uint256 added0, uint256 added1)
    {
        PositionContext memory ctx = _getPositionContext(positionId);
        (uint256 fees0, uint256 fees1) = _collect(positionId);

        fees0 = _collectProtocolFee(ctx.poolInfo.token0, fees0, IProtocolFeeCollector.FeeType.FEES);
        fees1 = _collectProtocolFee(ctx.poolInfo.token1, fees1, IProtocolFeeCollector.FeeType.FEES);

        (liquidity, added0, added1) = _increaseLiquidity(positionId, ctx, fees0, fees1, minLiquidity);

        emit CompoundedFees(positionId, added0, added1);
    }

    /**
     * @notice Migrates liquidity to a new range by withdrawing and minting a new position within the same pool
     * @dev Only callable by the position owner. Withdraws 100% of liquidity, collects any pending tokens,
     *      applies protocol LIQUIDITY fee on the amounts, and opens a new position with the provided range.
     *      This effectively charges the LIQUIDITY fee on principal and accrued fees;
     *      Reverts if minted liquidity is less than `minLiquidity`.
     * @param positionId Position id to migrate from
     * @param recipient Recipient of the new position
     * @param newLower New lower tick
     * @param newUpper New upper tick
     * @param minLiquidity Minimal acceptable liquidity for the new position
     * @return newPositionId Newly minted NFT id
     * @return liquidity Minted liquidity in the new position
     * @return amount0 Amount of token0 supplied in the new position
     * @return amount1 Amount of token1 supplied in the new position
     */
    function moveRange(uint256 positionId, address recipient, int24 newLower, int24 newUpper, uint256 minLiquidity)
        external
        onlyPositionOwner(positionId)
        returns (uint256 newPositionId, uint128 liquidity, uint256 amount0, uint256 amount1)
    {
        PositionContext memory ctx = _getPositionContext(positionId);
        _decreaseLiquidity(positionId, PRECISION);
        (uint256 amount0Collected, uint256 amount1Collected) = _collect(positionId);
        ctx.tickLower = newLower;
        ctx.tickUpper = newUpper;
        // just compound all fees into new position
        (newPositionId, liquidity, amount0, amount1) =
            _openPosition(ctx, amount0Collected, amount1Collected, recipient, minLiquidity);
        emit RangeMoved(newPositionId, positionId, newLower, newUpper, amount0, amount1);
    }

    /**
     * @notice Withdraws a percentage of liquidity and transfers both tokens to a recipient
     * @dev Only callable by the position owner. Applies protocol LIQUIDITY fee on withdrawn amounts
     *      before transferring to `recipient`.
     * @param positionId Position id
     * @param percent Basis points of liquidity to withdraw (1e4 = 100%)
     * @param recipient Receiver of withdrawn tokens
     * @param minAmountOut0 Minimal acceptable token0 amount (post-fee)
     * @param minAmountOut1 Minimal acceptable token1 amount (post-fee)
     */
    function withdraw(
        uint256 positionId,
        uint32 percent,
        address recipient,
        uint256 minAmountOut0,
        uint256 minAmountOut1
    ) external returns (uint256 amount0, uint256 amount1) {
        PoolInfo memory poolInfo = _getPoolInfoById(positionId);
        (amount0, amount1) = _withdraw(positionId, percent);
        amount0 = _collectProtocolFee(poolInfo.token0, amount0, IProtocolFeeCollector.FeeType.LIQUIDITY);
        amount1 = _collectProtocolFee(poolInfo.token1, amount1, IProtocolFeeCollector.FeeType.LIQUIDITY);
        require(amount0 >= minAmountOut0, Amount0LessThanMin());
        require(amount1 >= minAmountOut1, Amount1LessThanMin());
        if (amount0 > 0) {
            IERC20Metadata(poolInfo.token0).safeTransfer(recipient, amount0);
        }
        if (amount1 > 0) {
            IERC20Metadata(poolInfo.token1).safeTransfer(recipient, amount1);
        }
        emit WithdrawnBothTokens(positionId, poolInfo.token0, poolInfo.token1, amount0, amount1);
    }

    /**
     * @notice Withdraws a percentage of liquidity and swaps the proceeds into a single token
     * @dev Only callable by the position owner. Applies protocol LIQUIDITY fee after performing the
     *      internal swap, then transfers `amountOut` to `recipient`.
     * @param positionId Position id
     * @param percent Basis points of liquidity to withdraw (1e4 = 100%)
     * @param recipient Receiver of withdrawn tokens
     * @param tokenOut Desired output token (must be pool token0 or token1)
     * @param minAmountOut Minimal acceptable output (post-fee and post-swap)
     */
    function withdraw(uint256 positionId, uint32 percent, address recipient, address tokenOut, uint256 minAmountOut)
        external
        returns (uint256 amountOut)
    {
        PoolInfo memory poolInfo = _getPoolInfoById(positionId);
        require(tokenOut == poolInfo.token0 || tokenOut == poolInfo.token1, InvalidTokenOut());
        (uint256 amount0, uint256 amount1) = _withdraw(positionId, percent);
        if (tokenOut == poolInfo.token0) {
            amountOut = _collectProtocolFee(
                poolInfo.token0, amount0 + _swap(false, amount1, poolInfo), IProtocolFeeCollector.FeeType.LIQUIDITY
            );
        } else {
            amountOut = _collectProtocolFee(
                poolInfo.token1, amount1 + _swap(true, amount0, poolInfo), IProtocolFeeCollector.FeeType.LIQUIDITY
            );
        }
        require(amountOut >= minAmountOut, AmountLessThanMin());
        IERC20Metadata(tokenOut).safeTransfer(recipient, amountOut);
        emit WithdrawnSingleToken(positionId, tokenOut, amountOut, amount0, amount1);
    }

    /* ============ INTERNAL FUNCTIONS ============ */

    /**
     * @notice Resolves the Uniswap V3 pool address by token order and fee tier
     * @param token0 Pool token0 address
     * @param token1 Pool token1 address
     * @param fee Fee tier (e.g. 500, 3000, 10000)
     * @return pool Pool address
     */
    function _getPool(address token0, address token1, uint24 fee) private view returns (address) {
        return factory.getPool(token0, token1, fee);
    }

    /**
     * @notice Retrieves all position data from Uniswap position manager
     * @dev Fetches complete position struct and maps to internal data structure
     * @param positionId Position ID to query
     * @return rawPositionData Complete position data including tokens, range, liquidity, and fees
     */
    function _getRawPositionData(uint256 positionId) internal view returns (RawPositionData memory rawPositionData) {
        (
            ,
            ,
            address token0,
            address token1,
            uint24 fee,
            int24 tickLower,
            int24 tickUpper,
            uint128 liquidity,
            uint256 feeGrowthInside0LastX128,
            uint256 feeGrowthInside1LastX128,
            uint128 tokensOwed0,
            uint128 tokensOwed1
        ) = positionManager.positions(positionId);
        rawPositionData = RawPositionData({
            token0: token0,
            token1: token1,
            fee: fee,
            tickLower: tickLower,
            tickUpper: tickUpper,
            liquidity: liquidity,
            feeGrowthInside0LastX128: feeGrowthInside0LastX128,
            feeGrowthInside1LastX128: feeGrowthInside1LastX128,
            claimedFee0: tokensOwed0,
            claimedFee1: tokensOwed1
        });
    }

    /**
     * @notice Claims fees for a position
     * @param positionId Position id
     * @param recipient Recipient of the fees
     * @param transferInfoInToken Transfer info in token
     * @return amount0 Amount of token0 claimed
     * @return amount1 Amount of token1 claimed
     */
    function _claimFees(uint256 positionId, address recipient, TransferInfoInToken transferInfoInToken)
        internal
        onlyPositionOwner(positionId)
        returns (uint256 amount0, uint256 amount1)
    {
        (PoolInfo memory poolInfo) = _getPoolInfoById(positionId);
        (amount0, amount1) = _collect(positionId);
        amount0 = _collectProtocolFee(poolInfo.token0, amount0, IProtocolFeeCollector.FeeType.FEES);
        amount1 = _collectProtocolFee(poolInfo.token1, amount1, IProtocolFeeCollector.FeeType.FEES);
        if (transferInfoInToken != TransferInfoInToken.BOTH) {
            if (transferInfoInToken == TransferInfoInToken.TOKEN0) {
                amount0 += _swap(false, amount1, poolInfo);
                amount1 = 0;
            } else {
                amount1 += _swap(true, amount0, poolInfo);
                amount0 = 0;
            }
        }
        if (amount0 > 0) IERC20Metadata(poolInfo.token0).safeTransfer(recipient, amount0);
        if (amount1 > 0) IERC20Metadata(poolInfo.token1).safeTransfer(recipient, amount1);
    }

    /**
     * @notice Reads the pool info (addresses and fee) from a position id
     * @param positionId The Uniswap V3 position token id
     * @return poolInfo Pool metadata for the underlying pool
     */
    function _getPoolInfoById(uint256 positionId) internal view returns (PoolInfo memory poolInfo) {
        (,, address token0, address token1, uint24 fee,,,,,,,) = positionManager.positions(positionId);
        address pool = _getPool(token0, token1, fee);
        poolInfo = PoolInfo({pool: pool, token0: token0, token1: token1, fee: fee});
    }

    /**
     * @notice Builds a compact position context used across internal flows
     * @param positionId The Uniswap V3 position token id
     * @return ctx Context with pool info and tick bounds
     */
    function _getPositionContext(uint256 positionId) internal view returns (PositionContext memory ctx) {
        (,, address token0, address token1, uint24 fee, int24 tickLower, int24 tickUpper,,,,,) =
            positionManager.positions(positionId);
        PoolInfo memory poolInfo =
            PoolInfo({pool: _getPool(token0, token1, fee), token0: token0, token1: token1, fee: fee});
        ctx = PositionContext({poolInfo: poolInfo, tickLower: tickLower, tickUpper: tickUpper});
    }

    function _getTokenLiquidity(uint256 tokenId) internal view virtual returns (uint128 liquidity) {
        (,,,,,,, liquidity,,,,) = positionManager.positions(tokenId);
    }

    function _getTokensOwed(uint256 tokenId) internal view virtual returns (uint128 amount0, uint128 amount1) {
        (,,,,,,,,,, amount0, amount1) = positionManager.positions(tokenId);
    }

    /**
     * @notice Opens a new position
     * @param ctx Position context
     * @param amount0 Amount of token0
     * @param amount1 Amount of token1
     * @param recipient Recipient of the position
     * @param minLiquidity Minimal acceptable liquidity minted
     * @return positionId Position id
     * @return liquidity Minted liquidity in the new position
     * @return amount0Used Amount of token0 used in the new position
     * @return amount1Used Amount of token1 used in the new position
     */
    function _openPosition(
        PositionContext memory ctx,
        uint256 amount0,
        uint256 amount1,
        address recipient,
        uint256 minLiquidity
    ) internal returns (uint256 positionId, uint128 liquidity, uint256 amount0Used, uint256 amount1Used) {
        amount0 = _collectProtocolFee(ctx.poolInfo.token0, amount0, IProtocolFeeCollector.FeeType.LIQUIDITY);
        amount1 = _collectProtocolFee(ctx.poolInfo.token1, amount1, IProtocolFeeCollector.FeeType.LIQUIDITY);
        // find optimal amounts
        (amount0, amount1) = _toOptimalRatio(ctx, amount0, amount1);
        _ensureAllowance(ctx.poolInfo.token0, amount0);
        _ensureAllowance(ctx.poolInfo.token1, amount1);

        (positionId, liquidity, amount0Used, amount1Used) = _mintPosition(ctx, amount0, amount1, recipient);
        require(liquidity >= minLiquidity, LiquidityLessThanMin());

        _sendBackRemainingTokens(ctx.poolInfo.token0, ctx.poolInfo.token1, amount0 - amount0Used, amount1 - amount1Used);
    }

    function _increaseLiquidity(
        uint256 positionId,
        PositionContext memory ctx,
        uint256 amount0,
        uint256 amount1,
        uint128 minLiquidity
    ) internal returns (uint128 liquidity, uint256 added0, uint256 added1) {
        (amount0, amount1) = _toOptimalRatio(ctx, amount0, amount1);
        _ensureAllowance(ctx.poolInfo.token0, amount0);
        _ensureAllowance(ctx.poolInfo.token1, amount1);
        (liquidity, added0, added1) = positionManager.increaseLiquidity(
            INonfungiblePositionManager.IncreaseLiquidityParams({
                tokenId: positionId,
                amount0Desired: amount0,
                amount1Desired: amount1,
                amount0Min: 0,
                amount1Min: 0,
                deadline: type(uint256).max
            })
        );
        require(liquidity >= minLiquidity, LiquidityLessThanMin());
        _sendBackRemainingTokens(ctx.poolInfo.token0, ctx.poolInfo.token1, amount0 - added0, amount1 - added1);
    }

    function _mintPosition(PositionContext memory ctx, uint256 amount0, uint256 amount1, address recipient)
        internal
        returns (uint256 tokenId, uint128 liquidity, uint256 amount0Used, uint256 amount1Used)
    {
        (tokenId, liquidity, amount0Used, amount1Used) = INonfungiblePositionManager(positionManager).mint(
            INonfungiblePositionManager.MintParams({
                token0: ctx.poolInfo.token0,
                token1: ctx.poolInfo.token1,
                fee: ctx.poolInfo.fee,
                tickLower: ctx.tickLower,
                tickUpper: ctx.tickUpper,
                amount0Desired: amount0,
                amount1Desired: amount1,
                amount0Min: 0,
                amount1Min: 0,
                recipient: recipient,
                deadline: block.timestamp
            })
        );
    }

    function _decreaseLiquidity(uint256 positionId, uint32 percent)
        internal
        returns (uint256 amount0, uint256 amount1)
    {
        uint128 totalLiquidity = _getTokenLiquidity(positionId);
        // Decrease liquidity for the current position and return the received token amounts
        (amount0, amount1) = positionManager.decreaseLiquidity(
            INonfungiblePositionManager.DecreaseLiquidityParams({
                tokenId: positionId,
                liquidity: totalLiquidity * percent / PRECISION,
                amount0Min: 0,
                amount1Min: 0,
                deadline: type(uint256).max
            })
        );
    }

    function _collect(uint256 positionId) internal returns (uint256 amount0, uint256 amount1) {
        (amount0, amount1) = _collect(positionId, address(this), type(uint128).max, type(uint128).max);
    }

    function _collect(uint256 positionId, address recipient, uint128 amount0Max, uint128 amount1Max)
        internal
        returns (uint256 amount0, uint256 amount1)
    {
        // Collect earned fees from the liquidity position
        (amount0, amount1) = positionManager.collect(
            INonfungiblePositionManager.CollectParams({
                tokenId: positionId,
                recipient: recipient,
                amount0Max: amount0Max,
                amount1Max: amount1Max
            })
        );
    }

    function _withdraw(uint256 positionId, uint32 percent)
        internal
        onlyPositionOwner(positionId)
        returns (uint256 amount0, uint256 amount1)
    {
        // decrease liquidity
        (uint256 liq0, uint256 liq1) = _decreaseLiquidity(positionId, percent);
        (uint128 owed0, uint128 owed1) = _getTokensOwed(positionId);

        (amount0, amount1) = _collect(
            positionId,
            address(this),
            uint128(liq0 + (uint256(owed0) - liq0) * percent / PRECISION),
            uint128(liq1 + (uint256(owed1) - liq1) * percent / PRECISION)
        );
    }

    /**
     * @notice Rebalances input amounts towards the optimal proportion for the given price range
     * @dev Computes desired amounts via _getAmountsInBothTokens. If one side has an excess over
     *      desired + dust, performs a bounded swap with sqrtPriceLimit to avoid crossing the range.
     *      If the excess is within dust, skips swapping.
     * @param ctx Position context (pool info and tick bounds)
     * @param amount0 Current token0 amount available
     * @param amount1 Current token1 amount available
     * @return amount0 Rebalanced token0 amount
     * @return amount1 Rebalanced token1 amount
     */
    function _toOptimalRatio(PositionContext memory ctx, uint256 amount0, uint256 amount1)
        internal
        returns (uint256, uint256)
    {
        Prices memory prices = _currentLowerUpper(ctx);
        // Compute desired amounts for target liquidity under current price and bounds
        uint256 amount1In0 = FullMath.mulDiv(amount1, 2 ** 192, uint256(prices.current) * uint256(prices.current));
        (uint256 want0, uint256 want1) =
            _getAmountsInBothTokens(amount0 + amount1In0, prices.current, prices.lower, prices.upper);

        want1 = FullMath.mulDiv(want1, uint256(prices.current) * uint256(prices.current), 2 ** 192);
        if (amount0 > want0) {
            uint160 limit = _priceLimitForExcess(true, prices);

            (int256 d0, int256 d1) = _swapWithPriceLimit(true, amount0 - want0, ctx.poolInfo, limit);
            amount0 -= uint256(d0);
            amount1 += uint256(-d1);
        } else if (amount1 > want1) {
            uint160 limit = _priceLimitForExcess(false, prices);
            (int256 d0, int256 d1) = _swapWithPriceLimit(false, amount1 - want1, ctx.poolInfo, limit);
            amount0 += uint256(-d0);
            amount1 -= uint256(d1);
        }
        return (amount0, amount1);
    }

    /**
     * @notice Gets current price, lower, and upper
     * @param ctx Position context
     */
    function _currentLowerUpper(PositionContext memory ctx) private view returns (Prices memory prices) {
        prices.current = uint160(getCurrentSqrtPriceX96(ctx.poolInfo.pool));
        prices.lower = TickMath.getSqrtRatioAtTick(ctx.tickLower);
        prices.upper = TickMath.getSqrtRatioAtTick(ctx.tickUpper);
    }

    /**
     * @notice Computes a conservative sqrtPriceLimitX96 for bounded swaps when rebalancing
     * @dev Prevents price from crossing the position range during the swap. If current price is
     *      already beyond the corresponding bound, returns that bound; if price is inside the
     *      range, returns a value slightly inside the bound; otherwise returns 0 to use default.
     * @param zeroForOne true if selling token0 for token1, false otherwise
     * @return limit Sqrt price limit to be used in swap
     */
    function _priceLimitForExcess(bool zeroForOne, Prices memory prices) private pure returns (uint160 limit) {
        if (zeroForOne) {
            // Selling token0 makes price go down: guard at upper if outside, else lower if inside
            if (prices.current >= prices.upper) return prices.upper;
            if (prices.current > prices.lower) return prices.lower;
            return 0;
        } else {
            // Selling token1 makes price go up: guard at lower if outside, else upper if inside
            if (prices.current <= prices.lower) return prices.lower;
            if (prices.current < prices.upper) return prices.upper;
            return 0;
        }
    }

    function _getAmountsInBothTokens(
        uint256 amount,
        uint160 sqrtPriceX96,
        uint160 sqrtPriceLower,
        uint160 sqrtPriceUpper
    ) internal pure returns (uint256 amountFor0, uint256 amountFor1) {
        if (sqrtPriceX96 <= sqrtPriceLower) {
            amountFor0 = amount;
        } else if (sqrtPriceX96 < sqrtPriceUpper) {
            uint256 n = FullMath.mulDiv(sqrtPriceUpper, sqrtPriceX96 - sqrtPriceLower, FixedPoint96.Q96);
            uint256 d = FullMath.mulDiv(sqrtPriceX96, sqrtPriceUpper - sqrtPriceX96, FixedPoint96.Q96);
            uint256 x = FullMath.mulDiv(n, FixedPoint96.Q96, d);
            amountFor0 = FullMath.mulDiv(amount, FixedPoint96.Q96, x + FixedPoint96.Q96);
            amountFor1 = amount - amountFor0;
        } else {
            amountFor1 = amount;
        }
    }

    /**
     * @notice Collects protocol fee from the given amount
     * @param token Token address
     * @param amount Amount of tokens to collect fee from
     * @param feeType Type of fee to collect (LIQUIDITY, DEPOSIT, FEES)
     * @return amount Amount of tokens after collecting fee
     */
    function _collectProtocolFee(address token, uint256 amount, IProtocolFeeCollector.FeeType feeType)
        private
        returns (uint256)
    {
        if (amount == 0) return 0;
        uint256 protocolFee = protocolFeeCollector.calculateProtocolFee(amount, feeType);
        IERC20Metadata(token).safeTransfer(address(protocolFeeCollector), protocolFee);
        return amount - protocolFee;
    }

    function _calculateUnclaimedFees(
        address pool,
        int24 tickLower,
        int24 tickUpper,
        uint128 liquidity,
        uint256 feeGrowthInside0LastX128,
        uint256 feeGrowthInside1LastX128
    ) internal view returns (uint256 fee0, uint256 fee1) {
        (, int24 currentTick,,,,,) = IUniswapV3Pool(pool).slot0();
        uint256 feeGrowthGlobal0X128 = IUniswapV3Pool(pool).feeGrowthGlobal0X128();
        uint256 feeGrowthGlobal1X128 = IUniswapV3Pool(pool).feeGrowthGlobal1X128();
        (,, uint256 feeGrowthOutside0X128Lower, uint256 feeGrowthOutside1X128Lower,,,,) =
            IUniswapV3Pool(pool).ticks(tickLower);
        (,, uint256 feeGrowthOutside0X128Upper, uint256 feeGrowthOutside1X128Upper,,,,) =
            IUniswapV3Pool(pool).ticks(tickUpper);

        uint256 feeGrowthInside0X128;
        uint256 feeGrowthInside1X128;

        unchecked {
            if (currentTick < tickLower) {
                feeGrowthInside0X128 = feeGrowthOutside0X128Lower - feeGrowthOutside0X128Upper;
                feeGrowthInside1X128 = feeGrowthOutside1X128Lower - feeGrowthOutside1X128Upper;
            } else if (currentTick >= tickUpper) {
                feeGrowthInside0X128 = feeGrowthOutside0X128Upper - feeGrowthOutside0X128Lower;
                feeGrowthInside1X128 = feeGrowthOutside1X128Upper - feeGrowthOutside1X128Lower;
            } else {
                feeGrowthInside0X128 = feeGrowthGlobal0X128 - feeGrowthOutside0X128Lower - feeGrowthOutside0X128Upper;
                feeGrowthInside1X128 = feeGrowthGlobal1X128 - feeGrowthOutside1X128Lower - feeGrowthOutside1X128Upper;
            }

            fee0 =
                FullMath.mulDiv(uint256(feeGrowthInside0X128 - feeGrowthInside0LastX128), liquidity, FixedPoint128.Q128);
            fee1 =
                FullMath.mulDiv(uint256(feeGrowthInside1X128 - feeGrowthInside1LastX128), liquidity, FixedPoint128.Q128);
        }
    }

    /**
     * @notice Gets human-readable price from pool's current tick
     * @dev Converts sqrtPriceX96 to decimal-adjusted price (token1 per token0)
     * @param pool Pool address
     * @param token0 First token address
     * @param token1 Second token address
     * @return price Current price adjusted for token decimals
     */
    function _getPriceFromPool(address pool, address token0, address token1) internal view returns (uint256 price) {
        uint256 sqrtPriceX96 = getCurrentSqrtPriceX96(pool);

        uint256 ratio = FullMath.mulDiv(uint256(sqrtPriceX96), uint256(sqrtPriceX96), 1 << 192);
        price = FullMath.mulDiv(ratio, 10 ** IERC20Metadata(token0).decimals(), 10 ** IERC20Metadata(token1).decimals());
    }

    function _ensureAllowance(address token, uint256 amount) internal {
        if (IERC20Metadata(token).allowance(address(this), address(positionManager)) < amount) {
            IERC20Metadata(token).forceApprove(address(positionManager), type(uint256).max);
        }
    }

    /**
     * @notice Sends back the remaining tokens to the sender
     * @param token0 Token0 address
     * @param token1 Token1 address
     * @param amount0 Amount of token0 to send back
     * @param amount1 Amount of token1 to send back
     */
    function _sendBackRemainingTokens(address token0, address token1, uint256 amount0, uint256 amount1) internal {
        if (amount0 > 0) {
            IERC20Metadata(token0).safeTransfer(msg.sender, amount0);
        }
        if (amount1 > 0) {
            IERC20Metadata(token1).safeTransfer(msg.sender, amount1);
        }
    }

    /**
     * @notice Executes an unbounded swap in the pool and returns the output amount
     * @dev Uses extreme sqrtPriceLimit to allow full price traversal. For rebalancing
     *      within a range prefer _swapWithPriceLimit to avoid crossing range bounds.
     * @param zeroForOne true for token0->token1 swap, false for token1->token0
     * @param amount Exact input amount
     * @param poolInfo Pool metadata (addresses and fee)
     * @return out Exact output amount received
     */
    function _swap(bool zeroForOne, uint256 amount, PoolInfo memory poolInfo) internal returns (uint256 out) {
        (int256 amount0, int256 amount1) = _swapWithPriceLimit(zeroForOne, amount, poolInfo, 0);
        // Output amount is the negative leg (exact input convention)
        out = uint256(-(zeroForOne ? amount1 : amount0));
    }

    /**
     * @notice Executes a swap with a conservative sqrt price limit for rebalancing
     * @dev If limit is zero, uses an extreme limit to avoid accidental reverts, but
     *      in rebalancing flows limit should be chosen via _priceLimitForExcess.
     * @param zeroForOne true for token0->token1 swap, false for token1->token0
     * @param amount The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
     * @param poolInfo Pool metadata (addresses and fee)
     * @param sqrtPriceLimitX96 Sqrt price limit (Q96). Zero uses extreme default
     * @return amount0 Signed token0 delta (positive = we pay token0)
     * @return amount1 Signed token1 delta (positive = we pay token1)
     */
    function _swapWithPriceLimit(bool zeroForOne, uint256 amount, PoolInfo memory poolInfo, uint160 sqrtPriceLimitX96)
        internal
        returns (int256 amount0, int256 amount1)
    {
        if (amount == 0) return (0, 0);
        if (sqrtPriceLimitX96 == 0) {
            sqrtPriceLimitX96 = zeroForOne ? TickMath.MIN_SQRT_RATIO + 1 : TickMath.MAX_SQRT_RATIO - 1;
        }
        (amount0, amount1) = IUniswapV3Pool(poolInfo.pool).swap(
            address(this),
            zeroForOne,
            int256(amount),
            sqrtPriceLimitX96,
            zeroForOne
                ? abi.encode(poolInfo.token0, poolInfo.token1, poolInfo.fee)
                : abi.encode(poolInfo.token1, poolInfo.token0, poolInfo.fee)
        );
    }

    /* ============ CALLBACK FUNCTIONS ============ */

    /**
     * @notice Uniswap V3 swap callback for providing required token amounts during swaps
     * @param amount0Delta Amount of the first token delta
     * @param amount1Delta Amount of the second token delta
     * @param data Encoded data containing swap details
     */
    function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) external override {
        // Ensure the callback is being called by the correct pool
        require(amount0Delta > 0 || amount1Delta > 0, InvalidSwapCallbackDeltas());
        (address tokenIn, address tokenOut, uint24 fee) = abi.decode(data, (address, address, uint24));
        require(factory.getPool(tokenIn, tokenOut, fee) == msg.sender, InvalidSwapCallbackCaller());
        (bool isExactInput, uint256 amountToPay) =
            amount0Delta > 0 ? (tokenIn < tokenOut, uint256(amount0Delta)) : (tokenOut < tokenIn, uint256(amount1Delta));

        // Transfer the required amount back to the pool
        if (isExactInput) {
            IERC20Metadata(tokenIn).safeTransfer(msg.sender, amountToPay);
        } else {
            IERC20Metadata(tokenOut).safeTransfer(msg.sender, amountToPay);
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";

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

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
        return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
        return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     *
     * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
     * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
     * set here.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            safeTransfer(token, to, value);
        } else if (!token.transferAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
     * has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferFromAndCallRelaxed(
        IERC1363 token,
        address from,
        address to,
        uint256 value,
        bytes memory data
    ) internal {
        if (to.code.length == 0) {
            safeTransferFrom(token, from, to, value);
        } else if (!token.transferFromAndCall(from, to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
     * Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
     * once without retrying, and relies on the returned value to be true.
     *
     * Reverts if the returned value is other than `true`.
     */
    function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            forceApprove(token, to, value);
        } else if (!token.approveAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            // bubble errors
            if iszero(success) {
                let ptr := mload(0x40)
                returndatacopy(ptr, 0, returndatasize())
                revert(ptr, returndatasize())
            }
            returnSize := returndatasize()
            returnValue := mload(0)
        }

        if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        bool success;
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            returnSize := returndatasize()
            returnValue := mload(0)
        }
        return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity >=0.6.2;

import {IERC20} from "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC-20 standard.
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

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

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

// 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;
}

// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.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 {
    error T();
    error R();

    /// @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) {
        unchecked {
            uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick));
            if (absTick > uint256(int256(MAX_TICK))) revert 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) {
        unchecked {
            // second inequality must be < because the price can never reach the price at the max tick
            if (!(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO)) revert 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 6 of 32 : IUniswapV3Pool.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import {IUniswapV3PoolImmutables} from './pool/IUniswapV3PoolImmutables.sol';
import {IUniswapV3PoolState} from './pool/IUniswapV3PoolState.sol';
import {IUniswapV3PoolDerivedState} from './pool/IUniswapV3PoolDerivedState.sol';
import {IUniswapV3PoolActions} from './pool/IUniswapV3PoolActions.sol';
import {IUniswapV3PoolOwnerActions} from './pool/IUniswapV3PoolOwnerActions.sol';
import {IUniswapV3PoolErrors} from './pool/IUniswapV3PoolErrors.sol';
import {IUniswapV3PoolEvents} from './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,
    IUniswapV3PoolErrors,
    IUniswapV3PoolEvents
{

}

// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

import '@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol';
import '@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol';

import './IPoolInitializer.sol';
import './IERC721Permit.sol';
import './IPeripheryPayments.sol';
import './IPeripheryImmutableState.sol';
import '../libraries/PoolAddress.sol';

/// @title Non-fungible token for positions
/// @notice Wraps Uniswap V3 positions in a non-fungible token interface which allows for them to be transferred
/// and authorized.
interface INonfungiblePositionManager is
    IPoolInitializer,
    IPeripheryPayments,
    IPeripheryImmutableState,
    IERC721Metadata,
    IERC721Enumerable,
    IERC721Permit
{
    /// @notice Emitted when liquidity is increased for a position NFT
    /// @dev Also emitted when a token is minted
    /// @param tokenId The ID of the token for which liquidity was increased
    /// @param liquidity The amount by which liquidity for the NFT position was increased
    /// @param amount0 The amount of token0 that was paid for the increase in liquidity
    /// @param amount1 The amount of token1 that was paid for the increase in liquidity
    event IncreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
    /// @notice Emitted when liquidity is decreased for a position NFT
    /// @param tokenId The ID of the token for which liquidity was decreased
    /// @param liquidity The amount by which liquidity for the NFT position was decreased
    /// @param amount0 The amount of token0 that was accounted for the decrease in liquidity
    /// @param amount1 The amount of token1 that was accounted for the decrease in liquidity
    event DecreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
    /// @notice Emitted when tokens are collected for a position NFT
    /// @dev The amounts reported may not be exactly equivalent to the amounts transferred, due to rounding behavior
    /// @param tokenId The ID of the token for which underlying tokens were collected
    /// @param recipient The address of the account that received the collected tokens
    /// @param amount0 The amount of token0 owed to the position that was collected
    /// @param amount1 The amount of token1 owed to the position that was collected
    event Collect(uint256 indexed tokenId, address recipient, uint256 amount0, uint256 amount1);

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

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

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

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

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

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

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

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

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

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

// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;

interface IProtocolFeeCollector {
    // -------- Types --------
    enum FeeType {
        LIQUIDITY,
        FEES,
        DEPOSIT
    }

    // -------- Events --------
    event UpdatedProtocolFees(uint256 liquidityProtocolFee, uint256 feesProtocolFee, uint256 depositProtocolFee);
    event UpdatedProtocolFee(FeeType indexed protocolFeeType, uint256 protocolFeeBps);
    event WithdrawnProtocolFee(address indexed token, address indexed recipient, uint256 amount);
    event WithdrawnETH(address recipient, uint256 amount);

    // -------- External --------
    function setFees(uint256 _liquidityFeeBps, uint256 _feesFeeBps, uint256 _depositFeeBps) external;

    function setLiquidityProtocolFee(uint256 feeBps) external;
    function setFeesProtocolFee(uint256 feeBps) external;
    function setDepositProtocolFee(uint256 feeBps) external;

    function withdrawProtocolFees(address tokenOut, address recipient) external;
    function withdrawETH(address payable recipient) external;

    // -------- Views --------
    function getAccumulatedProtocolFees(address token) external view returns (uint256);

    function calculateProtocolFee(uint256 amount, FeeType feeType) external view returns (uint256);
}

// 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;
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.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) {
        unchecked {
            // 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 = (0 - 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) {
        unchecked {
            result = mulDiv(a, b, denominator);
            if (mulmod(a, b, denominator) > 0) {
                require(result < type(uint256).max);
                result++;
            }
        }
    }
}

File 11 of 32 : 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 12 of 32 : 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;
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
interface IERC20 {
    /**
     * @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);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)

pragma solidity >=0.6.2;

import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";

/**
 * @title IERC1363
 * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
 *
 * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
 * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
 */
interface IERC1363 is IERC20, IERC165 {
    /*
     * Note: the ERC-165 identifier for this interface is 0xb0202a11.
     * 0xb0202a11 ===
     *   bytes4(keccak256('transferAndCall(address,uint256)')) ^
     *   bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
     */

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @param data Additional data with no specified format, sent in call to `spender`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}

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

// 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
    /// @return 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.
    /// @return observationIndex The index of the last oracle observation that was written,
    /// @return observationCardinality The current maximum number of observations stored in the pool,
    /// @return observationCardinalityNext The next maximum number of observations, to be updated when the observation.
    /// @return 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
    /// @return The liquidity at the current price of the pool
    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
    /// @return liquidityNet how much liquidity changes when the pool price crosses the tick,
    /// @return feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0,
    /// @return feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1,
    /// @return tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick
    /// @return secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick,
    /// @return secondsOutside the seconds spent on the other side of the tick from the current tick,
    /// @return 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,
    /// @return feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke,
    /// @return feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke,
    /// @return tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke,
    /// @return 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,
    /// @return tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp,
    /// @return secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp,
    /// @return 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
        );
}

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

// 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;
}

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

/// @title Errors emitted by a pool
/// @notice Contains all events emitted by the pool
interface IUniswapV3PoolErrors {
    error LOK();
    error TLU();
    error TLM();
    error TUM();
    error AI();
    error M0();
    error M1();
    error AS();
    error IIA();
    error L();
    error F0();
    error F1();
}

File 21 of 32 : 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);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Metadata.sol)

pragma solidity >=0.6.2;

import {IERC721} from "../IERC721.sol";

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Enumerable.sol)

pragma solidity >=0.6.2;

import {IERC721} from "../IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Enumerable is IERC721 {
    /**
     * @dev Returns the total amount of tokens stored by the contract.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns a token ID owned by `owner` at a given `index` of its token list.
     * Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
     */
    function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);

    /**
     * @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
     * Use along with {totalSupply} to enumerate all tokens.
     */
    function tokenByIndex(uint256 index) external view returns (uint256);
}

// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

/// @title Creates and initializes V3 Pools
/// @notice Provides a method for creating and initializing a pool, if necessary, for bundling with other methods that
/// require the pool to exist.
interface IPoolInitializer {
    /// @notice Creates a new pool if it does not exist, then initializes if not initialized
    /// @dev This method can be bundled with others via IMulticall for the first action (e.g. mint) performed against a pool
    /// @param token0 The contract address of token0 of the pool
    /// @param token1 The contract address of token1 of the pool
    /// @param fee The fee amount of the v3 pool for the specified token pair
    /// @param sqrtPriceX96 The initial square root price of the pool as a Q64.96 value
    /// @return pool Returns the pool address based on the pair of tokens and fee, will return the newly created pool address if necessary
    function createAndInitializePoolIfNecessary(
        address token0,
        address token1,
        uint24 fee,
        uint160 sqrtPriceX96
    ) external payable returns (address pool);
}

// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;

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

/// @title ERC721 with permit
/// @notice Extension to ERC721 that includes a permit function for signature based approvals
interface IERC721Permit is IERC721 {
    /// @notice The permit typehash used in the permit signature
    /// @return The typehash for the permit
    function PERMIT_TYPEHASH() external pure returns (bytes32);

    /// @notice The domain separator used in the permit signature
    /// @return The domain seperator used in encoding of permit signature
    function DOMAIN_SEPARATOR() external view returns (bytes32);

    /// @notice Approve of a specific token ID for spending by spender via signature
    /// @param spender The account that is being approved
    /// @param tokenId The ID of the token that is being approved for spending
    /// @param deadline The deadline timestamp by which the call must be mined for the approve to work
    /// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s`
    /// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s`
    /// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v`
    function permit(
        address spender,
        uint256 tokenId,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external payable;
}

// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;

/// @title Periphery Payments
/// @notice Functions to ease deposits and withdrawals of ETH
interface IPeripheryPayments {
    /// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH.
    /// @dev The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users.
    /// @param amountMinimum The minimum amount of WETH9 to unwrap
    /// @param recipient The address receiving ETH
    function unwrapWETH9(uint256 amountMinimum, address recipient) external payable;

    /// @notice Refunds any ETH balance held by this contract to the `msg.sender`
    /// @dev Useful for bundling with mint or increase liquidity that uses ether, or exact output swaps
    /// that use ether for the input amount
    function refundETH() external payable;

    /// @notice Transfers the full amount of a token held by this contract to recipient
    /// @dev The amountMinimum parameter prevents malicious contracts from stealing the token from users
    /// @param token The contract address of the token which will be transferred to `recipient`
    /// @param amountMinimum The minimum amount of token required for a transfer
    /// @param recipient The destination address of the token
    function sweepToken(
        address token,
        uint256 amountMinimum,
        address recipient
    ) external payable;
}

// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Immutable state
/// @notice Functions that return immutable state of the router
interface IPeripheryImmutableState {
    /// @return Returns the address of the Uniswap V3 factory
    function factory() external view returns (address);

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

// 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 = 0xa598dd2fba360510c5a8f02f44423a4468e902df5857dbce3ca162a43a3a31ff;

    /// @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(
            uint160(
                uint256(
                    keccak256(
                        abi.encodePacked(
                            hex'ff',
                            factory,
                            keccak256(abi.encode(key.token0, key.token1, key.fee)),
                            POOL_INIT_CODE_HASH
                        )
                    )
                )
            )
        );
    }
}

File 29 of 32 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)

pragma solidity >=0.4.16;

import {IERC20} from "../token/ERC20/IERC20.sol";

File 30 of 32 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)

pragma solidity >=0.4.16;

import {IERC165} from "../utils/introspection/IERC165.sol";

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/IERC721.sol)

pragma solidity >=0.6.2;

import {IERC165} from "../../utils/introspection/IERC165.sol";

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

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

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

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

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

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

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

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC-721
     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
     * understand this adds an external call which potentially creates a reentrancy vulnerability.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 tokenId) external;

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)

pragma solidity >=0.4.16;

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

Settings
{
  "remappings": [
    "@openzeppelin/=lib/openzeppelin-contracts/",
    "@uniswap/v3-core/=lib/v3-core/",
    "@uniswap/v3-periphery/=lib/v3-periphery/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "forge-std/=lib/forge-std/src/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "v3-core/=lib/v3-core/contracts/",
    "v3-periphery/=lib/v3-periphery/contracts/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "cancun",
  "viaIR": false
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"contract INonfungiblePositionManager","name":"_positionManager","type":"address"},{"internalType":"contract IProtocolFeeCollector","name":"_protocolFeeCollector","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"Amount0LessThanMin","type":"error"},{"inputs":[],"name":"Amount1LessThanMin","type":"error"},{"inputs":[],"name":"AmountLessThanMin","type":"error"},{"inputs":[],"name":"InvalidSwapCallbackCaller","type":"error"},{"inputs":[],"name":"InvalidSwapCallbackDeltas","type":"error"},{"inputs":[],"name":"InvalidTokenOut","type":"error"},{"inputs":[],"name":"LiquidityLessThanMin","type":"error"},{"inputs":[],"name":"NotPositionOwner","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"T","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"positionId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"ClaimedFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"positionId","type":"uint256"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ClaimedFeesInToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"positionId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountToken0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountToken1","type":"uint256"}],"name":"CompoundedFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"positionId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountToken0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountToken1","type":"uint256"}],"name":"LiquidityIncreased","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"positionId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"liquidity","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"},{"indexed":false,"internalType":"int24","name":"tickLower","type":"int24"},{"indexed":false,"internalType":"int24","name":"tickUpper","type":"int24"},{"indexed":false,"internalType":"uint256","name":"sqrtPriceX96","type":"uint256"}],"name":"PositionCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"positionId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"oldPositionId","type":"uint256"},{"indexed":false,"internalType":"int24","name":"tickLower","type":"int24"},{"indexed":false,"internalType":"int24","name":"tickUpper","type":"int24"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"RangeMoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"positionId","type":"uint256"},{"indexed":false,"internalType":"address","name":"token0","type":"address"},{"indexed":false,"internalType":"address","name":"token1","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"WithdrawnBothTokens","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"positionId","type":"uint256"},{"indexed":false,"internalType":"address","name":"tokenOut","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"WithdrawnSingleToken","type":"event"},{"inputs":[],"name":"PRECISION","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"positionId","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"minAmountOut0","type":"uint256"},{"internalType":"uint256","name":"minAmountOut1","type":"uint256"}],"name":"claimFees","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"positionId","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"}],"name":"claimFees","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"positionId","type":"uint256"},{"internalType":"uint128","name":"minLiquidity","type":"uint128"}],"name":"compoundFees","outputs":[{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"added0","type":"uint256"},{"internalType":"uint256","name":"added1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"poolAddress","type":"address"},{"internalType":"uint256","name":"amountIn0","type":"uint256"},{"internalType":"uint256","name":"amountIn1","type":"uint256"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"minLiquidity","type":"uint256"}],"name":"createPosition","outputs":[{"internalType":"uint256","name":"positionId","type":"uint256"},{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"contract IUniswapV3Factory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pool","type":"address"}],"name":"getCurrentSqrtPriceX96","outputs":[{"internalType":"uint256","name":"sqrtPriceX96","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"poolAddress","type":"address"}],"name":"getPoolInfo","outputs":[{"components":[{"internalType":"address","name":"pool","type":"address"},{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"}],"internalType":"struct LPManager.PoolInfo","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"positionId","type":"uint256"}],"name":"getPosition","outputs":[{"components":[{"internalType":"address","name":"pool","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"unclaimedFee0","type":"uint256"},{"internalType":"uint256","name":"unclaimedFee1","type":"uint256"},{"internalType":"uint128","name":"claimedFee0","type":"uint128"},{"internalType":"uint128","name":"claimedFee1","type":"uint128"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"uint256","name":"price","type":"uint256"}],"internalType":"struct LPManager.Position","name":"position","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"positionId","type":"uint256"},{"internalType":"uint256","name":"amountIn0","type":"uint256"},{"internalType":"uint256","name":"amountIn1","type":"uint256"},{"internalType":"uint128","name":"minLiquidity","type":"uint128"}],"name":"increaseLiquidity","outputs":[{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"added0","type":"uint256"},{"internalType":"uint256","name":"added1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"positionId","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"int24","name":"newLower","type":"int24"},{"internalType":"int24","name":"newUpper","type":"int24"},{"internalType":"uint256","name":"minLiquidity","type":"uint256"}],"name":"moveRange","outputs":[{"internalType":"uint256","name":"newPositionId","type":"uint256"},{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"positionManager","outputs":[{"internalType":"contract INonfungiblePositionManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"protocolFeeCollector","outputs":[{"internalType":"contract IProtocolFeeCollector","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int256","name":"amount0Delta","type":"int256"},{"internalType":"int256","name":"amount1Delta","type":"int256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"uniswapV3SwapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"positionId","type":"uint256"},{"internalType":"uint32","name":"percent","type":"uint32"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"positionId","type":"uint256"},{"internalType":"uint32","name":"percent","type":"uint32"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"minAmountOut0","type":"uint256"},{"internalType":"uint256","name":"minAmountOut1","type":"uint256"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]

60e060405234801561000f575f5ffd5b50604051613d28380380613d2883398101604081905261002e916100cc565b6001600160a01b03808316608081905290821660a0526040805163c45a015560e01b8152905163c45a0155916004808201926020929091908290030181865afa15801561007d573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906100a19190610104565b6001600160a01b031660c052506101269050565b6001600160a01b03811681146100c9575f5ffd5b50565b5f5f604083850312156100dd575f5ffd5b82516100e8816100b5565b60208401519092506100f9816100b5565b809150509250929050565b5f60208284031215610114575f5ffd5b815161011f816100b5565b9392505050565b60805160a05160c051613b536101d55f395f81816102ed0152818161103d0152611dab01525f81816102a80152818161142a01526114b101525f81816102560152818161084201528181610c0601528181611189015281816112870152818161158d015281816117890152818161187b01528181611a1601528181611c8501528181612209015281816122f601528181612642015281816126cb0152818161274101526127cb0152613b535ff3fe608060405234801561000f575f5ffd5b50600436106100fb575f3560e01c8063791b98bc11610093578063c45a015511610063578063c45a0155146102e8578063d74b48411461030f578063eb02c30114610322578063fa461e3314610342575f5ffd5b8063791b98bc146102515780638291613f14610290578063850a1501146102a3578063aaf5eb68146102ca575f5ffd5b806342d60518116100ce57806342d60518146101c8578063494d6eb2146101f05780634aa2ccde1461022b5780635f95389b1461023e575f5ffd5b806306bfa938146100ff5780630f3e3d6c1461015c5780631c0706681461017d5780633a9307ae146101b5575b5f5ffd5b61011261010d366004612f9a565b610357565b6040805182516001600160a01b03908116825260208085015182169083015283830151169181019190915260609182015162ffffff16918101919091526080015b60405180910390f35b61016f61016a366004612fc6565b6104dd565b604051908152602001610153565b61019061018b366004613031565b61064b565b604080516001600160801b039094168452602084019290925290820152606001610153565b61016f6101c3366004612f9a565b610721565b6101db6101d636600461306f565b610799565b60408051928352602083019190915201610153565b6102036101fe3660046130b7565b610831565b604080519485526001600160801b039093166020850152918301526060820152608001610153565b6101db6102393660046130fd565b6109b7565b61020361024c36600461314b565b610ae2565b6102787f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610153565b61019061029e3660046131c2565b610bf6565b6102787f000000000000000000000000000000000000000000000000000000000000000081565b6102d361271081565b60405163ffffffff9091168152602001610153565b6102787f000000000000000000000000000000000000000000000000000000000000000081565b61016f61031d3660046131f0565b610d58565b610335610330366004613235565b610e71565b604051610153919061324c565b61035561035036600461334f565b610feb565b005b604080516080810182525f8082526020820181905291810182905260608101919091526040518060800160405280836001600160a01b03168152602001836001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156103d0573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103f491906133db565b6001600160a01b03168152602001836001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561043e573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061046291906133db565b6001600160a01b03168152602001836001600160a01b031663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa1580156104ac573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906104d09190613411565b62ffffff16905292915050565b5f5f6104e887611161565b905080602001516001600160a01b0316846001600160a01b03161480610523575080604001516001600160a01b0316846001600160a01b0316145b61053f5760405162db68fd60e51b815260040160405180910390fd5b5f5f61054b8989611269565b9150915082602001516001600160a01b0316866001600160a01b0316036105965761058f836020015161057f5f84876113cf565b6105899085613440565b5f611402565b93506105b7565b6105b483604001516105aa600185876113cf565b6105899084613440565b93505b848410156105d8576040516301f6c75f60e41b815260040160405180910390fd5b6105ec6001600160a01b03871688866114eb565b604080516001600160a01b0388168152602081018690529081018390526060810182905289907f15c9d8a29603b0fd35224d2d2c8c3e5b1de8dd934da09d77a325c440c414996e9060800160405180910390a250505095945050505050565b5f5f5f5f6106588861154f565b905086156106905780516020015161067b906001600160a01b031633308a6116a6565b80516020015161068d90886002611402565b96505b85156106c6578051604001516106b1906001600160a01b03163330896116a6565b8051604001516106c390876002611402565b95505b6106d388828989896116e5565b6040805183815260208101839052939750919550935089917f3e7eb8fbb7b6a8eb3e381b450c3f3d92463dfc879765790e9853f3024269edd9910160405180910390a2509450945094915050565b5f816001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa15801561075e573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610782919061348e565b50506001600160a01b039094169695505050505050565b5f5f6107a686865f61185d565b9092509050838210156107cc576040516314e6bc3960e21b815260040160405180910390fd5b828110156107ed57604051631eaaddbf60e21b815260040160405180910390fd5b604080518381526020810183905287917fd1a27b0a6e4ccfb5e88f3bf8541d20f6f570f8914096eca1ee2cdb02272b2d23910160405180910390a294509492505050565b5f5f5f5f88336001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316636352211e836040518263ffffffff1660e01b815260040161088e91815260200190565b602060405180830381865afa1580156108a9573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108cd91906133db565b6001600160a01b0316146108f4576040516370d645e360e01b815260040160405180910390fd5b5f6108fe8b61154f565b905061090c8b612710611a06565b50505f5f6109198d611b3c565b60028d810b60208701528c900b6040860152909250905061093d8383838f8d611b5b565b604051939b50919950975095508d9089907f30e6efd0a3eb84003ce49aeb795850cc19ba47c460d7a8e5bd607b620bdaf7dc9061099f908f908f908c908c90600294850b81529290930b60208301526040820152606081019190915260800190565b60405180910390a35050505095509550955095915050565b5f5f5f6109c388611161565b90506109cf8888611269565b602083015191945092506109e490845f611402565b92506109f58160400151835f611402565b915084831015610a18576040516314e6bc3960e21b815260040160405180910390fd5b83821015610a3957604051631eaaddbf60e21b815260040160405180910390fd5b8215610a58576020810151610a58906001600160a01b031687856114eb565b8115610a77576040810151610a77906001600160a01b031687846114eb565b60208082015160408084015181516001600160a01b0393841681529216928201929092529081018490526060810183905288907ff03e26d7ce4a5b79cb5975966bf6a07469ce355d8def91776f0deab9296e51e99060800160405180910390a2509550959350505050565b5f5f5f5f5f610af08c610357565b90508a15610b12576020810151610b12906001600160a01b031633308e6116a6565b8915610b32576040810151610b32906001600160a01b031633308d6116a6565b5f60405180606001604052808381526020018b60020b81526020018a60020b8152509050610b63818d8d8b8b611b5b565b80965081975082985083995050505050857f4ee6534f885c00e8a879fd1448d3f547b201baa92ca45e050972942253fa35768686868e8e610ba6895f0151610721565b604080516001600160801b039097168752602087019590955293850192909252600290810b60608501520b608083015260a082015260c00160405180910390a25050975097509750979350505050565b5f5f5f84336001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316636352211e836040518263ffffffff1660e01b8152600401610c5291815260200190565b602060405180830381865afa158015610c6d573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c9191906133db565b6001600160a01b031614610cb8576040516370d645e360e01b815260040160405180910390fd5b5f610cc28761154f565b90505f5f610ccf89611b3c565b91509150610ce6835f015160200151836001611402565b9150610cfb835f015160400151826001611402565b9050610d0a898484848c6116e5565b6040805183815260208101839052939a5091985096508a917fa2408b9a719abe3b2f43b5e40f63c3d7f326086e61505fe5ac9f2d4aab78e2a2910160405180910390a2505050509250925092565b5f5f610d6386611161565b905080602001516001600160a01b0316846001600160a01b03161480610d9e575080604001516001600160a01b0316846001600160a01b0316145b610dba5760405162db68fd60e51b815260040160405180910390fd5b5f5f610dec888885602001516001600160a01b0316896001600160a01b031614610de557600261185d565b600161185d565b91509150815f14610dfd5781610dff565b805b935084841015610e22576040516301f6c75f60e41b815260040160405180910390fd5b856001600160a01b0316887f8636097e39ca626a39220baabff34cfba63780e1bdd128e1048bc02c912d76ca86604051610e5e91815260200190565b60405180910390a3505050949350505050565b60408051610180810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810182905290610eda83611c29565b90505f610ef3825f015183602001518460400151611d92565b90505f5f610f1983856060015186608001518760a001518860c001518960e00151611e2b565b91509150604051806101800160405280846001600160a01b03168152602001856040015162ffffff168152602001855f01516001600160a01b0316815260200185602001516001600160a01b031681526020018560a001516001600160801b031681526020018381526020018281526020018561010001516001600160801b031681526020018561012001516001600160801b03168152602001856060015160020b8152602001856080015160020b8152602001610fdf85875f015188602001516120e9565b90529695505050505050565b5f841380610ff857505f83135b611015576040516304871fa360e41b815260040160405180910390fd5b5f808061102484860186613514565b604051630b4c774160e11b8152929550909350915033907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690631698ee829061107e9087908790879060040161355c565b602060405180830381865afa158015611099573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110bd91906133db565b6001600160a01b0316146110e4576040516394490a3d60e01b815260040160405180910390fd5b5f5f5f891361110857846001600160a01b0316846001600160a01b0316108861111f565b836001600160a01b0316856001600160a01b031610895b9150915081156111425761113d6001600160a01b03861633836114eb565b611156565b6111566001600160a01b03851633836114eb565b505050505050505050565b604080516080810182525f8082526020820181905291810182905260608101919091525f5f5f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166399fbab88866040518263ffffffff1660e01b81526004016111d591815260200190565b61018060405180830381865afa1580156111f1573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611215919061358f565b5050505050505094509450945050505f611230848484611d92565b604080516080810182526001600160a01b039283168152958216602087015293169284019290925262ffffff1660608301525092915050565b6040516331a9108f60e11b8152600481018390525f908190849033907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690636352211e90602401602060405180830381865afa1580156112d4573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112f891906133db565b6001600160a01b03161461131f576040516370d645e360e01b815260040160405180910390fd5b5f5f61132b8787611a06565b915091505f5f61133a896121e7565b90925090506113bf893061271063ffffffff8c16611361896001600160801b038916613669565b61136b919061367c565b61137591906136a7565b61137f9088613440565b61271063ffffffff8d1661139c896001600160801b038916613669565b6113a6919061367c565b6113b091906136a7565b6113ba9088613440565b612287565b909a909950975050505050505050565b5f5f5f6113de8686865f61236f565b91509150856113ed57816113ef565b805b6113f8906136ba565b9695505050505050565b5f825f0361141157505f6114e4565b6040516315ae6bf160e21b81525f906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906356b9afc49061146190879087906004016136e8565b602060405180830381865afa15801561147c573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114a09190613718565b90506114d66001600160a01b0386167f0000000000000000000000000000000000000000000000000000000000000000836114eb565b6114e08185613669565b9150505b9392505050565b6040516001600160a01b0383811660248301526044820183905261154a91859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050612476565b505050565b6040805160e0810182525f606082018181526080830182905260a0830182905260c08301829052825260208201819052918101919091525f5f5f5f5f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166399fbab88886040518263ffffffff1660e01b81526004016115d991815260200190565b61018060405180830381865afa1580156115f5573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611619919061358f565b50505050509650965096509650965050505f6040518060800160405280611641888888611d92565b6001600160a01b03168152602001876001600160a01b03168152602001866001600160a01b031681526020018562ffffff16815250905060405180606001604052808281526020018460020b81526020018360020b8152509650505050505050919050565b6040516001600160a01b0384811660248301528381166044830152606482018390526116df9186918216906323b872dd90608401611518565b50505050565b5f5f5f6116f38787876124e6565b88516020015191975095506117089087612625565b8651604001516117189086612625565b6040805160c081018252898152602081018881528183018881525f60608401818152608085019182525f1960a08601908152955163219f5d1760e01b815294516004860152925160248501529051604484015290516064830152516084820152905160a48201526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063219f5d179060c4016060604051808303815f875af11580156117cf573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117f3919061372f565b919450925090506001600160801b0380851690841610156118275760405163bd2a915d60e01b815260040160405180910390fd5b865160208101516040909101516118529190611843858a613669565b61184d858a613669565b6126f5565b955095509592505050565b6040516331a9108f60e11b8152600481018490525f908190859033907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690636352211e90602401602060405180830381865afa1580156118c8573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118ec91906133db565b6001600160a01b031614611913576040516370d645e360e01b815260040160405180910390fd5b5f61191d87611161565b905061192887611b3c565b6020830151919550935061193e90856001611402565b93506119508160400151846001611402565b92505f856002811115611965576119656136d4565b146119be57600185600281111561197e5761197e6136d4565b036119a25761198e5f84836113cf565b6119989085613440565b93505f92506119be565b6119ae600185836113cf565b6119b89084613440565b92505f93505b83156119dd5760208101516119dd906001600160a01b031687866114eb565b82156119fc5760408101516119fc906001600160a01b031687856114eb565b5050935093915050565b5f5f5f611a1285612729565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630c49ccbe6040518060a0016040528088815260200161271063ffffffff168863ffffffff1686611a6f9190613763565b611a79919061378c565b6001600160801b031681526020015f81526020015f81526020015f198152506040518263ffffffff1660e01b8152600401611af191905f60a082019050825182526001600160801b03602084015116602083015260408301516040830152606083015160608301526080830151608083015292915050565b60408051808303815f875af1158015611b0c573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b3091906137b9565b90969095509350505050565b5f5f611b5183306001600160801b0380612287565b9094909350915050565b5f5f5f5f611b71895f015160200151895f611402565b9750611b85895f015160400151885f611402565b9650611b928989896124e6565b8a51602001519199509750611ba79089612625565b885160400151611bb79088612625565b611bc3898989896127c5565b929650909450925090506001600160801b038316851115611bf75760405163bd2a915d60e01b815260040160405180910390fd5b88516020810151604090910151611c1d9190611c13858c613669565b61184d858c613669565b95509550955095915050565b60408051610140810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e0810182905261010081018290526101208101919091525f5f5f5f5f5f5f5f5f5f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166399fbab888d6040518263ffffffff1660e01b8152600401611cd191815260200190565b61018060405180830381865afa158015611ced573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611d11919061358f565b60408051610140810182526001600160a01b039b8c1681529a90991660208b015262ffffff90971697890197909752600294850b60608901529290930b60808701526001600160801b0390811660a087015260c086019290925260e0850152918216610100840152166101208201529e9d5050505050505050505050505050565b604051630b4c774160e11b81525f906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690631698ee8290611de49087908790879060040161355c565b602060405180830381865afa158015611dff573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e2391906133db565b949350505050565b5f5f5f886001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa158015611e6a573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e8e919061348e565b50505050509150505f896001600160a01b031663f30583996040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ed3573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ef79190613718565b90505f8a6001600160a01b031663461413196040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f36573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f5a9190613718565b60405163f30dba9360e01b815260028c900b60048201529091505f9081906001600160a01b038e169063f30dba939060240161010060405180830381865afa158015611fa8573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611fcc91906137db565b505050509350935050505f5f8e6001600160a01b031663f30dba938e6040518263ffffffff1660e01b815260040161200d919060029190910b815260200190565b61010060405180830381865afa158015612029573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061204d91906137db565b505050509350935050505f5f8f60020b8960020b121561207457505081840381840361209d565b8e60020b8960020b1261208e57505083820383820361209d565b83868903039150828588030390505b6120b78d83038f6001600160801b0316600160801b6128f5565b9a506120d38c82038f6001600160801b0316600160801b6128f5565b9950505050505050505050965096945050505050565b5f5f6120f485610721565b90505f6121068283600160c01b6128f5565b90506113f881866001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015612148573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061216c919061387a565b61217790600a61396e565b866001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156121b3573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906121d7919061387a565b6121e290600a61396e565b6128f5565b60405163133f757160e31b8152600481018290525f9081906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906399fbab889060240161018060405180830381865afa15801561224f573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612273919061358f565b909e909d509b505050505050505050505050565b604080516080810182528581526001600160a01b03858116602083019081526001600160801b0386811684860190815286821660608601908152955163fc6f786560e01b815294516004860152915183166024850152905181166044840152925190921660648201525f9182917f00000000000000000000000000000000000000000000000000000000000000009091169063fc6f7865906084015b60408051808303815f875af115801561233e573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061236291906137b9565b9097909650945050505050565b5f5f845f0361238257505f90508061246d565b826001600160a01b03165f036123ce57856123bb576123b6600173fffd8963efd1fc6a506488495d951d5263988d2661397c565b6123cb565b6123cb6401000276a3600161399b565b92505b83516001600160a01b031663128acb08308888878261241c5789604001518a602001518b606001516040516020016124089392919061355c565b60405160208183030381529060405261244d565b89602001518a604001518b6060015160405160200161243d9392919061355c565b6040516020818303038152906040525b6040518663ffffffff1660e01b81526004016123239594939291906139ba565b94509492505050565b5f5f60205f8451602086015f885af180612495576040513d5f823e3d81fd5b50505f513d915081156124ac5780600114156124b9565b6001600160a01b0384163b155b156116df57604051635274afe760e01b81526001600160a01b038516600482015260240160405180910390fd5b5f5f5f6124f28661299f565b80519091505f90612518908690600160c01b906121e2906001600160a01b03168061367c565b90505f8061253a612529848a613440565b855160208701516040880151612a0f565b8551919350915061256490829061255a906001600160a01b03168061367c565b600160c01b6128f5565b9050818811156125c3575f61257a600186612ad6565b90505f80612595600161258d878e613669565b8e518661236f565b90925090506125a4828c613669565b9a506125af816136ba565b6125b9908b613440565b9950505050612612565b80871115612612575f6125d65f86612ad6565b90505f806125e88161258d868d613669565b91509150816125f6906136ba565b612600908c613440565b9a5061260c818b613669565b99505050505b878795509550505050505b935093915050565b604051636eb1769f60e11b81523060048201526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116602483015282919084169063dd62ed3e90604401602060405180830381865afa158015612692573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906126b69190613718565b10156126f1576126f16001600160a01b0383167f00000000000000000000000000000000000000000000000000000000000000005f19612b94565b5050565b811561270f5761270f6001600160a01b03851633846114eb565b80156116df576116df6001600160a01b03841633836114eb565b60405163133f757160e31b8152600481018290525f907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906399fbab889060240161018060405180830381865afa15801561278f573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906127b3919061358f565b50929c9b505050505050505050505050565b5f5f5f5f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663883164566040518061016001604052808b5f0151602001516001600160a01b031681526020018b5f0151604001516001600160a01b031681526020018b5f01516060015162ffffff1681526020018b6020015160020b81526020018b6040015160020b81526020018a81526020018981526020015f81526020015f8152602001886001600160a01b03168152602001428152506040518263ffffffff1660e01b81526004016128a39190613a1d565b6080604051808303815f875af11580156128bf573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906128e39190613ae1565b929b919a509850909650945050505050565b5f80805f19858709858702925082811083820303915050805f03612929575f841161291e575f5ffd5b5082900490506114e4565b808411612934575f5ffd5b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b604080516060810182525f80825260208201819052918101919091528151516129c790610721565b6001600160a01b0316815260208201516129e090612c23565b6001600160a01b0316602082015260408201516129fc90612c23565b6001600160a01b03166040820152919050565b5f5f836001600160a01b0316856001600160a01b031611612a325785915061246d565b826001600160a01b0316856001600160a01b03161015612ace575f612a776001600160a01b038516612a64878961397c565b6001600160a01b0316600160601b6128f5565b90505f612a916001600160a01b038816612a64898861397c565b90505f612aa383600160601b846128f5565b9050612ab889600160601b6121e28185613440565b9450612ac4858a613669565b935050505061246d565b509492505050565b5f8215612b3b5781604001516001600160a01b0316825f01516001600160a01b031610612b0857506040810151612b8e565b81602001516001600160a01b0316825f01516001600160a01b03161115612b3457506020810151612b8e565b505f612b8e565b81602001516001600160a01b0316825f01516001600160a01b031611612b6657506020810151612b8e565b81604001516001600160a01b0316825f01516001600160a01b03161015612b34575060408101515b92915050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b179052612be58482612f3e565b6116df576040516001600160a01b0384811660248301525f6044830152612c1991869182169063095ea7b390606401611518565b6116df8482612476565b5f5f5f8360020b12612c38578260020b612c3f565b8260020b5f035b9050620d89e8811115612c65576040516315e4079d60e11b815260040160405180910390fd5b5f816001165f03612c7a57600160801b612c8c565b6ffffcb933bd6fad37aa2d162d1a5940015b70ffffffffffffffffffffffffffffffffff1690506002821615612cc0576ffff97272373d413259a46990580e213a0260801c5b6004821615612cdf576ffff2e50f5f656932ef12357cf3c7fdcc0260801c5b6008821615612cfe576fffe5caca7e10e4e61c3624eaa0941cd00260801c5b6010821615612d1d576fffcb9843d60f6159c9db58835c9266440260801c5b6020821615612d3c576fff973b41fa98c081472e6896dfb254c00260801c5b6040821615612d5b576fff2ea16466c96a3843ec78b326b528610260801c5b6080821615612d7a576ffe5dee046a99a2a811c461f1969c30530260801c5b610100821615612d9a576ffcbe86c7900a88aedcffc83b479aa3a40260801c5b610200821615612dba576ff987a7253ac413176f2b074cf7815e540260801c5b610400821615612dda576ff3392b0822b70005940c7a398e4b70f30260801c5b610800821615612dfa576fe7159475a2c29b7443b29c7fa6e889d90260801c5b611000821615612e1a576fd097f3bdfd2022b8845ad8f792aa58250260801c5b612000821615612e3a576fa9f746462d870fdf8a65dc1f90e061e50260801c5b614000821615612e5a576f70d869a156d2a1b890bb3df62baf32f70260801c5b618000821615612e7a576f31be135f97d08fd981231505542fcfa60260801c5b62010000821615612e9b576f09aa508b5b7a84e1c677de54f3e99bc90260801c5b62020000821615612ebb576e5d6af8dedb81196699c329225ee6040260801c5b62040000821615612eda576d2216e584f5fa1ea926041bedfe980260801c5b62080000821615612ef7576b048a170391f7dc42444e8fa20260801c5b5f8460020b1315612f1657805f1981612f1257612f12613693565b0490505b640100000000810615612f2a576001612f2c565b5f5b60ff16602082901c0192505050919050565b5f5f5f5f60205f8651602088015f8a5af192503d91505f5190508280156113f857508115612f6f57806001146113f8565b50505050506001600160a01b03163b151590565b6001600160a01b0381168114612f97575f5ffd5b50565b5f60208284031215612faa575f5ffd5b81356114e481612f83565b63ffffffff81168114612f97575f5ffd5b5f5f5f5f5f60a08688031215612fda575f5ffd5b853594506020860135612fec81612fb5565b93506040860135612ffc81612f83565b9250606086013561300c81612f83565b949793965091946080013592915050565b6001600160801b0381168114612f97575f5ffd5b5f5f5f5f60808587031215613044575f5ffd5b84359350602085013592506040850135915060608501356130648161301d565b939692955090935050565b5f5f5f5f60808587031215613082575f5ffd5b84359350602085013561309481612f83565b93969395505050506040820135916060013590565b8060020b8114612f97575f5ffd5b5f5f5f5f5f60a086880312156130cb575f5ffd5b8535945060208601356130dd81612f83565b935060408601356130ed816130a9565b9250606086013561300c816130a9565b5f5f5f5f5f60a08688031215613111575f5ffd5b85359450602086013561312381612fb5565b9350604086013561313381612f83565b94979396509394606081013594506080013592915050565b5f5f5f5f5f5f5f60e0888a031215613161575f5ffd5b873561316c81612f83565b96506020880135955060408801359450606088013561318a816130a9565b9350608088013561319a816130a9565b925060a08801356131aa81612f83565b96999598509396929591949193505060c09091013590565b5f5f604083850312156131d3575f5ffd5b8235915060208301356131e58161301d565b809150509250929050565b5f5f5f5f60808587031215613203575f5ffd5b84359350602085013561321581612f83565b9250604085013561322581612f83565b9396929550929360600135925050565b5f60208284031215613245575f5ffd5b5035919050565b81516001600160a01b0316815261018081016020830151613274602084018262ffffff169052565b50604083015161328f60408401826001600160a01b03169052565b5060608301516132aa60608401826001600160a01b03169052565b5060808301516132c560808401826001600160801b03169052565b5060a083015160a083015260c083015160c083015260e08301516132f460e08401826001600160801b03169052565b506101008301516133116101008401826001600160801b03169052565b5061012083015161332861012084018260020b9052565b5061014083015161333f61014084018260020b9052565b5061016092830151919092015290565b5f5f5f5f60608587031215613362575f5ffd5b8435935060208501359250604085013567ffffffffffffffff811115613386575f5ffd5b8501601f81018713613396575f5ffd5b803567ffffffffffffffff8111156133ac575f5ffd5b8760208284010111156133bd575f5ffd5b949793965060200194505050565b80516133d681612f83565b919050565b5f602082840312156133eb575f5ffd5b81516114e481612f83565b62ffffff81168114612f97575f5ffd5b80516133d6816133f6565b5f60208284031215613421575f5ffd5b81516114e4816133f6565b634e487b7160e01b5f52601160045260245ffd5b80820180821115612b8e57612b8e61342c565b80516133d6816130a9565b805161ffff811681146133d6575f5ffd5b805160ff811681146133d6575f5ffd5b805180151581146133d6575f5ffd5b5f5f5f5f5f5f5f60e0888a0312156134a4575f5ffd5b87516134af81612f83565b60208901519097506134c0816130a9565b95506134ce6040890161345e565b94506134dc6060890161345e565b93506134ea6080890161345e565b92506134f860a0890161346f565b915061350660c0890161347f565b905092959891949750929550565b5f5f5f60608486031215613526575f5ffd5b833561353181612f83565b9250602084013561354181612f83565b91506040840135613551816133f6565b809150509250925092565b6001600160a01b03938416815291909216602082015262ffffff909116604082015260600190565b80516133d68161301d565b5f5f5f5f5f5f5f5f5f5f5f5f6101808d8f0312156135ab575f5ffd5b8c516bffffffffffffffffffffffff811681146135c6575f5ffd5b9b506135d460208e016133cb565b9a506135e260408e016133cb565b99506135f060608e016133cb565b98506135fe60808e01613406565b975061360c60a08e01613453565b965061361a60c08e01613453565b955061362860e08e01613584565b6101008e01516101208f0151919650945092506136486101408e01613584565b91506136576101608e01613584565b90509295989b509295989b509295989b565b81810381811115612b8e57612b8e61342c565b8082028115828204841417612b8e57612b8e61342c565b634e487b7160e01b5f52601260045260245ffd5b5f826136b5576136b5613693565b500490565b5f600160ff1b82016136ce576136ce61342c565b505f0390565b634e487b7160e01b5f52602160045260245ffd5b828152604081016003831061370b57634e487b7160e01b5f52602160045260245ffd5b8260208301529392505050565b5f60208284031215613728575f5ffd5b5051919050565b5f5f5f60608486031215613741575f5ffd5b835161374c8161301d565b602085015160409095015190969495509392505050565b6001600160801b0381811683821602908116908181146137855761378561342c565b5092915050565b5f6001600160801b038316806137a4576137a4613693565b806001600160801b0384160491505092915050565b5f5f604083850312156137ca575f5ffd5b505080516020909101519092909150565b5f5f5f5f5f5f5f5f610100898b0312156137f3575f5ffd5b88516137fe8161301d565b80985050602089015180600f0b8114613815575f5ffd5b60408a015160608b015160808c01519299509097509550600681900b811461383b575f5ffd5b60a08a015190945061384c81612f83565b60c08a015190935061385d81612fb5565b915061386b60e08a0161347f565b90509295985092959890939650565b5f6020828403121561388a575f5ffd5b6114e48261346f565b6001815b600184111561261d578085048111156138b2576138b261342c565b60018416156138c057908102905b60019390931c928002613897565b5f826138dc57506001612b8e565b816138e857505f612b8e565b81600181146138fe576002811461390857613924565b6001915050612b8e565b60ff8411156139195761391961342c565b50506001821b612b8e565b5060208310610133831016604e8410600b8410161715613947575081810a612b8e565b6139535f198484613893565b805f19048211156139665761396661342c565b029392505050565b5f6114e460ff8416836138ce565b6001600160a01b038281168282160390811115612b8e57612b8e61342c565b6001600160a01b038181168382160190811115612b8e57612b8e61342c565b60018060a01b0386168152841515602082015283604082015260018060a01b038316606082015260a060808201525f82518060a0840152806020850160c085015e5f60c0828501015260c0601f19601f8301168401019150509695505050505050565b81516001600160a01b0316815261016081016020830151613a4960208401826001600160a01b03169052565b506040830151613a60604084018262ffffff169052565b506060830151613a75606084018260020b9052565b506080830151613a8a608084018260020b9052565b5060a083015160a083015260c083015160c083015260e083015160e0830152610100830151610100830152610120830151613ad16101208401826001600160a01b03169052565b5061014092830151919092015290565b5f5f5f5f60808587031215613af4575f5ffd5b84516020860151909450613b078161301d565b604086015160609096015194979096509250505056fea2646970667358221220561681335150e1be31bac6e7e7e7045b4540aff0d5d32c3ea574b05e8bfd0ead64736f6c634300081e0033000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe88000000000000000000000000fd3be1d641adaa64c005dc2d6a2ff5bea96ad744

Deployed Bytecode

0x608060405234801561000f575f5ffd5b50600436106100fb575f3560e01c8063791b98bc11610093578063c45a015511610063578063c45a0155146102e8578063d74b48411461030f578063eb02c30114610322578063fa461e3314610342575f5ffd5b8063791b98bc146102515780638291613f14610290578063850a1501146102a3578063aaf5eb68146102ca575f5ffd5b806342d60518116100ce57806342d60518146101c8578063494d6eb2146101f05780634aa2ccde1461022b5780635f95389b1461023e575f5ffd5b806306bfa938146100ff5780630f3e3d6c1461015c5780631c0706681461017d5780633a9307ae146101b5575b5f5ffd5b61011261010d366004612f9a565b610357565b6040805182516001600160a01b03908116825260208085015182169083015283830151169181019190915260609182015162ffffff16918101919091526080015b60405180910390f35b61016f61016a366004612fc6565b6104dd565b604051908152602001610153565b61019061018b366004613031565b61064b565b604080516001600160801b039094168452602084019290925290820152606001610153565b61016f6101c3366004612f9a565b610721565b6101db6101d636600461306f565b610799565b60408051928352602083019190915201610153565b6102036101fe3660046130b7565b610831565b604080519485526001600160801b039093166020850152918301526060820152608001610153565b6101db6102393660046130fd565b6109b7565b61020361024c36600461314b565b610ae2565b6102787f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe8881565b6040516001600160a01b039091168152602001610153565b61019061029e3660046131c2565b610bf6565b6102787f000000000000000000000000fd3be1d641adaa64c005dc2d6a2ff5bea96ad74481565b6102d361271081565b60405163ffffffff9091168152602001610153565b6102787f0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f98481565b61016f61031d3660046131f0565b610d58565b610335610330366004613235565b610e71565b604051610153919061324c565b61035561035036600461334f565b610feb565b005b604080516080810182525f8082526020820181905291810182905260608101919091526040518060800160405280836001600160a01b03168152602001836001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156103d0573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103f491906133db565b6001600160a01b03168152602001836001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561043e573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061046291906133db565b6001600160a01b03168152602001836001600160a01b031663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa1580156104ac573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906104d09190613411565b62ffffff16905292915050565b5f5f6104e887611161565b905080602001516001600160a01b0316846001600160a01b03161480610523575080604001516001600160a01b0316846001600160a01b0316145b61053f5760405162db68fd60e51b815260040160405180910390fd5b5f5f61054b8989611269565b9150915082602001516001600160a01b0316866001600160a01b0316036105965761058f836020015161057f5f84876113cf565b6105899085613440565b5f611402565b93506105b7565b6105b483604001516105aa600185876113cf565b6105899084613440565b93505b848410156105d8576040516301f6c75f60e41b815260040160405180910390fd5b6105ec6001600160a01b03871688866114eb565b604080516001600160a01b0388168152602081018690529081018390526060810182905289907f15c9d8a29603b0fd35224d2d2c8c3e5b1de8dd934da09d77a325c440c414996e9060800160405180910390a250505095945050505050565b5f5f5f5f6106588861154f565b905086156106905780516020015161067b906001600160a01b031633308a6116a6565b80516020015161068d90886002611402565b96505b85156106c6578051604001516106b1906001600160a01b03163330896116a6565b8051604001516106c390876002611402565b95505b6106d388828989896116e5565b6040805183815260208101839052939750919550935089917f3e7eb8fbb7b6a8eb3e381b450c3f3d92463dfc879765790e9853f3024269edd9910160405180910390a2509450945094915050565b5f816001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa15801561075e573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610782919061348e565b50506001600160a01b039094169695505050505050565b5f5f6107a686865f61185d565b9092509050838210156107cc576040516314e6bc3960e21b815260040160405180910390fd5b828110156107ed57604051631eaaddbf60e21b815260040160405180910390fd5b604080518381526020810183905287917fd1a27b0a6e4ccfb5e88f3bf8541d20f6f570f8914096eca1ee2cdb02272b2d23910160405180910390a294509492505050565b5f5f5f5f88336001600160a01b03167f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b0316636352211e836040518263ffffffff1660e01b815260040161088e91815260200190565b602060405180830381865afa1580156108a9573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108cd91906133db565b6001600160a01b0316146108f4576040516370d645e360e01b815260040160405180910390fd5b5f6108fe8b61154f565b905061090c8b612710611a06565b50505f5f6109198d611b3c565b60028d810b60208701528c900b6040860152909250905061093d8383838f8d611b5b565b604051939b50919950975095508d9089907f30e6efd0a3eb84003ce49aeb795850cc19ba47c460d7a8e5bd607b620bdaf7dc9061099f908f908f908c908c90600294850b81529290930b60208301526040820152606081019190915260800190565b60405180910390a35050505095509550955095915050565b5f5f5f6109c388611161565b90506109cf8888611269565b602083015191945092506109e490845f611402565b92506109f58160400151835f611402565b915084831015610a18576040516314e6bc3960e21b815260040160405180910390fd5b83821015610a3957604051631eaaddbf60e21b815260040160405180910390fd5b8215610a58576020810151610a58906001600160a01b031687856114eb565b8115610a77576040810151610a77906001600160a01b031687846114eb565b60208082015160408084015181516001600160a01b0393841681529216928201929092529081018490526060810183905288907ff03e26d7ce4a5b79cb5975966bf6a07469ce355d8def91776f0deab9296e51e99060800160405180910390a2509550959350505050565b5f5f5f5f5f610af08c610357565b90508a15610b12576020810151610b12906001600160a01b031633308e6116a6565b8915610b32576040810151610b32906001600160a01b031633308d6116a6565b5f60405180606001604052808381526020018b60020b81526020018a60020b8152509050610b63818d8d8b8b611b5b565b80965081975082985083995050505050857f4ee6534f885c00e8a879fd1448d3f547b201baa92ca45e050972942253fa35768686868e8e610ba6895f0151610721565b604080516001600160801b039097168752602087019590955293850192909252600290810b60608501520b608083015260a082015260c00160405180910390a25050975097509750979350505050565b5f5f5f84336001600160a01b03167f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b0316636352211e836040518263ffffffff1660e01b8152600401610c5291815260200190565b602060405180830381865afa158015610c6d573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c9191906133db565b6001600160a01b031614610cb8576040516370d645e360e01b815260040160405180910390fd5b5f610cc28761154f565b90505f5f610ccf89611b3c565b91509150610ce6835f015160200151836001611402565b9150610cfb835f015160400151826001611402565b9050610d0a898484848c6116e5565b6040805183815260208101839052939a5091985096508a917fa2408b9a719abe3b2f43b5e40f63c3d7f326086e61505fe5ac9f2d4aab78e2a2910160405180910390a2505050509250925092565b5f5f610d6386611161565b905080602001516001600160a01b0316846001600160a01b03161480610d9e575080604001516001600160a01b0316846001600160a01b0316145b610dba5760405162db68fd60e51b815260040160405180910390fd5b5f5f610dec888885602001516001600160a01b0316896001600160a01b031614610de557600261185d565b600161185d565b91509150815f14610dfd5781610dff565b805b935084841015610e22576040516301f6c75f60e41b815260040160405180910390fd5b856001600160a01b0316887f8636097e39ca626a39220baabff34cfba63780e1bdd128e1048bc02c912d76ca86604051610e5e91815260200190565b60405180910390a3505050949350505050565b60408051610180810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810182905290610eda83611c29565b90505f610ef3825f015183602001518460400151611d92565b90505f5f610f1983856060015186608001518760a001518860c001518960e00151611e2b565b91509150604051806101800160405280846001600160a01b03168152602001856040015162ffffff168152602001855f01516001600160a01b0316815260200185602001516001600160a01b031681526020018560a001516001600160801b031681526020018381526020018281526020018561010001516001600160801b031681526020018561012001516001600160801b03168152602001856060015160020b8152602001856080015160020b8152602001610fdf85875f015188602001516120e9565b90529695505050505050565b5f841380610ff857505f83135b611015576040516304871fa360e41b815260040160405180910390fd5b5f808061102484860186613514565b604051630b4c774160e11b8152929550909350915033907f0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f9846001600160a01b031690631698ee829061107e9087908790879060040161355c565b602060405180830381865afa158015611099573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110bd91906133db565b6001600160a01b0316146110e4576040516394490a3d60e01b815260040160405180910390fd5b5f5f5f891361110857846001600160a01b0316846001600160a01b0316108861111f565b836001600160a01b0316856001600160a01b031610895b9150915081156111425761113d6001600160a01b03861633836114eb565b611156565b6111566001600160a01b03851633836114eb565b505050505050505050565b604080516080810182525f8082526020820181905291810182905260608101919091525f5f5f7f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b03166399fbab88866040518263ffffffff1660e01b81526004016111d591815260200190565b61018060405180830381865afa1580156111f1573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611215919061358f565b5050505050505094509450945050505f611230848484611d92565b604080516080810182526001600160a01b039283168152958216602087015293169284019290925262ffffff1660608301525092915050565b6040516331a9108f60e11b8152600481018390525f908190849033907f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b031690636352211e90602401602060405180830381865afa1580156112d4573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112f891906133db565b6001600160a01b03161461131f576040516370d645e360e01b815260040160405180910390fd5b5f5f61132b8787611a06565b915091505f5f61133a896121e7565b90925090506113bf893061271063ffffffff8c16611361896001600160801b038916613669565b61136b919061367c565b61137591906136a7565b61137f9088613440565b61271063ffffffff8d1661139c896001600160801b038916613669565b6113a6919061367c565b6113b091906136a7565b6113ba9088613440565b612287565b909a909950975050505050505050565b5f5f5f6113de8686865f61236f565b91509150856113ed57816113ef565b805b6113f8906136ba565b9695505050505050565b5f825f0361141157505f6114e4565b6040516315ae6bf160e21b81525f906001600160a01b037f000000000000000000000000fd3be1d641adaa64c005dc2d6a2ff5bea96ad74416906356b9afc49061146190879087906004016136e8565b602060405180830381865afa15801561147c573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114a09190613718565b90506114d66001600160a01b0386167f000000000000000000000000fd3be1d641adaa64c005dc2d6a2ff5bea96ad744836114eb565b6114e08185613669565b9150505b9392505050565b6040516001600160a01b0383811660248301526044820183905261154a91859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050612476565b505050565b6040805160e0810182525f606082018181526080830182905260a0830182905260c08301829052825260208201819052918101919091525f5f5f5f5f7f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b03166399fbab88886040518263ffffffff1660e01b81526004016115d991815260200190565b61018060405180830381865afa1580156115f5573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611619919061358f565b50505050509650965096509650965050505f6040518060800160405280611641888888611d92565b6001600160a01b03168152602001876001600160a01b03168152602001866001600160a01b031681526020018562ffffff16815250905060405180606001604052808281526020018460020b81526020018360020b8152509650505050505050919050565b6040516001600160a01b0384811660248301528381166044830152606482018390526116df9186918216906323b872dd90608401611518565b50505050565b5f5f5f6116f38787876124e6565b88516020015191975095506117089087612625565b8651604001516117189086612625565b6040805160c081018252898152602081018881528183018881525f60608401818152608085019182525f1960a08601908152955163219f5d1760e01b815294516004860152925160248501529051604484015290516064830152516084820152905160a48201526001600160a01b037f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe88169063219f5d179060c4016060604051808303815f875af11580156117cf573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117f3919061372f565b919450925090506001600160801b0380851690841610156118275760405163bd2a915d60e01b815260040160405180910390fd5b865160208101516040909101516118529190611843858a613669565b61184d858a613669565b6126f5565b955095509592505050565b6040516331a9108f60e11b8152600481018490525f908190859033907f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b031690636352211e90602401602060405180830381865afa1580156118c8573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118ec91906133db565b6001600160a01b031614611913576040516370d645e360e01b815260040160405180910390fd5b5f61191d87611161565b905061192887611b3c565b6020830151919550935061193e90856001611402565b93506119508160400151846001611402565b92505f856002811115611965576119656136d4565b146119be57600185600281111561197e5761197e6136d4565b036119a25761198e5f84836113cf565b6119989085613440565b93505f92506119be565b6119ae600185836113cf565b6119b89084613440565b92505f93505b83156119dd5760208101516119dd906001600160a01b031687866114eb565b82156119fc5760408101516119fc906001600160a01b031687856114eb565b5050935093915050565b5f5f5f611a1285612729565b90507f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b0316630c49ccbe6040518060a0016040528088815260200161271063ffffffff168863ffffffff1686611a6f9190613763565b611a79919061378c565b6001600160801b031681526020015f81526020015f81526020015f198152506040518263ffffffff1660e01b8152600401611af191905f60a082019050825182526001600160801b03602084015116602083015260408301516040830152606083015160608301526080830151608083015292915050565b60408051808303815f875af1158015611b0c573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b3091906137b9565b90969095509350505050565b5f5f611b5183306001600160801b0380612287565b9094909350915050565b5f5f5f5f611b71895f015160200151895f611402565b9750611b85895f015160400151885f611402565b9650611b928989896124e6565b8a51602001519199509750611ba79089612625565b885160400151611bb79088612625565b611bc3898989896127c5565b929650909450925090506001600160801b038316851115611bf75760405163bd2a915d60e01b815260040160405180910390fd5b88516020810151604090910151611c1d9190611c13858c613669565b61184d858c613669565b95509550955095915050565b60408051610140810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e0810182905261010081018290526101208101919091525f5f5f5f5f5f5f5f5f5f7f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b03166399fbab888d6040518263ffffffff1660e01b8152600401611cd191815260200190565b61018060405180830381865afa158015611ced573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611d11919061358f565b60408051610140810182526001600160a01b039b8c1681529a90991660208b015262ffffff90971697890197909752600294850b60608901529290930b60808701526001600160801b0390811660a087015260c086019290925260e0850152918216610100840152166101208201529e9d5050505050505050505050505050565b604051630b4c774160e11b81525f906001600160a01b037f0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f9841690631698ee8290611de49087908790879060040161355c565b602060405180830381865afa158015611dff573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e2391906133db565b949350505050565b5f5f5f886001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa158015611e6a573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e8e919061348e565b50505050509150505f896001600160a01b031663f30583996040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ed3573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ef79190613718565b90505f8a6001600160a01b031663461413196040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f36573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f5a9190613718565b60405163f30dba9360e01b815260028c900b60048201529091505f9081906001600160a01b038e169063f30dba939060240161010060405180830381865afa158015611fa8573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611fcc91906137db565b505050509350935050505f5f8e6001600160a01b031663f30dba938e6040518263ffffffff1660e01b815260040161200d919060029190910b815260200190565b61010060405180830381865afa158015612029573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061204d91906137db565b505050509350935050505f5f8f60020b8960020b121561207457505081840381840361209d565b8e60020b8960020b1261208e57505083820383820361209d565b83868903039150828588030390505b6120b78d83038f6001600160801b0316600160801b6128f5565b9a506120d38c82038f6001600160801b0316600160801b6128f5565b9950505050505050505050965096945050505050565b5f5f6120f485610721565b90505f6121068283600160c01b6128f5565b90506113f881866001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015612148573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061216c919061387a565b61217790600a61396e565b866001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156121b3573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906121d7919061387a565b6121e290600a61396e565b6128f5565b60405163133f757160e31b8152600481018290525f9081906001600160a01b037f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe8816906399fbab889060240161018060405180830381865afa15801561224f573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612273919061358f565b909e909d509b505050505050505050505050565b604080516080810182528581526001600160a01b03858116602083019081526001600160801b0386811684860190815286821660608601908152955163fc6f786560e01b815294516004860152915183166024850152905181166044840152925190921660648201525f9182917f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe889091169063fc6f7865906084015b60408051808303815f875af115801561233e573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061236291906137b9565b9097909650945050505050565b5f5f845f0361238257505f90508061246d565b826001600160a01b03165f036123ce57856123bb576123b6600173fffd8963efd1fc6a506488495d951d5263988d2661397c565b6123cb565b6123cb6401000276a3600161399b565b92505b83516001600160a01b031663128acb08308888878261241c5789604001518a602001518b606001516040516020016124089392919061355c565b60405160208183030381529060405261244d565b89602001518a604001518b6060015160405160200161243d9392919061355c565b6040516020818303038152906040525b6040518663ffffffff1660e01b81526004016123239594939291906139ba565b94509492505050565b5f5f60205f8451602086015f885af180612495576040513d5f823e3d81fd5b50505f513d915081156124ac5780600114156124b9565b6001600160a01b0384163b155b156116df57604051635274afe760e01b81526001600160a01b038516600482015260240160405180910390fd5b5f5f5f6124f28661299f565b80519091505f90612518908690600160c01b906121e2906001600160a01b03168061367c565b90505f8061253a612529848a613440565b855160208701516040880151612a0f565b8551919350915061256490829061255a906001600160a01b03168061367c565b600160c01b6128f5565b9050818811156125c3575f61257a600186612ad6565b90505f80612595600161258d878e613669565b8e518661236f565b90925090506125a4828c613669565b9a506125af816136ba565b6125b9908b613440565b9950505050612612565b80871115612612575f6125d65f86612ad6565b90505f806125e88161258d868d613669565b91509150816125f6906136ba565b612600908c613440565b9a5061260c818b613669565b99505050505b878795509550505050505b935093915050565b604051636eb1769f60e11b81523060048201526001600160a01b037f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe888116602483015282919084169063dd62ed3e90604401602060405180830381865afa158015612692573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906126b69190613718565b10156126f1576126f16001600160a01b0383167f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe885f19612b94565b5050565b811561270f5761270f6001600160a01b03851633846114eb565b80156116df576116df6001600160a01b03841633836114eb565b60405163133f757160e31b8152600481018290525f907f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b0316906399fbab889060240161018060405180830381865afa15801561278f573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906127b3919061358f565b50929c9b505050505050505050505050565b5f5f5f5f7f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b031663883164566040518061016001604052808b5f0151602001516001600160a01b031681526020018b5f0151604001516001600160a01b031681526020018b5f01516060015162ffffff1681526020018b6020015160020b81526020018b6040015160020b81526020018a81526020018981526020015f81526020015f8152602001886001600160a01b03168152602001428152506040518263ffffffff1660e01b81526004016128a39190613a1d565b6080604051808303815f875af11580156128bf573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906128e39190613ae1565b929b919a509850909650945050505050565b5f80805f19858709858702925082811083820303915050805f03612929575f841161291e575f5ffd5b5082900490506114e4565b808411612934575f5ffd5b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b604080516060810182525f80825260208201819052918101919091528151516129c790610721565b6001600160a01b0316815260208201516129e090612c23565b6001600160a01b0316602082015260408201516129fc90612c23565b6001600160a01b03166040820152919050565b5f5f836001600160a01b0316856001600160a01b031611612a325785915061246d565b826001600160a01b0316856001600160a01b03161015612ace575f612a776001600160a01b038516612a64878961397c565b6001600160a01b0316600160601b6128f5565b90505f612a916001600160a01b038816612a64898861397c565b90505f612aa383600160601b846128f5565b9050612ab889600160601b6121e28185613440565b9450612ac4858a613669565b935050505061246d565b509492505050565b5f8215612b3b5781604001516001600160a01b0316825f01516001600160a01b031610612b0857506040810151612b8e565b81602001516001600160a01b0316825f01516001600160a01b03161115612b3457506020810151612b8e565b505f612b8e565b81602001516001600160a01b0316825f01516001600160a01b031611612b6657506020810151612b8e565b81604001516001600160a01b0316825f01516001600160a01b03161015612b34575060408101515b92915050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b179052612be58482612f3e565b6116df576040516001600160a01b0384811660248301525f6044830152612c1991869182169063095ea7b390606401611518565b6116df8482612476565b5f5f5f8360020b12612c38578260020b612c3f565b8260020b5f035b9050620d89e8811115612c65576040516315e4079d60e11b815260040160405180910390fd5b5f816001165f03612c7a57600160801b612c8c565b6ffffcb933bd6fad37aa2d162d1a5940015b70ffffffffffffffffffffffffffffffffff1690506002821615612cc0576ffff97272373d413259a46990580e213a0260801c5b6004821615612cdf576ffff2e50f5f656932ef12357cf3c7fdcc0260801c5b6008821615612cfe576fffe5caca7e10e4e61c3624eaa0941cd00260801c5b6010821615612d1d576fffcb9843d60f6159c9db58835c9266440260801c5b6020821615612d3c576fff973b41fa98c081472e6896dfb254c00260801c5b6040821615612d5b576fff2ea16466c96a3843ec78b326b528610260801c5b6080821615612d7a576ffe5dee046a99a2a811c461f1969c30530260801c5b610100821615612d9a576ffcbe86c7900a88aedcffc83b479aa3a40260801c5b610200821615612dba576ff987a7253ac413176f2b074cf7815e540260801c5b610400821615612dda576ff3392b0822b70005940c7a398e4b70f30260801c5b610800821615612dfa576fe7159475a2c29b7443b29c7fa6e889d90260801c5b611000821615612e1a576fd097f3bdfd2022b8845ad8f792aa58250260801c5b612000821615612e3a576fa9f746462d870fdf8a65dc1f90e061e50260801c5b614000821615612e5a576f70d869a156d2a1b890bb3df62baf32f70260801c5b618000821615612e7a576f31be135f97d08fd981231505542fcfa60260801c5b62010000821615612e9b576f09aa508b5b7a84e1c677de54f3e99bc90260801c5b62020000821615612ebb576e5d6af8dedb81196699c329225ee6040260801c5b62040000821615612eda576d2216e584f5fa1ea926041bedfe980260801c5b62080000821615612ef7576b048a170391f7dc42444e8fa20260801c5b5f8460020b1315612f1657805f1981612f1257612f12613693565b0490505b640100000000810615612f2a576001612f2c565b5f5b60ff16602082901c0192505050919050565b5f5f5f5f60205f8651602088015f8a5af192503d91505f5190508280156113f857508115612f6f57806001146113f8565b50505050506001600160a01b03163b151590565b6001600160a01b0381168114612f97575f5ffd5b50565b5f60208284031215612faa575f5ffd5b81356114e481612f83565b63ffffffff81168114612f97575f5ffd5b5f5f5f5f5f60a08688031215612fda575f5ffd5b853594506020860135612fec81612fb5565b93506040860135612ffc81612f83565b9250606086013561300c81612f83565b949793965091946080013592915050565b6001600160801b0381168114612f97575f5ffd5b5f5f5f5f60808587031215613044575f5ffd5b84359350602085013592506040850135915060608501356130648161301d565b939692955090935050565b5f5f5f5f60808587031215613082575f5ffd5b84359350602085013561309481612f83565b93969395505050506040820135916060013590565b8060020b8114612f97575f5ffd5b5f5f5f5f5f60a086880312156130cb575f5ffd5b8535945060208601356130dd81612f83565b935060408601356130ed816130a9565b9250606086013561300c816130a9565b5f5f5f5f5f60a08688031215613111575f5ffd5b85359450602086013561312381612fb5565b9350604086013561313381612f83565b94979396509394606081013594506080013592915050565b5f5f5f5f5f5f5f60e0888a031215613161575f5ffd5b873561316c81612f83565b96506020880135955060408801359450606088013561318a816130a9565b9350608088013561319a816130a9565b925060a08801356131aa81612f83565b96999598509396929591949193505060c09091013590565b5f5f604083850312156131d3575f5ffd5b8235915060208301356131e58161301d565b809150509250929050565b5f5f5f5f60808587031215613203575f5ffd5b84359350602085013561321581612f83565b9250604085013561322581612f83565b9396929550929360600135925050565b5f60208284031215613245575f5ffd5b5035919050565b81516001600160a01b0316815261018081016020830151613274602084018262ffffff169052565b50604083015161328f60408401826001600160a01b03169052565b5060608301516132aa60608401826001600160a01b03169052565b5060808301516132c560808401826001600160801b03169052565b5060a083015160a083015260c083015160c083015260e08301516132f460e08401826001600160801b03169052565b506101008301516133116101008401826001600160801b03169052565b5061012083015161332861012084018260020b9052565b5061014083015161333f61014084018260020b9052565b5061016092830151919092015290565b5f5f5f5f60608587031215613362575f5ffd5b8435935060208501359250604085013567ffffffffffffffff811115613386575f5ffd5b8501601f81018713613396575f5ffd5b803567ffffffffffffffff8111156133ac575f5ffd5b8760208284010111156133bd575f5ffd5b949793965060200194505050565b80516133d681612f83565b919050565b5f602082840312156133eb575f5ffd5b81516114e481612f83565b62ffffff81168114612f97575f5ffd5b80516133d6816133f6565b5f60208284031215613421575f5ffd5b81516114e4816133f6565b634e487b7160e01b5f52601160045260245ffd5b80820180821115612b8e57612b8e61342c565b80516133d6816130a9565b805161ffff811681146133d6575f5ffd5b805160ff811681146133d6575f5ffd5b805180151581146133d6575f5ffd5b5f5f5f5f5f5f5f60e0888a0312156134a4575f5ffd5b87516134af81612f83565b60208901519097506134c0816130a9565b95506134ce6040890161345e565b94506134dc6060890161345e565b93506134ea6080890161345e565b92506134f860a0890161346f565b915061350660c0890161347f565b905092959891949750929550565b5f5f5f60608486031215613526575f5ffd5b833561353181612f83565b9250602084013561354181612f83565b91506040840135613551816133f6565b809150509250925092565b6001600160a01b03938416815291909216602082015262ffffff909116604082015260600190565b80516133d68161301d565b5f5f5f5f5f5f5f5f5f5f5f5f6101808d8f0312156135ab575f5ffd5b8c516bffffffffffffffffffffffff811681146135c6575f5ffd5b9b506135d460208e016133cb565b9a506135e260408e016133cb565b99506135f060608e016133cb565b98506135fe60808e01613406565b975061360c60a08e01613453565b965061361a60c08e01613453565b955061362860e08e01613584565b6101008e01516101208f0151919650945092506136486101408e01613584565b91506136576101608e01613584565b90509295989b509295989b509295989b565b81810381811115612b8e57612b8e61342c565b8082028115828204841417612b8e57612b8e61342c565b634e487b7160e01b5f52601260045260245ffd5b5f826136b5576136b5613693565b500490565b5f600160ff1b82016136ce576136ce61342c565b505f0390565b634e487b7160e01b5f52602160045260245ffd5b828152604081016003831061370b57634e487b7160e01b5f52602160045260245ffd5b8260208301529392505050565b5f60208284031215613728575f5ffd5b5051919050565b5f5f5f60608486031215613741575f5ffd5b835161374c8161301d565b602085015160409095015190969495509392505050565b6001600160801b0381811683821602908116908181146137855761378561342c565b5092915050565b5f6001600160801b038316806137a4576137a4613693565b806001600160801b0384160491505092915050565b5f5f604083850312156137ca575f5ffd5b505080516020909101519092909150565b5f5f5f5f5f5f5f5f610100898b0312156137f3575f5ffd5b88516137fe8161301d565b80985050602089015180600f0b8114613815575f5ffd5b60408a015160608b015160808c01519299509097509550600681900b811461383b575f5ffd5b60a08a015190945061384c81612f83565b60c08a015190935061385d81612fb5565b915061386b60e08a0161347f565b90509295985092959890939650565b5f6020828403121561388a575f5ffd5b6114e48261346f565b6001815b600184111561261d578085048111156138b2576138b261342c565b60018416156138c057908102905b60019390931c928002613897565b5f826138dc57506001612b8e565b816138e857505f612b8e565b81600181146138fe576002811461390857613924565b6001915050612b8e565b60ff8411156139195761391961342c565b50506001821b612b8e565b5060208310610133831016604e8410600b8410161715613947575081810a612b8e565b6139535f198484613893565b805f19048211156139665761396661342c565b029392505050565b5f6114e460ff8416836138ce565b6001600160a01b038281168282160390811115612b8e57612b8e61342c565b6001600160a01b038181168382160190811115612b8e57612b8e61342c565b60018060a01b0386168152841515602082015283604082015260018060a01b038316606082015260a060808201525f82518060a0840152806020850160c085015e5f60c0828501015260c0601f19601f8301168401019150509695505050505050565b81516001600160a01b0316815261016081016020830151613a4960208401826001600160a01b03169052565b506040830151613a60604084018262ffffff169052565b506060830151613a75606084018260020b9052565b506080830151613a8a608084018260020b9052565b5060a083015160a083015260c083015160c083015260e083015160e0830152610100830151610100830152610120830151613ad16101208401826001600160a01b03169052565b5061014092830151919092015290565b5f5f5f5f60808587031215613af4575f5ffd5b84516020860151909450613b078161301d565b604086015160609096015194979096509250505056fea2646970667358221220561681335150e1be31bac6e7e7e7045b4540aff0d5d32c3ea574b05e8bfd0ead64736f6c634300081e0033

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

000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe88000000000000000000000000fd3be1d641adaa64c005dc2d6a2ff5bea96ad744

-----Decoded View---------------
Arg [0] : _positionManager (address): 0xC36442b4a4522E871399CD717aBDD847Ab11FE88
Arg [1] : _protocolFeeCollector (address): 0xfD3BE1d641aDAa64C005dC2D6A2Ff5bEA96AD744

-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe88
Arg [1] : 000000000000000000000000fd3be1d641adaa64c005dc2d6a2ff5bea96ad744


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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