ETH Price: $3,880.94 (+0.67%)

Contract

0xBEA0EBfd3957863A820f5e126eed801CCffF0Bc6
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Cross-Chain Transactions

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
ArrakisV2

Compiler Version
v0.8.13+commit.abaa5c0e

Optimization Enabled:
Yes with 833 runs

Other Settings:
default evmVersion
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.13;

import {
    IUniswapV3MintCallback
} from "@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3MintCallback.sol";
import {
    IUniswapV3Pool
} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
import {
    IUniswapV3Factory,
    ArrakisV2Storage,
    IERC20,
    SafeERC20,
    EnumerableSet,
    Range,
    Rebalance
} from "./abstract/ArrakisV2Storage.sol";
import {FullMath} from "@arrakisfi/v3-lib-0.8/contracts/LiquidityAmounts.sol";
import {Withdraw, UnderlyingPayload} from "./structs/SArrakisV2.sol";
import {Position} from "./libraries/Position.sol";
import {Pool} from "./libraries/Pool.sol";
import {Underlying as UnderlyingHelper} from "./libraries/Underlying.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";

/// @title ArrakisV2 LP vault version 2
/// @notice Smart contract managing liquidity providing strategy for a given token pair
/// using multiple Uniswap V3 LP positions on multiple fee tiers.
/// @author Arrakis Finance
/// @dev DO NOT ADD STATE VARIABLES - APPEND THEM TO ArrakisV2Storage
contract ArrakisV2 is IUniswapV3MintCallback, ArrakisV2Storage {
    using SafeERC20 for IERC20;
    using EnumerableSet for EnumerableSet.AddressSet;

    // solhint-disable-next-line no-empty-blocks
    constructor(IUniswapV3Factory factory_) ArrakisV2Storage(factory_) {}

    /// @notice Uniswap V3 callback fn, called back on pool.mint
    function uniswapV3MintCallback(
        uint256 amount0Owed_,
        uint256 amount1Owed_,
        bytes calldata /*_data*/
    ) external override {
        _uniswapV3CallBack(amount0Owed_, amount1Owed_);
    }

    /// @notice mint Arrakis V2 shares by depositing underlying
    /// @param mintAmount_ represent the amount of Arrakis V2 shares to mint.
    /// @param receiver_ address that will receive Arrakis V2 shares.
    /// @return amount0 amount of token0 needed to mint mintAmount_ of shares.
    /// @return amount1 amount of token1 needed to mint mintAmount_ of shares.
    // solhint-disable-next-line function-max-lines, code-complexity
    function mint(uint256 mintAmount_, address receiver_)
        external
        nonReentrant
        returns (uint256 amount0, uint256 amount1)
    {
        require(mintAmount_ > 0, "MA");
        require(
            restrictedMint == address(0) || msg.sender == restrictedMint,
            "R"
        );
        address me = address(this);
        uint256 ts = totalSupply();
        bool isTotalSupplyGtZero = ts > 0;
        if (isTotalSupplyGtZero) {
            (amount0, amount1) = UnderlyingHelper.totalUnderlyingForMint(
                UnderlyingPayload({
                    ranges: _ranges,
                    factory: factory,
                    token0: address(token0),
                    token1: address(token1),
                    self: me
                }),
                mintAmount_,
                ts
            );
        } else {
            uint256 denominator = 1 ether;
            uint256 init0M = init0;
            uint256 init1M = init1;

            amount0 = FullMath.mulDivRoundingUp(
                mintAmount_,
                init0M,
                denominator
            );
            amount1 = FullMath.mulDivRoundingUp(
                mintAmount_,
                init1M,
                denominator
            );

            /// @dev check ratio against small values that skew init ratio
            if (FullMath.mulDiv(mintAmount_, init0M, denominator) == 0) {
                amount0 = 0;
            }
            if (FullMath.mulDiv(mintAmount_, init1M, denominator) == 0) {
                amount1 = 0;
            }

            uint256 amount0Mint = init0M != 0
                ? FullMath.mulDiv(amount0, denominator, init0M)
                : type(uint256).max;
            uint256 amount1Mint = init1M != 0
                ? FullMath.mulDiv(amount1, denominator, init1M)
                : type(uint256).max;

            require(
                (amount0Mint < amount1Mint ? amount0Mint : amount1Mint) ==
                    mintAmount_,
                "A0&A1"
            );
        }

        _mint(receiver_, mintAmount_);

        // transfer amounts owed to contract
        if (amount0 > 0) {
            token0.safeTransferFrom(msg.sender, me, amount0);
        }
        if (amount1 > 0) {
            token1.safeTransferFrom(msg.sender, me, amount1);
        }

        if (isTotalSupplyGtZero) {
            for (uint256 i; i < _ranges.length; i++) {
                Range memory range = _ranges[i];
                IUniswapV3Pool pool = IUniswapV3Pool(
                    factory.getPool(
                        address(token0),
                        address(token1),
                        range.feeTier
                    )
                );
                uint128 liquidity = Position.getLiquidityByRange(
                    pool,
                    me,
                    range.lowerTick,
                    range.upperTick
                );

                liquidity = SafeCast.toUint128(
                    FullMath.mulDiv(liquidity, mintAmount_, ts)
                );

                if (liquidity == 0) continue;

                pool.mint(me, range.lowerTick, range.upperTick, liquidity, "");
            }
        }

        emit LogMint(receiver_, mintAmount_, amount0, amount1);
    }

    /// @notice burn Arrakis V2 shares and withdraw underlying.
    /// @param burnAmount_ amount of vault shares to burn.
    /// @param receiver_ address to receive underlying tokens withdrawn.
    /// @return amount0 amount of token0 sent to receiver
    /// @return amount1 amount of token1 sent to receiver
    // solhint-disable-next-line function-max-lines, code-complexity
    function burn(uint256 burnAmount_, address receiver_)
        external
        nonReentrant
        returns (uint256 amount0, uint256 amount1)
    {
        require(burnAmount_ > 0, "BA");

        uint256 ts = totalSupply();
        require(ts > 0, "TS");

        _burn(msg.sender, burnAmount_);

        Withdraw memory total;
        for (uint256 i; i < _ranges.length; i++) {
            Range memory range = _ranges[i];
            IUniswapV3Pool pool = IUniswapV3Pool(
                factory.getPool(address(token0), address(token1), range.feeTier)
            );
            uint128 liquidity = Position.getLiquidityByRange(
                pool,
                address(this),
                range.lowerTick,
                range.upperTick
            );

            liquidity = SafeCast.toUint128(
                FullMath.mulDiv(liquidity, burnAmount_, ts)
            );

            if (liquidity == 0) continue;

            Withdraw memory withdraw = _withdraw(
                pool,
                range.lowerTick,
                range.upperTick,
                liquidity
            );

            total.fee0 += withdraw.fee0;
            total.fee1 += withdraw.fee1;

            total.burn0 += withdraw.burn0;
            total.burn1 += withdraw.burn1;
        }

        if (burnAmount_ == ts) delete _ranges;

        _applyFees(total.fee0, total.fee1);

        uint256 leftOver0 = token0.balanceOf(address(this)) -
            managerBalance0 -
            total.burn0;
        uint256 leftOver1 = token1.balanceOf(address(this)) -
            managerBalance1 -
            total.burn1;

        // the proportion of user balance.
        amount0 = FullMath.mulDiv(leftOver0, burnAmount_, ts);
        amount1 = FullMath.mulDiv(leftOver1, burnAmount_, ts);

        amount0 += total.burn0;
        amount1 += total.burn1;

        if (amount0 > 0) {
            token0.safeTransfer(receiver_, amount0);
        }

        if (amount1 > 0) {
            token1.safeTransfer(receiver_, amount1);
        }

        // For monitoring how much user burn LP token for getting their token back.
        emit LPBurned(msg.sender, total.burn0, total.burn1);
        emit LogCollectedFees(total.fee0, total.fee1);
        emit LogBurn(receiver_, burnAmount_, amount0, amount1);
    }

    /// @notice rebalance ArrakisV2 vault's UniswapV3 positions
    /// @param rebalanceParams_ rebalance params, containing ranges where
    /// we need to collect tokens and ranges where we need to mint liquidity.
    /// Also contain swap payload to changes token0/token1 proportion.
    /// @dev only Manager contract can call this function.
    // solhint-disable-next-line function-max-lines, code-complexity
    function rebalance(Rebalance calldata rebalanceParams_)
        external
        onlyManager
        nonReentrant
    {
        // Burns.
        IUniswapV3Factory mFactory = factory;
        IERC20 mToken0 = token0;
        IERC20 mToken1 = token1;

        {
            Withdraw memory aggregator;
            for (uint256 i; i < rebalanceParams_.burns.length; i++) {
                IUniswapV3Pool pool = IUniswapV3Pool(
                    mFactory.getPool(
                        address(mToken0),
                        address(mToken1),
                        rebalanceParams_.burns[i].range.feeTier
                    )
                );

                uint128 liquidity = Position.getLiquidityByRange(
                    pool,
                    address(this),
                    rebalanceParams_.burns[i].range.lowerTick,
                    rebalanceParams_.burns[i].range.upperTick
                );

                if (liquidity == 0) continue;

                uint128 liquidityToWithdraw;

                if (rebalanceParams_.burns[i].liquidity == type(uint128).max)
                    liquidityToWithdraw = liquidity;
                else liquidityToWithdraw = rebalanceParams_.burns[i].liquidity;

                Withdraw memory withdraw = _withdraw(
                    pool,
                    rebalanceParams_.burns[i].range.lowerTick,
                    rebalanceParams_.burns[i].range.upperTick,
                    liquidityToWithdraw
                );

                if (liquidityToWithdraw == liquidity) {
                    (bool exists, uint256 index) = Position.rangeExists(
                        _ranges,
                        rebalanceParams_.burns[i].range
                    );
                    require(exists, "RRNE");

                    _ranges[index] = _ranges[_ranges.length - 1];
                    _ranges.pop();
                }

                aggregator.burn0 += withdraw.burn0;
                aggregator.burn1 += withdraw.burn1;

                aggregator.fee0 += withdraw.fee0;
                aggregator.fee1 += withdraw.fee1;
            }

            require(aggregator.burn0 >= rebalanceParams_.minBurn0, "B0");
            require(aggregator.burn1 >= rebalanceParams_.minBurn1, "B1");

            if (aggregator.fee0 > 0 || aggregator.fee1 > 0) {
                _applyFees(aggregator.fee0, aggregator.fee1);

                emit LogCollectedFees(aggregator.fee0, aggregator.fee1);
            }
        }

        // Swap.
        if (rebalanceParams_.swap.amountIn > 0) {
            require(_routers.contains(rebalanceParams_.swap.router), "NR");

            uint256 balance0Before = mToken0.balanceOf(address(this));
            uint256 balance1Before = mToken1.balanceOf(address(this));

            mToken0.safeApprove(address(rebalanceParams_.swap.router), 0);
            mToken1.safeApprove(address(rebalanceParams_.swap.router), 0);

            mToken0.safeApprove(
                address(rebalanceParams_.swap.router),
                balance0Before
            );
            mToken1.safeApprove(
                address(rebalanceParams_.swap.router),
                balance1Before
            );

            (bool success, ) = rebalanceParams_.swap.router.call(
                rebalanceParams_.swap.payload
            );
            require(success, "SC");

            uint256 balance0After = mToken0.balanceOf(address(this));
            uint256 balance1After = mToken1.balanceOf(address(this));
            if (rebalanceParams_.swap.zeroForOne) {
                require(
                    (balance1After >=
                        balance1Before +
                            rebalanceParams_.swap.expectedMinReturn) &&
                        (balance0After >=
                            balance0Before - rebalanceParams_.swap.amountIn),
                    "SF"
                );
                balance0After = balance0Before - balance0After;
                balance1After = balance1After - balance1Before;
            } else {
                require(
                    (balance0After >=
                        balance0Before +
                            rebalanceParams_.swap.expectedMinReturn) &&
                        (balance1After >=
                            balance1Before - rebalanceParams_.swap.amountIn),
                    "SF"
                );
                balance0After = balance0After - balance0Before;
                balance1After = balance1Before - balance1After;
            }
            emit LogRebalance(rebalanceParams_, balance0After, balance1After);
        } else {
            emit LogRebalance(rebalanceParams_, 0, 0);
        }

        // Mints.
        uint256 aggregator0;
        uint256 aggregator1;
        for (uint256 i; i < rebalanceParams_.mints.length; i++) {
            (bool exists, ) = Position.rangeExists(
                _ranges,
                rebalanceParams_.mints[i].range
            );
            address pool = factory.getPool(
                address(token0),
                address(token1),
                rebalanceParams_.mints[i].range.feeTier
            );
            if (!exists) {
                // check that the pool exists on Uniswap V3.

                require(pool != address(0), "NUP");
                require(_pools.contains(pool), "P");
                require(
                    Pool.validateTickSpacing(
                        pool,
                        rebalanceParams_.mints[i].range
                    ),
                    "RTS"
                );

                _ranges.push(rebalanceParams_.mints[i].range);
            }

            (uint256 amt0, uint256 amt1) = IUniswapV3Pool(pool).mint(
                address(this),
                rebalanceParams_.mints[i].range.lowerTick,
                rebalanceParams_.mints[i].range.upperTick,
                rebalanceParams_.mints[i].liquidity,
                ""
            );
            aggregator0 += amt0;
            aggregator1 += amt1;
        }
        require(aggregator0 >= rebalanceParams_.minDeposit0, "D0");
        require(aggregator1 >= rebalanceParams_.minDeposit1, "D1");

        require(token0.balanceOf(address(this)) >= managerBalance0, "MB0");
        require(token1.balanceOf(address(this)) >= managerBalance1, "MB1");
    }

    /// @notice will send manager fees to manager
    /// @dev anyone can call this function
    function withdrawManagerBalance() external nonReentrant {
        _withdrawManagerBalance();
    }

    function _withdraw(
        IUniswapV3Pool pool_,
        int24 lowerTick_,
        int24 upperTick_,
        uint128 liquidity_
    ) internal returns (Withdraw memory withdraw) {
        (withdraw.burn0, withdraw.burn1) = pool_.burn(
            lowerTick_,
            upperTick_,
            liquidity_
        );

        (uint256 collect0, uint256 collect1) = _collectFees(
            pool_,
            lowerTick_,
            upperTick_
        );

        withdraw.fee0 = collect0 - withdraw.burn0;
        withdraw.fee1 = collect1 - withdraw.burn1;
    }
}

File 2 of 38 : FixedPoint96.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.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;
}

// 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.
            // EDIT for 0.8 compatibility:
            // see: https://ethereum.stackexchange.com/questions/96642/unary-operator-cannot-be-applied-to-type-uint256
            uint256 twos = denominator & (~denominator + 1);

            // Divide denominator by power of two
            assembly {
                denominator := div(denominator, twos)
            }

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

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

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

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

// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.0;
import {FullMath} from "./FullMath.sol";
import {FixedPoint96} from "@uniswap/v3-core/contracts/libraries/FixedPoint96.sol";

