ETH Price: $2,936.48 (-0.39%)

Contract

0xcdfCaB084b2d29025772141d3BF473bd9673aaA8

Overview

ETH Balance

0 ETH

ETH Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Block
From
To
Sweep To Merchan...385935162026-01-25 11:51:151 hr ago1769341875IN
0xcdfCaB08...d9673aaA8
0 ETH0.000000030.0005
Sweep To Merchan...385430382026-01-24 21:49:5715 hrs ago1769291397IN
0xcdfCaB08...d9673aaA8
0 ETH0.000000030.0005
Sweep To Merchan...384714712026-01-24 1:57:1035 hrs ago1769219830IN
0xcdfCaB08...d9673aaA8
0 ETH0.000000030.0005
Sweep To Merchan...384339872026-01-23 15:32:2645 hrs ago1769182346IN
0xcdfCaB08...d9673aaA8
0 ETH0.000000050.0005
Sweep To Merchan...365755912026-01-02 3:19:1023 days ago1767323950IN
0xcdfCaB08...d9673aaA8
0 ETH00.00000028
Sweep To Merchan...365750982026-01-02 3:10:5723 days ago1767323457IN
0xcdfCaB08...d9673aaA8
0 ETH00.0000021
Sweep To Merchan...365750632026-01-02 3:10:2223 days ago1767323422IN
0xcdfCaB08...d9673aaA8
0 ETH00.00000205
Sweep To Merchan...365382072026-01-01 16:56:0623 days ago1767286566IN
0xcdfCaB08...d9673aaA8
0 ETH00.00000029
Sweep To Merchan...364681772025-12-31 21:28:5624 days ago1767216536IN
0xcdfCaB08...d9673aaA8
0 ETH00.00000026
Sweep To Merchan...364285962025-12-31 10:29:1525 days ago1767176955IN
0xcdfCaB08...d9673aaA8
0 ETH00.00000027
Sweep To Merchan...364249442025-12-31 9:28:2325 days ago1767173303IN
0xcdfCaB08...d9673aaA8
0 ETH00.00000027
Sweep To Merchan...364247792025-12-31 9:25:3825 days ago1767173138IN
0xcdfCaB08...d9673aaA8
0 ETH00.00002743
Sweep To Merchan...363800872025-12-30 21:00:4625 days ago1767128446IN
0xcdfCaB08...d9673aaA8
0 ETH00.00000027
Sweep To Merchan...363779512025-12-30 20:25:1025 days ago1767126310IN
0xcdfCaB08...d9673aaA8
0 ETH00.00000027

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block From To
385935162026-01-25 11:51:151 hr ago1769341875
0xcdfCaB08...d9673aaA8
0 ETH
385935162026-01-25 11:51:151 hr ago1769341875
0xcdfCaB08...d9673aaA8
0 ETH
385935162026-01-25 11:51:151 hr ago1769341875
0xcdfCaB08...d9673aaA8
0 ETH
385935162026-01-25 11:51:151 hr ago1769341875
0xcdfCaB08...d9673aaA8
0 ETH
385935162026-01-25 11:51:151 hr ago1769341875
0xcdfCaB08...d9673aaA8
0 ETH
385935162026-01-25 11:51:151 hr ago1769341875
0xcdfCaB08...d9673aaA8
0 ETH
385935162026-01-25 11:51:151 hr ago1769341875
0xcdfCaB08...d9673aaA8
0 ETH
385935152026-01-25 11:51:141 hr ago1769341874
0xcdfCaB08...d9673aaA8
0 ETH
385935152026-01-25 11:51:141 hr ago1769341874
0xcdfCaB08...d9673aaA8
0 ETH
385935152026-01-25 11:51:141 hr ago1769341874
0xcdfCaB08...d9673aaA8
0 ETH
385935152026-01-25 11:51:141 hr ago1769341874
0xcdfCaB08...d9673aaA8
0 ETH
385935152026-01-25 11:51:141 hr ago1769341874
0xcdfCaB08...d9673aaA8
0 ETH
385935152026-01-25 11:51:141 hr ago1769341874
0xcdfCaB08...d9673aaA8
0 ETH
385935152026-01-25 11:51:141 hr ago1769341874
0xcdfCaB08...d9673aaA8
0 ETH
385935152026-01-25 11:51:141 hr ago1769341874
0xcdfCaB08...d9673aaA8
0 ETH
385935152026-01-25 11:51:141 hr ago1769341874
0xcdfCaB08...d9673aaA8
0 ETH
385935152026-01-25 11:51:141 hr ago1769341874
0xcdfCaB08...d9673aaA8
0 ETH
385650032026-01-25 3:56:029 hrs ago1769313362
0xcdfCaB08...d9673aaA8
0 ETH
385650032026-01-25 3:56:029 hrs ago1769313362
0xcdfCaB08...d9673aaA8
0 ETH
385650032026-01-25 3:56:029 hrs ago1769313362
0xcdfCaB08...d9673aaA8
0 ETH
385650032026-01-25 3:56:029 hrs ago1769313362
0xcdfCaB08...d9673aaA8
0 ETH
385650032026-01-25 3:56:029 hrs ago1769313362
0xcdfCaB08...d9673aaA8
0 ETH
385650032026-01-25 3:56:029 hrs ago1769313362
0xcdfCaB08...d9673aaA8
0 ETH
385650032026-01-25 3:56:029 hrs ago1769313362
0xcdfCaB08...d9673aaA8
0 ETH
385650032026-01-25 3:56:029 hrs ago1769313362
0xcdfCaB08...d9673aaA8
0 ETH
View All Internal Transactions

Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
UniversalJITHook

Compiler Version
v0.8.26+commit.8a97fa7a

Optimization Enabled:
Yes with 100000 runs

Other Settings:
cancun EvmVersion
File 1 of 39 : UniversalJITHook.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

// OpenZeppelin Uniswap Hooks
import {BaseHook} from "@openzeppelin/uniswap-hooks/src/base/BaseHook.sol";
import {CurrencySettler, IERC20} from "@openzeppelin/uniswap-hooks/src/utils/CurrencySettler.sol";

// Uniswap V4 Core Interfaces
import {IPoolManager, SwapParams, ModifyLiquidityParams} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";

import {LiquidityAmounts} from "@uniswap/v4-core/test/utils/LiquidityAmounts.sol";

