FRAX Price: $0.99 (-2.34%)

Contract

0x90eeBEBa24B35f5264669c9561079cB77cE6D1cf

Overview

FRAX Balance | FXTL Balance

0 FRAX | 262 FXTL

FRAX Value

$0.00

Token Holdings

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Block
From
To

There are no matching entries

> 10 Internal Transactions and 1 Token Transfer found.

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block From To
237415732025-08-04 7:50:57173 days ago1754293857
0x90eeBEBa...77cE6D1cf
0 FRAX
237415642025-08-04 7:50:39173 days ago1754293839
0x90eeBEBa...77cE6D1cf
0 FRAX
237410512025-08-04 7:33:33173 days ago1754292813
0x90eeBEBa...77cE6D1cf
0 FRAX
237409892025-08-04 7:31:29173 days ago1754292689
0x90eeBEBa...77cE6D1cf
0 FRAX
237409792025-08-04 7:31:09173 days ago1754292669
0x90eeBEBa...77cE6D1cf
0 FRAX
237409412025-08-04 7:29:53173 days ago1754292593
0x90eeBEBa...77cE6D1cf
0 FRAX
233552152025-07-26 9:12:21182 days ago1753521141
0x90eeBEBa...77cE6D1cf
0 FRAX
233551942025-07-26 9:11:39182 days ago1753521099
0x90eeBEBa...77cE6D1cf
0 FRAX
204431412025-05-19 23:23:13250 days ago1747696993
0x90eeBEBa...77cE6D1cf
0 FRAX
202469062025-05-15 10:22:03254 days ago1747304523
0x90eeBEBa...77cE6D1cf
0 FRAX
191964572025-04-21 2:47:05279 days ago1745203625
0x90eeBEBa...77cE6D1cf
0 FRAX
191964542025-04-21 2:46:59279 days ago1745203619
0x90eeBEBa...77cE6D1cf
0 FRAX
191964522025-04-21 2:46:55279 days ago1745203615
0x90eeBEBa...77cE6D1cf
0 FRAX
191963432025-04-21 2:43:17279 days ago1745203397
0x90eeBEBa...77cE6D1cf
0 FRAX
191963412025-04-21 2:43:13279 days ago1745203393
0x90eeBEBa...77cE6D1cf
0 FRAX
173826772025-03-10 3:07:45321 days ago1741576065
0x90eeBEBa...77cE6D1cf
0 FRAX
173826772025-03-10 3:07:45321 days ago1741576065
0x90eeBEBa...77cE6D1cf
0 FRAX
173826712025-03-10 3:07:33321 days ago1741576053
0x90eeBEBa...77cE6D1cf
0 FRAX
173826712025-03-10 3:07:33321 days ago1741576053
0x90eeBEBa...77cE6D1cf
0 FRAX
173826552025-03-10 3:07:01321 days ago1741576021
0x90eeBEBa...77cE6D1cf
0 FRAX
173826552025-03-10 3:07:01321 days ago1741576021
0x90eeBEBa...77cE6D1cf
0 FRAX
173826492025-03-10 3:06:49321 days ago1741576009
0x90eeBEBa...77cE6D1cf
0 FRAX
173826492025-03-10 3:06:49321 days ago1741576009
0x90eeBEBa...77cE6D1cf
0 FRAX
173826292025-03-10 3:06:09321 days ago1741575969
0x90eeBEBa...77cE6D1cf
0 FRAX
173826252025-03-10 3:06:01321 days ago1741575961
0x90eeBEBa...77cE6D1cf
0 FRAX
View All Internal Transactions

Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
TeaVaultV3Pair

Compiler Version
v0.8.26+commit.8a97fa7a

Optimization Enabled:
Yes with 1 runs

Other Settings:
paris EvmVersion
File 1 of 32 : TeaVaultV3Pair.sol
// SPDX-License-Identifier: BUSL-1.1
// Teahouse Finance

pragma solidity =0.8.26;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeCast.sol";
import "@openzeppelin/contracts/utils/Address.sol";

import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol";
import "@uniswap/v3-core/contracts/libraries/TickMath.sol";
import "@uniswap/v3-core/contracts/libraries/FullMath.sol";
import "@uniswap/v3-periphery/contracts/libraries/PoolAddress.sol";

import "./interface/IUniswapV3Pool.sol";
import "./interface/ITeaVaultV3Pair.sol";
import "./interface/IGenericRouter1Inch.sol";
import "./interface/INileGauge.sol";
import "./interface/IRewardCounter.sol";
import "./library/VaultUtils.sol";
import "./library/GenericRouter1Inch.sol";

//import "hardhat/console.sol";