/// @title Liquidity amount functions
/// @notice Provides functions for computing liquidity amounts from token amounts and prices
library LiquidityAmounts {
    function toUint128(uint256 x) private pure returns (uint128 y) {
        require((y = uint128(x)) == x);
    }

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

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

    /// @notice Computes the maximum amount of liquidity received for a given amount of token0, token1, the current
    /// pool prices and the prices at the tick boundaries
    function getLiquidityForAmounts(
        uint160 sqrtRatioX96,
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint256 amount0,
        uint256 amount1
    ) internal pure returns (uint128 liquidity) {
        if (sqrtRatioAX96 > sqrtRatioBX96)
            (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

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

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

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

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

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

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

    /// @notice Computes the token0 and token1 value for a given amount of liquidity, the current
    /// pool prices and the prices at the tick boundaries
    function getAmountsForLiquidity(
        uint160 sqrtRatioX96,
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint128 liquidity
    ) internal pure returns (uint256 amount0, uint256 amount1) {
        if (sqrtRatioAX96 > sqrtRatioBX96)
            (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

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

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

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

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

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

// SPDX-License-Identifier: BUSL-1.1
pragma solidity >=0.8.0;

import './SafeCast.sol';

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

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

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

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

        require(sqrtRatioAX96 > 0);

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

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

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

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

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

// 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 {
    /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128
    int24 internal constant MIN_TICK = -887272;
    /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128
    int24 internal constant MAX_TICK = -MIN_TICK;

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

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

        // EDIT: 0.8 compatibility
        require(absTick <= uint256(int256(MAX_TICK)), "T");

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

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

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

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

        uint256 r = ratio;
        uint256 msb = 0;

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

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

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

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

        int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    function __Ownable_init() internal onlyInitializing {
        __Ownable_init_unchained();
    }

    function __Ownable_init_unchained() internal onlyInitializing {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

import "../../utils/AddressUpgradeable.sol";

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint8 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.
     */
    modifier initializer() {
        bool isTopLevelCall = _setInitializedVersion(1);
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original
     * initialization step. This is essential to configure modules that are added through upgrades and that require
     * initialization.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     */
    modifier reinitializer(uint8 version) {
        bool isTopLevelCall = _setInitializedVersion(version);
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(version);
        }
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     */
    function _disableInitializers() internal virtual {
        _setInitializedVersion(type(uint8).max);
    }

    function _setInitializedVersion(uint8 version) private returns (bool) {
        // If the contract is initializing we ignore whether _initialized is set in order to support multiple
        // inheritance patterns, but we only do this in the context of a constructor, and for the lowest level
        // of initializers, because in other contexts the contract may have been reentered.
        if (_initializing) {
            require(
                version == 1 && !AddressUpgradeable.isContract(address(this)),
                "Initializable: contract is already initialized"
            );
            return false;
        } else {
            require(_initialized < version, "Initializable: contract is already initialized");
            _initialized = version;
            return true;
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

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

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

    uint256 private _status;

    function __ReentrancyGuard_init() internal onlyInitializing {
        __ReentrancyGuard_init_unchained();
    }

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        _status = _NOT_ENTERED;
    }

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

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

        _;

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

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

import "./IERC20Upgradeable.sol";
import "./extensions/IERC20MetadataUpgradeable.sol";
import "../../utils/ContextUpgradeable.sol";
import "../../proxy/utils/Initializable.sol";

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

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

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

    function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {
        _name = name_;
        _symbol = symbol_;
    }

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

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

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

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

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

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

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

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual override returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, amount);
        _transfer(from, to, amount);
        return true;
    }

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

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

        return true;
    }

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

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
        }
        _balances[to] += amount;

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

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

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

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

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

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

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

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

        _afterTokenTransfer(account, address(0), amount);
    }

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

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

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.
     *
     * Does not update the allowance amount in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Might emit an {Approval} event.
     */
    function _spendAllowance(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "ERC20: insufficient allowance");
            unchecked {
                _approve(owner, spender, currentAllowance - amount);
            }
        }
    }

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

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

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[45] private __gap;
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20Upgradeable.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20MetadataUpgradeable is IERC20Upgradeable {
    /**
     * @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: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20Upgradeable {
    /**
     * @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 amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

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

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

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

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

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

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

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

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

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

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

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

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

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

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

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}

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

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
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 amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/math/SafeCast.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
        return int256(value);
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (utils/structs/EnumerableSet.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

            if (lastIndex != toDeleteIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastValue;
                // Update the index for the moved value
                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
            }

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

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

            return true;
        } else {
            return false;
        }
    }

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

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

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

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

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

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

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

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

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

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        return _values(set._inner);
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

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

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

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

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

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

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

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

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

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

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

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

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        assembly {
            result := store
        }

        return result;
    }
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

}

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

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

File 27 of 38 : 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: 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 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);
}

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

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

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

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

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

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

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

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

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

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

File 31 of 38 : 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;
}

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.13;

import {
    IUniswapV3Factory
} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol";
import {
    IUniswapV3Pool
} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
import {
    IERC20,
    SafeERC20
} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {
    OwnableUpgradeable
} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {
    ERC20Upgradeable
} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import {
    ReentrancyGuardUpgradeable
} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import {
    EnumerableSet
} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {Range, Rebalance, InitializePayload} from "../structs/SArrakisV2.sol";
import {hundredPercent} from "../constants/CArrakisV2.sol";

/// @title ArrakisV2Storage base contract containing all ArrakisV2 storage variables.
// solhint-disable-next-line max-states-count
abstract contract ArrakisV2Storage is
    OwnableUpgradeable,
    ERC20Upgradeable,
    ReentrancyGuardUpgradeable
{
    using SafeERC20 for IERC20;
    using EnumerableSet for EnumerableSet.AddressSet;

    IUniswapV3Factory public immutable factory;

    IERC20 public token0;
    IERC20 public token1;

    uint256 public init0;
    uint256 public init1;

    // #region manager data

    uint16 public managerFeeBPS;
    uint256 public managerBalance0;
    uint256 public managerBalance1;
    address public manager;
    address public restrictedMint;

    // #endregion manager data

    Range[] internal _ranges;

    EnumerableSet.AddressSet internal _pools;
    EnumerableSet.AddressSet internal _routers;

    // #region events

    event LogMint(
        address indexed receiver,
        uint256 mintAmount,
        uint256 amount0In,
        uint256 amount1In
    );

    event LogBurn(
        address indexed receiver,
        uint256 burnAmount,
        uint256 amount0Out,
        uint256 amount1Out
    );

    event LPBurned(
        address indexed user,
        uint256 burnAmount0,
        uint256 burnAmount1
    );

    event LogRebalance(
        Rebalance rebalanceParams,
        uint256 swapDelta0,
        uint256 swapDelta1
    );

    event LogCollectedFees(uint256 fee0, uint256 fee1);

    event LogWithdrawManagerBalance(uint256 amount0, uint256 amount1);
    // #region Setting events

    event LogSetInits(uint256 init0, uint256 init1);
    event LogAddPools(uint24[] feeTiers);
    event LogRemovePools(address[] pools);
    event LogSetManager(address newManager);
    event LogSetManagerFeeBPS(uint16 managerFeeBPS);
    event LogRestrictedMint(address minter);
    event LogWhitelistRouters(address[] routers);
    event LogBlacklistRouters(address[] routers);
    // #endregion Setting events

    // #endregion events

    // #region modifiers

    modifier onlyManager() {
        require(manager == msg.sender, "NM");
        _;
    }

    // #endregion modifiers

    constructor(IUniswapV3Factory factory_) {
        require(address(factory_) != address(0), "ZF");
        factory = factory_;
    }

    // solhint-disable-next-line function-max-lines
    function initialize(
        string calldata name_,
        string calldata symbol_,
        InitializePayload calldata params_
    ) external initializer {
        require(params_.feeTiers.length > 0, "NFT");
        require(params_.token0 != address(0), "T0");
        require(params_.token0 < params_.token1, "WTO");
        require(params_.owner != address(0), "OAZ");
        require(params_.manager != address(0), "MAZ");
        require(params_.init0 > 0 || params_.init1 > 0, "I");

        __ERC20_init(name_, symbol_);
        __ReentrancyGuard_init();

        _addPools(params_.feeTiers, params_.token0, params_.token1);

        token0 = IERC20(params_.token0);
        token1 = IERC20(params_.token1);

        _whitelistRouters(params_.routers);

        _transferOwnership(params_.owner);

        manager = params_.manager;

        init0 = params_.init0;
        init1 = params_.init1;

        emit LogAddPools(params_.feeTiers);
        emit LogSetInits(params_.init0, params_.init1);
        emit LogSetManager(params_.manager);
    }

    // #region setter functions

    /// @notice set initial virtual allocation of token0 and token1
    /// @param init0_ initial virtual allocation of token 0.
    /// @param init1_ initial virtual allocation of token 1.
    /// @dev only callable by restrictedMint or by owner if restrictedMint is unset.
    function setInits(uint256 init0_, uint256 init1_) external {
        require(init0_ > 0 || init1_ > 0, "I");
        require(totalSupply() == 0, "TS");
        address requiredCaller = restrictedMint == address(0)
            ? owner()
            : restrictedMint;
        require(msg.sender == requiredCaller, "R");
        emit LogSetInits(init0 = init0_, init1 = init1_);
    }

    /// @notice whitelist pools
    /// @param feeTiers_ list of fee tiers associated to pools to whitelist.
    /// @dev only callable by owner.
    function addPools(uint24[] calldata feeTiers_) external onlyOwner {
        _addPools(feeTiers_, address(token0), address(token1));
        emit LogAddPools(feeTiers_);
    }

    /// @notice unwhitelist pools
    /// @param pools_ list of pools to remove from whitelist.
    /// @dev only callable by owner.
    function removePools(address[] calldata pools_) external onlyOwner {
        for (uint256 i = 0; i < pools_.length; i++) {
            require(_pools.contains(pools_[i]), "NP");

            _pools.remove(pools_[i]);
        }
        emit LogRemovePools(pools_);
    }

    /// @notice whitelist routers
    /// @param routers_ list of router addresses to whitelist.
    /// @dev only callable by owner.
    function whitelistRouters(address[] calldata routers_) external onlyOwner {
        _whitelistRouters(routers_);
    }

    /// @notice blacklist routers
    /// @param routers_ list of routers addresses to blacklist.
    /// @dev only callable by owner.
    function blacklistRouters(address[] calldata routers_) external onlyOwner {
        for (uint256 i = 0; i < routers_.length; i++) {
            require(_routers.contains(routers_[i]), "RW");

            _routers.remove(routers_[i]);
        }
        emit LogBlacklistRouters(routers_);
    }

    /// @notice set manager
    /// @param manager_ manager address.
    /// @dev only callable by owner.
    function setManager(address manager_) external onlyOwner nonReentrant {
        _collectFeesOnPools();
        _withdrawManagerBalance();
        manager = manager_;
        emit LogSetManager(manager_);
    }

    /// @notice set manager fee bps
    /// @param managerFeeBPS_ manager fee in basis points.
    /// @dev only callable by manager.
    function setManagerFeeBPS(uint16 managerFeeBPS_)
        external
        onlyManager
        nonReentrant
    {
        require(managerFeeBPS_ <= 10000, "MFO");
        _collectFeesOnPools();
        managerFeeBPS = managerFeeBPS_;
        emit LogSetManagerFeeBPS(managerFeeBPS_);
    }

    /// @notice set restricted minter
    /// @param minter_ address of restricted minter.
    /// @dev only callable by owner.
    function setRestrictedMint(address minter_) external onlyOwner {
        restrictedMint = minter_;
        emit LogRestrictedMint(minter_);
    }

    // #endregion setter functions

    // #region getter functions

    /// @notice get full list of ranges, guaranteed to contain all active vault LP Positions.
    /// @return ranges list of ranges
    function getRanges() external view returns (Range[] memory) {
        return _ranges;
    }

    function getPools() external view returns (address[] memory) {
        uint256 len = _pools.length();
        address[] memory output = new address[](len);
        for (uint256 i; i < len; i++) {
            output[i] = _pools.at(i);
        }

        return output;
    }

    function getRouters() external view returns (address[] memory) {
        uint256 len = _routers.length();
        address[] memory output = new address[](len);
        for (uint256 i; i < len; i++) {
            output[i] = _routers.at(i);
        }

        return output;
    }

    // #endregion getter functions

    // #region internal functions

    function _uniswapV3CallBack(uint256 amount0_, uint256 amount1_) internal {
        require(_pools.contains(msg.sender), "CC");

        if (amount0_ > 0) token0.safeTransfer(msg.sender, amount0_);
        if (amount1_ > 0) token1.safeTransfer(msg.sender, amount1_);
    }

    function _withdrawManagerBalance() internal {
        uint256 amount0 = managerBalance0;
        uint256 amount1 = managerBalance1;

        managerBalance0 = 0;
        managerBalance1 = 0;

        /// @dev token can blacklist manager and make this function fail,
        /// so we use try catch to deal with blacklisting.

        if (amount0 > 0) {
            // solhint-disable-next-line no-empty-blocks
            try token0.transfer(manager, amount0) {} catch {
                amount0 = 0;
            }
        }

        if (amount1 > 0) {
            // solhint-disable-next-line no-empty-blocks
            try token1.transfer(manager, amount1) {} catch {
                amount1 = 0;
            }
        }

        emit LogWithdrawManagerBalance(amount0, amount1);
    }

    function _addPools(
        uint24[] calldata feeTiers_,
        address token0Addr_,
        address token1Addr_
    ) internal {
        for (uint256 i = 0; i < feeTiers_.length; i++) {
            address pool = factory.getPool(
                token0Addr_,
                token1Addr_,
                feeTiers_[i]
            );

            require(pool != address(0), "ZA");
            require(!_pools.contains(pool), "P");

            // explicit.
            _pools.add(pool);
        }
    }

    function _collectFeesOnPools() internal {
        uint256 fees0;
        uint256 fees1;
        for (uint256 i; i < _ranges.length; i++) {
            Range memory range = _ranges[i];
            IUniswapV3Pool pool = IUniswapV3Pool(
                factory.getPool(address(token0), address(token1), range.feeTier)
            );

            /// @dev to update the position and collect fees.
            pool.burn(range.lowerTick, range.upperTick, 0);

            (uint256 collect0, uint256 collect1) = _collectFees(
                pool,
                range.lowerTick,
                range.upperTick
            );

            fees0 += collect0;
            fees1 += collect1;
        }

        _applyFees(fees0, fees1);
        emit LogCollectedFees(fees0, fees1);
    }

    function _collectFees(
        IUniswapV3Pool pool_,
        int24 lowerTick_,
        int24 upperTick_
    ) internal returns (uint256 collect0, uint256 collect1) {
        (collect0, collect1) = pool_.collect(
            address(this),
            lowerTick_,
            upperTick_,
            type(uint128).max,
            type(uint128).max
        );
    }

    function _whitelistRouters(address[] calldata routers_) internal {
        for (uint256 i = 0; i < routers_.length; i++) {
            require(
                routers_[i] != address(token0) &&
                    routers_[i] != address(token1),
                "RT"
            );
            require(!_routers.contains(routers_[i]), "CR");
            // explicit.
            _routers.add(routers_[i]);
        }

        emit LogWhitelistRouters(routers_);
    }

    function _applyFees(uint256 fee0_, uint256 fee1_) internal {
        uint16 mManagerFeeBPS = managerFeeBPS;
        managerBalance0 += (fee0_ * mManagerFeeBPS) / hundredPercent;
        managerBalance1 += (fee1_ * mManagerFeeBPS) / hundredPercent;
    }

    // #endregion internal functions
}

File 33 of 38 : CArrakisV2.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;

uint16 constant hundredPercent = 10_000;

// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;

import {
    IUniswapV3Factory
} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {InitializePayload} from "../structs/SArrakisV2.sol";
import {Range, Rebalance} from "../structs/SArrakisV2.sol";

interface IArrakisV2 is IERC20 {
    // #region events

    event LogMint(
        address indexed receiver,
        uint256 mintAmount,
        uint256 amount0In,
        uint256 amount1In
    );

    event LogBurn(
        address indexed receiver,
        uint256 burnAmount,
        uint256 amount0Out,
        uint256 amount1Out
    );

    event LPBurned(
        address indexed user,
        uint256 burnAmount0,
        uint256 burnAmount1
    );

    event LogRebalance(
        Rebalance rebalanceParams,
        uint256 swapDelta0,
        uint256 swapDelta1
    );

    event LogCollectedFees(uint256 fee0, uint256 fee1);

    event LogWithdrawManagerBalance(uint256 amount0, uint256 amount1);
    // #region Setting events

    event LogSetInits(uint256 init0, uint256 init1);
    event LogAddPools(uint24[] feeTiers);
    event LogRemovePools(address[] pools);
    event LogSetManager(address newManager);
    event LogSetManagerFeeBPS(uint16 managerFeeBPS);
    event LogRestrictedMint(address minter);
    event LogWhitelistRouters(address[] routers);
    event LogBlacklistRouters(address[] routers);

    // #endregion Setting events

    // #endregion events

    function initialize(
        string calldata name_,
        string calldata symbol_,
        InitializePayload calldata params_
    ) external;

    // #region state modifiying functions.

    function mint(uint256 mintAmount_, address receiver_)
        external
        returns (uint256 amount0, uint256 amount1);

    function burn(uint256 burnAmount_, address receiver_)
        external
        returns (uint256 amount0, uint256 amount1);

    function rebalance(Rebalance calldata rebalanceParams_) external;

    function withdrawManagerBalance() external;

    function setInits(uint256 init0_, uint256 init1_) external;

    function addPools(uint24[] calldata feeTiers_) external;

    function removePools(address[] calldata pools_) external;

    function whitelistRouters(address[] calldata routers_) external;

    function blacklistRouters(address[] calldata routers_) external;

    function setManager(address manager_) external;

    function setRestrictedMint(address minter_) external;

    function setManagerFeeBPS(uint16 managerFeeBPS_) external;

    function transferOwnership(address newOwner) external;

    function renounceOwnership() external;

    // #endregion state modifiying functions.

    function factory() external view returns (IUniswapV3Factory);

    function token0() external view returns (IERC20);

    function token1() external view returns (IERC20);

    function init0() external view returns (uint256);

    function init1() external view returns (uint256);

    function manager() external view returns (address);

    function managerFeeBPS() external view returns (uint16);

    function restrictedMint() external view returns (address);

    function managerBalance0() external view returns (uint256);

    function managerBalance1() external view returns (uint256);

    function getRanges() external view returns (Range[] memory);

    function getPools() external view returns (address[] memory);

    function getRouters() external view returns (address[] memory);

    function owner() external view returns (address);

    function name() external view returns (string memory);

    function symbol() external view returns (string memory);

    function decimals() external view returns (uint8);
}

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

import {
    IUniswapV3Pool
} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
import {
    IUniswapV3Pool
} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
import {Range} from "../structs/SArrakisV2.sol";

library Pool {
    function validateTickSpacing(address pool_, Range memory range_)
        public
        view
        returns (bool)
    {
        int24 spacing = IUniswapV3Pool(pool_).tickSpacing();
        return
            range_.lowerTick < range_.upperTick &&
            range_.lowerTick % spacing == 0 &&
            range_.upperTick % spacing == 0;
    }
}

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

import {
    IUniswapV3Pool
} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
import {Range} from "../structs/SArrakisV2.sol";

library Position {
    function getLiquidityByRange(
        IUniswapV3Pool pool_,
        address self_,
        int24 lowerTick_,
        int24 upperTick_
    ) public view returns (uint128 liquidity) {
        (liquidity, , , , ) = pool_.positions(
            getPositionId(self_, lowerTick_, upperTick_)
        );
    }

    function getPositionId(
        address self_,
        int24 lowerTick_,
        int24 upperTick_
    ) public pure returns (bytes32 positionId) {
        return keccak256(abi.encodePacked(self_, lowerTick_, upperTick_));
    }

    function rangeExists(Range[] memory currentRanges_, Range memory range_)
        public
        pure
        returns (bool ok, uint256 index)
    {
        for (uint256 i; i < currentRanges_.length; i++) {
            ok =
                range_.lowerTick == currentRanges_[i].lowerTick &&
                range_.upperTick == currentRanges_[i].upperTick &&
                range_.feeTier == currentRanges_[i].feeTier;
            if (ok) {
                index = i;
                break;
            }
        }
    }
}

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.13;

import {
    IUniswapV3Pool
} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
import {IArrakisV2} from "../interfaces/IArrakisV2.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {
    FullMath,
    LiquidityAmounts
} from "@arrakisfi/v3-lib-0.8/contracts/LiquidityAmounts.sol";
import {SqrtPriceMath} from "@arrakisfi/v3-lib-0.8/contracts/SqrtPriceMath.sol";
import {TickMath} from "@arrakisfi/v3-lib-0.8/contracts/TickMath.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import {
    UnderlyingPayload,
    RangeData,
    PositionUnderlying,
    ComputeFeesPayload,
    GetFeesPayload
} from "../structs/SArrakisV2.sol";
import {Position} from "./Position.sol";

library Underlying {
    // solhint-disable-next-line function-max-lines
    function totalUnderlyingForMint(
        UnderlyingPayload memory underlyingPayload_,
        uint256 mintAmount_,
        uint256 totalSupply_
    ) public view returns (uint256 amount0, uint256 amount1) {
        uint256 fee0;
        uint256 fee1;
        for (uint256 i; i < underlyingPayload_.ranges.length; i++) {
            {
                IUniswapV3Pool pool = IUniswapV3Pool(
                    underlyingPayload_.factory.getPool(
                        underlyingPayload_.token0,
                        underlyingPayload_.token1,
                        underlyingPayload_.ranges[i].feeTier
                    )
                );
                (
                    uint256 a0,
                    uint256 a1,
                    uint256 f0,
                    uint256 f1
                ) = underlyingMint(
                        RangeData({
                            self: underlyingPayload_.self,
                            range: underlyingPayload_.ranges[i],
                            pool: pool
                        }),
                        mintAmount_,
                        totalSupply_
                    );
                amount0 += a0;
                amount1 += a1;
                fee0 += f0;
                fee1 += f1;
            }
        }

        IArrakisV2 arrakisV2 = IArrakisV2(underlyingPayload_.self);

        (uint256 fee0After, uint256 fee1After) = subtractAdminFees(
            fee0,
            fee1,
            arrakisV2.managerFeeBPS()
        );

        amount0 += FullMath.mulDivRoundingUp(
            mintAmount_,
            fee0After +
                IERC20(underlyingPayload_.token0).balanceOf(
                    underlyingPayload_.self
                ) -
                arrakisV2.managerBalance0(),
            totalSupply_
        );
        amount1 += FullMath.mulDivRoundingUp(
            mintAmount_,
            fee1After +
                IERC20(underlyingPayload_.token1).balanceOf(
                    underlyingPayload_.self
                ) -
                arrakisV2.managerBalance1(),
            totalSupply_
        );
    }

    // solhint-disable-next-line function-max-lines
    function totalUnderlyingWithFees(
        UnderlyingPayload memory underlyingPayload_
    )
        public
        view
        returns (
            uint256 amount0,
            uint256 amount1,
            uint256 fee0,
            uint256 fee1
        )
    {
        return _totalUnderlyingWithFees(underlyingPayload_, 0);
    }

    function totalUnderlyingAtPriceWithFees(
        UnderlyingPayload memory underlyingPayload_,
        uint160 sqrtPriceX96_
    )
        public
        view
        returns (
            uint256 amount0,
            uint256 amount1,
            uint256 fee0,
            uint256 fee1
        )
    {
        return _totalUnderlyingWithFees(underlyingPayload_, sqrtPriceX96_);
    }

    function underlying(RangeData memory underlying_, uint160 sqrtPriceX96_)
        public
        view
        returns (
            uint256 amount0,
            uint256 amount1,
            uint256 fee0,
            uint256 fee1
        )
    {
        (uint160 sqrtPriceX96, int24 tick, , , , , ) = underlying_.pool.slot0();
        bytes32 positionId = Position.getPositionId(
            underlying_.self,
            underlying_.range.lowerTick,
            underlying_.range.upperTick
        );
        PositionUnderlying memory positionUnderlying = PositionUnderlying({
            positionId: positionId,
            sqrtPriceX96: sqrtPriceX96_ > 0 ? sqrtPriceX96_ : sqrtPriceX96,
            tick: tick,
            lowerTick: underlying_.range.lowerTick,
            upperTick: underlying_.range.upperTick,
            pool: underlying_.pool
        });
        (amount0, amount1, fee0, fee1) = getUnderlyingBalances(
            positionUnderlying
        );
    }

    function underlyingMint(
        RangeData memory underlying_,
        uint256 mintAmount_,
        uint256 totalSupply_
    )
        public
        view
        returns (
            uint256 amount0,
            uint256 amount1,
            uint256 fee0,
            uint256 fee1
        )
    {
        (uint160 sqrtPriceX96, int24 tick, , , , , ) = underlying_.pool.slot0();
        bytes32 positionId = Position.getPositionId(
            underlying_.self,
            underlying_.range.lowerTick,
            underlying_.range.upperTick
        );
        PositionUnderlying memory positionUnderlying = PositionUnderlying({
            positionId: positionId,
            sqrtPriceX96: sqrtPriceX96,
            tick: tick,
            lowerTick: underlying_.range.lowerTick,
            upperTick: underlying_.range.upperTick,
            pool: underlying_.pool
        });
        (amount0, amount1, fee0, fee1) = getUnderlyingBalancesMint(
            positionUnderlying,
            mintAmount_,
            totalSupply_
        );
    }

    // solhint-disable-next-line function-max-lines
    function getUnderlyingBalancesMint(
        PositionUnderlying memory positionUnderlying_,
        uint256 mintAmount_,
        uint256 totalSupply_
    )
        public
        view
        returns (
            uint256 amount0Current,
            uint256 amount1Current,
            uint256 fee0,
            uint256 fee1
        )
    {
        uint128 liquidity;
        {
            uint256 feeGrowthInside0Last;
            uint256 feeGrowthInside1Last;
            uint128 tokensOwed0;
            uint128 tokensOwed1;
            (
                liquidity,
                feeGrowthInside0Last,
                feeGrowthInside1Last,
                tokensOwed0,
                tokensOwed1
            ) = positionUnderlying_.pool.positions(
                positionUnderlying_.positionId
            );

            // compute current fees earned
            (fee0, fee1) = _getFeesEarned(
                GetFeesPayload({
                    feeGrowthInside0Last: feeGrowthInside0Last,
                    feeGrowthInside1Last: feeGrowthInside1Last,
                    pool: positionUnderlying_.pool,
                    liquidity: liquidity,
                    tick: positionUnderlying_.tick,
                    lowerTick: positionUnderlying_.lowerTick,
                    upperTick: positionUnderlying_.upperTick
                })
            );

            fee0 += uint256(tokensOwed0);
            fee1 += uint256(tokensOwed1);
        }

        // compute current holdings from liquidity
        (amount0Current, amount1Current) = getAmountsForDelta(
            positionUnderlying_.sqrtPriceX96,
            TickMath.getSqrtRatioAtTick(positionUnderlying_.lowerTick),
            TickMath.getSqrtRatioAtTick(positionUnderlying_.upperTick),
            SafeCast.toInt128(
                SafeCast.toInt256(
                    FullMath.mulDiv(
                        uint256(liquidity),
                        mintAmount_,
                        totalSupply_
                    )
                )
            )
        );
    }

    // solhint-disable-next-line function-max-lines
    function getUnderlyingBalances(
        PositionUnderlying memory positionUnderlying_
    )
        public
        view
        returns (
            uint256 amount0Current,
            uint256 amount1Current,
            uint256 fee0,
            uint256 fee1
        )
    {
        (
            uint128 liquidity,
            uint256 feeGrowthInside0Last,
            uint256 feeGrowthInside1Last,
            uint128 tokensOwed0,
            uint128 tokensOwed1
        ) = positionUnderlying_.pool.positions(positionUnderlying_.positionId);

        // compute current fees earned
        (fee0, fee1) = _getFeesEarned(
            GetFeesPayload({
                feeGrowthInside0Last: feeGrowthInside0Last,
                feeGrowthInside1Last: feeGrowthInside1Last,
                pool: positionUnderlying_.pool,
                liquidity: liquidity,
                tick: positionUnderlying_.tick,
                lowerTick: positionUnderlying_.lowerTick,
                upperTick: positionUnderlying_.upperTick
            })
        );

        // compute current holdings from liquidity
        (amount0Current, amount1Current) = LiquidityAmounts
            .getAmountsForLiquidity(
                positionUnderlying_.sqrtPriceX96,
                TickMath.getSqrtRatioAtTick(positionUnderlying_.lowerTick),
                TickMath.getSqrtRatioAtTick(positionUnderlying_.upperTick),
                liquidity
            );

        fee0 += uint256(tokensOwed0);
        fee1 += uint256(tokensOwed1);
    }

    /// @notice Computes the token0 and token1 value for a given amount of liquidity, the current
    /// pool prices and the prices at the tick boundaries
    function getAmountsForDelta(
        uint160 sqrtRatioX96,
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        int128 liquidity
    ) public pure returns (uint256 amount0, uint256 amount1) {
        if (sqrtRatioAX96 > sqrtRatioBX96)
            (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

        if (sqrtRatioX96 < sqrtRatioAX96) {
            amount0 = SafeCast.toUint256(
                SqrtPriceMath.getAmount0Delta(
                    sqrtRatioAX96,
                    sqrtRatioBX96,
                    liquidity
                )
            );
        } else if (sqrtRatioX96 < sqrtRatioBX96) {
            amount0 = SafeCast.toUint256(
                SqrtPriceMath.getAmount0Delta(
                    sqrtRatioX96,
                    sqrtRatioBX96,
                    liquidity
                )
            );
            amount1 = SafeCast.toUint256(
                SqrtPriceMath.getAmount1Delta(
                    sqrtRatioAX96,
                    sqrtRatioX96,
                    liquidity
                )
            );
        } else {
            amount1 = SafeCast.toUint256(
                SqrtPriceMath.getAmount1Delta(
                    sqrtRatioAX96,
                    sqrtRatioBX96,
                    liquidity
                )
            );
        }
    }

    function subtractAdminFees(
        uint256 rawFee0_,
        uint256 rawFee1_,
        uint16 managerFeeBPS_
    ) public pure returns (uint256 fee0, uint256 fee1) {
        fee0 = rawFee0_ - ((rawFee0_ * (managerFeeBPS_)) / 10000);
        fee1 = rawFee1_ - ((rawFee1_ * (managerFeeBPS_)) / 10000);
    }

    // solhint-disable-next-line function-max-lines
    function computeMintAmounts(
        uint256 current0_,
        uint256 current1_,
        uint256 totalSupply_,
        uint256 amount0Max_,
        uint256 amount1Max_
    ) public pure returns (uint256 mintAmount) {
        // compute proportional amount of tokens to mint
        if (current0_ == 0 && current1_ > 0) {
            mintAmount = FullMath.mulDiv(amount1Max_, totalSupply_, current1_);
        } else if (current1_ == 0 && current0_ > 0) {
            mintAmount = FullMath.mulDiv(amount0Max_, totalSupply_, current0_);
        } else if (current0_ > 0 && current1_ > 0) {
            uint256 amount0Mint = FullMath.mulDiv(
                amount0Max_,
                totalSupply_,
                current0_
            );
            uint256 amount1Mint = FullMath.mulDiv(
                amount1Max_,
                totalSupply_,
                current1_
            );
            require(
                amount0Mint > 0 && amount1Mint > 0,
                "ArrakisVaultV2: mint 0"
            );

            mintAmount = amount0Mint < amount1Mint ? amount0Mint : amount1Mint;
        } else {
            revert("ArrakisVaultV2: panic");
        }
    }

    // solhint-disable-next-line function-max-lines
    function _getFeesEarned(GetFeesPayload memory feeInfo_)
        private
        view
        returns (uint256 fee0, uint256 fee1)
    {
        (
            ,
            ,
            uint256 feeGrowthOutside0Lower,
            uint256 feeGrowthOutside1Lower,
            ,
            ,
            ,

        ) = feeInfo_.pool.ticks(feeInfo_.lowerTick);
        (
            ,
            ,
            uint256 feeGrowthOutside0Upper,
            uint256 feeGrowthOutside1Upper,
            ,
            ,
            ,

        ) = feeInfo_.pool.ticks(feeInfo_.upperTick);

        ComputeFeesPayload memory payload = ComputeFeesPayload({
            feeGrowthInsideLast: feeInfo_.feeGrowthInside0Last,
            feeGrowthOutsideLower: feeGrowthOutside0Lower,
            feeGrowthOutsideUpper: feeGrowthOutside0Upper,
            feeGrowthGlobal: feeInfo_.pool.feeGrowthGlobal0X128(),
            pool: feeInfo_.pool,
            liquidity: feeInfo_.liquidity,
            tick: feeInfo_.tick,
            lowerTick: feeInfo_.lowerTick,
            upperTick: feeInfo_.upperTick
        });

        fee0 = _computeFeesEarned(payload);
        payload.feeGrowthInsideLast = feeInfo_.feeGrowthInside1Last;
        payload.feeGrowthOutsideLower = feeGrowthOutside1Lower;
        payload.feeGrowthOutsideUpper = feeGrowthOutside1Upper;
        payload.feeGrowthGlobal = feeInfo_.pool.feeGrowthGlobal1X128();
        fee1 = _computeFeesEarned(payload);
    }

    // solhint-disable-next-line function-max-lines
    function _totalUnderlyingWithFees(
        UnderlyingPayload memory underlyingPayload_,
        uint160 sqrtPriceX96_
    )
        private
        view
        returns (
            uint256 amount0,
            uint256 amount1,
            uint256 fee0,
            uint256 fee1
        )
    {
        for (uint256 i; i < underlyingPayload_.ranges.length; i++) {
            {
                IUniswapV3Pool pool = IUniswapV3Pool(
                    underlyingPayload_.factory.getPool(
                        underlyingPayload_.token0,
                        underlyingPayload_.token1,
                        underlyingPayload_.ranges[i].feeTier
                    )
                );
                (uint256 a0, uint256 a1, uint256 f0, uint256 f1) = underlying(
                    RangeData({
                        self: underlyingPayload_.self,
                        range: underlyingPayload_.ranges[i],
                        pool: pool
                    }),
                    sqrtPriceX96_
                );
                amount0 += a0;
                amount1 += a1;
                fee0 += f0;
                fee1 += f1;
            }
        }

        IArrakisV2 arrakisV2 = IArrakisV2(underlyingPayload_.self);

        (uint256 fee0After, uint256 fee1After) = subtractAdminFees(
            fee0,
            fee1,
            arrakisV2.managerFeeBPS()
        );

        amount0 +=
            fee0After +
            IERC20(underlyingPayload_.token0).balanceOf(
                underlyingPayload_.self
            ) -
            arrakisV2.managerBalance0();
        amount1 +=
            fee1After +
            IERC20(underlyingPayload_.token1).balanceOf(
                underlyingPayload_.self
            ) -
            arrakisV2.managerBalance1();
    }

    function _computeFeesEarned(ComputeFeesPayload memory computeFees_)
        private
        pure
        returns (uint256 fee)
    {
        unchecked {
            // calculate fee growth below
            uint256 feeGrowthBelow;
            if (computeFees_.tick >= computeFees_.lowerTick) {
                feeGrowthBelow = computeFees_.feeGrowthOutsideLower;
            } else {
                feeGrowthBelow =
                    computeFees_.feeGrowthGlobal -
                    computeFees_.feeGrowthOutsideLower;
            }

            // calculate fee growth above
            uint256 feeGrowthAbove;
            if (computeFees_.tick < computeFees_.upperTick) {
                feeGrowthAbove = computeFees_.feeGrowthOutsideUpper;
            } else {
                feeGrowthAbove =
                    computeFees_.feeGrowthGlobal -
                    computeFees_.feeGrowthOutsideUpper;
            }

            uint256 feeGrowthInside = computeFees_.feeGrowthGlobal -
                feeGrowthBelow -
                feeGrowthAbove;
            fee = FullMath.mulDiv(
                computeFees_.liquidity,
                feeGrowthInside - computeFees_.feeGrowthInsideLast,
                0x100000000000000000000000000000000
            );
        }
    }
}

File 38 of 38 : SArrakisV2.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;

import {
    IUniswapV3Pool
} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
import {
    IUniswapV3Factory
} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol";

struct PositionLiquidity {
    uint128 liquidity;
    Range range;
}

struct SwapPayload {
    bytes payload;
    address router;
    uint256 amountIn;
    uint256 expectedMinReturn;
    bool zeroForOne;
}

struct Range {
    int24 lowerTick;
    int24 upperTick;
    uint24 feeTier;
}

struct Rebalance {
    PositionLiquidity[] burns;
    PositionLiquidity[] mints;
    SwapPayload swap;
    uint256 minBurn0;
    uint256 minBurn1;
    uint256 minDeposit0;
    uint256 minDeposit1;
}

struct RangeWeight {
    Range range;
    uint256 weight; // should be between 0 and 100%
}

struct InitializePayload {
    uint24[] feeTiers;
    address token0;
    address token1;
    address owner;
    uint256 init0;
    uint256 init1;
    address manager;
    address[] routers;
}

// #region internal Structs

struct UnderlyingOutput {
    uint256 amount0;
    uint256 amount1;
    uint256 fee0;
    uint256 fee1;
    uint256 leftOver0;
    uint256 leftOver1;
}

struct ComputeFeesPayload {
    uint256 feeGrowthInsideLast;
    uint256 feeGrowthOutsideLower;
    uint256 feeGrowthOutsideUpper;
    uint256 feeGrowthGlobal;
    IUniswapV3Pool pool;
    uint128 liquidity;
    int24 tick;
    int24 lowerTick;
    int24 upperTick;
}

struct GetFeesPayload {
    uint256 feeGrowthInside0Last;
    uint256 feeGrowthInside1Last;
    IUniswapV3Pool pool;
    uint128 liquidity;
    int24 tick;
    int24 lowerTick;
    int24 upperTick;
}

struct PositionUnderlying {
    bytes32 positionId;
    uint160 sqrtPriceX96;
    IUniswapV3Pool pool;
    int24 tick;
    int24 lowerTick;
    int24 upperTick;
}

struct Withdraw {
    uint256 burn0;
    uint256 burn1;
    uint256 fee0;
    uint256 fee1;
}

struct UnderlyingPayload {
    Range[] ranges;
    IUniswapV3Factory factory;
    address token0;
    address token1;
    address self;
}

struct RangeData {
    address self;
    Range range;
    IUniswapV3Pool pool;
}

// #endregion internal Structs

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 833
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "metadata": {
    "useLiteralContent": true
  },
  "libraries": {
    "contracts/ArrakisV2.sol": {
      "Pool": "0x6d843e2b0c023150403c73ed385d915dcde086d9",
      "Position": "0x7f9c70ec572282f87417bf75417c7a838739f89d",
      "Underlying": "0x666651c520bf4721f2f5b0460ed8b8d60bbdde8b"
    }
  }
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"contract IUniswapV3Factory","name":"factory_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"burnAmount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"burnAmount1","type":"uint256"}],"name":"LPBurned","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint24[]","name":"feeTiers","type":"uint24[]"}],"name":"LogAddPools","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address[]","name":"routers","type":"address[]"}],"name":"LogBlacklistRouters","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"burnAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount0Out","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1Out","type":"uint256"}],"name":"LogBurn","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"fee0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee1","type":"uint256"}],"name":"LogCollectedFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"mintAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount0In","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1In","type":"uint256"}],"name":"LogMint","type":"event"},{"anonymous":false,"inputs":[{"components":[{"components":[{"internalType":"uint128","name":"liquidity","type":"uint128"},{"components":[{"internalType":"int24","name":"lowerTick","type":"int24"},{"internalType":"int24","name":"upperTick","type":"int24"},{"internalType":"uint24","name":"feeTier","type":"uint24"}],"internalType":"struct Range","name":"range","type":"tuple"}],"internalType":"struct PositionLiquidity[]","name":"burns","type":"tuple[]"},{"components":[{"internalType":"uint128","name":"liquidity","type":"uint128"},{"components":[{"internalType":"int24","name":"lowerTick","type":"int24"},{"internalType":"int24","name":"upperTick","type":"int24"},{"internalType":"uint24","name":"feeTier","type":"uint24"}],"internalType":"struct Range","name":"range","type":"tuple"}],"internalType":"struct PositionLiquidity[]","name":"mints","type":"tuple[]"},{"components":[{"internalType":"bytes","name":"payload","type":"bytes"},{"internalType":"address","name":"router","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"expectedMinReturn","type":"uint256"},{"internalType":"bool","name":"zeroForOne","type":"bool"}],"internalType":"struct SwapPayload","name":"swap","type":"tuple"},{"internalType":"uint256","name":"minBurn0","type":"uint256"},{"internalType":"uint256","name":"minBurn1","type":"uint256"},{"internalType":"uint256","name":"minDeposit0","type":"uint256"},{"internalType":"uint256","name":"minDeposit1","type":"uint256"}],"indexed":false,"internalType":"struct Rebalance","name":"rebalanceParams","type":"tuple"},{"indexed":false,"internalType":"uint256","name":"swapDelta0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"swapDelta1","type":"uint256"}],"name":"LogRebalance","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address[]","name":"pools","type":"address[]"}],"name":"LogRemovePools","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"minter","type":"address"}],"name":"LogRestrictedMint","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"init0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"init1","type":"uint256"}],"name":"LogSetInits","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newManager","type":"address"}],"name":"LogSetManager","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"managerFeeBPS","type":"uint16"}],"name":"LogSetManagerFeeBPS","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address[]","name":"routers","type":"address[]"}],"name":"LogWhitelistRouters","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"LogWithdrawManagerBalance","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"uint24[]","name":"feeTiers_","type":"uint24[]"}],"name":"addPools","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"routers_","type":"address[]"}],"name":"blacklistRouters","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"burnAmount_","type":"uint256"},{"internalType":"address","name":"receiver_","type":"address"}],"name":"burn","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"contract IUniswapV3Factory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPools","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRanges","outputs":[{"components":[{"internalType":"int24","name":"lowerTick","type":"int24"},{"internalType":"int24","name":"upperTick","type":"int24"},{"internalType":"uint24","name":"feeTier","type":"uint24"}],"internalType":"struct Range[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRouters","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"init0","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"init1","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"name_","type":"string"},{"internalType":"string","name":"symbol_","type":"string"},{"components":[{"internalType":"uint24[]","name":"feeTiers","type":"uint24[]"},{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"init0","type":"uint256"},{"internalType":"uint256","name":"init1","type":"uint256"},{"internalType":"address","name":"manager","type":"address"},{"internalType":"address[]","name":"routers","type":"address[]"}],"internalType":"struct InitializePayload","name":"params_","type":"tuple"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"manager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"managerBalance0","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"managerBalance1","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"managerFeeBPS","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"mintAmount_","type":"uint256"},{"internalType":"address","name":"receiver_","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"uint128","name":"liquidity","type":"uint128"},{"components":[{"internalType":"int24","name":"lowerTick","type":"int24"},{"internalType":"int24","name":"upperTick","type":"int24"},{"internalType":"uint24","name":"feeTier","type":"uint24"}],"internalType":"struct Range","name":"range","type":"tuple"}],"internalType":"struct PositionLiquidity[]","name":"burns","type":"tuple[]"},{"components":[{"internalType":"uint128","name":"liquidity","type":"uint128"},{"components":[{"internalType":"int24","name":"lowerTick","type":"int24"},{"internalType":"int24","name":"upperTick","type":"int24"},{"internalType":"uint24","name":"feeTier","type":"uint24"}],"internalType":"struct Range","name":"range","type":"tuple"}],"internalType":"struct PositionLiquidity[]","name":"mints","type":"tuple[]"},{"components":[{"internalType":"bytes","name":"payload","type":"bytes"},{"internalType":"address","name":"router","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"expectedMinReturn","type":"uint256"},{"internalType":"bool","name":"zeroForOne","type":"bool"}],"internalType":"struct SwapPayload","name":"swap","type":"tuple"},{"internalType":"uint256","name":"minBurn0","type":"uint256"},{"internalType":"uint256","name":"minBurn1","type":"uint256"},{"internalType":"uint256","name":"minDeposit0","type":"uint256"},{"internalType":"uint256","name":"minDeposit1","type":"uint256"}],"internalType":"struct Rebalance","name":"rebalanceParams_","type":"tuple"}],"name":"rebalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"pools_","type":"address[]"}],"name":"removePools","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"restrictedMint","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"init0_","type":"uint256"},{"internalType":"uint256","name":"init1_","type":"uint256"}],"name":"setInits","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"manager_","type":"address"}],"name":"setManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"managerFeeBPS_","type":"uint16"}],"name":"setManagerFeeBPS","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"minter_","type":"address"}],"name":"setRestrictedMint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token0","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token1","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount0Owed_","type":"uint256"},{"internalType":"uint256","name":"amount1Owed_","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"uniswapV3MintCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"routers_","type":"address[]"}],"name":"whitelistRouters","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawManagerBalance","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60a06040523480156200001157600080fd5b50604051620060b6380380620060b6833981016040819052620000349162000088565b806001600160a01b038116620000755760405162461bcd60e51b81526020600482015260026024820152612d2360f11b604482015260640160405180910390fd5b6001600160a01b031660805250620000ba565b6000602082840312156200009b57600080fd5b81516001600160a01b0381168114620000b357600080fd5b9392505050565b608051615faf620001076000396000818161052201528181610f0401528181611b9b0152818161243a015281816126d60152818161334c01528181613bfb0152613f7b0152615faf6000f3fe608060405234801561001057600080fd5b50600436106102d35760003560e01c806386ac1cb911610186578063c7a4ae17116100e3578063dd62ed3e11610097578063f2fde38b11610071578063f2fde38b14610606578063f88c31ce14610619578063fcd3533c1461062157600080fd5b8063dd62ed3e146105b1578063e4fadbce146105ea578063f2eb3e34146105fd57600080fd5b8063d0ebdbe7116100c8578063d0ebdbe714610578578063d21220a71461058b578063d34879971461059e57600080fd5b8063c7a4ae1714610544578063ccdf7a021461055757600080fd5b806395d89b411161013a578063a5ff1dc71161011f578063a5ff1dc7146104f7578063a9059cbb1461050a578063c45a01551461051d57600080fd5b806395d89b41146104dc578063a457c2d7146104e457600080fd5b80638da5cb5b1161016b5780638da5cb5b1461049057806392e49dfd146104a157806394bf804d146104b457600080fd5b806386ac1cb91461046a5780638712e4971461047d57600080fd5b80633f7b613511610234578063617a3419116101e857806370a08231116101cd57806370a0823114610431578063715018a61461045a5780637ecd67171461046257600080fd5b8063617a341914610407578063673a2a1f1461041c57600080fd5b80634794c84a116102195780634794c84a146103ce578063481c6a75146103e15780634b164140146103f457600080fd5b80633f7b6135146103b257806342fb9d44146103c557600080fd5b806314b806301161028b57806323b872dd1161027057806323b872dd1461037d578063313ce56714610390578063395093511461039f57600080fd5b806314b806301461036c57806318160ddd1461037557600080fd5b8063095ea7b3116102bc578063095ea7b3146103095780630d6e66311461032c5780630dfe16811461034157600080fd5b8063065756db146102d857806306fdde03146102f4575b600080fd5b6102e160ce5481565b6040519081526020015b60405180910390f35b6102fc610634565b6040516102eb9190615265565b61031c6103173660046152b8565b6106c6565b60405190151581526020016102eb565b61033f61033a3660046152e4565b6106e0565b005b60c954610354906001600160a01b031681565b6040516001600160a01b0390911681526020016102eb565b6102e160cb5481565b6067546102e1565b61031c61038b366004615301565b610793565b604051601281526020016102eb565b61031c6103ad3660046152b8565b6107b9565b61033f6103c0366004615342565b6107f8565b6102e160cf5481565b61033f6103dc366004615364565b610924565b60d054610354906001600160a01b031681565b61033f6104023660046153d4565b610a4e565b61040f610b99565b6040516102eb9190615416565b610424610c1c565b6040516102eb9190615486565b6102e161043f3660046152e4565b6001600160a01b031660009081526065602052604090205490565b61033f610ccc565b61033f610d32565b61033f6104783660046153d4565b610d98565b61033f61048b3660046154c7565b610e43565b6033546001600160a01b0316610354565b61033f6104af3660046153d4565b612160565b6104c76104c2366004615502565b612297565b604080519283526020830191909152016102eb565b6102fc612937565b61031c6104f23660046152b8565b612946565b61033f6105053660046153d4565b6129fb565b61031c6105183660046152b8565b612a63565b6103547f000000000000000000000000000000000000000000000000000000000000000081565b60d154610354906001600160a01b031681565b60cd546105659061ffff1681565b60405161ffff90911681526020016102eb565b61033f6105863660046152e4565b612a71565b60ca54610354906001600160a01b031681565b61033f6105ac366004615574565b612b80565b6102e16105bf3660046155c7565b6001600160a01b03918216600090815260666020908152604080832093909416825291909152205490565b61033f6105f83660046155f5565b612b90565b6102e160cc5481565b61033f6106143660046152e4565b61301f565b610424613101565b6104c761062f366004615502565b6131aa565b60606068805461064390615691565b80601f016020809104026020016040519081016040528092919081815260200182805461066f90615691565b80156106bc5780601f10610691576101008083540402835291602001916106bc565b820191906000526020600020905b81548152906001019060200180831161069f57829003601f168201915b5050505050905090565b6000336106d48185856137ac565b60019150505b92915050565b6033546001600160a01b0316331461073f5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064015b60405180910390fd5b60d180546001600160a01b0319166001600160a01b0383169081179091556040519081527f6b7f177e85ebe3aabaf1339b9a445ac908b2bef730372180fa280958e2414ee39060200160405180910390a150565b6000336107a18582856138d0565b6107ac85858561395c565b60019150505b9392505050565b3360008181526066602090815260408083206001600160a01b03871684529091528120549091906106d490829086906107f39087906156e1565b6137ac565b60008211806108075750600081115b6108375760405162461bcd60e51b81526020600482015260016024820152604960f81b6044820152606401610736565b6067541561086c5760405162461bcd60e51b8152602060048201526002602482015261545360f01b6044820152606401610736565b60d1546000906001600160a01b0316156108915760d1546001600160a01b031661089e565b6033546001600160a01b03165b9050336001600160a01b038216146108dc5760405162461bcd60e51b81526020600482015260016024820152602960f91b6044820152606401610736565b60cb83905560cc82905560408051848152602081018490527ff8966e026442bb0adb17149a6d44e394d2b6eb3c5cc1dc71b3c0698000548ae6910160405180910390a1505050565b60d0546001600160a01b031633146109635760405162461bcd60e51b81526020600482015260026024820152614e4d60f01b6044820152606401610736565b6002609754036109b55760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610736565b600260975561271061ffff821611156109f65760405162461bcd60e51b81526020600482015260036024820152624d464f60e81b6044820152606401610736565b6109fe613b59565b60cd805461ffff191661ffff83169081179091556040519081527fa73ff0774d4c8681f79fa6546f34bab7a3037f3b3aab405401a1fd8c6e5ca3d6906020015b60405180910390a1506001609755565b6033546001600160a01b03163314610aa85760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610736565b60005b81811015610b5b57610ae5838383818110610ac857610ac86156f9565b9050602002016020810190610add91906152e4565b60d390613d7a565b610b165760405162461bcd60e51b815260206004820152600260248201526104e560f41b6044820152606401610736565b610b48838383818110610b2b57610b2b6156f9565b9050602002016020810190610b4091906152e4565b60d390613d9c565b5080610b538161570f565b915050610aab565b507f024551cce253d1a442bfe99dae530a00a492fb8c67c4456cce3c9d23eecd39618282604051610b8d929190615728565b60405180910390a15050565b606060d2805480602002602001604051908101604052809291908181526020016000905b82821015610c135760008481526020908190206040805160608101825291850154600281810b845263010000008204900b838501526601000000000000900462ffffff1690820152825260019092019101610bbd565b50505050905090565b60606000610c2a60d3613db1565b905060008167ffffffffffffffff811115610c4757610c47615776565b604051908082528060200260200182016040528015610c70578160200160208202803683370190505b50905060005b82811015610cc557610c8960d382613dbb565b828281518110610c9b57610c9b6156f9565b6001600160a01b039092166020928302919091019091015280610cbd8161570f565b915050610c76565b5092915050565b6033546001600160a01b03163314610d265760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610736565b610d306000613dc7565b565b600260975403610d845760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610736565b6002609755610d91613e19565b6001609755565b6033546001600160a01b03163314610df25760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610736565b60c95460ca54610e1291849184916001600160a01b039081169116613f6c565b7f1b402611d70c7735d942445aaa3ebbf878149bece6b797870b44a581c5f7f4c98282604051610b8d92919061579d565b60d0546001600160a01b03163314610e825760405162461bcd60e51b81526020600482015260026024820152614e4d60f01b6044820152606401610736565b600260975403610ed45760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610736565b600260975560c95460ca5460408051608081018252600080825260208201819052918101829052606081018290527f0000000000000000000000000000000000000000000000000000000000000000936001600160a01b039081169316915b610f3d86806157dc565b90508110156114615760006001600160a01b038616631698ee828686610f638b806157dc565b87818110610f7357610f736156f9565b610f8a926080918202019081019150606001615826565b6040516001600160e01b031960e086901b1681526001600160a01b03938416600482015292909116602483015262ffffff166044820152606401602060405180830381865afa158015610fe1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110059190615843565b90506000737f9c70ec572282f87417bf75417c7a838739f89d635f49415b833061102f8c806157dc565b8881811061103f5761103f6156f9565b611058926040608090920201908101915060200161586f565b6110628d806157dc565b89818110611072576110726156f9565b61108b926060608090920201908101915060400161586f565b6040516001600160e01b031960e087901b1681526001600160a01b039485166004820152939092166024840152600290810b60448401520b6064820152608401602060405180830381865af41580156110e8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061110c91906158a1565b9050806001600160801b031660000361112657505061144f565b60006001600160801b0361113a8a806157dc565b8681811061114a5761114a6156f9565b61116092602060809092020190810191506158be565b6001600160801b0316036111755750806111a8565b61117f89806157dc565b8581811061118f5761118f6156f9565b6111a592602060809092020190810191506158be565b90505b600061121a846111b88c806157dc565b888181106111c8576111c86156f9565b6111e1926040608090920201908101915060200161586f565b6111eb8d806157dc565b898181106111fb576111fb6156f9565b611214926060608090920201908101915060400161586f565b856140ec565b9050826001600160801b0316826001600160801b0316036113eb57600080737f9c70ec572282f87417bf75417c7a838739f89d630c3c0bfc60d261125e8f806157dc565b8b81811061126e5761126e6156f9565b9050608002016020016040518363ffffffff1660e01b815260040161129492919061591f565b6040805180830381865af41580156112b0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112d491906159a8565b915091508161130e5760405162461bcd60e51b81526004016107369060208082526004908201526352524e4560e01b604082015260600190565b60d2805461131e906001906159d6565b8154811061132e5761132e6156f9565b9060005260206000200160d2828154811061134b5761134b6156f9565b6000918252602090912082549101805462ffffff92831662ffffff19821681178355845463010000009081900485160265ffffffffffff199092161717808255925466010000000000009081900490921690910268ffffff0000000000001990921691909117905560d28054806113c4576113c46159ed565b6000828152602090208101600019908101805468ffffffffffffffffff1916905501905550505b8051865187906113fc9083906156e1565b90525060208082015190870180516114159083906156e1565b905250604080820151908701805161142e9083906156e1565b90525060608082015190870180516114479083906156e1565b905250505050505b806114598161570f565b915050610f33565b5080516060860135111561149c5760405162461bcd60e51b8152602060048201526002602482015261042360f41b6044820152606401610736565b8460800135816020015110156114d95760405162461bcd60e51b8152602060048201526002602482015261423160f01b6044820152606401610736565b6000816040015111806114f0575060008160600151115b1561154857611507816040015182606001516141e5565b6040808201516060830151825191825260208201527fdbbb3a796242c9562af701570b096cb2478cd507fcd2d4080025883b10a623a5910160405180910390a15b5060006115586040860186615a03565b604001351115611a8a5761158b6115726040860186615a03565b6115839060408101906020016152e4565b60d590613d7a565b6115bc5760405162461bcd60e51b8152602060048201526002602482015261272960f11b6044820152606401610736565b6040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa158015611603573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116279190615a23565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038416906370a0823190602401602060405180830381865afa158015611671573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116959190615a23565b90506116ca6116a76040880188615a03565b6116b89060408101906020016152e4565b6001600160a01b038616906000614250565b6116fd6116da6040880188615a03565b6116eb9060408101906020016152e4565b6001600160a01b038516906000614250565b61172f61170d6040880188615a03565b61171e9060408101906020016152e4565b6001600160a01b0386169084614250565b61176161173f6040880188615a03565b6117509060408101906020016152e4565b6001600160a01b0385169083614250565b60006117706040880188615a03565b6117819060408101906020016152e4565b6001600160a01b03166117976040890189615a03565b6117a19080615a3c565b6040516117af929190615a83565b6000604051808303816000865af19150503d80600081146117ec576040519150601f19603f3d011682016040523d82523d6000602084013e6117f1565b606091505b50509050806118275760405162461bcd60e51b8152602060048201526002602482015261534360f01b6044820152606401610736565b6040516370a0823160e01b81523060048201526000906001600160a01b038716906370a0823190602401602060405180830381865afa15801561186e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118929190615a23565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038716906370a0823190602401602060405180830381865afa1580156118dc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119009190615a23565b905061190f60408a018a615a03565b6119209060a0810190608001615a9e565b156119b75761193260408a018a615a03565b6119409060600135856156e1565b8110158015611969575061195760408a018a615a03565b6119659060400135866159d6565b8210155b61199a5760405162461bcd60e51b815260206004820152600260248201526129a360f11b6044820152606401610736565b6119a482866159d6565b91506119b084826159d6565b9050611a45565b6119c460408a018a615a03565b6119d29060600135866156e1565b82101580156119fb57506119e960408a018a615a03565b6119f79060400135856159d6565b8110155b611a2c5760405162461bcd60e51b815260206004820152600260248201526129a360f11b6044820152606401610736565b611a3685836159d6565b9150611a4281856159d6565b90505b7fab3abe7e2ad787892344ed4ada44aad53c7d53e9d6b5ee91f20bd30ed39540b7898383604051611a7893929190615ccb565b60405180910390a15050505050611ac7565b7fab3abe7e2ad787892344ed4ada44aad53c7d53e9d6b5ee91f20bd30ed39540b784600080604051611abe93929190615ccb565b60405180910390a15b60008060005b611ada60208801886157dc565b9050811015611f9a576000737f9c70ec572282f87417bf75417c7a838739f89d630c3c0bfc60d2611b0e60208c018c6157dc565b86818110611b1e57611b1e6156f9565b9050608002016020016040518363ffffffff1660e01b8152600401611b4492919061591f565b6040805180830381865af4158015611b60573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b8491906159a8565b5060c95460ca549192506000916001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811692631698ee82929082169116611bd560208e018e6157dc565b88818110611be557611be56156f9565b611bfc926080918202019081019150606001615826565b6040516001600160e01b031960e086901b1681526001600160a01b03938416600482015292909116602483015262ffffff166044820152606401602060405180830381865afa158015611c53573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c779190615843565b905081611e18576001600160a01b038116611cba5760405162461bcd60e51b815260206004820152600360248201526204e55560ec1b6044820152606401610736565b611cc560d382613d7a565b611cf55760405162461bcd60e51b81526020600482015260016024820152600560fc1b6044820152606401610736565b736d843e2b0c023150403c73ed385d915dcde086d9636b01882082611d1d60208d018d6157dc565b87818110611d2d57611d2d6156f9565b9050608002016020016040518363ffffffff1660e01b8152600401611d53929190615cf0565b602060405180830381865af4158015611d70573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d949190615d0d565b611dc65760405162461bcd60e51b815260206004820152600360248201526252545360e81b6044820152606401610736565b60d2611dd560208b018b6157dc565b85818110611de557611de56156f9565b8354600181018555600094855260209485902060809092029390930193909301929091019050611e158282615d2a565b50505b6000806001600160a01b038316633c8a7d8d30611e3860208f018f6157dc565b89818110611e4857611e486156f9565b611e61926040608090920201908101915060200161586f565b8e8060200190611e7191906157dc565b8a818110611e8157611e816156f9565b611e9a926060608090920201908101915060400161586f565b8f8060200190611eaa91906157dc565b8b818110611eba57611eba6156f9565b611ed092602060809092020190810191506158be565b6040516001600160e01b031960e087901b1681526001600160a01b039094166004850152600292830b6024850152910b60448301526001600160801b0316606482015260a06084820152600060a482015260c40160408051808303816000875af1158015611f42573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f669190615db6565b9092509050611f7582886156e1565b9650611f8181876156e1565b9550505050508080611f929061570f565b915050611acd565b508560a00135821015611fd45760405162461bcd60e51b8152602060048201526002602482015261044360f41b6044820152606401610736565b8560c0013581101561200d5760405162461bcd60e51b8152602060048201526002602482015261443160f01b6044820152606401610736565b60ce5460c9546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015612058573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061207c9190615a23565b10156120b05760405162461bcd60e51b815260206004820152600360248201526204d42360ec1b6044820152606401610736565b60cf5460ca546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa1580156120fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061211f9190615a23565b10156121535760405162461bcd60e51b81526020600482015260036024820152624d423160e81b6044820152606401610736565b5050600160975550505050565b6033546001600160a01b031633146121ba5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610736565b60005b81811015612265576121ef8383838181106121da576121da6156f9565b905060200201602081019061158391906152e4565b6122205760405162461bcd60e51b8152602060048201526002602482015261525760f01b6044820152606401610736565b612252838383818110612235576122356156f9565b905060200201602081019061224a91906152e4565b60d590613d9c565b508061225d8161570f565b9150506121bd565b507fbe6c83115c5bf7fd07e41c6002394841bd7dc0348f3b7c58645e8950f604f5c48282604051610b8d929190615728565b6000806002609754036122ec5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610736565b6002609755836123235760405162461bcd60e51b81526020600482015260026024820152614d4160f01b6044820152606401610736565b60d1546001600160a01b03161580612345575060d1546001600160a01b031633145b6123755760405162461bcd60e51b81526020600482015260016024820152602960f91b6044820152606401610736565b30600061238160675490565b905080158015906124f15773666651c520bf4721f2f5b0460ed8b8d60bbdde8b6383d7ba9f6040518060a0016040528060d2805480602002602001604051908101604052809291908181526020016000905b828210156124295760008481526020908190206040805160608101825291850154600281810b845263010000008204900b838501526601000000000000900462ffffff16908201528252600190920191016123d3565b505050908252506001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116602083015260c954811660408084019190915260ca5482166060840152908816608090920191909152516001600160e01b031960e084901b1681526124a791908b908790600401615dda565b6040805180830381865af41580156124c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124e79190615db6565b90955093506125eb565b60cb5460cc54670de0b6b3a7640000919061250d8a83856143b9565b975061251a8a82856143b9565b96506125278a8385614402565b60000361253357600097505b61253e8a8285614402565b60000361254a57600096505b60008260000361255c57600019612567565b612567898585614402565b905060008260000361257b57600019612586565b612586898685614402565b90508b8183106125965781612598565b825b146125e55760405162461bcd60e51b815260206004820152600560248201527f41302641310000000000000000000000000000000000000000000000000000006044820152606401610736565b50505050505b6125f586886144b0565b84156126135760c954612613906001600160a01b031633858861458f565b83156126315760ca54612631906001600160a01b031633858761458f565b80156128da5760005b60d2548110156128d857600060d28281548110612659576126596156f9565b60009182526020808320604080516060810182529390910154600281810b855263010000008204900b92840192909252660100000000000090910462ffffff1682820181905260c95460ca549251630b4c774160e11b81526001600160a01b039182166004820152928116602484015260448301919091529193507f000000000000000000000000000000000000000000000000000000000000000090911690631698ee8290606401602060405180830381865afa15801561271f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127439190615843565b82516020840151604051635f49415b60e01b81526001600160a01b0380851660048301528a166024820152600292830b6044820152910b6064820152909150600090737f9c70ec572282f87417bf75417c7a838739f89d90635f49415b90608401602060405180830381865af41580156127c1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127e591906158a1565b90506128036127fe826001600160801b03168d89614402565b6145c7565b9050806001600160801b031660000361281e575050506128c6565b82516020840151604051633c8a7d8d60e01b81526001600160a01b038a81166004830152600293840b60248301529190920b60448301526001600160801b038316606483015260a06084830152600060a4830152831690633c8a7d8d9060c40160408051808303816000875af115801561289c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128c09190615db6565b50505050505b806128d08161570f565b91505061263a565b505b60408051888152602081018790529081018590526001600160a01b038716907f5f11830295067c4bcc7d02d4e3b048cd7427be50a3aeb6afc9d3d559ee64bcfa9060600160405180910390a2505060016097555090939092509050565b60606069805461064390615691565b3360008181526066602090815260408083206001600160a01b0387168452909152812054909190838110156129e35760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760448201527f207a65726f0000000000000000000000000000000000000000000000000000006064820152608401610736565b6129f082868684036137ac565b506001949350505050565b6033546001600160a01b03163314612a555760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610736565b612a5f828261464a565b5050565b6000336106d481858561395c565b6033546001600160a01b03163314612acb5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610736565b600260975403612b1d5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610736565b6002609755612b2a613b59565b612b32613e19565b60d080546001600160a01b0319166001600160a01b0383169081179091556040519081527f9b6ffaf4cbfd923495440b7f17ced9394289f001b3ead53ab67e2c3f3e39b0f590602001610a3e565b612b8a84846147c8565b50505050565b6000612b9c600161483e565b90508015612bb4576000805461ff0019166101001790555b6000612bc08380615e97565b905011612bf55760405162461bcd60e51b815260206004820152600360248201526213919560ea1b6044820152606401610736565b6000612c0760408401602085016152e4565b6001600160a01b031603612c425760405162461bcd60e51b8152602060048201526002602482015261054360f41b6044820152606401610736565b612c5260608301604084016152e4565b6001600160a01b0316612c6b60408401602085016152e4565b6001600160a01b031610612ca75760405162461bcd60e51b815260206004820152600360248201526257544f60e81b6044820152606401610736565b6000612cb960808401606085016152e4565b6001600160a01b031603612cf55760405162461bcd60e51b815260206004820152600360248201526227a0ad60e91b6044820152606401610736565b6000612d0760e0840160c085016152e4565b6001600160a01b031603612d435760405162461bcd60e51b815260206004820152600360248201526226a0ad60e91b6044820152606401610736565b600082608001351180612d5a575060008260a00135115b612d8a5760405162461bcd60e51b81526020600482015260016024820152604960f81b6044820152606401610736565b612dfd86868080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050604080516020601f8a01819004810282018101909252888152925088915087908190840183828082843760009201919091525061495992505050565b612e056149ce565b612e37612e128380615e97565b612e2260408601602087016152e4565b612e3260608701604088016152e4565b613f6c565b612e4760408301602084016152e4565b60c980546001600160a01b0319166001600160a01b0392909216919091179055612e7760608301604084016152e4565b60ca80546001600160a01b0319166001600160a01b0392909216919091179055612eac612ea760e0840184615e97565b61464a565b612ec4612ebf60808401606085016152e4565b613dc7565b612ed460e0830160c084016152e4565b60d080546001600160a01b0319166001600160a01b0392909216919091179055608082013560cb5560a082013560cc557f1b402611d70c7735d942445aaa3ebbf878149bece6b797870b44a581c5f7f4c9612f2f8380615e97565b604051612f3d92919061579d565b60405180910390a1604080516080840135815260a084013560208201527ff8966e026442bb0adb17149a6d44e394d2b6eb3c5cc1dc71b3c0698000548ae6910160405180910390a17f9b6ffaf4cbfd923495440b7f17ced9394289f001b3ead53ab67e2c3f3e39b0f5612fb660e0840160c085016152e4565b6040516001600160a01b03909116815260200160405180910390a18015613017576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050505050565b6033546001600160a01b031633146130795760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610736565b6001600160a01b0381166130f55760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152608401610736565b6130fe81613dc7565b50565b6060600061310f60d5613db1565b905060008167ffffffffffffffff81111561312c5761312c615776565b604051908082528060200260200182016040528015613155578160200160208202803683370190505b50905060005b82811015610cc55761316e60d582613dbb565b828281518110613180576131806156f9565b6001600160a01b0390921660209283029190910190910152806131a28161570f565b91505061315b565b6000806002609754036131ff5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610736565b6002609755836132365760405162461bcd60e51b8152602060048201526002602482015261424160f01b6044820152606401610736565b600061324160675490565b9050600081116132785760405162461bcd60e51b8152602060048201526002602482015261545360f01b6044820152606401610736565b6132823386614a41565b6132ad6040518060800160405280600081526020016000815260200160008152602001600081525090565b60005b60d25481101561351b57600060d282815481106132cf576132cf6156f9565b60009182526020808320604080516060810182529390910154600281810b855263010000008204900b92840192909252660100000000000090910462ffffff1682820181905260c95460ca549251630b4c774160e11b81526001600160a01b039182166004820152928116602484015260448301919091529193507f000000000000000000000000000000000000000000000000000000000000000090911690631698ee8290606401602060405180830381865afa158015613395573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133b99190615843565b82516020840151604051635f49415b60e01b81526001600160a01b0384166004820152306024820152600292830b6044820152910b6064820152909150600090737f9c70ec572282f87417bf75417c7a838739f89d90635f49415b90608401602060405180830381865af4158015613435573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061345991906158a1565b90506134726127fe826001600160801b03168c89614402565b9050806001600160801b031660000361348d57505050613509565b60006134a38385600001518660200151856140ec565b90508060400151866040018181516134bb91906156e1565b90525060608082015190870180516134d49083906156e1565b9052508051865187906134e89083906156e1565b90525060208082015190870180516135019083906156e1565b905250505050505b806135138161570f565b9150506132b0565b5081860361352f5761352f60d26000615165565b613541816040015182606001516141e5565b805160ce5460c9546040516370a0823160e01b815230600482015260009392916001600160a01b0316906370a0823190602401602060405180830381865afa158015613591573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135b59190615a23565b6135bf91906159d6565b6135c991906159d6565b602083015160cf5460ca546040516370a0823160e01b81523060048201529394506000936001600160a01b03909116906370a0823190602401602060405180830381865afa15801561361f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136439190615a23565b61364d91906159d6565b61365791906159d6565b9050613664828986614402565b9550613671818986614402565b835190955061368090876156e1565b955082602001518561369291906156e1565b945085156136b15760c9546136b1906001600160a01b03168888614b8f565b84156136ce5760ca546136ce906001600160a01b03168887614b8f565b8251602080850151604080519384529183015233917fbcc5876d59ecdf66ef7ccae24657b11650939218782f8d741e78fd3c35d285a3910160405180910390a26040808401516060850151825191825260208201527fdbbb3a796242c9562af701570b096cb2478cd507fcd2d4080025883b10a623a5910160405180910390a160408051898152602081018890529081018690526001600160a01b038816907f86dacd5ce62967ebd3d915a82b22ad7e159538e50c7ba451e073fec048d9f1279060600160405180910390a250506001609755509194909350915050565b6001600160a01b03831661380e5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610736565b6001600160a01b03821661386f5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610736565b6001600160a01b0383811660008181526066602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b038381166000908152606660209081526040808320938616835292905220546000198114612b8a578181101561394f5760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610736565b612b8a84848484036137ac565b6001600160a01b0383166139d85760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f20616460448201527f64726573730000000000000000000000000000000000000000000000000000006064820152608401610736565b6001600160a01b038216613a3a5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610736565b6001600160a01b03831660009081526065602052604090205481811015613ac95760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e742065786365656473206260448201527f616c616e636500000000000000000000000000000000000000000000000000006064820152608401610736565b6001600160a01b03808516600090815260656020526040808220858503905591851681529081208054849290613b009084906156e1565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051613b4c91815260200190565b60405180910390a3612b8a565b60008060005b60d254811015613d3957600060d28281548110613b7e57613b7e6156f9565b60009182526020808320604080516060810182529390910154600281810b855263010000008204900b92840192909252660100000000000090910462ffffff1682820181905260c95460ca549251630b4c774160e11b81526001600160a01b039182166004820152928116602484015260448301919091529193507f000000000000000000000000000000000000000000000000000000000000000090911690631698ee8290606401602060405180830381865afa158015613c44573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c689190615843565b8251602084015160405163a34123a760e01b8152600292830b6004820152910b6024820152600060448201529091506001600160a01b0382169063a34123a79060640160408051808303816000875af1158015613cc9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ced9190615db6565b5050600080613d058385600001518660200151614bbf565b9092509050613d1482886156e1565b9650613d2081876156e1565b9550505050508080613d319061570f565b915050613b5f565b50613d4482826141e5565b60408051838152602081018390527fdbbb3a796242c9562af701570b096cb2478cd507fcd2d4080025883b10a623a59101610b8d565b6001600160a01b038116600090815260018301602052604081205415156107b2565b60006107b2836001600160a01b038416614c6a565b60006106da825490565b60006107b28383614d5d565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60ce805460cf8054600093849055929055908115613eb15760c95460d05460405163a9059cbb60e01b81526001600160a01b0391821660048201526024810185905291169063a9059cbb906044016020604051808303816000875af1925050508015613ea2575060408051601f3d908101601f19168201909252613e9f91810190615d0d565b60015b613eaf5760009150613eb1565b505b8015613f365760ca5460d05460405163a9059cbb60e01b81526001600160a01b0391821660048201526024810184905291169063a9059cbb906044016020604051808303816000875af1925050508015613f28575060408051601f3d908101601f19168201909252613f2591810190615d0d565b60015b613f3457506000613f36565b505b60408051838152602081018390527fa292e28c648da34e20b372054caab5f0359198b3b4d5f0ef9945d4616e15dc979101610b8d565b60005b838110156140e55760007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316631698ee828585898987818110613fbc57613fbc6156f9565b9050602002016020810190613fd19190615826565b6040516001600160e01b031960e086901b1681526001600160a01b03938416600482015292909116602483015262ffffff166044820152606401602060405180830381865afa158015614028573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061404c9190615843565b90506001600160a01b0381166140895760405162461bcd60e51b81526020600482015260026024820152615a4160f01b6044820152606401610736565b61409460d382613d7a565b156140c55760405162461bcd60e51b81526020600482015260016024820152600560fc1b6044820152606401610736565b6140d060d382614d87565b505080806140dd9061570f565b915050613f6f565b5050505050565b6141176040518060800160405280600081526020016000815260200160008152602001600081525090565b60405163a34123a760e01b8152600285810b600483015284900b60248201526001600160801b03831660448201526001600160a01b0386169063a34123a79060640160408051808303816000875af1158015614177573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061419b9190615db6565b602083015281526000806141b0878787614bbf565b845191935091506141c190836159d6565b604084015260208301516141d590826159d6565b6060840152509095945050505050565b60cd5461ffff166127106141f98285615ee1565b6142039190615f16565b60ce600082825461421491906156e1565b90915550612710905061422b61ffff831684615ee1565b6142359190615f16565b60cf600082825461424691906156e1565b9091555050505050565b8015806142ca5750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa1580156142a4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142c89190615a23565b155b61433c5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527f20746f206e6f6e2d7a65726f20616c6c6f77616e6365000000000000000000006064820152608401610736565b6040516001600160a01b0383166024820152604481018290526143b490849063095ea7b360e01b906064015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff166001600160e01b031990931692909217909152614d9c565b505050565b60006143c6848484614402565b9050600082806143d8576143d8615f00565b84860911156107b25760001981106143ef57600080fd5b806143f98161570f565b95945050505050565b600080806000198587098587029250828110838203039150508060000361443b576000841161443057600080fd5b5082900490506107b2565b80841161444757600080fd5b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b6001600160a01b0382166145065760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610736565b806067600082825461451891906156e1565b90915550506001600160a01b038216600090815260656020526040812080548392906145459084906156e1565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b6040516001600160a01b0380851660248301528316604482015260648101829052612b8a9085906323b872dd60e01b90608401614368565b60006001600160801b038211156146465760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203160448201527f32382062697473000000000000000000000000000000000000000000000000006064820152608401610736565b5090565b60005b818110156147965760c9546001600160a01b0316838383818110614673576146736156f9565b905060200201602081019061468891906152e4565b6001600160a01b0316141580156146d9575060ca546001600160a01b03168383838181106146b8576146b86156f9565b90506020020160208101906146cd91906152e4565b6001600160a01b031614155b61470a5760405162461bcd60e51b8152602060048201526002602482015261149560f21b6044820152606401610736565b61471f8383838181106121da576121da6156f9565b156147515760405162461bcd60e51b815260206004820152600260248201526121a960f11b6044820152606401610736565b614783838383818110614766576147666156f9565b905060200201602081019061477b91906152e4565b60d590614d87565b508061478e8161570f565b91505061464d565b507f102656122b5bfb41d864259a385db02d34584f3a71b6c6c35c14cbdaf9038fe68282604051610b8d929190615728565b6147d360d333613d7a565b6148045760405162461bcd60e51b8152602060048201526002602482015261434360f01b6044820152606401610736565b81156148215760c954614821906001600160a01b03163384614b8f565b8015612a5f5760ca54612a5f906001600160a01b03163383614b8f565b60008054610100900460ff16156148cc578160ff1660011480156148615750303b155b6148c45760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610736565b506000919050565b60005460ff80841691161061493a5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610736565b506000805460ff191660ff92909216919091179055600190565b919050565b600054610100900460ff166149c45760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610736565b612a5f8282614e81565b600054610100900460ff16614a395760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610736565b610d30614f13565b6001600160a01b038216614aa15760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610736565b6001600160a01b03821660009081526065602052604090205481811015614b155760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610736565b6001600160a01b0383166000908152606560205260408120838303905560678054849290614b449084906159d6565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3505050565b6040516001600160a01b0383166024820152604481018290526143b490849063a9059cbb60e01b90606401614368565b6040516309e3d67b60e31b8152306004820152600283810b602483015282900b60448201526001600160801b0360648201819052608482015260009081906001600160a01b03861690634f1eb3d89060a40160408051808303816000875af1158015614c2f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614c539190615f38565b6001600160801b0391821697911695509350505050565b60008181526001830160205260408120548015614d53576000614c8e6001836159d6565b8554909150600090614ca2906001906159d6565b9050818114614d07576000866000018281548110614cc257614cc26156f9565b9060005260206000200154905080876000018481548110614ce557614ce56156f9565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080614d1857614d186159ed565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506106da565b60009150506106da565b6000826000018281548110614d7457614d746156f9565b9060005260206000200154905092915050565b60006107b2836001600160a01b038416614f7e565b6000614df1826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316614fcd9092919063ffffffff16565b8051909150156143b45780806020019051810190614e0f9190615d0d565b6143b45760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610736565b600054610100900460ff16614eec5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610736565b8151614eff906068906020850190615183565b5080516143b4906069906020840190615183565b600054610100900460ff16610d915760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610736565b6000818152600183016020526040812054614fc5575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556106da565b5060006106da565b6060614fdc8484600085614fe4565b949350505050565b60608247101561505c5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608401610736565b6001600160a01b0385163b6150b35760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610736565b600080866001600160a01b031685876040516150cf9190615f67565b60006040518083038185875af1925050503d806000811461510c576040519150601f19603f3d011682016040523d82523d6000602084013e615111565b606091505b509150915061512182828661512c565b979650505050505050565b6060831561513b5750816107b2565b82511561514b5782518084602001fd5b8160405162461bcd60e51b81526004016107369190615265565b50805460008255906000526020600020908101906130fe9190615203565b82805461518f90615691565b90600052602060002090601f0160209004810192826151b157600085556151f7565b82601f106151ca57805160ff19168380011785556151f7565b828001600101855582156151f7579182015b828111156151f75782518255916020019190600101906151dc565b50614646929150615224565b5b8082111561464657805468ffffffffffffffffff19168155600101615204565b5b808211156146465760008155600101615225565b60005b8381101561525457818101518382015260200161523c565b83811115612b8a5750506000910152565b6020815260008251806020840152615284816040850160208701615239565b601f01601f19169190910160400192915050565b6001600160a01b03811681146130fe57600080fd5b803561495481615298565b600080604083850312156152cb57600080fd5b82356152d681615298565b946020939093013593505050565b6000602082840312156152f657600080fd5b81356107b281615298565b60008060006060848603121561531657600080fd5b833561532181615298565b9250602084013561533181615298565b929592945050506040919091013590565b6000806040838503121561535557600080fd5b50508035926020909101359150565b60006020828403121561537657600080fd5b813561ffff811681146107b257600080fd5b60008083601f84011261539a57600080fd5b50813567ffffffffffffffff8111156153b257600080fd5b6020830191508360208260051b85010111156153cd57600080fd5b9250929050565b600080602083850312156153e757600080fd5b823567ffffffffffffffff8111156153fe57600080fd5b61540a85828601615388565b90969095509350505050565b6020808252825182820181905260009190848201906040850190845b8181101561547a57615467838551805160020b8252602081015160020b602083015262ffffff60408201511660408301525050565b9284019260609290920191600101615432565b50909695505050505050565b6020808252825182820181905260009190848201906040850190845b8181101561547a5783516001600160a01b0316835292840192918401916001016154a2565b6000602082840312156154d957600080fd5b813567ffffffffffffffff8111156154f057600080fd5b820160e081850312156107b257600080fd5b6000806040838503121561551557600080fd5b82359150602083013561552781615298565b809150509250929050565b60008083601f84011261554457600080fd5b50813567ffffffffffffffff81111561555c57600080fd5b6020830191508360208285010111156153cd57600080fd5b6000806000806060858703121561558a57600080fd5b8435935060208501359250604085013567ffffffffffffffff8111156155af57600080fd5b6155bb87828801615532565b95989497509550505050565b600080604083850312156155da57600080fd5b82356155e581615298565b9150602083013561552781615298565b60008060008060006060868803121561560d57600080fd5b853567ffffffffffffffff8082111561562557600080fd5b61563189838a01615532565b9097509550602088013591508082111561564a57600080fd5b61565689838a01615532565b9095509350604088013591508082111561566f57600080fd5b508601610100818903121561568357600080fd5b809150509295509295909350565b600181811c908216806156a557607f821691505b6020821081036156c557634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b600082198211156156f4576156f46156cb565b500190565b634e487b7160e01b600052603260045260246000fd5b600060018201615721576157216156cb565b5060010190565b60208082528181018390526000908460408401835b8681101561576b57823561575081615298565b6001600160a01b03168252918301919083019060010161573d565b509695505050505050565b634e487b7160e01b600052604160045260246000fd5b62ffffff811681146130fe57600080fd5b60208082528181018390526000908460408401835b8681101561576b5782356157c58161578c565b62ffffff16825291830191908301906001016157b2565b6000808335601e198436030181126157f357600080fd5b83018035915067ffffffffffffffff82111561580e57600080fd5b6020019150600781901b36038213156153cd57600080fd5b60006020828403121561583857600080fd5b81356107b28161578c565b60006020828403121561585557600080fd5b81516107b281615298565b8060020b81146130fe57600080fd5b60006020828403121561588157600080fd5b81356107b281615860565b6001600160801b03811681146130fe57600080fd5b6000602082840312156158b357600080fd5b81516107b28161588c565b6000602082840312156158d057600080fd5b81356107b28161588c565b80356158e681615860565b60020b825260208101356158f981615860565b60020b6020830152604081013561590f8161578c565b62ffffff81166040840152505050565b6000608082016080835280855480835260a08501915086600052602092508260002060005b8281101561597f578154600281810b8652601882901c900b8686015260301c62ffffff16604085015260609093019260019182019101615944565b50505080925050615992818401856158db565b509392505050565b80151581146130fe57600080fd5b600080604083850312156159bb57600080fd5b82516159c68161599a565b6020939093015192949293505050565b6000828210156159e8576159e86156cb565b500390565b634e487b7160e01b600052603160045260246000fd5b60008235609e19833603018112615a1957600080fd5b9190910192915050565b600060208284031215615a3557600080fd5b5051919050565b6000808335601e19843603018112615a5357600080fd5b83018035915067ffffffffffffffff821115615a6e57600080fd5b6020019150368190038213156153cd57600080fd5b8183823760009101908152919050565b80356149548161599a565b600060208284031215615ab057600080fd5b81356107b28161599a565b6000808335601e19843603018112615ad257600080fd5b830160208101925035905067ffffffffffffffff811115615af257600080fd5b8060071b36038313156153cd57600080fd5b8183526000602080850194508260005b85811015615b53578135615b278161588c565b6001600160801b03168752615b408388018385016158db565b6080968701969190910190600101615b14565b509495945050505050565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b60008135601e19833603018112615b9d57600080fd5b8201803567ffffffffffffffff811115615bb657600080fd5b803603841315615bc557600080fd5b60a08552615bda60a086018260208501615b5e565b915050615be9602084016152ad565b6001600160a01b0381166020860152506040830135604085015260608301356060850152615c1960808401615a93565b8015156080860152615992565b6000615c328283615abb565b60e08552615c4460e086018284615b04565b915050615c546020840184615abb565b8583036020870152615c67838284615b04565b925050506040830135609e19843603018112615c8257600080fd5b8482036040860152615c9682858301615b87565b915050606083013560608501526080830135608085015260a083013560a085015260c083013560c08501528091505092915050565b606081526000615cde6060830186615c26565b60208301949094525060400152919050565b6001600160a01b0383168152608081016107b260208301846158db565b600060208284031215615d1f57600080fd5b81516107b28161599a565b8135615d3581615860565b815462ffffff82811662ffffff1983161784556020850135615d5681615860565b8060181b9050818416935065ffffff00000091508082168465ffffffffffff198516171785556040860135615d8a8161578c565b911668ffffffffffffffffff19929092169092171760309190911b68ffffff0000000000001617905550565b60008060408385031215615dc957600080fd5b505080516020909101519092909150565b6060808252845160a083830152805161010084018190526000929160209190820190610120860190855b81811015615e4957615e39838551805160020b8252602081015160020b602083015262ffffff60408201511660408301525050565b9284019291850191600101615e04565b5050828901516001600160a01b039081166080888101919091526040808c0151831660a08a0152958b0151821660c08901529099015190981660e08601525083019490945250919091015290565b6000808335601e19843603018112615eae57600080fd5b83018035915067ffffffffffffffff821115615ec957600080fd5b6020019150600581901b36038213156153cd57600080fd5b6000816000190483118215151615615efb57615efb6156cb565b500290565b634e487b7160e01b600052601260045260246000fd5b600082615f3357634e487b7160e01b600052601260045260246000fd5b500490565b60008060408385031215615f4b57600080fd5b8251615f568161588c565b60208401519092506155278161588c565b60008251615a1981846020870161523956fea2646970667358221220ade3a88f158043a4517c9e1b6a8862d17b220b43baa2c912b13907c5569fb20164736f6c634300080d00330000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f984

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106102d35760003560e01c806386ac1cb911610186578063c7a4ae17116100e3578063dd62ed3e11610097578063f2fde38b11610071578063f2fde38b14610606578063f88c31ce14610619578063fcd3533c1461062157600080fd5b8063dd62ed3e146105b1578063e4fadbce146105ea578063f2eb3e34146105fd57600080fd5b8063d0ebdbe7116100c8578063d0ebdbe714610578578063d21220a71461058b578063d34879971461059e57600080fd5b8063c7a4ae1714610544578063ccdf7a021461055757600080fd5b806395d89b411161013a578063a5ff1dc71161011f578063a5ff1dc7146104f7578063a9059cbb1461050a578063c45a01551461051d57600080fd5b806395d89b41146104dc578063a457c2d7146104e457600080fd5b80638da5cb5b1161016b5780638da5cb5b1461049057806392e49dfd146104a157806394bf804d146104b457600080fd5b806386ac1cb91461046a5780638712e4971461047d57600080fd5b80633f7b613511610234578063617a3419116101e857806370a08231116101cd57806370a0823114610431578063715018a61461045a5780637ecd67171461046257600080fd5b8063617a341914610407578063673a2a1f1461041c57600080fd5b80634794c84a116102195780634794c84a146103ce578063481c6a75146103e15780634b164140146103f457600080fd5b80633f7b6135146103b257806342fb9d44146103c557600080fd5b806314b806301161028b57806323b872dd1161027057806323b872dd1461037d578063313ce56714610390578063395093511461039f57600080fd5b806314b806301461036c57806318160ddd1461037557600080fd5b8063095ea7b3116102bc578063095ea7b3146103095780630d6e66311461032c5780630dfe16811461034157600080fd5b8063065756db146102d857806306fdde03146102f4575b600080fd5b6102e160ce5481565b6040519081526020015b60405180910390f35b6102fc610634565b6040516102eb9190615265565b61031c6103173660046152b8565b6106c6565b60405190151581526020016102eb565b61033f61033a3660046152e4565b6106e0565b005b60c954610354906001600160a01b031681565b6040516001600160a01b0390911681526020016102eb565b6102e160cb5481565b6067546102e1565b61031c61038b366004615301565b610793565b604051601281526020016102eb565b61031c6103ad3660046152b8565b6107b9565b61033f6103c0366004615342565b6107f8565b6102e160cf5481565b61033f6103dc366004615364565b610924565b60d054610354906001600160a01b031681565b61033f6104023660046153d4565b610a4e565b61040f610b99565b6040516102eb9190615416565b610424610c1c565b6040516102eb9190615486565b6102e161043f3660046152e4565b6001600160a01b031660009081526065602052604090205490565b61033f610ccc565b61033f610d32565b61033f6104783660046153d4565b610d98565b61033f61048b3660046154c7565b610e43565b6033546001600160a01b0316610354565b61033f6104af3660046153d4565b612160565b6104c76104c2366004615502565b612297565b604080519283526020830191909152016102eb565b6102fc612937565b61031c6104f23660046152b8565b612946565b61033f6105053660046153d4565b6129fb565b61031c6105183660046152b8565b612a63565b6103547f0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f98481565b60d154610354906001600160a01b031681565b60cd546105659061ffff1681565b60405161ffff90911681526020016102eb565b61033f6105863660046152e4565b612a71565b60ca54610354906001600160a01b031681565b61033f6105ac366004615574565b612b80565b6102e16105bf3660046155c7565b6001600160a01b03918216600090815260666020908152604080832093909416825291909152205490565b61033f6105f83660046155f5565b612b90565b6102e160cc5481565b61033f6106143660046152e4565b61301f565b610424613101565b6104c761062f366004615502565b6131aa565b60606068805461064390615691565b80601f016020809104026020016040519081016040528092919081815260200182805461066f90615691565b80156106bc5780601f10610691576101008083540402835291602001916106bc565b820191906000526020600020905b81548152906001019060200180831161069f57829003601f168201915b5050505050905090565b6000336106d48185856137ac565b60019150505b92915050565b6033546001600160a01b0316331461073f5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064015b60405180910390fd5b60d180546001600160a01b0319166001600160a01b0383169081179091556040519081527f6b7f177e85ebe3aabaf1339b9a445ac908b2bef730372180fa280958e2414ee39060200160405180910390a150565b6000336107a18582856138d0565b6107ac85858561395c565b60019150505b9392505050565b3360008181526066602090815260408083206001600160a01b03871684529091528120549091906106d490829086906107f39087906156e1565b6137ac565b60008211806108075750600081115b6108375760405162461bcd60e51b81526020600482015260016024820152604960f81b6044820152606401610736565b6067541561086c5760405162461bcd60e51b8152602060048201526002602482015261545360f01b6044820152606401610736565b60d1546000906001600160a01b0316156108915760d1546001600160a01b031661089e565b6033546001600160a01b03165b9050336001600160a01b038216146108dc5760405162461bcd60e51b81526020600482015260016024820152602960f91b6044820152606401610736565b60cb83905560cc82905560408051848152602081018490527ff8966e026442bb0adb17149a6d44e394d2b6eb3c5cc1dc71b3c0698000548ae6910160405180910390a1505050565b60d0546001600160a01b031633146109635760405162461bcd60e51b81526020600482015260026024820152614e4d60f01b6044820152606401610736565b6002609754036109b55760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610736565b600260975561271061ffff821611156109f65760405162461bcd60e51b81526020600482015260036024820152624d464f60e81b6044820152606401610736565b6109fe613b59565b60cd805461ffff191661ffff83169081179091556040519081527fa73ff0774d4c8681f79fa6546f34bab7a3037f3b3aab405401a1fd8c6e5ca3d6906020015b60405180910390a1506001609755565b6033546001600160a01b03163314610aa85760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610736565b60005b81811015610b5b57610ae5838383818110610ac857610ac86156f9565b9050602002016020810190610add91906152e4565b60d390613d7a565b610b165760405162461bcd60e51b815260206004820152600260248201526104e560f41b6044820152606401610736565b610b48838383818110610b2b57610b2b6156f9565b9050602002016020810190610b4091906152e4565b60d390613d9c565b5080610b538161570f565b915050610aab565b507f024551cce253d1a442bfe99dae530a00a492fb8c67c4456cce3c9d23eecd39618282604051610b8d929190615728565b60405180910390a15050565b606060d2805480602002602001604051908101604052809291908181526020016000905b82821015610c135760008481526020908190206040805160608101825291850154600281810b845263010000008204900b838501526601000000000000900462ffffff1690820152825260019092019101610bbd565b50505050905090565b60606000610c2a60d3613db1565b905060008167ffffffffffffffff811115610c4757610c47615776565b604051908082528060200260200182016040528015610c70578160200160208202803683370190505b50905060005b82811015610cc557610c8960d382613dbb565b828281518110610c9b57610c9b6156f9565b6001600160a01b039092166020928302919091019091015280610cbd8161570f565b915050610c76565b5092915050565b6033546001600160a01b03163314610d265760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610736565b610d306000613dc7565b565b600260975403610d845760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610736565b6002609755610d91613e19565b6001609755565b6033546001600160a01b03163314610df25760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610736565b60c95460ca54610e1291849184916001600160a01b039081169116613f6c565b7f1b402611d70c7735d942445aaa3ebbf878149bece6b797870b44a581c5f7f4c98282604051610b8d92919061579d565b60d0546001600160a01b03163314610e825760405162461bcd60e51b81526020600482015260026024820152614e4d60f01b6044820152606401610736565b600260975403610ed45760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610736565b600260975560c95460ca5460408051608081018252600080825260208201819052918101829052606081018290527f0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f984936001600160a01b039081169316915b610f3d86806157dc565b90508110156114615760006001600160a01b038616631698ee828686610f638b806157dc565b87818110610f7357610f736156f9565b610f8a926080918202019081019150606001615826565b6040516001600160e01b031960e086901b1681526001600160a01b03938416600482015292909116602483015262ffffff166044820152606401602060405180830381865afa158015610fe1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110059190615843565b90506000737f9c70ec572282f87417bf75417c7a838739f89d635f49415b833061102f8c806157dc565b8881811061103f5761103f6156f9565b611058926040608090920201908101915060200161586f565b6110628d806157dc565b89818110611072576110726156f9565b61108b926060608090920201908101915060400161586f565b6040516001600160e01b031960e087901b1681526001600160a01b039485166004820152939092166024840152600290810b60448401520b6064820152608401602060405180830381865af41580156110e8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061110c91906158a1565b9050806001600160801b031660000361112657505061144f565b60006001600160801b0361113a8a806157dc565b8681811061114a5761114a6156f9565b61116092602060809092020190810191506158be565b6001600160801b0316036111755750806111a8565b61117f89806157dc565b8581811061118f5761118f6156f9565b6111a592602060809092020190810191506158be565b90505b600061121a846111b88c806157dc565b888181106111c8576111c86156f9565b6111e1926040608090920201908101915060200161586f565b6111eb8d806157dc565b898181106111fb576111fb6156f9565b611214926060608090920201908101915060400161586f565b856140ec565b9050826001600160801b0316826001600160801b0316036113eb57600080737f9c70ec572282f87417bf75417c7a838739f89d630c3c0bfc60d261125e8f806157dc565b8b81811061126e5761126e6156f9565b9050608002016020016040518363ffffffff1660e01b815260040161129492919061591f565b6040805180830381865af41580156112b0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112d491906159a8565b915091508161130e5760405162461bcd60e51b81526004016107369060208082526004908201526352524e4560e01b604082015260600190565b60d2805461131e906001906159d6565b8154811061132e5761132e6156f9565b9060005260206000200160d2828154811061134b5761134b6156f9565b6000918252602090912082549101805462ffffff92831662ffffff19821681178355845463010000009081900485160265ffffffffffff199092161717808255925466010000000000009081900490921690910268ffffff0000000000001990921691909117905560d28054806113c4576113c46159ed565b6000828152602090208101600019908101805468ffffffffffffffffff1916905501905550505b8051865187906113fc9083906156e1565b90525060208082015190870180516114159083906156e1565b905250604080820151908701805161142e9083906156e1565b90525060608082015190870180516114479083906156e1565b905250505050505b806114598161570f565b915050610f33565b5080516060860135111561149c5760405162461bcd60e51b8152602060048201526002602482015261042360f41b6044820152606401610736565b8460800135816020015110156114d95760405162461bcd60e51b8152602060048201526002602482015261423160f01b6044820152606401610736565b6000816040015111806114f0575060008160600151115b1561154857611507816040015182606001516141e5565b6040808201516060830151825191825260208201527fdbbb3a796242c9562af701570b096cb2478cd507fcd2d4080025883b10a623a5910160405180910390a15b5060006115586040860186615a03565b604001351115611a8a5761158b6115726040860186615a03565b6115839060408101906020016152e4565b60d590613d7a565b6115bc5760405162461bcd60e51b8152602060048201526002602482015261272960f11b6044820152606401610736565b6040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa158015611603573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116279190615a23565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038416906370a0823190602401602060405180830381865afa158015611671573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116959190615a23565b90506116ca6116a76040880188615a03565b6116b89060408101906020016152e4565b6001600160a01b038616906000614250565b6116fd6116da6040880188615a03565b6116eb9060408101906020016152e4565b6001600160a01b038516906000614250565b61172f61170d6040880188615a03565b61171e9060408101906020016152e4565b6001600160a01b0386169084614250565b61176161173f6040880188615a03565b6117509060408101906020016152e4565b6001600160a01b0385169083614250565b60006117706040880188615a03565b6117819060408101906020016152e4565b6001600160a01b03166117976040890189615a03565b6117a19080615a3c565b6040516117af929190615a83565b6000604051808303816000865af19150503d80600081146117ec576040519150601f19603f3d011682016040523d82523d6000602084013e6117f1565b606091505b50509050806118275760405162461bcd60e51b8152602060048201526002602482015261534360f01b6044820152606401610736565b6040516370a0823160e01b81523060048201526000906001600160a01b038716906370a0823190602401602060405180830381865afa15801561186e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118929190615a23565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038716906370a0823190602401602060405180830381865afa1580156118dc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119009190615a23565b905061190f60408a018a615a03565b6119209060a0810190608001615a9e565b156119b75761193260408a018a615a03565b6119409060600135856156e1565b8110158015611969575061195760408a018a615a03565b6119659060400135866159d6565b8210155b61199a5760405162461bcd60e51b815260206004820152600260248201526129a360f11b6044820152606401610736565b6119a482866159d6565b91506119b084826159d6565b9050611a45565b6119c460408a018a615a03565b6119d29060600135866156e1565b82101580156119fb57506119e960408a018a615a03565b6119f79060400135856159d6565b8110155b611a2c5760405162461bcd60e51b815260206004820152600260248201526129a360f11b6044820152606401610736565b611a3685836159d6565b9150611a4281856159d6565b90505b7fab3abe7e2ad787892344ed4ada44aad53c7d53e9d6b5ee91f20bd30ed39540b7898383604051611a7893929190615ccb565b60405180910390a15050505050611ac7565b7fab3abe7e2ad787892344ed4ada44aad53c7d53e9d6b5ee91f20bd30ed39540b784600080604051611abe93929190615ccb565b60405180910390a15b60008060005b611ada60208801886157dc565b9050811015611f9a576000737f9c70ec572282f87417bf75417c7a838739f89d630c3c0bfc60d2611b0e60208c018c6157dc565b86818110611b1e57611b1e6156f9565b9050608002016020016040518363ffffffff1660e01b8152600401611b4492919061591f565b6040805180830381865af4158015611b60573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b8491906159a8565b5060c95460ca549192506000916001600160a01b037f0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f984811692631698ee82929082169116611bd560208e018e6157dc565b88818110611be557611be56156f9565b611bfc926080918202019081019150606001615826565b6040516001600160e01b031960e086901b1681526001600160a01b03938416600482015292909116602483015262ffffff166044820152606401602060405180830381865afa158015611c53573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c779190615843565b905081611e18576001600160a01b038116611cba5760405162461bcd60e51b815260206004820152600360248201526204e55560ec1b6044820152606401610736565b611cc560d382613d7a565b611cf55760405162461bcd60e51b81526020600482015260016024820152600560fc1b6044820152606401610736565b736d843e2b0c023150403c73ed385d915dcde086d9636b01882082611d1d60208d018d6157dc565b87818110611d2d57611d2d6156f9565b9050608002016020016040518363ffffffff1660e01b8152600401611d53929190615cf0565b602060405180830381865af4158015611d70573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d949190615d0d565b611dc65760405162461bcd60e51b815260206004820152600360248201526252545360e81b6044820152606401610736565b60d2611dd560208b018b6157dc565b85818110611de557611de56156f9565b8354600181018555600094855260209485902060809092029390930193909301929091019050611e158282615d2a565b50505b6000806001600160a01b038316633c8a7d8d30611e3860208f018f6157dc565b89818110611e4857611e486156f9565b611e61926040608090920201908101915060200161586f565b8e8060200190611e7191906157dc565b8a818110611e8157611e816156f9565b611e9a926060608090920201908101915060400161586f565b8f8060200190611eaa91906157dc565b8b818110611eba57611eba6156f9565b611ed092602060809092020190810191506158be565b6040516001600160e01b031960e087901b1681526001600160a01b039094166004850152600292830b6024850152910b60448301526001600160801b0316606482015260a06084820152600060a482015260c40160408051808303816000875af1158015611f42573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f669190615db6565b9092509050611f7582886156e1565b9650611f8181876156e1565b9550505050508080611f929061570f565b915050611acd565b508560a00135821015611fd45760405162461bcd60e51b8152602060048201526002602482015261044360f41b6044820152606401610736565b8560c0013581101561200d5760405162461bcd60e51b8152602060048201526002602482015261443160f01b6044820152606401610736565b60ce5460c9546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015612058573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061207c9190615a23565b10156120b05760405162461bcd60e51b815260206004820152600360248201526204d42360ec1b6044820152606401610736565b60cf5460ca546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa1580156120fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061211f9190615a23565b10156121535760405162461bcd60e51b81526020600482015260036024820152624d423160e81b6044820152606401610736565b5050600160975550505050565b6033546001600160a01b031633146121ba5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610736565b60005b81811015612265576121ef8383838181106121da576121da6156f9565b905060200201602081019061158391906152e4565b6122205760405162461bcd60e51b8152602060048201526002602482015261525760f01b6044820152606401610736565b612252838383818110612235576122356156f9565b905060200201602081019061224a91906152e4565b60d590613d9c565b508061225d8161570f565b9150506121bd565b507fbe6c83115c5bf7fd07e41c6002394841bd7dc0348f3b7c58645e8950f604f5c48282604051610b8d929190615728565b6000806002609754036122ec5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610736565b6002609755836123235760405162461bcd60e51b81526020600482015260026024820152614d4160f01b6044820152606401610736565b60d1546001600160a01b03161580612345575060d1546001600160a01b031633145b6123755760405162461bcd60e51b81526020600482015260016024820152602960f91b6044820152606401610736565b30600061238160675490565b905080158015906124f15773666651c520bf4721f2f5b0460ed8b8d60bbdde8b6383d7ba9f6040518060a0016040528060d2805480602002602001604051908101604052809291908181526020016000905b828210156124295760008481526020908190206040805160608101825291850154600281810b845263010000008204900b838501526601000000000000900462ffffff16908201528252600190920191016123d3565b505050908252506001600160a01b037f0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f9848116602083015260c954811660408084019190915260ca5482166060840152908816608090920191909152516001600160e01b031960e084901b1681526124a791908b908790600401615dda565b6040805180830381865af41580156124c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124e79190615db6565b90955093506125eb565b60cb5460cc54670de0b6b3a7640000919061250d8a83856143b9565b975061251a8a82856143b9565b96506125278a8385614402565b60000361253357600097505b61253e8a8285614402565b60000361254a57600096505b60008260000361255c57600019612567565b612567898585614402565b905060008260000361257b57600019612586565b612586898685614402565b90508b8183106125965781612598565b825b146125e55760405162461bcd60e51b815260206004820152600560248201527f41302641310000000000000000000000000000000000000000000000000000006044820152606401610736565b50505050505b6125f586886144b0565b84156126135760c954612613906001600160a01b031633858861458f565b83156126315760ca54612631906001600160a01b031633858761458f565b80156128da5760005b60d2548110156128d857600060d28281548110612659576126596156f9565b60009182526020808320604080516060810182529390910154600281810b855263010000008204900b92840192909252660100000000000090910462ffffff1682820181905260c95460ca549251630b4c774160e11b81526001600160a01b039182166004820152928116602484015260448301919091529193507f0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f98490911690631698ee8290606401602060405180830381865afa15801561271f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127439190615843565b82516020840151604051635f49415b60e01b81526001600160a01b0380851660048301528a166024820152600292830b6044820152910b6064820152909150600090737f9c70ec572282f87417bf75417c7a838739f89d90635f49415b90608401602060405180830381865af41580156127c1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127e591906158a1565b90506128036127fe826001600160801b03168d89614402565b6145c7565b9050806001600160801b031660000361281e575050506128c6565b82516020840151604051633c8a7d8d60e01b81526001600160a01b038a81166004830152600293840b60248301529190920b60448301526001600160801b038316606483015260a06084830152600060a4830152831690633c8a7d8d9060c40160408051808303816000875af115801561289c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128c09190615db6565b50505050505b806128d08161570f565b91505061263a565b505b60408051888152602081018790529081018590526001600160a01b038716907f5f11830295067c4bcc7d02d4e3b048cd7427be50a3aeb6afc9d3d559ee64bcfa9060600160405180910390a2505060016097555090939092509050565b60606069805461064390615691565b3360008181526066602090815260408083206001600160a01b0387168452909152812054909190838110156129e35760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760448201527f207a65726f0000000000000000000000000000000000000000000000000000006064820152608401610736565b6129f082868684036137ac565b506001949350505050565b6033546001600160a01b03163314612a555760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610736565b612a5f828261464a565b5050565b6000336106d481858561395c565b6033546001600160a01b03163314612acb5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610736565b600260975403612b1d5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610736565b6002609755612b2a613b59565b612b32613e19565b60d080546001600160a01b0319166001600160a01b0383169081179091556040519081527f9b6ffaf4cbfd923495440b7f17ced9394289f001b3ead53ab67e2c3f3e39b0f590602001610a3e565b612b8a84846147c8565b50505050565b6000612b9c600161483e565b90508015612bb4576000805461ff0019166101001790555b6000612bc08380615e97565b905011612bf55760405162461bcd60e51b815260206004820152600360248201526213919560ea1b6044820152606401610736565b6000612c0760408401602085016152e4565b6001600160a01b031603612c425760405162461bcd60e51b8152602060048201526002602482015261054360f41b6044820152606401610736565b612c5260608301604084016152e4565b6001600160a01b0316612c6b60408401602085016152e4565b6001600160a01b031610612ca75760405162461bcd60e51b815260206004820152600360248201526257544f60e81b6044820152606401610736565b6000612cb960808401606085016152e4565b6001600160a01b031603612cf55760405162461bcd60e51b815260206004820152600360248201526227a0ad60e91b6044820152606401610736565b6000612d0760e0840160c085016152e4565b6001600160a01b031603612d435760405162461bcd60e51b815260206004820152600360248201526226a0ad60e91b6044820152606401610736565b600082608001351180612d5a575060008260a00135115b612d8a5760405162461bcd60e51b81526020600482015260016024820152604960f81b6044820152606401610736565b612dfd86868080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050604080516020601f8a01819004810282018101909252888152925088915087908190840183828082843760009201919091525061495992505050565b612e056149ce565b612e37612e128380615e97565b612e2260408601602087016152e4565b612e3260608701604088016152e4565b613f6c565b612e4760408301602084016152e4565b60c980546001600160a01b0319166001600160a01b0392909216919091179055612e7760608301604084016152e4565b60ca80546001600160a01b0319166001600160a01b0392909216919091179055612eac612ea760e0840184615e97565b61464a565b612ec4612ebf60808401606085016152e4565b613dc7565b612ed460e0830160c084016152e4565b60d080546001600160a01b0319166001600160a01b0392909216919091179055608082013560cb5560a082013560cc557f1b402611d70c7735d942445aaa3ebbf878149bece6b797870b44a581c5f7f4c9612f2f8380615e97565b604051612f3d92919061579d565b60405180910390a1604080516080840135815260a084013560208201527ff8966e026442bb0adb17149a6d44e394d2b6eb3c5cc1dc71b3c0698000548ae6910160405180910390a17f9b6ffaf4cbfd923495440b7f17ced9394289f001b3ead53ab67e2c3f3e39b0f5612fb660e0840160c085016152e4565b6040516001600160a01b03909116815260200160405180910390a18015613017576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050505050565b6033546001600160a01b031633146130795760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610736565b6001600160a01b0381166130f55760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152608401610736565b6130fe81613dc7565b50565b6060600061310f60d5613db1565b905060008167ffffffffffffffff81111561312c5761312c615776565b604051908082528060200260200182016040528015613155578160200160208202803683370190505b50905060005b82811015610cc55761316e60d582613dbb565b828281518110613180576131806156f9565b6001600160a01b0390921660209283029190910190910152806131a28161570f565b91505061315b565b6000806002609754036131ff5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610736565b6002609755836132365760405162461bcd60e51b8152602060048201526002602482015261424160f01b6044820152606401610736565b600061324160675490565b9050600081116132785760405162461bcd60e51b8152602060048201526002602482015261545360f01b6044820152606401610736565b6132823386614a41565b6132ad6040518060800160405280600081526020016000815260200160008152602001600081525090565b60005b60d25481101561351b57600060d282815481106132cf576132cf6156f9565b60009182526020808320604080516060810182529390910154600281810b855263010000008204900b92840192909252660100000000000090910462ffffff1682820181905260c95460ca549251630b4c774160e11b81526001600160a01b039182166004820152928116602484015260448301919091529193507f0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f98490911690631698ee8290606401602060405180830381865afa158015613395573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133b99190615843565b82516020840151604051635f49415b60e01b81526001600160a01b0384166004820152306024820152600292830b6044820152910b6064820152909150600090737f9c70ec572282f87417bf75417c7a838739f89d90635f49415b90608401602060405180830381865af4158015613435573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061345991906158a1565b90506134726127fe826001600160801b03168c89614402565b9050806001600160801b031660000361348d57505050613509565b60006134a38385600001518660200151856140ec565b90508060400151866040018181516134bb91906156e1565b90525060608082015190870180516134d49083906156e1565b9052508051865187906134e89083906156e1565b90525060208082015190870180516135019083906156e1565b905250505050505b806135138161570f565b9150506132b0565b5081860361352f5761352f60d26000615165565b613541816040015182606001516141e5565b805160ce5460c9546040516370a0823160e01b815230600482015260009392916001600160a01b0316906370a0823190602401602060405180830381865afa158015613591573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135b59190615a23565b6135bf91906159d6565b6135c991906159d6565b602083015160cf5460ca546040516370a0823160e01b81523060048201529394506000936001600160a01b03909116906370a0823190602401602060405180830381865afa15801561361f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136439190615a23565b61364d91906159d6565b61365791906159d6565b9050613664828986614402565b9550613671818986614402565b835190955061368090876156e1565b955082602001518561369291906156e1565b945085156136b15760c9546136b1906001600160a01b03168888614b8f565b84156136ce5760ca546136ce906001600160a01b03168887614b8f565b8251602080850151604080519384529183015233917fbcc5876d59ecdf66ef7ccae24657b11650939218782f8d741e78fd3c35d285a3910160405180910390a26040808401516060850151825191825260208201527fdbbb3a796242c9562af701570b096cb2478cd507fcd2d4080025883b10a623a5910160405180910390a160408051898152602081018890529081018690526001600160a01b038816907f86dacd5ce62967ebd3d915a82b22ad7e159538e50c7ba451e073fec048d9f1279060600160405180910390a250506001609755509194909350915050565b6001600160a01b03831661380e5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610736565b6001600160a01b03821661386f5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610736565b6001600160a01b0383811660008181526066602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b038381166000908152606660209081526040808320938616835292905220546000198114612b8a578181101561394f5760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610736565b612b8a84848484036137ac565b6001600160a01b0383166139d85760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f20616460448201527f64726573730000000000000000000000000000000000000000000000000000006064820152608401610736565b6001600160a01b038216613a3a5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610736565b6001600160a01b03831660009081526065602052604090205481811015613ac95760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e742065786365656473206260448201527f616c616e636500000000000000000000000000000000000000000000000000006064820152608401610736565b6001600160a01b03808516600090815260656020526040808220858503905591851681529081208054849290613b009084906156e1565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051613b4c91815260200190565b60405180910390a3612b8a565b60008060005b60d254811015613d3957600060d28281548110613b7e57613b7e6156f9565b60009182526020808320604080516060810182529390910154600281810b855263010000008204900b92840192909252660100000000000090910462ffffff1682820181905260c95460ca549251630b4c774160e11b81526001600160a01b039182166004820152928116602484015260448301919091529193507f0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f98490911690631698ee8290606401602060405180830381865afa158015613c44573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c689190615843565b8251602084015160405163a34123a760e01b8152600292830b6004820152910b6024820152600060448201529091506001600160a01b0382169063a34123a79060640160408051808303816000875af1158015613cc9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ced9190615db6565b5050600080613d058385600001518660200151614bbf565b9092509050613d1482886156e1565b9650613d2081876156e1565b9550505050508080613d319061570f565b915050613b5f565b50613d4482826141e5565b60408051838152602081018390527fdbbb3a796242c9562af701570b096cb2478cd507fcd2d4080025883b10a623a59101610b8d565b6001600160a01b038116600090815260018301602052604081205415156107b2565b60006107b2836001600160a01b038416614c6a565b60006106da825490565b60006107b28383614d5d565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60ce805460cf8054600093849055929055908115613eb15760c95460d05460405163a9059cbb60e01b81526001600160a01b0391821660048201526024810185905291169063a9059cbb906044016020604051808303816000875af1925050508015613ea2575060408051601f3d908101601f19168201909252613e9f91810190615d0d565b60015b613eaf5760009150613eb1565b505b8015613f365760ca5460d05460405163a9059cbb60e01b81526001600160a01b0391821660048201526024810184905291169063a9059cbb906044016020604051808303816000875af1925050508015613f28575060408051601f3d908101601f19168201909252613f2591810190615d0d565b60015b613f3457506000613f36565b505b60408051838152602081018390527fa292e28c648da34e20b372054caab5f0359198b3b4d5f0ef9945d4616e15dc979101610b8d565b60005b838110156140e55760007f0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f9846001600160a01b0316631698ee828585898987818110613fbc57613fbc6156f9565b9050602002016020810190613fd19190615826565b6040516001600160e01b031960e086901b1681526001600160a01b03938416600482015292909116602483015262ffffff166044820152606401602060405180830381865afa158015614028573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061404c9190615843565b90506001600160a01b0381166140895760405162461bcd60e51b81526020600482015260026024820152615a4160f01b6044820152606401610736565b61409460d382613d7a565b156140c55760405162461bcd60e51b81526020600482015260016024820152600560fc1b6044820152606401610736565b6140d060d382614d87565b505080806140dd9061570f565b915050613f6f565b5050505050565b6141176040518060800160405280600081526020016000815260200160008152602001600081525090565b60405163a34123a760e01b8152600285810b600483015284900b60248201526001600160801b03831660448201526001600160a01b0386169063a34123a79060640160408051808303816000875af1158015614177573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061419b9190615db6565b602083015281526000806141b0878787614bbf565b845191935091506141c190836159d6565b604084015260208301516141d590826159d6565b6060840152509095945050505050565b60cd5461ffff166127106141f98285615ee1565b6142039190615f16565b60ce600082825461421491906156e1565b90915550612710905061422b61ffff831684615ee1565b6142359190615f16565b60cf600082825461424691906156e1565b9091555050505050565b8015806142ca5750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa1580156142a4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142c89190615a23565b155b61433c5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527f20746f206e6f6e2d7a65726f20616c6c6f77616e6365000000000000000000006064820152608401610736565b6040516001600160a01b0383166024820152604481018290526143b490849063095ea7b360e01b906064015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff166001600160e01b031990931692909217909152614d9c565b505050565b60006143c6848484614402565b9050600082806143d8576143d8615f00565b84860911156107b25760001981106143ef57600080fd5b806143f98161570f565b95945050505050565b600080806000198587098587029250828110838203039150508060000361443b576000841161443057600080fd5b5082900490506107b2565b80841161444757600080fd5b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b6001600160a01b0382166145065760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610736565b806067600082825461451891906156e1565b90915550506001600160a01b038216600090815260656020526040812080548392906145459084906156e1565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b6040516001600160a01b0380851660248301528316604482015260648101829052612b8a9085906323b872dd60e01b90608401614368565b60006001600160801b038211156146465760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203160448201527f32382062697473000000000000000000000000000000000000000000000000006064820152608401610736565b5090565b60005b818110156147965760c9546001600160a01b0316838383818110614673576146736156f9565b905060200201602081019061468891906152e4565b6001600160a01b0316141580156146d9575060ca546001600160a01b03168383838181106146b8576146b86156f9565b90506020020160208101906146cd91906152e4565b6001600160a01b031614155b61470a5760405162461bcd60e51b8152602060048201526002602482015261149560f21b6044820152606401610736565b61471f8383838181106121da576121da6156f9565b156147515760405162461bcd60e51b815260206004820152600260248201526121a960f11b6044820152606401610736565b614783838383818110614766576147666156f9565b905060200201602081019061477b91906152e4565b60d590614d87565b508061478e8161570f565b91505061464d565b507f102656122b5bfb41d864259a385db02d34584f3a71b6c6c35c14cbdaf9038fe68282604051610b8d929190615728565b6147d360d333613d7a565b6148045760405162461bcd60e51b8152602060048201526002602482015261434360f01b6044820152606401610736565b81156148215760c954614821906001600160a01b03163384614b8f565b8015612a5f5760ca54612a5f906001600160a01b03163383614b8f565b60008054610100900460ff16156148cc578160ff1660011480156148615750303b155b6148c45760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610736565b506000919050565b60005460ff80841691161061493a5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610736565b506000805460ff191660ff92909216919091179055600190565b919050565b600054610100900460ff166149c45760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610736565b612a5f8282614e81565b600054610100900460ff16614a395760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610736565b610d30614f13565b6001600160a01b038216614aa15760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610736565b6001600160a01b03821660009081526065602052604090205481811015614b155760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610736565b6001600160a01b0383166000908152606560205260408120838303905560678054849290614b449084906159d6565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3505050565b6040516001600160a01b0383166024820152604481018290526143b490849063a9059cbb60e01b90606401614368565b6040516309e3d67b60e31b8152306004820152600283810b602483015282900b60448201526001600160801b0360648201819052608482015260009081906001600160a01b03861690634f1eb3d89060a40160408051808303816000875af1158015614c2f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614c539190615f38565b6001600160801b0391821697911695509350505050565b60008181526001830160205260408120548015614d53576000614c8e6001836159d6565b8554909150600090614ca2906001906159d6565b9050818114614d07576000866000018281548110614cc257614cc26156f9565b9060005260206000200154905080876000018481548110614ce557614ce56156f9565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080614d1857614d186159ed565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506106da565b60009150506106da565b6000826000018281548110614d7457614d746156f9565b9060005260206000200154905092915050565b60006107b2836001600160a01b038416614f7e565b6000614df1826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316614fcd9092919063ffffffff16565b8051909150156143b45780806020019051810190614e0f9190615d0d565b6143b45760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610736565b600054610100900460ff16614eec5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610736565b8151614eff906068906020850190615183565b5080516143b4906069906020840190615183565b600054610100900460ff16610d915760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610736565b6000818152600183016020526040812054614fc5575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556106da565b5060006106da565b6060614fdc8484600085614fe4565b949350505050565b60608247101561505c5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608401610736565b6001600160a01b0385163b6150b35760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610736565b600080866001600160a01b031685876040516150cf9190615f67565b60006040518083038185875af1925050503d806000811461510c576040519150601f19603f3d011682016040523d82523d6000602084013e615111565b606091505b509150915061512182828661512c565b979650505050505050565b6060831561513b5750816107b2565b82511561514b5782518084602001fd5b8160405162461bcd60e51b81526004016107369190615265565b50805460008255906000526020600020908101906130fe9190615203565b82805461518f90615691565b90600052602060002090601f0160209004810192826151b157600085556151f7565b82601f106151ca57805160ff19168380011785556151f7565b828001600101855582156151f7579182015b828111156151f75782518255916020019190600101906151dc565b50614646929150615224565b5b8082111561464657805468ffffffffffffffffff19168155600101615204565b5b808211156146465760008155600101615225565b60005b8381101561525457818101518382015260200161523c565b83811115612b8a5750506000910152565b6020815260008251806020840152615284816040850160208701615239565b601f01601f19169190910160400192915050565b6001600160a01b03811681146130fe57600080fd5b803561495481615298565b600080604083850312156152cb57600080fd5b82356152d681615298565b946020939093013593505050565b6000602082840312156152f657600080fd5b81356107b281615298565b60008060006060848603121561531657600080fd5b833561532181615298565b9250602084013561533181615298565b929592945050506040919091013590565b6000806040838503121561535557600080fd5b50508035926020909101359150565b60006020828403121561537657600080fd5b813561ffff811681146107b257600080fd5b60008083601f84011261539a57600080fd5b50813567ffffffffffffffff8111156153b257600080fd5b6020830191508360208260051b85010111156153cd57600080fd5b9250929050565b600080602083850312156153e757600080fd5b823567ffffffffffffffff8111156153fe57600080fd5b61540a85828601615388565b90969095509350505050565b6020808252825182820181905260009190848201906040850190845b8181101561547a57615467838551805160020b8252602081015160020b602083015262ffffff60408201511660408301525050565b9284019260609290920191600101615432565b50909695505050505050565b6020808252825182820181905260009190848201906040850190845b8181101561547a5783516001600160a01b0316835292840192918401916001016154a2565b6000602082840312156154d957600080fd5b813567ffffffffffffffff8111156154f057600080fd5b820160e081850312156107b257600080fd5b6000806040838503121561551557600080fd5b82359150602083013561552781615298565b809150509250929050565b60008083601f84011261554457600080fd5b50813567ffffffffffffffff81111561555c57600080fd5b6020830191508360208285010111156153cd57600080fd5b6000806000806060858703121561558a57600080fd5b8435935060208501359250604085013567ffffffffffffffff8111156155af57600080fd5b6155bb87828801615532565b95989497509550505050565b600080604083850312156155da57600080fd5b82356155e581615298565b9150602083013561552781615298565b60008060008060006060868803121561560d57600080fd5b853567ffffffffffffffff8082111561562557600080fd5b61563189838a01615532565b9097509550602088013591508082111561564a57600080fd5b61565689838a01615532565b9095509350604088013591508082111561566f57600080fd5b508601610100818903121561568357600080fd5b809150509295509295909350565b600181811c908216806156a557607f821691505b6020821081036156c557634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b600082198211156156f4576156f46156cb565b500190565b634e487b7160e01b600052603260045260246000fd5b600060018201615721576157216156cb565b5060010190565b60208082528181018390526000908460408401835b8681101561576b57823561575081615298565b6001600160a01b03168252918301919083019060010161573d565b509695505050505050565b634e487b7160e01b600052604160045260246000fd5b62ffffff811681146130fe57600080fd5b60208082528181018390526000908460408401835b8681101561576b5782356157c58161578c565b62ffffff16825291830191908301906001016157b2565b6000808335601e198436030181126157f357600080fd5b83018035915067ffffffffffffffff82111561580e57600080fd5b6020019150600781901b36038213156153cd57600080fd5b60006020828403121561583857600080fd5b81356107b28161578c565b60006020828403121561585557600080fd5b81516107b281615298565b8060020b81146130fe57600080fd5b60006020828403121561588157600080fd5b81356107b281615860565b6001600160801b03811681146130fe57600080fd5b6000602082840312156158b357600080fd5b81516107b28161588c565b6000602082840312156158d057600080fd5b81356107b28161588c565b80356158e681615860565b60020b825260208101356158f981615860565b60020b6020830152604081013561590f8161578c565b62ffffff81166040840152505050565b6000608082016080835280855480835260a08501915086600052602092508260002060005b8281101561597f578154600281810b8652601882901c900b8686015260301c62ffffff16604085015260609093019260019182019101615944565b50505080925050615992818401856158db565b509392505050565b80151581146130fe57600080fd5b600080604083850312156159bb57600080fd5b82516159c68161599a565b6020939093015192949293505050565b6000828210156159e8576159e86156cb565b500390565b634e487b7160e01b600052603160045260246000fd5b60008235609e19833603018112615a1957600080fd5b9190910192915050565b600060208284031215615a3557600080fd5b5051919050565b6000808335601e19843603018112615a5357600080fd5b83018035915067ffffffffffffffff821115615a6e57600080fd5b6020019150368190038213156153cd57600080fd5b8183823760009101908152919050565b80356149548161599a565b600060208284031215615ab057600080fd5b81356107b28161599a565b6000808335601e19843603018112615ad257600080fd5b830160208101925035905067ffffffffffffffff811115615af257600080fd5b8060071b36038313156153cd57600080fd5b8183526000602080850194508260005b85811015615b53578135615b278161588c565b6001600160801b03168752615b408388018385016158db565b6080968701969190910190600101615b14565b509495945050505050565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b60008135601e19833603018112615b9d57600080fd5b8201803567ffffffffffffffff811115615bb657600080fd5b803603841315615bc557600080fd5b60a08552615bda60a086018260208501615b5e565b915050615be9602084016152ad565b6001600160a01b0381166020860152506040830135604085015260608301356060850152615c1960808401615a93565b8015156080860152615992565b6000615c328283615abb565b60e08552615c4460e086018284615b04565b915050615c546020840184615abb565b8583036020870152615c67838284615b04565b925050506040830135609e19843603018112615c8257600080fd5b8482036040860152615c9682858301615b87565b915050606083013560608501526080830135608085015260a083013560a085015260c083013560c08501528091505092915050565b606081526000615cde6060830186615c26565b60208301949094525060400152919050565b6001600160a01b0383168152608081016107b260208301846158db565b600060208284031215615d1f57600080fd5b81516107b28161599a565b8135615d3581615860565b815462ffffff82811662ffffff1983161784556020850135615d5681615860565b8060181b9050818416935065ffffff00000091508082168465ffffffffffff198516171785556040860135615d8a8161578c565b911668ffffffffffffffffff19929092169092171760309190911b68ffffff0000000000001617905550565b60008060408385031215615dc957600080fd5b505080516020909101519092909150565b6060808252845160a083830152805161010084018190526000929160209190820190610120860190855b81811015615e4957615e39838551805160020b8252602081015160020b602083015262ffffff60408201511660408301525050565b9284019291850191600101615e04565b5050828901516001600160a01b039081166080888101919091526040808c0151831660a08a0152958b0151821660c08901529099015190981660e08601525083019490945250919091015290565b6000808335601e19843603018112615eae57600080fd5b83018035915067ffffffffffffffff821115615ec957600080fd5b6020019150600581901b36038213156153cd57600080fd5b6000816000190483118215151615615efb57615efb6156cb565b500290565b634e487b7160e01b600052601260045260246000fd5b600082615f3357634e487b7160e01b600052601260045260246000fd5b500490565b60008060408385031215615f4b57600080fd5b8251615f568161588c565b60208401519092506155278161588c565b60008251615a1981846020870161523956fea2646970667358221220ade3a88f158043a4517c9e1b6a8862d17b220b43baa2c912b13907c5569fb20164736f6c634300080d0033

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

0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f984

-----Decoded View---------------
Arg [0] : factory_ (address): 0x1F98431c8aD98523631AE4a59f267346ea31F984

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f984


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

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.