// Uniswap V4 Core Types
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
import {PoolId, PoolIdLibrary} from "@uniswap/v4-core/src/types/PoolId.sol";
import {Currency, CurrencyLibrary} from "@uniswap/v4-core/src/types/Currency.sol";
import {BalanceDelta, BalanceDeltaLibrary} from "@uniswap/v4-core/src/types/BalanceDelta.sol";
import {BeforeSwapDelta, BeforeSwapDeltaLibrary, toBeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";

// Uniswap V4 Core Libraries
import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";
import {TickMath} from "@uniswap/v4-core/src/libraries/TickMath.sol";
import {SafeCast} from "@uniswap/v4-core/src/libraries/SafeCast.sol";

// Hook Interfaces
import {IMinimalJITOracle, OracleReport} from "./interfaces/IMinimalJITOracle.sol";
import {IMinimalMerchantController} from "./interfaces/IMinimalMerchantController.sol";
import {IMinimalWrappedAssetV2} from "./interfaces/IMinimalWrappedAssetV2.sol";

// Hook Libraries
import {VirtualPrice, VirtualPriceLibrary} from "./lib/VirtualPrice.sol";

import {Ownable} from "solady/auth/Ownable.sol";

contract UniversalJITHook is BaseHook, Ownable {
    using PoolIdLibrary for PoolKey;
    using CurrencySettler for Currency;
    using CurrencyLibrary for Currency;
    using BalanceDeltaLibrary for BalanceDelta;
    using VirtualPriceLibrary for VirtualPrice;

    Currency public immutable PAIR_TOKEN;

    IMinimalJITOracle public oracle;
    IMinimalMerchantController public merchantController;
    address public merchant;

    mapping(PoolId => VirtualPrice) public upperVirtualPrice;
    mapping(PoolId => VirtualPrice) public lowerVirtualPrice;

    error AssetNotAllowed();
    error PairCurrencyNotAllowed();
    error NonWhitelistedAsset();
    error ZeroAddress();
    error OracleReportNotAvailable();
    error NotEnoughLiquidityUSDC();
    error UnsupportedOperation();
    error BlacklistedUser();
    error InvalidHook();

    /// @notice Emitted when a JIT swap is executed.
    /// @param poolId The pool ID.
    /// @param zeroForOne Whether the swap is zero for one.
    /// @param virtualSqrtPriceAfter The virtual sqrt price after the swap.
    /// @param amountIn The amount in.
    /// @param amountOut The amount out.
    event JITSwapResult(PoolId poolId, bool zeroForOne, uint160 virtualSqrtPriceAfter, uint256 amountIn, uint256 amountOut);

    constructor(
        IPoolManager _poolManager,
        IMinimalJITOracle _oracle,
        IMinimalMerchantController _merchantController,
        IERC20 _pairToken,
        address _owner,
        address _merchant
    ) BaseHook(_poolManager) {
        // Initialize owner
        _initializeOwner(_owner);

        // Set the oracle and merchant controller
        _setOracle(_oracle);
        _setMerchantController(_merchantController);
        _setMerchant(_merchant);

        // Check for zero addresses
        if (address(_poolManager) == address(0)) revert ZeroAddress();
        if (address(_pairToken) == address(0)) revert ZeroAddress();

        // Initialize the immutable variables
        PAIR_TOKEN = Currency.wrap(address(_pairToken));
    }

    function setOracle(IMinimalJITOracle _oracle) external onlyOwner {
        _setOracle(_oracle);
    }

    function setMerchantController(IMinimalMerchantController _merchantController) external onlyOwner {
        _setMerchantController(_merchantController);
    }

    function setMerchant(address _merchant) external onlyOwner {
        _setMerchant(_merchant);
    }

    function getHookPermissions() public pure override returns (Hooks.Permissions memory) {
        return Hooks.Permissions({
            beforeInitialize: true,
            afterInitialize: false,
            beforeAddLiquidity: true,
            afterAddLiquidity: false,
            beforeRemoveLiquidity: true,
            afterRemoveLiquidity: false,
            beforeSwap: true,
            afterSwap: false,
            beforeDonate: true,
            afterDonate: false,
            beforeSwapReturnDelta: true,
            afterSwapReturnDelta: false,
            afterAddLiquidityReturnDelta: false,
            afterRemoveLiquidityReturnDelta: false
        });
    }

    // ===================================
    // ===== HOOK INTERNAL FUNCTIONS =====
    // ===================================
    function _beforeInitialize(address sender, PoolKey calldata key, uint160) internal view override returns (bytes4) {
        if (sender != owner()) revert Unauthorized();

        // Check that at least one currency is PairCurrency and that the other is whitelisted as uAsset in MerchantController
        if (_isPairCurrency(key.currency0)) {
            if (!merchantController.isAssetWhitelisted(address(Currency.unwrap(key.currency1)))) revert AssetNotAllowed();
        } else if (_isPairCurrency(key.currency1)) {
            if (!merchantController.isAssetWhitelisted(address(Currency.unwrap(key.currency0)))) revert AssetNotAllowed();
        } else {
            revert PairCurrencyNotAllowed();
        }

        // Check the pool is whitelisted by trying to retrieve a price from the oracle
        try oracle.safeGetPrice(key.toId()) {
            // If the oracle report is available, continue
        } catch {
            // If the oracle report is not available, revert
            revert OracleReportNotAvailable();
        }

        return (BaseHook.beforeInitialize.selector);
    }
    
     function _beforeSwap(address, PoolKey calldata key, SwapParams calldata swapParams, bytes calldata)
        internal
        override
        returns (bytes4, BeforeSwapDelta, uint24)
    {
        // Check if the currency is whitelisted and the caller is not blacklisted
        if (!merchantController.isAssetWhitelisted(Currency.unwrap(key.currency0 == PAIR_TOKEN ? key.currency1 : key.currency0))) revert NonWhitelistedAsset();
        if (_isCallerBlacklisted(key.currency0 == PAIR_TOKEN ? key.currency1 : key.currency0)) revert BlacklistedUser();
        
        PoolId poolId = key.toId();
        
        // Get the oracle report
        OracleReport memory report = oracle.safeGetPrice(poolId);

        // If the oracle report is newer or happened in the same block as the last update, update the virtual price
        if (swapParams.zeroForOne && report.timestamp > lowerVirtualPrice[poolId].timestamp) {
            lowerVirtualPrice[poolId].update(TickMath.getSqrtPriceAtTick(report.jitLowerTick), report.timestamp);
        } else if (!swapParams.zeroForOne && report.timestamp > upperVirtualPrice[poolId].timestamp) {
            upperVirtualPrice[poolId].update(TickMath.getSqrtPriceAtTick(report.jitUpperTick), report.timestamp);
        }

        if (swapParams.zeroForOne) {
            return (BaseHook.beforeSwap.selector, _zeroForOneSwap(key, report, swapParams), 0);
        } else {
            return (BaseHook.beforeSwap.selector, _oneForZeroSwap(key, report, swapParams), 0);
        }
    }

    function _beforeAddLiquidity(address, PoolKey calldata, ModifyLiquidityParams calldata, bytes calldata)
        internal
        override
        returns (bytes4)
    {
        revert UnsupportedOperation();
    }

    function _beforeRemoveLiquidity(address, PoolKey calldata, ModifyLiquidityParams calldata, bytes calldata)
        internal
        override
        returns (bytes4)
    {
        revert UnsupportedOperation();
    }
    
    function _beforeDonate(address, PoolKey calldata, uint256, uint256, bytes calldata) internal override returns (bytes4) {
        revert UnsupportedOperation();
    }

    function _zeroForOneSwap(PoolKey calldata key, OracleReport memory report, SwapParams calldata swapParams) internal returns (BeforeSwapDelta delta) {
        (uint160 sqrtPriceLowerX96, uint160 sqrtPriceUpperX96, uint128 liquidity) = _computeReportZeroForOne(key, report);
        if (swapParams.amountSpecified < 0) {
            delta = _exactInputZeroToOne(key, sqrtPriceLowerX96, sqrtPriceUpperX96, swapParams.sqrtPriceLimitX96, liquidity, uint256(-swapParams.amountSpecified));
        } else {
            delta = _exactOutputZeroToOne(key, sqrtPriceLowerX96, sqrtPriceUpperX96, swapParams.sqrtPriceLimitX96, liquidity, uint256(swapParams.amountSpecified));
        }
    }

    function _oneForZeroSwap(PoolKey calldata key, OracleReport memory report, SwapParams calldata swapParams) internal returns (BeforeSwapDelta delta) {
        (uint160 sqrtPriceLowerX96, uint160 sqrtPriceUpperX96, uint128 liquidity) = _computeReportOneForZero(key, report);
        if (swapParams.amountSpecified < 0) {
            delta = _exactInputOneToZero(key, sqrtPriceLowerX96, sqrtPriceUpperX96, swapParams.sqrtPriceLimitX96, liquidity, uint256(-swapParams.amountSpecified));
        } else {
            delta = _exactOutputOneToZero(key, sqrtPriceLowerX96, sqrtPriceUpperX96, swapParams.sqrtPriceLimitX96, liquidity, uint256(swapParams.amountSpecified));
        }
    }

    function _computeReportZeroForOne(PoolKey calldata key, OracleReport memory report) internal view returns (uint160, uint160, uint128) {
        // Compute the tick range based on the oracle report
        int24 tickLower = report.jitLowerTick - int24(report.jitLowerRange);
        int24 tickUpper = report.jitLowerTick;

        uint160 sqrtPriceLowerX96 = TickMath.getSqrtPriceAtTick(tickLower);
        uint160 sqrtPriceUpperX96 = TickMath.getSqrtPriceAtTick(tickUpper);

        if (key.currency0 == PAIR_TOKEN) {
            // If buying uAssets, use the oracle liquidity
            uint128 liquidity = LiquidityAmounts.getLiquidityForAmount1(sqrtPriceLowerX96, sqrtPriceUpperX96, report.uAssetLiquidity);
            return (sqrtPriceLowerX96, lowerVirtualPrice[key.toId()].virtualSqrtPriceX96, liquidity);
        } else {
            uint128 liquidity = LiquidityAmounts.getLiquidityForAmount1(sqrtPriceLowerX96, sqrtPriceUpperX96, report.usdcLiquidity);
            return (sqrtPriceLowerX96, lowerVirtualPrice[key.toId()].virtualSqrtPriceX96, liquidity);
        }
    }

    function _computeReportOneForZero(PoolKey calldata key, OracleReport memory report) internal view returns (uint160, uint160, uint128) {
        // Compute the tick range based on the oracle report
        int24 tickLower = report.jitUpperTick;
        int24 tickUpper = report.jitUpperTick + int24(report.jitUpperRange);

        uint160 sqrtPriceLowerX96 = TickMath.getSqrtPriceAtTick(tickLower);
        uint160 sqrtPriceUpperX96 = TickMath.getSqrtPriceAtTick(tickUpper);

        if (key.currency1 == PAIR_TOKEN) {
            // If buying uAssets, use the oracle liquidity
            uint128 liquidity = LiquidityAmounts.getLiquidityForAmount0(sqrtPriceLowerX96, sqrtPriceUpperX96, report.uAssetLiquidity);
            return (upperVirtualPrice[key.toId()].virtualSqrtPriceX96,  sqrtPriceUpperX96, liquidity);
        } else {
            uint128 liquidity = LiquidityAmounts.getLiquidityForAmount0(sqrtPriceLowerX96, sqrtPriceUpperX96, report.usdcLiquidity);
            return (upperVirtualPrice[key.toId()].virtualSqrtPriceX96,  sqrtPriceUpperX96, liquidity);
        }
    }


    function _exactInputZeroToOne(PoolKey calldata key, uint160 sqrtPriceLowerX96, uint160 sqrtPriceUpperX96, uint160 sqrtPriceLimitX96, uint128 liquidity, uint256 amountIn) internal returns (BeforeSwapDelta delta) {
        (uint256 amount1Out, uint256 amount0InAfter, uint160 sqrtPriceAfter) = VirtualPriceLibrary.quoteExactInputZeroForOneWithLimit(
            liquidity,
            sqrtPriceUpperX96,
            sqrtPriceLowerX96,
            sqrtPriceLimitX96,
            amountIn
        );

        PoolId poolId = key.toId();

        lowerVirtualPrice[poolId].updatePrice(sqrtPriceAfter);

        delta = toBeforeSwapDelta(
            int128(SafeCast.toInt128(amount0InAfter)), // Specified amount (input delta)
            int128(SafeCast.toInt128(-int256(amount1Out))) // Unspecified amount (output delta)
        );

        if (key.currency0 == PAIR_TOKEN) {
            _takeUSDC(amount0InAfter);
            _settleUAsset(key.currency1, amount1Out);

        } else {
            _takeUAsset(key.currency0, amount0InAfter);
            _settleUSDC(amount1Out);
        }

        emit JITSwapResult(poolId, true, sqrtPriceAfter, amount0InAfter, amount1Out);
    }

    function _exactOutputZeroToOne(
        PoolKey calldata key,
        uint160 sqrtPriceLowerX96,
        uint160 sqrtPriceUpperX96,
        uint160 sqrtPriceLimitX96,
        uint128 liquidity,
        uint256 amountOut
    ) internal returns (BeforeSwapDelta delta) {
        (uint256 amount0In, uint256 amount1OutAfter, uint160 sqrtPriceAfter) = VirtualPriceLibrary.quoteExactOutputZeroForOneWithLimit(
            liquidity,
            sqrtPriceUpperX96,
            sqrtPriceLowerX96,
            sqrtPriceLimitX96,
            amountOut
        );

        PoolId poolId = key.toId();

        lowerVirtualPrice[poolId].updatePrice(sqrtPriceAfter);

        delta = toBeforeSwapDelta(
            -int128(SafeCast.toInt128(amount1OutAfter)), // Specified amount (output provided by hook)
            int128(SafeCast.toInt128(amount0In)) // Unspecified amount (input owed to hook)
        );

        if (key.currency0 == PAIR_TOKEN) {
            _takeUSDC(amount0In);
            _settleUAsset(key.currency1, amount1OutAfter);

        } else {
            _takeUAsset(key.currency0, amount0In);
            _settleUSDC(amount1OutAfter);
        }

        emit JITSwapResult(poolId, true, sqrtPriceAfter, amount0In, amount1OutAfter);
    }

    function _exactInputOneToZero(PoolKey calldata key, uint160 sqrtPriceLowerX96, uint160 sqrtPriceUpperX96, uint160 sqrtPriceLimitX96, uint128 liquidity, uint256 amountIn) internal returns (BeforeSwapDelta delta) {
        (uint256 amount0Out, uint256 amount1InAfter, uint160 sqrtPriceAfter) = VirtualPriceLibrary.quoteExactInputOneForZeroWithLimit(
            liquidity,
            sqrtPriceLowerX96,
            sqrtPriceUpperX96,
            sqrtPriceLimitX96,
            amountIn
        );

        PoolId poolId = key.toId();

        upperVirtualPrice[poolId].updatePrice(sqrtPriceAfter);

        delta = toBeforeSwapDelta(
            int128(SafeCast.toInt128(amount1InAfter)), // Specified amount (input delta)
            int128(SafeCast.toInt128(-int256(amount0Out))) // Unspecified amount (output delta)
        );

        if (key.currency1 == PAIR_TOKEN) {
            _takeUSDC(amount1InAfter);
            _settleUAsset(key.currency0, amount0Out);

        } else {
            _takeUAsset(key.currency1, amount1InAfter);
            _settleUSDC(amount0Out);
        }

        emit JITSwapResult(poolId, false, sqrtPriceAfter, amount1InAfter, amount0Out);
    }

    function _exactOutputOneToZero(
        PoolKey calldata key,
        uint160 sqrtPriceLowerX96,
        uint160 sqrtPriceUpperX96,
        uint160 sqrtPriceLimitX96,
        uint128 liquidity,
        uint256 amountOut
    ) internal returns (BeforeSwapDelta delta) {
        (uint256 amount1In, uint256 amount0OutAfter, uint160 sqrtPriceAfter) = VirtualPriceLibrary.quoteExactOutputOneForZeroWithLimit(
            liquidity,
            sqrtPriceLowerX96,
            sqrtPriceUpperX96,
            sqrtPriceLimitX96,
            amountOut
        );

        PoolId poolId = key.toId();    

        upperVirtualPrice[poolId].updatePrice(sqrtPriceAfter);

        delta = toBeforeSwapDelta(
            -int128(SafeCast.toInt128(amount0OutAfter)), // Specified amount (output provided by hook)
            int128(SafeCast.toInt128(amount1In)) // Unspecified amount (input owed to hook)
        );

        if (key.currency1 == PAIR_TOKEN) {
            _takeUSDC(amount1In);
            _settleUAsset(key.currency0, amount0OutAfter);

        } else {
            _takeUAsset(key.currency1, amount1In);
            _settleUSDC(amount0OutAfter);
        }

        emit JITSwapResult(poolId, false, sqrtPriceAfter, amount1In, amount0OutAfter);
    }

    function _takeUSDC(uint256 amount) internal {
        PAIR_TOKEN.take(poolManager, address(this), amount, true);
    }

    function _takeUAsset(Currency asset, uint256 amount) internal {
        asset.take(poolManager, address(this), amount, true);
    }

    // Burns PAIR_TOKEN claims and settles the remainder to the merchant
    function _settleUSDC(uint256 amount) internal {
        uint256 settled = _settleWithClaims(PAIR_TOKEN, amount);
        uint256 remain = amount - settled;

        if (remain > 0) {
            if (remain > PAIR_TOKEN.balanceOf(address(merchant))) revert NotEnoughLiquidityUSDC();
            PAIR_TOKEN.settle(poolManager, merchant, remain, false);
        }
    }

    function _settleUAsset(Currency asset, uint256 amount) internal {
        uint256 settled = _settleWithClaims(asset, amount);
        uint256 remain = amount - settled;

        if (remain > 0) {
            address assetAddress = Currency.unwrap(asset);
            merchantController.mintFromHook(assetAddress, address(this), remain);
            asset.settle(poolManager, address(this), remain, false);
        }
    }

    function _settleWithClaims(Currency currency, uint256 amount) internal returns (uint256) {
        if (amount == 0) return 0;

        // Claims from hook for that currency
        uint256 claims = poolManager.balanceOf(address(this), currency.toId());
        if (claims == 0) return 0;

        uint256 useAmt = amount < claims ? amount : claims;
        currency.settle(poolManager, address(this), useAmt, true);

        // Clean up leftover claims
        if (claims > useAmt) {
            _clearCurrencyClaims(currency, claims - useAmt);
        }
        
        return useAmt;
    }

    function _clearCurrencyClaims(Currency currency, uint256 amount) internal {
        uint256 poolBalance = currency.balanceOf(address(poolManager));
        uint256 available = amount < poolBalance ? amount : poolBalance;
        if (available == 0) return;

        poolManager.burn(address(this), currency.toId(), available);
        if (_isPairCurrency(currency)) {
            currency.take(poolManager, merchant, available, false);
        } else {
            currency.take(poolManager, address(this), available, false);
            merchantController.burnFromHook(Currency.unwrap(currency), address(this), available);
        }
    }

    // ==============================================
    // ========== Post-swap sweeping (TX 2) =========
    // ==============================================
    function sweepToMerchant(PoolKey calldata key) external {
        if (address(key.hooks) != address(this)) revert InvalidHook();

        // Check if the currency is whitelisted
        if (_isPairCurrency(key.currency0)) {
            if (!merchantController.isAssetWhitelisted(address(Currency.unwrap(key.currency1)))) revert AssetNotAllowed();
        } else if (_isPairCurrency(key.currency1)) {
            if (!merchantController.isAssetWhitelisted(address(Currency.unwrap(key.currency0)))) revert AssetNotAllowed();
        } else {
            revert PairCurrencyNotAllowed();
        }
        
        poolManager.unlock(abi.encode(key));
    }

    function unlockCallback(bytes calldata data) external onlyPoolManager returns (bytes memory) {
        PoolKey memory key = abi.decode(data, (PoolKey));


        bool pairIs0 = _isPairCurrency(key.currency0);
        Currency pairCurrency = pairIs0 ? key.currency0 : key.currency1; // USDC
        Currency wrappedCurrency = pairIs0 ? key.currency1 : key.currency0; // uAsset

        // Burn wrapped claims (take to hook and burn)
        uint256 wrappedClaims = poolManager.balanceOf(address(this), wrappedCurrency.toId());
        if (wrappedClaims > 0) {
            poolManager.burn(address(this), wrappedCurrency.toId(), wrappedClaims);
            wrappedCurrency.take(poolManager, address(this), wrappedClaims, false);
            merchantController.burnFromHook(Currency.unwrap(wrappedCurrency), address(this), wrappedClaims);
        }

        // Move USDC claims to merchant
        uint256 pairClaims = poolManager.balanceOf(address(this), pairCurrency.toId());
        if (pairClaims > 0) {
            poolManager.burn(address(this), pairCurrency.toId(), pairClaims);
            pairCurrency.take(poolManager, merchant, pairClaims, false);
        }

        return "";
    }

    // ==============================
    // ====== Private Functions =====
    // ==============================
    function _setOracle(IMinimalJITOracle _oracle) private {
        if (address(_oracle) == address(0)) revert ZeroAddress();
        oracle = _oracle;
    }

    function _setMerchantController(IMinimalMerchantController _merchantController) private {
        if (address(_merchantController) == address(0)) revert ZeroAddress();
        merchantController = _merchantController;
    }

    function _setMerchant(address _merchant) private {
        if (_merchant == address(0)) revert ZeroAddress();
        merchant = _merchant;
    }

    function _isPairCurrency(Currency currency) private view returns (bool) {
        return Currency.unwrap(currency) == Currency.unwrap(PAIR_TOKEN);
    }

    function _isCallerBlacklisted(Currency currency) private view returns (bool) {
        IMinimalWrappedAssetV2 token = IMinimalWrappedAssetV2(Currency.unwrap(currency));
        return token.getUserBlacklist(tx.origin);
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Uniswap Hooks (last updated v1.2.0) (src/base/BaseHook.sol)

pragma solidity ^0.8.26;

// External imports
import {IHooks} from "@uniswap/v4-core/src/interfaces/IHooks.sol";
import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";
import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
import {BeforeSwapDelta} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";
import {SwapParams, ModifyLiquidityParams} from "@uniswap/v4-core/src/types/PoolOperation.sol";

/**
 * @dev Base hook implementation.
 *
 * This contract defines all hook entry points, as well as security and permission helpers.
 * Based on the https://github.com/Uniswap/v4-periphery/blob/main/src/base/hooks/BaseHook.sol[Uniswap v4 periphery implementation].
 *
 * NOTE: Hook entry points must be overridden and implemented by the inheriting hook to be used. Their respective
 * flags must be set to true in the `getHookPermissions` function as well.
 *
 * WARNING: This is experimental software and is provided on an "as is" and "as available" basis. We do
 * not give any warranties and will not be liable for any losses incurred through any use of this code
 * base.
 *
 * _Available since v0.1.0_
 */
abstract contract BaseHook is IHooks {
    /*
     * @dev The pool manager singleton contract.
     */
    IPoolManager public immutable poolManager;

    /**
     * @dev The hook function is not implemented.
     */
    error HookNotImplemented();

    /**
     * @notice Thrown when calling unlockCallback where the caller is not `PoolManager`.
     */
    error NotPoolManager();

    /**
     * @dev Check that the hook address matches the expected permissions and flags.
     */
    constructor(IPoolManager _poolManager) {
        poolManager = _poolManager;
        _validateHookAddress(this);
    }

    /**
     * @notice Only allow calls from the `PoolManager` contract
     */
    modifier onlyPoolManager() {
        if (msg.sender != address(poolManager)) revert NotPoolManager();
        _;
    }

    /**
     * @dev Get the hook permissions to signal which hook functions are to be implemented.
     *
     * Used at deployment to validate the address correctly represents the expected permissions.
     *
     * @return permissions The hook permissions.
     */
    function getHookPermissions() public pure virtual returns (Hooks.Permissions memory permissions);

    /**
     * @dev Validate the hook address against the expected permissions.
     */
    function _validateHookAddress(BaseHook hook) internal pure {
        Hooks.validateHookPermissions(hook, getHookPermissions());
    }

    /**
     * @inheritdoc IHooks
     */
    function beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96)
        external
        onlyPoolManager
        returns (bytes4)
    {
        return _beforeInitialize(sender, key, sqrtPriceX96);
    }

    /**
     * @dev Hook implementation for `beforeInitialize`, to be overridden by the inheriting hook. The
     * flag must be set to true in the `getHookPermissions` function.
     */
    function _beforeInitialize(address, PoolKey calldata, uint160) internal virtual returns (bytes4) {
        revert HookNotImplemented();
    }

    /**
     * @inheritdoc IHooks
     */
    function afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)
        external
        onlyPoolManager
        returns (bytes4)
    {
        return _afterInitialize(sender, key, sqrtPriceX96, tick);
    }

    /**
     * @dev Hook implementation for `afterInitialize`, to be overridden by the inheriting hook. The
     * flag must be set to true in the `getHookPermissions` function.
     */
    function _afterInitialize(address, PoolKey calldata, uint160, int24) internal virtual returns (bytes4) {
        revert HookNotImplemented();
    }

    /**
     * @inheritdoc IHooks
     */
    function beforeAddLiquidity(
        address sender,
        PoolKey calldata key,
        ModifyLiquidityParams calldata params,
        bytes calldata hookData
    ) external onlyPoolManager returns (bytes4) {
        return _beforeAddLiquidity(sender, key, params, hookData);
    }

    /**
     * @dev Hook implementation for `beforeAddLiquidity`, to be overridden by the inheriting hook. The
     * flag must be set to true in the `getHookPermissions` function.
     */
    function _beforeAddLiquidity(address, PoolKey calldata, ModifyLiquidityParams calldata, bytes calldata)
        internal
        virtual
        returns (bytes4)
    {
        revert HookNotImplemented();
    }

    /**
     * @inheritdoc IHooks
     */
    function beforeRemoveLiquidity(
        address sender,
        PoolKey calldata key,
        ModifyLiquidityParams calldata params,
        bytes calldata hookData
    ) external onlyPoolManager returns (bytes4) {
        return _beforeRemoveLiquidity(sender, key, params, hookData);
    }

    /**
     * @dev Hook implementation for `beforeRemoveLiquidity`, to be overridden by the inheriting hook. The
     * flag must be set to true in the `getHookPermissions` function.
     */
    function _beforeRemoveLiquidity(address, PoolKey calldata, ModifyLiquidityParams calldata, bytes calldata)
        internal
        virtual
        returns (bytes4)
    {
        revert HookNotImplemented();
    }

    /**
     * @inheritdoc IHooks
     */
    function afterAddLiquidity(
        address sender,
        PoolKey calldata key,
        ModifyLiquidityParams calldata params,
        BalanceDelta delta0,
        BalanceDelta delta1,
        bytes calldata hookData
    ) external onlyPoolManager returns (bytes4, BalanceDelta) {
        return _afterAddLiquidity(sender, key, params, delta0, delta1, hookData);
    }

    /**
     * @dev Hook implementation for `afterAddLiquidity`, to be overridden by the inheriting hook. The
     * flag must be set to true in the `getHookPermissions` function.
     */
    function _afterAddLiquidity(
        address,
        PoolKey calldata,
        ModifyLiquidityParams calldata,
        BalanceDelta,
        BalanceDelta,
        bytes calldata
    ) internal virtual returns (bytes4, BalanceDelta) {
        revert HookNotImplemented();
    }

    /**
     * @inheritdoc IHooks
     */
    function afterRemoveLiquidity(
        address sender,
        PoolKey calldata key,
        ModifyLiquidityParams calldata params,
        BalanceDelta delta0,
        BalanceDelta delta1,
        bytes calldata hookData
    ) external onlyPoolManager returns (bytes4, BalanceDelta) {
        return _afterRemoveLiquidity(sender, key, params, delta0, delta1, hookData);
    }

    /**
     * @dev Hook implementation for `afterRemoveLiquidity`, to be overridden by the inheriting hook. The
     * flag must be set to true in the `getHookPermissions` function.
     */
    function _afterRemoveLiquidity(
        address,
        PoolKey calldata,
        ModifyLiquidityParams calldata,
        BalanceDelta,
        BalanceDelta,
        bytes calldata
    ) internal virtual returns (bytes4, BalanceDelta) {
        revert HookNotImplemented();
    }

    /**
     * @inheritdoc IHooks
     */
    function beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)
        external
        onlyPoolManager
        returns (bytes4, BeforeSwapDelta, uint24)
    {
        return _beforeSwap(sender, key, params, hookData);
    }

    /**
     * @dev Hook implementation for `beforeSwap`, to be overridden by the inheriting hook. The
     * flag must be set to true in the `getHookPermissions` function.
     */
    function _beforeSwap(address, PoolKey calldata, SwapParams calldata, bytes calldata)
        internal
        virtual
        returns (bytes4, BeforeSwapDelta, uint24)
    {
        revert HookNotImplemented();
    }

    /**
     * @inheritdoc IHooks
     */
    function afterSwap(
        address sender,
        PoolKey calldata key,
        SwapParams calldata params,
        BalanceDelta delta,
        bytes calldata hookData
    ) external onlyPoolManager returns (bytes4, int128) {
        return _afterSwap(sender, key, params, delta, hookData);
    }

    /**
     * @dev Hook implementation for `afterSwap`, to be overridden by the inheriting hook. The
     * flag must be set to true in the `getHookPermissions` function.
     */
    function _afterSwap(address, PoolKey calldata, SwapParams calldata, BalanceDelta, bytes calldata)
        internal
        virtual
        returns (bytes4, int128)
    {
        revert HookNotImplemented();
    }

    /**
     * @inheritdoc IHooks
     */
    function beforeDonate(
        address sender,
        PoolKey calldata key,
        uint256 amount0,
        uint256 amount1,
        bytes calldata hookData
    ) external onlyPoolManager returns (bytes4) {
        return _beforeDonate(sender, key, amount0, amount1, hookData);
    }

    /**
     * @dev Hook implementation for `beforeDonate`, to be overridden by the inheriting hook. The
     * flag must be set to true in the `getHookPermissions` function.
     */
    function _beforeDonate(address, PoolKey calldata, uint256, uint256, bytes calldata)
        internal
        virtual
        returns (bytes4)
    {
        revert HookNotImplemented();
    }

    /**
     * @inheritdoc IHooks
     */
    function afterDonate(
        address sender,
        PoolKey calldata key,
        uint256 amount0,
        uint256 amount1,
        bytes calldata hookData
    ) external onlyPoolManager returns (bytes4) {
        return _afterDonate(sender, key, amount0, amount1, hookData);
    }

    /**
     * @dev Hook implementation for `afterDonate`, to be overridden by the inheriting hook. The
     * flag must be set to true in the `getHookPermissions` function.
     */
    function _afterDonate(address, PoolKey calldata, uint256, uint256, bytes calldata)
        internal
        virtual
        returns (bytes4)
    {
        revert HookNotImplemented();
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Uniswap Hooks (last updated v0.1.0) (src/utils/CurrencySettler.sol)

pragma solidity ^0.8.26;

// External imports
import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

/**
 * @dev Library used to interact with the `PoolManager` to settle any open deltas.
 * To settle a positive delta (a credit to the user), a user may take or mint.
 * To settle a negative delta (a debt on the user), a user may transfer or burn to pay off a debt.
 *
 * Based on the https://github.com/Uniswap/v4-core/blob/main/test/utils/CurrencySettler.sol[Uniswap v4 test utils implementation].
 *
 * NOTE: Deltas are synced before any ERC-20 transfers in {settle} function.
 */
library CurrencySettler {
    using SafeERC20 for IERC20;

    /**
     * @notice Settle (pay) a currency to the `PoolManager`
     * @param currency Currency to settle
     * @param poolManager `PoolManager` to settle to
     * @param payer Address of the payer, which can be the hook itself or an external address.
     * @param amount Amount to send
     * @param burn If true, burn the ERC-6909 token, otherwise transfer ERC-20 to the `PoolManager`
     */
    function settle(Currency currency, IPoolManager poolManager, address payer, uint256 amount, bool burn) internal {
        // Early return when amount is 0 given that some tokens may revert in this case
        if (amount == 0) return;

        // For native currencies or burns, calling sync is not required
        // Short circuit for ERC-6909 burns to support ERC-6909-wrapped native tokens
        if (burn) {
            poolManager.burn(payer, currency.toId(), amount);
        } else if (currency.isAddressZero()) {
            poolManager.sync(currency);
            poolManager.settle{value: amount}();
        } else {
            poolManager.sync(currency);
            if (payer != address(this)) {
                IERC20(Currency.unwrap(currency)).safeTransferFrom(payer, address(poolManager), amount);
            } else {
                IERC20(Currency.unwrap(currency)).safeTransfer(address(poolManager), amount);
            }
            poolManager.settle();
        }
    }

    /**
     * @notice Take (receive) a currency from the `PoolManager`
     * @param currency Currency to take
     * @param poolManager `PoolManager` to take from
     * @param recipient Address of the recipient of the ERC-6909 or ERC-20 token.
     * @param amount Amount to receive
     * @param claims If true, mint the ERC-6909 token, otherwise transfer ERC-20 from the `PoolManager` to recipient
     */
    function take(Currency currency, IPoolManager poolManager, address recipient, uint256 amount, bool claims)
        internal
    {
        // Early return when amount is 0 given that some tokens may revert in this case
        if (amount == 0) return;

        claims ? poolManager.mint(recipient, currency.toId(), amount) : poolManager.take(currency, recipient, amount);
    }
}

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

import {Currency} from "../types/Currency.sol";
import {PoolKey} from "../types/PoolKey.sol";
import {IHooks} from "./IHooks.sol";
import {IERC6909Claims} from "./external/IERC6909Claims.sol";
import {IProtocolFees} from "./IProtocolFees.sol";
import {BalanceDelta} from "../types/BalanceDelta.sol";
import {PoolId} from "../types/PoolId.sol";
import {IExtsload} from "./IExtsload.sol";
import {IExttload} from "./IExttload.sol";
import {ModifyLiquidityParams, SwapParams} from "../types/PoolOperation.sol";

/// @notice Interface for the PoolManager
interface IPoolManager is IProtocolFees, IERC6909Claims, IExtsload, IExttload {
    /// @notice Thrown when a currency is not netted out after the contract is unlocked
    error CurrencyNotSettled();

    /// @notice Thrown when trying to interact with a non-initialized pool
    error PoolNotInitialized();

    /// @notice Thrown when unlock is called, but the contract is already unlocked
    error AlreadyUnlocked();

    /// @notice Thrown when a function is called that requires the contract to be unlocked, but it is not
    error ManagerLocked();

    /// @notice Pools are limited to type(int16).max tickSpacing in #initialize, to prevent overflow
    error TickSpacingTooLarge(int24 tickSpacing);

    /// @notice Pools must have a positive non-zero tickSpacing passed to #initialize
    error TickSpacingTooSmall(int24 tickSpacing);

    /// @notice PoolKey must have currencies where address(currency0) < address(currency1)
    error CurrenciesOutOfOrderOrEqual(address currency0, address currency1);

    /// @notice Thrown when a call to updateDynamicLPFee is made by an address that is not the hook,
    /// or on a pool that does not have a dynamic swap fee.
    error UnauthorizedDynamicLPFeeUpdate();

    /// @notice Thrown when trying to swap amount of 0
    error SwapAmountCannotBeZero();

    ///@notice Thrown when native currency is passed to a non native settlement
    error NonzeroNativeValue();

    /// @notice Thrown when `clear` is called with an amount that is not exactly equal to the open currency delta.
    error MustClearExactPositiveDelta();

    /// @notice Emitted when a new pool is initialized
    /// @param id The abi encoded hash of the pool key struct for the new pool
    /// @param currency0 The first currency of the pool by address sort order
    /// @param currency1 The second currency 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 hooks The hooks contract address for the pool, or address(0) if none
    /// @param sqrtPriceX96 The price of the pool on initialization
    /// @param tick The initial tick of the pool corresponding to the initialized price
    event Initialize(
        PoolId indexed id,
        Currency indexed currency0,
        Currency indexed currency1,
        uint24 fee,
        int24 tickSpacing,
        IHooks hooks,
        uint160 sqrtPriceX96,
        int24 tick
    );

    /// @notice Emitted when a liquidity position is modified
    /// @param id The abi encoded hash of the pool key struct for the pool that was modified
    /// @param sender The address that modified the pool
    /// @param tickLower The lower tick of the position
    /// @param tickUpper The upper tick of the position
    /// @param liquidityDelta The amount of liquidity that was added or removed
    /// @param salt The extra data to make positions unique
    event ModifyLiquidity(
        PoolId indexed id, address indexed sender, int24 tickLower, int24 tickUpper, int256 liquidityDelta, bytes32 salt
    );

    /// @notice Emitted for swaps between currency0 and currency1
    /// @param id The abi encoded hash of the pool key struct for the pool that was modified
    /// @param sender The address that initiated the swap call, and that received the callback
    /// @param amount0 The delta of the currency0 balance of the pool
    /// @param amount1 The delta of the currency1 balance of the pool
    /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96
    /// @param liquidity The liquidity of the pool after the swap
    /// @param tick The log base 1.0001 of the price of the pool after the swap
    /// @param fee The swap fee in hundredths of a bip
    event Swap(
        PoolId indexed id,
        address indexed sender,
        int128 amount0,
        int128 amount1,
        uint160 sqrtPriceX96,
        uint128 liquidity,
        int24 tick,
        uint24 fee
    );

    /// @notice Emitted for donations
    /// @param id The abi encoded hash of the pool key struct for the pool that was donated to
    /// @param sender The address that initiated the donate call
    /// @param amount0 The amount donated in currency0
    /// @param amount1 The amount donated in currency1
    event Donate(PoolId indexed id, address indexed sender, uint256 amount0, uint256 amount1);

    /// @notice All interactions on the contract that account deltas require unlocking. A caller that calls `unlock` must implement
    /// `IUnlockCallback(msg.sender).unlockCallback(data)`, where they interact with the remaining functions on this contract.
    /// @dev The only functions callable without an unlocking are `initialize` and `updateDynamicLPFee`
    /// @param data Any data to pass to the callback, via `IUnlockCallback(msg.sender).unlockCallback(data)`
    /// @return The data returned by the call to `IUnlockCallback(msg.sender).unlockCallback(data)`
    function unlock(bytes calldata data) external returns (bytes memory);

    /// @notice Initialize the state for a given pool ID
    /// @dev A swap fee totaling MAX_SWAP_FEE (100%) makes exact output swaps impossible since the input is entirely consumed by the fee
    /// @param key The pool key for the pool to initialize
    /// @param sqrtPriceX96 The initial square root price
    /// @return tick The initial tick of the pool
    function initialize(PoolKey memory key, uint160 sqrtPriceX96) external returns (int24 tick);

    /// @notice Modify the liquidity for the given pool
    /// @dev Poke by calling with a zero liquidityDelta
    /// @param key The pool to modify liquidity in
    /// @param params The parameters for modifying the liquidity
    /// @param hookData The data to pass through to the add/removeLiquidity hooks
    /// @return callerDelta The balance delta of the caller of modifyLiquidity. This is the total of both principal, fee deltas, and hook deltas if applicable
    /// @return feesAccrued The balance delta of the fees generated in the liquidity range. Returned for informational purposes
    /// @dev Note that feesAccrued can be artificially inflated by a malicious actor and integrators should be careful using the value
    /// For pools with a single liquidity position, actors can donate to themselves to inflate feeGrowthGlobal (and consequently feesAccrued)
    /// atomically donating and collecting fees in the same unlockCallback may make the inflated value more extreme
    function modifyLiquidity(PoolKey memory key, ModifyLiquidityParams memory params, bytes calldata hookData)
        external
        returns (BalanceDelta callerDelta, BalanceDelta feesAccrued);

    /// @notice Swap against the given pool
    /// @param key The pool to swap in
    /// @param params The parameters for swapping
    /// @param hookData The data to pass through to the swap hooks
    /// @return swapDelta The balance delta of the address swapping
    /// @dev Swapping on low liquidity pools may cause unexpected swap amounts when liquidity available is less than amountSpecified.
    /// Additionally note that if interacting with hooks that have the BEFORE_SWAP_RETURNS_DELTA_FLAG or AFTER_SWAP_RETURNS_DELTA_FLAG
    /// the hook may alter the swap input/output. Integrators should perform checks on the returned swapDelta.
    function swap(PoolKey memory key, SwapParams memory params, bytes calldata hookData)
        external
        returns (BalanceDelta swapDelta);

    /// @notice Donate the given currency amounts to the in-range liquidity providers of a pool
    /// @dev Calls to donate can be frontrun adding just-in-time liquidity, with the aim of receiving a portion donated funds.
    /// Donors should keep this in mind when designing donation mechanisms.
    /// @dev This function donates to in-range LPs at slot0.tick. In certain edge-cases of the swap algorithm, the `sqrtPrice` of
    /// a pool can be at the lower boundary of tick `n`, but the `slot0.tick` of the pool is already `n - 1`. In this case a call to
    /// `donate` would donate to tick `n - 1` (slot0.tick) not tick `n` (getTickAtSqrtPrice(slot0.sqrtPriceX96)).
    /// Read the comments in `Pool.swap()` for more information about this.
    /// @param key The key of the pool to donate to
    /// @param amount0 The amount of currency0 to donate
    /// @param amount1 The amount of currency1 to donate
    /// @param hookData The data to pass through to the donate hooks
    /// @return BalanceDelta The delta of the caller after the donate
    function donate(PoolKey memory key, uint256 amount0, uint256 amount1, bytes calldata hookData)
        external
        returns (BalanceDelta);

    /// @notice Writes the current ERC20 balance of the specified currency to transient storage
    /// This is used to checkpoint balances for the manager and derive deltas for the caller.
    /// @dev This MUST be called before any ERC20 tokens are sent into the contract, but can be skipped
    /// for native tokens because the amount to settle is determined by the sent value.
    /// However, if an ERC20 token has been synced and not settled, and the caller instead wants to settle
    /// native funds, this function can be called with the native currency to then be able to settle the native currency
    function sync(Currency currency) external;

    /// @notice Called by the user to net out some value owed to the user
    /// @dev Will revert if the requested amount is not available, consider using `mint` instead
    /// @dev Can also be used as a mechanism for free flash loans
    /// @param currency The currency to withdraw from the pool manager
    /// @param to The address to withdraw to
    /// @param amount The amount of currency to withdraw
    function take(Currency currency, address to, uint256 amount) external;

    /// @notice Called by the user to pay what is owed
    /// @return paid The amount of currency settled
    function settle() external payable returns (uint256 paid);

    /// @notice Called by the user to pay on behalf of another address
    /// @param recipient The address to credit for the payment
    /// @return paid The amount of currency settled
    function settleFor(address recipient) external payable returns (uint256 paid);

    /// @notice WARNING - Any currency that is cleared, will be non-retrievable, and locked in the contract permanently.
    /// A call to clear will zero out a positive balance WITHOUT a corresponding transfer.
    /// @dev This could be used to clear a balance that is considered dust.
    /// Additionally, the amount must be the exact positive balance. This is to enforce that the caller is aware of the amount being cleared.
    function clear(Currency currency, uint256 amount) external;

    /// @notice Called by the user to move value into ERC6909 balance
    /// @param to The address to mint the tokens to
    /// @param id The currency address to mint to ERC6909s, as a uint256
    /// @param amount The amount of currency to mint
    /// @dev The id is converted to a uint160 to correspond to a currency address
    /// If the upper 12 bytes are not 0, they will be 0-ed out
    function mint(address to, uint256 id, uint256 amount) external;

    /// @notice Called by the user to move value from ERC6909 balance
    /// @param from The address to burn the tokens from
    /// @param id The currency address to burn from ERC6909s, as a uint256
    /// @param amount The amount of currency to burn
    /// @dev The id is converted to a uint160 to correspond to a currency address
    /// If the upper 12 bytes are not 0, they will be 0-ed out
    function burn(address from, uint256 id, uint256 amount) external;

    /// @notice Updates the pools lp fees for the a pool that has enabled dynamic lp fees.
    /// @dev A swap fee totaling MAX_SWAP_FEE (100%) makes exact output swaps impossible since the input is entirely consumed by the fee
    /// @param key The key of the pool to update dynamic LP fees for
    /// @param newDynamicLPFee The new dynamic pool LP fee
    function updateDynamicLPFee(PoolKey memory key, uint24 newDynamicLPFee) external;
}

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import "../../src/libraries/FullMath.sol";
import "../../src/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, "liquidity overflow");
    }

    /// @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 sqrtPriceAX96 A sqrt price representing the first tick boundary
    /// @param sqrtPriceBX96 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 sqrtPriceAX96, uint160 sqrtPriceBX96, uint256 amount0)
        internal
        pure
        returns (uint128 liquidity)
    {
        if (sqrtPriceAX96 > sqrtPriceBX96) (sqrtPriceAX96, sqrtPriceBX96) = (sqrtPriceBX96, sqrtPriceAX96);
        uint256 intermediate = FullMath.mulDiv(sqrtPriceAX96, sqrtPriceBX96, FixedPoint96.Q96);
        return toUint128(FullMath.mulDiv(amount0, intermediate, sqrtPriceBX96 - sqrtPriceAX96));
    }

    /// @notice Computes the amount of liquidity received for a given amount of token1 and price range
    /// @dev Calculates amount1 / (sqrt(upper) - sqrt(lower)).
    /// @param sqrtPriceAX96 A sqrt price representing the first tick boundary
    /// @param sqrtPriceBX96 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 sqrtPriceAX96, uint160 sqrtPriceBX96, uint256 amount1)
        internal
        pure
        returns (uint128 liquidity)
    {
        if (sqrtPriceAX96 > sqrtPriceBX96) (sqrtPriceAX96, sqrtPriceBX96) = (sqrtPriceBX96, sqrtPriceAX96);
        return toUint128(FullMath.mulDiv(amount1, FixedPoint96.Q96, sqrtPriceBX96 - sqrtPriceAX96));
    }

    /// @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 sqrtPriceX96 A sqrt price representing the current pool prices
    /// @param sqrtPriceAX96 A sqrt price representing the first tick boundary
    /// @param sqrtPriceBX96 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 sqrtPriceX96,
        uint160 sqrtPriceAX96,
        uint160 sqrtPriceBX96,
        uint256 amount0,
        uint256 amount1
    ) internal pure returns (uint128 liquidity) {
        if (sqrtPriceAX96 > sqrtPriceBX96) (sqrtPriceAX96, sqrtPriceBX96) = (sqrtPriceBX96, sqrtPriceAX96);

        if (sqrtPriceX96 <= sqrtPriceAX96) {
            liquidity = getLiquidityForAmount0(sqrtPriceAX96, sqrtPriceBX96, amount0);
        } else if (sqrtPriceX96 < sqrtPriceBX96) {
            uint128 liquidity0 = getLiquidityForAmount0(sqrtPriceX96, sqrtPriceBX96, amount0);
            uint128 liquidity1 = getLiquidityForAmount1(sqrtPriceAX96, sqrtPriceX96, amount1);

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

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

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

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

        return FullMath.mulDiv(liquidity, sqrtPriceBX96 - sqrtPriceAX96, 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 sqrtPriceX96 A sqrt price representing the current pool prices
    /// @param sqrtPriceAX96 A sqrt price representing the first tick boundary
    /// @param sqrtPriceBX96 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 sqrtPriceX96,
        uint160 sqrtPriceAX96,
        uint160 sqrtPriceBX96,
        uint128 liquidity
    ) internal pure returns (uint256 amount0, uint256 amount1) {
        if (sqrtPriceAX96 > sqrtPriceBX96) (sqrtPriceAX96, sqrtPriceBX96) = (sqrtPriceBX96, sqrtPriceAX96);

        if (sqrtPriceX96 <= sqrtPriceAX96) {
            amount0 = getAmount0ForLiquidity(sqrtPriceAX96, sqrtPriceBX96, liquidity);
        } else if (sqrtPriceX96 < sqrtPriceBX96) {
            amount0 = getAmount0ForLiquidity(sqrtPriceX96, sqrtPriceBX96, liquidity);
            amount1 = getAmount1ForLiquidity(sqrtPriceAX96, sqrtPriceX96, liquidity);
        } else {
            amount1 = getAmount1ForLiquidity(sqrtPriceAX96, sqrtPriceBX96, liquidity);
        }
    }
}

File 6 of 39 : PoolKey.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {Currency} from "./Currency.sol";
import {IHooks} from "../interfaces/IHooks.sol";
import {PoolIdLibrary} from "./PoolId.sol";

using PoolIdLibrary for PoolKey global;

/// @notice Returns the key for identifying a pool
struct PoolKey {
    /// @notice The lower currency of the pool, sorted numerically
    Currency currency0;
    /// @notice The higher currency of the pool, sorted numerically
    Currency currency1;
    /// @notice The pool LP fee, capped at 1_000_000. If the highest bit is 1, the pool has a dynamic fee and must be exactly equal to 0x800000
    uint24 fee;
    /// @notice Ticks that involve positions must be a multiple of tick spacing
    int24 tickSpacing;
    /// @notice The hooks of the pool
    IHooks hooks;
}

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

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

type PoolId is bytes32;

/// @notice Library for computing the ID of a pool
library PoolIdLibrary {
    /// @notice Returns value equal to keccak256(abi.encode(poolKey))
    function toId(PoolKey memory poolKey) internal pure returns (PoolId poolId) {
        assembly ("memory-safe") {
            // 0xa0 represents the total size of the poolKey struct (5 slots of 32 bytes)
            poolId := keccak256(poolKey, 0xa0)
        }
    }
}

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

import {IERC20Minimal} from "../interfaces/external/IERC20Minimal.sol";
import {CustomRevert} from "../libraries/CustomRevert.sol";

type Currency is address;

using {greaterThan as >, lessThan as <, greaterThanOrEqualTo as >=, equals as ==} for Currency global;
using CurrencyLibrary for Currency global;

function equals(Currency currency, Currency other) pure returns (bool) {
    return Currency.unwrap(currency) == Currency.unwrap(other);
}

function greaterThan(Currency currency, Currency other) pure returns (bool) {
    return Currency.unwrap(currency) > Currency.unwrap(other);
}

function lessThan(Currency currency, Currency other) pure returns (bool) {
    return Currency.unwrap(currency) < Currency.unwrap(other);
}

function greaterThanOrEqualTo(Currency currency, Currency other) pure returns (bool) {
    return Currency.unwrap(currency) >= Currency.unwrap(other);
}

/// @title CurrencyLibrary
/// @dev This library allows for transferring and holding native tokens and ERC20 tokens
library CurrencyLibrary {
    /// @notice Additional context for ERC-7751 wrapped error when a native transfer fails
    error NativeTransferFailed();

    /// @notice Additional context for ERC-7751 wrapped error when an ERC20 transfer fails
    error ERC20TransferFailed();

    /// @notice A constant to represent the native currency
    Currency public constant ADDRESS_ZERO = Currency.wrap(address(0));

    function transfer(Currency currency, address to, uint256 amount) internal {
        // altered from https://github.com/transmissions11/solmate/blob/44a9963d4c78111f77caa0e65d677b8b46d6f2e6/src/utils/SafeTransferLib.sol
        // modified custom error selectors

        bool success;
        if (currency.isAddressZero()) {
            assembly ("memory-safe") {
                // Transfer the ETH and revert if it fails.
                success := call(gas(), to, amount, 0, 0, 0, 0)
            }
            // revert with NativeTransferFailed, containing the bubbled up error as an argument
            if (!success) {
                CustomRevert.bubbleUpAndRevertWith(to, bytes4(0), NativeTransferFailed.selector);
            }
        } else {
            assembly ("memory-safe") {
                // Get a pointer to some free memory.
                let fmp := mload(0x40)

                // Write the abi-encoded calldata into memory, beginning with the function selector.
                mstore(fmp, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
                mstore(add(fmp, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
                mstore(add(fmp, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.

                success :=
                    and(
                        // Set success to whether the call reverted, if not we check it either
                        // returned exactly 1 (can't just be non-zero data), or had no return data.
                        or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
                        // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
                        // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                        // Counterintuitively, this call must be positioned second to the or() call in the
                        // surrounding and() call or else returndatasize() will be zero during the computation.
                        call(gas(), currency, 0, fmp, 68, 0, 32)
                    )

                // Now clean the memory we used
                mstore(fmp, 0) // 4 byte `selector` and 28 bytes of `to` were stored here
                mstore(add(fmp, 0x20), 0) // 4 bytes of `to` and 28 bytes of `amount` were stored here
                mstore(add(fmp, 0x40), 0) // 4 bytes of `amount` were stored here
            }
            // revert with ERC20TransferFailed, containing the bubbled up error as an argument
            if (!success) {
                CustomRevert.bubbleUpAndRevertWith(
                    Currency.unwrap(currency), IERC20Minimal.transfer.selector, ERC20TransferFailed.selector
                );
            }
        }
    }

    function balanceOfSelf(Currency currency) internal view returns (uint256) {
        if (currency.isAddressZero()) {
            return address(this).balance;
        } else {
            return IERC20Minimal(Currency.unwrap(currency)).balanceOf(address(this));
        }
    }

    function balanceOf(Currency currency, address owner) internal view returns (uint256) {
        if (currency.isAddressZero()) {
            return owner.balance;
        } else {
            return IERC20Minimal(Currency.unwrap(currency)).balanceOf(owner);
        }
    }

    function isAddressZero(Currency currency) internal pure returns (bool) {
        return Currency.unwrap(currency) == Currency.unwrap(ADDRESS_ZERO);
    }

    function toId(Currency currency) internal pure returns (uint256) {
        return uint160(Currency.unwrap(currency));
    }

    // If the upper 12 bytes are non-zero, they will be zero-ed out
    // Therefore, fromId() and toId() are not inverses of each other
    function fromId(uint256 id) internal pure returns (Currency) {
        return Currency.wrap(address(uint160(id)));
    }
}

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

import {SafeCast} from "../libraries/SafeCast.sol";

/// @dev Two `int128` values packed into a single `int256` where the upper 128 bits represent the amount0
/// and the lower 128 bits represent the amount1.
type BalanceDelta is int256;

using {add as +, sub as -, eq as ==, neq as !=} for BalanceDelta global;
using BalanceDeltaLibrary for BalanceDelta global;
using SafeCast for int256;

function toBalanceDelta(int128 _amount0, int128 _amount1) pure returns (BalanceDelta balanceDelta) {
    assembly ("memory-safe") {
        balanceDelta := or(shl(128, _amount0), and(sub(shl(128, 1), 1), _amount1))
    }
}

function add(BalanceDelta a, BalanceDelta b) pure returns (BalanceDelta) {
    int256 res0;
    int256 res1;
    assembly ("memory-safe") {
        let a0 := sar(128, a)
        let a1 := signextend(15, a)
        let b0 := sar(128, b)
        let b1 := signextend(15, b)
        res0 := add(a0, b0)
        res1 := add(a1, b1)
    }
    return toBalanceDelta(res0.toInt128(), res1.toInt128());
}

function sub(BalanceDelta a, BalanceDelta b) pure returns (BalanceDelta) {
    int256 res0;
    int256 res1;
    assembly ("memory-safe") {
        let a0 := sar(128, a)
        let a1 := signextend(15, a)
        let b0 := sar(128, b)
        let b1 := signextend(15, b)
        res0 := sub(a0, b0)
        res1 := sub(a1, b1)
    }
    return toBalanceDelta(res0.toInt128(), res1.toInt128());
}

function eq(BalanceDelta a, BalanceDelta b) pure returns (bool) {
    return BalanceDelta.unwrap(a) == BalanceDelta.unwrap(b);
}

function neq(BalanceDelta a, BalanceDelta b) pure returns (bool) {
    return BalanceDelta.unwrap(a) != BalanceDelta.unwrap(b);
}

/// @notice Library for getting the amount0 and amount1 deltas from the BalanceDelta type
library BalanceDeltaLibrary {
    /// @notice A BalanceDelta of 0
    BalanceDelta public constant ZERO_DELTA = BalanceDelta.wrap(0);

    function amount0(BalanceDelta balanceDelta) internal pure returns (int128 _amount0) {
        assembly ("memory-safe") {
            _amount0 := sar(128, balanceDelta)
        }
    }

    function amount1(BalanceDelta balanceDelta) internal pure returns (int128 _amount1) {
        assembly ("memory-safe") {
            _amount1 := signextend(15, balanceDelta)
        }
    }
}

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

// Return type of the beforeSwap hook.
// Upper 128 bits is the delta in specified tokens. Lower 128 bits is delta in unspecified tokens (to match the afterSwap hook)
type BeforeSwapDelta is int256;

// Creates a BeforeSwapDelta from specified and unspecified
function toBeforeSwapDelta(int128 deltaSpecified, int128 deltaUnspecified)
    pure
    returns (BeforeSwapDelta beforeSwapDelta)
{
    assembly ("memory-safe") {
        beforeSwapDelta := or(shl(128, deltaSpecified), and(sub(shl(128, 1), 1), deltaUnspecified))
    }
}

/// @notice Library for getting the specified and unspecified deltas from the BeforeSwapDelta type
library BeforeSwapDeltaLibrary {
    /// @notice A BeforeSwapDelta of 0
    BeforeSwapDelta public constant ZERO_DELTA = BeforeSwapDelta.wrap(0);

    /// extracts int128 from the upper 128 bits of the BeforeSwapDelta
    /// returned by beforeSwap
    function getSpecifiedDelta(BeforeSwapDelta delta) internal pure returns (int128 deltaSpecified) {
        assembly ("memory-safe") {
            deltaSpecified := sar(128, delta)
        }
    }

    /// extracts int128 from the lower 128 bits of the BeforeSwapDelta
    /// returned by beforeSwap and afterSwap
    function getUnspecifiedDelta(BeforeSwapDelta delta) internal pure returns (int128 deltaUnspecified) {
        assembly ("memory-safe") {
            deltaUnspecified := signextend(15, delta)
        }
    }
}

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

import {PoolKey} from "../types/PoolKey.sol";
import {IHooks} from "../interfaces/IHooks.sol";
import {SafeCast} from "./SafeCast.sol";
import {LPFeeLibrary} from "./LPFeeLibrary.sol";
import {BalanceDelta, toBalanceDelta, BalanceDeltaLibrary} from "../types/BalanceDelta.sol";
import {BeforeSwapDelta, BeforeSwapDeltaLibrary} from "../types/BeforeSwapDelta.sol";
import {IPoolManager} from "../interfaces/IPoolManager.sol";
import {ModifyLiquidityParams, SwapParams} from "../types/PoolOperation.sol";
import {ParseBytes} from "./ParseBytes.sol";
import {CustomRevert} from "./CustomRevert.sol";

/// @notice V4 decides whether to invoke specific hooks by inspecting the least significant bits
/// of the address that the hooks contract is deployed to.
/// For example, a hooks contract deployed to address: 0x0000000000000000000000000000000000002400
/// has the lowest bits '10 0100 0000 0000' which would cause the 'before initialize' and 'after add liquidity' hooks to be used.
library Hooks {
    using LPFeeLibrary for uint24;
    using Hooks for IHooks;
    using SafeCast for int256;
    using BeforeSwapDeltaLibrary for BeforeSwapDelta;
    using ParseBytes for bytes;
    using CustomRevert for bytes4;

    uint160 internal constant ALL_HOOK_MASK = uint160((1 << 14) - 1);

    uint160 internal constant BEFORE_INITIALIZE_FLAG = 1 << 13;
    uint160 internal constant AFTER_INITIALIZE_FLAG = 1 << 12;

    uint160 internal constant BEFORE_ADD_LIQUIDITY_FLAG = 1 << 11;
    uint160 internal constant AFTER_ADD_LIQUIDITY_FLAG = 1 << 10;

    uint160 internal constant BEFORE_REMOVE_LIQUIDITY_FLAG = 1 << 9;
    uint160 internal constant AFTER_REMOVE_LIQUIDITY_FLAG = 1 << 8;

    uint160 internal constant BEFORE_SWAP_FLAG = 1 << 7;
    uint160 internal constant AFTER_SWAP_FLAG = 1 << 6;

    uint160 internal constant BEFORE_DONATE_FLAG = 1 << 5;
    uint160 internal constant AFTER_DONATE_FLAG = 1 << 4;

    uint160 internal constant BEFORE_SWAP_RETURNS_DELTA_FLAG = 1 << 3;
    uint160 internal constant AFTER_SWAP_RETURNS_DELTA_FLAG = 1 << 2;
    uint160 internal constant AFTER_ADD_LIQUIDITY_RETURNS_DELTA_FLAG = 1 << 1;
    uint160 internal constant AFTER_REMOVE_LIQUIDITY_RETURNS_DELTA_FLAG = 1 << 0;

    struct Permissions {
        bool beforeInitialize;
        bool afterInitialize;
        bool beforeAddLiquidity;
        bool afterAddLiquidity;
        bool beforeRemoveLiquidity;
        bool afterRemoveLiquidity;
        bool beforeSwap;
        bool afterSwap;
        bool beforeDonate;
        bool afterDonate;
        bool beforeSwapReturnDelta;
        bool afterSwapReturnDelta;
        bool afterAddLiquidityReturnDelta;
        bool afterRemoveLiquidityReturnDelta;
    }

    /// @notice Thrown if the address will not lead to the specified hook calls being called
    /// @param hooks The address of the hooks contract
    error HookAddressNotValid(address hooks);

    /// @notice Hook did not return its selector
    error InvalidHookResponse();

    /// @notice Additional context for ERC-7751 wrapped error when a hook call fails
    error HookCallFailed();

    /// @notice The hook's delta changed the swap from exactIn to exactOut or vice versa
    error HookDeltaExceedsSwapAmount();

    /// @notice Utility function intended to be used in hook constructors to ensure
    /// the deployed hooks address causes the intended hooks to be called
    /// @param permissions The hooks that are intended to be called
    /// @dev permissions param is memory as the function will be called from constructors
    function validateHookPermissions(IHooks self, Permissions memory permissions) internal pure {
        if (
            permissions.beforeInitialize != self.hasPermission(BEFORE_INITIALIZE_FLAG)
                || permissions.afterInitialize != self.hasPermission(AFTER_INITIALIZE_FLAG)
                || permissions.beforeAddLiquidity != self.hasPermission(BEFORE_ADD_LIQUIDITY_FLAG)
                || permissions.afterAddLiquidity != self.hasPermission(AFTER_ADD_LIQUIDITY_FLAG)
                || permissions.beforeRemoveLiquidity != self.hasPermission(BEFORE_REMOVE_LIQUIDITY_FLAG)
                || permissions.afterRemoveLiquidity != self.hasPermission(AFTER_REMOVE_LIQUIDITY_FLAG)
                || permissions.beforeSwap != self.hasPermission(BEFORE_SWAP_FLAG)
                || permissions.afterSwap != self.hasPermission(AFTER_SWAP_FLAG)
                || permissions.beforeDonate != self.hasPermission(BEFORE_DONATE_FLAG)
                || permissions.afterDonate != self.hasPermission(AFTER_DONATE_FLAG)
                || permissions.beforeSwapReturnDelta != self.hasPermission(BEFORE_SWAP_RETURNS_DELTA_FLAG)
                || permissions.afterSwapReturnDelta != self.hasPermission(AFTER_SWAP_RETURNS_DELTA_FLAG)
                || permissions.afterAddLiquidityReturnDelta != self.hasPermission(AFTER_ADD_LIQUIDITY_RETURNS_DELTA_FLAG)
                || permissions.afterRemoveLiquidityReturnDelta
                    != self.hasPermission(AFTER_REMOVE_LIQUIDITY_RETURNS_DELTA_FLAG)
        ) {
            HookAddressNotValid.selector.revertWith(address(self));
        }
    }

    /// @notice Ensures that the hook address includes at least one hook flag or dynamic fees, or is the 0 address
    /// @param self The hook to verify
    /// @param fee The fee of the pool the hook is used with
    /// @return bool True if the hook address is valid
    function isValidHookAddress(IHooks self, uint24 fee) internal pure returns (bool) {
        // The hook can only have a flag to return a hook delta on an action if it also has the corresponding action flag
        if (!self.hasPermission(BEFORE_SWAP_FLAG) && self.hasPermission(BEFORE_SWAP_RETURNS_DELTA_FLAG)) return false;
        if (!self.hasPermission(AFTER_SWAP_FLAG) && self.hasPermission(AFTER_SWAP_RETURNS_DELTA_FLAG)) return false;
        if (!self.hasPermission(AFTER_ADD_LIQUIDITY_FLAG) && self.hasPermission(AFTER_ADD_LIQUIDITY_RETURNS_DELTA_FLAG))
        {
            return false;
        }
        if (
            !self.hasPermission(AFTER_REMOVE_LIQUIDITY_FLAG)
                && self.hasPermission(AFTER_REMOVE_LIQUIDITY_RETURNS_DELTA_FLAG)
        ) return false;

        // If there is no hook contract set, then fee cannot be dynamic
        // If a hook contract is set, it must have at least 1 flag set, or have a dynamic fee
        return address(self) == address(0)
            ? !fee.isDynamicFee()
            : (uint160(address(self)) & ALL_HOOK_MASK > 0 || fee.isDynamicFee());
    }

    /// @notice performs a hook call using the given calldata on the given hook that doesn't return a delta
    /// @return result The complete data returned by the hook
    function callHook(IHooks self, bytes memory data) internal returns (bytes memory result) {
        bool success;
        assembly ("memory-safe") {
            success := call(gas(), self, 0, add(data, 0x20), mload(data), 0, 0)
        }
        // Revert with FailedHookCall, containing any error message to bubble up
        if (!success) CustomRevert.bubbleUpAndRevertWith(address(self), bytes4(data), HookCallFailed.selector);

        // The call was successful, fetch the returned data
        assembly ("memory-safe") {
            // allocate result byte array from the free memory pointer
            result := mload(0x40)
            // store new free memory pointer at the end of the array padded to 32 bytes
            mstore(0x40, add(result, and(add(returndatasize(), 0x3f), not(0x1f))))
            // store length in memory
            mstore(result, returndatasize())
            // copy return data to result
            returndatacopy(add(result, 0x20), 0, returndatasize())
        }

        // Length must be at least 32 to contain the selector. Check expected selector and returned selector match.
        if (result.length < 32 || result.parseSelector() != data.parseSelector()) {
            InvalidHookResponse.selector.revertWith();
        }
    }

    /// @notice performs a hook call using the given calldata on the given hook
    /// @return int256 The delta returned by the hook
    function callHookWithReturnDelta(IHooks self, bytes memory data, bool parseReturn) internal returns (int256) {
        bytes memory result = callHook(self, data);

        // If this hook wasn't meant to return something, default to 0 delta
        if (!parseReturn) return 0;

        // A length of 64 bytes is required to return a bytes4, and a 32 byte delta
        if (result.length != 64) InvalidHookResponse.selector.revertWith();
        return result.parseReturnDelta();
    }

    /// @notice modifier to prevent calling a hook if they initiated the action
    modifier noSelfCall(IHooks self) {
        if (msg.sender != address(self)) {
            _;
        }
    }

    /// @notice calls beforeInitialize hook if permissioned and validates return value
    function beforeInitialize(IHooks self, PoolKey memory key, uint160 sqrtPriceX96) internal noSelfCall(self) {
        if (self.hasPermission(BEFORE_INITIALIZE_FLAG)) {
            self.callHook(abi.encodeCall(IHooks.beforeInitialize, (msg.sender, key, sqrtPriceX96)));
        }
    }

    /// @notice calls afterInitialize hook if permissioned and validates return value
    function afterInitialize(IHooks self, PoolKey memory key, uint160 sqrtPriceX96, int24 tick)
        internal
        noSelfCall(self)
    {
        if (self.hasPermission(AFTER_INITIALIZE_FLAG)) {
            self.callHook(abi.encodeCall(IHooks.afterInitialize, (msg.sender, key, sqrtPriceX96, tick)));
        }
    }

    /// @notice calls beforeModifyLiquidity hook if permissioned and validates return value
    function beforeModifyLiquidity(
        IHooks self,
        PoolKey memory key,
        ModifyLiquidityParams memory params,
        bytes calldata hookData
    ) internal noSelfCall(self) {
        if (params.liquidityDelta > 0 && self.hasPermission(BEFORE_ADD_LIQUIDITY_FLAG)) {
            self.callHook(abi.encodeCall(IHooks.beforeAddLiquidity, (msg.sender, key, params, hookData)));
        } else if (params.liquidityDelta <= 0 && self.hasPermission(BEFORE_REMOVE_LIQUIDITY_FLAG)) {
            self.callHook(abi.encodeCall(IHooks.beforeRemoveLiquidity, (msg.sender, key, params, hookData)));
        }
    }

    /// @notice calls afterModifyLiquidity hook if permissioned and validates return value
    function afterModifyLiquidity(
        IHooks self,
        PoolKey memory key,
        ModifyLiquidityParams memory params,
        BalanceDelta delta,
        BalanceDelta feesAccrued,
        bytes calldata hookData
    ) internal returns (BalanceDelta callerDelta, BalanceDelta hookDelta) {
        if (msg.sender == address(self)) return (delta, BalanceDeltaLibrary.ZERO_DELTA);

        callerDelta = delta;
        if (params.liquidityDelta > 0) {
            if (self.hasPermission(AFTER_ADD_LIQUIDITY_FLAG)) {
                hookDelta = BalanceDelta.wrap(
                    self.callHookWithReturnDelta(
                        abi.encodeCall(
                            IHooks.afterAddLiquidity, (msg.sender, key, params, delta, feesAccrued, hookData)
                        ),
                        self.hasPermission(AFTER_ADD_LIQUIDITY_RETURNS_DELTA_FLAG)
                    )
                );
                callerDelta = callerDelta - hookDelta;
            }
        } else {
            if (self.hasPermission(AFTER_REMOVE_LIQUIDITY_FLAG)) {
                hookDelta = BalanceDelta.wrap(
                    self.callHookWithReturnDelta(
                        abi.encodeCall(
                            IHooks.afterRemoveLiquidity, (msg.sender, key, params, delta, feesAccrued, hookData)
                        ),
                        self.hasPermission(AFTER_REMOVE_LIQUIDITY_RETURNS_DELTA_FLAG)
                    )
                );
                callerDelta = callerDelta - hookDelta;
            }
        }
    }

    /// @notice calls beforeSwap hook if permissioned and validates return value
    function beforeSwap(IHooks self, PoolKey memory key, SwapParams memory params, bytes calldata hookData)
        internal
        returns (int256 amountToSwap, BeforeSwapDelta hookReturn, uint24 lpFeeOverride)
    {
        amountToSwap = params.amountSpecified;
        if (msg.sender == address(self)) return (amountToSwap, BeforeSwapDeltaLibrary.ZERO_DELTA, lpFeeOverride);

        if (self.hasPermission(BEFORE_SWAP_FLAG)) {
            bytes memory result = callHook(self, abi.encodeCall(IHooks.beforeSwap, (msg.sender, key, params, hookData)));

            // A length of 96 bytes is required to return a bytes4, a 32 byte delta, and an LP fee
            if (result.length != 96) InvalidHookResponse.selector.revertWith();

            // dynamic fee pools that want to override the cache fee, return a valid fee with the override flag. If override flag
            // is set but an invalid fee is returned, the transaction will revert. Otherwise the current LP fee will be used
            if (key.fee.isDynamicFee()) lpFeeOverride = result.parseFee();

            // skip this logic for the case where the hook return is 0
            if (self.hasPermission(BEFORE_SWAP_RETURNS_DELTA_FLAG)) {
                hookReturn = BeforeSwapDelta.wrap(result.parseReturnDelta());

                // any return in unspecified is passed to the afterSwap hook for handling
                int128 hookDeltaSpecified = hookReturn.getSpecifiedDelta();

                // Update the swap amount according to the hook's return, and check that the swap type doesn't change (exact input/output)
                if (hookDeltaSpecified != 0) {
                    bool exactInput = amountToSwap < 0;
                    amountToSwap += hookDeltaSpecified;
                    if (exactInput ? amountToSwap > 0 : amountToSwap < 0) {
                        HookDeltaExceedsSwapAmount.selector.revertWith();
                    }
                }
            }
        }
    }

    /// @notice calls afterSwap hook if permissioned and validates return value
    function afterSwap(
        IHooks self,
        PoolKey memory key,
        SwapParams memory params,
        BalanceDelta swapDelta,
        bytes calldata hookData,
        BeforeSwapDelta beforeSwapHookReturn
    ) internal returns (BalanceDelta, BalanceDelta) {
        if (msg.sender == address(self)) return (swapDelta, BalanceDeltaLibrary.ZERO_DELTA);

        int128 hookDeltaSpecified = beforeSwapHookReturn.getSpecifiedDelta();
        int128 hookDeltaUnspecified = beforeSwapHookReturn.getUnspecifiedDelta();

        if (self.hasPermission(AFTER_SWAP_FLAG)) {
            hookDeltaUnspecified += self.callHookWithReturnDelta(
                abi.encodeCall(IHooks.afterSwap, (msg.sender, key, params, swapDelta, hookData)),
                self.hasPermission(AFTER_SWAP_RETURNS_DELTA_FLAG)
            ).toInt128();
        }

        BalanceDelta hookDelta;
        if (hookDeltaUnspecified != 0 || hookDeltaSpecified != 0) {
            hookDelta = (params.amountSpecified < 0 == params.zeroForOne)
                ? toBalanceDelta(hookDeltaSpecified, hookDeltaUnspecified)
                : toBalanceDelta(hookDeltaUnspecified, hookDeltaSpecified);

            // the caller has to pay for (or receive) the hook's delta
            swapDelta = swapDelta - hookDelta;
        }
        return (swapDelta, hookDelta);
    }

    /// @notice calls beforeDonate hook if permissioned and validates return value
    function beforeDonate(IHooks self, PoolKey memory key, uint256 amount0, uint256 amount1, bytes calldata hookData)
        internal
        noSelfCall(self)
    {
        if (self.hasPermission(BEFORE_DONATE_FLAG)) {
            self.callHook(abi.encodeCall(IHooks.beforeDonate, (msg.sender, key, amount0, amount1, hookData)));
        }
    }

    /// @notice calls afterDonate hook if permissioned and validates return value
    function afterDonate(IHooks self, PoolKey memory key, uint256 amount0, uint256 amount1, bytes calldata hookData)
        internal
        noSelfCall(self)
    {
        if (self.hasPermission(AFTER_DONATE_FLAG)) {
            self.callHook(abi.encodeCall(IHooks.afterDonate, (msg.sender, key, amount0, amount1, hookData)));
        }
    }

    function hasPermission(IHooks self, uint160 flag) internal pure returns (bool) {
        return uint160(address(self)) & flag != 0;
    }
}

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

import {BitMath} from "./BitMath.sol";
import {CustomRevert} from "./CustomRevert.sol";

/// @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 {
    using CustomRevert for bytes4;

    /// @notice Thrown when the tick passed to #getSqrtPriceAtTick is not between MIN_TICK and MAX_TICK
    error InvalidTick(int24 tick);
    /// @notice Thrown when the price passed to #getTickAtSqrtPrice does not correspond to a price between MIN_TICK and MAX_TICK
    error InvalidSqrtPrice(uint160 sqrtPriceX96);

    /// @dev The minimum tick that may be passed to #getSqrtPriceAtTick computed from log base 1.0001 of 2**-128
    /// @dev If ever MIN_TICK and MAX_TICK are not centered around 0, the absTick logic in getSqrtPriceAtTick cannot be used
    int24 internal constant MIN_TICK = -887272;
    /// @dev The maximum tick that may be passed to #getSqrtPriceAtTick computed from log base 1.0001 of 2**128
    /// @dev If ever MIN_TICK and MAX_TICK are not centered around 0, the absTick logic in getSqrtPriceAtTick cannot be used
    int24 internal constant MAX_TICK = 887272;

    /// @dev The minimum tick spacing value drawn from the range of type int16 that is greater than 0, i.e. min from the range [1, 32767]
    int24 internal constant MIN_TICK_SPACING = 1;
    /// @dev The maximum tick spacing value drawn from the range of type int16, i.e. max from the range [1, 32767]
    int24 internal constant MAX_TICK_SPACING = type(int16).max;

    /// @dev The minimum value that can be returned from #getSqrtPriceAtTick. Equivalent to getSqrtPriceAtTick(MIN_TICK)
    uint160 internal constant MIN_SQRT_PRICE = 4295128739;
    /// @dev The maximum value that can be returned from #getSqrtPriceAtTick. Equivalent to getSqrtPriceAtTick(MAX_TICK)
    uint160 internal constant MAX_SQRT_PRICE = 1461446703485210103287273052203988822378723970342;
    /// @dev A threshold used for optimized bounds check, equals `MAX_SQRT_PRICE - MIN_SQRT_PRICE - 1`
    uint160 internal constant MAX_SQRT_PRICE_MINUS_MIN_SQRT_PRICE_MINUS_ONE =
        1461446703485210103287273052203988822378723970342 - 4295128739 - 1;

    /// @notice Given a tickSpacing, compute the maximum usable tick
    function maxUsableTick(int24 tickSpacing) internal pure returns (int24) {
        unchecked {
            return (MAX_TICK / tickSpacing) * tickSpacing;
        }
    }

    /// @notice Given a tickSpacing, compute the minimum usable tick
    function minUsableTick(int24 tickSpacing) internal pure returns (int24) {
        unchecked {
            return (MIN_TICK / tickSpacing) * tickSpacing;
        }
    }

    /// @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 price of the two assets (currency1/currency0)
    /// at the given tick
    function getSqrtPriceAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) {
        unchecked {
            uint256 absTick;
            assembly ("memory-safe") {
                tick := signextend(2, tick)
                // mask = 0 if tick >= 0 else -1 (all 1s)
                let mask := sar(255, tick)
                // if tick >= 0, |tick| = tick = 0 ^ tick
                // if tick < 0, |tick| = ~~|tick| = ~(-|tick| - 1) = ~(tick - 1) = (-1) ^ (tick - 1)
                // either way, |tick| = mask ^ (tick + mask)
                absTick := xor(mask, add(mask, tick))
            }

            if (absTick > uint256(int256(MAX_TICK))) InvalidTick.selector.revertWith(tick);

            // The tick is decomposed into bits, and for each bit with index i that is set, the product of 1/sqrt(1.0001^(2^i))
            // is calculated (using Q128.128). The constants used for this calculation are rounded to the nearest integer

            // Equivalent to:
            //     price = absTick & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : 0x100000000000000000000000000000000;
            //     or price = int(2**128 / sqrt(1.0001)) if (absTick & 0x1) else 1 << 128
            uint256 price;
            assembly ("memory-safe") {
                price := xor(shl(128, 1), mul(xor(shl(128, 1), 0xfffcb933bd6fad37aa2d162d1a594001), and(absTick, 0x1)))
            }
            if (absTick & 0x2 != 0) price = (price * 0xfff97272373d413259a46990580e213a) >> 128;
            if (absTick & 0x4 != 0) price = (price * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128;
            if (absTick & 0x8 != 0) price = (price * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128;
            if (absTick & 0x10 != 0) price = (price * 0xffcb9843d60f6159c9db58835c926644) >> 128;
            if (absTick & 0x20 != 0) price = (price * 0xff973b41fa98c081472e6896dfb254c0) >> 128;
            if (absTick & 0x40 != 0) price = (price * 0xff2ea16466c96a3843ec78b326b52861) >> 128;
            if (absTick & 0x80 != 0) price = (price * 0xfe5dee046a99a2a811c461f1969c3053) >> 128;
            if (absTick & 0x100 != 0) price = (price * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128;
            if (absTick & 0x200 != 0) price = (price * 0xf987a7253ac413176f2b074cf7815e54) >> 128;
            if (absTick & 0x400 != 0) price = (price * 0xf3392b0822b70005940c7a398e4b70f3) >> 128;
            if (absTick & 0x800 != 0) price = (price * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128;
            if (absTick & 0x1000 != 0) price = (price * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128;
            if (absTick & 0x2000 != 0) price = (price * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128;
            if (absTick & 0x4000 != 0) price = (price * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128;
            if (absTick & 0x8000 != 0) price = (price * 0x31be135f97d08fd981231505542fcfa6) >> 128;
            if (absTick & 0x10000 != 0) price = (price * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128;
            if (absTick & 0x20000 != 0) price = (price * 0x5d6af8dedb81196699c329225ee604) >> 128;
            if (absTick & 0x40000 != 0) price = (price * 0x2216e584f5fa1ea926041bedfe98) >> 128;
            if (absTick & 0x80000 != 0) price = (price * 0x48a170391f7dc42444e8fa2) >> 128;

            assembly ("memory-safe") {
                // if (tick > 0) price = type(uint256).max / price;
                if sgt(tick, 0) { price := div(not(0), price) }

                // 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 getTickAtSqrtPrice of the output price is always consistent
                // `sub(shl(32, 1), 1)` is `type(uint32).max`
                // `price + type(uint32).max` will not overflow because `price` fits in 192 bits
                sqrtPriceX96 := shr(32, add(price, sub(shl(32, 1), 1)))
            }
        }
    }

    /// @notice Calculates the greatest tick value such that getSqrtPriceAtTick(tick) <= sqrtPriceX96
    /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_PRICE, as MIN_SQRT_PRICE is the lowest value getSqrtPriceAtTick may
    /// ever return.
    /// @param sqrtPriceX96 The sqrt price for which to compute the tick as a Q64.96
    /// @return tick The greatest tick for which the getSqrtPriceAtTick(tick) is less than or equal to the input sqrtPriceX96
    function getTickAtSqrtPrice(uint160 sqrtPriceX96) internal pure returns (int24 tick) {
        unchecked {
            // Equivalent: if (sqrtPriceX96 < MIN_SQRT_PRICE || sqrtPriceX96 >= MAX_SQRT_PRICE) revert InvalidSqrtPrice();
            // second inequality must be >= because the price can never reach the price at the max tick
            // if sqrtPriceX96 < MIN_SQRT_PRICE, the `sub` underflows and `gt` is true
            // if sqrtPriceX96 >= MAX_SQRT_PRICE, sqrtPriceX96 - MIN_SQRT_PRICE > MAX_SQRT_PRICE - MIN_SQRT_PRICE - 1
            if ((sqrtPriceX96 - MIN_SQRT_PRICE) > MAX_SQRT_PRICE_MINUS_MIN_SQRT_PRICE_MINUS_ONE) {
                InvalidSqrtPrice.selector.revertWith(sqrtPriceX96);
            }

            uint256 price = uint256(sqrtPriceX96) << 32;

            uint256 r = price;
            uint256 msb = BitMath.mostSignificantBit(r);

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

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

            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(63, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(62, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(61, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(60, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(59, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(58, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(57, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(56, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(55, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(54, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(53, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(52, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(51, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                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; // Q22.128 number

            // Magic number represents the ceiling of the maximum value of the error when approximating log_sqrt10001(x)
            int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128);

            // Magic number represents the minimum value of the error when approximating log_sqrt10001(x), when
            // sqrtPrice is from the range (2^-64, 2^64). This is safe as MIN_SQRT_PRICE is more than 2^-64. If MIN_SQRT_PRICE
            // is changed, this may need to be changed too
            int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128);

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

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

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

/// @title Safe casting methods
/// @notice Contains methods for safely casting between types
library SafeCast {
    using CustomRevert for bytes4;

    error SafeCastOverflow();

    /// @notice Cast a uint256 to a uint160, revert on overflow
    /// @param x The uint256 to be downcasted
    /// @return y The downcasted integer, now type uint160
    function toUint160(uint256 x) internal pure returns (uint160 y) {
        y = uint160(x);
        if (y != x) SafeCastOverflow.selector.revertWith();
    }

    /// @notice Cast a uint256 to a uint128, revert on overflow
    /// @param x The uint256 to be downcasted
    /// @return y The downcasted integer, now type uint128
    function toUint128(uint256 x) internal pure returns (uint128 y) {
        y = uint128(x);
        if (x != y) SafeCastOverflow.selector.revertWith();
    }

    /// @notice Cast a int128 to a uint128, revert on overflow or underflow
    /// @param x The int128 to be casted
    /// @return y The casted integer, now type uint128
    function toUint128(int128 x) internal pure returns (uint128 y) {
        if (x < 0) SafeCastOverflow.selector.revertWith();
        y = uint128(x);
    }

    /// @notice Cast a int256 to a int128, revert on overflow or underflow
    /// @param x The int256 to be downcasted
    /// @return y The downcasted integer, now type int128
    function toInt128(int256 x) internal pure returns (int128 y) {
        y = int128(x);
        if (y != x) SafeCastOverflow.selector.revertWith();
    }

    /// @notice Cast a uint256 to a int256, revert on overflow
    /// @param x The uint256 to be casted
    /// @return y The casted integer, now type int256
    function toInt256(uint256 x) internal pure returns (int256 y) {
        y = int256(x);
        if (y < 0) SafeCastOverflow.selector.revertWith();
    }

    /// @notice Cast a uint256 to a int128, revert on overflow
    /// @param x The uint256 to be downcasted
    /// @return The downcasted integer, now type int128
    function toInt128(uint256 x) internal pure returns (int128) {
        if (x >= 1 << 127) SafeCastOverflow.selector.revertWith();
        return int128(int256(x));
    }
}

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

import {PoolId} from "@uniswap/v4-core/src/types/PoolId.sol";

/**
    * @notice Struct containing oracle price and range information.
    * @param jitLowerTick Observed tick (price) for lower side.
    * @param jitUpperTick Observed tick (price) for upper side.
    * @param jitLowerRange Range around jitLowerTick in ticks.
    * @param jitUpperRange Range around jitUpperTick in ticks.
    * @param uAssetLiquidity Observed uAsset liquidity at the time of the report.
    * @param usdcLiquidity Observed USDC liquidity at the time of the report.
    * @param timestamp Timestamp at which the report was produced.
    */
struct OracleReport {
    int24 jitLowerTick;
    int24 jitUpperTick;
    uint24 jitLowerRange;
    uint24 jitUpperRange;
    uint256 uAssetLiquidity;
    uint256 usdcLiquidity;
    uint48 timestamp;
}

/**
 * @title IMinimalJITOracle
 * @notice Minimal interface for JIT Oracles to be used with Uniswap v4 hooks.
 * @dev Contracts implementing this interface provide oracle functionalities and are called by the hook.
 */
interface IMinimalJITOracle {
    /**
     * @notice Returns a validated price report for a given pool. Reverts if the price is deemed unsafe by oracle logic.
     * @dev This function must implement all security and sanity checks.
     * @param poolId The PoolId identifier of the Uniswap v4 pool.
     * @return report The current OracleReport for the specified pool.
     */
    function safeGetPrice(PoolId poolId) external view returns (OracleReport memory report);
}

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

/**
 * @title IMinimalMerchantController
 * @notice Minimal interface for MerchantController to be used with the UnisversalJITHook.
 * @dev Provides minting and burning functionalities callable by the approved hook and exposes a method for asset whitelisting checks.
 */
interface IMinimalMerchantController {
    /**
     * @notice Mints wrapped tokens from the hook.
     * @dev Can only be called by the configured hook address.
     * @param asset The address of the wrapped asset to mint.
     * @param to The recipient address of the minted tokens.
     * @param amount The amount of tokens to mint.
     */
    function mintFromHook(address asset, address to, uint256 amount) external;

    /**
     * @notice Burns wrapped tokens from the hook.
     * @dev Can only be called by the configured hook address.
     * @param asset The address of the wrapped asset to burn.
     * @param from The address from which tokens will be burned.
     * @param amount The amount of tokens to burn.
     */
    function burnFromHook(address asset, address from, uint256 amount) external;

    /**
     * @notice Checks if an asset is whitelisted as a uAsset.
     * @param asset The address of the asset to check.
     * @return bool True if the asset is whitelisted, false otherwise.
     */
    function isAssetWhitelisted(address asset) external view returns (bool);
}

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

/**
 * @title IMinimalWrappedAssetV2
 * @notice Minimal interface for WrappedAssetV2 to be used with the UnisversalJITHook.
 * @dev Provides a method for checking if a user is blacklisted.
 */
interface IMinimalWrappedAssetV2 {
    /**
     * @notice Checks if a user is blacklisted.
     * @param user The address of the user to check.
     * @return bool True if the user is blacklisted, false otherwise.
     */
    function getUserBlacklist(address user) external view returns (bool);
}

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

import {SqrtPriceMath} from "@uniswap/v4-core/src/libraries/SqrtPriceMath.sol";

struct VirtualPrice {
    // The timestamp of the last update
    uint48 timestamp;
    uint160 virtualSqrtPriceX96;
}

error InsufficientVirtualLiquidity();
error InvalidVirtualRange();
error InvalidSqrtPriceLimit();
error InsufficientLiquidityForExactOutput();

library VirtualPriceLibrary {
    function update(VirtualPrice storage virtualPrice, uint160 virtualSqrtPriceX96, uint48 timestamp) internal {
        virtualPrice.timestamp = timestamp;
        virtualPrice.virtualSqrtPriceX96 = virtualSqrtPriceX96;
    }

    function updatePrice(VirtualPrice storage virtualPrice, uint160 virtualSqrtPriceX96) internal {
        virtualPrice.virtualSqrtPriceX96 = virtualSqrtPriceX96;
    }

    function quoteExactInputZeroForOneWithLimit(
        uint128 liquidity,
        uint160 sqrtCurrent,
        uint160 sqrtPriceLower,
        uint160 sqrtPriceLimit,
        uint256 amount0In
    ) internal pure returns (uint256 amount1Out, uint256 amount0InAfter, uint160 sqrtPriceAfter) {
        if (sqrtPriceLimit >= sqrtCurrent && sqrtPriceLimit != 0) revert InvalidSqrtPriceLimit();

        if (sqrtPriceLimit > sqrtPriceLower && sqrtPriceLimit != 0) {
            // If the limit is above the lowest price and below the virtual price, we apply the limit
            (amount1Out, amount0InAfter, sqrtPriceAfter) =
                quoteExactInputZeroForOne(liquidity, sqrtCurrent, sqrtPriceLimit, amount0In);
        } else {
            // If it's equal or below the lowest price or disabled by setting the limit to 0, we don't apply the limit
            (amount1Out, amount0InAfter, sqrtPriceAfter) =
                quoteExactInputZeroForOne(liquidity, sqrtCurrent, sqrtPriceLower, amount0In);
        }
    }

    function quoteExactInputZeroForOne(
        uint128 liquidity,
        uint160 sqrtCurrent,
        uint160 sqrtPriceLower,
        uint256 amount0In
    ) internal pure returns (uint256 amount1Out, uint256 amount0InAfter, uint160 sqrtPriceAfter) {
        if (liquidity == 0 || amount0In == 0) return (0, 0, sqrtCurrent);
        if (sqrtPriceLower >= sqrtCurrent) revert InvalidVirtualRange();

        // Use roundUp=false so that getNextSqrtPriceFromInput won't cross the limit
        uint256 maxAmount0 = SqrtPriceMath.getAmount0Delta(sqrtPriceLower, sqrtCurrent, liquidity, false);
        
        // Cap input at maxAmount0 if limit would be exceeded
        amount0InAfter = amount0In > maxAmount0 ? maxAmount0 : amount0In;
        
        // Always calculate price consistently using getNextSqrtPriceFromInput
        // This ensures output is identical whether limit is hit or not for same input
        sqrtPriceAfter = SqrtPriceMath.getNextSqrtPriceFromInput(sqrtCurrent, liquidity, amount0InAfter, true);
        amount1Out = SqrtPriceMath.getAmount1Delta(sqrtPriceAfter, sqrtCurrent, liquidity, false);

        // TODO: Invariant, remove after testing
        require(sqrtPriceAfter >= sqrtPriceLower, "INVARIANT: sqrtPriceAfter >= sqrtPriceLower");
    }

    function quoteExactOutputZeroForOneWithLimit(
        uint128 liquidity,
        uint160 sqrtCurrent,
        uint160 sqrtPriceLower,
        uint160 sqrtPriceLimit,
        uint256 amount1Out
    ) internal pure returns (uint256 amount0In, uint256 amount1OutAfter, uint160 sqrtPriceAfter) {
        if (sqrtPriceLimit >= sqrtCurrent && sqrtPriceLimit != 0) revert InvalidSqrtPriceLimit();

        if (sqrtPriceLimit > sqrtPriceLower && sqrtPriceLimit != 0) {
            // If the limit is above the lowest price and below the virtual price, we apply the limit
            (amount0In, amount1OutAfter, sqrtPriceAfter) =
                quoteExactOutputZeroForOne(liquidity, sqrtCurrent, sqrtPriceLimit, amount1Out);
        } else {
            // If it's equal or below the lowest price or disabled by setting the limit to 0, we don't apply the limit
            (amount0In, amount1OutAfter, sqrtPriceAfter) =
                quoteExactOutputZeroForOne(liquidity, sqrtCurrent, sqrtPriceLower, amount1Out);
        }
    }

    function quoteExactOutputZeroForOne(
        uint128 liquidity,
        uint160 sqrtCurrent,
        uint160 sqrtPriceLower,
        uint256 amount1Out
    ) internal pure returns (uint256 amount0In, uint256 amount1OutAfter, uint160 sqrtPriceAfter) {
        if (liquidity == 0 || amount1Out == 0) return (0, 0, sqrtCurrent);
        if (sqrtPriceLower >= sqrtCurrent) revert InvalidVirtualRange();

        // For exact output, check if there's enough liquidity - if not, revert
        uint256 maxAmount1 = SqrtPriceMath.getAmount1Delta(sqrtPriceLower, sqrtCurrent, liquidity, false);
        if (amount1Out > maxAmount1) revert InsufficientLiquidityForExactOutput();
        
        // Output is exactly what was requested
        amount1OutAfter = amount1Out;
        
        // Calculate price and input
        sqrtPriceAfter = SqrtPriceMath.getNextSqrtPriceFromOutput(sqrtCurrent, liquidity, amount1OutAfter, true);
        amount0In = SqrtPriceMath.getAmount0Delta(sqrtPriceAfter, sqrtCurrent, liquidity, true);

        // TODO: Invariant, remove after testing
        require(sqrtPriceAfter >= sqrtPriceLower, "INVARIANT: sqrtPriceAfter >= sqrtPriceLower");
    }

     function quoteExactInputOneForZeroWithLimit(
        uint128 liquidity,
        uint160 sqrtCurrent,
        uint160 sqrtPriceUpper,
        uint160 sqrtPriceLimit,
        uint256 amount1In
    ) internal pure returns (uint256 amount0Out, uint256 amount1InAfter, uint160 sqrtPriceAfter) {
        if (sqrtPriceLimit <= sqrtCurrent && sqrtPriceLimit != 0) revert InvalidSqrtPriceLimit();

        if (sqrtPriceLimit < sqrtPriceUpper && sqrtPriceLimit != 0) {
            // If the limit is below the highest price and above the virtual price, we apply the limit
            (amount0Out, amount1InAfter, sqrtPriceAfter) =
                quoteExactInputOneForZero(liquidity, sqrtCurrent, sqrtPriceLimit, amount1In);
        } else {
            // If it's equal or above the upper price or disabled by setting the limit to 0, we don't apply the limit
            (amount0Out, amount1InAfter, sqrtPriceAfter) =
                quoteExactInputOneForZero(liquidity, sqrtCurrent, sqrtPriceUpper, amount1In);
        }
    }

    function quoteExactInputOneForZero(
        uint128 liquidity,
        uint160 sqrtCurrent,
        uint160 sqrtPriceUpper,
        uint256 amount1In
    ) internal pure returns (uint256 amount0Out, uint256 amount1InAfter, uint160 sqrtPriceAfter) {
        if (liquidity == 0 || amount1In == 0) return (0, 0, sqrtCurrent);
        if (sqrtPriceUpper <= sqrtCurrent) revert InvalidVirtualRange();

        // Use roundUp=false so that getNextSqrtPriceFromInput won't cross the limit
        uint256 maxAmount1 = SqrtPriceMath.getAmount1Delta(sqrtCurrent, sqrtPriceUpper, liquidity, false);
        
        // Cap input at maxAmount1 if limit would be exceeded
        amount1InAfter = amount1In > maxAmount1 ? maxAmount1 : amount1In;
        
        // Always calculate price consistently using getNextSqrtPriceFromInput
        sqrtPriceAfter = SqrtPriceMath.getNextSqrtPriceFromInput(sqrtCurrent, liquidity, amount1InAfter, false);
        amount0Out = SqrtPriceMath.getAmount0Delta(sqrtCurrent, sqrtPriceAfter, liquidity, false);

        // TODO: Invariant, remove after testing
        require(sqrtPriceAfter <= sqrtPriceUpper, "INVARIANT: sqrtPriceAfter <= sqrtPriceUpper");
    }

     function quoteExactOutputOneForZeroWithLimit(
        uint128 liquidity,
        uint160 sqrtCurrent,
        uint160 sqrtPriceUpper,
        uint160 sqrtPriceLimit,
        uint256 amount0Out
    ) internal pure returns (uint256 amount1In, uint256 amount0OutAfter, uint160 sqrtPriceAfter) {
        if (sqrtPriceLimit <= sqrtCurrent && sqrtPriceLimit != 0) revert InvalidSqrtPriceLimit();

        if (sqrtPriceLimit < sqrtPriceUpper && sqrtPriceLimit != 0) {
            // If the limit is below the highest price and above the virtual price, we apply the limit
            (amount1In, amount0OutAfter, sqrtPriceAfter) =
                quoteExactOutputOneForZero(liquidity, sqrtCurrent, sqrtPriceLimit, amount0Out);
        } else {
            // If it's equal or above the upper price or disabled by setting the limit to 0, we don't apply the limit
            (amount1In, amount0OutAfter, sqrtPriceAfter) =
                quoteExactOutputOneForZero(liquidity, sqrtCurrent, sqrtPriceUpper, amount0Out);
        }
    }

    function quoteExactOutputOneForZero(
        uint128 liquidity,
        uint160 sqrtCurrent,
        uint160 sqrtPriceUpper,
        uint256 amount0Out
    ) internal pure returns (uint256 amount1In, uint256 amount0OutAfter, uint160 sqrtPriceAfter) {
        if (liquidity == 0 || amount0Out == 0) return (0, 0, sqrtCurrent);
        if (sqrtPriceUpper <= sqrtCurrent) revert InvalidVirtualRange();

        // For exact output, check if there's enough liquidity - if not, revert
        uint256 maxAmount0 = SqrtPriceMath.getAmount0Delta(sqrtCurrent, sqrtPriceUpper, liquidity, false);
        if (amount0Out > maxAmount0) revert InsufficientLiquidityForExactOutput();
        
        // Output is exactly what was requested
        amount0OutAfter = amount0Out;
        
        // Calculate price and input
        sqrtPriceAfter = SqrtPriceMath.getNextSqrtPriceFromOutput(sqrtCurrent, liquidity, amount0OutAfter, false);
        amount1In = SqrtPriceMath.getAmount1Delta(sqrtCurrent, sqrtPriceAfter, liquidity, true);

        // TODO: Invariant, remove after testing
        require(sqrtPriceAfter <= sqrtPriceUpper, "INVARIANT: sqrtPriceAfter <= sqrtPriceUpper");
    }
}

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

/// @notice Simple single owner authorization mixin.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/auth/Ownable.sol)
///
/// @dev Note:
/// This implementation does NOT auto-initialize the owner to `msg.sender`.
/// You MUST call the `_initializeOwner` in the constructor / initializer.
///
/// While the ownable portion follows
/// [EIP-173](https://eips.ethereum.org/EIPS/eip-173) for compatibility,
/// the nomenclature for the 2-step ownership handover may be unique to this codebase.
abstract contract Ownable {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       CUSTOM ERRORS                        */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev The caller is not authorized to call the function.
    error Unauthorized();

    /// @dev The `newOwner` cannot be the zero address.
    error NewOwnerIsZeroAddress();

    /// @dev The `pendingOwner` does not have a valid handover request.
    error NoHandoverRequest();

    /// @dev Cannot double-initialize.
    error AlreadyInitialized();

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                           EVENTS                           */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev The ownership is transferred from `oldOwner` to `newOwner`.
    /// This event is intentionally kept the same as OpenZeppelin's Ownable to be
    /// compatible with indexers and [EIP-173](https://eips.ethereum.org/EIPS/eip-173),
    /// despite it not being as lightweight as a single argument event.
    event OwnershipTransferred(address indexed oldOwner, address indexed newOwner);

    /// @dev An ownership handover to `pendingOwner` has been requested.
    event OwnershipHandoverRequested(address indexed pendingOwner);

    /// @dev The ownership handover to `pendingOwner` has been canceled.
    event OwnershipHandoverCanceled(address indexed pendingOwner);

    /// @dev `keccak256(bytes("OwnershipTransferred(address,address)"))`.
    uint256 private constant _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE =
        0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0;

    /// @dev `keccak256(bytes("OwnershipHandoverRequested(address)"))`.
    uint256 private constant _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE =
        0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d;

    /// @dev `keccak256(bytes("OwnershipHandoverCanceled(address)"))`.
    uint256 private constant _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE =
        0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                          STORAGE                           */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev The owner slot is given by:
    /// `bytes32(~uint256(uint32(bytes4(keccak256("_OWNER_SLOT_NOT")))))`.
    /// It is intentionally chosen to be a high value
    /// to avoid collision with lower slots.
    /// The choice of manual storage layout is to enable compatibility
    /// with both regular and upgradeable contracts.
    bytes32 internal constant _OWNER_SLOT =
        0xffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927;

    /// The ownership handover slot of `newOwner` is given by:
    /// ```
    ///     mstore(0x00, or(shl(96, user), _HANDOVER_SLOT_SEED))
    ///     let handoverSlot := keccak256(0x00, 0x20)
    /// ```
    /// It stores the expiry timestamp of the two-step ownership handover.
    uint256 private constant _HANDOVER_SLOT_SEED = 0x389a75e1;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                     INTERNAL FUNCTIONS                     */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Override to return true to make `_initializeOwner` prevent double-initialization.
    function _guardInitializeOwner() internal pure virtual returns (bool guard) {}

    /// @dev Initializes the owner directly without authorization guard.
    /// This function must be called upon initialization,
    /// regardless of whether the contract is upgradeable or not.
    /// This is to enable generalization to both regular and upgradeable contracts,
    /// and to save gas in case the initial owner is not the caller.
    /// For performance reasons, this function will not check if there
    /// is an existing owner.
    function _initializeOwner(address newOwner) internal virtual {
        if (_guardInitializeOwner()) {
            /// @solidity memory-safe-assembly
            assembly {
                let ownerSlot := _OWNER_SLOT
                if sload(ownerSlot) {
                    mstore(0x00, 0x0dc149f0) // `AlreadyInitialized()`.
                    revert(0x1c, 0x04)
                }
                // Clean the upper 96 bits.
                newOwner := shr(96, shl(96, newOwner))
                // Store the new value.
                sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner))))
                // Emit the {OwnershipTransferred} event.
                log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner)
            }
        } else {
            /// @solidity memory-safe-assembly
            assembly {
                // Clean the upper 96 bits.
                newOwner := shr(96, shl(96, newOwner))
                // Store the new value.
                sstore(_OWNER_SLOT, newOwner)
                // Emit the {OwnershipTransferred} event.
                log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner)
            }
        }
    }

    /// @dev Sets the owner directly without authorization guard.
    function _setOwner(address newOwner) internal virtual {
        if (_guardInitializeOwner()) {
            /// @solidity memory-safe-assembly
            assembly {
                let ownerSlot := _OWNER_SLOT
                // Clean the upper 96 bits.
                newOwner := shr(96, shl(96, newOwner))
                // Emit the {OwnershipTransferred} event.
                log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner)
                // Store the new value.
                sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner))))
            }
        } else {
            /// @solidity memory-safe-assembly
            assembly {
                let ownerSlot := _OWNER_SLOT
                // Clean the upper 96 bits.
                newOwner := shr(96, shl(96, newOwner))
                // Emit the {OwnershipTransferred} event.
                log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner)
                // Store the new value.
                sstore(ownerSlot, newOwner)
            }
        }
    }

    /// @dev Throws if the sender is not the owner.
    function _checkOwner() internal view virtual {
        /// @solidity memory-safe-assembly
        assembly {
            // If the caller is not the stored owner, revert.
            if iszero(eq(caller(), sload(_OWNER_SLOT))) {
                mstore(0x00, 0x82b42900) // `Unauthorized()`.
                revert(0x1c, 0x04)
            }
        }
    }

    /// @dev Returns how long a two-step ownership handover is valid for in seconds.
    /// Override to return a different value if needed.
    /// Made internal to conserve bytecode. Wrap it in a public function if needed.
    function _ownershipHandoverValidFor() internal view virtual returns (uint64) {
        return 48 * 3600;
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                  PUBLIC UPDATE FUNCTIONS                   */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Allows the owner to transfer the ownership to `newOwner`.
    function transferOwnership(address newOwner) public payable virtual onlyOwner {
        /// @solidity memory-safe-assembly
        assembly {
            if iszero(shl(96, newOwner)) {
                mstore(0x00, 0x7448fbae) // `NewOwnerIsZeroAddress()`.
                revert(0x1c, 0x04)
            }
        }
        _setOwner(newOwner);
    }

    /// @dev Allows the owner to renounce their ownership.
    function renounceOwnership() public payable virtual onlyOwner {
        _setOwner(address(0));
    }

    /// @dev Request a two-step ownership handover to the caller.
    /// The request will automatically expire in 48 hours (172800 seconds) by default.
    function requestOwnershipHandover() public payable virtual {
        unchecked {
            uint256 expires = block.timestamp + _ownershipHandoverValidFor();
            /// @solidity memory-safe-assembly
            assembly {
                // Compute and set the handover slot to `expires`.
                mstore(0x0c, _HANDOVER_SLOT_SEED)
                mstore(0x00, caller())
                sstore(keccak256(0x0c, 0x20), expires)
                // Emit the {OwnershipHandoverRequested} event.
                log2(0, 0, _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE, caller())
            }
        }
    }

    /// @dev Cancels the two-step ownership handover to the caller, if any.
    function cancelOwnershipHandover() public payable virtual {
        /// @solidity memory-safe-assembly
        assembly {
            // Compute and set the handover slot to 0.
            mstore(0x0c, _HANDOVER_SLOT_SEED)
            mstore(0x00, caller())
            sstore(keccak256(0x0c, 0x20), 0)
            // Emit the {OwnershipHandoverCanceled} event.
            log2(0, 0, _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE, caller())
        }
    }

    /// @dev Allows the owner to complete the two-step ownership handover to `pendingOwner`.
    /// Reverts if there is no existing ownership handover requested by `pendingOwner`.
    function completeOwnershipHandover(address pendingOwner) public payable virtual onlyOwner {
        /// @solidity memory-safe-assembly
        assembly {
            // Compute and set the handover slot to 0.
            mstore(0x0c, _HANDOVER_SLOT_SEED)
            mstore(0x00, pendingOwner)
            let handoverSlot := keccak256(0x0c, 0x20)
            // If the handover does not exist, or has expired.
            if gt(timestamp(), sload(handoverSlot)) {
                mstore(0x00, 0x6f5e8818) // `NoHandoverRequest()`.
                revert(0x1c, 0x04)
            }
            // Set the handover slot to 0.
            sstore(handoverSlot, 0)
        }
        _setOwner(pendingOwner);
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                   PUBLIC READ FUNCTIONS                    */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Returns the owner of the contract.
    function owner() public view virtual returns (address result) {
        /// @solidity memory-safe-assembly
        assembly {
            result := sload(_OWNER_SLOT)
        }
    }

    /// @dev Returns the expiry timestamp for the two-step ownership handover to `pendingOwner`.
    function ownershipHandoverExpiresAt(address pendingOwner)
        public
        view
        virtual
        returns (uint256 result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            // Compute the handover slot.
            mstore(0x0c, _HANDOVER_SLOT_SEED)
            mstore(0x00, pendingOwner)
            // Load the handover slot.
            result := sload(keccak256(0x0c, 0x20))
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                         MODIFIERS                          */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Marks a function as only callable by the owner.
    modifier onlyOwner() virtual {
        _checkOwner();
        _;
    }
}

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

import {PoolKey} from "../types/PoolKey.sol";
import {BalanceDelta} from "../types/BalanceDelta.sol";
import {ModifyLiquidityParams, SwapParams} from "../types/PoolOperation.sol";
import {BeforeSwapDelta} from "../types/BeforeSwapDelta.sol";

/// @notice V4 decides whether to invoke specific hooks by inspecting the least significant bits
/// of the address that the hooks contract is deployed to.
/// For example, a hooks contract deployed to address: 0x0000000000000000000000000000000000002400
/// has the lowest bits '10 0100 0000 0000' which would cause the 'before initialize' and 'after add liquidity' hooks to be used.
/// See the Hooks library for the full spec.
/// @dev Should only be callable by the v4 PoolManager.
interface IHooks {
    /// @notice The hook called before the state of a pool is initialized
    /// @param sender The initial msg.sender for the initialize call
    /// @param key The key for the pool being initialized
    /// @param sqrtPriceX96 The sqrt(price) of the pool as a Q64.96
    /// @return bytes4 The function selector for the hook
    function beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96) external returns (bytes4);

    /// @notice The hook called after the state of a pool is initialized
    /// @param sender The initial msg.sender for the initialize call
    /// @param key The key for the pool being initialized
    /// @param sqrtPriceX96 The sqrt(price) of the pool as a Q64.96
    /// @param tick The current tick after the state of a pool is initialized
    /// @return bytes4 The function selector for the hook
    function afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)
        external
        returns (bytes4);

    /// @notice The hook called before liquidity is added
    /// @param sender The initial msg.sender for the add liquidity call
    /// @param key The key for the pool
    /// @param params The parameters for adding liquidity
    /// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be passed on to the hook
    /// @return bytes4 The function selector for the hook
    function beforeAddLiquidity(
        address sender,
        PoolKey calldata key,
        ModifyLiquidityParams calldata params,
        bytes calldata hookData
    ) external returns (bytes4);

    /// @notice The hook called after liquidity is added
    /// @param sender The initial msg.sender for the add liquidity call
    /// @param key The key for the pool
    /// @param params The parameters for adding liquidity
    /// @param delta The caller's balance delta after adding liquidity; the sum of principal delta, fees accrued, and hook delta
    /// @param feesAccrued The fees accrued since the last time fees were collected from this position
    /// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be passed on to the hook
    /// @return bytes4 The function selector for the hook
    /// @return BalanceDelta The hook's delta in token0 and token1. Positive: the hook is owed/took currency, negative: the hook owes/sent currency
    function afterAddLiquidity(
        address sender,
        PoolKey calldata key,
        ModifyLiquidityParams calldata params,
        BalanceDelta delta,
        BalanceDelta feesAccrued,
        bytes calldata hookData
    ) external returns (bytes4, BalanceDelta);

    /// @notice The hook called before liquidity is removed
    /// @param sender The initial msg.sender for the remove liquidity call
    /// @param key The key for the pool
    /// @param params The parameters for removing liquidity
    /// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be be passed on to the hook
    /// @return bytes4 The function selector for the hook
    function beforeRemoveLiquidity(
        address sender,
        PoolKey calldata key,
        ModifyLiquidityParams calldata params,
        bytes calldata hookData
    ) external returns (bytes4);

    /// @notice The hook called after liquidity is removed
    /// @param sender The initial msg.sender for the remove liquidity call
    /// @param key The key for the pool
    /// @param params The parameters for removing liquidity
    /// @param delta The caller's balance delta after removing liquidity; the sum of principal delta, fees accrued, and hook delta
    /// @param feesAccrued The fees accrued since the last time fees were collected from this position
    /// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be be passed on to the hook
    /// @return bytes4 The function selector for the hook
    /// @return BalanceDelta The hook's delta in token0 and token1. Positive: the hook is owed/took currency, negative: the hook owes/sent currency
    function afterRemoveLiquidity(
        address sender,
        PoolKey calldata key,
        ModifyLiquidityParams calldata params,
        BalanceDelta delta,
        BalanceDelta feesAccrued,
        bytes calldata hookData
    ) external returns (bytes4, BalanceDelta);

    /// @notice The hook called before a swap
    /// @param sender The initial msg.sender for the swap call
    /// @param key The key for the pool
    /// @param params The parameters for the swap
    /// @param hookData Arbitrary data handed into the PoolManager by the swapper to be be passed on to the hook
    /// @return bytes4 The function selector for the hook
    /// @return BeforeSwapDelta The hook's delta in specified and unspecified currencies. Positive: the hook is owed/took currency, negative: the hook owes/sent currency
    /// @return uint24 Optionally override the lp fee, only used if three conditions are met: 1. the Pool has a dynamic fee, 2. the value's 2nd highest bit is set (23rd bit, 0x400000), and 3. the value is less than or equal to the maximum fee (1 million)
    function beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)
        external
        returns (bytes4, BeforeSwapDelta, uint24);

    /// @notice The hook called after a swap
    /// @param sender The initial msg.sender for the swap call
    /// @param key The key for the pool
    /// @param params The parameters for the swap
    /// @param delta The amount owed to the caller (positive) or owed to the pool (negative)
    /// @param hookData Arbitrary data handed into the PoolManager by the swapper to be be passed on to the hook
    /// @return bytes4 The function selector for the hook
    /// @return int128 The hook's delta in unspecified currency. Positive: the hook is owed/took currency, negative: the hook owes/sent currency
    function afterSwap(
        address sender,
        PoolKey calldata key,
        SwapParams calldata params,
        BalanceDelta delta,
        bytes calldata hookData
    ) external returns (bytes4, int128);

    /// @notice The hook called before donate
    /// @param sender The initial msg.sender for the donate call
    /// @param key The key for the pool
    /// @param amount0 The amount of token0 being donated
    /// @param amount1 The amount of token1 being donated
    /// @param hookData Arbitrary data handed into the PoolManager by the donor to be be passed on to the hook
    /// @return bytes4 The function selector for the hook
    function beforeDonate(
        address sender,
        PoolKey calldata key,
        uint256 amount0,
        uint256 amount1,
        bytes calldata hookData
    ) external returns (bytes4);

    /// @notice The hook called after donate
    /// @param sender The initial msg.sender for the donate call
    /// @param key The key for the pool
    /// @param amount0 The amount of token0 being donated
    /// @param amount1 The amount of token1 being donated
    /// @param hookData Arbitrary data handed into the PoolManager by the donor to be be passed on to the hook
    /// @return bytes4 The function selector for the hook
    function afterDonate(
        address sender,
        PoolKey calldata key,
        uint256 amount0,
        uint256 amount1,
        bytes calldata hookData
    ) external returns (bytes4);
}

File 20 of 39 : PoolOperation.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import {PoolKey} from "../types/PoolKey.sol";
import {BalanceDelta} from "../types/BalanceDelta.sol";

/// @notice Parameter struct for `ModifyLiquidity` pool operations
struct ModifyLiquidityParams {
    // the lower and upper tick of the position
    int24 tickLower;
    int24 tickUpper;
    // how to modify the liquidity
    int256 liquidityDelta;
    // a value to set if you want unique liquidity positions at the same range
    bytes32 salt;
}

/// @notice Parameter struct for `Swap` pool operations
struct SwapParams {
    /// Whether to swap token0 for token1 or vice versa
    bool zeroForOne;
    /// The desired input amount if negative (exactIn), or the desired output amount if positive (exactOut)
    int256 amountSpecified;
    /// The sqrt price at which, if reached, the swap will stop executing
    uint160 sqrtPriceLimitX96;
}

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

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

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

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

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

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        if (!_safeTransfer(token, to, value, true)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @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 {
        if (!_safeTransferFrom(token, from, to, value, true)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

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

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

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

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

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

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

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

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

    /**
     * @dev Imitates a Solidity `token.transfer(to, value)` call, 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 to The recipient of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeTransfer(IERC20 token, address to, uint256 value, bool bubble) private returns (bool success) {
        bytes4 selector = IERC20.transfer.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(to, shr(96, not(0))))
            mstore(0x24, value)
            success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
        }
    }

    /**
     * @dev Imitates a Solidity `token.transferFrom(from, to, value)` call, 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 from The sender of the tokens
     * @param to The recipient of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value,
        bool bubble
    ) private returns (bool success) {
        bytes4 selector = IERC20.transferFrom.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(from, shr(96, not(0))))
            mstore(0x24, and(to, shr(96, not(0))))
            mstore(0x44, value)
            success := call(gas(), token, 0, 0x00, 0x64, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
            mstore(0x60, 0)
        }
    }

    /**
     * @dev Imitates a Solidity `token.approve(spender, value)` call, 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 spender The spender of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeApprove(IERC20 token, address spender, uint256 value, bool bubble) private returns (bool success) {
        bytes4 selector = IERC20.approve.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(spender, shr(96, not(0))))
            mstore(0x24, value)
            success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
        }
    }
}

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

/// @notice Interface for claims over a contract balance, wrapped as a ERC6909
interface IERC6909Claims {
    /*//////////////////////////////////////////////////////////////
                                 EVENTS
    //////////////////////////////////////////////////////////////*/

    event OperatorSet(address indexed owner, address indexed operator, bool approved);

    event Approval(address indexed owner, address indexed spender, uint256 indexed id, uint256 amount);

    event Transfer(address caller, address indexed from, address indexed to, uint256 indexed id, uint256 amount);

    /*//////////////////////////////////////////////////////////////
                                 FUNCTIONS
    //////////////////////////////////////////////////////////////*/

    /// @notice Owner balance of an id.
    /// @param owner The address of the owner.
    /// @param id The id of the token.
    /// @return amount The balance of the token.
    function balanceOf(address owner, uint256 id) external view returns (uint256 amount);

    /// @notice Spender allowance of an id.
    /// @param owner The address of the owner.
    /// @param spender The address of the spender.
    /// @param id The id of the token.
    /// @return amount The allowance of the token.
    function allowance(address owner, address spender, uint256 id) external view returns (uint256 amount);

    /// @notice Checks if a spender is approved by an owner as an operator
    /// @param owner The address of the owner.
    /// @param spender The address of the spender.
    /// @return approved The approval status.
    function isOperator(address owner, address spender) external view returns (bool approved);

    /// @notice Transfers an amount of an id from the caller to a receiver.
    /// @param receiver The address of the receiver.
    /// @param id The id of the token.
    /// @param amount The amount of the token.
    /// @return bool True, always, unless the function reverts
    function transfer(address receiver, uint256 id, uint256 amount) external returns (bool);

    /// @notice Transfers an amount of an id from a sender to a receiver.
    /// @param sender The address of the sender.
    /// @param receiver The address of the receiver.
    /// @param id The id of the token.
    /// @param amount The amount of the token.
    /// @return bool True, always, unless the function reverts
    function transferFrom(address sender, address receiver, uint256 id, uint256 amount) external returns (bool);

    /// @notice Approves an amount of an id to a spender.
    /// @param spender The address of the spender.
    /// @param id The id of the token.
    /// @param amount The amount of the token.
    /// @return bool True, always
    function approve(address spender, uint256 id, uint256 amount) external returns (bool);

    /// @notice Sets or removes an operator for the caller.
    /// @param operator The address of the operator.
    /// @param approved The approval status.
    /// @return bool True, always
    function setOperator(address operator, bool approved) external returns (bool);
}

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

import {Currency} from "../types/Currency.sol";
import {PoolId} from "../types/PoolId.sol";
import {PoolKey} from "../types/PoolKey.sol";

/// @notice Interface for all protocol-fee related functions in the pool manager
interface IProtocolFees {
    /// @notice Thrown when protocol fee is set too high
    error ProtocolFeeTooLarge(uint24 fee);

    /// @notice Thrown when collectProtocolFees or setProtocolFee is not called by the controller.
    error InvalidCaller();

    /// @notice Thrown when collectProtocolFees is attempted on a token that is synced.
    error ProtocolFeeCurrencySynced();

    /// @notice Emitted when the protocol fee controller address is updated in setProtocolFeeController.
    event ProtocolFeeControllerUpdated(address indexed protocolFeeController);

    /// @notice Emitted when the protocol fee is updated for a pool.
    event ProtocolFeeUpdated(PoolId indexed id, uint24 protocolFee);

    /// @notice Given a currency address, returns the protocol fees accrued in that currency
    /// @param currency The currency to check
    /// @return amount The amount of protocol fees accrued in the currency
    function protocolFeesAccrued(Currency currency) external view returns (uint256 amount);

    /// @notice Sets the protocol fee for the given pool
    /// @param key The key of the pool to set a protocol fee for
    /// @param newProtocolFee The fee to set
    function setProtocolFee(PoolKey memory key, uint24 newProtocolFee) external;

    /// @notice Sets the protocol fee controller
    /// @param controller The new protocol fee controller
    function setProtocolFeeController(address controller) external;

    /// @notice Collects the protocol fees for a given recipient and currency, returning the amount collected
    /// @dev This will revert if the contract is unlocked
    /// @param recipient The address to receive the protocol fees
    /// @param currency The currency to withdraw
    /// @param amount The amount of currency to withdraw
    /// @return amountCollected The amount of currency successfully withdrawn
    function collectProtocolFees(address recipient, Currency currency, uint256 amount)
        external
        returns (uint256 amountCollected);

    /// @notice Returns the current protocol fee controller address
    /// @return address The current protocol fee controller address
    function protocolFeeController() external view returns (address);
}

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

/// @notice Interface for functions to access any storage slot in a contract
interface IExtsload {
    /// @notice Called by external contracts to access granular pool state
    /// @param slot Key of slot to sload
    /// @return value The value of the slot as bytes32
    function extsload(bytes32 slot) external view returns (bytes32 value);

    /// @notice Called by external contracts to access granular pool state
    /// @param startSlot Key of slot to start sloading from
    /// @param nSlots Number of slots to load into return value
    /// @return values List of loaded values.
    function extsload(bytes32 startSlot, uint256 nSlots) external view returns (bytes32[] memory values);

    /// @notice Called by external contracts to access sparse pool state
    /// @param slots List of slots to SLOAD from.
    /// @return values List of loaded values.
    function extsload(bytes32[] calldata slots) external view returns (bytes32[] memory values);
}

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

/// @notice Interface for functions to access any transient storage slot in a contract
interface IExttload {
    /// @notice Called by external contracts to access transient storage of the contract
    /// @param slot Key of slot to tload
    /// @return value The value of the slot as bytes32
    function exttload(bytes32 slot) external view returns (bytes32 value);

    /// @notice Called by external contracts to access sparse transient pool state
    /// @param slots List of slots to tload
    /// @return values List of loaded values
    function exttload(bytes32[] calldata slots) external view returns (bytes32[] memory values);
}

// 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 = a * b; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly ("memory-safe") {
                let mm := mulmod(a, b, not(0))
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

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

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

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

            // Make division exact by subtracting the remainder from [prod1 prod0]
            // Compute remainder using mulmod
            uint256 remainder;
            assembly ("memory-safe") {
                remainder := mulmod(a, b, denominator)
            }
            // Subtract 256 bit number from 512 bit number
            assembly ("memory-safe") {
                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 ("memory-safe") {
                denominator := div(denominator, twos)
            }

            // Divide [prod1 prod0] by the factors of two
            assembly ("memory-safe") {
                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 ("memory-safe") {
                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 preconditions 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 > 0);
            }
        }
    }
}

File 28 of 39 : FixedPoint96.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

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

/// @title Minimal ERC20 interface for Uniswap
/// @notice Contains a subset of the full ERC20 interface that is used in Uniswap V3
interface IERC20Minimal {
    /// @notice Returns an account's balance in the token
    /// @param account The account for which to look up the number of tokens it has, i.e. its balance
    /// @return The number of tokens held by the account
    function balanceOf(address account) external view returns (uint256);

    /// @notice Transfers the amount of token from the `msg.sender` to the recipient
    /// @param recipient The account that will receive the amount transferred
    /// @param amount The number of tokens to send from the sender to the recipient
    /// @return Returns true for a successful transfer, false for an unsuccessful transfer
    function transfer(address recipient, uint256 amount) external returns (bool);

    /// @notice Returns the current allowance given to a spender by an owner
    /// @param owner The account of the token owner
    /// @param spender The account of the token spender
    /// @return The current allowance granted by `owner` to `spender`
    function allowance(address owner, address spender) external view returns (uint256);

    /// @notice Sets the allowance of a spender from the `msg.sender` to the value `amount`
    /// @param spender The account which will be allowed to spend a given amount of the owners tokens
    /// @param amount The amount of tokens allowed to be used by `spender`
    /// @return Returns true for a successful approval, false for unsuccessful
    function approve(address spender, uint256 amount) external returns (bool);

    /// @notice Transfers `amount` tokens from `sender` to `recipient` up to the allowance given to the `msg.sender`
    /// @param sender The account from which the transfer will be initiated
    /// @param recipient The recipient of the transfer
    /// @param amount The amount of the transfer
    /// @return Returns true for a successful transfer, false for unsuccessful
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);

    /// @notice Event emitted when tokens are transferred from one address to another, either via `#transfer` or `#transferFrom`.
    /// @param from The account from which the tokens were sent, i.e. the balance decreased
    /// @param to The account to which the tokens were sent, i.e. the balance increased
    /// @param value The amount of tokens that were transferred
    event Transfer(address indexed from, address indexed to, uint256 value);

    /// @notice Event emitted when the approval amount for the spender of a given owner's tokens changes.
    /// @param owner The account that approved spending of its tokens
    /// @param spender The account for which the spending allowance was modified
    /// @param value The new allowance from the owner to the spender
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

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

/// @title Library for reverting with custom errors efficiently
/// @notice Contains functions for reverting with custom errors with different argument types efficiently
/// @dev To use this library, declare `using CustomRevert for bytes4;` and replace `revert CustomError()` with
/// `CustomError.selector.revertWith()`
/// @dev The functions may tamper with the free memory pointer but it is fine since the call context is exited immediately
library CustomRevert {
    /// @dev ERC-7751 error for wrapping bubbled up reverts
    error WrappedError(address target, bytes4 selector, bytes reason, bytes details);

    /// @dev Reverts with the selector of a custom error in the scratch space
    function revertWith(bytes4 selector) internal pure {
        assembly ("memory-safe") {
            mstore(0, selector)
            revert(0, 0x04)
        }
    }

    /// @dev Reverts with a custom error with an address argument in the scratch space
    function revertWith(bytes4 selector, address addr) internal pure {
        assembly ("memory-safe") {
            mstore(0, selector)
            mstore(0x04, and(addr, 0xffffffffffffffffffffffffffffffffffffffff))
            revert(0, 0x24)
        }
    }

    /// @dev Reverts with a custom error with an int24 argument in the scratch space
    function revertWith(bytes4 selector, int24 value) internal pure {
        assembly ("memory-safe") {
            mstore(0, selector)
            mstore(0x04, signextend(2, value))
            revert(0, 0x24)
        }
    }

    /// @dev Reverts with a custom error with a uint160 argument in the scratch space
    function revertWith(bytes4 selector, uint160 value) internal pure {
        assembly ("memory-safe") {
            mstore(0, selector)
            mstore(0x04, and(value, 0xffffffffffffffffffffffffffffffffffffffff))
            revert(0, 0x24)
        }
    }

    /// @dev Reverts with a custom error with two int24 arguments
    function revertWith(bytes4 selector, int24 value1, int24 value2) internal pure {
        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(fmp, selector)
            mstore(add(fmp, 0x04), signextend(2, value1))
            mstore(add(fmp, 0x24), signextend(2, value2))
            revert(fmp, 0x44)
        }
    }

    /// @dev Reverts with a custom error with two uint160 arguments
    function revertWith(bytes4 selector, uint160 value1, uint160 value2) internal pure {
        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(fmp, selector)
            mstore(add(fmp, 0x04), and(value1, 0xffffffffffffffffffffffffffffffffffffffff))
            mstore(add(fmp, 0x24), and(value2, 0xffffffffffffffffffffffffffffffffffffffff))
            revert(fmp, 0x44)
        }
    }

    /// @dev Reverts with a custom error with two address arguments
    function revertWith(bytes4 selector, address value1, address value2) internal pure {
        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(fmp, selector)
            mstore(add(fmp, 0x04), and(value1, 0xffffffffffffffffffffffffffffffffffffffff))
            mstore(add(fmp, 0x24), and(value2, 0xffffffffffffffffffffffffffffffffffffffff))
            revert(fmp, 0x44)
        }
    }

    /// @notice bubble up the revert message returned by a call and revert with a wrapped ERC-7751 error
    /// @dev this method can be vulnerable to revert data bombs
    function bubbleUpAndRevertWith(
        address revertingContract,
        bytes4 revertingFunctionSelector,
        bytes4 additionalContext
    ) internal pure {
        bytes4 wrappedErrorSelector = WrappedError.selector;
        assembly ("memory-safe") {
            // Ensure the size of the revert data is a multiple of 32 bytes
            let encodedDataSize := mul(div(add(returndatasize(), 31), 32), 32)

            let fmp := mload(0x40)

            // Encode wrapped error selector, address, function selector, offset, additional context, size, revert reason
            mstore(fmp, wrappedErrorSelector)
            mstore(add(fmp, 0x04), and(revertingContract, 0xffffffffffffffffffffffffffffffffffffffff))
            mstore(
                add(fmp, 0x24),
                and(revertingFunctionSelector, 0xffffffff00000000000000000000000000000000000000000000000000000000)
            )
            // offset revert reason
            mstore(add(fmp, 0x44), 0x80)
            // offset additional context
            mstore(add(fmp, 0x64), add(0xa0, encodedDataSize))
            // size revert reason
            mstore(add(fmp, 0x84), returndatasize())
            // revert reason
            returndatacopy(add(fmp, 0xa4), 0, returndatasize())
            // size additional context
            mstore(add(fmp, add(0xa4, encodedDataSize)), 0x04)
            // additional context
            mstore(
                add(fmp, add(0xc4, encodedDataSize)),
                and(additionalContext, 0xffffffff00000000000000000000000000000000000000000000000000000000)
            )
            revert(fmp, add(0xe4, encodedDataSize))
        }
    }
}

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

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

/// @notice Library of helper functions for a pools LP fee
library LPFeeLibrary {
    using LPFeeLibrary for uint24;
    using CustomRevert for bytes4;

    /// @notice Thrown when the static or dynamic fee on a pool exceeds 100%.
    error LPFeeTooLarge(uint24 fee);

    /// @notice An lp fee of exactly 0b1000000... signals a dynamic fee pool. This isn't a valid static fee as it is > MAX_LP_FEE
    uint24 public constant DYNAMIC_FEE_FLAG = 0x800000;

    /// @notice the second bit of the fee returned by beforeSwap is used to signal if the stored LP fee should be overridden in this swap
    // only dynamic-fee pools can return a fee via the beforeSwap hook
    uint24 public constant OVERRIDE_FEE_FLAG = 0x400000;

    /// @notice mask to remove the override fee flag from a fee returned by the beforeSwaphook
    uint24 public constant REMOVE_OVERRIDE_MASK = 0xBFFFFF;

    /// @notice the lp fee is represented in hundredths of a bip, so the max is 100%
    uint24 public constant MAX_LP_FEE = 1000000;

    /// @notice returns true if a pool's LP fee signals that the pool has a dynamic fee
    /// @param self The fee to check
    /// @return bool True of the fee is dynamic
    function isDynamicFee(uint24 self) internal pure returns (bool) {
        return self == DYNAMIC_FEE_FLAG;
    }

    /// @notice returns true if an LP fee is valid, aka not above the maximum permitted fee
    /// @param self The fee to check
    /// @return bool True of the fee is valid
    function isValid(uint24 self) internal pure returns (bool) {
        return self <= MAX_LP_FEE;
    }

    /// @notice validates whether an LP fee is larger than the maximum, and reverts if invalid
    /// @param self The fee to validate
    function validate(uint24 self) internal pure {
        if (!self.isValid()) LPFeeTooLarge.selector.revertWith(self);
    }

    /// @notice gets and validates the initial LP fee for a pool. Dynamic fee pools have an initial fee of 0.
    /// @dev if a dynamic fee pool wants a non-0 initial fee, it should call `updateDynamicLPFee` in the afterInitialize hook
    /// @param self The fee to get the initial LP from
    /// @return initialFee 0 if the fee is dynamic, otherwise the fee (if valid)
    function getInitialLPFee(uint24 self) internal pure returns (uint24) {
        // the initial fee for a dynamic fee pool is 0
        if (self.isDynamicFee()) return 0;
        self.validate();
        return self;
    }

    /// @notice returns true if the fee has the override flag set (2nd highest bit of the uint24)
    /// @param self The fee to check
    /// @return bool True of the fee has the override flag set
    function isOverride(uint24 self) internal pure returns (bool) {
        return self & OVERRIDE_FEE_FLAG != 0;
    }

    /// @notice returns a fee with the override flag removed
    /// @param self The fee to remove the override flag from
    /// @return fee The fee without the override flag set
    function removeOverrideFlag(uint24 self) internal pure returns (uint24) {
        return self & REMOVE_OVERRIDE_MASK;
    }

    /// @notice Removes the override flag and validates the fee (reverts if the fee is too large)
    /// @param self The fee to remove the override flag from, and then validate
    /// @return fee The fee without the override flag set (if valid)
    function removeOverrideFlagAndValidate(uint24 self) internal pure returns (uint24 fee) {
        fee = self.removeOverrideFlag();
        fee.validate();
    }
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/// @notice Parses bytes returned from hooks and the byte selector used to check return selectors from hooks.
/// @dev parseSelector also is used to parse the expected selector
/// For parsing hook returns, note that all hooks return either bytes4 or (bytes4, 32-byte-delta) or (bytes4, 32-byte-delta, uint24).
library ParseBytes {
    function parseSelector(bytes memory result) internal pure returns (bytes4 selector) {
        // equivalent: (selector,) = abi.decode(result, (bytes4, int256));
        assembly ("memory-safe") {
            selector := mload(add(result, 0x20))
        }
    }

    function parseFee(bytes memory result) internal pure returns (uint24 lpFee) {
        // equivalent: (,, lpFee) = abi.decode(result, (bytes4, int256, uint24));
        assembly ("memory-safe") {
            lpFee := mload(add(result, 0x60))
        }
    }

    function parseReturnDelta(bytes memory result) internal pure returns (int256 hookReturn) {
        // equivalent: (, hookReturnDelta) = abi.decode(result, (bytes4, int256));
        assembly ("memory-safe") {
            hookReturn := mload(add(result, 0x40))
        }
    }
}

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

/// @title BitMath
/// @dev This library provides functionality for computing bit properties of an unsigned integer
/// @author Solady (https://github.com/Vectorized/solady/blob/8200a70e8dc2a77ecb074fc2e99a2a0d36547522/src/utils/LibBit.sol)
library BitMath {
    /// @notice Returns the index of the most significant bit of the number,
    ///     where the least significant bit is at index 0 and the most significant bit is at index 255
    /// @param x the value for which to compute the most significant bit, must be greater than 0
    /// @return r the index of the most significant bit
    function mostSignificantBit(uint256 x) internal pure returns (uint8 r) {
        require(x > 0);

        assembly ("memory-safe") {
            r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
            r := or(r, shl(4, lt(0xffff, shr(r, x))))
            r := or(r, shl(3, lt(0xff, shr(r, x))))
            // forgefmt: disable-next-item
            r := or(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),
                0x0706060506020500060203020504000106050205030304010505030400000000))
        }
    }

    /// @notice Returns the index of the least significant bit of the number,
    ///     where the least significant bit is at index 0 and the most significant bit is at index 255
    /// @param x the value for which to compute the least significant bit, must be greater than 0
    /// @return r the index of the least significant bit
    function leastSignificantBit(uint256 x) internal pure returns (uint8 r) {
        require(x > 0);

        assembly ("memory-safe") {
            // Isolate the least significant bit.
            x := and(x, sub(0, x))
            // For the upper 3 bits of the result, use a De Bruijn-like lookup.
            // Credit to adhusson: https://blog.adhusson.com/cheap-find-first-set-evm/
            // forgefmt: disable-next-item
            r := shl(5, shr(252, shl(shl(2, shr(250, mul(x,
                0xb6db6db6ddddddddd34d34d349249249210842108c6318c639ce739cffffffff))),
                0x8040405543005266443200005020610674053026020000107506200176117077)))
            // For the lower 5 bits of the result, use a De Bruijn lookup.
            // forgefmt: disable-next-item
            r := or(r, byte(and(div(0xd76453e0, shr(r, x)), 0x1f),
                0x001f0d1e100c1d070f090b19131c1706010e11080a1a141802121b1503160405))
        }
    }
}

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

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

import {FullMath} from "./FullMath.sol";
import {UnsafeMath} from "./UnsafeMath.sol";
import {FixedPoint96} from "./FixedPoint96.sol";

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

    error InvalidPriceOrLiquidity();
    error InvalidPrice();
    error NotEnoughLiquidity();
    error PriceOverflow();

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

        if (add) {
            unchecked {
                uint256 product = amount * sqrtPX96;
                if (product / amount == sqrtPX96) {
                    uint256 denominator = numerator1 + product;
                    if (denominator >= numerator1) {
                        // always fits in 160 bits
                        return uint160(FullMath.mulDivRoundingUp(numerator1, sqrtPX96, denominator));
                    }
                }
            }
            // denominator is checked for overflow
            return uint160(UnsafeMath.divRoundingUp(numerator1, (numerator1 / sqrtPX96) + amount));
        } else {
            unchecked {
                uint256 product = amount * sqrtPX96;
                // if the product overflows, we know the denominator underflows
                // in addition, we must check that the denominator does not underflow
                // equivalent: if (product / amount != sqrtPX96 || numerator1 <= product) revert PriceOverflow();
                assembly ("memory-safe") {
                    if iszero(
                        and(
                            eq(div(product, amount), and(sqrtPX96, 0xffffffffffffffffffffffffffffffffffffffff)),
                            gt(numerator1, product)
                        )
                    ) {
                        mstore(0, 0xf5c787f1) // selector for PriceOverflow()
                        revert(0x1c, 0x04)
                    }
                }
                uint256 denominator = numerator1 - product;
                return FullMath.mulDivRoundingUp(numerator1, sqrtPX96, denominator).toUint160();
            }
        }
    }

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

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

            // equivalent: if (sqrtPX96 <= quotient) revert NotEnoughLiquidity();
            assembly ("memory-safe") {
                if iszero(gt(and(sqrtPX96, 0xffffffffffffffffffffffffffffffffffffffff), quotient)) {
                    mstore(0, 0x4323a555) // selector for NotEnoughLiquidity()
                    revert(0x1c, 0x04)
                }
            }
            // always fits 160 bits
            unchecked {
                return uint160(sqrtPX96 - quotient);
            }
        }
    }

    /// @notice Gets the next sqrt price given an input amount of currency0 or currency1
    /// @dev Throws if price or liquidity are 0, or if the next price is out of bounds
    /// @param sqrtPX96 The starting price, i.e., before accounting for the input amount
    /// @param liquidity The amount of usable liquidity
    /// @param amountIn How much of currency0, or currency1, is being swapped in
    /// @param zeroForOne Whether the amount in is currency0 or currency1
    /// @return uint160 The price after adding the input amount to currency0 or currency1
    function getNextSqrtPriceFromInput(uint160 sqrtPX96, uint128 liquidity, uint256 amountIn, bool zeroForOne)
        internal
        pure
        returns (uint160)
    {
        // equivalent: if (sqrtPX96 == 0 || liquidity == 0) revert InvalidPriceOrLiquidity();
        assembly ("memory-safe") {
            if or(
                iszero(and(sqrtPX96, 0xffffffffffffffffffffffffffffffffffffffff)),
                iszero(and(liquidity, 0xffffffffffffffffffffffffffffffff))
            ) {
                mstore(0, 0x4f2461b8) // selector for InvalidPriceOrLiquidity()
                revert(0x1c, 0x04)
            }
        }

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

    /// @notice Gets the next sqrt price given an output amount of currency0 or currency1
    /// @dev Throws if price or liquidity are 0 or the next price is out of bounds
    /// @param sqrtPX96 The starting price before accounting for the output amount
    /// @param liquidity The amount of usable liquidity
    /// @param amountOut How much of currency0, or currency1, is being swapped out
    /// @param zeroForOne Whether the amount out is currency1 or currency0
    /// @return uint160 The price after removing the output amount of currency0 or currency1
    function getNextSqrtPriceFromOutput(uint160 sqrtPX96, uint128 liquidity, uint256 amountOut, bool zeroForOne)
        internal
        pure
        returns (uint160)
    {
        // equivalent: if (sqrtPX96 == 0 || liquidity == 0) revert InvalidPriceOrLiquidity();
        assembly ("memory-safe") {
            if or(
                iszero(and(sqrtPX96, 0xffffffffffffffffffffffffffffffffffffffff)),
                iszero(and(liquidity, 0xffffffffffffffffffffffffffffffff))
            ) {
                mstore(0, 0x4f2461b8) // selector for InvalidPriceOrLiquidity()
                revert(0x1c, 0x04)
            }
        }

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

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

            // equivalent: if (sqrtPriceAX96 == 0) revert InvalidPrice();
            assembly ("memory-safe") {
                if iszero(and(sqrtPriceAX96, 0xffffffffffffffffffffffffffffffffffffffff)) {
                    mstore(0, 0x00bfc921) // selector for InvalidPrice()
                    revert(0x1c, 0x04)
                }
            }

            uint256 numerator1 = uint256(liquidity) << FixedPoint96.RESOLUTION;
            uint256 numerator2 = sqrtPriceBX96 - sqrtPriceAX96;

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

    /// @notice Equivalent to: `a >= b ? a - b : b - a`
    function absDiff(uint160 a, uint160 b) internal pure returns (uint256 res) {
        assembly ("memory-safe") {
            let diff :=
                sub(and(a, 0xffffffffffffffffffffffffffffffffffffffff), and(b, 0xffffffffffffffffffffffffffffffffffffffff))
            // mask = 0 if a >= b else -1 (all 1s)
            let mask := sar(255, diff)
            // if a >= b, res = a - b = 0 ^ (a - b)
            // if a < b, res = b - a = ~~(b - a) = ~(-(b - a) - 1) = ~(a - b - 1) = (-1) ^ (a - b - 1)
            // either way, res = mask ^ (a - b + mask)
            res := xor(mask, add(mask, diff))
        }
    }

    /// @notice Gets the amount1 delta between two prices
    /// @dev Calculates liquidity * (sqrt(upper) - sqrt(lower))
    /// @param sqrtPriceAX96 A sqrt price
    /// @param sqrtPriceBX96 Another sqrt price
    /// @param liquidity The amount of usable liquidity
    /// @param roundUp Whether to round the amount up, or down
    /// @return amount1 Amount of currency1 required to cover a position of size liquidity between the two passed prices
    function getAmount1Delta(uint160 sqrtPriceAX96, uint160 sqrtPriceBX96, uint128 liquidity, bool roundUp)
        internal
        pure
        returns (uint256 amount1)
    {
        uint256 numerator = absDiff(sqrtPriceAX96, sqrtPriceBX96);
        uint256 denominator = FixedPoint96.Q96;
        uint256 _liquidity = uint256(liquidity);

        /**
         * Equivalent to:
         *   amount1 = roundUp
         *       ? FullMath.mulDivRoundingUp(liquidity, sqrtPriceBX96 - sqrtPriceAX96, FixedPoint96.Q96)
         *       : FullMath.mulDiv(liquidity, sqrtPriceBX96 - sqrtPriceAX96, FixedPoint96.Q96);
         * Cannot overflow because `type(uint128).max * type(uint160).max >> 96 < (1 << 192)`.
         */
        amount1 = FullMath.mulDiv(_liquidity, numerator, denominator);
        assembly ("memory-safe") {
            amount1 := add(amount1, and(gt(mulmod(_liquidity, numerator, denominator), 0), roundUp))
        }
    }

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

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

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

pragma solidity >=0.6.2;

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

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

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

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

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

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

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

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

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

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

    /// @notice Calculates floor(a×b÷denominator)
    /// @dev division by 0 will return 0, and should be checked externally
    /// @param a The multiplicand
    /// @param b The multiplier
    /// @param denominator The divisor
    /// @return result The 256-bit result, floor(a×b÷denominator)
    function simpleMulDiv(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result) {
        assembly ("memory-safe") {
            result := div(mul(a, b), denominator)
        }
    }
}

File 37 of 39 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)

pragma solidity >=0.4.16;

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

File 38 of 39 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)

pragma solidity >=0.4.16;

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

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

pragma solidity >=0.4.16;

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

Settings
{
  "remappings": [
    "lib/UniswapX:openzeppelin-contracts-upgradeable/=lib/UniswapX/lib/openzeppelin-contracts-upgradeable/",
    "lib/UniswapX:openzeppelin-contracts/=lib/UniswapX/lib/openzeppelin-contracts/contracts/",
    "lib/UniswapX:openzeppelin/=lib/UniswapX/lib/openzeppelin-contracts/contracts/",
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "UniswapX/=lib/UniswapX/",
    "ds-test/=lib/UniswapX/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
    "forge-gas-snapshot/=lib/UniswapX/lib/forge-gas-snapshot/src/",
    "forge-std/=lib/forge-std/src/",
    "permit2/=lib/UniswapX/lib/permit2/",
    "solmate/=lib/UniswapX/lib/solmate/",
    "chainlink/=lib/chainlink/contracts/src/v0.8/",
    "across/=/lib/across/contracts/",
    "safe-smart-account/=lib/safe-smart-account/contracts/",
    "src/=src/",
    "script/=script/",
    "test/=test/",
    "@uniswap/v4-core/=lib/uniswap-hooks/lib/v4-core/",
    "@uniswap/v4-periphery/=lib/uniswap-hooks/lib/v4-periphery/",
    "v4-core/=lib/uniswap-hooks/lib/v4-core/",
    "v4-periphery/=lib/uniswap-hooks/lib/v4-periphery/",
    "@openzeppelin/uniswap-hooks/=lib/uniswap-hooks/",
    "hookmate/=lib/hookmate/src/",
    "@ensdomains/=lib/uniswap-hooks/lib/v4-core/node_modules/@ensdomains/",
    "FreshCryptoLib/=lib/UniswapX/lib/calibur/lib/webauthn-sol/lib/FreshCryptoLib/solidity/src/",
    "account-abstraction/=lib/UniswapX/lib/calibur/lib/account-abstraction/contracts/",
    "calibur/=lib/UniswapX/lib/calibur/",
    "erc20-eth/=lib/UniswapX/lib/calibur/lib/erc20-eth/src/",
    "halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
    "hardhat/=lib/uniswap-hooks/lib/v4-core/node_modules/hardhat/",
    "openzeppelin/=lib/UniswapX/lib/openzeppelin-contracts/contracts/",
    "solady/=lib/solady/src/",
    "solarray/=lib/UniswapX/lib/solarray/src/",
    "uniswap-hooks/=lib/uniswap-hooks/src/",
    "webauthn-sol/=lib/UniswapX/lib/calibur/lib/webauthn-sol/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 100000
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "cancun",
  "viaIR": false
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"contract IPoolManager","name":"_poolManager","type":"address"},{"internalType":"contract IMinimalJITOracle","name":"_oracle","type":"address"},{"internalType":"contract IMinimalMerchantController","name":"_merchantController","type":"address"},{"internalType":"contract IERC20","name":"_pairToken","type":"address"},{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_merchant","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyInitialized","type":"error"},{"inputs":[],"name":"AssetNotAllowed","type":"error"},{"inputs":[],"name":"BlacklistedUser","type":"error"},{"inputs":[],"name":"HookNotImplemented","type":"error"},{"inputs":[],"name":"InsufficientLiquidityForExactOutput","type":"error"},{"inputs":[],"name":"InvalidHook","type":"error"},{"inputs":[],"name":"InvalidSqrtPriceLimit","type":"error"},{"inputs":[],"name":"InvalidVirtualRange","type":"error"},{"inputs":[],"name":"NewOwnerIsZeroAddress","type":"error"},{"inputs":[],"name":"NoHandoverRequest","type":"error"},{"inputs":[],"name":"NonWhitelistedAsset","type":"error"},{"inputs":[],"name":"NotEnoughLiquidityUSDC","type":"error"},{"inputs":[],"name":"NotPoolManager","type":"error"},{"inputs":[],"name":"OracleReportNotAvailable","type":"error"},{"inputs":[],"name":"PairCurrencyNotAllowed","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"inputs":[],"name":"UnsupportedOperation","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"PoolId","name":"poolId","type":"bytes32"},{"indexed":false,"internalType":"bool","name":"zeroForOne","type":"bool"},{"indexed":false,"internalType":"uint160","name":"virtualSqrtPriceAfter","type":"uint160"},{"indexed":false,"internalType":"uint256","name":"amountIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountOut","type":"uint256"}],"name":"JITSwapResult","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"PAIR_TOKEN","outputs":[{"internalType":"Currency","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"key","type":"tuple"},{"components":[{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"int256","name":"liquidityDelta","type":"int256"},{"internalType":"bytes32","name":"salt","type":"bytes32"}],"internalType":"struct ModifyLiquidityParams","name":"params","type":"tuple"},{"internalType":"BalanceDelta","name":"delta0","type":"int256"},{"internalType":"BalanceDelta","name":"delta1","type":"int256"},{"internalType":"bytes","name":"hookData","type":"bytes"}],"name":"afterAddLiquidity","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"},{"internalType":"BalanceDelta","name":"","type":"int256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"key","type":"tuple"},{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"bytes","name":"hookData","type":"bytes"}],"name":"afterDonate","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"key","type":"tuple"},{"internalType":"uint160","name":"sqrtPriceX96","type":"uint160"},{"internalType":"int24","name":"tick","type":"int24"}],"name":"afterInitialize","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"key","type":"tuple"},{"components":[{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"int256","name":"liquidityDelta","type":"int256"},{"internalType":"bytes32","name":"salt","type":"bytes32"}],"internalType":"struct ModifyLiquidityParams","name":"params","type":"tuple"},{"internalType":"BalanceDelta","name":"delta0","type":"int256"},{"internalType":"BalanceDelta","name":"delta1","type":"int256"},{"internalType":"bytes","name":"hookData","type":"bytes"}],"name":"afterRemoveLiquidity","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"},{"internalType":"BalanceDelta","name":"","type":"int256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"key","type":"tuple"},{"components":[{"internalType":"bool","name":"zeroForOne","type":"bool"},{"internalType":"int256","name":"amountSpecified","type":"int256"},{"internalType":"uint160","name":"sqrtPriceLimitX96","type":"uint160"}],"internalType":"struct SwapParams","name":"params","type":"tuple"},{"internalType":"BalanceDelta","name":"delta","type":"int256"},{"internalType":"bytes","name":"hookData","type":"bytes"}],"name":"afterSwap","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"},{"internalType":"int128","name":"","type":"int128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"key","type":"tuple"},{"components":[{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"int256","name":"liquidityDelta","type":"int256"},{"internalType":"bytes32","name":"salt","type":"bytes32"}],"internalType":"struct ModifyLiquidityParams","name":"params","type":"tuple"},{"internalType":"bytes","name":"hookData","type":"bytes"}],"name":"beforeAddLiquidity","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"key","type":"tuple"},{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"bytes","name":"hookData","type":"bytes"}],"name":"beforeDonate","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"key","type":"tuple"},{"internalType":"uint160","name":"sqrtPriceX96","type":"uint160"}],"name":"beforeInitialize","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"key","type":"tuple"},{"components":[{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"int256","name":"liquidityDelta","type":"int256"},{"internalType":"bytes32","name":"salt","type":"bytes32"}],"internalType":"struct ModifyLiquidityParams","name":"params","type":"tuple"},{"internalType":"bytes","name":"hookData","type":"bytes"}],"name":"beforeRemoveLiquidity","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"key","type":"tuple"},{"components":[{"internalType":"bool","name":"zeroForOne","type":"bool"},{"internalType":"int256","name":"amountSpecified","type":"int256"},{"internalType":"uint160","name":"sqrtPriceLimitX96","type":"uint160"}],"internalType":"struct SwapParams","name":"params","type":"tuple"},{"internalType":"bytes","name":"hookData","type":"bytes"}],"name":"beforeSwap","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"},{"internalType":"BeforeSwapDelta","name":"","type":"int256"},{"internalType":"uint24","name":"","type":"uint24"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cancelOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"completeOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"getHookPermissions","outputs":[{"components":[{"internalType":"bool","name":"beforeInitialize","type":"bool"},{"internalType":"bool","name":"afterInitialize","type":"bool"},{"internalType":"bool","name":"beforeAddLiquidity","type":"bool"},{"internalType":"bool","name":"afterAddLiquidity","type":"bool"},{"internalType":"bool","name":"beforeRemoveLiquidity","type":"bool"},{"internalType":"bool","name":"afterRemoveLiquidity","type":"bool"},{"internalType":"bool","name":"beforeSwap","type":"bool"},{"internalType":"bool","name":"afterSwap","type":"bool"},{"internalType":"bool","name":"beforeDonate","type":"bool"},{"internalType":"bool","name":"afterDonate","type":"bool"},{"internalType":"bool","name":"beforeSwapReturnDelta","type":"bool"},{"internalType":"bool","name":"afterSwapReturnDelta","type":"bool"},{"internalType":"bool","name":"afterAddLiquidityReturnDelta","type":"bool"},{"internalType":"bool","name":"afterRemoveLiquidityReturnDelta","type":"bool"}],"internalType":"struct Hooks.Permissions","name":"","type":"tuple"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"PoolId","name":"","type":"bytes32"}],"name":"lowerVirtualPrice","outputs":[{"internalType":"uint48","name":"timestamp","type":"uint48"},{"internalType":"uint160","name":"virtualSqrtPriceX96","type":"uint160"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"merchant","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"merchantController","outputs":[{"internalType":"contract IMinimalMerchantController","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oracle","outputs":[{"internalType":"contract IMinimalJITOracle","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"result","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"ownershipHandoverExpiresAt","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolManager","outputs":[{"internalType":"contract IPoolManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"requestOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_merchant","type":"address"}],"name":"setMerchant","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IMinimalMerchantController","name":"_merchantController","type":"address"}],"name":"setMerchantController","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IMinimalJITOracle","name":"_oracle","type":"address"}],"name":"setOracle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"key","type":"tuple"}],"name":"sweepToMerchant","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"unlockCallback","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"PoolId","name":"","type":"bytes32"}],"name":"upperVirtualPrice","outputs":[{"internalType":"uint48","name":"timestamp","type":"uint48"},{"internalType":"uint160","name":"virtualSqrtPriceX96","type":"uint160"}],"stateMutability":"view","type":"function"}]

60c060405234801561000f575f80fd5b50604051615cc4380380615cc483398101604081905261002e91610450565b6001600160a01b03861660805285610045306100cf565b5061004f826101c2565b610058856101fd565b61006184610245565b61006a8161028e565b6001600160a01b0386166100915760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b0383166100b85760405163d92e233d60e01b815260040160405180910390fd5b50506001600160a01b031660a052506104d3915050565b6101bf816101ba604080516101c0810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810182905261018081018290526101a081019190915250604080516101c08101825260018082525f60208301819052928201819052606082018390526080820181905260a0820183905260c0820181905260e0820183905261010082018190526101208201839052610140820152610160810182905261018081018290526101a081019190915290565b6102d7565b50565b6001600160a01b0316638b78c6d819819055805f7f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08180a350565b6001600160a01b0381166102245760405163d92e233d60e01b815260040160405180910390fd5b5f80546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b03811661026c5760405163d92e233d60e01b815260040160405180910390fd5b600180546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b0381166102b55760405163d92e233d60e01b815260040160405180910390fd5b600280546001600160a01b0319166001600160a01b0392909216919091179055565b80511515612000831615151415806102fb5750602081015115156110008316151514155b806103125750604081015115156108008316151514155b806103295750606081015115156104008316151514155b806103405750608081015115156102008316151514155b80610357575060a081015115156101008316151514155b8061036d575060c0810151151560808316151514155b80610383575060e0810151151560408316151514155b8061039a5750610100810151151560208316151514155b806103b15750610120810151151560108316151514155b806103c85750610140810151151560088316151514155b806103df5750610160810151151560048316151514155b806103f65750610180810151151560028316151514155b8061040d57506101a0810151151560018316151514155b1561042357610423630732d7b560e51b83610427565b5050565b815f526001600160a01b03811660045260245ffd5b6001600160a01b03811681146101bf575f80fd5b5f805f805f8060c08789031215610465575f80fd5b86516104708161043c565b60208801519096506104818161043c565b60408801519095506104928161043c565b60608801519094506104a38161043c565b60808801519093506104b48161043c565b60a08801519092506104c58161043c565b809150509295509295509295565b60805160a0516156e96105db5f395f818161039b0152818161093601528181610e4a01528181612f950152818161312001528181613178015281816131f7015261450e01525f818161072d0152818161080b01528181610ae301528181610c1101528181610ca101528181610d3001528181610ddf01528181610eb101528181610fb8015281816110c801528181611180015281816112870152818161139c0152818161141e015281816114ab01528181611534015281816115b901528181612fb7015281816130a9015281816130f20152818161321b015281816138bd015281816139fa015281816143d30152818161441a0152818161457201526145bb01526156e95ff3fe6080604052600436106101c5575f3560e01c80638da5cb5b116100f2578063b6a8b0fa11610092578063e1b4af6911610062578063e1b4af691461076e578063f04e283e1461078d578063f2fde38b146107a0578063fee81cf4146107b3575f80fd5b8063b6a8b0fa146105fd578063c4e833ce1461061c578063dc4c90d31461071c578063dc98354e1461074f575f80fd5b8063a2fba484116100cd578063a2fba48414610539578063a5ff765114610558578063ae06ca9414610584578063b47b2fb1146105a3575f80fd5b80638da5cb5b146104da57806391dd73461461050d5780639f063efc146103bd575f80fd5b8063575e24b4116101685780636fe7e6eb116101385780636fe7e6eb14610469578063715018a6146104885780637adbf973146104905780637dc0d1d0146104af575f80fd5b8063575e24b4146103285780635ff851f61461038a5780636c2bbe7e146103bd5780636fdfde0214610414575f80fd5b8063259982e5116101a3578063259982e514610256578063470a8226146102b0578063535a1a811461030157806354d1f13d14610320575f80fd5b806303e753b4146101c957806321d0ee701461025657806325692962146102a6575b5f80fd5b3480156101d4575f80fd5b5061021e6101e3366004614bb2565b60046020525f908152604090205465ffffffffffff8116906601000000000000900473ffffffffffffffffffffffffffffffffffffffff1682565b6040805165ffffffffffff909316835273ffffffffffffffffffffffffffffffffffffffff9091166020830152015b60405180910390f35b348015610261575f80fd5b50610275610270366004614c55565b6107f2565b6040517fffffffff00000000000000000000000000000000000000000000000000000000909116815260200161024d565b6102ae610879565b005b3480156102bb575f80fd5b506001546102dc9073ffffffffffffffffffffffffffffffffffffffff1681565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200161024d565b34801561030c575f80fd5b506102ae61031b366004614ccc565b6108c6565b6102ae610bbd565b348015610333575f80fd5b50610347610342366004614cf6565b610bf6565b604080517fffffffff000000000000000000000000000000000000000000000000000000009094168452602084019290925262ffffff169082015260600161024d565b348015610395575f80fd5b506102dc7f000000000000000000000000000000000000000000000000000000000000000081565b3480156103c8575f80fd5b506103dc6103d7366004614d50565b610c87565b604080517fffffffff00000000000000000000000000000000000000000000000000000000909316835260208301919091520161024d565b34801561041f575f80fd5b5061021e61042e366004614bb2565b60036020525f908152604090205465ffffffffffff8116906601000000000000900473ffffffffffffffffffffffffffffffffffffffff1682565b348015610474575f80fd5b50610275610483366004614de9565b610d17565b6102ae610d9e565b34801561049b575f80fd5b506102ae6104aa366004614e42565b610db1565b3480156104ba575f80fd5b505f546102dc9073ffffffffffffffffffffffffffffffffffffffff1681565b3480156104e5575f80fd5b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927546102dc565b348015610518575f80fd5b5061052c610527366004614e5d565b610dc5565b60405161024d9190614e9c565b348015610544575f80fd5b506102ae610553366004614e42565b6113e2565b348015610563575f80fd5b506002546102dc9073ffffffffffffffffffffffffffffffffffffffff1681565b34801561058f575f80fd5b506102ae61059e366004614e42565b6113f3565b3480156105ae575f80fd5b506105c26105bd366004614eef565b611404565b604080517fffffffff000000000000000000000000000000000000000000000000000000009093168352600f9190910b60208301520161024d565b348015610608575f80fd5b50610275610617366004614f70565b611492565b348015610627575f80fd5b5061070f604080516101c0810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810182905261018081018290526101a081019190915250604080516101c08101825260018082525f60208301819052928201819052606082018390526080820181905260a0820183905260c0820181905260e0820183905261010082018190526101208201839052610140820152610160810182905261018081018290526101a081019190915290565b60405161024d9190614fca565b348015610727575f80fd5b506102dc7f000000000000000000000000000000000000000000000000000000000000000081565b34801561075a575f80fd5b506102756107693660046150eb565b61151b565b348015610779575f80fd5b50610275610788366004614f70565b6115a0565b6102ae61079b366004614e42565b61161e565b6102ae6107ae366004614e42565b611658565b3480156107be575f80fd5b506107e46107cd366004614e42565b63389a75e1600c9081525f91909152602090205490565b60405190815260200161024d565b5f3373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610862576040517fae18210a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61086f868686868661167e565b9695505050505050565b5f6202a30067ffffffffffffffff164201905063389a75e1600c52335f52806020600c2055337fdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d5f80a250565b306108d760a0830160808401614e42565b73ffffffffffffffffffffffffffffffffffffffff1614610924576040517f9c9d882300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6109736109346020830183614e42565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff90811691161490565b15610a6c5760015473ffffffffffffffffffffffffffffffffffffffff1663e4fbf4046109a66040840160208501614e42565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16815273ffffffffffffffffffffffffffffffffffffffff9091166004820152602401602060405180830381865afa158015610a0d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610a31919061513f565b610a67576040517f4847234300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610ae1565b610a7f6109346040830160208401614e42565b15610aaf5760015473ffffffffffffffffffffffffffffffffffffffff1663e4fbf4046109a66020840184614e42565b6040517f85d16a7e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff166348c8949182604051602001610b2e919061516a565b6040516020818303038152906040526040518263ffffffff1660e01b8152600401610b599190614e9c565b5f604051808303815f875af1158015610b74573d5f803e3d5ffd5b505050506040513d5f823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052610bb991908101906152be565b5050565b63389a75e1600c52335f525f6020600c2055337ffa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c925f80a2565b5f80803373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610c68576040517fae18210a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610c7588888888886116b1565b9250925092505b955095509592505050565b5f803373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610cf8576040517fae18210a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610d0789898989898989611ad5565b9150915097509795505050505050565b5f3373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610d87576040517fae18210a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610d9385858585611b09565b90505b949350505050565b610da6611b3c565b610daf5f611b71565b565b610db9611b3c565b610dc281611bd6565b50565b60603373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610e36576040517fae18210a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f610e4383850185615370565b80519091507f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff9081169116145f81610e94578260200151610e97565b82515b90505f82610ea6578351610eac565b83602001515b90505f7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1662fdd58e30610f1e8573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1690565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff90921660048301526024820152604401602060405180830381865afa158015610f8a573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610fae9190615408565b9050801561117d577f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f5298aca306110268573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1690565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff90921660048301526024820152604481018490526064015f604051808303815f87803b158015611095575f80fd5b505af11580156110a7573d5f803e3d5ffd5b506110ef9250505073ffffffffffffffffffffffffffffffffffffffff83167f000000000000000000000000000000000000000000000000000000000000000030845f611c69565b6001546040517f2565887400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff848116600483015230602483015260448201849052909116906325658874906064015f604051808303815f87803b158015611166575f80fd5b505af1158015611178573d5f803e3d5ffd5b505050505b5f7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1662fdd58e306111ed8773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1690565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff90921660048301526024820152604401602060405180830381865afa158015611259573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061127d9190615408565b905080156113c4577f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f5298aca306112f58773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1690565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff90921660048301526024820152604481018490526064015f604051808303815f87803b158015611364575f80fd5b505af1158015611376573d5f803e3d5ffd5b50506002546113c4925073ffffffffffffffffffffffffffffffffffffffff87811692507f00000000000000000000000000000000000000000000000000000000000000009116845f611c69565b60405180602001604052805f81525096505050505050505b92915050565b6113ea611b3c565b610dc281611de2565b6113fb611b3c565b610dc281611e76565b5f803373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614611475576040517fae18210a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611483888888888888611ad5565b91509150965096945050505050565b5f3373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614611502576040517fae18210a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61151087878787878761167e565b979650505050505050565b5f3373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000161461158b576040517fae18210a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611596848484611f0a565b90505b9392505050565b5f3373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614611610576040517fae18210a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611510878787878787611b09565b611626611b3c565b63389a75e1600c52805f526020600c20805442111561164c57636f5e88185f526004601cfd5b5f9055610dc281611b71565b611660611b3c565b8060601b61167557637448fbae5f526004601cfd5b610dc281611b71565b5f6040517f9ba6061b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001545f908190819073ffffffffffffffffffffffffffffffffffffffff1663e4fbf4046116e561093460208b018b614e42565b6116fb576116f660208a018a614e42565b61170b565b61170b60408a0160208b01614e42565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16815273ffffffffffffffffffffffffffffffffffffffff9091166004820152602401602060405180830381865afa158015611772573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611796919061513f565b6117cc576040517fe0fe9d5c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6118056117df61093460208a018a614e42565b6117f5576117f06020890189614e42565b6121e7565b6117f06040890160208a01614e42565b1561183c576040517fd9a60d2d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f61185661184f368a90038a018a615370565b60a0902090565b5f80546040517fbc60a7aa00000000000000000000000000000000000000000000000000000000815260048101849052929350909173ffffffffffffffffffffffffffffffffffffffff9091169063bc60a7aa9060240160e060405180830381865afa1580156118c8573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118ec9190615434565b90506118fb60208901896154c0565b801561192357505f8281526004602052604090205460c082015165ffffffffffff9182169116115b156119a7576119a2611937825f0151612277565b60c08301515f8581526004602052604090209190825473ffffffffffffffffffffffffffffffffffffffff9092166601000000000000027fffffffffffff000000000000000000000000000000000000000000000000000090921665ffffffffffff90911617179055565b611a5d565b6119b460208901896154c0565b1580156119dd57505f8281526003602052604090205460c082015165ffffffffffff9182169116115b15611a5d57611a5d6119f28260200151612277565b60c08301515f8581526003602052604090209190825473ffffffffffffffffffffffffffffffffffffffff9092166601000000000000027fffffffffffff000000000000000000000000000000000000000000000000000090921665ffffffffffff90911617179055565b611a6a60208901896154c0565b15611aa9577f575e24b400000000000000000000000000000000000000000000000000000000611a9b8a838b612574565b5f9450945094505050610c7c565b7f575e24b400000000000000000000000000000000000000000000000000000000611a9b8a838b6125f2565b5f806040517f0a85dc2900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6040517f0a85dc2900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927543314610daf576382b429005f526004601cfd5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927805473ffffffffffffffffffffffffffffffffffffffff9092169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a355565b73ffffffffffffffffffffffffffffffffffffffff8116611c23576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f80547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b8115611ddb5780611d05576040517f0b0d9c0900000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8681166004830152848116602483015260448201849052851690630b0d9c09906064015b5f604051808303815f87803b158015611cea575f80fd5b505af1158015611cfc573d5f803e3d5ffd5b50505050611ddb565b8373ffffffffffffffffffffffffffffffffffffffff1663156e29f684611d558873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1690565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff90921660048301526024820152604481018590526064015f604051808303815f87803b158015611dc4575f80fd5b505af1158015611dd6573d5f803e3d5ffd5b505050505b5050505050565b73ffffffffffffffffffffffffffffffffffffffff8116611e2f576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600280547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b73ffffffffffffffffffffffffffffffffffffffff8116611ec3576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b5f611f337fffffffffffffffffffffffffffffffffffffffffffffffffffffffff748739275490565b73ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614611f97576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611fa76109346020850185614e42565b156120a05760015473ffffffffffffffffffffffffffffffffffffffff1663e4fbf404611fda6040860160208701614e42565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16815273ffffffffffffffffffffffffffffffffffffffff9091166004820152602401602060405180830381865afa158015612041573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612065919061513f565b61209b576040517f4847234300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6120e3565b6120b36109346040850160208601614e42565b15610aaf5760015473ffffffffffffffffffffffffffffffffffffffff1663e4fbf404611fda6020860186614e42565b5f5473ffffffffffffffffffffffffffffffffffffffff1663bc60a7aa61211261184f36879003870187615370565b6040518263ffffffff1660e01b815260040161213091815260200190565b60e060405180830381865afa925050508015612187575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016820190925261218491810190615434565b60015b6121bd576040517f7aa0a98600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50507fdc98354e000000000000000000000000000000000000000000000000000000009392505050565b6040517f9fc558600000000000000000000000000000000000000000000000000000000081523260048201525f90829073ffffffffffffffffffffffffffffffffffffffff821690639fc5586090602401602060405180830381865afa158015612253573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611599919061513f565b60020b5f60ff82901d80830118620d89e88111156122b9576122b97f8b86327a000000000000000000000000000000000000000000000000000000008461265c565b7001fffcb933bd6fad37aa2d162d1a5940016001821602700100000000000000000000000000000000186002821615612302576ffff97272373d413259a46990580e213a0260801c5b6004821615612321576ffff2e50f5f656932ef12357cf3c7fdcc0260801c5b6008821615612340576fffe5caca7e10e4e61c3624eaa0941cd00260801c5b601082161561235f576fffcb9843d60f6159c9db58835c9266440260801c5b602082161561237e576fff973b41fa98c081472e6896dfb254c00260801c5b604082161561239d576fff2ea16466c96a3843ec78b326b528610260801c5b60808216156123bc576ffe5dee046a99a2a811c461f1969c30530260801c5b6101008216156123dc576ffcbe86c7900a88aedcffc83b479aa3a40260801c5b6102008216156123fc576ff987a7253ac413176f2b074cf7815e540260801c5b61040082161561241c576ff3392b0822b70005940c7a398e4b70f30260801c5b61080082161561243c576fe7159475a2c29b7443b29c7fa6e889d90260801c5b61100082161561245c576fd097f3bdfd2022b8845ad8f792aa58250260801c5b61200082161561247c576fa9f746462d870fdf8a65dc1f90e061e50260801c5b61400082161561249c576f70d869a156d2a1b890bb3df62baf32f70260801c5b6180008216156124bc576f31be135f97d08fd981231505542fcfa60260801c5b620100008216156124dd576f09aa508b5b7a84e1c677de54f3e99bc90260801c5b620200008216156124fd576e5d6af8dedb81196699c329225ee6040260801c5b6204000082161561251c576d2216e584f5fa1ea926041bedfe980260801c5b62080000821615612539576b048a170391f7dc42444e8fa20260801c5b5f841315612564577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff045b63ffffffff0160201c9392505050565b5f805f80612582878761266b565b9250925092505f856020013512156125c4576125bd8784846125aa60608a0160408b01614e42565b856125b860208c0135615508565b612734565b93506125e8565b6125e58784846125da60608a0160408b01614e42565b858a602001356128c1565b93505b5050509392505050565b5f805f806126008787612a21565b9250925092505f8560200135121561263b576125bd87848461262860608a0160408b01614e42565b8561263660208c0135615508565b612ae7565b6125e587848461265160608a0160408b01614e42565b858a60200135612c2b565b815f528060020b60045260245ffd5b5f805f808460400151855f0151612682919061553e565b85519091505f61269183612277565b90505f61269d83612277565b90506126af61093460208b018b614e42565b1561271d575f6126c483838b60800151612d6f565b90508260045f6126dc61184f368f90038f018f615370565b815260208101919091526040015f20549098506601000000000000900473ffffffffffffffffffffffffffffffffffffffff169650945061272d9350505050565b5f6126c483838b60a00151612d6f565b9250925092565b5f805f8061274586898b8a89612de7565b919450925090505f61275f61184f368d90038d018d615370565b5f81815260046020526040902080547fffffffffffff0000000000000000000000000000000000000000ffffffffffff16660100000000000073ffffffffffffffffffffffffffffffffffffffff86160217905590506127ee6127c184612efc565b6127d26127cd87615508565b612f41565b6fffffffffffffffffffffffffffffffff1660809190911b1790565b945061280061093460208d018d614e42565b1561282c5761280e83612f7b565b61282761282160408d0160208e01614e42565b85612fdf565b61284b565b61284261283c60208d018d614e42565b846130d6565b61284b8461311a565b604080518281526001602082015273ffffffffffffffffffffffffffffffffffffffff84169181019190915260608101849052608081018590527f51138130c9e3f5e656a90e531b54fe7abcc6af57fce40e810cb359be53a764ed9060a0015b60405180910390a1505050509695505050505050565b5f805f806128d286898b8a89613248565b919450925090505f6128ec61184f368d90038d018d615370565b5f81815260046020526040902080547fffffffffffff0000000000000000000000000000000000000000ffffffffffff16660100000000000073ffffffffffffffffffffffffffffffffffffffff861602179055905061296061294e84612efc565b6129579061557f565b6127d286612efc565b945061297261093460208d018d614e42565b1561299e5761298084612f7b565b61299961299360408d0160208e01614e42565b84612fdf565b6129bd565b6129b46129ae60208d018d614e42565b856130d6565b6129bd8361311a565b604080518281526001602082015273ffffffffffffffffffffffffffffffffffffffff84169181019190915260608101859052608081018490527f51138130c9e3f5e656a90e531b54fe7abcc6af57fce40e810cb359be53a764ed9060a0016128ab565b602081015160608201515f9182918291908290612a3e90836155bb565b90505f612a4a83612277565b90505f612a5683612277565b9050612a6b61093460408b0160208c01614e42565b15612ad7575f612a8083838b60800151613340565b905060035f612a9761184f368e90038e018e615370565b815260208101919091526040015f20546601000000000000900473ffffffffffffffffffffffffffffffffffffffff169750909550935061272d92505050565b5f612a8083838b60a00151613340565b5f805f80612af8868a8a8a896133db565b919450925090505f612b1261184f368d90038d018d615370565b5f81815260036020526040902080547fffffffffffff0000000000000000000000000000000000000000ffffffffffff16660100000000000073ffffffffffffffffffffffffffffffffffffffff8616021790559050612b746127c184612efc565b9450612b8961093460408d0160208e01614e42565b15612bac57612b9783612f7b565b612ba761282160208d018d614e42565b612bc8565b612bbf61283c60408d0160208e01614e42565b612bc88461311a565b604080518281525f602082015273ffffffffffffffffffffffffffffffffffffffff84169181019190915260608101849052608081018590527f51138130c9e3f5e656a90e531b54fe7abcc6af57fce40e810cb359be53a764ed9060a0016128ab565b5f805f80612c3c868a8a8a896134d3565b919450925090505f612c5661184f368d90038d018d615370565b5f81815260036020526040902080547fffffffffffff0000000000000000000000000000000000000000ffffffffffff16660100000000000073ffffffffffffffffffffffffffffffffffffffff8616021790559050612cb861294e84612efc565b9450612ccd61093460408d0160208e01614e42565b15612cf057612cdb84612f7b565b612ceb61299360208d018d614e42565b612d0c565b612d036129ae60408d0160208e01614e42565b612d0c8361311a565b604080518281525f602082015273ffffffffffffffffffffffffffffffffffffffff84169181019190915260608101859052608081018490527f51138130c9e3f5e656a90e531b54fe7abcc6af57fce40e810cb359be53a764ed9060a0016128ab565b5f8273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161115612da8579192915b611596612de2836c01000000000000000000000000612dc788886155fc565b73ffffffffffffffffffffffffffffffffffffffff166135cb565b613686565b5f805f8673ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1610158015612e3b575073ffffffffffffffffffffffffffffffffffffffff851615155b15612e72576040517fe48210ec00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8573ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16118015612ec2575073ffffffffffffffffffffffffffffffffffffffff851615155b15612edf57612ed388888787613707565b91945092509050610c7c565b612eeb88888887613707565b919a90995090975095505050505050565b5f6f800000000000000000000000000000008210612f3d57612f3d7f93dafdf1000000000000000000000000000000000000000000000000000000006138a3565b5090565b80600f81900b8114612f7657612f767f93dafdf1000000000000000000000000000000000000000000000000000000006138a3565b919050565b610dc273ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000167f000000000000000000000000000000000000000000000000000000000000000030846001611c69565b5f612fea83836138ab565b90505f612ff78284615628565b905080156130d0576001546040517f9290398600000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff808716600483015230602483015260448201849052869216906392903986906064015f604051808303815f87803b158015613076575f80fd5b505af1158015613088573d5f803e3d5ffd5b50611ddb9250505073ffffffffffffffffffffffffffffffffffffffff86167f000000000000000000000000000000000000000000000000000000000000000030855f613a3d565b50505050565b610bb973ffffffffffffffffffffffffffffffffffffffff83167f000000000000000000000000000000000000000000000000000000000000000030846001611c69565b5f6131457f0000000000000000000000000000000000000000000000000000000000000000836138ab565b90505f6131528284615628565b90508015613243576002546131a09073ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000081169116613d5a565b8111156131d9576040517f2b3f50fe00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6002546132439073ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000008116917f00000000000000000000000000000000000000000000000000000000000000009116845f613a3d565b505050565b5f805f8673ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161015801561329c575073ffffffffffffffffffffffffffffffffffffffff851615155b156132d3576040517fe48210ec00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8573ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16118015613323575073ffffffffffffffffffffffffffffffffffffffff851615155b1561333457612ed388888787613e29565b612eeb88888887613e29565b5f8273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161115613379579192915b5f6133be8573ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff166c010000000000000000000000006135cb565b90506133d2612de28483612dc789896155fc565b95945050505050565b5f805f8673ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161115801561342f575073ffffffffffffffffffffffffffffffffffffffff851615155b15613466576040517fe48210ec00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8573ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161080156134b6575073ffffffffffffffffffffffffffffffffffffffff851615155b156134c757612ed388888787613f28565b612eeb88888887613f28565b5f805f8673ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1611158015613527575073ffffffffffffffffffffffffffffffffffffffff851615155b1561355e576040517fe48210ec00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8573ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161080156135ae575073ffffffffffffffffffffffffffffffffffffffff851615155b156135bf57612ed3888887876140b7565b612eeb888888876140b7565b5f838302817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff85870982811083820303915050808411613609575f80fd5b805f0361361b57508290049050611599565b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b806fffffffffffffffffffffffffffffffff81168114612f76576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f6c6971756964697479206f766572666c6f77000000000000000000000000000060448201526064015b60405180910390fd5b5f80806fffffffffffffffffffffffffffffffff87161580613727575083155b1561373957505f915081905084613899565b8573ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161061379e576040517fc05711fa00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6137ab86888a5f6141b5565b90508085116137ba57846137bc565b805b92506137cb87898560016142e7565b91506137d982888a5f61434b565b93508573ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161015613897576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f494e56415249414e543a207371727450726963654166746572203e3d2073717260448201527f7450726963654c6f77657200000000000000000000000000000000000000000060648201526084016136fe565b505b9450945094915050565b805f5260045ffd5b5f815f036138ba57505f6113dc565b5f7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1662fdd58e3061392a8773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1690565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff90921660048301526024820152604401602060405180830381865afa158015613996573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906139ba9190615408565b9050805f036139cc575f9150506113dc565b5f8184106139da57816139dc565b835b9050613a2273ffffffffffffffffffffffffffffffffffffffff86167f000000000000000000000000000000000000000000000000000000000000000030846001613a3d565b80821115610d9657610d9685613a388385615628565b6143b6565b8115611ddb578015613af6578373ffffffffffffffffffffffffffffffffffffffff1663f5298aca84613a998873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1690565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff9092166004830152602482015260448101859052606401611cd3565b73ffffffffffffffffffffffffffffffffffffffff8516613c03576040517fa584119400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff868116600483015285169063a5841194906024015f604051808303815f87803b158015613b77575f80fd5b505af1158015613b89573d5f803e3d5ffd5b505050508373ffffffffffffffffffffffffffffffffffffffff166311da60b4836040518263ffffffff1660e01b815260040160206040518083038185885af1158015613bd8573d5f803e3d5ffd5b50505050506040513d601f19601f82011682018060405250810190613bfd9190615408565b50611ddb565b6040517fa584119400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff868116600483015285169063a5841194906024015f604051808303815f87803b158015613c69575f80fd5b505af1158015613c7b573d5f803e3d5ffd5b5050505073ffffffffffffffffffffffffffffffffffffffff83163014613cc357613cbe73ffffffffffffffffffffffffffffffffffffffff8616848685614675565b613ce4565b613ce473ffffffffffffffffffffffffffffffffffffffff861685846146d1565b8373ffffffffffffffffffffffffffffffffffffffff166311da60b46040518163ffffffff1660e01b81526004016020604051808303815f875af1158015613d2e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613d529190615408565b505050505050565b5f73ffffffffffffffffffffffffffffffffffffffff8316613d94575073ffffffffffffffffffffffffffffffffffffffff8116316113dc565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff83811660048301528416906370a0823190602401602060405180830381865afa158015613dfe573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613e229190615408565b90506113dc565b5f80806fffffffffffffffffffffffffffffffff87161580613e49575083155b15613e5b57505f915081905084613899565b8573ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1610613ec0576040517fc05711fa00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f613ecd86888a5f61434b565b905080851115613f09576040517f90b2d91f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b849250613f19878985600161472c565b91506137d982888a60016141b5565b5f80806fffffffffffffffffffffffffffffffff87161580613f48575083155b15613f5a57505f915081905084613899565b8573ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1611613fbf576040517fc05711fa00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f613fcc87878a5f61434b565b9050808511613fdb5784613fdd565b805b9250613feb8789855f6142e7565b9150613ff987838a5f6141b5565b93508573ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161115613897576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f494e56415249414e543a207371727450726963654166746572203c3d2073717260448201527f745072696365557070657200000000000000000000000000000000000000000060648201526084016136fe565b5f80806fffffffffffffffffffffffffffffffff871615806140d7575083155b156140e957505f915081905084613899565b8573ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161161414e576040517fc05711fa00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f61415b87878a5f6141b5565b905080851115614197576040517f90b2d91f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8492506141a68789855f61472c565b9150613ff987838a600161434b565b5f8373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1611156141ee579293925b73ffffffffffffffffffffffffffffffffffffffff85166142155762bfc9215f526004601cfd5b7bffffffffffffffffffffffffffffffff000000000000000000000000606084901b1673ffffffffffffffffffffffffffffffffffffffff86860316836142a1578673ffffffffffffffffffffffffffffffffffffffff1661428e83838973ffffffffffffffffffffffffffffffffffffffff166135cb565b8161429b5761429b61563b565b04611510565b6115106142c583838973ffffffffffffffffffffffffffffffffffffffff16614789565b8873ffffffffffffffffffffffffffffffffffffffff16808204910615150190565b5f6fffffffffffffffffffffffffffffffff84161573ffffffffffffffffffffffffffffffffffffffff861615171561432757634f2461b85f526004601cfd5b8161433e5761433985858560016147b9565b610d93565b610d93858585600161491b565b5f73ffffffffffffffffffffffffffffffffffffffff8481169086160360ff81901d908101186c010000000000000000000000006fffffffffffffffffffffffffffffffff851661439d8184846135cb565b9350845f83858409111684019350505050949350505050565b5f6143f773ffffffffffffffffffffffffffffffffffffffff84167f0000000000000000000000000000000000000000000000000000000000000000613d5a565b90505f8183106144075781614409565b825b9050805f036144185750505050565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f5298aca306144888773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1690565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff90921660048301526024820152604481018490526064015f604051808303815f87803b1580156144f7575f80fd5b505af1158015614509573d5f803e3d5ffd5b5050507f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff9081169086161490501561459f5760025461459a9073ffffffffffffffffffffffffffffffffffffffff868116917f00000000000000000000000000000000000000000000000000000000000000009116845f611c69565b6130d0565b6145e273ffffffffffffffffffffffffffffffffffffffff85167f000000000000000000000000000000000000000000000000000000000000000030845f611c69565b6001546040517f2565887400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff868116600483015230602483015260448201849052909116906325658874906064015f604051808303815f87803b158015614659575f80fd5b505af115801561466b573d5f803e3d5ffd5b5050505050505050565b614683848484846001614a50565b6130d0576040517f5274afe700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff851660048201526024016136fe565b6146de8383836001614ae3565b613243576040517f5274afe700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff841660048201526024016136fe565b5f6fffffffffffffffffffffffffffffffff84161573ffffffffffffffffffffffffffffffffffffffff861615171561476c57634f2461b85f526004601cfd5b8161477d576143398585855f61491b565b610d938585855f6147b9565b5f6147958484846135cb565b905081806147a5576147a561563b565b838509156115995760010180611599575f80fd5b5f811561485e575f73ffffffffffffffffffffffffffffffffffffffff84111561480c57614807846c01000000000000000000000000876fffffffffffffffffffffffffffffffff166135cb565b61482c565b61482c6fffffffffffffffffffffffffffffffff8616606086901b615668565b90506148566148518273ffffffffffffffffffffffffffffffffffffffff89166156a0565b614b6b565b915050610d96565b5f73ffffffffffffffffffffffffffffffffffffffff8411156148aa576148a5846c01000000000000000000000000876fffffffffffffffffffffffffffffffff16614789565b6148d0565b6148d0606085901b6fffffffffffffffffffffffffffffffff8716808204910615150190565b90508073ffffffffffffffffffffffffffffffffffffffff8716116148fc57634323a5555f526004601cfd5b73ffffffffffffffffffffffffffffffffffffffff8616039050610d96565b5f825f0361492a575083610d96565b7bffffffffffffffffffffffffffffffff000000000000000000000000606085901b1682156149f55773ffffffffffffffffffffffffffffffffffffffff86168481029085828161497d5761497d61563b565b04036149ba578181018281106149b8576149ae838973ffffffffffffffffffffffffffffffffffffffff1683614789565b9350505050610d96565b505b5061485681856149e073ffffffffffffffffffffffffffffffffffffffff8a1683615668565b6149ea91906156a0565b808204910615150190565b73ffffffffffffffffffffffffffffffffffffffff8616848102908582041481831116614a295763f5c787f15f526004601cfd5b8082036149ae6148518473ffffffffffffffffffffffffffffffffffffffff8b1684614789565b6040517f23b872dd000000000000000000000000000000000000000000000000000000005f81815273ffffffffffffffffffffffffffffffffffffffff8781166004528616602452604485905291602083606481808c5af1925060015f51148316614ad2578383151615614ac6573d5f823e3d81fd5b5f883b113d1516831692505b604052505f60605295945050505050565b6040517fa9059cbb000000000000000000000000000000000000000000000000000000005f81815273ffffffffffffffffffffffffffffffffffffffff8616600452602485905291602083604481808b5af1925060015f51148316614b5f578383151615614b53573d5f823e3d81fd5b5f873b113d1516831692505b60405250949350505050565b8073ffffffffffffffffffffffffffffffffffffffff81168114612f7657612f767f93dafdf1000000000000000000000000000000000000000000000000000000006138a3565b5f60208284031215614bc2575f80fd5b5035919050565b73ffffffffffffffffffffffffffffffffffffffff81168114610dc2575f80fd5b5f60a08284031215614bfa575f80fd5b50919050565b5f60808284031215614bfa575f80fd5b5f8083601f840112614c20575f80fd5b50813567ffffffffffffffff811115614c37575f80fd5b602083019150836020828501011115614c4e575f80fd5b9250929050565b5f805f805f6101608688031215614c6a575f80fd5b8535614c7581614bc9565b9450614c848760208801614bea565b9350614c938760c08801614c00565b925061014086013567ffffffffffffffff811115614caf575f80fd5b614cbb88828901614c10565b969995985093965092949392505050565b5f60a08284031215614cdc575f80fd5b6115998383614bea565b5f60608284031215614bfa575f80fd5b5f805f805f6101408688031215614d0b575f80fd5b8535614d1681614bc9565b9450614d258760208801614bea565b9350614d348760c08801614ce6565b925061012086013567ffffffffffffffff811115614caf575f80fd5b5f805f805f805f6101a0888a031215614d67575f80fd5b8735614d7281614bc9565b9650614d818960208a01614bea565b9550614d908960c08a01614c00565b94506101408801359350610160880135925061018088013567ffffffffffffffff811115614dbc575f80fd5b614dc88a828b01614c10565b989b979a50959850939692959293505050565b8060020b8114610dc2575f80fd5b5f805f806101008587031215614dfd575f80fd5b8435614e0881614bc9565b9350614e178660208701614bea565b925060c0850135614e2781614bc9565b915060e0850135614e3781614ddb565b939692955090935050565b5f60208284031215614e52575f80fd5b813561159981614bc9565b5f8060208385031215614e6e575f80fd5b823567ffffffffffffffff811115614e84575f80fd5b614e9085828601614c10565b90969095509350505050565b602081525f82518060208401528060208501604085015e5f6040828501015260407fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f83011684010191505092915050565b5f805f805f806101608789031215614f05575f80fd5b8635614f1081614bc9565b9550614f1f8860208901614bea565b9450614f2e8860c08901614ce6565b9350610120870135925061014087013567ffffffffffffffff811115614f52575f80fd5b614f5e89828a01614c10565b979a9699509497509295939492505050565b5f805f805f806101208789031215614f86575f80fd5b8635614f9181614bc9565b9550614fa08860208901614bea565b945060c0870135935060e0870135925061010087013567ffffffffffffffff811115614f52575f80fd5b8151151581526101c081016020830151614fe8602084018215159052565b506040830151614ffc604084018215159052565b506060830151615010606084018215159052565b506080830151615024608084018215159052565b5060a083015161503860a084018215159052565b5060c083015161504c60c084018215159052565b5060e083015161506060e084018215159052565b5061010083015161507661010084018215159052565b5061012083015161508c61012084018215159052565b506101408301516150a261014084018215159052565b506101608301516150b861016084018215159052565b506101808301516150ce61018084018215159052565b506101a08301516150e46101a084018215159052565b5092915050565b5f805f60e084860312156150fd575f80fd5b833561510881614bc9565b92506151178560208601614bea565b915060c084013561512781614bc9565b809150509250925092565b8015158114610dc2575f80fd5b5f6020828403121561514f575f80fd5b815161159981615132565b62ffffff81168114610dc2575f80fd5b60a08101823561517981614bc9565b73ffffffffffffffffffffffffffffffffffffffff168252602083013561519f81614bc9565b73ffffffffffffffffffffffffffffffffffffffff16602083015260408301356151c88161515a565b62ffffff16604083015260608301356151e081614ddb565b60020b606083015260808301356151f681614bc9565b73ffffffffffffffffffffffffffffffffffffffff811660808401525092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b60405160e0810167ffffffffffffffff8111828210171561526957615269615219565b60405290565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff811182821017156152b6576152b6615219565b604052919050565b5f602082840312156152ce575f80fd5b815167ffffffffffffffff8111156152e4575f80fd5b8201601f810184136152f4575f80fd5b805167ffffffffffffffff81111561530e5761530e615219565b61533f60207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8401160161526f565b818152856020838501011115615353575f80fd5b8160208401602083015e5f91810160200191909152949350505050565b5f60a0828403128015615381575f80fd5b5060405160a0810167ffffffffffffffff811182821017156153a5576153a5615219565b60405282356153b381614bc9565b815260208301356153c381614bc9565b602082015260408301356153d68161515a565b604082015260608301356153e981614ddb565b606082015260808301356153fc81614bc9565b60808201529392505050565b5f60208284031215615418575f80fd5b5051919050565b805165ffffffffffff81168114612f76575f80fd5b5f60e0828403128015615445575f80fd5b5061544e615246565b825161545981614ddb565b8152602083015161546981614ddb565b6020820152604083015161547c8161515a565b6040820152606083015161548f8161515a565b60608201526080838101519082015260a080840151908201526154b460c0840161541f565b60c08201529392505050565b5f602082840312156154d0575f80fd5b813561159981615132565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f7f80000000000000000000000000000000000000000000000000000000000000008203615538576155386154db565b505f0390565b600282810b9082900b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000008112627fffff821317156113dc576113dc6154db565b5f81600f0b7fffffffffffffffffffffffffffffffff8000000000000000000000000000000081036155b3576155b36154db565b5f0392915050565b600281810b9083900b01627fffff81137fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff800000821217156113dc576113dc6154db565b73ffffffffffffffffffffffffffffffffffffffff82811682821603908111156113dc576113dc6154db565b818103818111156113dc576113dc6154db565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f8261569b577f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b500490565b808201808211156113dc576113dc6154db56fea264697066735822122031421759edcaa26c7adcc67f00e18ecfbefd853933a76194a820f87c02c2370764736f6c634300081a00330000000000000000000000001f984000000000000000000000000000000000040000000000000000000000006bece1a3d1ed2da49c76105c6f874fe1608a8e1400000000000000000000000074ed5ed72df3bff374e4c87b8ff4bdebca954abe000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad600000000000000000000000074ed5ed72df3bff374e4c87b8ff4bdebca954abe0000000000000000000000003542a74555802e5bce60655f143a5c80addda5a1

Deployed Bytecode

0x6080604052600436106101c5575f3560e01c80638da5cb5b116100f2578063b6a8b0fa11610092578063e1b4af6911610062578063e1b4af691461076e578063f04e283e1461078d578063f2fde38b146107a0578063fee81cf4146107b3575f80fd5b8063b6a8b0fa146105fd578063c4e833ce1461061c578063dc4c90d31461071c578063dc98354e1461074f575f80fd5b8063a2fba484116100cd578063a2fba48414610539578063a5ff765114610558578063ae06ca9414610584578063b47b2fb1146105a3575f80fd5b80638da5cb5b146104da57806391dd73461461050d5780639f063efc146103bd575f80fd5b8063575e24b4116101685780636fe7e6eb116101385780636fe7e6eb14610469578063715018a6146104885780637adbf973146104905780637dc0d1d0146104af575f80fd5b8063575e24b4146103285780635ff851f61461038a5780636c2bbe7e146103bd5780636fdfde0214610414575f80fd5b8063259982e5116101a3578063259982e514610256578063470a8226146102b0578063535a1a811461030157806354d1f13d14610320575f80fd5b806303e753b4146101c957806321d0ee701461025657806325692962146102a6575b5f80fd5b3480156101d4575f80fd5b5061021e6101e3366004614bb2565b60046020525f908152604090205465ffffffffffff8116906601000000000000900473ffffffffffffffffffffffffffffffffffffffff1682565b6040805165ffffffffffff909316835273ffffffffffffffffffffffffffffffffffffffff9091166020830152015b60405180910390f35b348015610261575f80fd5b50610275610270366004614c55565b6107f2565b6040517fffffffff00000000000000000000000000000000000000000000000000000000909116815260200161024d565b6102ae610879565b005b3480156102bb575f80fd5b506001546102dc9073ffffffffffffffffffffffffffffffffffffffff1681565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200161024d565b34801561030c575f80fd5b506102ae61031b366004614ccc565b6108c6565b6102ae610bbd565b348015610333575f80fd5b50610347610342366004614cf6565b610bf6565b604080517fffffffff000000000000000000000000000000000000000000000000000000009094168452602084019290925262ffffff169082015260600161024d565b348015610395575f80fd5b506102dc7f000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad681565b3480156103c8575f80fd5b506103dc6103d7366004614d50565b610c87565b604080517fffffffff00000000000000000000000000000000000000000000000000000000909316835260208301919091520161024d565b34801561041f575f80fd5b5061021e61042e366004614bb2565b60036020525f908152604090205465ffffffffffff8116906601000000000000900473ffffffffffffffffffffffffffffffffffffffff1682565b348015610474575f80fd5b50610275610483366004614de9565b610d17565b6102ae610d9e565b34801561049b575f80fd5b506102ae6104aa366004614e42565b610db1565b3480156104ba575f80fd5b505f546102dc9073ffffffffffffffffffffffffffffffffffffffff1681565b3480156104e5575f80fd5b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927546102dc565b348015610518575f80fd5b5061052c610527366004614e5d565b610dc5565b60405161024d9190614e9c565b348015610544575f80fd5b506102ae610553366004614e42565b6113e2565b348015610563575f80fd5b506002546102dc9073ffffffffffffffffffffffffffffffffffffffff1681565b34801561058f575f80fd5b506102ae61059e366004614e42565b6113f3565b3480156105ae575f80fd5b506105c26105bd366004614eef565b611404565b604080517fffffffff000000000000000000000000000000000000000000000000000000009093168352600f9190910b60208301520161024d565b348015610608575f80fd5b50610275610617366004614f70565b611492565b348015610627575f80fd5b5061070f604080516101c0810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810182905261018081018290526101a081019190915250604080516101c08101825260018082525f60208301819052928201819052606082018390526080820181905260a0820183905260c0820181905260e0820183905261010082018190526101208201839052610140820152610160810182905261018081018290526101a081019190915290565b60405161024d9190614fca565b348015610727575f80fd5b506102dc7f0000000000000000000000001f9840000000000000000000000000000000000481565b34801561075a575f80fd5b506102756107693660046150eb565b61151b565b348015610779575f80fd5b50610275610788366004614f70565b6115a0565b6102ae61079b366004614e42565b61161e565b6102ae6107ae366004614e42565b611658565b3480156107be575f80fd5b506107e46107cd366004614e42565b63389a75e1600c9081525f91909152602090205490565b60405190815260200161024d565b5f3373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000001f984000000000000000000000000000000000041614610862576040517fae18210a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61086f868686868661167e565b9695505050505050565b5f6202a30067ffffffffffffffff164201905063389a75e1600c52335f52806020600c2055337fdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d5f80a250565b306108d760a0830160808401614e42565b73ffffffffffffffffffffffffffffffffffffffff1614610924576040517f9c9d882300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6109736109346020830183614e42565b7f000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad673ffffffffffffffffffffffffffffffffffffffff90811691161490565b15610a6c5760015473ffffffffffffffffffffffffffffffffffffffff1663e4fbf4046109a66040840160208501614e42565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16815273ffffffffffffffffffffffffffffffffffffffff9091166004820152602401602060405180830381865afa158015610a0d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610a31919061513f565b610a67576040517f4847234300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610ae1565b610a7f6109346040830160208401614e42565b15610aaf5760015473ffffffffffffffffffffffffffffffffffffffff1663e4fbf4046109a66020840184614e42565b6040517f85d16a7e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7f0000000000000000000000001f9840000000000000000000000000000000000473ffffffffffffffffffffffffffffffffffffffff166348c8949182604051602001610b2e919061516a565b6040516020818303038152906040526040518263ffffffff1660e01b8152600401610b599190614e9c565b5f604051808303815f875af1158015610b74573d5f803e3d5ffd5b505050506040513d5f823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052610bb991908101906152be565b5050565b63389a75e1600c52335f525f6020600c2055337ffa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c925f80a2565b5f80803373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000001f984000000000000000000000000000000000041614610c68576040517fae18210a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610c7588888888886116b1565b9250925092505b955095509592505050565b5f803373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000001f984000000000000000000000000000000000041614610cf8576040517fae18210a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610d0789898989898989611ad5565b9150915097509795505050505050565b5f3373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000001f984000000000000000000000000000000000041614610d87576040517fae18210a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610d9385858585611b09565b90505b949350505050565b610da6611b3c565b610daf5f611b71565b565b610db9611b3c565b610dc281611bd6565b50565b60603373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000001f984000000000000000000000000000000000041614610e36576040517fae18210a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f610e4383850185615370565b80519091507f000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad673ffffffffffffffffffffffffffffffffffffffff9081169116145f81610e94578260200151610e97565b82515b90505f82610ea6578351610eac565b83602001515b90505f7f0000000000000000000000001f9840000000000000000000000000000000000473ffffffffffffffffffffffffffffffffffffffff1662fdd58e30610f1e8573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1690565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff90921660048301526024820152604401602060405180830381865afa158015610f8a573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610fae9190615408565b9050801561117d577f0000000000000000000000001f9840000000000000000000000000000000000473ffffffffffffffffffffffffffffffffffffffff1663f5298aca306110268573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1690565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff90921660048301526024820152604481018490526064015f604051808303815f87803b158015611095575f80fd5b505af11580156110a7573d5f803e3d5ffd5b506110ef9250505073ffffffffffffffffffffffffffffffffffffffff83167f0000000000000000000000001f9840000000000000000000000000000000000430845f611c69565b6001546040517f2565887400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff848116600483015230602483015260448201849052909116906325658874906064015f604051808303815f87803b158015611166575f80fd5b505af1158015611178573d5f803e3d5ffd5b505050505b5f7f0000000000000000000000001f9840000000000000000000000000000000000473ffffffffffffffffffffffffffffffffffffffff1662fdd58e306111ed8773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1690565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff90921660048301526024820152604401602060405180830381865afa158015611259573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061127d9190615408565b905080156113c4577f0000000000000000000000001f9840000000000000000000000000000000000473ffffffffffffffffffffffffffffffffffffffff1663f5298aca306112f58773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1690565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff90921660048301526024820152604481018490526064015f604051808303815f87803b158015611364575f80fd5b505af1158015611376573d5f803e3d5ffd5b50506002546113c4925073ffffffffffffffffffffffffffffffffffffffff87811692507f0000000000000000000000001f984000000000000000000000000000000000049116845f611c69565b60405180602001604052805f81525096505050505050505b92915050565b6113ea611b3c565b610dc281611de2565b6113fb611b3c565b610dc281611e76565b5f803373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000001f984000000000000000000000000000000000041614611475576040517fae18210a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611483888888888888611ad5565b91509150965096945050505050565b5f3373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000001f984000000000000000000000000000000000041614611502576040517fae18210a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61151087878787878761167e565b979650505050505050565b5f3373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000001f98400000000000000000000000000000000004161461158b576040517fae18210a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611596848484611f0a565b90505b9392505050565b5f3373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000001f984000000000000000000000000000000000041614611610576040517fae18210a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611510878787878787611b09565b611626611b3c565b63389a75e1600c52805f526020600c20805442111561164c57636f5e88185f526004601cfd5b5f9055610dc281611b71565b611660611b3c565b8060601b61167557637448fbae5f526004601cfd5b610dc281611b71565b5f6040517f9ba6061b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001545f908190819073ffffffffffffffffffffffffffffffffffffffff1663e4fbf4046116e561093460208b018b614e42565b6116fb576116f660208a018a614e42565b61170b565b61170b60408a0160208b01614e42565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16815273ffffffffffffffffffffffffffffffffffffffff9091166004820152602401602060405180830381865afa158015611772573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611796919061513f565b6117cc576040517fe0fe9d5c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6118056117df61093460208a018a614e42565b6117f5576117f06020890189614e42565b6121e7565b6117f06040890160208a01614e42565b1561183c576040517fd9a60d2d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f61185661184f368a90038a018a615370565b60a0902090565b5f80546040517fbc60a7aa00000000000000000000000000000000000000000000000000000000815260048101849052929350909173ffffffffffffffffffffffffffffffffffffffff9091169063bc60a7aa9060240160e060405180830381865afa1580156118c8573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118ec9190615434565b90506118fb60208901896154c0565b801561192357505f8281526004602052604090205460c082015165ffffffffffff9182169116115b156119a7576119a2611937825f0151612277565b60c08301515f8581526004602052604090209190825473ffffffffffffffffffffffffffffffffffffffff9092166601000000000000027fffffffffffff000000000000000000000000000000000000000000000000000090921665ffffffffffff90911617179055565b611a5d565b6119b460208901896154c0565b1580156119dd57505f8281526003602052604090205460c082015165ffffffffffff9182169116115b15611a5d57611a5d6119f28260200151612277565b60c08301515f8581526003602052604090209190825473ffffffffffffffffffffffffffffffffffffffff9092166601000000000000027fffffffffffff000000000000000000000000000000000000000000000000000090921665ffffffffffff90911617179055565b611a6a60208901896154c0565b15611aa9577f575e24b400000000000000000000000000000000000000000000000000000000611a9b8a838b612574565b5f9450945094505050610c7c565b7f575e24b400000000000000000000000000000000000000000000000000000000611a9b8a838b6125f2565b5f806040517f0a85dc2900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6040517f0a85dc2900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927543314610daf576382b429005f526004601cfd5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927805473ffffffffffffffffffffffffffffffffffffffff9092169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a355565b73ffffffffffffffffffffffffffffffffffffffff8116611c23576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f80547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b8115611ddb5780611d05576040517f0b0d9c0900000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8681166004830152848116602483015260448201849052851690630b0d9c09906064015b5f604051808303815f87803b158015611cea575f80fd5b505af1158015611cfc573d5f803e3d5ffd5b50505050611ddb565b8373ffffffffffffffffffffffffffffffffffffffff1663156e29f684611d558873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1690565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff90921660048301526024820152604481018590526064015f604051808303815f87803b158015611dc4575f80fd5b505af1158015611dd6573d5f803e3d5ffd5b505050505b5050505050565b73ffffffffffffffffffffffffffffffffffffffff8116611e2f576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600280547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b73ffffffffffffffffffffffffffffffffffffffff8116611ec3576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b5f611f337fffffffffffffffffffffffffffffffffffffffffffffffffffffffff748739275490565b73ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614611f97576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611fa76109346020850185614e42565b156120a05760015473ffffffffffffffffffffffffffffffffffffffff1663e4fbf404611fda6040860160208701614e42565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16815273ffffffffffffffffffffffffffffffffffffffff9091166004820152602401602060405180830381865afa158015612041573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612065919061513f565b61209b576040517f4847234300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6120e3565b6120b36109346040850160208601614e42565b15610aaf5760015473ffffffffffffffffffffffffffffffffffffffff1663e4fbf404611fda6020860186614e42565b5f5473ffffffffffffffffffffffffffffffffffffffff1663bc60a7aa61211261184f36879003870187615370565b6040518263ffffffff1660e01b815260040161213091815260200190565b60e060405180830381865afa925050508015612187575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016820190925261218491810190615434565b60015b6121bd576040517f7aa0a98600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50507fdc98354e000000000000000000000000000000000000000000000000000000009392505050565b6040517f9fc558600000000000000000000000000000000000000000000000000000000081523260048201525f90829073ffffffffffffffffffffffffffffffffffffffff821690639fc5586090602401602060405180830381865afa158015612253573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611599919061513f565b60020b5f60ff82901d80830118620d89e88111156122b9576122b97f8b86327a000000000000000000000000000000000000000000000000000000008461265c565b7001fffcb933bd6fad37aa2d162d1a5940016001821602700100000000000000000000000000000000186002821615612302576ffff97272373d413259a46990580e213a0260801c5b6004821615612321576ffff2e50f5f656932ef12357cf3c7fdcc0260801c5b6008821615612340576fffe5caca7e10e4e61c3624eaa0941cd00260801c5b601082161561235f576fffcb9843d60f6159c9db58835c9266440260801c5b602082161561237e576fff973b41fa98c081472e6896dfb254c00260801c5b604082161561239d576fff2ea16466c96a3843ec78b326b528610260801c5b60808216156123bc576ffe5dee046a99a2a811c461f1969c30530260801c5b6101008216156123dc576ffcbe86c7900a88aedcffc83b479aa3a40260801c5b6102008216156123fc576ff987a7253ac413176f2b074cf7815e540260801c5b61040082161561241c576ff3392b0822b70005940c7a398e4b70f30260801c5b61080082161561243c576fe7159475a2c29b7443b29c7fa6e889d90260801c5b61100082161561245c576fd097f3bdfd2022b8845ad8f792aa58250260801c5b61200082161561247c576fa9f746462d870fdf8a65dc1f90e061e50260801c5b61400082161561249c576f70d869a156d2a1b890bb3df62baf32f70260801c5b6180008216156124bc576f31be135f97d08fd981231505542fcfa60260801c5b620100008216156124dd576f09aa508b5b7a84e1c677de54f3e99bc90260801c5b620200008216156124fd576e5d6af8dedb81196699c329225ee6040260801c5b6204000082161561251c576d2216e584f5fa1ea926041bedfe980260801c5b62080000821615612539576b048a170391f7dc42444e8fa20260801c5b5f841315612564577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff045b63ffffffff0160201c9392505050565b5f805f80612582878761266b565b9250925092505f856020013512156125c4576125bd8784846125aa60608a0160408b01614e42565b856125b860208c0135615508565b612734565b93506125e8565b6125e58784846125da60608a0160408b01614e42565b858a602001356128c1565b93505b5050509392505050565b5f805f806126008787612a21565b9250925092505f8560200135121561263b576125bd87848461262860608a0160408b01614e42565b8561263660208c0135615508565b612ae7565b6125e587848461265160608a0160408b01614e42565b858a60200135612c2b565b815f528060020b60045260245ffd5b5f805f808460400151855f0151612682919061553e565b85519091505f61269183612277565b90505f61269d83612277565b90506126af61093460208b018b614e42565b1561271d575f6126c483838b60800151612d6f565b90508260045f6126dc61184f368f90038f018f615370565b815260208101919091526040015f20549098506601000000000000900473ffffffffffffffffffffffffffffffffffffffff169650945061272d9350505050565b5f6126c483838b60a00151612d6f565b9250925092565b5f805f8061274586898b8a89612de7565b919450925090505f61275f61184f368d90038d018d615370565b5f81815260046020526040902080547fffffffffffff0000000000000000000000000000000000000000ffffffffffff16660100000000000073ffffffffffffffffffffffffffffffffffffffff86160217905590506127ee6127c184612efc565b6127d26127cd87615508565b612f41565b6fffffffffffffffffffffffffffffffff1660809190911b1790565b945061280061093460208d018d614e42565b1561282c5761280e83612f7b565b61282761282160408d0160208e01614e42565b85612fdf565b61284b565b61284261283c60208d018d614e42565b846130d6565b61284b8461311a565b604080518281526001602082015273ffffffffffffffffffffffffffffffffffffffff84169181019190915260608101849052608081018590527f51138130c9e3f5e656a90e531b54fe7abcc6af57fce40e810cb359be53a764ed9060a0015b60405180910390a1505050509695505050505050565b5f805f806128d286898b8a89613248565b919450925090505f6128ec61184f368d90038d018d615370565b5f81815260046020526040902080547fffffffffffff0000000000000000000000000000000000000000ffffffffffff16660100000000000073ffffffffffffffffffffffffffffffffffffffff861602179055905061296061294e84612efc565b6129579061557f565b6127d286612efc565b945061297261093460208d018d614e42565b1561299e5761298084612f7b565b61299961299360408d0160208e01614e42565b84612fdf565b6129bd565b6129b46129ae60208d018d614e42565b856130d6565b6129bd8361311a565b604080518281526001602082015273ffffffffffffffffffffffffffffffffffffffff84169181019190915260608101859052608081018490527f51138130c9e3f5e656a90e531b54fe7abcc6af57fce40e810cb359be53a764ed9060a0016128ab565b602081015160608201515f9182918291908290612a3e90836155bb565b90505f612a4a83612277565b90505f612a5683612277565b9050612a6b61093460408b0160208c01614e42565b15612ad7575f612a8083838b60800151613340565b905060035f612a9761184f368e90038e018e615370565b815260208101919091526040015f20546601000000000000900473ffffffffffffffffffffffffffffffffffffffff169750909550935061272d92505050565b5f612a8083838b60a00151613340565b5f805f80612af8868a8a8a896133db565b919450925090505f612b1261184f368d90038d018d615370565b5f81815260036020526040902080547fffffffffffff0000000000000000000000000000000000000000ffffffffffff16660100000000000073ffffffffffffffffffffffffffffffffffffffff8616021790559050612b746127c184612efc565b9450612b8961093460408d0160208e01614e42565b15612bac57612b9783612f7b565b612ba761282160208d018d614e42565b612bc8565b612bbf61283c60408d0160208e01614e42565b612bc88461311a565b604080518281525f602082015273ffffffffffffffffffffffffffffffffffffffff84169181019190915260608101849052608081018590527f51138130c9e3f5e656a90e531b54fe7abcc6af57fce40e810cb359be53a764ed9060a0016128ab565b5f805f80612c3c868a8a8a896134d3565b919450925090505f612c5661184f368d90038d018d615370565b5f81815260036020526040902080547fffffffffffff0000000000000000000000000000000000000000ffffffffffff16660100000000000073ffffffffffffffffffffffffffffffffffffffff8616021790559050612cb861294e84612efc565b9450612ccd61093460408d0160208e01614e42565b15612cf057612cdb84612f7b565b612ceb61299360208d018d614e42565b612d0c565b612d036129ae60408d0160208e01614e42565b612d0c8361311a565b604080518281525f602082015273ffffffffffffffffffffffffffffffffffffffff84169181019190915260608101859052608081018490527f51138130c9e3f5e656a90e531b54fe7abcc6af57fce40e810cb359be53a764ed9060a0016128ab565b5f8273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161115612da8579192915b611596612de2836c01000000000000000000000000612dc788886155fc565b73ffffffffffffffffffffffffffffffffffffffff166135cb565b613686565b5f805f8673ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1610158015612e3b575073ffffffffffffffffffffffffffffffffffffffff851615155b15612e72576040517fe48210ec00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8573ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16118015612ec2575073ffffffffffffffffffffffffffffffffffffffff851615155b15612edf57612ed388888787613707565b91945092509050610c7c565b612eeb88888887613707565b919a90995090975095505050505050565b5f6f800000000000000000000000000000008210612f3d57612f3d7f93dafdf1000000000000000000000000000000000000000000000000000000006138a3565b5090565b80600f81900b8114612f7657612f767f93dafdf1000000000000000000000000000000000000000000000000000000006138a3565b919050565b610dc273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad6167f0000000000000000000000001f9840000000000000000000000000000000000430846001611c69565b5f612fea83836138ab565b90505f612ff78284615628565b905080156130d0576001546040517f9290398600000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff808716600483015230602483015260448201849052869216906392903986906064015f604051808303815f87803b158015613076575f80fd5b505af1158015613088573d5f803e3d5ffd5b50611ddb9250505073ffffffffffffffffffffffffffffffffffffffff86167f0000000000000000000000001f9840000000000000000000000000000000000430855f613a3d565b50505050565b610bb973ffffffffffffffffffffffffffffffffffffffff83167f0000000000000000000000001f9840000000000000000000000000000000000430846001611c69565b5f6131457f000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad6836138ab565b90505f6131528284615628565b90508015613243576002546131a09073ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad681169116613d5a565b8111156131d9576040517f2b3f50fe00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6002546132439073ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad68116917f0000000000000000000000001f984000000000000000000000000000000000049116845f613a3d565b505050565b5f805f8673ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161015801561329c575073ffffffffffffffffffffffffffffffffffffffff851615155b156132d3576040517fe48210ec00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8573ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16118015613323575073ffffffffffffffffffffffffffffffffffffffff851615155b1561333457612ed388888787613e29565b612eeb88888887613e29565b5f8273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161115613379579192915b5f6133be8573ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff166c010000000000000000000000006135cb565b90506133d2612de28483612dc789896155fc565b95945050505050565b5f805f8673ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161115801561342f575073ffffffffffffffffffffffffffffffffffffffff851615155b15613466576040517fe48210ec00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8573ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161080156134b6575073ffffffffffffffffffffffffffffffffffffffff851615155b156134c757612ed388888787613f28565b612eeb88888887613f28565b5f805f8673ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1611158015613527575073ffffffffffffffffffffffffffffffffffffffff851615155b1561355e576040517fe48210ec00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8573ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161080156135ae575073ffffffffffffffffffffffffffffffffffffffff851615155b156135bf57612ed3888887876140b7565b612eeb888888876140b7565b5f838302817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff85870982811083820303915050808411613609575f80fd5b805f0361361b57508290049050611599565b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b806fffffffffffffffffffffffffffffffff81168114612f76576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f6c6971756964697479206f766572666c6f77000000000000000000000000000060448201526064015b60405180910390fd5b5f80806fffffffffffffffffffffffffffffffff87161580613727575083155b1561373957505f915081905084613899565b8573ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161061379e576040517fc05711fa00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6137ab86888a5f6141b5565b90508085116137ba57846137bc565b805b92506137cb87898560016142e7565b91506137d982888a5f61434b565b93508573ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161015613897576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f494e56415249414e543a207371727450726963654166746572203e3d2073717260448201527f7450726963654c6f77657200000000000000000000000000000000000000000060648201526084016136fe565b505b9450945094915050565b805f5260045ffd5b5f815f036138ba57505f6113dc565b5f7f0000000000000000000000001f9840000000000000000000000000000000000473ffffffffffffffffffffffffffffffffffffffff1662fdd58e3061392a8773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1690565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff90921660048301526024820152604401602060405180830381865afa158015613996573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906139ba9190615408565b9050805f036139cc575f9150506113dc565b5f8184106139da57816139dc565b835b9050613a2273ffffffffffffffffffffffffffffffffffffffff86167f0000000000000000000000001f9840000000000000000000000000000000000430846001613a3d565b80821115610d9657610d9685613a388385615628565b6143b6565b8115611ddb578015613af6578373ffffffffffffffffffffffffffffffffffffffff1663f5298aca84613a998873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1690565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff9092166004830152602482015260448101859052606401611cd3565b73ffffffffffffffffffffffffffffffffffffffff8516613c03576040517fa584119400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff868116600483015285169063a5841194906024015f604051808303815f87803b158015613b77575f80fd5b505af1158015613b89573d5f803e3d5ffd5b505050508373ffffffffffffffffffffffffffffffffffffffff166311da60b4836040518263ffffffff1660e01b815260040160206040518083038185885af1158015613bd8573d5f803e3d5ffd5b50505050506040513d601f19601f82011682018060405250810190613bfd9190615408565b50611ddb565b6040517fa584119400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff868116600483015285169063a5841194906024015f604051808303815f87803b158015613c69575f80fd5b505af1158015613c7b573d5f803e3d5ffd5b5050505073ffffffffffffffffffffffffffffffffffffffff83163014613cc357613cbe73ffffffffffffffffffffffffffffffffffffffff8616848685614675565b613ce4565b613ce473ffffffffffffffffffffffffffffffffffffffff861685846146d1565b8373ffffffffffffffffffffffffffffffffffffffff166311da60b46040518163ffffffff1660e01b81526004016020604051808303815f875af1158015613d2e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613d529190615408565b505050505050565b5f73ffffffffffffffffffffffffffffffffffffffff8316613d94575073ffffffffffffffffffffffffffffffffffffffff8116316113dc565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff83811660048301528416906370a0823190602401602060405180830381865afa158015613dfe573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613e229190615408565b90506113dc565b5f80806fffffffffffffffffffffffffffffffff87161580613e49575083155b15613e5b57505f915081905084613899565b8573ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1610613ec0576040517fc05711fa00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f613ecd86888a5f61434b565b905080851115613f09576040517f90b2d91f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b849250613f19878985600161472c565b91506137d982888a60016141b5565b5f80806fffffffffffffffffffffffffffffffff87161580613f48575083155b15613f5a57505f915081905084613899565b8573ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1611613fbf576040517fc05711fa00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f613fcc87878a5f61434b565b9050808511613fdb5784613fdd565b805b9250613feb8789855f6142e7565b9150613ff987838a5f6141b5565b93508573ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161115613897576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f494e56415249414e543a207371727450726963654166746572203c3d2073717260448201527f745072696365557070657200000000000000000000000000000000000000000060648201526084016136fe565b5f80806fffffffffffffffffffffffffffffffff871615806140d7575083155b156140e957505f915081905084613899565b8573ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161161414e576040517fc05711fa00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f61415b87878a5f6141b5565b905080851115614197576040517f90b2d91f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8492506141a68789855f61472c565b9150613ff987838a600161434b565b5f8373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1611156141ee579293925b73ffffffffffffffffffffffffffffffffffffffff85166142155762bfc9215f526004601cfd5b7bffffffffffffffffffffffffffffffff000000000000000000000000606084901b1673ffffffffffffffffffffffffffffffffffffffff86860316836142a1578673ffffffffffffffffffffffffffffffffffffffff1661428e83838973ffffffffffffffffffffffffffffffffffffffff166135cb565b8161429b5761429b61563b565b04611510565b6115106142c583838973ffffffffffffffffffffffffffffffffffffffff16614789565b8873ffffffffffffffffffffffffffffffffffffffff16808204910615150190565b5f6fffffffffffffffffffffffffffffffff84161573ffffffffffffffffffffffffffffffffffffffff861615171561432757634f2461b85f526004601cfd5b8161433e5761433985858560016147b9565b610d93565b610d93858585600161491b565b5f73ffffffffffffffffffffffffffffffffffffffff8481169086160360ff81901d908101186c010000000000000000000000006fffffffffffffffffffffffffffffffff851661439d8184846135cb565b9350845f83858409111684019350505050949350505050565b5f6143f773ffffffffffffffffffffffffffffffffffffffff84167f0000000000000000000000001f98400000000000000000000000000000000004613d5a565b90505f8183106144075781614409565b825b9050805f036144185750505050565b7f0000000000000000000000001f9840000000000000000000000000000000000473ffffffffffffffffffffffffffffffffffffffff1663f5298aca306144888773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1690565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff90921660048301526024820152604481018490526064015f604051808303815f87803b1580156144f7575f80fd5b505af1158015614509573d5f803e3d5ffd5b5050507f000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad673ffffffffffffffffffffffffffffffffffffffff9081169086161490501561459f5760025461459a9073ffffffffffffffffffffffffffffffffffffffff868116917f0000000000000000000000001f984000000000000000000000000000000000049116845f611c69565b6130d0565b6145e273ffffffffffffffffffffffffffffffffffffffff85167f0000000000000000000000001f9840000000000000000000000000000000000430845f611c69565b6001546040517f2565887400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff868116600483015230602483015260448201849052909116906325658874906064015f604051808303815f87803b158015614659575f80fd5b505af115801561466b573d5f803e3d5ffd5b5050505050505050565b614683848484846001614a50565b6130d0576040517f5274afe700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff851660048201526024016136fe565b6146de8383836001614ae3565b613243576040517f5274afe700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff841660048201526024016136fe565b5f6fffffffffffffffffffffffffffffffff84161573ffffffffffffffffffffffffffffffffffffffff861615171561476c57634f2461b85f526004601cfd5b8161477d576143398585855f61491b565b610d938585855f6147b9565b5f6147958484846135cb565b905081806147a5576147a561563b565b838509156115995760010180611599575f80fd5b5f811561485e575f73ffffffffffffffffffffffffffffffffffffffff84111561480c57614807846c01000000000000000000000000876fffffffffffffffffffffffffffffffff166135cb565b61482c565b61482c6fffffffffffffffffffffffffffffffff8616606086901b615668565b90506148566148518273ffffffffffffffffffffffffffffffffffffffff89166156a0565b614b6b565b915050610d96565b5f73ffffffffffffffffffffffffffffffffffffffff8411156148aa576148a5846c01000000000000000000000000876fffffffffffffffffffffffffffffffff16614789565b6148d0565b6148d0606085901b6fffffffffffffffffffffffffffffffff8716808204910615150190565b90508073ffffffffffffffffffffffffffffffffffffffff8716116148fc57634323a5555f526004601cfd5b73ffffffffffffffffffffffffffffffffffffffff8616039050610d96565b5f825f0361492a575083610d96565b7bffffffffffffffffffffffffffffffff000000000000000000000000606085901b1682156149f55773ffffffffffffffffffffffffffffffffffffffff86168481029085828161497d5761497d61563b565b04036149ba578181018281106149b8576149ae838973ffffffffffffffffffffffffffffffffffffffff1683614789565b9350505050610d96565b505b5061485681856149e073ffffffffffffffffffffffffffffffffffffffff8a1683615668565b6149ea91906156a0565b808204910615150190565b73ffffffffffffffffffffffffffffffffffffffff8616848102908582041481831116614a295763f5c787f15f526004601cfd5b8082036149ae6148518473ffffffffffffffffffffffffffffffffffffffff8b1684614789565b6040517f23b872dd000000000000000000000000000000000000000000000000000000005f81815273ffffffffffffffffffffffffffffffffffffffff8781166004528616602452604485905291602083606481808c5af1925060015f51148316614ad2578383151615614ac6573d5f823e3d81fd5b5f883b113d1516831692505b604052505f60605295945050505050565b6040517fa9059cbb000000000000000000000000000000000000000000000000000000005f81815273ffffffffffffffffffffffffffffffffffffffff8616600452602485905291602083604481808b5af1925060015f51148316614b5f578383151615614b53573d5f823e3d81fd5b5f873b113d1516831692505b60405250949350505050565b8073ffffffffffffffffffffffffffffffffffffffff81168114612f7657612f767f93dafdf1000000000000000000000000000000000000000000000000000000006138a3565b5f60208284031215614bc2575f80fd5b5035919050565b73ffffffffffffffffffffffffffffffffffffffff81168114610dc2575f80fd5b5f60a08284031215614bfa575f80fd5b50919050565b5f60808284031215614bfa575f80fd5b5f8083601f840112614c20575f80fd5b50813567ffffffffffffffff811115614c37575f80fd5b602083019150836020828501011115614c4e575f80fd5b9250929050565b5f805f805f6101608688031215614c6a575f80fd5b8535614c7581614bc9565b9450614c848760208801614bea565b9350614c938760c08801614c00565b925061014086013567ffffffffffffffff811115614caf575f80fd5b614cbb88828901614c10565b969995985093965092949392505050565b5f60a08284031215614cdc575f80fd5b6115998383614bea565b5f60608284031215614bfa575f80fd5b5f805f805f6101408688031215614d0b575f80fd5b8535614d1681614bc9565b9450614d258760208801614bea565b9350614d348760c08801614ce6565b925061012086013567ffffffffffffffff811115614caf575f80fd5b5f805f805f805f6101a0888a031215614d67575f80fd5b8735614d7281614bc9565b9650614d818960208a01614bea565b9550614d908960c08a01614c00565b94506101408801359350610160880135925061018088013567ffffffffffffffff811115614dbc575f80fd5b614dc88a828b01614c10565b989b979a50959850939692959293505050565b8060020b8114610dc2575f80fd5b5f805f806101008587031215614dfd575f80fd5b8435614e0881614bc9565b9350614e178660208701614bea565b925060c0850135614e2781614bc9565b915060e0850135614e3781614ddb565b939692955090935050565b5f60208284031215614e52575f80fd5b813561159981614bc9565b5f8060208385031215614e6e575f80fd5b823567ffffffffffffffff811115614e84575f80fd5b614e9085828601614c10565b90969095509350505050565b602081525f82518060208401528060208501604085015e5f6040828501015260407fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f83011684010191505092915050565b5f805f805f806101608789031215614f05575f80fd5b8635614f1081614bc9565b9550614f1f8860208901614bea565b9450614f2e8860c08901614ce6565b9350610120870135925061014087013567ffffffffffffffff811115614f52575f80fd5b614f5e89828a01614c10565b979a9699509497509295939492505050565b5f805f805f806101208789031215614f86575f80fd5b8635614f9181614bc9565b9550614fa08860208901614bea565b945060c0870135935060e0870135925061010087013567ffffffffffffffff811115614f52575f80fd5b8151151581526101c081016020830151614fe8602084018215159052565b506040830151614ffc604084018215159052565b506060830151615010606084018215159052565b506080830151615024608084018215159052565b5060a083015161503860a084018215159052565b5060c083015161504c60c084018215159052565b5060e083015161506060e084018215159052565b5061010083015161507661010084018215159052565b5061012083015161508c61012084018215159052565b506101408301516150a261014084018215159052565b506101608301516150b861016084018215159052565b506101808301516150ce61018084018215159052565b506101a08301516150e46101a084018215159052565b5092915050565b5f805f60e084860312156150fd575f80fd5b833561510881614bc9565b92506151178560208601614bea565b915060c084013561512781614bc9565b809150509250925092565b8015158114610dc2575f80fd5b5f6020828403121561514f575f80fd5b815161159981615132565b62ffffff81168114610dc2575f80fd5b60a08101823561517981614bc9565b73ffffffffffffffffffffffffffffffffffffffff168252602083013561519f81614bc9565b73ffffffffffffffffffffffffffffffffffffffff16602083015260408301356151c88161515a565b62ffffff16604083015260608301356151e081614ddb565b60020b606083015260808301356151f681614bc9565b73ffffffffffffffffffffffffffffffffffffffff811660808401525092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b60405160e0810167ffffffffffffffff8111828210171561526957615269615219565b60405290565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff811182821017156152b6576152b6615219565b604052919050565b5f602082840312156152ce575f80fd5b815167ffffffffffffffff8111156152e4575f80fd5b8201601f810184136152f4575f80fd5b805167ffffffffffffffff81111561530e5761530e615219565b61533f60207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8401160161526f565b818152856020838501011115615353575f80fd5b8160208401602083015e5f91810160200191909152949350505050565b5f60a0828403128015615381575f80fd5b5060405160a0810167ffffffffffffffff811182821017156153a5576153a5615219565b60405282356153b381614bc9565b815260208301356153c381614bc9565b602082015260408301356153d68161515a565b604082015260608301356153e981614ddb565b606082015260808301356153fc81614bc9565b60808201529392505050565b5f60208284031215615418575f80fd5b5051919050565b805165ffffffffffff81168114612f76575f80fd5b5f60e0828403128015615445575f80fd5b5061544e615246565b825161545981614ddb565b8152602083015161546981614ddb565b6020820152604083015161547c8161515a565b6040820152606083015161548f8161515a565b60608201526080838101519082015260a080840151908201526154b460c0840161541f565b60c08201529392505050565b5f602082840312156154d0575f80fd5b813561159981615132565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f7f80000000000000000000000000000000000000000000000000000000000000008203615538576155386154db565b505f0390565b600282810b9082900b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000008112627fffff821317156113dc576113dc6154db565b5f81600f0b7fffffffffffffffffffffffffffffffff8000000000000000000000000000000081036155b3576155b36154db565b5f0392915050565b600281810b9083900b01627fffff81137fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff800000821217156113dc576113dc6154db565b73ffffffffffffffffffffffffffffffffffffffff82811682821603908111156113dc576113dc6154db565b818103818111156113dc576113dc6154db565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f8261569b577f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b500490565b808201808211156113dc576113dc6154db56fea264697066735822122031421759edcaa26c7adcc67f00e18ecfbefd853933a76194a820f87c02c2370764736f6c634300081a0033

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

0000000000000000000000001f984000000000000000000000000000000000040000000000000000000000006bece1a3d1ed2da49c76105c6f874fe1608a8e1400000000000000000000000074ed5ed72df3bff374e4c87b8ff4bdebca954abe000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad600000000000000000000000074ed5ed72df3bff374e4c87b8ff4bdebca954abe0000000000000000000000003542a74555802e5bce60655f143a5c80addda5a1

-----Decoded View---------------
Arg [0] : _poolManager (address): 0x1F98400000000000000000000000000000000004
Arg [1] : _oracle (address): 0x6bEce1A3D1ed2Da49c76105c6F874fE1608A8e14
Arg [2] : _merchantController (address): 0x74eD5ED72Df3BFF374e4C87B8ff4bdEbCA954Abe
Arg [3] : _pairToken (address): 0x078D782b760474a361dDA0AF3839290b0EF57AD6
Arg [4] : _owner (address): 0x74eD5ED72Df3BFF374e4C87B8ff4bdEbCA954Abe
Arg [5] : _merchant (address): 0x3542A74555802e5bCe60655f143A5C80ADDDA5A1

-----Encoded View---------------
6 Constructor Arguments found :
Arg [0] : 0000000000000000000000001f98400000000000000000000000000000000004
Arg [1] : 0000000000000000000000006bece1a3d1ed2da49c76105c6f874fe1608a8e14
Arg [2] : 00000000000000000000000074ed5ed72df3bff374e4c87b8ff4bdebca954abe
Arg [3] : 000000000000000000000000078d782b760474a361dda0af3839290b0ef57ad6
Arg [4] : 00000000000000000000000074ed5ed72df3bff374e4c87b8ff4bdebca954abe
Arg [5] : 0000000000000000000000003542a74555802e5bce60655f143a5c80addda5a1


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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