contract TeaVaultV3Pair is
    ITeaVaultV3Pair,
    Initializable,
    UUPSUpgradeable,
    OwnableUpgradeable,
    ReentrancyGuardUpgradeable,
    ERC20Upgradeable
{
    using SafeERC20 for ERC20Upgradeable;
    using FullMath for uint256;
    using SafeCast for uint256;

    uint256 public SECONDS_IN_A_YEAR;
    uint256 public DECIMALS_MULTIPLIER;
    uint256 public FEE_MULTIPLIER;
    uint8 internal DECIMALS;
    uint8 internal MAX_POSITION_LENGTH;

    address public manager;
    Position[] public positions;
    FeeConfig public feeConfig;

    IUniswapV3Pool public pool;
    ERC20Upgradeable private token0;
    ERC20Upgradeable private token1;

    uint256 private callbackStatus;
    uint256 public lastCollectManagementFee;

    IGenericRouter1Inch public router1Inch;
    uint256 public FEE_CAP;

    address public rewardClaimer;

    // LXP-L distribution
    address public lxpL;
    uint256 private lastRewardBalance;

    uint256 private X36;
    uint256 private rewardsPerShareX36;
    mapping(address => IRewardCounter.UserData) private userData;

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers(); // prevent attackers from using implementation contracts (audit ID:4)
    }

    function initialize(
        string calldata _name,
        string calldata _symbol,
        address _factory,
        address _token0,
        address _token1,
        uint24 _feeTier,
        uint8 _decimalOffset,
        uint24 _feeCap,
        FeeConfig calldata _feeConfig,
        address _owner,
        address _rewardClaimer
    ) public initializer {
        __UUPSUpgradeable_init();
        __Ownable_init(_owner);
        __ReentrancyGuard_init();
        __ERC20_init(_name, _symbol);

        if (_token0 >= _token1) {
            revert InvalidTokenOrder();
        }
        
        SECONDS_IN_A_YEAR = 365 * 24 * 60 * 60;
        DECIMALS_MULTIPLIER = 10 ** _decimalOffset;
        FEE_MULTIPLIER = 1000000;
        MAX_POSITION_LENGTH = 5;

        IUniswapV3Factory factory = IUniswapV3Factory(_factory);
        pool = IUniswapV3Pool(factory.getPool(_token0, _token1, _feeTier));
        if (address(pool) == address(0)) revert PoolNotInitialized(); // Make sure the pool exists (audit ID:1)

        token0 = ERC20Upgradeable(_token0);
        token1 = ERC20Upgradeable(_token1);
        DECIMALS = _decimalOffset + token0.decimals();

        callbackStatus = 1;

        // set a hardcap on fee configuration (audit ID:3)
        if (_feeCap >= FEE_MULTIPLIER) revert InvalidFeeCap();
        FEE_CAP = _feeCap;
        rewardClaimer = _rewardClaimer;
        
        _setFeeConfig(_feeConfig); // set initial fee config (audit ID:2)

        emit TeaVaultV3PairCreated(address(this));
    }

    function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}

    function decimals() public view override returns (uint8) {
        return DECIMALS;
    }

    function assetToken0() public view override returns (address) {
        return address(token0);
    }

    function assetToken1() public view override returns (address) {
        return address(token1);
    }

    function getToken0Balance() external override view returns (uint256 amount) {
        return token0.balanceOf(address(this));
    }

    function getToken1Balance() external override view returns (uint256 amount) {
        return token1.balanceOf(address(this));
    }

    function getPoolInfo() external view returns (address, address, uint8, uint8, uint24, uint160, int24) {
        uint24 feeTier = pool.fee();
        uint8 decimals0 = token0.decimals();
        uint8 decimals1 = token1.decimals();
        (uint160 sqrtPriceX96, int24 tick, , , , , ) = pool.slot0();

        return (address(token0), address(token1), decimals0, decimals1, feeTier, sqrtPriceX96, tick);
    }

    /// @inheritdoc ITeaVaultV3Pair
    function setFeeConfig(FeeConfig calldata _feeConfig) external override onlyOwner {
        _collectManagementFee();
        _collectAllSwapFee();
        _setFeeConfig(_feeConfig);
    }

    function _setFeeConfig(FeeConfig calldata _feeConfig) internal {
        if (_feeConfig.entryFee + _feeConfig.exitFee > FEE_CAP) revert InvalidFeePercentage();
        if (_feeConfig.performanceFee > FEE_CAP) revert InvalidFeePercentage();
        if (_feeConfig.managementFee > FEE_CAP) revert InvalidFeePercentage();

        feeConfig = _feeConfig;

        emit FeeConfigChanged(msg.sender, block.timestamp, _feeConfig);
    }

    /// @inheritdoc ITeaVaultV3Pair
    function assignManager(address _manager) external override onlyOwner {
        manager = _manager;
        emit ManagerChanged(msg.sender, _manager);
    }

    function assignRouter1Inch(address _router1Inch) external onlyOwner {
        router1Inch = IGenericRouter1Inch(_router1Inch);
    }

    /// @inheritdoc ITeaVaultV3Pair
    function collectManagementFee() external onlyManager returns (uint256 collectedShares) {
        return _collectManagementFee();
    }

    /// @dev mint shares as management fee, based on time since last time collected
    /// @dev must be called every time before totalSupply changed
    function _collectManagementFee() internal returns (uint256 collectedShares) {
        uint256 timeDiff = block.timestamp - lastCollectManagementFee;
        if (timeDiff > 0) {
            unchecked {
                uint256 feeTimesTimediff = feeConfig.managementFee * timeDiff;
                uint256 denominator = (
                    FEE_MULTIPLIER * SECONDS_IN_A_YEAR > feeTimesTimediff?
                        FEE_MULTIPLIER * SECONDS_IN_A_YEAR - feeTimesTimediff:
                        1
                );
                collectedShares = totalSupply().mulDivRoundingUp(feeTimesTimediff, denominator);
            }

            if (collectedShares > 0) {
                _mint(feeConfig.vault, collectedShares);
                emit ManagementFeeCollected(collectedShares);
            }

            lastCollectManagementFee = block.timestamp;
        }
    }

    /// @inheritdoc ITeaVaultV3Pair
    function deposit(
        uint256 _shares,
        uint256 _amount0Max,
        uint256 _amount1Max
    ) external override nonReentrant returns (uint256 depositedAmount0, uint256 depositedAmount1) {
        if (_shares == 0) revert InvalidShareAmount();
        _collectManagementFee();
        uint256 totalShares = totalSupply();

        if (totalShares == 0) {
            // vault is empty, default to 1:1 share to token0 ratio (offseted by _decimalOffset)
            depositedAmount0 = _shares / DECIMALS_MULTIPLIER;
            token0.safeTransferFrom(msg.sender, address(this), depositedAmount0);
        }
        else {
            _collectAllSwapFee();

            uint256 positionLength = positions.length;
            uint256 amount0;
            uint256 amount1;
            uint128 liquidity;
            bytes memory callbackData = abi.encode(msg.sender);

            for (uint256 i; i < positionLength; i++) {
                Position storage position = positions[i];

                liquidity = uint256(position.liquidity).mulDivRoundingUp(_shares, totalShares).toUint128();
                (amount0, amount1) = _addLiquidity(position.tickLower, position.tickUpper, liquidity, callbackData);

                position.liquidity += liquidity;
                depositedAmount0 += amount0;
                depositedAmount1 += amount1;
            }

            amount0 = token0.balanceOf(address(this)).mulDivRoundingUp(_shares, totalShares);
            amount1 = token1.balanceOf(address(this)).mulDivRoundingUp(_shares, totalShares);
            depositedAmount0 += amount0;
            depositedAmount1 += amount1;
            
            token0.safeTransferFrom(msg.sender, address(this), amount0);
            token1.safeTransferFrom(msg.sender, address(this), amount1);
        }

        // make sure a user can't make a zero amount deposit
        if (depositedAmount0 == 0 && depositedAmount1 == 0) revert InvalidShareAmount();

        // collect entry fee for users
        // do not collect entry fee for fee recipient
        uint256 entryFeeAmount0;
        uint256 entryFeeAmount1;

        if (msg.sender != feeConfig.vault) {
            entryFeeAmount0 = depositedAmount0.mulDivRoundingUp(feeConfig.entryFee, FEE_MULTIPLIER);
            entryFeeAmount1 = depositedAmount1.mulDivRoundingUp(feeConfig.entryFee, FEE_MULTIPLIER);

            if (entryFeeAmount0 > 0) {
                token0.safeTransferFrom(msg.sender, feeConfig.vault, entryFeeAmount0);
            }
            
            if (entryFeeAmount1 > 0) {
                token1.safeTransferFrom(msg.sender, feeConfig.vault, entryFeeAmount1);
            }

            depositedAmount0 += entryFeeAmount0;
            depositedAmount1 += entryFeeAmount1;
        }

        // price slippage check
        if (depositedAmount0 > _amount0Max || depositedAmount1 > _amount1Max) revert InvalidPriceSlippage(depositedAmount0, depositedAmount1);
        _mint(msg.sender, _shares);

        emit DepositShares(msg.sender, _shares, depositedAmount0, depositedAmount1, entryFeeAmount0, entryFeeAmount1);
    }

    /// @inheritdoc ITeaVaultV3Pair
    function withdraw(
        uint256 _shares,
        uint256 _amount0Min,
        uint256 _amount1Min
    ) external override nonReentrant returns (uint256 withdrawnAmount0, uint256 withdrawnAmount1) {
        if (_shares == 0) revert InvalidShareAmount();
        _collectManagementFee();
        uint256 totalShares = totalSupply();

        // collect exit fee for users
        // do not collect exit fee for fee recipient
        uint256 exitFeeAmount;
        if (msg.sender != feeConfig.vault) {
            // calculate exit fee
            exitFeeAmount = _shares.mulDivRoundingUp(feeConfig.exitFee, FEE_MULTIPLIER);
            if (exitFeeAmount > 0) {
                _transfer(msg.sender, feeConfig.vault, exitFeeAmount);
            }

            _shares -= exitFeeAmount;
        }

        _burn(msg.sender, _shares);

        uint256 positionLength = positions.length;
        uint256 amount0;
        uint256 amount1;

        // collect all swap fees first
        _collectAllSwapFee();

        // calculate how much percentage of "cash" should be withdrawn
        // need to be done before removing any liquidity positions
        withdrawnAmount0 = token0.balanceOf(address(this)).mulDiv(_shares, totalShares);
        withdrawnAmount1 = token1.balanceOf(address(this)).mulDiv(_shares, totalShares);

        uint256 i;
        for (; i < positionLength; i++) {
            Position storage position = positions[i];
            int24 tickLower = position.tickLower;
            int24 tickUpper = position.tickUpper;
            uint128 liquidity = uint256(position.liquidity).mulDiv(_shares, totalShares).toUint128();

            (amount0, amount1) = _removeLiquidity(tickLower, tickUpper, liquidity);
            _collect(tickLower, tickUpper);
            withdrawnAmount0 += amount0;
            withdrawnAmount1 += amount1;

            position.liquidity -= liquidity;
        }

        // remove position entries with no liquidity
        i = 0;
        while(i < positions.length) {
            if (positions[i].liquidity == 0) {
                positions[i] = positions[positions.length - 1];
                positions.pop();
            }
            else {
                i++;
            }
        }

        // slippage check
        if (withdrawnAmount0 < _amount0Min || withdrawnAmount1 < _amount1Min) revert InvalidPriceSlippage(withdrawnAmount0, withdrawnAmount1);

        token0.safeTransfer(msg.sender, withdrawnAmount0);
        token1.safeTransfer(msg.sender, withdrawnAmount1);

        emit WithdrawShares(msg.sender, _shares, withdrawnAmount0, withdrawnAmount1, exitFeeAmount);
    }

    /// @inheritdoc ITeaVaultV3Pair
    function addLiquidity(
        int24 _tickLower,
        int24 _tickUpper,
        uint128 _liquidity,
        uint256 _amount0Min,
        uint256 _amount1Min,
        uint64 _deadline
    ) external override checkDeadline(_deadline) onlyManager returns (uint256 amount0, uint256 amount1) {
        uint256 positionLength = positions.length;
        uint256 i;

        for (; i < positionLength; i++) {
            Position storage position = positions[i];
            if (position.tickLower == _tickLower && position.tickUpper == _tickUpper) {
                (amount0, amount1) = _addLiquidity(_tickLower, _tickUpper, _liquidity, _amount0Min, _amount1Min);
                position.liquidity += _liquidity;

                return (amount0, amount1);
            }
        }

        if (i == MAX_POSITION_LENGTH) revert PositionLengthExceedsLimit();

        (amount0, amount1) = _addLiquidity(_tickLower, _tickUpper, _liquidity, _amount0Min, _amount1Min);
        positions.push(Position({
            tickLower: _tickLower,
            tickUpper: _tickUpper,
            liquidity: _liquidity
        }));
    }

    /// @inheritdoc ITeaVaultV3Pair
    function removeLiquidity(
        int24 _tickLower,
        int24 _tickUpper,
        uint128 _liquidity,
        uint256 _amount0Min,
        uint256 _amount1Min,
        uint64 _deadline
    ) external checkDeadline(_deadline) onlyManager returns (uint256 amount0, uint256 amount1) {
        uint256 positionLength = positions.length;

        for (uint256 i; i < positionLength; i++) {
            Position storage position = positions[i];
            if (position.tickLower == _tickLower && position.tickUpper == _tickUpper) {
                // collect swap fee before remove liquidity to ensure correct calculation of performance fee
                _collectPositionSwapFee(position);

                (amount0, amount1) = _removeLiquidity(_tickLower, _tickUpper, _liquidity);
                if (amount0 < _amount0Min || amount1 < _amount1Min) revert InvalidPriceSlippage(amount0, amount1);
                _collect(_tickLower, _tickUpper);

                if (position.liquidity == _liquidity) {
                    positions[i] = positions[positionLength - 1];
                    positions.pop();
                }
                else {
                    position.liquidity -= _liquidity;
                }

                return (amount0, amount1);
            }
        }

        revert PositionDoesNotExist();
    }

    /// @inheritdoc ITeaVaultV3Pair
    function collectPositionSwapFee(
        int24 _tickLower,
        int24 _tickUpper
    ) external onlyManager returns (uint128 amount0, uint128 amount1) {
        uint256 positionLength = positions.length;

        for (uint256 i; i < positionLength; i++) {
            Position storage position = positions[i];
            if (position.tickLower == _tickLower && position.tickUpper == _tickUpper) {
                return _collectPositionSwapFee(position);
            }
        }

        revert PositionDoesNotExist();
    }

    function _collectPositionSwapFee(Position storage position) internal returns(uint128 amount0, uint128 amount1) {
        pool.burn(position.tickLower, position.tickUpper, 0);
        (amount0, amount1) =  _collect(position.tickLower, position.tickUpper);

        _collectPerformanceFee(amount0, amount1);
    }

    /// @inheritdoc ITeaVaultV3Pair
    function collectAllSwapFee() external onlyManager returns (uint128 amount0, uint128 amount1) {
        return _collectAllSwapFee();
    }

    function _collectAllSwapFee() internal returns (uint128 amount0, uint128 amount1) {
        uint256 positionLength = positions.length;
        uint128 _amount0;
        uint128 _amount1;

        for (uint256 i; i < positionLength; i++) {
            Position storage position = positions[i];
            pool.burn(position.tickLower, position.tickUpper, 0);
            (_amount0, _amount1) = _collect(position.tickLower, position.tickUpper);
            unchecked {
                amount0 += _amount0;
                amount1 += _amount1;
            }
        }

        _collectPerformanceFee(amount0, amount1);
    }

    function _collectPerformanceFee(uint128 amount0, uint128 amount1) internal {
        uint256 performanceFeeAmount0 = uint256(amount0).mulDivRoundingUp(feeConfig.performanceFee, FEE_MULTIPLIER);
        uint256 performanceFeeAmount1 = uint256(amount1).mulDivRoundingUp(feeConfig.performanceFee, FEE_MULTIPLIER);

        if (performanceFeeAmount0 > 0) {
            token0.safeTransfer(feeConfig.vault, performanceFeeAmount0);
        }

        if (performanceFeeAmount1 > 0) {
            token1.safeTransfer(feeConfig.vault, performanceFeeAmount1);
        }

        emit CollectSwapFees(address(pool), amount0, amount1, performanceFeeAmount0, performanceFeeAmount1);
    }

    function _addLiquidity(
        int24 _tickLower,
        int24 _tickUpper,
        uint128 _liquidity,
        uint256 _amount0Min,
        uint256 _amount1Min
    ) internal returns (uint256 amount0, uint256 amount1) {
        (amount0, amount1) = _addLiquidity(_tickLower, _tickUpper, _liquidity, abi.encode(address(0)));
        if (amount0 < _amount0Min || amount1 < _amount1Min) revert InvalidPriceSlippage(amount0, amount1);
    }

    function _addLiquidity(
        int24 _tickLower,
        int24 _tickUpper,
        uint128 _liquidity,
        bytes memory _callbackData
    ) internal checkLiquidity(_liquidity) returns (uint256 amount0, uint256 amount1) {
        callbackStatus = 2;
        (amount0, amount1) = pool.mint(address(this), _tickLower, _tickUpper, _liquidity, _callbackData);
        callbackStatus = 1;
        
        emit AddLiquidity(address(pool), _tickLower, _tickUpper, _liquidity, amount0, amount1);
    }

    function ramsesV2MintCallback(uint256 _amount0Owed, uint256 _amount1Owed, bytes calldata _data) external {
        if (callbackStatus != 2) revert InvalidCallbackStatus();
        if (address(pool) != msg.sender) revert InvalidCallbackCaller();

        address depositor = abi.decode(_data, (address));

        if (_amount0Owed > 0) {
            depositor == address(0)?
                token0.safeTransfer(msg.sender, _amount0Owed):
                token0.safeTransferFrom(depositor, msg.sender, _amount0Owed);
        }

        if (_amount1Owed > 0) {
            depositor == address(0)?
                token1.safeTransfer(msg.sender, _amount1Owed):
                token1.safeTransferFrom(depositor, msg.sender, _amount1Owed);
        }
    }

    function _removeLiquidity(
        int24 _tickLower,
        int24 _tickUpper,
        uint128 _liquidity
    ) internal checkLiquidity(_liquidity) returns (uint256 amount0, uint256 amount1) {
        (amount0, amount1) = pool.burn(_tickLower, _tickUpper, _liquidity);

        emit RemoveLiquidity(address(pool), _tickLower, _tickUpper, _liquidity, amount0, amount1);
    }

    function _collect(int24 _tickLower, int24 _tickUpper) internal returns (uint128 amount0, uint128 amount1) {
        (amount0, amount1) = pool.collect(address(this), _tickLower, _tickUpper, type(uint128).max, type(uint128).max);

        emit Collect(address(pool), _tickLower, _tickUpper, amount0, amount1);
    }

    /// @inheritdoc ITeaVaultV3Pair
    function swapInputSingle(
        bool _zeroForOne,
        uint256 _amountIn,
        uint256 _amountOutMin,
        uint160 _minPriceInSqrtPriceX96,
        uint64 _deadline
    ) public onlyManager checkDeadline(_deadline) returns (uint256 amountOut) {
        callbackStatus = 2;
        (int256 amount0, int256 amount1) = pool.swap(
            address(this),
            _zeroForOne,
            _amountIn.toInt256(),
            _minPriceInSqrtPriceX96 == 0 
                ? (_zeroForOne ? TickMath.MIN_SQRT_RATIO + 1 : TickMath.MAX_SQRT_RATIO - 1)
                : _minPriceInSqrtPriceX96,
            abi.encode(_zeroForOne)
        );
        callbackStatus = 1;

        amountOut = uint256(-(_zeroForOne ? amount1 : amount0));
        if(amountOut < _amountOutMin) revert InvalidPriceSlippage(amountOut, 0);

        emit Swap(_zeroForOne, true, _amountIn, amountOut);
    }

    /// @inheritdoc ITeaVaultV3Pair
    function swapOutputSingle(
        bool _zeroForOne,
        uint256 _amountOut,
        uint256 _amountInMax,
        uint160 _maxPriceInSqrtPriceX96,
        uint64 _deadline
    ) public onlyManager checkDeadline(_deadline) returns (uint256 amountIn) {
        callbackStatus = 2;
        (int256 amount0Delta, int256 amount1Delta) = pool.swap(
            address(this),
            _zeroForOne,
            -_amountOut.toInt256(),
            _maxPriceInSqrtPriceX96 == 0
                ? (_zeroForOne ? TickMath.MIN_SQRT_RATIO + 1 : TickMath.MAX_SQRT_RATIO - 1)
                : _maxPriceInSqrtPriceX96,
            abi.encode(_zeroForOne)
        );
        callbackStatus = 1;

        uint256 amountOutReceived;
        
        (amountIn, amountOutReceived) = _zeroForOne
            ? (uint256(amount0Delta), uint256(-amount1Delta))
            : (uint256(amount1Delta), uint256(-amount0Delta));

        // it's technically possible to not receive the full output amount,
        // so if no price limit has been specified, require this possibility away
        if (_maxPriceInSqrtPriceX96 == 0 && amountOutReceived != _amountOut) revert InvalidPriceSlippage(amountOutReceived, 0);
        if (amountIn > _amountInMax) revert InvalidPriceSlippage(amountIn, 0);

        emit Swap(_zeroForOne, false, amountIn, _amountOut);
    }

    function ramsesV2SwapCallback(int256 _amount0Delta, int256 _amount1Delta, bytes calldata _data) external {
        if (callbackStatus != 2) revert InvalidCallbackStatus();
        if (address(pool) != msg.sender) revert InvalidCallbackCaller();
        if (_amount0Delta == 0 || _amount1Delta == 0) revert SwapInZeroLiquidityRegion();

        bool zeroForOne = abi.decode(_data, (bool));
        (bool isExactInput, uint256 amountToPay) =
            _amount0Delta > 0
                ? (zeroForOne, uint256(_amount0Delta))
                : (!zeroForOne, uint256(_amount1Delta));

        if (isExactInput == zeroForOne) {
            token0.safeTransfer(msg.sender, amountToPay);
        }
        else {
            token1.safeTransfer(msg.sender, amountToPay);
        }
    }

    /// @inheritdoc ITeaVaultV3Pair
    function multicall(bytes[] calldata data) external returns (bytes[] memory results) {
        results = new bytes[](data.length);
        for (uint256 i; i < data.length; i++) {
            (bool success, bytes memory returndata) = address(this).delegatecall(data[i]);
            results[i] = Address.verifyCallResult(success, returndata);
        }
        return results;
    }

    /// @inheritdoc ITeaVaultV3Pair
    function positionInfo(
        int24 _tickLower,
        int24 _tickUpper
    ) external override view returns (uint256 amount0, uint256 amount1, uint256 fee0, uint256 fee1) {
        uint256 positionsLength = positions.length;
        for (uint256 i; i < positionsLength; i++) {
            Position storage position = positions[i];
            if (position.tickLower == _tickLower && position.tickUpper == _tickUpper) {
                return VaultUtils.positionInfo(address(this), pool, positions[i]);
            }
        }

        revert PositionDoesNotExist();
    }

    /// @inheritdoc ITeaVaultV3Pair
    function positionInfo(
        uint256 _index
    ) external override view returns (uint256 amount0, uint256 amount1, uint256 fee0, uint256 fee1) {
        if (_index >= positions.length) revert PositionDoesNotExist();
        return VaultUtils.positionInfo(address(this), pool, positions[_index]);
    }

    /// @inheritdoc ITeaVaultV3Pair
    function allPositionInfo() public view returns (uint256 amount0, uint256 amount1, uint256 fee0, uint256 fee1) {
        uint256 _amount0;
        uint256 _amount1;
        uint256 _fee0;
        uint256 _fee1;

        uint256 positionsLength = positions.length;
        for (uint256 i; i < positionsLength; i++) {
            (_amount0, _amount1, _fee0, _fee1) = VaultUtils.positionInfo(address(this), pool, positions[i]);
            amount0 += _amount0;
            amount1 += _amount1;
            fee0 += _fee0;
            fee1 += _fee1;
        }
    }

    /// @inheritdoc ITeaVaultV3Pair
    function vaultAllUnderlyingAssets() public override view returns (uint256 amount0, uint256 amount1) {        
        (uint256 _amount0, uint256 _amount1, uint256 _fee0, uint256 _fee1) = allPositionInfo();
        amount0 = _amount0 + _fee0;
        amount1 = _amount1 + _fee1;
        amount0 = amount0 + token0.balanceOf(address(this));
        amount1 = amount1 + token1.balanceOf(address(this));
    }

    /// @inheritdoc ITeaVaultV3Pair
    function estimatedValueInToken0() external override view returns (uint256 value0) {
        (uint256 _amount0, uint256 _amount1) = vaultAllUnderlyingAssets();
        value0 = VaultUtils.estimatedValueInToken0(pool, _amount0, _amount1);
    }

    /// @inheritdoc ITeaVaultV3Pair
    function estimatedValueInToken1() external override view returns (uint256 value1) {
        (uint256 _amount0, uint256 _amount1) = vaultAllUnderlyingAssets();
        value1 = VaultUtils.estimatedValueInToken1(pool, _amount0, _amount1);
    }

    /// @inheritdoc ITeaVaultV3Pair
    function getLiquidityForAmounts(
        int24 tickLower,
        int24 tickUpper,
        uint256 amount0,
        uint256 amount1
    ) external view returns (uint128 liquidity) {
        return VaultUtils.getLiquidityForAmounts(pool, tickLower, tickUpper, amount0, amount1);
    }

    /// @inheritdoc ITeaVaultV3Pair
    function getAmountsForLiquidity(
        int24 tickLower,
        int24 tickUpper,
        uint128 liquidity
    ) external view returns (uint256 amount0, uint256 amount1) {
        return VaultUtils.getAmountsForLiquidity(pool, tickLower, tickUpper, liquidity);
    }

    /// @inheritdoc ITeaVaultV3Pair
    function getAllPositions() external view returns (Position[] memory results) {
        return positions;
    }

    /// @notice swap tokens using 1Inch router via ClipperRouter
    /// @param srcToken Source token
    /// @param dstToken Destination token
    /// @param inputAmount Amount of source tokens to swap
    /// @param outputAmount Amount of destination tokens to receive
    /// @param goodUntil Timestamp until the swap will be valid
    /// @param r Clipper order signature (r part)
    /// @param vs Clipper order signature (vs part)
    /// @return returnAmount Amount of destination tokens received
    function clipperSwap(
        address clipperExchange,
        address srcToken,
        address dstToken,
        uint256 inputAmount,
        uint256 outputAmount,
        uint256 goodUntil,
        bytes32 r,
        bytes32 vs
    ) external nonReentrant onlyManager returns(uint256 returnAmount) {
        if (srcToken != address(token0) && srcToken != address(token1)) {
            revert InvalidSwapToken();
        }

        // simulate using uniswap to find a safe minimum amount
        uint256 minAmount = simulateSwapInputSingle(srcToken == address(token0), inputAmount);
        return GenericRouter1Inch.clipperSwap(
            router1Inch,
            IERC20(token0),
            IERC20(token1),
            minAmount,
            clipperExchange,
            srcToken,
            dstToken,
            inputAmount,
            outputAmount,
            goodUntil,
            r,
            vs
        );
    }

    /// @notice swap tokens using 1Inch router via GenericRouter
    /// @param executor Aggregation executor that executes calls described in `data`
    /// @param desc Swap description
    /// @param permit Should contain valid permit that can be used in `IERC20Permit.permit` calls.
    /// @param data Encoded calls that `caller` should execute in between of swaps
    /// @return returnAmount Resulting token amount
    /// @return spentAmount Source token amount        
    function swap(
        address executor,
        IGenericRouter1Inch.SwapDescription calldata desc,
        bytes calldata permit,
        bytes calldata data
    ) external nonReentrant onlyManager returns (uint256 returnAmount, uint256 spentAmount) {
        if (desc.srcToken != address(token0) && desc.srcToken != address(token1)) {
            revert InvalidSwapToken();
        }

        uint256 minAmount = simulateSwapInputSingle(desc.srcToken == address(token0), desc.amount);
        return GenericRouter1Inch.swap(
            router1Inch,
            IERC20(token0),
            IERC20(token1),
            minAmount,
            executor,
            desc,
            permit,
            data
        );
    }

    /// @notice Swap tokens using 1Inch router via unoswap (for UniswapV2)
    /// @param srcToken Source token
    /// @param amount Amount of source tokens to swap
    /// @param minReturn Minimal allowed returnAmount to make transaction commit
    /// @param pools Pools chain used for swaps. Pools src and dst tokens should match to make swap happen
    function unoswap(
        address srcToken,
        uint256 amount,
        uint256 minReturn,
        uint256[] calldata pools
    ) external nonReentrant onlyManager returns(uint256 returnAmount) {
        if (srcToken != address(token0) && srcToken != address(token1)) {
            revert InvalidSwapToken();
        }

        uint256 minAmount = simulateSwapInputSingle(srcToken == address(token0), amount);
        return GenericRouter1Inch.unoswap(
            router1Inch,
            IERC20(token0),
            IERC20(token1),
            minAmount,
            srcToken,
            amount,
            minReturn,
            pools            
        );
    }

    /// @notice Swap tokens using 1Inch router via UniswapV3
    /// @param amount Amount of source tokens to swap
    /// @param minReturn Minimal allowed returnAmount to make transaction commit
    /// @param pools Pools chain used for swaps. Pools src and dst tokens should match to make swap happen
    function uniswapV3Swap(
        uint256 amount,
        uint256 minReturn,
        uint256[] calldata pools
    ) external nonReentrant onlyManager returns(uint256 returnAmount) {
        uint256 poolData = pools[0];
        bool zeroForOne = poolData & (1 << 255) == 0;
        IUniswapV3Pool swapPool = IUniswapV3Pool(address(uint160(poolData)));

        address srcToken = zeroForOne? swapPool.token0(): swapPool.token1();
        if (srcToken != address(token0) && srcToken != address(token1)) {
            revert InvalidSwapToken();
        }

        // simulate using uniswap
        uint256 minAmount = simulateSwapInputSingle(srcToken == address(token0), amount);
        return GenericRouter1Inch.uniswapV3Swap(
            router1Inch,
            IERC20(token0),
            IERC20(token1),
            srcToken == address(token0),
            minAmount,
            amount,
            minReturn,
            pools
        );
    }

    /// @notice Simulate in-place swap
    /// @param _zeroForOne Swap direction from token0 to token1 or not
    /// @param _amountIn Amount of input token
    /// @return amountOut Output token amount
    function simulateSwapInputSingle(bool _zeroForOne, uint256 _amountIn) internal returns (uint256 amountOut) {
        (bool success, bytes memory returndata) = address(this).delegatecall(
            abi.encodeWithSignature("simulateSwapInputSingleInternal(bool,uint256)", _zeroForOne, _amountIn));
        
        if (success) {
            // shouldn't happen, revert
            revert();
        }
        else {
            if (returndata.length == 0) {
                // no result, revert
                revert();
            }

            amountOut = abi.decode(returndata, (uint256));
        }
    }

    /// @dev Helper function for simulating in-place swap
    /// @dev This function always revert, so there's no point calling it directly
    function simulateSwapInputSingleInternal(bool _zeroForOne, uint256 _amountIn) external onlyManager {
        callbackStatus = 2;
        (bool success, bytes memory returndata) = address(pool).call(
            abi.encodeWithSignature(
                "swap(address,bool,int256,uint160,bytes)",
                address(this),
                _zeroForOne,
                _amountIn.toInt256(),
                _zeroForOne ? TickMath.MIN_SQRT_RATIO + 1 : TickMath.MAX_SQRT_RATIO - 1,
                abi.encode(_zeroForOne)
            )
        );
        callbackStatus = 1;
        
        if (success) {
            (int256 amount0, int256 amount1) = abi.decode(returndata, (int256, int256));
            uint256 amountOut = uint256(-(_zeroForOne ? amount1 : amount0));
            bytes memory data = abi.encode(amountOut);
            assembly {
                revert(add(data, 32), 32)
            }
        }
        else {
            revert();
        }
    }

    function setRewardClaimer(address _rewardClaimer) external onlyOwner {
        if (_rewardClaimer == address(0)) revert ZeroAddress();
        rewardClaimer = _rewardClaimer;

        emit rewardClaimerSet(_rewardClaimer);
    }

    function claimAndForwardReward(INileGauge _gauge, address _to) external onlyRewardClaimer nonReentrant {
        if (_to == address(0)) revert ZeroAddress();
        address[] memory rewardTokens = _gauge.getRewardTokens();

        uint256 positionLength = positions.length;
        for (uint256 i; i < positionLength;) {
            Position storage position = positions[i];
            _gauge.getReward(address(this), 0, position.tickLower, position.tickUpper, rewardTokens, address(this));

            unchecked { i = i + 1; }
        }

        ERC20Upgradeable _token0 = token0;
        ERC20Upgradeable _token1 = token1;
        for (uint256 i; i < rewardTokens.length;) {
            ERC20Upgradeable rewardToken = ERC20Upgradeable(rewardTokens[i]);
            if (rewardToken != _token0 && rewardToken != _token1) {
                uint256 balance = rewardToken.balanceOf(address(this));
                uint256 fee = balance.mulDivRoundingUp(feeConfig.performanceFee, FEE_MULTIPLIER);
                if (balance > fee) {
                    rewardToken.safeTransfer(feeConfig.vault, fee);
                    rewardToken.safeTransfer(_to, balance - fee);
                }
            }

            unchecked { i = i + 1; }
        }

        emit rewardClaimed(_to);
    }

    function setUpLxpL(address _lxpL) external onlyOwner {
        if (_lxpL != address(0)) revert ZeroAddress();
        if (_lxpL == address(token0) || _lxpL == address(token1)) revert InvalidToken();
        if (lxpL != address(0)) revert LxpLAlreadySet();
        X36 = 10 ** 36;
        lxpL = _lxpL;
        _onReceiveRewards();
    }

    function _lxpBalance() internal view returns (uint256) {
        return ERC20Upgradeable(lxpL).balanceOf(address(this));
    }

    function _updateUserData(address _owner, uint256 _oldShares) internal {
        uint256 rewards = (rewardsPerShareX36 - userData[_owner].lastRewardPerShareX36).mulDiv(_oldShares, X36);
        userData[_owner].unclaimedRewards += rewards;
        userData[_owner].lastRewardPerShareX36 = rewardsPerShareX36;
    }

    function claim() external nonReentrant returns (uint256 amount) {
        _onReceiveRewards();
        _updateUserData(msg.sender, balanceOf(msg.sender));
        amount = userData[msg.sender].unclaimedRewards;
        userData[msg.sender].unclaimedRewards = 0;

        if (amount > 0) {
            // lastRewardBalance is updated in _onReceiveRewards()
            ERC20Upgradeable(lxpL).transfer(msg.sender, amount);
            lastRewardBalance = lastRewardBalance - amount;
        }
    }

    function _onReceiveRewards() internal {
        uint256 balance = _lxpBalance();
        if (balance > lastRewardBalance) {
            rewardsPerShareX36 += (balance - lastRewardBalance).mulDiv(X36, totalSupply());
            lastRewardBalance = balance;
        }
    }

    function _update(address from, address to, uint256 value) internal override {
        // X36 will be initialized to 10 ** 36 in setUpLxpL()
        if (X36 != 0) {
            _onReceiveRewards();
            if (from != address(0)) {
                _updateUserData(from, balanceOf(from));
            }
            if (to != address(0)) {
                _updateUserData(to, balanceOf(to));
            }
        }

        super._update(from, to, value);
    }

    // modifiers

    /**
     * @dev Throws if called by any account other than the manager.
     */
    modifier onlyManager() {
        if (msg.sender != manager) revert CallerIsNotManager();
        _;
    }

    modifier onlyRewardClaimer() {
        if (msg.sender != rewardClaimer) revert CallerIsNotRewardClaimer();
        _;
    }

    modifier checkLiquidity(uint128 _liquidity) {
        if (_liquidity == 0) revert ZeroLiquidity();
        _;
    }

    modifier checkDeadline(uint256 _deadline) {
        if (block.timestamp > _deadline) revert TransactionExpired();
        _;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../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.
 *
 * The initial owner is set to the address provided by the deployer. 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 {
    /// @custom:storage-location erc7201:openzeppelin.storage.Ownable
    struct OwnableStorage {
        address _owner;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant OwnableStorageLocation = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300;

    function _getOwnableStorage() private pure returns (OwnableStorage storage $) {
        assembly {
            $.slot := OwnableStorageLocation
        }
    }

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

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

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

    function __Ownable_init_unchained(address initialOwner) internal onlyInitializing {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling 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 {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

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

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

pragma solidity ^0.8.20;

/**
 * @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]
 * ```solidity
 * 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 Storage of the initializable contract.
     *
     * It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
     * when using with upgradeable contracts.
     *
     * @custom:storage-location erc7201:openzeppelin.storage.Initializable
     */
    struct InitializableStorage {
        /**
         * @dev Indicates that the contract has been initialized.
         */
        uint64 _initialized;
        /**
         * @dev Indicates that the contract is in the process of being initialized.
         */
        bool _initializing;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;

    /**
     * @dev The contract is already initialized.
     */
    error InvalidInitialization();

    /**
     * @dev The contract is not initializing.
     */
    error NotInitializing();

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint64 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.
     *
     * Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
     * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
     * production.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        // Cache values to avoid duplicated sloads
        bool isTopLevelCall = !$._initializing;
        uint64 initialized = $._initialized;

        // Allowed calls:
        // - initialSetup: the contract is not in the initializing state and no previous version was
        //                 initialized
        // - construction: the contract is initialized at version 1 (no reininitialization) and the
        //                 current contract is just being deployed
        bool initialSetup = initialized == 0 && isTopLevelCall;
        bool construction = initialized == 1 && address(this).code.length == 0;

        if (!initialSetup && !construction) {
            revert InvalidInitialization();
        }
        $._initialized = 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.
     *
     * 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.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * 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.
     *
     * WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint64 version) {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing || $._initialized >= version) {
            revert InvalidInitialization();
        }
        $._initialized = version;
        $._initializing = true;
        _;
        $._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() {
        _checkInitializing();
        _;
    }

    /**
     * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
     */
    function _checkInitializing() internal view virtual {
        if (!_isInitializing()) {
            revert NotInitializing();
        }
    }

    /**
     * @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.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing) {
            revert InvalidInitialization();
        }
        if ($._initialized != type(uint64).max) {
            $._initialized = type(uint64).max;
            emit Initialized(type(uint64).max);
        }
    }

    /**
     * @dev Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint64) {
        return _getInitializableStorage()._initialized;
    }

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _getInitializableStorage()._initializing;
    }

    /**
     * @dev Returns a pointer to the storage namespace.
     */
    // solhint-disable-next-line var-name-mixedcase
    function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
        assembly {
            $.slot := INITIALIZABLE_STORAGE
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/UUPSUpgradeable.sol)

pragma solidity ^0.8.20;

import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {Initializable} from "./Initializable.sol";

/**
 * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
 * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
 *
 * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
 * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
 * `UUPSUpgradeable` with a custom implementation of upgrades.
 *
 * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
 */
abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable {
    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
    address private immutable __self = address(this);

    /**
     * @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`
     * and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
     * while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.
     * If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must
     * be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
     * during an upgrade.
     */
    string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";

    /**
     * @dev The call is from an unauthorized context.
     */
    error UUPSUnauthorizedCallContext();

    /**
     * @dev The storage `slot` is unsupported as a UUID.
     */
    error UUPSUnsupportedProxiableUUID(bytes32 slot);

    /**
     * @dev Check that the execution is being performed through a delegatecall call and that the execution context is
     * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
     * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
     * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
     * fail.
     */
    modifier onlyProxy() {
        _checkProxy();
        _;
    }

    /**
     * @dev Check that the execution is not being performed through a delegate call. This allows a function to be
     * callable on the implementing contract but not through proxies.
     */
    modifier notDelegated() {
        _checkNotDelegated();
        _;
    }

    function __UUPSUpgradeable_init() internal onlyInitializing {
    }

    function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
     * implementation. It is used to validate the implementation's compatibility when performing an upgrade.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
     */
    function proxiableUUID() external view virtual notDelegated returns (bytes32) {
        return ERC1967Utils.IMPLEMENTATION_SLOT;
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
     * encoded in `data`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     *
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, data);
    }

    /**
     * @dev Reverts if the execution is not performed via delegatecall or the execution
     * context is not of a proxy with an ERC1967-compliant implementation pointing to self.
     * See {_onlyProxy}.
     */
    function _checkProxy() internal view virtual {
        if (
            address(this) == __self || // Must be called through delegatecall
            ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
        ) {
            revert UUPSUnauthorizedCallContext();
        }
    }

    /**
     * @dev Reverts if the execution is performed via delegatecall.
     * See {notDelegated}.
     */
    function _checkNotDelegated() internal view virtual {
        if (address(this) != __self) {
            // Must not be called through delegatecall
            revert UUPSUnauthorizedCallContext();
        }
    }

    /**
     * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
     * {upgradeToAndCall}.
     *
     * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
     *
     * ```solidity
     * function _authorizeUpgrade(address) internal onlyOwner {}
     * ```
     */
    function _authorizeUpgrade(address newImplementation) internal virtual;

    /**
     * @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.
     *
     * As a security check, {proxiableUUID} is invoked in the new implementation, and the return value
     * is expected to be the implementation slot in ERC1967.
     *
     * Emits an {IERC1967-Upgraded} event.
     */
    function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {
        try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
            if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
                revert UUPSUnsupportedProxiableUUID(slot);
            }
            ERC1967Utils.upgradeToAndCall(newImplementation, data);
        } catch {
            // The implementation is not UUPS
            revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
        }
    }
}

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

pragma solidity ^0.8.20;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {ContextUpgradeable} from "../../utils/ContextUpgradeable.sol";
import {IERC20Errors} from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
import {Initializable} from "../../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}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * 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.
 */
abstract contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20, IERC20Metadata, IERC20Errors {
    /// @custom:storage-location erc7201:openzeppelin.storage.ERC20
    struct ERC20Storage {
        mapping(address account => uint256) _balances;

        mapping(address account => mapping(address spender => uint256)) _allowances;

        uint256 _totalSupply;

        string _name;
        string _symbol;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ERC20")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant ERC20StorageLocation = 0x52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace00;

    function _getERC20Storage() private pure returns (ERC20Storage storage $) {
        assembly {
            $.slot := ERC20StorageLocation
        }
    }

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * 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 {
        ERC20Storage storage $ = _getERC20Storage();
        $._name = name_;
        $._symbol = symbol_;
    }

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

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual returns (string memory) {
        ERC20Storage storage $ = _getERC20Storage();
        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 default value returned by this function, unless
     * it's 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 returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual returns (uint256) {
        ERC20Storage storage $ = _getERC20Storage();
        return $._totalSupply;
    }

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

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

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

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `value` 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 value) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, value);
        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 `value`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `value`.
     */
    function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, value);
        _transfer(from, to, value);
        return true;
    }

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to`.
     *
     * 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.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _transfer(address from, address to, uint256 value) internal {
        if (from == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        if (to == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(from, to, value);
    }

    /**
     * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
     * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
     * this function.
     *
     * Emits a {Transfer} event.
     */
    function _update(address from, address to, uint256 value) internal virtual {
        ERC20Storage storage $ = _getERC20Storage();
        if (from == address(0)) {
            // Overflow check required: The rest of the code assumes that totalSupply never overflows
            $._totalSupply += value;
        } else {
            uint256 fromBalance = $._balances[from];
            if (fromBalance < value) {
                revert ERC20InsufficientBalance(from, fromBalance, value);
            }
            unchecked {
                // Overflow not possible: value <= fromBalance <= totalSupply.
                $._balances[from] = fromBalance - value;
            }
        }

        if (to == address(0)) {
            unchecked {
                // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
                $._totalSupply -= value;
            }
        } else {
            unchecked {
                // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
                $._balances[to] += value;
            }
        }

        emit Transfer(from, to, value);
    }

    /**
     * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
     * Relies on the `_update` mechanism
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _mint(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(address(0), account, value);
    }

    /**
     * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
     * Relies on the `_update` mechanism.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead
     */
    function _burn(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        _update(account, address(0), value);
    }

    /**
     * @dev Sets `value` 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.
     *
     * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
     */
    function _approve(address owner, address spender, uint256 value) internal {
        _approve(owner, spender, value, true);
    }

    /**
     * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
     *
     * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
     * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
     * `Approval` event during `transferFrom` operations.
     *
     * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
     * true using the following override:
     * ```
     * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
     *     super._approve(owner, spender, value, true);
     * }
     * ```
     *
     * Requirements are the same as {_approve}.
     */
    function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
        ERC20Storage storage $ = _getERC20Storage();
        if (owner == address(0)) {
            revert ERC20InvalidApprover(address(0));
        }
        if (spender == address(0)) {
            revert ERC20InvalidSpender(address(0));
        }
        $._allowances[owner][spender] = value;
        if (emitEvent) {
            emit Approval(owner, spender, value);
        }
    }

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;
import {Initializable} from "../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;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;
import {Initializable} from "../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;

    /// @custom:storage-location erc7201:openzeppelin.storage.ReentrancyGuard
    struct ReentrancyGuardStorage {
        uint256 _status;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant ReentrancyGuardStorageLocation = 0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;

    function _getReentrancyGuardStorage() private pure returns (ReentrancyGuardStorage storage $) {
        assembly {
            $.slot := ReentrancyGuardStorageLocation
        }
    }

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

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

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        $._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() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if ($._status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

        // Any calls to nonReentrant after this point will fail
        $._status = ENTERED;
    }

    function _nonReentrantAfter() private {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        $._status = NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        return $._status == ENTERED;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC1822.sol)

pragma solidity ^0.8.20;

/**
 * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
 * proxy whose upgrades are fully controlled by the current implementation.
 */
interface IERC1822Proxiable {
    /**
     * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
     * address.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy.
     */
    function proxiableUUID() external view returns (bytes32);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;

/**
 * @dev Standard ERC20 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
 */
interface IERC20Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC20InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC20InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     * @param allowance Amount of tokens a `spender` is allowed to operate with.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC20InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `spender` to be approved. Used in approvals.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC20InvalidSpender(address spender);
}

/**
 * @dev Standard ERC721 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
 */
interface IERC721Errors {
    /**
     * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
     * Used in balance queries.
     * @param owner Address of the current owner of a token.
     */
    error ERC721InvalidOwner(address owner);

    /**
     * @dev Indicates a `tokenId` whose `owner` is the zero address.
     * @param tokenId Identifier number of a token.
     */
    error ERC721NonexistentToken(uint256 tokenId);

    /**
     * @dev Indicates an error related to the ownership over a particular token. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param tokenId Identifier number of a token.
     * @param owner Address of the current owner of a token.
     */
    error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC721InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC721InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param tokenId Identifier number of a token.
     */
    error ERC721InsufficientApproval(address operator, uint256 tokenId);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC721InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC721InvalidOperator(address operator);
}

/**
 * @dev Standard ERC1155 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.
 */
interface IERC1155Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     * @param tokenId Identifier number of a token.
     */
    error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC1155InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC1155InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param owner Address of the current owner of a token.
     */
    error ERC1155MissingApprovalForAll(address operator, address owner);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC1155InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC1155InvalidOperator(address operator);

    /**
     * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
     * Used in batch transfers.
     * @param idsLength Length of the array of token identifiers
     * @param valuesLength Length of the array of token amounts
     */
    error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/beacon/IBeacon.sol)

pragma solidity ^0.8.20;

/**
 * @dev This is the interface that {BeaconProxy} expects of its beacon.
 */
interface IBeacon {
    /**
     * @dev Must return an address that can be used as a delegate call target.
     *
     * {UpgradeableBeacon} will check that this address is a contract.
     */
    function implementation() external view returns (address);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/ERC1967/ERC1967Utils.sol)

pragma solidity ^0.8.20;

import {IBeacon} from "../beacon/IBeacon.sol";
import {Address} from "../../utils/Address.sol";
import {StorageSlot} from "../../utils/StorageSlot.sol";

/**
 * @dev This abstract contract provides getters and event emitting update functions for
 * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
 */
library ERC1967Utils {
    // We re-declare ERC-1967 events here because they can't be used directly from IERC1967.
    // This will be fixed in Solidity 0.8.21. At that point we should remove these events.
    /**
     * @dev Emitted when the implementation is upgraded.
     */
    event Upgraded(address indexed implementation);

    /**
     * @dev Emitted when the admin account has changed.
     */
    event AdminChanged(address previousAdmin, address newAdmin);

    /**
     * @dev Emitted when the beacon is changed.
     */
    event BeaconUpgraded(address indexed beacon);

    /**
     * @dev Storage slot with the address of the current implementation.
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    /**
     * @dev The `implementation` of the proxy is invalid.
     */
    error ERC1967InvalidImplementation(address implementation);

    /**
     * @dev The `admin` of the proxy is invalid.
     */
    error ERC1967InvalidAdmin(address admin);

    /**
     * @dev The `beacon` of the proxy is invalid.
     */
    error ERC1967InvalidBeacon(address beacon);

    /**
     * @dev An upgrade function sees `msg.value > 0` that may be lost.
     */
    error ERC1967NonPayable();

    /**
     * @dev Returns the current implementation address.
     */
    function getImplementation() internal view returns (address) {
        return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 implementation slot.
     */
    function _setImplementation(address newImplementation) private {
        if (newImplementation.code.length == 0) {
            revert ERC1967InvalidImplementation(newImplementation);
        }
        StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
    }

    /**
     * @dev Performs implementation upgrade with additional setup call if data is nonempty.
     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
     * to avoid stuck value in the contract.
     *
     * Emits an {IERC1967-Upgraded} event.
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) internal {
        _setImplementation(newImplementation);
        emit Upgraded(newImplementation);

        if (data.length > 0) {
            Address.functionDelegateCall(newImplementation, data);
        } else {
            _checkNonPayable();
        }
    }

    /**
     * @dev Storage slot with the admin of the contract.
     * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    /**
     * @dev Returns the current admin.
     *
     * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using
     * the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
     * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
     */
    function getAdmin() internal view returns (address) {
        return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 admin slot.
     */
    function _setAdmin(address newAdmin) private {
        if (newAdmin == address(0)) {
            revert ERC1967InvalidAdmin(address(0));
        }
        StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
    }

    /**
     * @dev Changes the admin of the proxy.
     *
     * Emits an {IERC1967-AdminChanged} event.
     */
    function changeAdmin(address newAdmin) internal {
        emit AdminChanged(getAdmin(), newAdmin);
        _setAdmin(newAdmin);
    }

    /**
     * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
     * This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;

    /**
     * @dev Returns the current beacon.
     */
    function getBeacon() internal view returns (address) {
        return StorageSlot.getAddressSlot(BEACON_SLOT).value;
    }

    /**
     * @dev Stores a new beacon in the EIP1967 beacon slot.
     */
    function _setBeacon(address newBeacon) private {
        if (newBeacon.code.length == 0) {
            revert ERC1967InvalidBeacon(newBeacon);
        }

        StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;

        address beaconImplementation = IBeacon(newBeacon).implementation();
        if (beaconImplementation.code.length == 0) {
            revert ERC1967InvalidImplementation(beaconImplementation);
        }
    }

    /**
     * @dev Change the beacon and trigger a setup call if data is nonempty.
     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
     * to avoid stuck value in the contract.
     *
     * Emits an {IERC1967-BeaconUpgraded} event.
     *
     * CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
     * it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
     * efficiency.
     */
    function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
        _setBeacon(newBeacon);
        emit BeaconUpgraded(newBeacon);

        if (data.length > 0) {
            Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
        } else {
            _checkNonPayable();
        }
    }

    /**
     * @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
     * if an upgrade doesn't perform an initialization call.
     */
    function _checkNonPayable() private {
        if (msg.value > 0) {
            revert ERC1967NonPayable();
        }
    }
}

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

pragma solidity ^0.8.20;

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

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

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

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

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

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * CAUTION: See Security Considerations above.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

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

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

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

pragma solidity ^0.8.20;

/**
 * @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 value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

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

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

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

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

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../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;

    /**
     * @dev An operation with an ERC20 token failed.
     */
    error SafeERC20FailedOperation(address token);

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

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

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

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

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

    /**
     * @dev 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);
        if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // 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 cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
    }
}

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

pragma solidity ^0.8.20;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error AddressInsufficientBalance(address account);

    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @dev A call to an address target failed. The target may have reverted.
     */
    error FailedInnerCall();

    /**
     * @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://consensys.net/diligence/blog/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.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        if (address(this).balance < amount) {
            revert AddressInsufficientBalance(address(this));
        }

        (bool success, ) = recipient.call{value: amount}("");
        if (!success) {
            revert FailedInnerCall();
        }
    }

    /**
     * @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 or custom error, it is bubbled
     * up by this function (like regular Solidity function calls). However, if
     * the call reverted with no returned reason, this function reverts with a
     * {FailedInnerCall} error.
     *
     * 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.
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0);
    }

    /**
     * @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`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert AddressInsufficientBalance(address(this));
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
     * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
     * unsuccessful call.
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata
    ) internal view returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            // only check if target is a contract if the call was successful and the return data is empty
            // otherwise we already know that it was a contract
            if (returndata.length == 0 && target.code.length == 0) {
                revert AddressEmptyCode(target);
            }
            return returndata;
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
     * revert reason or with a default {FailedInnerCall} error.
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            return returndata;
        }
    }

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) private pure {
        // 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
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert FailedInnerCall();
        }
    }
}

File 17 of 32 : SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.

pragma solidity ^0.8.20;

/**
 * @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.
 */
library SafeCast {
    /**
     * @dev Value doesn't fit in an uint of `bits` size.
     */
    error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);

    /**
     * @dev An int value doesn't fit in an uint of `bits` size.
     */
    error SafeCastOverflowedIntToUint(int256 value);

    /**
     * @dev Value doesn't fit in an int of `bits` size.
     */
    error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);

    /**
     * @dev An uint value doesn't fit in an int of `bits` size.
     */
    error SafeCastOverflowedUintToInt(uint256 value);

    /**
     * @dev Returns the downcasted uint248 from uint256, reverting on
     * overflow (when the input is greater than largest uint248).
     *
     * Counterpart to Solidity's `uint248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        if (value > type(uint248).max) {
            revert SafeCastOverflowedUintDowncast(248, value);
        }
        return uint248(value);
    }

    /**
     * @dev Returns the downcasted uint240 from uint256, reverting on
     * overflow (when the input is greater than largest uint240).
     *
     * Counterpart to Solidity's `uint240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        if (value > type(uint240).max) {
            revert SafeCastOverflowedUintDowncast(240, value);
        }
        return uint240(value);
    }

    /**
     * @dev Returns the downcasted uint232 from uint256, reverting on
     * overflow (when the input is greater than largest uint232).
     *
     * Counterpart to Solidity's `uint232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        if (value > type(uint232).max) {
            revert SafeCastOverflowedUintDowncast(232, value);
        }
        return uint232(value);
    }

    /**
     * @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) {
        if (value > type(uint224).max) {
            revert SafeCastOverflowedUintDowncast(224, value);
        }
        return uint224(value);
    }

    /**
     * @dev Returns the downcasted uint216 from uint256, reverting on
     * overflow (when the input is greater than largest uint216).
     *
     * Counterpart to Solidity's `uint216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        if (value > type(uint216).max) {
            revert SafeCastOverflowedUintDowncast(216, value);
        }
        return uint216(value);
    }

    /**
     * @dev Returns the downcasted uint208 from uint256, reverting on
     * overflow (when the input is greater than largest uint208).
     *
     * Counterpart to Solidity's `uint208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        if (value > type(uint208).max) {
            revert SafeCastOverflowedUintDowncast(208, value);
        }
        return uint208(value);
    }

    /**
     * @dev Returns the downcasted uint200 from uint256, reverting on
     * overflow (when the input is greater than largest uint200).
     *
     * Counterpart to Solidity's `uint200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        if (value > type(uint200).max) {
            revert SafeCastOverflowedUintDowncast(200, value);
        }
        return uint200(value);
    }

    /**
     * @dev Returns the downcasted uint192 from uint256, reverting on
     * overflow (when the input is greater than largest uint192).
     *
     * Counterpart to Solidity's `uint192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        if (value > type(uint192).max) {
            revert SafeCastOverflowedUintDowncast(192, value);
        }
        return uint192(value);
    }

    /**
     * @dev Returns the downcasted uint184 from uint256, reverting on
     * overflow (when the input is greater than largest uint184).
     *
     * Counterpart to Solidity's `uint184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        if (value > type(uint184).max) {
            revert SafeCastOverflowedUintDowncast(184, value);
        }
        return uint184(value);
    }

    /**
     * @dev Returns the downcasted uint176 from uint256, reverting on
     * overflow (when the input is greater than largest uint176).
     *
     * Counterpart to Solidity's `uint176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        if (value > type(uint176).max) {
            revert SafeCastOverflowedUintDowncast(176, value);
        }
        return uint176(value);
    }

    /**
     * @dev Returns the downcasted uint168 from uint256, reverting on
     * overflow (when the input is greater than largest uint168).
     *
     * Counterpart to Solidity's `uint168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        if (value > type(uint168).max) {
            revert SafeCastOverflowedUintDowncast(168, value);
        }
        return uint168(value);
    }

    /**
     * @dev Returns the downcasted uint160 from uint256, reverting on
     * overflow (when the input is greater than largest uint160).
     *
     * Counterpart to Solidity's `uint160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        if (value > type(uint160).max) {
            revert SafeCastOverflowedUintDowncast(160, value);
        }
        return uint160(value);
    }

    /**
     * @dev Returns the downcasted uint152 from uint256, reverting on
     * overflow (when the input is greater than largest uint152).
     *
     * Counterpart to Solidity's `uint152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        if (value > type(uint152).max) {
            revert SafeCastOverflowedUintDowncast(152, value);
        }
        return uint152(value);
    }

    /**
     * @dev Returns the downcasted uint144 from uint256, reverting on
     * overflow (when the input is greater than largest uint144).
     *
     * Counterpart to Solidity's `uint144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        if (value > type(uint144).max) {
            revert SafeCastOverflowedUintDowncast(144, value);
        }
        return uint144(value);
    }

    /**
     * @dev Returns the downcasted uint136 from uint256, reverting on
     * overflow (when the input is greater than largest uint136).
     *
     * Counterpart to Solidity's `uint136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        if (value > type(uint136).max) {
            revert SafeCastOverflowedUintDowncast(136, value);
        }
        return uint136(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) {
        if (value > type(uint128).max) {
            revert SafeCastOverflowedUintDowncast(128, value);
        }
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint120 from uint256, reverting on
     * overflow (when the input is greater than largest uint120).
     *
     * Counterpart to Solidity's `uint120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        if (value > type(uint120).max) {
            revert SafeCastOverflowedUintDowncast(120, value);
        }
        return uint120(value);
    }

    /**
     * @dev Returns the downcasted uint112 from uint256, reverting on
     * overflow (when the input is greater than largest uint112).
     *
     * Counterpart to Solidity's `uint112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        if (value > type(uint112).max) {
            revert SafeCastOverflowedUintDowncast(112, value);
        }
        return uint112(value);
    }

    /**
     * @dev Returns the downcasted uint104 from uint256, reverting on
     * overflow (when the input is greater than largest uint104).
     *
     * Counterpart to Solidity's `uint104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        if (value > type(uint104).max) {
            revert SafeCastOverflowedUintDowncast(104, value);
        }
        return uint104(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) {
        if (value > type(uint96).max) {
            revert SafeCastOverflowedUintDowncast(96, value);
        }
        return uint96(value);
    }

    /**
     * @dev Returns the downcasted uint88 from uint256, reverting on
     * overflow (when the input is greater than largest uint88).
     *
     * Counterpart to Solidity's `uint88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        if (value > type(uint88).max) {
            revert SafeCastOverflowedUintDowncast(88, value);
        }
        return uint88(value);
    }

    /**
     * @dev Returns the downcasted uint80 from uint256, reverting on
     * overflow (when the input is greater than largest uint80).
     *
     * Counterpart to Solidity's `uint80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        if (value > type(uint80).max) {
            revert SafeCastOverflowedUintDowncast(80, value);
        }
        return uint80(value);
    }

    /**
     * @dev Returns the downcasted uint72 from uint256, reverting on
     * overflow (when the input is greater than largest uint72).
     *
     * Counterpart to Solidity's `uint72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        if (value > type(uint72).max) {
            revert SafeCastOverflowedUintDowncast(72, value);
        }
        return uint72(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) {
        if (value > type(uint64).max) {
            revert SafeCastOverflowedUintDowncast(64, value);
        }
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint56 from uint256, reverting on
     * overflow (when the input is greater than largest uint56).
     *
     * Counterpart to Solidity's `uint56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        if (value > type(uint56).max) {
            revert SafeCastOverflowedUintDowncast(56, value);
        }
        return uint56(value);
    }

    /**
     * @dev Returns the downcasted uint48 from uint256, reverting on
     * overflow (when the input is greater than largest uint48).
     *
     * Counterpart to Solidity's `uint48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        if (value > type(uint48).max) {
            revert SafeCastOverflowedUintDowncast(48, value);
        }
        return uint48(value);
    }

    /**
     * @dev Returns the downcasted uint40 from uint256, reverting on
     * overflow (when the input is greater than largest uint40).
     *
     * Counterpart to Solidity's `uint40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        if (value > type(uint40).max) {
            revert SafeCastOverflowedUintDowncast(40, value);
        }
        return uint40(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) {
        if (value > type(uint32).max) {
            revert SafeCastOverflowedUintDowncast(32, value);
        }
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint24 from uint256, reverting on
     * overflow (when the input is greater than largest uint24).
     *
     * Counterpart to Solidity's `uint24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        if (value > type(uint24).max) {
            revert SafeCastOverflowedUintDowncast(24, value);
        }
        return uint24(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) {
        if (value > type(uint16).max) {
            revert SafeCastOverflowedUintDowncast(16, value);
        }
        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) {
        if (value > type(uint8).max) {
            revert SafeCastOverflowedUintDowncast(8, value);
        }
        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) {
        if (value < 0) {
            revert SafeCastOverflowedIntToUint(value);
        }
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int248 from int256, reverting on
     * overflow (when the input is less than smallest int248 or
     * greater than largest int248).
     *
     * Counterpart to Solidity's `int248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     */
    function toInt248(int256 value) internal pure returns (int248 downcasted) {
        downcasted = int248(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(248, value);
        }
    }

    /**
     * @dev Returns the downcasted int240 from int256, reverting on
     * overflow (when the input is less than smallest int240 or
     * greater than largest int240).
     *
     * Counterpart to Solidity's `int240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     */
    function toInt240(int256 value) internal pure returns (int240 downcasted) {
        downcasted = int240(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(240, value);
        }
    }

    /**
     * @dev Returns the downcasted int232 from int256, reverting on
     * overflow (when the input is less than smallest int232 or
     * greater than largest int232).
     *
     * Counterpart to Solidity's `int232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     */
    function toInt232(int256 value) internal pure returns (int232 downcasted) {
        downcasted = int232(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(232, value);
        }
    }

    /**
     * @dev Returns the downcasted int224 from int256, reverting on
     * overflow (when the input is less than smallest int224 or
     * greater than largest int224).
     *
     * Counterpart to Solidity's `int224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     */
    function toInt224(int256 value) internal pure returns (int224 downcasted) {
        downcasted = int224(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(224, value);
        }
    }

    /**
     * @dev Returns the downcasted int216 from int256, reverting on
     * overflow (when the input is less than smallest int216 or
     * greater than largest int216).
     *
     * Counterpart to Solidity's `int216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     */
    function toInt216(int256 value) internal pure returns (int216 downcasted) {
        downcasted = int216(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(216, value);
        }
    }

    /**
     * @dev Returns the downcasted int208 from int256, reverting on
     * overflow (when the input is less than smallest int208 or
     * greater than largest int208).
     *
     * Counterpart to Solidity's `int208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     */
    function toInt208(int256 value) internal pure returns (int208 downcasted) {
        downcasted = int208(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(208, value);
        }
    }

    /**
     * @dev Returns the downcasted int200 from int256, reverting on
     * overflow (when the input is less than smallest int200 or
     * greater than largest int200).
     *
     * Counterpart to Solidity's `int200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     */
    function toInt200(int256 value) internal pure returns (int200 downcasted) {
        downcasted = int200(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(200, value);
        }
    }

    /**
     * @dev Returns the downcasted int192 from int256, reverting on
     * overflow (when the input is less than smallest int192 or
     * greater than largest int192).
     *
     * Counterpart to Solidity's `int192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     */
    function toInt192(int256 value) internal pure returns (int192 downcasted) {
        downcasted = int192(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(192, value);
        }
    }

    /**
     * @dev Returns the downcasted int184 from int256, reverting on
     * overflow (when the input is less than smallest int184 or
     * greater than largest int184).
     *
     * Counterpart to Solidity's `int184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     */
    function toInt184(int256 value) internal pure returns (int184 downcasted) {
        downcasted = int184(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(184, value);
        }
    }

    /**
     * @dev Returns the downcasted int176 from int256, reverting on
     * overflow (when the input is less than smallest int176 or
     * greater than largest int176).
     *
     * Counterpart to Solidity's `int176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     */
    function toInt176(int256 value) internal pure returns (int176 downcasted) {
        downcasted = int176(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(176, value);
        }
    }

    /**
     * @dev Returns the downcasted int168 from int256, reverting on
     * overflow (when the input is less than smallest int168 or
     * greater than largest int168).
     *
     * Counterpart to Solidity's `int168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     */
    function toInt168(int256 value) internal pure returns (int168 downcasted) {
        downcasted = int168(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(168, value);
        }
    }

    /**
     * @dev Returns the downcasted int160 from int256, reverting on
     * overflow (when the input is less than smallest int160 or
     * greater than largest int160).
     *
     * Counterpart to Solidity's `int160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     */
    function toInt160(int256 value) internal pure returns (int160 downcasted) {
        downcasted = int160(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(160, value);
        }
    }

    /**
     * @dev Returns the downcasted int152 from int256, reverting on
     * overflow (when the input is less than smallest int152 or
     * greater than largest int152).
     *
     * Counterpart to Solidity's `int152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     */
    function toInt152(int256 value) internal pure returns (int152 downcasted) {
        downcasted = int152(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(152, value);
        }
    }

    /**
     * @dev Returns the downcasted int144 from int256, reverting on
     * overflow (when the input is less than smallest int144 or
     * greater than largest int144).
     *
     * Counterpart to Solidity's `int144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     */
    function toInt144(int256 value) internal pure returns (int144 downcasted) {
        downcasted = int144(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(144, value);
        }
    }

    /**
     * @dev Returns the downcasted int136 from int256, reverting on
     * overflow (when the input is less than smallest int136 or
     * greater than largest int136).
     *
     * Counterpart to Solidity's `int136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     */
    function toInt136(int256 value) internal pure returns (int136 downcasted) {
        downcasted = int136(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(136, 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
     */
    function toInt128(int256 value) internal pure returns (int128 downcasted) {
        downcasted = int128(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(128, value);
        }
    }

    /**
     * @dev Returns the downcasted int120 from int256, reverting on
     * overflow (when the input is less than smallest int120 or
     * greater than largest int120).
     *
     * Counterpart to Solidity's `int120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     */
    function toInt120(int256 value) internal pure returns (int120 downcasted) {
        downcasted = int120(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(120, value);
        }
    }

    /**
     * @dev Returns the downcasted int112 from int256, reverting on
     * overflow (when the input is less than smallest int112 or
     * greater than largest int112).
     *
     * Counterpart to Solidity's `int112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     */
    function toInt112(int256 value) internal pure returns (int112 downcasted) {
        downcasted = int112(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(112, value);
        }
    }

    /**
     * @dev Returns the downcasted int104 from int256, reverting on
     * overflow (when the input is less than smallest int104 or
     * greater than largest int104).
     *
     * Counterpart to Solidity's `int104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     */
    function toInt104(int256 value) internal pure returns (int104 downcasted) {
        downcasted = int104(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(104, value);
        }
    }

    /**
     * @dev Returns the downcasted int96 from int256, reverting on
     * overflow (when the input is less than smallest int96 or
     * greater than largest int96).
     *
     * Counterpart to Solidity's `int96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     */
    function toInt96(int256 value) internal pure returns (int96 downcasted) {
        downcasted = int96(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(96, value);
        }
    }

    /**
     * @dev Returns the downcasted int88 from int256, reverting on
     * overflow (when the input is less than smallest int88 or
     * greater than largest int88).
     *
     * Counterpart to Solidity's `int88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     */
    function toInt88(int256 value) internal pure returns (int88 downcasted) {
        downcasted = int88(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(88, value);
        }
    }

    /**
     * @dev Returns the downcasted int80 from int256, reverting on
     * overflow (when the input is less than smallest int80 or
     * greater than largest int80).
     *
     * Counterpart to Solidity's `int80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     */
    function toInt80(int256 value) internal pure returns (int80 downcasted) {
        downcasted = int80(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(80, value);
        }
    }

    /**
     * @dev Returns the downcasted int72 from int256, reverting on
     * overflow (when the input is less than smallest int72 or
     * greater than largest int72).
     *
     * Counterpart to Solidity's `int72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     */
    function toInt72(int256 value) internal pure returns (int72 downcasted) {
        downcasted = int72(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(72, 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
     */
    function toInt64(int256 value) internal pure returns (int64 downcasted) {
        downcasted = int64(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(64, value);
        }
    }

    /**
     * @dev Returns the downcasted int56 from int256, reverting on
     * overflow (when the input is less than smallest int56 or
     * greater than largest int56).
     *
     * Counterpart to Solidity's `int56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     */
    function toInt56(int256 value) internal pure returns (int56 downcasted) {
        downcasted = int56(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(56, value);
        }
    }

    /**
     * @dev Returns the downcasted int48 from int256, reverting on
     * overflow (when the input is less than smallest int48 or
     * greater than largest int48).
     *
     * Counterpart to Solidity's `int48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     */
    function toInt48(int256 value) internal pure returns (int48 downcasted) {
        downcasted = int48(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(48, value);
        }
    }

    /**
     * @dev Returns the downcasted int40 from int256, reverting on
     * overflow (when the input is less than smallest int40 or
     * greater than largest int40).
     *
     * Counterpart to Solidity's `int40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     */
    function toInt40(int256 value) internal pure returns (int40 downcasted) {
        downcasted = int40(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(40, 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
     */
    function toInt32(int256 value) internal pure returns (int32 downcasted) {
        downcasted = int32(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(32, value);
        }
    }

    /**
     * @dev Returns the downcasted int24 from int256, reverting on
     * overflow (when the input is less than smallest int24 or
     * greater than largest int24).
     *
     * Counterpart to Solidity's `int24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     */
    function toInt24(int256 value) internal pure returns (int24 downcasted) {
        downcasted = int24(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(24, 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
     */
    function toInt16(int256 value) internal pure returns (int16 downcasted) {
        downcasted = int16(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(16, 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
     */
    function toInt8(int256 value) internal pure returns (int8 downcasted) {
        downcasted = int8(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(8, 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
        if (value > uint256(type(int256).max)) {
            revert SafeCastOverflowedUintToInt(value);
        }
        return int256(value);
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.

pragma solidity ^0.8.20;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(newImplementation.code.length > 0);
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 */
library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
     */
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
     */
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }
}

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

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

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

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

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

/// @title Math library for computing sqrt prices from ticks and vice versa
/// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports
/// prices between 2**-128 and 2**128
library TickMath {
    error T();
    error R();

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

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

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

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

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

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

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

            uint256 r = ratio;
            uint256 msb = 0;

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

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

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

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

            int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

interface IGenericRouter1Inch {

    struct SwapDescription {
        address srcToken;
        address dstToken;
        address payable srcReceiver;
        address payable dstReceiver;
        uint256 amount;
        uint256 minReturnAmount;
        uint256 flags;
    }

    /// @notice Performs a swap, delegating all calls encoded in `data` to `executor`. See tests for usage examples
    /// @dev router keeps 1 wei of every token on the contract balance for gas optimisations reasons. This affects first swap of every token by leaving 1 wei on the contract.
    /// @param executor Aggregation executor that executes calls described in `data`
    /// @param desc Swap description
    /// @param permit Should contain valid permit that can be used in `IERC20Permit.permit` calls.
    /// @param data Encoded calls that `caller` should execute in between of swaps
    /// @return returnAmount Resulting token amount
    /// @return spentAmount Source token amount
    function swap(
        address executor,
        SwapDescription calldata desc,
        bytes calldata permit,
        bytes calldata data
    ) external payable returns (uint256 returnAmount, uint256 spentAmount);

    /// @notice Same as `clipperSwapTo` but uses `msg.sender` as recipient
    /// @param srcToken Source token
    /// @param dstToken Destination token
    /// @param inputAmount Amount of source tokens to swap
    /// @param outputAmount Amount of destination tokens to receive
    /// @param goodUntil Timestamp until the swap will be valid
    /// @param r Clipper order signature (r part)
    /// @param vs Clipper order signature (vs part)
    /// @return returnAmount Amount of destination tokens received
    function clipperSwap(
        address clipperExchange,
        address srcToken,
        address dstToken,
        uint256 inputAmount,
        uint256 outputAmount,
        uint256 goodUntil,
        bytes32 r,
        bytes32 vs
    ) external payable returns(uint256 returnAmount);

    /// @notice Performs swap using Uniswap exchange. Wraps and unwraps ETH if required.
    /// Sending non-zero `msg.value` for anything but ETH swaps is prohibited
    /// @param srcToken Source token
    /// @param amount Amount of source tokens to swap
    /// @param minReturn Minimal allowed returnAmount to make transaction commit
    /// @param pools Pools chain used for swaps. Pools src and dst tokens should match to make swap happen
    function unoswap(
        address srcToken,
        uint256 amount,
        uint256 minReturn,
        uint256[] calldata pools
    ) external payable returns(uint256 returnAmount);

    /// @notice Same as `uniswapV3SwapTo` but uses `msg.sender` as recipient
    /// @param amount Amount of source tokens to swap
    /// @param minReturn Minimal allowed returnAmount to make transaction commit
    /// @param pools Pools chain used for swaps. Pools src and dst tokens should match to make swap happen
    function uniswapV3Swap(
        uint256 amount,
        uint256 minReturn,
        uint256[] calldata pools
    ) external payable returns(uint256 returnAmount);
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

interface INileGauge {

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

    function getReward(
        address owner,
        uint256 index,
        int24 tickLower,
        int24 tickUpper,
        address[] memory tokens,
        address receiver
    ) external;
    
}

File 28 of 32 : IRewardCounter.sol
// SPDX-License-Identifier: BUSL
// Teahouse Finance

pragma solidity ^0.8.0;

interface IRewardCounter {

    struct UserData {
        uint256 unclaimedRewards;
        uint256 lastRewardPerShareX36;
    }

}

// SPDX-License-Identifier: BUSL-1.1
// Teahouse Finance

pragma solidity ^0.8.0;

interface ITeaVaultV3Pair {

    error PoolNotInitialized();
    error InvalidFeePercentage();
    error InvalidFeeCap();
    error InvalidShareAmount();
    error PositionLengthExceedsLimit();
    error InvalidPriceSlippage(uint256 amount0, uint256 amount1);
    error PositionDoesNotExist();
    error ZeroLiquidity();
    error CallerIsNotManager();
    error CallerIsNotRewardClaimer();
    error InvalidCallbackStatus();
    error InvalidCallbackCaller();
    error SwapInZeroLiquidityRegion();
    error TransactionExpired();
    error InvalidSwapToken();
    error InvalidSwapReceiver();
    error InsufficientSwapResult(uint256 minAmount, uint256 convertedAmount);
    error InvalidTokenOrder();
    error ZeroAddress();
    error InvalidToken();
    error LxpLAlreadySet();

    event TeaVaultV3PairCreated(address indexed teaVaultAddress);
    event FeeConfigChanged(address indexed sender, uint256 timestamp, FeeConfig feeConfig);
    event ManagerChanged(address indexed sender, address indexed newManager);
    event ManagementFeeCollected(uint256 shares);
    event DepositShares(address indexed shareOwner, uint256 shares, uint256 amount0, uint256 amount1, uint256 feeAmount0, uint256 feeAmount1);
    event WithdrawShares(address indexed shareOwner, uint256 shares, uint256 amount0, uint256 amount1, uint256 feeShares);
    event AddLiquidity(address indexed pool, int24 tickLower, int24 tickUpper, uint128 liquidity, uint256 amount0, uint256 amount1);
    event RemoveLiquidity(address indexed pool, int24 tickLower, int24 tickUpper, uint128 liquidity, uint256 amount0, uint256 amount1);
    event Collect(address indexed pool, int24 tickLower, int24 tickUpper, uint256 amount0, uint256 amount1);
    event CollectSwapFees(address indexed pool, uint256 amount0, uint256 amount1, uint256 feeAmount0, uint256 feeAmount1);
    event Swap(bool indexed zeroForOne, bool indexed exactInput, uint256 amountIn, uint256 amountOut);
    event rewardClaimerSet(address indexed claimer);
    event rewardClaimed(address indexed to);

    /// @notice Fee config structure
    /// @param vault Fee goes to this address
    /// @param entryFee Entry fee in 0.0001% (collected when depositing)
    /// @param exitFee Exit fee in 0.0001% (collected when withdrawing)
    /// @param performanceFee Platform performance fee in 0.0001% (collected for each cycle, from profits)
    /// @param managementFee Platform yearly management fee in 0.0001% (collected when depositing/withdrawing)
    struct FeeConfig {
        address vault;
        uint24 entryFee;
        uint24 exitFee;
        uint24 performanceFee;
        uint24 managementFee;
    }

    /// @notice Uniswap V3 position structure
    /// @param tickLower Tick lower bound
    /// @param tickUpper Tick upper bound
    /// @param liquidity Liquidity size
    struct Position {
        int24 tickLower;
        int24 tickUpper;
        uint128 liquidity;
    }

    /// @notice get asset token0 address
    /// @return token0 token0 address
    function assetToken0() external view returns (address token0);

    /// @notice get asset token1 address
    /// @return token1 token1 address
    function assetToken1() external view returns (address token1);

    /// @notice get vault balance of token0
    /// @return amount vault balance of token0
    function getToken0Balance() external view returns (uint256 amount);

    /// @notice get vault balance of token1
    /// @return amount vault balance of token1
    function getToken1Balance() external view returns (uint256 amount);

    /// @notice get pool token and price info
    /// @return token0 token0 address
    /// @return token1 token1 address
    /// @return decimals0 token0 decimals
    /// @return decimals1 token1 decimals
    /// @return feeTier current pool price in tick
    /// @return sqrtPriceX96 current pool price in sqrtPriceX96
    /// @return tick current pool price in tick
    function getPoolInfo() external view returns (
        address token0,
        address token1,
        uint8 decimals0,
        uint8 decimals1,
        uint24 feeTier,
        uint160 sqrtPriceX96,
        int24 tick
    );

    /// @notice Set fee structure and vault addresses
    /// @notice Only available to admins
    /// @param _feeConfig Fee structure settings
    function setFeeConfig(FeeConfig calldata _feeConfig) external;

    /// @notice Assign fund manager
    /// @notice Only the owner can do this
    /// @param _manager Fund manager address
    function assignManager(address _manager) external;

    /// @notice Collect management fee by share token inflation
    /// @notice Only fund manager can do this
    /// @return collectedShares Share amount collected by minting
    function collectManagementFee() external returns (uint256 collectedShares);

    /// @notice Mint shares and deposit token0 and token1
    /// @param _shares Share amount to be mint
    /// @param _amount0Max Max token0 amount to be deposited
    /// @param _amount1Max Max token1 amount to be deposited
    /// @return depositedAmount0 Deposited token0 amount
    /// @return depositedAmount1 Deposited token1 amount
    function deposit(
        uint256 _shares,
        uint256 _amount0Max,
        uint256 _amount1Max
    ) external returns (uint256 depositedAmount0, uint256 depositedAmount1);

    /// @notice Burn shares and withdraw token0 and token1
    /// @param _shares Share amount to be burnt
    /// @param _amount0Min Min token0 amount to be withdrawn
    /// @param _amount1Min Min token1 amount to be withdrawn
    /// @return withdrawnAmount0 Withdrew token0 amount
    /// @return withdrawnAmount1 Withdrew token1 amount
    function withdraw(
        uint256 _shares,
        uint256 _amount0Min,
        uint256 _amount1Min
    ) external returns (uint256 withdrawnAmount0, uint256 withdrawnAmount1);

    /// @notice Add liquidity to a position from this vault
    /// @notice Only fund manager can do this
    /// @param _tickLower Tick lower bound
    /// @param _tickUpper Tick upper bound
    /// @param _liquidity Liquidity to be added to the position
    /// @param _amount0Min Minimum token0 amount to be added to the position
    /// @param _amount1Min Minimum token1 amount to be added to the position
    /// @param _deadline Deadline of the transaction (transaction will revert if after this timestamp)
    /// @return amount0 Token0 amount added to the position
    /// @return amount1 Token1 amount added to the position
    function addLiquidity(
        int24 _tickLower,
        int24 _tickUpper,
        uint128 _liquidity,
        uint256 _amount0Min,
        uint256 _amount1Min,
        uint64 _deadline
    ) external returns (uint256 amount0, uint256 amount1);

    /// @notice Remove liquidity from a position from this vault
    /// @notice Only fund manager can do this
    /// @param _tickLower Tick lower bound
    /// @param _tickUpper Tick upper bound
    /// @param _liquidity Liquidity to be removed from the position
    /// @param _amount0Min Minimum token0 amount to be removed from the position
    /// @param _amount1Min Minimum token1 amount to be removed from the position
    /// @param _deadline Deadline of the transaction (transaction will revert if after this timestamp)
    /// @return amount0 Token0 amount removed from the position
    /// @return amount1 Token1 amount removed from the position
    function removeLiquidity(
        int24 _tickLower,
        int24 _tickUpper,
        uint128 _liquidity,
        uint256 _amount0Min,
        uint256 _amount1Min,
        uint64 _deadline
    ) external returns (uint256 amount0, uint256 amount1);

    /// @notice Collect swap fee of a position
    /// @notice Only fund manager can do this
    /// @param _tickLower Tick lower bound
    /// @param _tickUpper Tick upper bound
    /// @return amount0 Token0 amount collected from the position
    /// @return amount1 Token1 amount collected from the position
    function collectPositionSwapFee(
        int24 _tickLower,
        int24 _tickUpper
    ) external returns (uint128 amount0, uint128 amount1);

    /// @notice Collect swap fee of all positions
    /// @notice Only fund manager can do this
    /// @return amount0 Token0 amount collected from the positions
    /// @return amount1 Token1 amount collected from the positions
    function collectAllSwapFee() external returns (uint128 amount0, uint128 amount1);

    /// @notice Swap tokens on the pool with exact input amount
    /// @notice Only fund manager can do this
    /// @param _zeroForOne Swap direction from token0 to token1 or not
    /// @param _amountIn Amount of input token
    /// @param _amountOutMin Required minimum output token amount
    /// @param _minPriceInSqrtPriceX96 Minimum price in sqrtPriceX96
    /// @param _deadline Deadline of the transaction (transaction will revert if after this timestamp)
    /// @return amountOut Output token amount
    function swapInputSingle(
        bool _zeroForOne,
        uint256 _amountIn,
        uint256 _amountOutMin,
        uint160 _minPriceInSqrtPriceX96,
        uint64 _deadline
    ) external returns (uint256 amountOut);


    /// @notice Swap tokens on the pool with exact output amount
    /// @notice Only fund manager can do this
    /// @param _zeroForOne Swap direction from token0 to token1 or not
    /// @param _amountOut Output token amount
    /// @param _amountInMax Required maximum input token amount
    /// @param _maxPriceInSqrtPriceX96 Maximum price in sqrtPriceX96
    /// @param _deadline Deadline of the transaction (transaction will revert if after this timestamp)
    /// @return amountIn Input token amount
    function swapOutputSingle(
        bool _zeroForOne,
        uint256 _amountOut,
        uint256 _amountInMax,
        uint160 _maxPriceInSqrtPriceX96,
        uint64 _deadline
    ) external returns (uint256 amountIn);

    /// @notice Process batch operations in one transation
    /// @return results Results in bytes array
    function multicall(bytes[] calldata data) external returns (bytes[] memory results);

    /// @notice Get position info by specifying tickLower and tickUpper of the position
    /// @param _tickLower Tick lower bound
    /// @param _tickUpper Tick upper bound
    /// @return amount0 Current position token0 amount
    /// @return amount1 Current position token1 amount
    /// @return fee0 Pending fee token0 amount
    /// @return fee1 Pending fee token1 amount
    function positionInfo(
        int24 _tickLower,
        int24 _tickUpper
    ) external view returns (uint256 amount0, uint256 amount1, uint256 fee0, uint256 fee1);

    /// @notice Get position info by specifying position index
    /// @param _index Position index
    /// @return amount0 Current position token0 amount
    /// @return amount1 Current position token1 amount
    /// @return fee0 Pending fee token0 amount
    /// @return fee1 Pending fee token1 amount
    function positionInfo(
        uint256 _index
    ) external view returns (uint256 amount0, uint256 amount1, uint256 fee0, uint256 fee1);

    /// @notice Get all position info
    /// @return amount0 All positions token0 amount
    /// @return amount1 All positions token1 amount
    /// @return fee0 All positions pending fee token0 amount
    /// @return fee1 All positions pending fee token1 amount
    function allPositionInfo() external view returns (uint256 amount0, uint256 amount1, uint256 fee0, uint256 fee1);

    /// @notice Get underlying assets hold by this vault
    /// @return amount0 Total token0 amount
    /// @return amount1 Total token1 amount
    function vaultAllUnderlyingAssets() external view returns (uint256 amount0, uint256 amount1);

    /// @notice Get vault value in token0
    /// @return value0 Vault value in token0
    function estimatedValueInToken0() external view returns (uint256 value0);

    /// @notice Get vault value in token1
    /// @return value1 Vault value in token1
    function estimatedValueInToken1() external view returns (uint256 value1);

    /// @notice Calculate liquidity of a position from amount0 and amount1
    /// @param tickLower lower tick of the position
    /// @param tickUpper upper tick of the position
    /// @param amount0 amount of token0
    /// @param amount1 amount of token1
    /// @return liquidity calculated liquidity 
    function getLiquidityForAmounts(
        int24 tickLower,
        int24 tickUpper,
        uint256 amount0,
        uint256 amount1
    ) external view returns (uint128 liquidity);

    /// @notice Calculate amount of tokens required for liquidity of a position
    /// @param tickLower lower tick of the position
    /// @param tickUpper upper tick of the position
    /// @param liquidity amount of liquidity
    /// @return amount0 amount of token0 required
    /// @return amount1 amount of token1 required
    function getAmountsForLiquidity(
        int24 tickLower,
        int24 tickUpper,
        uint128 liquidity
    ) external view returns (uint256 amount0, uint256 amount1);

    /// @notice Get all open positions
    /// @return results Array of all open positions
   function getAllPositions() external view returns (Position[] memory results);
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

interface IUniswapV3Pool {

    function token0() external view returns (address);
    function token1() external view returns (address);
    function fee() external view returns (uint24);
    function slot0() external view returns (
        uint160 sqrtPriceX96,
        int24 tick,
        uint16 observationIndex,
        uint16 observationCardinality,
        uint16 observationCardinalityNext,
        uint8 feeProtocol,
        bool unlocked
    );
    function feeGrowthGlobal0X128() external view returns (uint256);
    function feeGrowthGlobal1X128() external view returns (uint256);
    function ticks(int24 tick) external view returns (
        uint128 liquidityGross,
        int128 liquidityNet,
        uint256 feeGrowthOutside0X128,
        uint256 feeGrowthOutside1X128,
        int56 tickCumulativeOutside,
        uint160 secondsPerLiquidityOutsideX128,
        uint32 secondsOutside,
        bool initialized
    );
    function positions(bytes32 key) external view returns (
        uint128 liquidity,
        uint256 feeGrowthInside0LastX128,
        uint256 feeGrowthInside1LastX128,
        uint128 tokensOwed0,
        uint128 tokensOwed1
    );
    function mint(
        address recipient,
        int24 tickLower,
        int24 tickUpper,
        uint128 amount,
        bytes calldata data
    ) external returns (uint256 amount0, uint256 amount1);
    function collect(
        address recipient,
        int24 tickLower,
        int24 tickUpper,
        uint128 amount0Requested,
        uint128 amount1Requested
    ) external returns (uint128 amount0, uint128 amount1);
    function burn(
        int24 tickLower,
        int24 tickUpper,
        uint128 amount
    ) external returns (uint256 amount0, uint256 amount1);
    function swap(
        address recipient,
        bool zeroForOne,
        int256 amountSpecified,
        uint160 sqrtPriceLimitX96,
        bytes calldata data
    ) external returns (int256 amount0, int256 amount1);

}

// SPDX-License-Identifier: BUSL-1.1
// Teahouse Finance

pragma solidity =0.8.26;

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

import "../interface/ITeaVaultV3Pair.sol";
import "../interface/IGenericRouter1Inch.sol";

library GenericRouter1Inch {

    using SafeERC20 for IERC20;

    /// @notice swap tokens using 1Inch router via ClipperRouter
    /// @param srcToken Source token
    /// @param dstToken Destination token
    /// @param inputAmount Amount of source tokens to swap
    /// @param outputAmount Amount of destination tokens to receive
    /// @param goodUntil Timestamp until the swap will be valid
    /// @param r Clipper order signature (r part)
    /// @param vs Clipper order signature (vs part)
    /// @return returnAmount Amount of destination tokens received
    function clipperSwap(
        IGenericRouter1Inch router1Inch,
        IERC20 token0,
        IERC20 token1,
        uint256 minAmount,
        address clipperExchange,
        address srcToken,
        address dstToken,
        uint256 inputAmount,
        uint256 outputAmount,
        uint256 goodUntil,
        bytes32 r,
        bytes32 vs
    ) external returns(uint256 returnAmount) {
        if (srcToken == address(token0)) {
            // perform actual swap
            token0.forceApprove(address(router1Inch), inputAmount);
            uint256 token1BalanceBefore = token1.balanceOf(address(this));
            returnAmount = router1Inch.clipperSwap(clipperExchange, srcToken, dstToken, inputAmount, outputAmount, goodUntil, r, vs);
            uint256 token1BalanceAfter = token1.balanceOf(address(this));
            uint256 convertedAmount = token1BalanceAfter - token1BalanceBefore;
            if (convertedAmount < minAmount) {
                revert ITeaVaultV3Pair.InsufficientSwapResult(minAmount, convertedAmount);
            }
        }
        else {
            // perform actual swap
            token1.forceApprove(address(router1Inch), inputAmount);
            uint256 token0BalanceBefore = token0.balanceOf(address(this));
            returnAmount = router1Inch.clipperSwap(clipperExchange, srcToken, dstToken, inputAmount, outputAmount, goodUntil, r, vs);
            uint256 token0BalanceAfter = token0.balanceOf(address(this));
            uint256 convertedAmount = token0BalanceAfter - token0BalanceBefore;
            if (convertedAmount < minAmount) {
                revert ITeaVaultV3Pair.InsufficientSwapResult(minAmount, convertedAmount);
            }
        }
    }

    /// @notice swap tokens using 1Inch router via GenericRouter
    /// @param executor Aggregation executor that executes calls described in `data`
    /// @param desc Swap description
    /// @param permit Should contain valid permit that can be used in `IERC20Permit.permit` calls.
    /// @param data Encoded calls that `caller` should execute in between of swaps
    /// @return returnAmount Resulting token amount
    /// @return spentAmount Source token amount        
    function swap(
        IGenericRouter1Inch router1Inch,
        IERC20 token0,
        IERC20 token1,
        uint256 minAmount,
        address executor,
        IGenericRouter1Inch.SwapDescription calldata desc,
        bytes calldata permit,
        bytes calldata data
    ) external returns (uint256 returnAmount, uint256 spentAmount) {
        if (desc.srcToken == address(token0)) {
            // perform actual swap
            token0.forceApprove(address(router1Inch), desc.amount);
            uint256 token1BalanceBefore = token1.balanceOf(address(this));
            (returnAmount, spentAmount) = router1Inch.swap(executor, desc, permit, data);
            uint256 token1BalanceAfter = token1.balanceOf(address(this));
            uint256 convertedAmount = token1BalanceAfter - token1BalanceBefore;
            if (convertedAmount < minAmount) {
                revert ITeaVaultV3Pair.InsufficientSwapResult(minAmount, convertedAmount);
            }
        }
        else {
            // perform actual swap
            token1.forceApprove(address(router1Inch), desc.amount);
            uint256 token0BalanceBefore = token0.balanceOf(address(this));
            (returnAmount, spentAmount) = router1Inch.swap(executor, desc, permit, data);
            uint256 token0BalanceAfter = token0.balanceOf(address(this));
            uint256 convertedAmount = token0BalanceAfter - token0BalanceBefore;
            if (convertedAmount < minAmount) {
                revert ITeaVaultV3Pair.InsufficientSwapResult(minAmount, convertedAmount);
            }
        }
    }

    /// @notice Swap tokens using 1Inch router via unoswap (for UniswapV2)
    /// @param srcToken Source token
    /// @param amount Amount of source tokens to swap
    /// @param minReturn Minimal allowed returnAmount to make transaction commit
    /// @param pools Pools chain used for swaps. Pools src and dst tokens should match to make swap happen
    function unoswap(
        IGenericRouter1Inch router1Inch,
        IERC20 token0,
        IERC20 token1,
        uint256 minAmount,        
        address srcToken,
        uint256 amount,
        uint256 minReturn,
        uint256[] calldata pools
    ) external returns(uint256 returnAmount) {
        if (srcToken == address(token0)) {
            // perform actual swap
            token0.forceApprove(address(router1Inch), amount);
            uint256 token1BalanceBefore = token1.balanceOf(address(this));
            (returnAmount) = router1Inch.unoswap(srcToken, amount, minReturn, pools);
            uint256 token1BalanceAfter = token1.balanceOf(address(this));
            uint256 convertedAmount = token1BalanceAfter - token1BalanceBefore;
            if (convertedAmount < minAmount) {
                revert ITeaVaultV3Pair.InsufficientSwapResult(minAmount, convertedAmount);
            }
        }
        else {
            // perform actual swap
            token1.forceApprove(address(router1Inch), amount);
            uint256 token0BalanceBefore = token0.balanceOf(address(this));
            (returnAmount) = router1Inch.unoswap(srcToken, amount, minReturn, pools);
            uint256 token0BalanceAfter = token0.balanceOf(address(this));
            uint256 convertedAmount = token0BalanceAfter - token0BalanceBefore;
            if (convertedAmount < minAmount) {
                revert ITeaVaultV3Pair.InsufficientSwapResult(minAmount, convertedAmount);
            }
        }
    }

    /// @notice Swap tokens using 1Inch router via UniswapV3
    /// @param amount Amount of source tokens to swap
    /// @param minReturn Minimal allowed returnAmount to make transaction commit
    /// @param pools Pools chain used for swaps. Pools src and dst tokens should match to make swap happen
    function uniswapV3Swap(
        IGenericRouter1Inch router1Inch,
        IERC20 token0,
        IERC20 token1,
        bool zeroForOne,
        uint256 minAmount,        
        uint256 amount,
        uint256 minReturn,
        uint256[] calldata pools
    ) external returns(uint256 returnAmount) {
        if (zeroForOne) {
            // perform actual swap
            token0.forceApprove(address(router1Inch), amount);
            uint256 token1BalanceBefore = token1.balanceOf(address(this));
            (returnAmount) = router1Inch.uniswapV3Swap(amount, minReturn, pools);
            uint256 token1BalanceAfter = token1.balanceOf(address(this));
            uint256 convertedAmount = token1BalanceAfter - token1BalanceBefore;
            if (convertedAmount < minAmount) {
                revert ITeaVaultV3Pair.InsufficientSwapResult(minAmount, convertedAmount);
            }
        }
        else {
            // perform actual swap
            token1.forceApprove(address(router1Inch), amount);
            uint256 token0BalanceBefore = token0.balanceOf(address(this));
            (returnAmount) = router1Inch.uniswapV3Swap(amount, minReturn, pools);
            uint256 token0BalanceAfter = token0.balanceOf(address(this));
            uint256 convertedAmount = token0BalanceAfter - token0BalanceBefore;
            if (convertedAmount < minAmount) {
                revert ITeaVaultV3Pair.InsufficientSwapResult(minAmount, convertedAmount);
            }
        }
    }
}

// SPDX-License-Identifier: BUSL-1.1
// Teahouse Finance

pragma solidity =0.8.26;

// import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
import "@uniswap/v3-core/contracts/libraries/TickMath.sol";
import "@uniswap/v3-periphery/contracts/libraries/LiquidityAmounts.sol";
import "@uniswap/v3-core/contracts/libraries/FixedPoint96.sol";
import "@uniswap/v3-core/contracts/libraries/FixedPoint128.sol";

import "../interface/IUniswapV3Pool.sol";
import "../interface/ITeaVaultV3Pair.sol";

library VaultUtils {

    function getLiquidityForAmounts(
        IUniswapV3Pool _pool,
        int24 _tickLower,
        int24 _tickUpper,
        uint256 _amount0,
        uint256 _amount1
    ) external view returns (uint128 liquidity) {
        (uint160 sqrtPriceX96, , , , , , ) = _pool.slot0();
        
        return LiquidityAmounts.getLiquidityForAmounts(
            sqrtPriceX96,
            TickMath.getSqrtRatioAtTick(_tickLower),
            TickMath.getSqrtRatioAtTick(_tickUpper),
            _amount0,
            _amount1
        );
    }

    function getAmountsForLiquidity(
        IUniswapV3Pool _pool,
        int24 _tickLower,
        int24 _tickUpper,
        uint128 _liquidity
    ) external view returns (uint256 amount0, uint256 amount1) {
        (uint160 sqrtPriceX96, , , , , , ) = _pool.slot0();

        return LiquidityAmounts.getAmountsForLiquidity(
            sqrtPriceX96,
            TickMath.getSqrtRatioAtTick(_tickLower),
            TickMath.getSqrtRatioAtTick(_tickUpper),
            _liquidity
        );
    }

    function positionInfo(
        address vault,
        IUniswapV3Pool pool,
        ITeaVaultV3Pair.Position storage position
    ) external view returns (uint256 amount0, uint256 amount1, uint256 fee0, uint256 fee1) {
        bytes32 positionKey = keccak256(abi.encodePacked(vault, uint256(0), position.tickLower, position.tickUpper));
        (uint160 sqrtPriceX96, int24 tick, , , , , ) = pool.slot0();
        uint256 feeGrowthGlobal0X128 = pool.feeGrowthGlobal0X128();
        uint256 feeGrowthGlobal1X128 = pool.feeGrowthGlobal1X128();
        (, , uint256 feeGrowthOutside0X128Lower, uint256 feeGrowthOutside1X128Lower, , , , ) = pool.ticks(position.tickLower);
        (, , uint256 feeGrowthOutside0X128Upper, uint256 feeGrowthOutside1X128Upper, , , , ) = pool.ticks(position.tickUpper);
        (
            uint128 liquidity,
            uint256 feeGrowthInside0Last,
            uint256 feeGrowthInside1Last,
            uint128 tokensOwed0,
            uint128 tokensOwed1
        ) = pool.positions(positionKey);

        (amount0, amount1) = LiquidityAmounts.getAmountsForLiquidity(
            sqrtPriceX96,
            TickMath.getSqrtRatioAtTick(position.tickLower),
            TickMath.getSqrtRatioAtTick(position.tickUpper),
            liquidity
        );
        
        fee0 = tokensOwed0 + potisionSwapFee(
            tick,
            position.tickLower,
            position.tickUpper,
            liquidity,
            feeGrowthGlobal0X128,
            feeGrowthInside0Last,
            feeGrowthOutside0X128Lower,
            feeGrowthOutside0X128Upper
        );

        fee1 = tokensOwed1 + potisionSwapFee(
            tick,
            position.tickLower,
            position.tickUpper,
            liquidity,
            feeGrowthGlobal1X128,
            feeGrowthInside1Last,
            feeGrowthOutside1X128Lower,
            feeGrowthOutside1X128Upper
        );
    }

    function potisionSwapFee(
        int24 _tick,
        int24 _tickLower,
        int24 _tickUpper,
        uint128 _liquidity,
        uint256 _feeGrowthGlobalX128,
        uint256 _feeGrowthInsideLastX128,
        uint256 _feeGrowthOutsideX128Lower,
        uint256 _feeGrowthOutsideX128Upper
    ) public pure returns (uint256 swapFee) {
        unchecked {
            uint256 feeGrowthInsideX128;
            uint256 feeGrowthBelowX128;
            uint256 feeGrowthAboveX128;

            feeGrowthBelowX128 = _tick >= _tickLower?
                _feeGrowthOutsideX128Lower:
                _feeGrowthGlobalX128 - _feeGrowthOutsideX128Lower;
            
            feeGrowthAboveX128 = _tick < _tickUpper?
                _feeGrowthOutsideX128Upper:
                _feeGrowthGlobalX128 - _feeGrowthOutsideX128Upper;

            feeGrowthInsideX128 = _feeGrowthGlobalX128 - feeGrowthBelowX128 - feeGrowthAboveX128;

            swapFee = FullMath.mulDiv(
                feeGrowthInsideX128 - _feeGrowthInsideLastX128,
                _liquidity,
                FixedPoint128.Q128
            );
        }
    }

    function estimatedValueInToken0(
        IUniswapV3Pool pool,
        uint256 _amount0,
        uint256 _amount1
    ) external view returns (uint256 value0) {
        (uint160 sqrtPriceX96, , , , , , ) = pool.slot0();

        value0 = _amount0 + FullMath.mulDiv(
            _amount1,
            FixedPoint96.Q96,
            FullMath.mulDiv(sqrtPriceX96, sqrtPriceX96, FixedPoint96.Q96)
        );
    }

    function estimatedValueInToken1(
        IUniswapV3Pool pool,
        uint256 _amount0,
        uint256 _amount1
    ) external view returns (uint256 value1) {
        (uint160 sqrtPriceX96, , , , , , ) = pool.slot0();

        value1 = _amount1 + FullMath.mulDiv(
            _amount0,
            FullMath.mulDiv(sqrtPriceX96, sqrtPriceX96, FixedPoint96.Q96),
            FixedPoint96.Q96
        );
    }
}

Settings
{
  "viaIR": true,
  "optimizer": {
    "enabled": true,
    "runs": 1
  },
  "evmVersion": "paris",
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {
    "contracts/library/GenericRouter1Inch.sol": {
      "GenericRouter1Inch": "0xdbfe68fae54d9875a50fdfd9af72b149f3acc899"
    },
    "contracts/library/VaultUtils.sol": {
      "VaultUtils": "0x2ed994fd3dc53bd4010652bfc00d980580823664"
    }
  }
}

Contract Security Audit

Contract ABI

API
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"CallerIsNotManager","type":"error"},{"inputs":[],"name":"CallerIsNotRewardClaimer","type":"error"},{"inputs":[{"internalType":"address","name":"implementation","type":"address"}],"name":"ERC1967InvalidImplementation","type":"error"},{"inputs":[],"name":"ERC1967NonPayable","type":"error"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"allowance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientAllowance","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientBalance","type":"error"},{"inputs":[{"internalType":"address","name":"approver","type":"address"}],"name":"ERC20InvalidApprover","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"ERC20InvalidReceiver","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"ERC20InvalidSender","type":"error"},{"inputs":[{"internalType":"address","name":"spender","type":"address"}],"name":"ERC20InvalidSpender","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[{"internalType":"uint256","name":"minAmount","type":"uint256"},{"internalType":"uint256","name":"convertedAmount","type":"uint256"}],"name":"InsufficientSwapResult","type":"error"},{"inputs":[],"name":"InvalidCallbackCaller","type":"error"},{"inputs":[],"name":"InvalidCallbackStatus","type":"error"},{"inputs":[],"name":"InvalidFeeCap","type":"error"},{"inputs":[],"name":"InvalidFeePercentage","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"InvalidPriceSlippage","type":"error"},{"inputs":[],"name":"InvalidShareAmount","type":"error"},{"inputs":[],"name":"InvalidSwapReceiver","type":"error"},{"inputs":[],"name":"InvalidSwapToken","type":"error"},{"inputs":[],"name":"InvalidToken","type":"error"},{"inputs":[],"name":"InvalidTokenOrder","type":"error"},{"inputs":[],"name":"LxpLAlreadySet","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"PoolNotInitialized","type":"error"},{"inputs":[],"name":"PositionDoesNotExist","type":"error"},{"inputs":[],"name":"PositionLengthExceedsLimit","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"uint8","name":"bits","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintDowncast","type":"error"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintToInt","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"SwapInZeroLiquidityRegion","type":"error"},{"inputs":[],"name":"TransactionExpired","type":"error"},{"inputs":[],"name":"UUPSUnauthorizedCallContext","type":"error"},{"inputs":[{"internalType":"bytes32","name":"slot","type":"bytes32"}],"name":"UUPSUnsupportedProxiableUUID","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"inputs":[],"name":"ZeroLiquidity","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pool","type":"address"},{"indexed":false,"internalType":"int24","name":"tickLower","type":"int24"},{"indexed":false,"internalType":"int24","name":"tickUpper","type":"int24"},{"indexed":false,"internalType":"uint128","name":"liquidity","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"AddLiquidity","type":"event"},{"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":true,"internalType":"address","name":"pool","type":"address"},{"indexed":false,"internalType":"int24","name":"tickLower","type":"int24"},{"indexed":false,"internalType":"int24","name":"tickUpper","type":"int24"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"Collect","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pool","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeAmount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeAmount1","type":"uint256"}],"name":"CollectSwapFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"shareOwner","type":"address"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeAmount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeAmount1","type":"uint256"}],"name":"DepositShares","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"},{"components":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"uint24","name":"entryFee","type":"uint24"},{"internalType":"uint24","name":"exitFee","type":"uint24"},{"internalType":"uint24","name":"performanceFee","type":"uint24"},{"internalType":"uint24","name":"managementFee","type":"uint24"}],"indexed":false,"internalType":"struct ITeaVaultV3Pair.FeeConfig","name":"feeConfig","type":"tuple"}],"name":"FeeConfigChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"ManagementFeeCollected","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"newManager","type":"address"}],"name":"ManagerChanged","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":"pool","type":"address"},{"indexed":false,"internalType":"int24","name":"tickLower","type":"int24"},{"indexed":false,"internalType":"int24","name":"tickUpper","type":"int24"},{"indexed":false,"internalType":"uint128","name":"liquidity","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"RemoveLiquidity","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bool","name":"zeroForOne","type":"bool"},{"indexed":true,"internalType":"bool","name":"exactInput","type":"bool"},{"indexed":false,"internalType":"uint256","name":"amountIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountOut","type":"uint256"}],"name":"Swap","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"teaVaultAddress","type":"address"}],"name":"TeaVaultV3PairCreated","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"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"shareOwner","type":"address"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeShares","type":"uint256"}],"name":"WithdrawShares","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"rewardClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"claimer","type":"address"}],"name":"rewardClaimerSet","type":"event"},{"inputs":[],"name":"DECIMALS_MULTIPLIER","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"FEE_CAP","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"FEE_MULTIPLIER","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SECONDS_IN_A_YEAR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UPGRADE_INTERFACE_VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int24","name":"_tickLower","type":"int24"},{"internalType":"int24","name":"_tickUpper","type":"int24"},{"internalType":"uint128","name":"_liquidity","type":"uint128"},{"internalType":"uint256","name":"_amount0Min","type":"uint256"},{"internalType":"uint256","name":"_amount1Min","type":"uint256"},{"internalType":"uint64","name":"_deadline","type":"uint64"}],"name":"addLiquidity","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"allPositionInfo","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint256","name":"fee0","type":"uint256"},{"internalType":"uint256","name":"fee1","type":"uint256"}],"stateMutability":"view","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":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"assetToken0","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"assetToken1","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_manager","type":"address"}],"name":"assignManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_router1Inch","type":"address"}],"name":"assignRouter1Inch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claim","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract INileGauge","name":"_gauge","type":"address"},{"internalType":"address","name":"_to","type":"address"}],"name":"claimAndForwardReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"clipperExchange","type":"address"},{"internalType":"address","name":"srcToken","type":"address"},{"internalType":"address","name":"dstToken","type":"address"},{"internalType":"uint256","name":"inputAmount","type":"uint256"},{"internalType":"uint256","name":"outputAmount","type":"uint256"},{"internalType":"uint256","name":"goodUntil","type":"uint256"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"vs","type":"bytes32"}],"name":"clipperSwap","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"collectAllSwapFee","outputs":[{"internalType":"uint128","name":"amount0","type":"uint128"},{"internalType":"uint128","name":"amount1","type":"uint128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"collectManagementFee","outputs":[{"internalType":"uint256","name":"collectedShares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int24","name":"_tickLower","type":"int24"},{"internalType":"int24","name":"_tickUpper","type":"int24"}],"name":"collectPositionSwapFee","outputs":[{"internalType":"uint128","name":"amount0","type":"uint128"},{"internalType":"uint128","name":"amount1","type":"uint128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_shares","type":"uint256"},{"internalType":"uint256","name":"_amount0Max","type":"uint256"},{"internalType":"uint256","name":"_amount1Max","type":"uint256"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"depositedAmount0","type":"uint256"},{"internalType":"uint256","name":"depositedAmount1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"estimatedValueInToken0","outputs":[{"internalType":"uint256","name":"value0","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"estimatedValueInToken1","outputs":[{"internalType":"uint256","name":"value1","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeConfig","outputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"uint24","name":"entryFee","type":"uint24"},{"internalType":"uint24","name":"exitFee","type":"uint24"},{"internalType":"uint24","name":"performanceFee","type":"uint24"},{"internalType":"uint24","name":"managementFee","type":"uint24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAllPositions","outputs":[{"components":[{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"uint128","name":"liquidity","type":"uint128"}],"internalType":"struct ITeaVaultV3Pair.Position[]","name":"results","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"uint128","name":"liquidity","type":"uint128"}],"name":"getAmountsForLiquidity","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"getLiquidityForAmounts","outputs":[{"internalType":"uint128","name":"liquidity","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPoolInfo","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint8","name":"","type":"uint8"},{"internalType":"uint8","name":"","type":"uint8"},{"internalType":"uint24","name":"","type":"uint24"},{"internalType":"uint160","name":"","type":"uint160"},{"internalType":"int24","name":"","type":"int24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getToken0Balance","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getToken1Balance","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"address","name":"_factory","type":"address"},{"internalType":"address","name":"_token0","type":"address"},{"internalType":"address","name":"_token1","type":"address"},{"internalType":"uint24","name":"_feeTier","type":"uint24"},{"internalType":"uint8","name":"_decimalOffset","type":"uint8"},{"internalType":"uint24","name":"_feeCap","type":"uint24"},{"components":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"uint24","name":"entryFee","type":"uint24"},{"internalType":"uint24","name":"exitFee","type":"uint24"},{"internalType":"uint24","name":"performanceFee","type":"uint24"},{"internalType":"uint24","name":"managementFee","type":"uint24"}],"internalType":"struct ITeaVaultV3Pair.FeeConfig","name":"_feeConfig","type":"tuple"},{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_rewardClaimer","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lastCollectManagementFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lxpL","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"manager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"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":[],"name":"pool","outputs":[{"internalType":"contract IUniswapV3Pool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"}],"name":"positionInfo","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint256","name":"fee0","type":"uint256"},{"internalType":"uint256","name":"fee1","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int24","name":"_tickLower","type":"int24"},{"internalType":"int24","name":"_tickUpper","type":"int24"}],"name":"positionInfo","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint256","name":"fee0","type":"uint256"},{"internalType":"uint256","name":"fee1","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"positions","outputs":[{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"uint128","name":"liquidity","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount0Owed","type":"uint256"},{"internalType":"uint256","name":"_amount1Owed","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"ramsesV2MintCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int256","name":"_amount0Delta","type":"int256"},{"internalType":"int256","name":"_amount1Delta","type":"int256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"ramsesV2SwapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int24","name":"_tickLower","type":"int24"},{"internalType":"int24","name":"_tickUpper","type":"int24"},{"internalType":"uint128","name":"_liquidity","type":"uint128"},{"internalType":"uint256","name":"_amount0Min","type":"uint256"},{"internalType":"uint256","name":"_amount1Min","type":"uint256"},{"internalType":"uint64","name":"_deadline","type":"uint64"}],"name":"removeLiquidity","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rewardClaimer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"router1Inch","outputs":[{"internalType":"contract IGenericRouter1Inch","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"uint24","name":"entryFee","type":"uint24"},{"internalType":"uint24","name":"exitFee","type":"uint24"},{"internalType":"uint24","name":"performanceFee","type":"uint24"},{"internalType":"uint24","name":"managementFee","type":"uint24"}],"internalType":"struct ITeaVaultV3Pair.FeeConfig","name":"_feeConfig","type":"tuple"}],"name":"setFeeConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_rewardClaimer","type":"address"}],"name":"setRewardClaimer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_lxpL","type":"address"}],"name":"setUpLxpL","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_zeroForOne","type":"bool"},{"internalType":"uint256","name":"_amountIn","type":"uint256"}],"name":"simulateSwapInputSingleInternal","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"executor","type":"address"},{"components":[{"internalType":"address","name":"srcToken","type":"address"},{"internalType":"address","name":"dstToken","type":"address"},{"internalType":"address payable","name":"srcReceiver","type":"address"},{"internalType":"address payable","name":"dstReceiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minReturnAmount","type":"uint256"},{"internalType":"uint256","name":"flags","type":"uint256"}],"internalType":"struct IGenericRouter1Inch.SwapDescription","name":"desc","type":"tuple"},{"internalType":"bytes","name":"permit","type":"bytes"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"swap","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"},{"internalType":"uint256","name":"spentAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_zeroForOne","type":"bool"},{"internalType":"uint256","name":"_amountIn","type":"uint256"},{"internalType":"uint256","name":"_amountOutMin","type":"uint256"},{"internalType":"uint160","name":"_minPriceInSqrtPriceX96","type":"uint160"},{"internalType":"uint64","name":"_deadline","type":"uint64"}],"name":"swapInputSingle","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_zeroForOne","type":"bool"},{"internalType":"uint256","name":"_amountOut","type":"uint256"},{"internalType":"uint256","name":"_amountInMax","type":"uint256"},{"internalType":"uint160","name":"_maxPriceInSqrtPriceX96","type":"uint160"},{"internalType":"uint64","name":"_deadline","type":"uint64"}],"name":"swapOutputSingle","outputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"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":"value","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":"value","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":"amount","type":"uint256"},{"internalType":"uint256","name":"minReturn","type":"uint256"},{"internalType":"uint256[]","name":"pools","type":"uint256[]"}],"name":"uniswapV3Swap","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"srcToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minReturn","type":"uint256"},{"internalType":"uint256[]","name":"pools","type":"uint256[]"}],"name":"unoswap","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"vaultAllUnderlyingAssets","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_shares","type":"uint256"},{"internalType":"uint256","name":"_amount0Min","type":"uint256"},{"internalType":"uint256","name":"_amount1Min","type":"uint256"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"withdrawnAmount0","type":"uint256"},{"internalType":"uint256","name":"withdrawnAmount1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]

60a080604052346100ea57306080527ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005460ff8160401c166100d9576002600160401b03196001600160401b03821601610073575b604051615f8f90816100f0823960805181818161162101526117eb0152f35b6001600160401b0319166001600160401b039081177ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005581527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602090a13880610054565b63f92ee8a960e01b60005260046000fd5b600080fdfe6080604052600436101561001257600080fd5b60003560e01c8062aeef8a14610436578063014a0abc146104315780630502b1c51461042c57806306fdde0314610427578063095ea7b3146104225780630abf051d1461041d57806312aa3caf1461041857806314e048ba1461041357806316f0115b1461040e57806318160ddd1461040957806318f56a0a146104045780631d3ecf9b146103ff5780631e5eb1d0146103fa57806323b872dd146103f55780632ab48216146103f05780632d2dcc48146103eb578063313ce567146103e6578063352ddc36146103e15780633e48f417146103dc5780633ee708bc146103d7578063481c6a75146103d25780634e71d92d146103cd5780634f1ef286146103c85780635153786b146103c357806351e79718146103be57806352d1902d146103b957806360246c88146103b4578063654b6487146103af5780636d7c2a57146103aa5780637019732f146103a557806370a08231146103a0578063715018a61461039b57806373d8fe671461039657806381c7b06d1461039157806384bd6d291461038c57806387f6c4931461038757806389097a6a146103825780638c625a871461037d5780638da5cb5b14610378578063955f263a1461037357806395d89b411461036e578063973544481461036957806399fbab88146103645780639c016ffd1461035f578063a301ad2b1461035a578063a41fe49f14610355578063a9059cbb14610350578063aa3c1d401461034b578063ac9650d814610346578063ad3cb1cc14610341578063b3c40be41461033c578063b5470ad814610337578063b591b13c14610332578063bbdd366a1461032d578063c2d9ecfa14610328578063c4fa17a414610323578063dd5f47db1461031e578063dd62ed3e14610319578063e045b7b414610314578063e449022e1461030f578063f2fde38b1461030a578063f57fa78d14610305578063f68eb65714610300578063faf6d874146102fb578063fe1f4559146102f65763feda50ec146102f157600080fd5b6133a9565b61333c565b6131dd565b6131a7565b61317e565b613151565b612f93565b612f6a565b612f2a565b612d45565b612cd9565b612c7a565b612c5c565b612c3e565b612974565b61295b565b612914565b612834565b61278c565b612757565b612426565b6123a3565b61236b565b61230b565b6121ae565b6120fe565b61201c565b611fe6565b611fcc565b611ed3565b611ea5565b611d3e565b611cfd565b611c13565b611bbb565b611b71565b611b48565b611b1c565b611a23565b611831565b6117d8565b6117af565b611730565b6115ce565b611426565b6113f9565b6113b1565b611271565b61122a565b611209565b611190565b61113e565b611041565b610fea565b610fc1565b610f0d565b610e82565b610e59565b610e3b565b610db4565b610d05565b610bc6565b610ae5565b610909565b610866565b61046b565b606090600319011261045557600435906024359060443590565b600080fd5b908152602081019190915260400190565b34610455576104793661043b565b9091610483614836565b60009283821561084c57610495614886565b5061049e613ce6565b90816106695750506104b26001548361357f565b926104d3846104ca6104c5600754610884565b610884565b30903390614bf1565b831580610661575b610650576000906000926005546104f181610884565b906104fb82610884565b33036105ac575b505085119081156105a2575b5061058357907fa9655c7bb3dce82c29396162aecd039217d6e09ea6ae1fe2c13650c8570e3ecc916105408433614c3a565b604080519485526020850186905284018690526060840152608083015233918060a081015b0390a2610570614872565b61057f6040519283928361045a565b0390f35b6308f51ff960e31b6000526004849052602485905260446000fd5b6000fd5b905085113861050e565b919796945092506105ff9060a01c62ffffff16926105f962ffffff60025495166105e36105da87838a614a26565b9687928b614a26565b9687938280610631575b50508361060757613541565b96613541565b953880610502565b61062c846106196104c5600854610884565b610624600554610884565b903390614bf1565b613541565b61064991336106446104c5600754610884565b614bf1565b38826105ed565b638c88122d60e01b60005260046000fd5b5084156104db565b6106759594919561494d565b50506004546040519061069d8261068f3360208301610fae565b03601f19810184528361154a565b86915b888284106107b757505050506106ba6104c5600754610884565b956040516370a0823160e01b8152602081806106d93060048301610fae565b03818b5afa80156107b2578683916106f993600091610783575b50614a26565b906107086104c5600854610884565b90602060405180936370a0823160e01b825281806107293060048301610fae565b03915afa9081156107b25761077e9461075e610756610764938b889661076e986000916107835750614a26565b958692613541565b99613541565b9830903390614bf1565b30336106446104c5600854610884565b6104d3565b6107a5915060203d6020116107ab575b61079d818361154a565b81019061354e565b386106f3565b503d610793565b61355d565b61083761083d89869b9761062c61084395610825886108066108016107df60019c9d9e6122b7565b50948554986107fc6107f08b6122d7565b6001600160801b031690565b614a26565b614a53565b8661081f610815839960020b90565b9160181c60020b90565b90614a86565b96909461083283546122d7565b6134fa565b90613518565b95613541565b970191906106a0565b638c88122d60e01b8552600485fd5b600091031261045557565b34610455576000366003190112610455576020600a54604051908152f35b6001600160a01b031690565b6001600160a01b0381160361045557565b606435906108ae82610890565b565b608435906108ae82610890565b6101a435906108ae82610890565b6101c435906108ae82610890565b9181601f84011215610455578235916001600160401b038311610455576020808501948460051b01011161045557565b346104555760803660031901126104555760043561092681610890565b602435604435916064356001600160401b0381116104555761094c9036906004016108d9565b610957939193614836565b60035460101c6001600160a01b03163303610a7f5761097d6104c56104c5600754610884565b6001600160a01b038416908114919082159081610a64575b50610a53576020946109aa846109f094614d01565b966109b6600b54610884565b946109c56104c5600754610884565b966109d46104c5600854610884565b996040519a8b998a9963fd9a0e3f60e01b8b5260048b016135b2565b038173dbfe68fae54d9875a50fdfd9af72b149f3acc8995af480156107b25761057f91600091610a34575b50610a24614872565b6040519081529081906020820190565b610a4d915060203d6020116107ab5761079d818361154a565b38610a1b565b633539a70160e01b60005260046000fd5b9050610a776104c56104c5600854610884565b141538610995565b630190a5dd60e21b60005260046000fd5b919082519283825260005b848110610abc575050826000602080949584010152601f8019910116010190565b80602080928401015182828601015201610a9b565b906020610ae2928181520190610a90565b90565b34610455576000366003190112610455576040516000600080516020615d7a83398151915254610b1481613605565b8084529060018116908115610ba25750600114610b48575b61057f83610b3c8185038261154a565b60405191829182610ad1565b600080516020615d7a8339815191526000908152600080516020615d3a833981519152939250905b808210610b8857509091508101602001610b3c610b2c565b919260018160209254838588010152019101909291610b70565b60ff191660208086019190915291151560051b84019091019150610b3c9050610b2c565b3461045557604036600319011261045557600435610be381610890565b6024353315610c70576001600160a01b038216918215610c5a57610c228291610c0b33614020565b9060018060a01b0316600052602052604060002090565b556040519081527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560203392a3602060405160018152f35b634a1406b160e11b600052600060045260246000fd5b63e602df0560e01b600052600060045260246000fd5b9181601f84011215610455578235916001600160401b038311610455576020838186019501011161045557565b62ffffff81160361045557565b60a435906108ae82610cb3565b60e435906108ae82610cb3565b60ff81160361045557565b60c435906108ae82610cda565b60a0906101031901126104555761010490565b34610455576101e0366003190112610455576004356001600160401b03811161045557610d36903690600401610c86565b60243591906001600160401b03831161045557610d5a610db2933690600401610c86565b604435610d6681610890565b610d6e6108a1565b610d766108b0565b610d7e610cc0565b91610d87610ce5565b93610d90610ccd565b95610d9a36610cf2565b97610da36108bd565b99610dac6108cb565b9b61363f565b005b346104555761014036600319011261045557600435610dd281610890565b60e036602319011261045557610104356001600160401b03811161045557610dfe903690600401610c86565b6101243592906001600160401b03841161045557610e23610e2b943690600401610c86565b939092613a5e565b9061057f6040519283928361045a565b34610455576000366003190112610455576020600c54604051908152f35b34610455576000366003190112610455576006546040516001600160a01b039091168152602090f35b34610455576000366003190112610455576020600080516020615e3a83398151915254604051908152f35b602060408183019282815284518094520192019060005b818110610ed15750505090565b909192602060606001928651805160020b82528381015160020b848301526040858060801b039101511660408201520194019101919091610ec4565b3461045557600036600319011261045557600454610f2a81613cf9565b90610f38604051928361154a565b80825260046000908152600080516020615efa833981519152602084015b838310610f6b576040518061057f8782610ead565b600160208192604051610f7d8161152a565b85548060020b82528060181c60020b84830152848060801b039060301c166040820152815201920192019190610f56565b6001600160a01b03909116815260200190565b3461045557600036600319011261045557600d546040516001600160a01b039091168152602090f35b346104555760003660031901126104555760a060055460405190600180841b038116825262ffffff81841c16602083015262ffffff8160b81c16604083015262ffffff8160d01c16606083015260e81c6080820152f35b346104555760603660031901126104555760043561105e81610890565b60243561106a81610890565b604435906110783384614765565b9260018401611098575b61108c9350615102565b60405160018152602090f35b8284106110b4576110af8361108c950333836159f7565b611082565b8284637dc7a0d960e11b6000523360045260245260445260646000fd5b8060020b0361045557565b6001600160801b0381160361045557565b60c090600319011261045557600435611105816110d1565b90602435611112816110d1565b9060443561111f816110dc565b90606435906084359060a4356001600160401b03811681036104555790565b346104555761114c366110ed565b9093919291906001600160401b0316421161117f5760035460101c6001600160a01b03163303610a7f57610e2b94613e26565b6338e5e54b60e21b60005260046000fd5b34610455576020366003190112610455576004356111ad81610890565b6111b5615468565b6003805462010000600160b01b031916601083901b62010000600160b01b03161790556001600160a01b0316337f605c2dbf762e5f7d60a546d42e7205dcb1b011ebc62a61736a57c9089d3a4350600080a3005b3461045557600036600319011261045557602060ff60035416604051908152f35b346104555760203660031901126104555760043561124781610890565b61124f615468565b600b80546001600160a01b0319166001600160a01b0392909216919091179055005b34610455576060366003190112610455576004356024356044356001600160401b038111610455576112a7903690600401610c86565b60026009540361137b576112bf6104c5600654610884565b336001600160a01b039091160361136a57816104c5916112e0930190613f4b565b918061132a575b50806112ef57005b6001600160a01b03821661131657610db29150336113116104c5600854610884565b61549e565b610db29133906106446104c5600854610884565b6001600160a01b0383166113515761134b90336113116104c5600754610884565b386112e7565b6113659033846106446104c5600754610884565b61134b565b6333b43e6360e21b60005260046000fd5b637748745560e01b60005260046000fd5b6040906003190112610455576004356113a4816110d1565b90602435610ae2816110d1565b34610455576113bf3661138c565b60035460101c6001600160a01b03163303610a7f576113dd91613f60565b604080516001600160801b039384168152919092166020820152f35b346104555760003660031901126104555760035460405160109190911c6001600160a01b03168152602090f35b346104555760003660031901126104555761143f614836565b6114476154c5565b61145a61145333613fdf565b5433615563565b61146333614006565b54600061146f33614006565b5580611482575b61057f90610a24614872565b6114936104c56104c5600e54610884565b906020604051809363a9059cbb60e01b8252816000816114b787336004840161406e565b03925af19182156107b25761057f926114e7575b506114e06114db82600f54613d38565b600f55565b9050611476565b6115089060203d60201161150d575b611500818361154a565b810190614059565b6114cb565b503d6114f6565b634e487b7160e01b600052604160045260246000fd5b606081019081106001600160401b0382111761154557604052565b611514565b601f909101601f19168101906001600160401b0382119082101761154557604052565b604051906108ae60608361154a565b6001600160401b03811161154557601f01601f191660200190565b9291926115a38261157c565b916115b1604051938461154a565b829481845281830111610455578281602093846000960137010152565b6040366003190112610455576004356115e681610890565b6024356001600160401b038111610455573660238201121561045557611616903690602481600401359101611597565b906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630811490811561170d575b506116fc57611659615468565b6040516352d1902d60e01b8152916020836004816001600160a01b0386165afa600093816116db575b506116a557634c9c8ce360e01b6000526001600160a01b03821660045260246000fd5b90600080516020615e5a83398151915283036116c557610db29250615c12565b632a87526960e21b600052600483905260246000fd5b6116f591945060203d6020116107ab5761079d818361154a565b9238611682565b63703e46dd60e11b60005260046000fd5b600080516020615e5a833981519152546001600160a01b0316141590503861164c565b34610455576000366003190112610455576008546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa80156107b25761057f91600091611790575b506040519081529081906020820190565b6117a9915060203d6020116107ab5761079d818361154a565b3861177f565b3461045557600036600319011261045557600e546040516001600160a01b039091168152602090f35b34610455576000366003190112610455577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031630036116fc576020604051600080516020615e5a8339815191528152f35b34610455576000366003190112610455576118506104c5600654610884565b60405163ddca3f4360e01b815290602082600481845afa9182156107b2576000926119f2575b506118856104c5600754610884565b60405163313ce56760e01b81529091602082600481865afa9182156107b2576000926119d1575b506118bb6104c5600854610884565b60405163313ce56760e01b81529094602082600481895afa9182156107b25760009261199c575b5060e06004929360405193848092633850c7bd851b82525afa9283156107b25761057f94600093600095611960575b50604080516001600160a01b03988916815298881660208a015260ff9182169089015216606087015262ffffff16608086015290921660a084015260029190910b60c0830152819060e0820190565b90945061198691935060e03d60e011611995575b61197e818361154a565b8101906140ad565b50505050509290929338611911565b503d611974565b600492506119c360e09160203d6020116119ca575b6119bb818361154a565b81019061378d565b92506118e2565b503d6119b1565b6119eb91925060203d6020116119ca576119bb818361154a565b90386118ac565b611a1591925060203d602011611a1c575b611a0d818361154a565b810190614089565b9038611876565b503d611a03565b34610455576060366003190112610455576024356004356044356001600160401b03811161045557611a59903690600401610c86565b9060026009540361137b57611a726104c5600654610884565b336001600160a01b039091160361136a5782158015611af8575b611ae757611a9c91810190614116565b916000821315611add575090805b151590151514600014611aca57610db290336113116104c5600754610884565b610db290336113116104c5600854610884565b9180159150611aaa565b63030e4c8d60e41b60005260046000fd5b508315611a8c565b9094939260609260808301968352602083015260408201520152565b346104555760003660031901126104555761057f611b3861414d565b9060409492945194859485611b00565b34610455576000366003190112610455576008546040516001600160a01b039091168152602090f35b3461045557602036600319011261045557600435611b8e81610890565b60018060a01b0316600052600080516020615d9a8339815191526020526020604060002054604051908152f35b3461045557600036600319011261045557611bd4615468565b600080516020615dfa83398151915280546001600160a01b031981169091556000906001600160a01b0316600080516020615e7a8339815191528280a3005b3461045557606036600319011261045557600435611c30816110d1565b602435611c3c816110d1565b60443590611c49826110dc565b600654604080516362891e0b60e01b81526001600160a01b039092166004830152600294850b60248301529190930b60448401526001600160801b0391909116606483015281608481732ed994fd3dc53bd4010652bfc00d9805808236645af49081156107b257600090600092611ccb575b5061057f6040519283928361045a565b9050611cef915060403d604011611cf6575b611ce7818361154a565b810190613bb2565b9038611cbb565b503d611cdd565b3461045557611d0b366110ed565b9093919291906001600160401b0316421161117f5760035460101c6001600160a01b03163303610a7f57610e2b94614291565b346104555761010036600319011261045557600435611d5c81610890565b60243590611d6982610890565b60443590611d7682610890565b6064359160843560e43560c43560a435611d8e614836565b60035460101c6001600160a01b03163303610a7f57611db46104c56104c5600754610884565b6001600160a01b038916908114949085159081611e8a575b50610a535787600496611de460209a6109f098614d01565b9a611df0600b54610884565b99611dff6104c5600754610884565b9c611e0e6104c5600854610884565b6040516310c3507960e21b81529e8f9d8e9d8e016001600160a01b039182168152918116602083015291821660408201526060810192909252918216608082015291811660a083015290911660c08201526101808101969594610160949193909260e08501526101008401526101208301526101408201520152565b9050611e9d6104c56104c5600854610884565b141538611dcc565b346104555760003660031901126104555760035460101c6001600160a01b03163303610a7f576113dd61494d565b3461045557602036600319011261045557600435600454811015611fbb57600654611f43916080916001600160a01b031690611f0e906122b7565b50604051631612a31760e31b81523060048201526001600160a01b039092166024830152604482015291829081906064820190565b0381732ed994fd3dc53bd4010652bfc00d9805808236645af480156107b2576000809160008091611f80575b9061057f9160405194859485611b00565b50505050611fa861057f9160803d608011611fb4575b611fa0818361154a565b81019061412b565b91935083929190611f6f565b503d611f96565b63f7b3b39160e01b60005260046000fd5b346104555761057f611b38611fe03661138c565b90614386565b3461045557600036600319011261045557600080516020615dfa833981519152546040516001600160a01b039091168152602090f35b3461045557608036600319011261045557600435612039816110d1565b602435612045816110d1565b6044356064359160018060a01b0360065416936040519463361d23b760e21b8652600486015260020b602485015260020b60448401526064830152608482015260208160a481732ed994fd3dc53bd4010652bfc00d9805808236645af480156107b25761057f916000916120cf575b506040516001600160801b0390911681529081906020820190565b6120f1915060203d6020116120f7575b6120e9818361154a565b810190614467565b386120b4565b503d6120df565b34610455576000366003190112610455576040516000600080516020615dda8339815191525461212d81613605565b8084529060018116908115610ba257506001146121545761057f83610b3c8185038261154a565b600080516020615dda8339815191526000908152600080516020615eda833981519152939250905b80821061219457509091508101602001610b3c610b2c565b91926001816020925483858801015201910190929161217c565b34610455576020366003190112610455576004356121cb81610890565b6121d3615468565b6001600160a01b03811680612290576121f36104c56104c5600754610884565b8114908115612276575b50612265576122106104c5600e54610884565b612254576a0c097ce7bc90715b34b9f160241b60105561224c90600e80546001600160a01b0319166001600160a01b0392909216919091179055565b610db26154c5565b63aff01e7360e01b60005260046000fd5b63c1ab6dc160e01b60005260046000fd5b90506122896104c56104c5600854610884565b14386121fd565b63d92e233d60e01b60005260046000fd5b634e487b7160e01b600052603260045260246000fd5b6004548110156122d257600460005260206000200190600090565b6122a1565b60301c6001600160801b031690565b600291820b815291900b60208201526001600160801b03909116604082015260600190565b3461045557602036600319011261045557600435600454811015610455576004600052600080516020615efa833981519152015460405190819061057f90603081901c6001600160801b031690601881901c600290810b91900b846122e6565b346104555760003660031901126104555760035460101c6001600160a01b03163303610a7f57602061239b614886565b604051908152f35b346104555760003660031901126104555760206123be61453c565b60065460405163092df84160e31b81529392849283926123eb92906001600160a01b03166004850161447c565b0381732ed994fd3dc53bd4010652bfc00d9805808236645af480156107b25761057f9160009161179057506040519081529081906020820190565b34610455576124343661043b565b909161243e614836565b60008180156127485761244f614886565b50612458613ce6565b92829060055461246781610884565b9061247182610884565b33036126f9575b50505061248582336156ef565b6004549261249161494d565b50506124a16104c5600754610884565b602060405180926370a0823160e01b825281806124c13060048301610fae565b03915afa9182156107b2576124e09287928692916126da575b506157ac565b926124ef6104c5600854610884565b602060405180926370a0823160e01b8252818061250f3060048301610fae565b03915afa80156107b25784879161252d936000916126da57506157ac565b9460005b828110612637575050506000945b600454808710156125a6576125606107f0612559896122b7565b50546122d7565b6125955761257861257361258892613d29565b6122b7565b50612582886122b7565b90613d63565b612590613dc5565b61253f565b50946125a09061449a565b9461253f565b5086841090811561262d575b50612612576105657f43394472faf6e72a904b108d59ae00f2935bfcdd08137aeb9f78e79aa366bcc5916125ef85336113116104c5600754610884565b61260286336113116104c5600854610884565b6040519182918787339785611b00565b6308f51ff960e31b6000526004839052602484905260446000fd5b90508410856125b2565b612643819796976122b7565b508054966126518860020b90565b9887856126618b60181c60020b90565b9a61266b906122d7565b6001600160801b03169161267e926157ac565b61268790614a53565b996126938b8b83615278565b9a61269e9192615356565b50506126a991613541565b976126b391613541565b9781546126bf906122d7565b906126c991613d10565b6126d291613518565b600101612531565b6126f3915060203d6020116107ab5761079d818361154a565b386124da565b91935061272e92509061271d9060b81c62ffffff1662ffffff600254911685614a26565b9283918280612737575b5050613d38565b90388080612478565b6127419133615102565b3882612727565b638c88122d60e01b8252600482fd5b346104555760403660031901126104555761278160043561277781610890565b6024359033615102565b602060405160018152f35b346104555760003660031901126104555760206127a761453c565b600654604051637d5dbf5160e11b81529392849283926123eb92906001600160a01b03166004850161447c565b602081016020825282518091526040820191602060408360051b8301019401926000915b83831061280757505050505090565b9091929394602080612825600193603f198682030187528951610a90565b970193019301919392906127f8565b34610455576020366003190112610455576004356001600160401b038111610455576128649036906004016108d9565b9061286e82613cf9565b9161287c604051938461154a565b808352601f1961288b82613cf9565b0160005b81811061290357505060005b8181106128b0576040518061057f86826127d4565b806128e76000806128c460019587896144a9565b906128d4604051809381936144ea565b0390305af46128e16144f8565b9061583e565b6128f18287614528565b526128fc8186614528565b500161289b565b80606060208093880101520161288f565b346104555760003660031901126104555761057f6040805190612937818361154a565b60058252640352e302e360dc1b602083015251918291602083526020830190610a90565b3461045557600036600319011261045557610e2b61453c565b346104555760403660031901126104555760043561299181610890565b60243561299d81610890565b600d546001600160a01b03163303612c2d576129b7614836565b6001600160a01b0381169182156122905760405163c4f59f9b60e01b815291906001600160a01b0316600083600481845afa9283156107b257600093612c08575b506004939293549060005b828110612b7c57505050612a18600754610884565b92612a24600854610884565b6001600160a01b03909416939060005b8151811015612b4e576001600160a01b03612a626104c5612a558486614528565b516001600160a01b031690565b16908682141580612b3b575b612a7d575b6001915001612a34565b6040516370a0823160e01b81529160208380612a9c3060048301610fae565b0381845afa9081156107b257600193600092612b1b575b5086600554612ada612acb8262ffffff9060d01c1690565b62ffffff600254911686614a26565b808511612aec575b5050505050612a73565b612b1194612b0682612b00612b0b95610884565b8761549e565b613d38565b9161549e565b3880868180612ae2565b612b3491925060203d81116107ab5761079d818361154a565b9038612ab3565b506001600160a01b038416821415612a6e565b847f29e197049bed9d0535b455fed2dc45b916a0de23b14a030659e8220ee42b2f20600080a2610db2614872565b612b88819695966122b7565b505490612ba2612b988360020b90565b9260181c60020b90565b833b156104555786600091612bce60405195869384936318d9dceb60e31b855230923060048701614697565b038183875af19182156107b257600192612bed575b5001949394612a03565b80612bfc6000612c029361154a565b8061085b565b38612be3565b612c269193503d806000833e612c1e818361154a565b810190614614565b91386129f8565b63c18e0ea960e01b60005260046000fd5b34610455576000366003190112610455576020600254604051908152f35b34610455576000366003190112610455576020600154604051908152f35b34610455576000366003190112610455576007546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa80156107b25761057f9160009161179057506040519081529081906020820190565b34610455576000366003190112610455576020600054604051908152f35b8015150361045557565b60a090600319011261045557600435612d1981612cf7565b906024359060443590606435612d2e81610890565b906084356001600160401b03811681036104555790565b3461045557612d5336612d01565b6003549394919391929160101c6001600160a01b03163303610a7f576001600160401b0316421161117f57612e1692612d8c6002600955565b6040612d9c6104c5600654610884565b612dad612da88861584b565b61471b565b6001600160a01b03841615939091908415612f25575060008615612f0a57506401000276a45b8351871515602082015292600090612df885604081015b03601f19810187528661154a565b8551630251596160e31b8152998a95869485938c306004870161472c565b03925af180156107b257600094600091612ee5575b50612e366001600955565b8315612ed557612e459061471b565b905b80612ecb575b612eaf57508211612e945761057f92600080516020615dba833981519152612e81600093604051918291151594878361045a565b0390a36040519081529081906020820190565b6308f51ff960e31b6000908152600483905260245260446000fd5b6308f51ff960e31b600090815260049190915260245260446000fd5b5084811415612e4d565b93612edf9061471b565b90612e47565b9050612f0191945060403d604011611cf657611ce7818361154a565b93909338612e2b565b5073fffd8963efd1fc6a506488495d951d5263988d25612dd3565b612dd3565b34610455576040366003190112610455576020612f61600435612f4c81610890565b610c0b60243591612f5c83610890565b614020565b54604051908152f35b34610455576000366003190112610455576007546040516001600160a01b039091168152602090f35b34610455576060366003190112610455576024356004356044356001600160401b03811161045557612fc99036906004016108d9565b929091612fd4614836565b60035460101c6001600160a01b03163303610a7f5760046020612ff78686614776565b356001600160a01b03811690600160ff1b1661310857604051630dfe168160e01b815292839182905afa9081156107b2576000916130d9575b50935b6130446104c56104c5600754610884565b6001600160a01b03909516948514908115806130bf575b610a535760209461306f846109f094614d01565b9461307b600b54610884565b9461308a6104c5600754610884565b966130996104c5600854610884565b996130a389610884565b146040519a8b998a99634eb2fed360e11b8b5260048b0161477f565b506130d16104c56104c5600854610884565b86141561305b565b6130fb915060203d602011613101575b6130f3818361154a565b810190613778565b38613030565b503d6130e9565b60405163d21220a760e01b815292839182905afa9081156107b257600091613132575b5093613033565b61314b915060203d602011613101576130f3818361154a565b3861312b565b3461045557602036600319011261045557610db260043561317181610890565b613179615468565b6147d2565b3461045557600036600319011261045557600b546040516001600160a01b039091168152602090f35b346104555760a0366003190112610455576131c0615468565b6131c8614886565b506131d161494d565b5050610db2600461503d565b34610455576131eb36612d01565b6003549394929360101c6001600160a01b03163303610a7f576001600160401b0316421161117f576040613293916132236002600955565b6132316104c5600654610884565b61323a8761584b565b916001600160a01b03811661333757506000851561331c57506401000276a45b83518615156020820152926000906132758560408101612dea565b8551630251596160e31b8152968795869485938b306004870161472c565b03925af180156107b2576132c3916000906000926132fa575b506132b76001600955565b83156132f3575061471b565b918210612e945761057f92600080516020615dba83398151915283600193612e816040519283921515958361045a565b905061471b565b9050613315915060403d604011611cf657611ce7818361154a565b90386132ac565b5073fffd8963efd1fc6a506488495d951d5263988d2561325a565b61325a565b346104555760203660031901126104555760043561335981610890565b613361615468565b6001600160a01b0316801561229057600d80546001600160a01b031916821790557fc5d42db7f469ababda43f710e99bd448d225e03f44c6c524448095c41dc606c2600080a2005b34610455576040366003190112610455576004356133c681612cf7565b60243560035460101c6001600160a01b03163303610a7f57600080916133ec6002600955565b6134036133fd6104c5600654610884565b9161584b565b828584146134c85750826401000276a45b6040805188151560208083019190915281529161346691613435908461154a565b6134586040519384926020840197630251596160e31b89528c306024870161472c565b03601f19810183528261154a565b51925af16134726144f8565b9061347d6001600955565b156104555760209161349a8284806134a695518301019101613bb2565b91156132f3575061471b565b6040518281019182526134c69080602084010390601f198201815261154a565bfd5b508273fffd8963efd1fc6a506488495d951d5263988d25613414565b634e487b7160e01b600052601160045260246000fd5b6001600160801b03918216908216019190821161351357565b6134e4565b8054600160301b600160b01b03191660309290921b600160301b600160b01b0316919091179055565b9190820180921161351357565b90816020910312610455575190565b6040513d6000823e3d90fd5b634e487b7160e01b600052601260045260246000fd5b8115613589570490565b613569565b81835290916001600160fb1b0383116104555760209260051b809284830137010190565b6001600160a01b039182168152918116602083015291821660408201526060810192909252909116608082015260a081019190915260c081019190915261010060e08201819052610ae29391019161358e565b90600182811c92168015613635575b602083101461361f57565b634e487b7160e01b600052602260045260246000fd5b91607f1691613614565b9a98969492909160ff9c9a9896949261366d600080516020615f3a833981519152549e8f60401c1615151590565b9d6001600160401b03168015908f8261375f575b506001149081613755575b15908161374c575b5061373b57600080516020615f3a83398151915280546001600160401b03191660011790556136c79c8e613716576137b6565b6136cd57565b600080516020615f3a833981519152805460ff60401b19169055604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602090a1565b600080516020615f3a833981519152805460ff60401b1916600160401b1790556137b6565b63f92ee8a960e01b60005260046000fd5b90501538613694565b303b15915061368c565b91508f613681565b60ff16604d811161351357600a0a90565b908160209103126104555751610ae281610890565b908160209103126104555751610ae281610cda565b9060ff8091169116019060ff821161351357565b6137e6906137ee93926137d76137f4979b9c9d9e6137d2615a25565b614d67565b6137df614d7b565b3691611597565b923691611597565b90614d8b565b6001600160a01b0381811694908316939084861015613a4d57613892936020936138216301e13380600055565b61383261382d8a613767565b600155565b61383e620f4240600255565b61385261050061ff00196003541617600355565b604051630b4c774160e11b81526001600160a01b0391821660048201529116602482015262ffffff90921660448301529092839190829081906064820190565b03916001600160a01b03165afa80156107b2576138d491600091613a2e575b50600680546001600160a01b0319166001600160a01b0392909216919091179055565b6006546001600160a01b03906138ed906104c590610884565b1615613a1d57600780546001600160a01b039384166001600160a01b03199182161790915560088054929093169116179055600460206139316104c5600754610884565b60405163313ce56760e01b815292839182905afa80156107b25761397192613961926000926139fc575b506137a2565b60ff1660ff196003541617600355565b61397b6001600955565b62ffffff6002549116908110156139eb576139c39261399c6139be92600c55565b600d80546001600160a01b0319166001600160a01b0392909216919091179055565b61503d565b307fdf71cb001a7432934a99d34855dc0f49942e430ce37c4d0ba3ba654079162ed7600080a2565b63035f0ce760e21b60005260046000fd5b613a1691925060203d6020116119ca576119bb818361154a565b903861395b565b63486aa30760e01b60005260046000fd5b613a47915060203d602011613101576130f3818361154a565b386138b1565b633f06bf8160e01b60005260046000fd5b919493613a69614836565b60035460101c6001600160a01b03163303610a7f57613a886024613ba8565b90613a9a6104c56104c5600754610884565b916001600160a01b031682141580613b7a575b610a5357604094613b2092613ad9906001600160a01b03613ace6024613ba8565b161460a43590614d01565b97613ae5600b54610884565b946024613af66104c5600754610884565b97613b056104c5600854610884565b9b8a519c8d9a8b9a634a94292360e11b8c5260048c01613bf4565b038173dbfe68fae54d9875a50fdfd9af72b149f3acc8995af49182156107b257600090600093613b56575b5091906108ae614872565b9050613b7291925060403d604011611cf657611ce7818361154a565b919038613b4b565b50613b856024613ba8565b613b966104c56104c5600854610884565b6001600160a01b039091161415613aad565b35610ae281610890565b9190826040910312610455576020825192015190565b35906108ae82610890565b908060209392818452848401376000828201840152601f01601f1916010190565b6001600160a01b0391821681529181166020830152918216604082015260608101929092529091166080820152610ae295909490939092613cd79290919060c0908035613c4081610890565b6001600160a01b031660a08901526020810135613c5c81610890565b6001600160a01b0316888301526040810135613c7781610890565b6001600160a01b031660e0890152613ca5613c9460608301613bc8565b6001600160a01b03166101008a0152565b608081013561012089015260a081013561014089015201356101608701526101c06101808701526101c0860191613bd3565b926101a0818503910152613bd3565b600080516020615e3a8339815191525490565b6001600160401b0381116115455760051b60200190565b6001600160801b03918216908216039190821161351357565b60001981019190821161351357565b9190820391821161351357565b9081549060181b65ffffff000000169065ffffff0000001916179055565b90613daf57818103613d73575050565b8154815462ffffff191662ffffff9091161781556108ae91613d9c815460181c60020b83613d45565b5460301c6001600160801b031690613518565b634e487b7160e01b600052600060045260246000fd5b6004548015613e10576000198101906004548210156122d257600460008181527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19a9092019190915555565b634e487b7160e01b600052603160045260246000fd5b9492919093946004549160005b838110613e4b5763f7b3b39160e01b60005260046000fd5b613e54816122b7565b508054613e618160020b90565b8560020b9060020b149081613f34575b50613e7f5750600101613e33565b92613e8f849892959697986151ec565b5050613e9c838383615278565b9990978810908115613f2a575b50613f0f5790613eb891615356565b5050613ec482546122d7565b6001600160801b0381811690831603613eff57505050612582613eec612573613ef394613d29565b50916122b7565b613efb613dc5565b9190565b613efb9450610837929350613d10565b6308f51ff960e31b6000526004879052602489905260446000fd5b9050891038613ea9565b60181c60020b90508860020b9060020b1438613e71565b908160209103126104555735610ae281610890565b906004549160005b838110613f805763f7b3b39160e01b60005260046000fd5b6004548110156122d25760046000528060206000200180548360020b8160020b149081613fc8575b50613fb65750600101613f68565b92505050613fc491506151ec565b9091565b60181c60020b90508460020b9060020b1438613fa8565b6001600160a01b03166000908152600080516020615d9a8339815191526020526040902090565b6001600160a01b0316600090815260126020526040902090565b6001600160a01b031660009081527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace016020526040902090565b908160209103126104555751610ae281612cf7565b6001600160a01b039091168152602081019190915260400190565b908160209103126104555751610ae281610cb3565b519061ffff8216820361045557565b908160e09103126104555780516140c381610890565b9160208201516140d2816110d1565b916140df6040820161409e565b916140ec6060830161409e565b916140f96080820161409e565b9160c060a083015161410a81610cda565b920151610ae281612cf7565b908160209103126104555735610ae281612cf7565b9190826080910312610455578151916020810151916060604083015192015190565b600090600090600090600090600454600090732ed994fd3dc53bd4010652bfc00d9805808236645b81831061418157505050565b9091939495966141a06080614197600654610884565b611f0e886122b7565b0381865af49182156107b2576001926141e492600080809281946141ed575b50906141d26141d8926141de9596613541565b9d613541565b9a613541565b97613541565b94019190614175565b6141de94506141d293506141d89250614214915060803d8111611fb457611fa0818361154a565b9550939092506141bf565b60045490600160401b82101561154557600182016004556000916004548110156122d25760208360046108ae955220019061426d815160020b839062ffffff198254169062ffffff16179055565b61427e602082015160020b83613d45565b604001516001600160801b031690613518565b90949291936004546000905b808210614312575060035460081c60ff161461430157846142ca6142fc926108ae956142ec988a876155c7565b9690976142e26142d861156d565b95869060020b9052565b60020b6020850152565b6001600160801b03166040830152565b61421f565b633a37518960e21b60005260046000fd5b9061431c816122b7565b5080546143298160020b90565b8660020b9060020b14908161436f575b5061434857506001019061429d565b93614362939250613efb95915096610837988197986155c7565b95909361083283546122d7565b60181c60020b90508960020b9060020b1438614339565b6004549160005b8381106143a55763f7b3b39160e01b60005260046000fd5b6143ae816122b7565b50546143ba8160020b90565b8460020b9060020b149081614450575b506143d75760010161438d565b90506143f6925060809150611f0e6143f0600654610884565b916122b7565b0381732ed994fd3dc53bd4010652bfc00d9805808236645af480156107b2576000928380938193614429575b5093929190565b9250509250614446915060803d8111611fb457611fa0818361154a565b9193909238614422565b60181c60020b90508260020b9060020b14386143ca565b908160209103126104555751610ae2816110dc565b604091949392606082019560018060a01b0316825260208201520152565b60001981146135135760010190565b91908110156122d25760051b81013590601e19813603018212156104555701803591906001600160401b038311610455576020018236038113610455579190565b908092918237016000815290565b3d15614523573d906145098261157c565b91614517604051938461154a565b82523d6000602084013e565b606090565b80518210156122d25760209160051b010190565b6145549061455a61454b61414d565b92959195613541565b93613541565b916145696104c5600754610884565b90602060405180936370a0823160e01b8252818061458a3060048301610fae565b03915afa9081156107b2576145a7926000926145f3575b50613541565b916145b66104c5600854610884565b90602060405180936370a0823160e01b825281806145d73060048301610fae565b03915afa9081156107b257610ae2926000926145f35750613541565b61460d91925060203d6020116107ab5761079d818361154a565b90386145a1565b602081830312610455578051906001600160401b03821161045557019080601f8301121561045557815161464781613cf9565b92614655604051948561154a565b81845260208085019260051b82010192831161045557602001905b82821061467d5750505090565b60208091835161468c81610890565b815201910190614670565b95949392909160c087019260018060a01b031687526000602088015260020b604087015260020b606086015260c060808601528151809152602060e0860192019060005b8181106146fc575050506001600160a01b0390911660a09390930192909252565b82516001600160a01b03168452602093840193909201916001016146db565b600160ff1b81146135135760000390565b6001600160a01b039182168152911515602083015260408201929092529116606082015260a060808201819052610ae292910190610a90565b90610c0b61477292614020565b5490565b90156122d25790565b6001600160a01b039182168152918116602083015290911660408201529015156060820152608081019190915260a081019190915260c081019190915261010060e08201819052610ae29391019161358e565b6001600160a01b0316801561482057600080516020615dfa83398151915280546001600160a01b0319811683179091556001600160a01b0316600080516020615e7a833981519152600080a3565b631e4fbdf760e01b600052600060045260246000fd5b6002600080516020615f1a8339815191525414614861576002600080516020615f1a83398151915255565b633ee5aeb560e01b60005260046000fd5b6001600080516020615f1a83398151915255565b600090600a54804203904282116135135742036148a05750565b91506148d06005549262ffffff8460e81c160280600254600054028181116000146149275703905b6107fc613ce6565b9182806148e3575b50506108ae42600a55565b6148ef6148f492610884565b614c3a565b6040518281527f147fac6415bee3006ba6002a9a6636f492d311690c9e52a2421afc6392e0fb9590602090a138826148d8565b50506001906148c8565b600291820b815291900b60208201526000604082015260600190565b6000906000906004546000905b80821061496d5750506108ae8284615870565b90926149bb9061497c856122b7565b50604061498d6104c5600654610884565b82549061499d612b988360020b90565b916000845180988195829463a34123a760e01b845260048401614931565b03925af19081156107b2576001936149e792614a02575b50546149e16108158260020b90565b90615356565b9601608083901b83900390811696919091011693019061495a565b614a199060403d8111611cf657611ce7818361154a565b506149d2565b1561045557565b929190614a348282866157ac565b9382156135895709614a4257565b906000198110156104555760010190565b6001600160801b038111614a6d576001600160801b031690565b6306dfcc6560e41b600052608060045260245260446000fd5b939291906001600160801b03821615614b9c57614aa36002600955565b604082614ab46104c5600654610884565b83600089614ad88651998a9687958694633c8a7d8d60e01b86523060048701614bad565b03925af19485156107b257600093600096614b67575b5090600080516020615d5a83398151915291614b0a6001600955565b614b60878660018060a01b03614b246104c5600654610884565b60408051600297880b81529790960b60208801526001600160801b039098169486019490945260608501526080840152931692819060a0820190565b0390a29190565b614b93919650600080516020615d5a83398151915292945060403d604011611cf657611ce7818361154a565b95909391614aee565b630200e8a960e31b60005260046000fd5b6001600160a01b039091168152600291820b602082015291900b60408201526001600160801b03909116606082015260a060808201819052610ae292910190610a90565b6040516323b872dd60e01b60208201526001600160a01b0392831660248201529290911660448301526064808301939093529181526108ae91614c3560848361154a565b61597c565b6001600160a01b03811691908215614ceb57601054614cb9575b600080516020615e3a833981519152549082820180921161351357600092614c9e614cb492600080516020615e9a83398151915294600080516020615e3a83398151915255613fdf565b8054820190556040519081529081906020820190565b0390a3565b614cc16154c5565b82600052600080516020615d9a833981519152602052614ce660406000205482615563565b614c54565b63ec442f0560e01b600052600060045260246000fd5b600091908291604051906020820192633fb6943b60e21b845215156024830152604482015260448152614d3560648261154a565b5190305af4614d426144f8565b9015614d4d57600080fd5b805190811561045557602080610ae293830101910161354e565b6108ae90614d73615a25565b613179615a25565b614d83615a25565b614872615a25565b614d93615a25565b614d9b615a25565b8051906001600160401b03821161154557614dcd82614dc8600080516020615d7a83398151915254613605565b615a53565b602090601f8311600114614e23579180614e03926108ae9594600092614e18575b50508160011b916000199060031b1c19161790565b600080516020615d7a83398151915255615b05565b015190503880614dee565b600080516020615d7a833981519152600052601f1983169190600080516020615d3a8339815191529260005b818110614e9d57509160019391856108ae97969410614e84575b505050811b01600080516020615d7a83398151915255615b05565b015160001960f88460031b161c19169055388080614e69565b92936020600181928786015181550195019301614e4f565b35610ae281610cb3565b9062ffffff8091169116019062ffffff821161351357565b614f9f60806108ae928035614eeb81610890565b600580546001600160a01b0319166001600160a01b03929092169190911790556020810135614f1981610cb3565b6005549062ffffff60a01b9060a01b168062ffffff60a01b198316176005556040830135614f4681610cb3565b65ffffffffffff60a01b199092161760b89190911b62ffffff60b81b1617600555614f99614f7660608301614eb5565b6005805462ffffff60d01b191660d09290921b62ffffff60d01b16919091179055565b01614eb5565b600580546001600160e81b031660e89290921b6001600160e81b031916919091179055565b90929162ffffff608060a09260c085019685528035614fe281610890565b600180861b03166020860152826020820135614ffd81610cb3565b16604086015282604082013561501281610cb3565b16606086015282606082013561502781610cb3565b1682860152013561503781610cb3565b16910152565b62ffffff61506261505060208401614eb5565b61505c60408501614eb5565b90614ebf565b600c5491829116116150da578062ffffff61507f60608501614eb5565b16116150da5762ffffff61509560808401614eb5565b16116150da576150a481614ed7565b7f9b77979ce4de4fc68093eab0fd33625b0cc9f868dbfa1df90cdc46b7e056cb2e604051806150d533944283614fc4565b0390a2565b63390edff560e11b60005260046000fd5b6001600160a01b0316600452602452604452606490565b916001600160a01b0383169182156151d6576001600160a01b038116938415614ceb5760105461517f575b61513681613fdf565b5483811061516857614cb4928492615162600080516020615e9a83398151915296614c9e940391613fdf565b55613fdf565b63391434e360e21b60005261059e918491906150eb565b6151876154c5565b83600052600080516020615d9a8339815191526020526151ac60406000205482615563565b84600052600080516020615d9a8339815191526020526151d160406000205483615563565b61512d565b634b637e8f60e11b600052600060045260246000fd5b600090604061522760018060a01b03600654168354835195868094819363a34123a760e01b83528060181c60020b9060020b60048401614931565b03925af19182156107b25761524e9261525a575b50548060020b9060181c60020b90615356565b90916108ae8284615870565b6152729060403d604011611cf657611ce7818361154a565b5061523b565b92916001600160801b03811615614b9c576006546040805163a34123a760e01b8152939184906001600160a01b0316816000816152ba88888d600485016122e6565b03925af19485156107b2576000936000966152fc575b5090600080516020615e1a83398151915291614b60878660018060a01b03614b246104c5600654610884565b615328919650600080516020615e1a83398151915292945060403d604011611cf657611ce7818361154a565b959093916152d0565b9190826040910312610455576020825161534a816110dc565b920151610ae2816110dc565b600654604080516309e3d67b60e31b8152306004820152600284810b602483015285900b60448201526001600160801b036064820181905260848201529394929391829060a49082906000906001600160a01b03165af19384156107b257600091600095615425575b50600080516020615eba8339815191529085946150d5849760018060a01b036153ec6104c5600654610884565b60408051600296870b81529690950b60208701526001600160801b03978816948601949094529516606084015293169281906080820190565b615459919550600080516020615eba833981519152925060403d604011615461575b615451818361154a565b810190615331565b9490916153bf565b503d615447565b600080516020615dfa833981519152546001600160a01b0316330361548957565b63118cdaa760e01b6000523360045260246000fd5b614c356108ae939261068f60405194859263a9059cbb60e01b60208501526024840161406e565b600e546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa9081156107b257600091615544575b50600f5490818111615510575050565b6114db61553f6155376155266108ae9585613d38565b601054615531613ce6565b916157ac565b601154613541565b601155565b61555d915060203d6020116107ab5761079d818361154a565b38615500565b906011549060018060a01b0383169182600052601260205260016040600020015481039081116135135761559a91601054916157ac565b90600052601260205260406000208054918201809211613513575560016155c360115492614006565b0155565b919492946040519160006020840152602083526155e560408461154a565b6001600160801b03821615614b9c5760406156346000946156066002600955565b6156146104c5600654610884565b908351968780948193633c8a7d8d60e01b835289898d3060048701614bad565b03925af19384156107b25760009384956156ba575b5090600080516020615d5a833981519152916156656001600955565b61567f868660018060a01b03614b246104c5600654610884565b0390a28193819582109081156156b0575b50615699575050565b6308f51ff960e31b60005260045260245260446000fd5b9050821038615690565b6156e6919550600080516020615d5a83398151915292945060403d604011611cf657611ce7818361154a565b94909391615649565b6001600160a01b038116919082156151d65760105461577a575b61571281613fdf565b548281106157655782600080516020615e9a8339815191529261573d60009695614cb4940391613fdf565b55610a2481600080516020615e3a8339815191525403600080516020615e3a83398151915255565b63391434e360e21b60005261059e92916150eb565b6157826154c5565b82600052600080516020615d9a8339815191526020526157a760406000205482615563565b615709565b9091600019838309928083029283808610950394808603951461582b579082916157d7868411614a1f565b09818060000316809204600281600302188082026002030280820260020302808202600203028082026002030280820260020302809102600203029360018380600003040190848311900302920304170290565b5050915061583a821515614a1f565b0490565b9091906108ae5750615cb9565b6001600160ff1b03811161585c5790565b63123baf0360e11b60005260045260246000fd5b600554917f332be93540ee368b088c0f9d4f6e5288d4ea5832df09318be7b59409050a5ed2916150d560d085901c62ffffff1660025462ffffff90911695906158d7906158c781896001600160801b038816614a26565b976001600160801b038716614a26565b90868061595a575b505080615932575b6006546001600160a01b0390615900906104c590610884565b604080516001600160801b03968716815296909516602087015293850196909652606084015293169281906080820190565b615955816159446104c5600854610884565b61594f600554610884565b9061549e565b6158e7565b6159759161594f61596f6104c5600754610884565b91610884565b38866158df565b6000806159a59260018060a01b03169360208151910182865af161599e6144f8565b9083615cf3565b80519081151591826159dc575b50506159bb5750565b635274afe760e01b60009081526001600160a01b0391909116600452602490fd5b6159ef9250602080918301019101614059565b1538806159b2565b906001600160a01b03821615610c70576001600160a01b03811615610c5a57610c0b615a2292614020565b55565b60ff600080516020615f3a8339815191525460401c1615615a4257565b631afcd79f60e31b60005260046000fd5b601f8111615a5f575050565b600080516020615d7a8339815191526000526020600020906020601f840160051c83019310615aa9575b601f0160051c01905b818110615a9d575050565b60008155600101615a92565b9091508190615a89565b601f8211615ac057505050565b6000526020600020906020601f840160051c83019310615afb575b601f0160051c01905b818110615aef575050565b60008155600101615ae4565b9091508190615adb565b80519091906001600160401b03811161154557615b4881615b34600080516020615dda83398151915254613605565b600080516020615dda833981519152615ab3565b602092601f8211600114615b8b57615b7992938291600092614e185750508160011b916000199060031b1c19161790565b600080516020615dda83398151915255565b600080516020615dda833981519152600052601f19821693600080516020615eda8339815191529160005b868110615bfa5750836001959610615be1575b505050811b01600080516020615dda83398151915255565b015160001960f88460031b161c19169055388080615bc9565b91926020600181928685015181550194019201615bb6565b90813b15615c9757600080516020615e5a83398151915280546001600160a01b0319166001600160a01b0384169081179091557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a2805115615c7d57615c7a91615cd9565b50565b505034615c8657565b63b398979f60e01b60005260046000fd5b50634c9c8ce360e01b60009081526001600160a01b0391909116600452602490fd5b805115615cc857805190602001fd5b630a12f52160e11b60005260046000fd5b600080610ae293602081519101845af4615cf16144f8565b915b90615cfe5750615cb9565b81511580615d30575b615d0f575090565b639996b31560e01b60009081526001600160a01b0391909116600452602490fd5b50803b15615d0756fe2ae08a8e29253f69ac5d979a101956ab8f8d9d7ded63fa7a83b16fc47648eab066003071e0f230260f5b0fcf3f58155206656900735cc736441b88ac6096acf652c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0352c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0089a0f954e20890e6f71ce02a4e8655fe6262b4e86117de9a0153620430af4ab752c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace049016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c1993008a3055ac2acbcc6bc795808b7df870b7b6dc76d3de454815764a611d9d19e2c252c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace02360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efdf59c04fc608cf72d827f0db12fc26499265dd6f84db95810fb62454e0979c1f46a2803e59a4de4e7a4c574b1243f25977ac4c77d5a1a4a609b5394cebb4a2aa8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00f0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00a2646970667358221220be6b7b954331ee9e2c368ba1fd0708b0055339f19de764d78fb0014943f7c7ae64736f6c634300081a0033

Deployed Bytecode

0x6080604052600436101561001257600080fd5b60003560e01c8062aeef8a14610436578063014a0abc146104315780630502b1c51461042c57806306fdde0314610427578063095ea7b3146104225780630abf051d1461041d57806312aa3caf1461041857806314e048ba1461041357806316f0115b1461040e57806318160ddd1461040957806318f56a0a146104045780631d3ecf9b146103ff5780631e5eb1d0146103fa57806323b872dd146103f55780632ab48216146103f05780632d2dcc48146103eb578063313ce567146103e6578063352ddc36146103e15780633e48f417146103dc5780633ee708bc146103d7578063481c6a75146103d25780634e71d92d146103cd5780634f1ef286146103c85780635153786b146103c357806351e79718146103be57806352d1902d146103b957806360246c88146103b4578063654b6487146103af5780636d7c2a57146103aa5780637019732f146103a557806370a08231146103a0578063715018a61461039b57806373d8fe671461039657806381c7b06d1461039157806384bd6d291461038c57806387f6c4931461038757806389097a6a146103825780638c625a871461037d5780638da5cb5b14610378578063955f263a1461037357806395d89b411461036e578063973544481461036957806399fbab88146103645780639c016ffd1461035f578063a301ad2b1461035a578063a41fe49f14610355578063a9059cbb14610350578063aa3c1d401461034b578063ac9650d814610346578063ad3cb1cc14610341578063b3c40be41461033c578063b5470ad814610337578063b591b13c14610332578063bbdd366a1461032d578063c2d9ecfa14610328578063c4fa17a414610323578063dd5f47db1461031e578063dd62ed3e14610319578063e045b7b414610314578063e449022e1461030f578063f2fde38b1461030a578063f57fa78d14610305578063f68eb65714610300578063faf6d874146102fb578063fe1f4559146102f65763feda50ec146102f157600080fd5b6133a9565b61333c565b6131dd565b6131a7565b61317e565b613151565b612f93565b612f6a565b612f2a565b612d45565b612cd9565b612c7a565b612c5c565b612c3e565b612974565b61295b565b612914565b612834565b61278c565b612757565b612426565b6123a3565b61236b565b61230b565b6121ae565b6120fe565b61201c565b611fe6565b611fcc565b611ed3565b611ea5565b611d3e565b611cfd565b611c13565b611bbb565b611b71565b611b48565b611b1c565b611a23565b611831565b6117d8565b6117af565b611730565b6115ce565b611426565b6113f9565b6113b1565b611271565b61122a565b611209565b611190565b61113e565b611041565b610fea565b610fc1565b610f0d565b610e82565b610e59565b610e3b565b610db4565b610d05565b610bc6565b610ae5565b610909565b610866565b61046b565b606090600319011261045557600435906024359060443590565b600080fd5b908152602081019190915260400190565b34610455576104793661043b565b9091610483614836565b60009283821561084c57610495614886565b5061049e613ce6565b90816106695750506104b26001548361357f565b926104d3846104ca6104c5600754610884565b610884565b30903390614bf1565b831580610661575b610650576000906000926005546104f181610884565b906104fb82610884565b33036105ac575b505085119081156105a2575b5061058357907fa9655c7bb3dce82c29396162aecd039217d6e09ea6ae1fe2c13650c8570e3ecc916105408433614c3a565b604080519485526020850186905284018690526060840152608083015233918060a081015b0390a2610570614872565b61057f6040519283928361045a565b0390f35b6308f51ff960e31b6000526004849052602485905260446000fd5b6000fd5b905085113861050e565b919796945092506105ff9060a01c62ffffff16926105f962ffffff60025495166105e36105da87838a614a26565b9687928b614a26565b9687938280610631575b50508361060757613541565b96613541565b953880610502565b61062c846106196104c5600854610884565b610624600554610884565b903390614bf1565b613541565b61064991336106446104c5600754610884565b614bf1565b38826105ed565b638c88122d60e01b60005260046000fd5b5084156104db565b6106759594919561494d565b50506004546040519061069d8261068f3360208301610fae565b03601f19810184528361154a565b86915b888284106107b757505050506106ba6104c5600754610884565b956040516370a0823160e01b8152602081806106d93060048301610fae565b03818b5afa80156107b2578683916106f993600091610783575b50614a26565b906107086104c5600854610884565b90602060405180936370a0823160e01b825281806107293060048301610fae565b03915afa9081156107b25761077e9461075e610756610764938b889661076e986000916107835750614a26565b958692613541565b99613541565b9830903390614bf1565b30336106446104c5600854610884565b6104d3565b6107a5915060203d6020116107ab575b61079d818361154a565b81019061354e565b386106f3565b503d610793565b61355d565b61083761083d89869b9761062c61084395610825886108066108016107df60019c9d9e6122b7565b50948554986107fc6107f08b6122d7565b6001600160801b031690565b614a26565b614a53565b8661081f610815839960020b90565b9160181c60020b90565b90614a86565b96909461083283546122d7565b6134fa565b90613518565b95613541565b970191906106a0565b638c88122d60e01b8552600485fd5b600091031261045557565b34610455576000366003190112610455576020600a54604051908152f35b6001600160a01b031690565b6001600160a01b0381160361045557565b606435906108ae82610890565b565b608435906108ae82610890565b6101a435906108ae82610890565b6101c435906108ae82610890565b9181601f84011215610455578235916001600160401b038311610455576020808501948460051b01011161045557565b346104555760803660031901126104555760043561092681610890565b602435604435916064356001600160401b0381116104555761094c9036906004016108d9565b610957939193614836565b60035460101c6001600160a01b03163303610a7f5761097d6104c56104c5600754610884565b6001600160a01b038416908114919082159081610a64575b50610a53576020946109aa846109f094614d01565b966109b6600b54610884565b946109c56104c5600754610884565b966109d46104c5600854610884565b996040519a8b998a9963fd9a0e3f60e01b8b5260048b016135b2565b038173dbfe68fae54d9875a50fdfd9af72b149f3acc8995af480156107b25761057f91600091610a34575b50610a24614872565b6040519081529081906020820190565b610a4d915060203d6020116107ab5761079d818361154a565b38610a1b565b633539a70160e01b60005260046000fd5b9050610a776104c56104c5600854610884565b141538610995565b630190a5dd60e21b60005260046000fd5b919082519283825260005b848110610abc575050826000602080949584010152601f8019910116010190565b80602080928401015182828601015201610a9b565b906020610ae2928181520190610a90565b90565b34610455576000366003190112610455576040516000600080516020615d7a83398151915254610b1481613605565b8084529060018116908115610ba25750600114610b48575b61057f83610b3c8185038261154a565b60405191829182610ad1565b600080516020615d7a8339815191526000908152600080516020615d3a833981519152939250905b808210610b8857509091508101602001610b3c610b2c565b919260018160209254838588010152019101909291610b70565b60ff191660208086019190915291151560051b84019091019150610b3c9050610b2c565b3461045557604036600319011261045557600435610be381610890565b6024353315610c70576001600160a01b038216918215610c5a57610c228291610c0b33614020565b9060018060a01b0316600052602052604060002090565b556040519081527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560203392a3602060405160018152f35b634a1406b160e11b600052600060045260246000fd5b63e602df0560e01b600052600060045260246000fd5b9181601f84011215610455578235916001600160401b038311610455576020838186019501011161045557565b62ffffff81160361045557565b60a435906108ae82610cb3565b60e435906108ae82610cb3565b60ff81160361045557565b60c435906108ae82610cda565b60a0906101031901126104555761010490565b34610455576101e0366003190112610455576004356001600160401b03811161045557610d36903690600401610c86565b60243591906001600160401b03831161045557610d5a610db2933690600401610c86565b604435610d6681610890565b610d6e6108a1565b610d766108b0565b610d7e610cc0565b91610d87610ce5565b93610d90610ccd565b95610d9a36610cf2565b97610da36108bd565b99610dac6108cb565b9b61363f565b005b346104555761014036600319011261045557600435610dd281610890565b60e036602319011261045557610104356001600160401b03811161045557610dfe903690600401610c86565b6101243592906001600160401b03841161045557610e23610e2b943690600401610c86565b939092613a5e565b9061057f6040519283928361045a565b34610455576000366003190112610455576020600c54604051908152f35b34610455576000366003190112610455576006546040516001600160a01b039091168152602090f35b34610455576000366003190112610455576020600080516020615e3a83398151915254604051908152f35b602060408183019282815284518094520192019060005b818110610ed15750505090565b909192602060606001928651805160020b82528381015160020b848301526040858060801b039101511660408201520194019101919091610ec4565b3461045557600036600319011261045557600454610f2a81613cf9565b90610f38604051928361154a565b80825260046000908152600080516020615efa833981519152602084015b838310610f6b576040518061057f8782610ead565b600160208192604051610f7d8161152a565b85548060020b82528060181c60020b84830152848060801b039060301c166040820152815201920192019190610f56565b6001600160a01b03909116815260200190565b3461045557600036600319011261045557600d546040516001600160a01b039091168152602090f35b346104555760003660031901126104555760a060055460405190600180841b038116825262ffffff81841c16602083015262ffffff8160b81c16604083015262ffffff8160d01c16606083015260e81c6080820152f35b346104555760603660031901126104555760043561105e81610890565b60243561106a81610890565b604435906110783384614765565b9260018401611098575b61108c9350615102565b60405160018152602090f35b8284106110b4576110af8361108c950333836159f7565b611082565b8284637dc7a0d960e11b6000523360045260245260445260646000fd5b8060020b0361045557565b6001600160801b0381160361045557565b60c090600319011261045557600435611105816110d1565b90602435611112816110d1565b9060443561111f816110dc565b90606435906084359060a4356001600160401b03811681036104555790565b346104555761114c366110ed565b9093919291906001600160401b0316421161117f5760035460101c6001600160a01b03163303610a7f57610e2b94613e26565b6338e5e54b60e21b60005260046000fd5b34610455576020366003190112610455576004356111ad81610890565b6111b5615468565b6003805462010000600160b01b031916601083901b62010000600160b01b03161790556001600160a01b0316337f605c2dbf762e5f7d60a546d42e7205dcb1b011ebc62a61736a57c9089d3a4350600080a3005b3461045557600036600319011261045557602060ff60035416604051908152f35b346104555760203660031901126104555760043561124781610890565b61124f615468565b600b80546001600160a01b0319166001600160a01b0392909216919091179055005b34610455576060366003190112610455576004356024356044356001600160401b038111610455576112a7903690600401610c86565b60026009540361137b576112bf6104c5600654610884565b336001600160a01b039091160361136a57816104c5916112e0930190613f4b565b918061132a575b50806112ef57005b6001600160a01b03821661131657610db29150336113116104c5600854610884565b61549e565b610db29133906106446104c5600854610884565b6001600160a01b0383166113515761134b90336113116104c5600754610884565b386112e7565b6113659033846106446104c5600754610884565b61134b565b6333b43e6360e21b60005260046000fd5b637748745560e01b60005260046000fd5b6040906003190112610455576004356113a4816110d1565b90602435610ae2816110d1565b34610455576113bf3661138c565b60035460101c6001600160a01b03163303610a7f576113dd91613f60565b604080516001600160801b039384168152919092166020820152f35b346104555760003660031901126104555760035460405160109190911c6001600160a01b03168152602090f35b346104555760003660031901126104555761143f614836565b6114476154c5565b61145a61145333613fdf565b5433615563565b61146333614006565b54600061146f33614006565b5580611482575b61057f90610a24614872565b6114936104c56104c5600e54610884565b906020604051809363a9059cbb60e01b8252816000816114b787336004840161406e565b03925af19182156107b25761057f926114e7575b506114e06114db82600f54613d38565b600f55565b9050611476565b6115089060203d60201161150d575b611500818361154a565b810190614059565b6114cb565b503d6114f6565b634e487b7160e01b600052604160045260246000fd5b606081019081106001600160401b0382111761154557604052565b611514565b601f909101601f19168101906001600160401b0382119082101761154557604052565b604051906108ae60608361154a565b6001600160401b03811161154557601f01601f191660200190565b9291926115a38261157c565b916115b1604051938461154a565b829481845281830111610455578281602093846000960137010152565b6040366003190112610455576004356115e681610890565b6024356001600160401b038111610455573660238201121561045557611616903690602481600401359101611597565b906001600160a01b037f00000000000000000000000090eebeba24b35f5264669c9561079cb77ce6d1cf1630811490811561170d575b506116fc57611659615468565b6040516352d1902d60e01b8152916020836004816001600160a01b0386165afa600093816116db575b506116a557634c9c8ce360e01b6000526001600160a01b03821660045260246000fd5b90600080516020615e5a83398151915283036116c557610db29250615c12565b632a87526960e21b600052600483905260246000fd5b6116f591945060203d6020116107ab5761079d818361154a565b9238611682565b63703e46dd60e11b60005260046000fd5b600080516020615e5a833981519152546001600160a01b0316141590503861164c565b34610455576000366003190112610455576008546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa80156107b25761057f91600091611790575b506040519081529081906020820190565b6117a9915060203d6020116107ab5761079d818361154a565b3861177f565b3461045557600036600319011261045557600e546040516001600160a01b039091168152602090f35b34610455576000366003190112610455577f00000000000000000000000090eebeba24b35f5264669c9561079cb77ce6d1cf6001600160a01b031630036116fc576020604051600080516020615e5a8339815191528152f35b34610455576000366003190112610455576118506104c5600654610884565b60405163ddca3f4360e01b815290602082600481845afa9182156107b2576000926119f2575b506118856104c5600754610884565b60405163313ce56760e01b81529091602082600481865afa9182156107b2576000926119d1575b506118bb6104c5600854610884565b60405163313ce56760e01b81529094602082600481895afa9182156107b25760009261199c575b5060e06004929360405193848092633850c7bd851b82525afa9283156107b25761057f94600093600095611960575b50604080516001600160a01b03988916815298881660208a015260ff9182169089015216606087015262ffffff16608086015290921660a084015260029190910b60c0830152819060e0820190565b90945061198691935060e03d60e011611995575b61197e818361154a565b8101906140ad565b50505050509290929338611911565b503d611974565b600492506119c360e09160203d6020116119ca575b6119bb818361154a565b81019061378d565b92506118e2565b503d6119b1565b6119eb91925060203d6020116119ca576119bb818361154a565b90386118ac565b611a1591925060203d602011611a1c575b611a0d818361154a565b810190614089565b9038611876565b503d611a03565b34610455576060366003190112610455576024356004356044356001600160401b03811161045557611a59903690600401610c86565b9060026009540361137b57611a726104c5600654610884565b336001600160a01b039091160361136a5782158015611af8575b611ae757611a9c91810190614116565b916000821315611add575090805b151590151514600014611aca57610db290336113116104c5600754610884565b610db290336113116104c5600854610884565b9180159150611aaa565b63030e4c8d60e41b60005260046000fd5b508315611a8c565b9094939260609260808301968352602083015260408201520152565b346104555760003660031901126104555761057f611b3861414d565b9060409492945194859485611b00565b34610455576000366003190112610455576008546040516001600160a01b039091168152602090f35b3461045557602036600319011261045557600435611b8e81610890565b60018060a01b0316600052600080516020615d9a8339815191526020526020604060002054604051908152f35b3461045557600036600319011261045557611bd4615468565b600080516020615dfa83398151915280546001600160a01b031981169091556000906001600160a01b0316600080516020615e7a8339815191528280a3005b3461045557606036600319011261045557600435611c30816110d1565b602435611c3c816110d1565b60443590611c49826110dc565b600654604080516362891e0b60e01b81526001600160a01b039092166004830152600294850b60248301529190930b60448401526001600160801b0391909116606483015281608481732ed994fd3dc53bd4010652bfc00d9805808236645af49081156107b257600090600092611ccb575b5061057f6040519283928361045a565b9050611cef915060403d604011611cf6575b611ce7818361154a565b810190613bb2565b9038611cbb565b503d611cdd565b3461045557611d0b366110ed565b9093919291906001600160401b0316421161117f5760035460101c6001600160a01b03163303610a7f57610e2b94614291565b346104555761010036600319011261045557600435611d5c81610890565b60243590611d6982610890565b60443590611d7682610890565b6064359160843560e43560c43560a435611d8e614836565b60035460101c6001600160a01b03163303610a7f57611db46104c56104c5600754610884565b6001600160a01b038916908114949085159081611e8a575b50610a535787600496611de460209a6109f098614d01565b9a611df0600b54610884565b99611dff6104c5600754610884565b9c611e0e6104c5600854610884565b6040516310c3507960e21b81529e8f9d8e9d8e016001600160a01b039182168152918116602083015291821660408201526060810192909252918216608082015291811660a083015290911660c08201526101808101969594610160949193909260e08501526101008401526101208301526101408201520152565b9050611e9d6104c56104c5600854610884565b141538611dcc565b346104555760003660031901126104555760035460101c6001600160a01b03163303610a7f576113dd61494d565b3461045557602036600319011261045557600435600454811015611fbb57600654611f43916080916001600160a01b031690611f0e906122b7565b50604051631612a31760e31b81523060048201526001600160a01b039092166024830152604482015291829081906064820190565b0381732ed994fd3dc53bd4010652bfc00d9805808236645af480156107b2576000809160008091611f80575b9061057f9160405194859485611b00565b50505050611fa861057f9160803d608011611fb4575b611fa0818361154a565b81019061412b565b91935083929190611f6f565b503d611f96565b63f7b3b39160e01b60005260046000fd5b346104555761057f611b38611fe03661138c565b90614386565b3461045557600036600319011261045557600080516020615dfa833981519152546040516001600160a01b039091168152602090f35b3461045557608036600319011261045557600435612039816110d1565b602435612045816110d1565b6044356064359160018060a01b0360065416936040519463361d23b760e21b8652600486015260020b602485015260020b60448401526064830152608482015260208160a481732ed994fd3dc53bd4010652bfc00d9805808236645af480156107b25761057f916000916120cf575b506040516001600160801b0390911681529081906020820190565b6120f1915060203d6020116120f7575b6120e9818361154a565b810190614467565b386120b4565b503d6120df565b34610455576000366003190112610455576040516000600080516020615dda8339815191525461212d81613605565b8084529060018116908115610ba257506001146121545761057f83610b3c8185038261154a565b600080516020615dda8339815191526000908152600080516020615eda833981519152939250905b80821061219457509091508101602001610b3c610b2c565b91926001816020925483858801015201910190929161217c565b34610455576020366003190112610455576004356121cb81610890565b6121d3615468565b6001600160a01b03811680612290576121f36104c56104c5600754610884565b8114908115612276575b50612265576122106104c5600e54610884565b612254576a0c097ce7bc90715b34b9f160241b60105561224c90600e80546001600160a01b0319166001600160a01b0392909216919091179055565b610db26154c5565b63aff01e7360e01b60005260046000fd5b63c1ab6dc160e01b60005260046000fd5b90506122896104c56104c5600854610884565b14386121fd565b63d92e233d60e01b60005260046000fd5b634e487b7160e01b600052603260045260246000fd5b6004548110156122d257600460005260206000200190600090565b6122a1565b60301c6001600160801b031690565b600291820b815291900b60208201526001600160801b03909116604082015260600190565b3461045557602036600319011261045557600435600454811015610455576004600052600080516020615efa833981519152015460405190819061057f90603081901c6001600160801b031690601881901c600290810b91900b846122e6565b346104555760003660031901126104555760035460101c6001600160a01b03163303610a7f57602061239b614886565b604051908152f35b346104555760003660031901126104555760206123be61453c565b60065460405163092df84160e31b81529392849283926123eb92906001600160a01b03166004850161447c565b0381732ed994fd3dc53bd4010652bfc00d9805808236645af480156107b25761057f9160009161179057506040519081529081906020820190565b34610455576124343661043b565b909161243e614836565b60008180156127485761244f614886565b50612458613ce6565b92829060055461246781610884565b9061247182610884565b33036126f9575b50505061248582336156ef565b6004549261249161494d565b50506124a16104c5600754610884565b602060405180926370a0823160e01b825281806124c13060048301610fae565b03915afa9182156107b2576124e09287928692916126da575b506157ac565b926124ef6104c5600854610884565b602060405180926370a0823160e01b8252818061250f3060048301610fae565b03915afa80156107b25784879161252d936000916126da57506157ac565b9460005b828110612637575050506000945b600454808710156125a6576125606107f0612559896122b7565b50546122d7565b6125955761257861257361258892613d29565b6122b7565b50612582886122b7565b90613d63565b612590613dc5565b61253f565b50946125a09061449a565b9461253f565b5086841090811561262d575b50612612576105657f43394472faf6e72a904b108d59ae00f2935bfcdd08137aeb9f78e79aa366bcc5916125ef85336113116104c5600754610884565b61260286336113116104c5600854610884565b6040519182918787339785611b00565b6308f51ff960e31b6000526004839052602484905260446000fd5b90508410856125b2565b612643819796976122b7565b508054966126518860020b90565b9887856126618b60181c60020b90565b9a61266b906122d7565b6001600160801b03169161267e926157ac565b61268790614a53565b996126938b8b83615278565b9a61269e9192615356565b50506126a991613541565b976126b391613541565b9781546126bf906122d7565b906126c991613d10565b6126d291613518565b600101612531565b6126f3915060203d6020116107ab5761079d818361154a565b386124da565b91935061272e92509061271d9060b81c62ffffff1662ffffff600254911685614a26565b9283918280612737575b5050613d38565b90388080612478565b6127419133615102565b3882612727565b638c88122d60e01b8252600482fd5b346104555760403660031901126104555761278160043561277781610890565b6024359033615102565b602060405160018152f35b346104555760003660031901126104555760206127a761453c565b600654604051637d5dbf5160e11b81529392849283926123eb92906001600160a01b03166004850161447c565b602081016020825282518091526040820191602060408360051b8301019401926000915b83831061280757505050505090565b9091929394602080612825600193603f198682030187528951610a90565b970193019301919392906127f8565b34610455576020366003190112610455576004356001600160401b038111610455576128649036906004016108d9565b9061286e82613cf9565b9161287c604051938461154a565b808352601f1961288b82613cf9565b0160005b81811061290357505060005b8181106128b0576040518061057f86826127d4565b806128e76000806128c460019587896144a9565b906128d4604051809381936144ea565b0390305af46128e16144f8565b9061583e565b6128f18287614528565b526128fc8186614528565b500161289b565b80606060208093880101520161288f565b346104555760003660031901126104555761057f6040805190612937818361154a565b60058252640352e302e360dc1b602083015251918291602083526020830190610a90565b3461045557600036600319011261045557610e2b61453c565b346104555760403660031901126104555760043561299181610890565b60243561299d81610890565b600d546001600160a01b03163303612c2d576129b7614836565b6001600160a01b0381169182156122905760405163c4f59f9b60e01b815291906001600160a01b0316600083600481845afa9283156107b257600093612c08575b506004939293549060005b828110612b7c57505050612a18600754610884565b92612a24600854610884565b6001600160a01b03909416939060005b8151811015612b4e576001600160a01b03612a626104c5612a558486614528565b516001600160a01b031690565b16908682141580612b3b575b612a7d575b6001915001612a34565b6040516370a0823160e01b81529160208380612a9c3060048301610fae565b0381845afa9081156107b257600193600092612b1b575b5086600554612ada612acb8262ffffff9060d01c1690565b62ffffff600254911686614a26565b808511612aec575b5050505050612a73565b612b1194612b0682612b00612b0b95610884565b8761549e565b613d38565b9161549e565b3880868180612ae2565b612b3491925060203d81116107ab5761079d818361154a565b9038612ab3565b506001600160a01b038416821415612a6e565b847f29e197049bed9d0535b455fed2dc45b916a0de23b14a030659e8220ee42b2f20600080a2610db2614872565b612b88819695966122b7565b505490612ba2612b988360020b90565b9260181c60020b90565b833b156104555786600091612bce60405195869384936318d9dceb60e31b855230923060048701614697565b038183875af19182156107b257600192612bed575b5001949394612a03565b80612bfc6000612c029361154a565b8061085b565b38612be3565b612c269193503d806000833e612c1e818361154a565b810190614614565b91386129f8565b63c18e0ea960e01b60005260046000fd5b34610455576000366003190112610455576020600254604051908152f35b34610455576000366003190112610455576020600154604051908152f35b34610455576000366003190112610455576007546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa80156107b25761057f9160009161179057506040519081529081906020820190565b34610455576000366003190112610455576020600054604051908152f35b8015150361045557565b60a090600319011261045557600435612d1981612cf7565b906024359060443590606435612d2e81610890565b906084356001600160401b03811681036104555790565b3461045557612d5336612d01565b6003549394919391929160101c6001600160a01b03163303610a7f576001600160401b0316421161117f57612e1692612d8c6002600955565b6040612d9c6104c5600654610884565b612dad612da88861584b565b61471b565b6001600160a01b03841615939091908415612f25575060008615612f0a57506401000276a45b8351871515602082015292600090612df885604081015b03601f19810187528661154a565b8551630251596160e31b8152998a95869485938c306004870161472c565b03925af180156107b257600094600091612ee5575b50612e366001600955565b8315612ed557612e459061471b565b905b80612ecb575b612eaf57508211612e945761057f92600080516020615dba833981519152612e81600093604051918291151594878361045a565b0390a36040519081529081906020820190565b6308f51ff960e31b6000908152600483905260245260446000fd5b6308f51ff960e31b600090815260049190915260245260446000fd5b5084811415612e4d565b93612edf9061471b565b90612e47565b9050612f0191945060403d604011611cf657611ce7818361154a565b93909338612e2b565b5073fffd8963efd1fc6a506488495d951d5263988d25612dd3565b612dd3565b34610455576040366003190112610455576020612f61600435612f4c81610890565b610c0b60243591612f5c83610890565b614020565b54604051908152f35b34610455576000366003190112610455576007546040516001600160a01b039091168152602090f35b34610455576060366003190112610455576024356004356044356001600160401b03811161045557612fc99036906004016108d9565b929091612fd4614836565b60035460101c6001600160a01b03163303610a7f5760046020612ff78686614776565b356001600160a01b03811690600160ff1b1661310857604051630dfe168160e01b815292839182905afa9081156107b2576000916130d9575b50935b6130446104c56104c5600754610884565b6001600160a01b03909516948514908115806130bf575b610a535760209461306f846109f094614d01565b9461307b600b54610884565b9461308a6104c5600754610884565b966130996104c5600854610884565b996130a389610884565b146040519a8b998a99634eb2fed360e11b8b5260048b0161477f565b506130d16104c56104c5600854610884565b86141561305b565b6130fb915060203d602011613101575b6130f3818361154a565b810190613778565b38613030565b503d6130e9565b60405163d21220a760e01b815292839182905afa9081156107b257600091613132575b5093613033565b61314b915060203d602011613101576130f3818361154a565b3861312b565b3461045557602036600319011261045557610db260043561317181610890565b613179615468565b6147d2565b3461045557600036600319011261045557600b546040516001600160a01b039091168152602090f35b346104555760a0366003190112610455576131c0615468565b6131c8614886565b506131d161494d565b5050610db2600461503d565b34610455576131eb36612d01565b6003549394929360101c6001600160a01b03163303610a7f576001600160401b0316421161117f576040613293916132236002600955565b6132316104c5600654610884565b61323a8761584b565b916001600160a01b03811661333757506000851561331c57506401000276a45b83518615156020820152926000906132758560408101612dea565b8551630251596160e31b8152968795869485938b306004870161472c565b03925af180156107b2576132c3916000906000926132fa575b506132b76001600955565b83156132f3575061471b565b918210612e945761057f92600080516020615dba83398151915283600193612e816040519283921515958361045a565b905061471b565b9050613315915060403d604011611cf657611ce7818361154a565b90386132ac565b5073fffd8963efd1fc6a506488495d951d5263988d2561325a565b61325a565b346104555760203660031901126104555760043561335981610890565b613361615468565b6001600160a01b0316801561229057600d80546001600160a01b031916821790557fc5d42db7f469ababda43f710e99bd448d225e03f44c6c524448095c41dc606c2600080a2005b34610455576040366003190112610455576004356133c681612cf7565b60243560035460101c6001600160a01b03163303610a7f57600080916133ec6002600955565b6134036133fd6104c5600654610884565b9161584b565b828584146134c85750826401000276a45b6040805188151560208083019190915281529161346691613435908461154a565b6134586040519384926020840197630251596160e31b89528c306024870161472c565b03601f19810183528261154a565b51925af16134726144f8565b9061347d6001600955565b156104555760209161349a8284806134a695518301019101613bb2565b91156132f3575061471b565b6040518281019182526134c69080602084010390601f198201815261154a565bfd5b508273fffd8963efd1fc6a506488495d951d5263988d25613414565b634e487b7160e01b600052601160045260246000fd5b6001600160801b03918216908216019190821161351357565b6134e4565b8054600160301b600160b01b03191660309290921b600160301b600160b01b0316919091179055565b9190820180921161351357565b90816020910312610455575190565b6040513d6000823e3d90fd5b634e487b7160e01b600052601260045260246000fd5b8115613589570490565b613569565b81835290916001600160fb1b0383116104555760209260051b809284830137010190565b6001600160a01b039182168152918116602083015291821660408201526060810192909252909116608082015260a081019190915260c081019190915261010060e08201819052610ae29391019161358e565b90600182811c92168015613635575b602083101461361f57565b634e487b7160e01b600052602260045260246000fd5b91607f1691613614565b9a98969492909160ff9c9a9896949261366d600080516020615f3a833981519152549e8f60401c1615151590565b9d6001600160401b03168015908f8261375f575b506001149081613755575b15908161374c575b5061373b57600080516020615f3a83398151915280546001600160401b03191660011790556136c79c8e613716576137b6565b6136cd57565b600080516020615f3a833981519152805460ff60401b19169055604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602090a1565b600080516020615f3a833981519152805460ff60401b1916600160401b1790556137b6565b63f92ee8a960e01b60005260046000fd5b90501538613694565b303b15915061368c565b91508f613681565b60ff16604d811161351357600a0a90565b908160209103126104555751610ae281610890565b908160209103126104555751610ae281610cda565b9060ff8091169116019060ff821161351357565b6137e6906137ee93926137d76137f4979b9c9d9e6137d2615a25565b614d67565b6137df614d7b565b3691611597565b923691611597565b90614d8b565b6001600160a01b0381811694908316939084861015613a4d57613892936020936138216301e13380600055565b61383261382d8a613767565b600155565b61383e620f4240600255565b61385261050061ff00196003541617600355565b604051630b4c774160e11b81526001600160a01b0391821660048201529116602482015262ffffff90921660448301529092839190829081906064820190565b03916001600160a01b03165afa80156107b2576138d491600091613a2e575b50600680546001600160a01b0319166001600160a01b0392909216919091179055565b6006546001600160a01b03906138ed906104c590610884565b1615613a1d57600780546001600160a01b039384166001600160a01b03199182161790915560088054929093169116179055600460206139316104c5600754610884565b60405163313ce56760e01b815292839182905afa80156107b25761397192613961926000926139fc575b506137a2565b60ff1660ff196003541617600355565b61397b6001600955565b62ffffff6002549116908110156139eb576139c39261399c6139be92600c55565b600d80546001600160a01b0319166001600160a01b0392909216919091179055565b61503d565b307fdf71cb001a7432934a99d34855dc0f49942e430ce37c4d0ba3ba654079162ed7600080a2565b63035f0ce760e21b60005260046000fd5b613a1691925060203d6020116119ca576119bb818361154a565b903861395b565b63486aa30760e01b60005260046000fd5b613a47915060203d602011613101576130f3818361154a565b386138b1565b633f06bf8160e01b60005260046000fd5b919493613a69614836565b60035460101c6001600160a01b03163303610a7f57613a886024613ba8565b90613a9a6104c56104c5600754610884565b916001600160a01b031682141580613b7a575b610a5357604094613b2092613ad9906001600160a01b03613ace6024613ba8565b161460a43590614d01565b97613ae5600b54610884565b946024613af66104c5600754610884565b97613b056104c5600854610884565b9b8a519c8d9a8b9a634a94292360e11b8c5260048c01613bf4565b038173dbfe68fae54d9875a50fdfd9af72b149f3acc8995af49182156107b257600090600093613b56575b5091906108ae614872565b9050613b7291925060403d604011611cf657611ce7818361154a565b919038613b4b565b50613b856024613ba8565b613b966104c56104c5600854610884565b6001600160a01b039091161415613aad565b35610ae281610890565b9190826040910312610455576020825192015190565b35906108ae82610890565b908060209392818452848401376000828201840152601f01601f1916010190565b6001600160a01b0391821681529181166020830152918216604082015260608101929092529091166080820152610ae295909490939092613cd79290919060c0908035613c4081610890565b6001600160a01b031660a08901526020810135613c5c81610890565b6001600160a01b0316888301526040810135613c7781610890565b6001600160a01b031660e0890152613ca5613c9460608301613bc8565b6001600160a01b03166101008a0152565b608081013561012089015260a081013561014089015201356101608701526101c06101808701526101c0860191613bd3565b926101a0818503910152613bd3565b600080516020615e3a8339815191525490565b6001600160401b0381116115455760051b60200190565b6001600160801b03918216908216039190821161351357565b60001981019190821161351357565b9190820391821161351357565b9081549060181b65ffffff000000169065ffffff0000001916179055565b90613daf57818103613d73575050565b8154815462ffffff191662ffffff9091161781556108ae91613d9c815460181c60020b83613d45565b5460301c6001600160801b031690613518565b634e487b7160e01b600052600060045260246000fd5b6004548015613e10576000198101906004548210156122d257600460008181527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19a9092019190915555565b634e487b7160e01b600052603160045260246000fd5b9492919093946004549160005b838110613e4b5763f7b3b39160e01b60005260046000fd5b613e54816122b7565b508054613e618160020b90565b8560020b9060020b149081613f34575b50613e7f5750600101613e33565b92613e8f849892959697986151ec565b5050613e9c838383615278565b9990978810908115613f2a575b50613f0f5790613eb891615356565b5050613ec482546122d7565b6001600160801b0381811690831603613eff57505050612582613eec612573613ef394613d29565b50916122b7565b613efb613dc5565b9190565b613efb9450610837929350613d10565b6308f51ff960e31b6000526004879052602489905260446000fd5b9050891038613ea9565b60181c60020b90508860020b9060020b1438613e71565b908160209103126104555735610ae281610890565b906004549160005b838110613f805763f7b3b39160e01b60005260046000fd5b6004548110156122d25760046000528060206000200180548360020b8160020b149081613fc8575b50613fb65750600101613f68565b92505050613fc491506151ec565b9091565b60181c60020b90508460020b9060020b1438613fa8565b6001600160a01b03166000908152600080516020615d9a8339815191526020526040902090565b6001600160a01b0316600090815260126020526040902090565b6001600160a01b031660009081527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace016020526040902090565b908160209103126104555751610ae281612cf7565b6001600160a01b039091168152602081019190915260400190565b908160209103126104555751610ae281610cb3565b519061ffff8216820361045557565b908160e09103126104555780516140c381610890565b9160208201516140d2816110d1565b916140df6040820161409e565b916140ec6060830161409e565b916140f96080820161409e565b9160c060a083015161410a81610cda565b920151610ae281612cf7565b908160209103126104555735610ae281612cf7565b9190826080910312610455578151916020810151916060604083015192015190565b600090600090600090600090600454600090732ed994fd3dc53bd4010652bfc00d9805808236645b81831061418157505050565b9091939495966141a06080614197600654610884565b611f0e886122b7565b0381865af49182156107b2576001926141e492600080809281946141ed575b50906141d26141d8926141de9596613541565b9d613541565b9a613541565b97613541565b94019190614175565b6141de94506141d293506141d89250614214915060803d8111611fb457611fa0818361154a565b9550939092506141bf565b60045490600160401b82101561154557600182016004556000916004548110156122d25760208360046108ae955220019061426d815160020b839062ffffff198254169062ffffff16179055565b61427e602082015160020b83613d45565b604001516001600160801b031690613518565b90949291936004546000905b808210614312575060035460081c60ff161461430157846142ca6142fc926108ae956142ec988a876155c7565b9690976142e26142d861156d565b95869060020b9052565b60020b6020850152565b6001600160801b03166040830152565b61421f565b633a37518960e21b60005260046000fd5b9061431c816122b7565b5080546143298160020b90565b8660020b9060020b14908161436f575b5061434857506001019061429d565b93614362939250613efb95915096610837988197986155c7565b95909361083283546122d7565b60181c60020b90508960020b9060020b1438614339565b6004549160005b8381106143a55763f7b3b39160e01b60005260046000fd5b6143ae816122b7565b50546143ba8160020b90565b8460020b9060020b149081614450575b506143d75760010161438d565b90506143f6925060809150611f0e6143f0600654610884565b916122b7565b0381732ed994fd3dc53bd4010652bfc00d9805808236645af480156107b2576000928380938193614429575b5093929190565b9250509250614446915060803d8111611fb457611fa0818361154a565b9193909238614422565b60181c60020b90508260020b9060020b14386143ca565b908160209103126104555751610ae2816110dc565b604091949392606082019560018060a01b0316825260208201520152565b60001981146135135760010190565b91908110156122d25760051b81013590601e19813603018212156104555701803591906001600160401b038311610455576020018236038113610455579190565b908092918237016000815290565b3d15614523573d906145098261157c565b91614517604051938461154a565b82523d6000602084013e565b606090565b80518210156122d25760209160051b010190565b6145549061455a61454b61414d565b92959195613541565b93613541565b916145696104c5600754610884565b90602060405180936370a0823160e01b8252818061458a3060048301610fae565b03915afa9081156107b2576145a7926000926145f3575b50613541565b916145b66104c5600854610884565b90602060405180936370a0823160e01b825281806145d73060048301610fae565b03915afa9081156107b257610ae2926000926145f35750613541565b61460d91925060203d6020116107ab5761079d818361154a565b90386145a1565b602081830312610455578051906001600160401b03821161045557019080601f8301121561045557815161464781613cf9565b92614655604051948561154a565b81845260208085019260051b82010192831161045557602001905b82821061467d5750505090565b60208091835161468c81610890565b815201910190614670565b95949392909160c087019260018060a01b031687526000602088015260020b604087015260020b606086015260c060808601528151809152602060e0860192019060005b8181106146fc575050506001600160a01b0390911660a09390930192909252565b82516001600160a01b03168452602093840193909201916001016146db565b600160ff1b81146135135760000390565b6001600160a01b039182168152911515602083015260408201929092529116606082015260a060808201819052610ae292910190610a90565b90610c0b61477292614020565b5490565b90156122d25790565b6001600160a01b039182168152918116602083015290911660408201529015156060820152608081019190915260a081019190915260c081019190915261010060e08201819052610ae29391019161358e565b6001600160a01b0316801561482057600080516020615dfa83398151915280546001600160a01b0319811683179091556001600160a01b0316600080516020615e7a833981519152600080a3565b631e4fbdf760e01b600052600060045260246000fd5b6002600080516020615f1a8339815191525414614861576002600080516020615f1a83398151915255565b633ee5aeb560e01b60005260046000fd5b6001600080516020615f1a83398151915255565b600090600a54804203904282116135135742036148a05750565b91506148d06005549262ffffff8460e81c160280600254600054028181116000146149275703905b6107fc613ce6565b9182806148e3575b50506108ae42600a55565b6148ef6148f492610884565b614c3a565b6040518281527f147fac6415bee3006ba6002a9a6636f492d311690c9e52a2421afc6392e0fb9590602090a138826148d8565b50506001906148c8565b600291820b815291900b60208201526000604082015260600190565b6000906000906004546000905b80821061496d5750506108ae8284615870565b90926149bb9061497c856122b7565b50604061498d6104c5600654610884565b82549061499d612b988360020b90565b916000845180988195829463a34123a760e01b845260048401614931565b03925af19081156107b2576001936149e792614a02575b50546149e16108158260020b90565b90615356565b9601608083901b83900390811696919091011693019061495a565b614a199060403d8111611cf657611ce7818361154a565b506149d2565b1561045557565b929190614a348282866157ac565b9382156135895709614a4257565b906000198110156104555760010190565b6001600160801b038111614a6d576001600160801b031690565b6306dfcc6560e41b600052608060045260245260446000fd5b939291906001600160801b03821615614b9c57614aa36002600955565b604082614ab46104c5600654610884565b83600089614ad88651998a9687958694633c8a7d8d60e01b86523060048701614bad565b03925af19485156107b257600093600096614b67575b5090600080516020615d5a83398151915291614b0a6001600955565b614b60878660018060a01b03614b246104c5600654610884565b60408051600297880b81529790960b60208801526001600160801b039098169486019490945260608501526080840152931692819060a0820190565b0390a29190565b614b93919650600080516020615d5a83398151915292945060403d604011611cf657611ce7818361154a565b95909391614aee565b630200e8a960e31b60005260046000fd5b6001600160a01b039091168152600291820b602082015291900b60408201526001600160801b03909116606082015260a060808201819052610ae292910190610a90565b6040516323b872dd60e01b60208201526001600160a01b0392831660248201529290911660448301526064808301939093529181526108ae91614c3560848361154a565b61597c565b6001600160a01b03811691908215614ceb57601054614cb9575b600080516020615e3a833981519152549082820180921161351357600092614c9e614cb492600080516020615e9a83398151915294600080516020615e3a83398151915255613fdf565b8054820190556040519081529081906020820190565b0390a3565b614cc16154c5565b82600052600080516020615d9a833981519152602052614ce660406000205482615563565b614c54565b63ec442f0560e01b600052600060045260246000fd5b600091908291604051906020820192633fb6943b60e21b845215156024830152604482015260448152614d3560648261154a565b5190305af4614d426144f8565b9015614d4d57600080fd5b805190811561045557602080610ae293830101910161354e565b6108ae90614d73615a25565b613179615a25565b614d83615a25565b614872615a25565b614d93615a25565b614d9b615a25565b8051906001600160401b03821161154557614dcd82614dc8600080516020615d7a83398151915254613605565b615a53565b602090601f8311600114614e23579180614e03926108ae9594600092614e18575b50508160011b916000199060031b1c19161790565b600080516020615d7a83398151915255615b05565b015190503880614dee565b600080516020615d7a833981519152600052601f1983169190600080516020615d3a8339815191529260005b818110614e9d57509160019391856108ae97969410614e84575b505050811b01600080516020615d7a83398151915255615b05565b015160001960f88460031b161c19169055388080614e69565b92936020600181928786015181550195019301614e4f565b35610ae281610cb3565b9062ffffff8091169116019062ffffff821161351357565b614f9f60806108ae928035614eeb81610890565b600580546001600160a01b0319166001600160a01b03929092169190911790556020810135614f1981610cb3565b6005549062ffffff60a01b9060a01b168062ffffff60a01b198316176005556040830135614f4681610cb3565b65ffffffffffff60a01b199092161760b89190911b62ffffff60b81b1617600555614f99614f7660608301614eb5565b6005805462ffffff60d01b191660d09290921b62ffffff60d01b16919091179055565b01614eb5565b600580546001600160e81b031660e89290921b6001600160e81b031916919091179055565b90929162ffffff608060a09260c085019685528035614fe281610890565b600180861b03166020860152826020820135614ffd81610cb3565b16604086015282604082013561501281610cb3565b16606086015282606082013561502781610cb3565b1682860152013561503781610cb3565b16910152565b62ffffff61506261505060208401614eb5565b61505c60408501614eb5565b90614ebf565b600c5491829116116150da578062ffffff61507f60608501614eb5565b16116150da5762ffffff61509560808401614eb5565b16116150da576150a481614ed7565b7f9b77979ce4de4fc68093eab0fd33625b0cc9f868dbfa1df90cdc46b7e056cb2e604051806150d533944283614fc4565b0390a2565b63390edff560e11b60005260046000fd5b6001600160a01b0316600452602452604452606490565b916001600160a01b0383169182156151d6576001600160a01b038116938415614ceb5760105461517f575b61513681613fdf565b5483811061516857614cb4928492615162600080516020615e9a83398151915296614c9e940391613fdf565b55613fdf565b63391434e360e21b60005261059e918491906150eb565b6151876154c5565b83600052600080516020615d9a8339815191526020526151ac60406000205482615563565b84600052600080516020615d9a8339815191526020526151d160406000205483615563565b61512d565b634b637e8f60e11b600052600060045260246000fd5b600090604061522760018060a01b03600654168354835195868094819363a34123a760e01b83528060181c60020b9060020b60048401614931565b03925af19182156107b25761524e9261525a575b50548060020b9060181c60020b90615356565b90916108ae8284615870565b6152729060403d604011611cf657611ce7818361154a565b5061523b565b92916001600160801b03811615614b9c576006546040805163a34123a760e01b8152939184906001600160a01b0316816000816152ba88888d600485016122e6565b03925af19485156107b2576000936000966152fc575b5090600080516020615e1a83398151915291614b60878660018060a01b03614b246104c5600654610884565b615328919650600080516020615e1a83398151915292945060403d604011611cf657611ce7818361154a565b959093916152d0565b9190826040910312610455576020825161534a816110dc565b920151610ae2816110dc565b600654604080516309e3d67b60e31b8152306004820152600284810b602483015285900b60448201526001600160801b036064820181905260848201529394929391829060a49082906000906001600160a01b03165af19384156107b257600091600095615425575b50600080516020615eba8339815191529085946150d5849760018060a01b036153ec6104c5600654610884565b60408051600296870b81529690950b60208701526001600160801b03978816948601949094529516606084015293169281906080820190565b615459919550600080516020615eba833981519152925060403d604011615461575b615451818361154a565b810190615331565b9490916153bf565b503d615447565b600080516020615dfa833981519152546001600160a01b0316330361548957565b63118cdaa760e01b6000523360045260246000fd5b614c356108ae939261068f60405194859263a9059cbb60e01b60208501526024840161406e565b600e546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa9081156107b257600091615544575b50600f5490818111615510575050565b6114db61553f6155376155266108ae9585613d38565b601054615531613ce6565b916157ac565b601154613541565b601155565b61555d915060203d6020116107ab5761079d818361154a565b38615500565b906011549060018060a01b0383169182600052601260205260016040600020015481039081116135135761559a91601054916157ac565b90600052601260205260406000208054918201809211613513575560016155c360115492614006565b0155565b919492946040519160006020840152602083526155e560408461154a565b6001600160801b03821615614b9c5760406156346000946156066002600955565b6156146104c5600654610884565b908351968780948193633c8a7d8d60e01b835289898d3060048701614bad565b03925af19384156107b25760009384956156ba575b5090600080516020615d5a833981519152916156656001600955565b61567f868660018060a01b03614b246104c5600654610884565b0390a28193819582109081156156b0575b50615699575050565b6308f51ff960e31b60005260045260245260446000fd5b9050821038615690565b6156e6919550600080516020615d5a83398151915292945060403d604011611cf657611ce7818361154a565b94909391615649565b6001600160a01b038116919082156151d65760105461577a575b61571281613fdf565b548281106157655782600080516020615e9a8339815191529261573d60009695614cb4940391613fdf565b55610a2481600080516020615e3a8339815191525403600080516020615e3a83398151915255565b63391434e360e21b60005261059e92916150eb565b6157826154c5565b82600052600080516020615d9a8339815191526020526157a760406000205482615563565b615709565b9091600019838309928083029283808610950394808603951461582b579082916157d7868411614a1f565b09818060000316809204600281600302188082026002030280820260020302808202600203028082026002030280820260020302809102600203029360018380600003040190848311900302920304170290565b5050915061583a821515614a1f565b0490565b9091906108ae5750615cb9565b6001600160ff1b03811161585c5790565b63123baf0360e11b60005260045260246000fd5b600554917f332be93540ee368b088c0f9d4f6e5288d4ea5832df09318be7b59409050a5ed2916150d560d085901c62ffffff1660025462ffffff90911695906158d7906158c781896001600160801b038816614a26565b976001600160801b038716614a26565b90868061595a575b505080615932575b6006546001600160a01b0390615900906104c590610884565b604080516001600160801b03968716815296909516602087015293850196909652606084015293169281906080820190565b615955816159446104c5600854610884565b61594f600554610884565b9061549e565b6158e7565b6159759161594f61596f6104c5600754610884565b91610884565b38866158df565b6000806159a59260018060a01b03169360208151910182865af161599e6144f8565b9083615cf3565b80519081151591826159dc575b50506159bb5750565b635274afe760e01b60009081526001600160a01b0391909116600452602490fd5b6159ef9250602080918301019101614059565b1538806159b2565b906001600160a01b03821615610c70576001600160a01b03811615610c5a57610c0b615a2292614020565b55565b60ff600080516020615f3a8339815191525460401c1615615a4257565b631afcd79f60e31b60005260046000fd5b601f8111615a5f575050565b600080516020615d7a8339815191526000526020600020906020601f840160051c83019310615aa9575b601f0160051c01905b818110615a9d575050565b60008155600101615a92565b9091508190615a89565b601f8211615ac057505050565b6000526020600020906020601f840160051c83019310615afb575b601f0160051c01905b818110615aef575050565b60008155600101615ae4565b9091508190615adb565b80519091906001600160401b03811161154557615b4881615b34600080516020615dda83398151915254613605565b600080516020615dda833981519152615ab3565b602092601f8211600114615b8b57615b7992938291600092614e185750508160011b916000199060031b1c19161790565b600080516020615dda83398151915255565b600080516020615dda833981519152600052601f19821693600080516020615eda8339815191529160005b868110615bfa5750836001959610615be1575b505050811b01600080516020615dda83398151915255565b015160001960f88460031b161c19169055388080615bc9565b91926020600181928685015181550194019201615bb6565b90813b15615c9757600080516020615e5a83398151915280546001600160a01b0319166001600160a01b0384169081179091557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a2805115615c7d57615c7a91615cd9565b50565b505034615c8657565b63b398979f60e01b60005260046000fd5b50634c9c8ce360e01b60009081526001600160a01b0391909116600452602490fd5b805115615cc857805190602001fd5b630a12f52160e11b60005260046000fd5b600080610ae293602081519101845af4615cf16144f8565b915b90615cfe5750615cb9565b81511580615d30575b615d0f575090565b639996b31560e01b60009081526001600160a01b0391909116600452602490fd5b50803b15615d0756fe2ae08a8e29253f69ac5d979a101956ab8f8d9d7ded63fa7a83b16fc47648eab066003071e0f230260f5b0fcf3f58155206656900735cc736441b88ac6096acf652c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0352c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0089a0f954e20890e6f71ce02a4e8655fe6262b4e86117de9a0153620430af4ab752c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace049016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c1993008a3055ac2acbcc6bc795808b7df870b7b6dc76d3de454815764a611d9d19e2c252c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace02360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efdf59c04fc608cf72d827f0db12fc26499265dd6f84db95810fb62454e0979c1f46a2803e59a4de4e7a4c574b1243f25977ac4c77d5a1a4a609b5394cebb4a2aa8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00f0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00a2646970667358221220be6b7b954331ee9e2c368ba1fd0708b0055339f19de764d78fb0014943f7c7ae64736f6c634300081a0033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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.