creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "src/PCSV3Automan.sol": {
        "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.18;\n\nimport \"./base/Automan.sol\";\nimport \"./base/SwapRouter.sol\";\n\ncontract PCSV3Automan is Automan, PCSV3SwapRouter {\n    constructor(\n        IPCSV3NonfungiblePositionManager nonfungiblePositionManager,\n        address owner_\n    ) payable Ownable(owner_) PCSV3Immutables(nonfungiblePositionManager) {}\n}\n"
      },
      "src/base/Automan.sol": {
        "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.18;\n\nimport \"solady/src/utils/SafeTransferLib.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol\";\nimport {INonfungiblePositionManager as INPM, IPCSV3NonfungiblePositionManager} from \"@aperture_finance/uni-v3-lib/src/interfaces/INonfungiblePositionManager.sol\";\nimport {LiquidityAmounts} from \"@aperture_finance/uni-v3-lib/src/LiquidityAmounts.sol\";\nimport {NPMCaller, Position} from \"@aperture_finance/uni-v3-lib/src/NPMCaller.sol\";\nimport {PoolKey} from \"@aperture_finance/uni-v3-lib/src/PoolKey.sol\";\nimport {SwapRouter} from \"./SwapRouter.sol\";\nimport {IAutoman} from \"../interfaces/IAutoman.sol\";\nimport {FullMath, OptimalSwap, TickMath, V3PoolCallee} from \"../libraries/OptimalSwap.sol\";\n\n/// @title Automation manager for UniV3-like liquidity positions with built-in optimal swap algorithm\n/// @author Aperture Finance\n/// @dev The validity of the tokens in `poolKey` and the pool contract computed from it is not checked here.\n/// However if they are invalid, pool `swap`, `burn` and `mint` will revert here or in `NonfungiblePositionManager`.\nabstract contract Automan is Ownable, SwapRouter, IAutoman {\n    using SafeTransferLib for address;\n    using FullMath for uint256;\n    using TickMath for int24;\n\n    uint256 internal constant MAX_FEE_PIPS = 1e18;\n\n    /************************************************\n     *  STATE VARIABLES\n     ***********************************************/\n\n    struct FeeConfig {\n        /// @notice The address that receives fees\n        /// @dev It is stored in the lower 160 bits of the slot\n        address feeCollector;\n        /// @notice The maximum fee percentage that can be charged for a transaction\n        /// @dev It is stored in the upper 96 bits of the slot\n        uint96 feeLimitPips;\n    }\n\n    FeeConfig public feeConfig;\n    /// @notice The address list that can perform automation\n    mapping(address => bool) public isController;\n    /// @notice The list of whitelisted routers\n    mapping(address => bool) public isWhiteListedSwapRouter;\n\n    /************************************************\n     *  ACCESS CONTROL\n     ***********************************************/\n\n    /// @dev Reverts if the caller is not a controller or the position owner\n    function checkAuthorizedForToken(uint256 tokenId) internal view {\n        if (isController[msg.sender]) return;\n        if (msg.sender != NPMCaller.ownerOf(npm, tokenId)) revert NotApproved();\n    }\n\n    /// @dev Reverts if the fee is greater than the limit\n    function checkFeeSanity(uint256 feePips) internal view {\n        if (feePips > feeConfig.feeLimitPips) revert FeeLimitExceeded();\n    }\n\n    /// @dev Reverts if the router is not whitelisted\n    /// @param swapData The address of the external router and call data\n    function checkRouter(bytes calldata swapData) internal view returns (address router) {\n        assembly {\n            router := shr(96, calldataload(swapData.offset))\n        }\n        if (!isWhiteListedSwapRouter[router]) revert NotWhitelistedRouter();\n    }\n\n    /************************************************\n     *  SETTERS\n     ***********************************************/\n\n    /// @notice Set the fee limit and collector\n    /// @param _feeConfig The new fee configuration\n    function setFeeConfig(FeeConfig calldata _feeConfig) external payable onlyOwner {\n        require(_feeConfig.feeLimitPips < MAX_FEE_PIPS);\n        require(_feeConfig.feeCollector != address(0));\n        feeConfig = _feeConfig;\n        emit FeeConfigSet(_feeConfig.feeCollector, _feeConfig.feeLimitPips);\n    }\n\n    /// @notice Set addresses that can perform automation\n    function setControllers(address[] calldata controllers, bool[] calldata statuses) external payable onlyOwner {\n        uint256 len = controllers.length;\n        require(len == statuses.length);\n        unchecked {\n            for (uint256 i; i < len; ++i) {\n                isController[controllers[i]] = statuses[i];\n            }\n        }\n        emit ControllersSet(controllers, statuses);\n    }\n\n    /// @notice Set whitelisted swap routers\n    /// @dev If `NonfungiblePositionManager` is a whitelisted router, this contract may approve arbitrary address to\n    /// spend NFTs it has been approved of.\n    /// @dev If an ERC20 token is whitelisted as a router, `transferFrom` may be called to drain tokens approved\n    /// to this contract during `mintOptimal` or `increaseLiquidityOptimal`.\n    /// @dev If a malicious router is whitelisted and called without slippage control, the caller may lose tokens in an\n    /// external swap. The router can't, however, drain ERC20 or ERC721 tokens which have been approved by other users\n    /// to this contract. Because this contract doesn't contain `transferFrom` with random `from` address like that in\n    /// SushiSwap's [`RouteProcessor2`](https://rekt.news/sushi-yoink-rekt/).\n    function setSwapRouters(address[] calldata routers, bool[] calldata statuses) external payable onlyOwner {\n        uint256 len = routers.length;\n        require(len == statuses.length);\n        unchecked {\n            for (uint256 i; i < len; ++i) {\n                address router = routers[i];\n                if (statuses[i]) {\n                    // revert if `router` is `NonfungiblePositionManager`\n                    if (router == address(npm)) revert InvalidSwapRouter();\n                    // revert if `router` is an ERC20 or not a contract\n                    //slither-disable-next-line reentrancy-no-eth\n                    (bool success, ) = router.call(abi.encodeCall(IERC20.approve, (address(npm), 0)));\n                    if (success) revert InvalidSwapRouter();\n                    isWhiteListedSwapRouter[router] = true;\n                } else {\n                    delete isWhiteListedSwapRouter[router];\n                }\n            }\n        }\n        emit SwapRoutersSet(routers, statuses);\n    }\n\n    /************************************************\n     *  GETTERS\n     ***********************************************/\n\n    /// @dev Wrapper around `INonfungiblePositionManager.positions`\n    /// @param tokenId The ID of the token that represents the position\n    /// @return Position token0 The address of the token0 for a specific pool\n    /// token1 The address of the token1 for a specific pool\n    /// feeTier The fee tier of the pool\n    /// tickLower The lower end of the tick range for the position\n    /// tickUpper The higher end of the tick range for the position\n    /// liquidity The liquidity of the position\n    function _positions(uint256 tokenId) internal view returns (Position memory) {\n        return NPMCaller.positions(npm, tokenId);\n    }\n\n    /// @notice Cast `Position` to `PoolKey`\n    /// @dev Solidity assigns free memory to structs when they are declared, which is unnecessary in this case.\n    /// But there is nothing we can do unless the memory of a struct is only assigned when using the `new` keyword.\n    function castPoolKey(Position memory pos) internal pure returns (PoolKey memory poolKey) {\n        assembly (\"memory-safe\") {\n            // `PoolKey` is a subset of `Position`\n            poolKey := pos\n        }\n    }\n\n    /// @notice Cast `MintParams` to `PoolKey`\n    function castPoolKey(INPM.MintParams memory params) internal pure returns (PoolKey memory poolKey) {\n        assembly (\"memory-safe\") {\n            // `PoolKey` is a subset of `MintParams`\n            poolKey := params\n        }\n    }\n\n    /// @inheritdoc IAutoman\n    function getOptimalSwap(\n        V3PoolCallee pool,\n        int24 tickLower,\n        int24 tickUpper,\n        uint256 amount0Desired,\n        uint256 amount1Desired\n    ) external view returns (uint256 amountIn, uint256 amountOut, bool zeroForOne, uint160 sqrtPriceX96) {\n        return OptimalSwap.getOptimalSwap(pool, tickLower, tickUpper, amount0Desired, amount1Desired);\n    }\n\n    /************************************************\n     *  INTERNAL ACTIONS\n     ***********************************************/\n\n    /// @dev Make a swap using a v3 pool directly or through an external router\n    /// @param poolKey The pool key containing the token addresses and fee tier\n    /// @param amountIn The amount of token to be swapped\n    /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0\n    /// @param swapData The address of the external router and call data\n    /// @return amountOut The amount of token received after swap\n    function _swap(\n        PoolKey memory poolKey,\n        uint256 amountIn,\n        bool zeroForOne,\n        bytes calldata swapData\n    ) private returns (uint256 amountOut) {\n        if (swapData.length == 0) {\n            amountOut = _poolSwap(poolKey, computeAddressSorted(poolKey), amountIn, zeroForOne);\n        } else {\n            address router = checkRouter(swapData);\n            amountOut = _routerSwap(poolKey, router, zeroForOne, swapData);\n        }\n    }\n\n    /// @dev Swap tokens to the optimal ratio to add liquidity and approve npm to spend\n    /// @param poolKey The pool key containing the token addresses and fee tier\n    /// @param tickLower The lower tick of the position in which to add liquidity\n    /// @param tickUpper The upper tick of the position in which to add liquidity\n    /// @param amount0Desired The desired amount of token0 to be spent\n    /// @param amount1Desired The desired amount of token1 to be spent\n    /// @return amount0 The amount of token0 after swap\n    /// @return amount1 The amount of token1 after swap\n    function _optimalSwap(\n        PoolKey memory poolKey,\n        int24 tickLower,\n        int24 tickUpper,\n        uint256 amount0Desired,\n        uint256 amount1Desired,\n        bytes calldata swapData\n    ) private returns (uint256 amount0, uint256 amount1) {\n        if (swapData.length == 0) {\n            // Swap with the v3 pool directly\n            (amount0, amount1) = _optimalSwapWithPool(poolKey, tickLower, tickUpper, amount0Desired, amount1Desired);\n        } else {\n            // Swap with a whitelisted router\n            address router = checkRouter(swapData);\n            (amount0, amount1) = _optimalSwapWithRouter(\n                poolKey,\n                router,\n                tickLower,\n                tickUpper,\n                amount0Desired,\n                amount1Desired,\n                swapData\n            );\n        }\n        // Approve the v3 position manager to spend the tokens\n        if (amount0 != 0) poolKey.token0.safeApprove(address(npm), amount0);\n        if (amount1 != 0) poolKey.token1.safeApprove(address(npm), amount1);\n    }\n\n    /// @notice Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens\n    /// must be collected first.\n    /// @param tokenId The ID of the token that is being burned\n    function _burn(uint256 tokenId) private {\n        return NPMCaller.burn(npm, tokenId);\n    }\n\n    /// @notice Collects tokens owed for a given token ID to this contract\n    /// @param tokenId The ID of the NFT for which tokens are being collected\n    /// @return amount0 The amount of fees collected in token0\n    /// @return amount1 The amount of fees collected in token1\n    function _collect(uint256 tokenId) private returns (uint256 amount0, uint256 amount1) {\n        return NPMCaller.collect(npm, tokenId, address(this));\n    }\n\n    /// @dev Internal function to mint and refund\n    function _mint(\n        INPM.MintParams memory params\n    ) private returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1) {\n        (tokenId, liquidity, amount0, amount1) = NPMCaller.mint(npm, params);\n        address recipient = params.recipient;\n        uint256 amount0Desired = params.amount0Desired;\n        uint256 amount1Desired = params.amount1Desired;\n        // Refund any surplus value to the recipient\n        unchecked {\n            if (amount0 < amount0Desired) {\n                address token0 = params.token0;\n                token0.safeApprove(address(npm), 0);\n                refund(token0, recipient, amount0Desired - amount0);\n            }\n            if (amount1 < amount1Desired) {\n                address token1 = params.token1;\n                token1.safeApprove(address(npm), 0);\n                refund(token1, recipient, amount1Desired - amount1);\n            }\n        }\n    }\n\n    /// @dev Internal increase liquidity abstraction\n    function _increaseLiquidity(\n        INPM.IncreaseLiquidityParams memory params,\n        address token0,\n        address token1\n    ) private returns (uint128 liquidity, uint256 amount0, uint256 amount1) {\n        (liquidity, amount0, amount1) = NPMCaller.increaseLiquidity(npm, params);\n        uint256 amount0Desired = params.amount0Desired;\n        uint256 amount1Desired = params.amount1Desired;\n        // Refund any surplus value to the caller\n        unchecked {\n            if (amount0 < amount0Desired) {\n                token0.safeApprove(address(npm), 0);\n                refund(token0, msg.sender, amount0Desired - amount0);\n            }\n            if (amount1 < amount1Desired) {\n                token1.safeApprove(address(npm), 0);\n                refund(token1, msg.sender, amount1Desired - amount1);\n            }\n        }\n    }\n\n    /// @dev Collect the tokens owed, deduct transaction fees in both tokens and send it to the fee collector\n    /// @param amount0Principal The principal amount of token0 used to calculate the fee\n    /// @param amount1Principal The principal amount of token1 used to calculate the fee\n    /// @return amount0 The amount of token0 after fees\n    /// @return amount1 The amount of token1 after fees\n    function _collectMinusFees(\n        uint256 tokenId,\n        address token0,\n        address token1,\n        uint256 amount0Principal,\n        uint256 amount1Principal,\n        uint256 feePips\n    ) private returns (uint256, uint256) {\n        // Collect the tokens owed then deduct transaction fees\n        (uint256 amount0Collected, uint256 amount1Collected) = _collect(tokenId);\n        // Calculations outside mulDiv won't overflow.\n        unchecked {\n            uint256 fee0 = amount0Principal.mulDiv(feePips, MAX_FEE_PIPS);\n            uint256 fee1 = amount1Principal.mulDiv(feePips, MAX_FEE_PIPS);\n            if (amount0Collected < fee0 || amount1Collected < fee1) revert InsufficientAmount();\n            address _feeCollector = feeConfig.feeCollector;\n            if (fee0 != 0) {\n                amount0Collected -= fee0;\n                refund(token0, _feeCollector, fee0);\n            }\n            if (fee1 != 0) {\n                amount1Collected -= fee1;\n                refund(token1, _feeCollector, fee1);\n            }\n        }\n        return (amount0Collected, amount1Collected);\n    }\n\n    /// @dev Collect the tokens owed, deduct transaction fees in both tokens and send it to the fee collector\n    /// @param amount0Delta The change in token0 used to calculate the fee\n    /// @param amount1Delta The change in token1 used to calculate the fee\n    /// @param liquidityDelta The change in liquidity used to calculate the principal\n    /// @return amount0 The amount of token0 after fees\n    /// @return amount1 The amount of token1 after fees\n    function _collectMinusFees(\n        Position memory pos,\n        uint256 tokenId,\n        uint256 amount0Delta,\n        uint256 amount1Delta,\n        uint128 liquidityDelta,\n        uint256 feePips\n    ) private returns (uint256, uint256) {\n        (uint256 amount0Collected, uint256 amount1Collected) = _collect(tokenId);\n        // Calculations outside mulDiv won't overflow.\n        unchecked {\n            uint256 fee0;\n            uint256 fee1;\n            {\n                uint256 numerator = feePips * pos.liquidity;\n                uint256 denominator = MAX_FEE_PIPS * liquidityDelta;\n                fee0 = amount0Delta.mulDiv(numerator, denominator);\n                fee1 = amount1Delta.mulDiv(numerator, denominator);\n            }\n            if (amount0Collected < fee0 || amount1Collected < fee1) revert InsufficientAmount();\n            address _feeCollector = feeConfig.feeCollector;\n            if (fee0 != 0) {\n                amount0Collected -= fee0;\n                refund(pos.token0, _feeCollector, fee0);\n            }\n            if (fee1 != 0) {\n                amount1Collected -= fee1;\n                refund(pos.token1, _feeCollector, fee1);\n            }\n        }\n        return (amount0Collected, amount1Collected);\n    }\n\n    /// @dev Internal decrease liquidity abstraction\n    function _decreaseLiquidity(\n        INPM.DecreaseLiquidityParams memory params,\n        uint256 feePips\n    ) private returns (uint256 amount0, uint256 amount1) {\n        uint256 tokenId = params.tokenId;\n        Position memory pos = _positions(tokenId);\n        // Slippage check is delegated to `NonfungiblePositionManager` via `DecreaseLiquidityParams`.\n        (uint256 amount0Delta, uint256 amount1Delta) = NPMCaller.decreaseLiquidity(npm, params);\n        // Collect the tokens owed and deduct transaction fees\n        (amount0, amount1) = _collectMinusFees(pos, tokenId, amount0Delta, amount1Delta, params.liquidity, feePips);\n        // Send the remaining amounts to the position owner\n        address owner = NPMCaller.ownerOf(npm, tokenId);\n        if (amount0 != 0) refund(pos.token0, owner, amount0);\n        if (amount1 != 0) refund(pos.token1, owner, amount1);\n    }\n\n    /// @dev Decrease liquidity and swap the tokens to a single token\n    function _decreaseCollectSingle(\n        INPM.DecreaseLiquidityParams memory params,\n        Position memory pos,\n        bool zeroForOne,\n        uint256 feePips,\n        bytes calldata swapData\n    ) private returns (uint256 amount) {\n        uint256 amountMin;\n        // Slippage check is done here instead of `NonfungiblePositionManager`\n        if (zeroForOne) {\n            amountMin = params.amount1Min;\n            params.amount1Min = 0;\n        } else {\n            amountMin = params.amount0Min;\n            params.amount0Min = 0;\n        }\n        // Reuse the `amount0Min` and `amount1Min` fields to avoid stack too deep error\n        (params.amount0Min, params.amount1Min) = NPMCaller.decreaseLiquidity(npm, params);\n        uint256 tokenId = params.tokenId;\n        // Collect the tokens owed and deduct transaction fees\n        (uint256 amount0, uint256 amount1) = _collectMinusFees(\n            pos,\n            tokenId,\n            params.amount0Min,\n            params.amount1Min,\n            params.liquidity,\n            feePips\n        );\n        // Swap to the desired token and send it to the position owner\n        // It is assumed that the swap is `exactIn` and all of the input tokens are consumed.\n        unchecked {\n            if (zeroForOne) {\n                amount = amount1 + _swap(castPoolKey(pos), amount0, true, swapData);\n                refund(pos.token1, NPMCaller.ownerOf(npm, tokenId), amount);\n            } else {\n                amount = amount0 + _swap(castPoolKey(pos), amount1, false, swapData);\n                refund(pos.token0, NPMCaller.ownerOf(npm, tokenId), amount);\n            }\n        }\n        if (amount < amountMin) revert InsufficientAmount();\n    }\n\n    /// @dev Internal decrease liquidity abstraction\n    function _decreaseLiquiditySingle(\n        INPM.DecreaseLiquidityParams memory params,\n        bool zeroForOne,\n        uint256 feePips,\n        bytes calldata swapData\n    ) private returns (uint256 amount) {\n        Position memory pos = _positions(params.tokenId);\n        amount = _decreaseCollectSingle(params, pos, zeroForOne, feePips, swapData);\n    }\n\n    /// @dev Internal function to remove liquidity and collect tokens to this contract minus fees\n    function _removeAndCollect(\n        INPM.DecreaseLiquidityParams memory params,\n        uint256 feePips\n    ) private returns (address token0, address token1, uint256 amount0, uint256 amount1) {\n        uint256 tokenId = params.tokenId;\n        Position memory pos = _positions(tokenId);\n        token0 = pos.token0;\n        token1 = pos.token1;\n        // Update `params.liquidity` to the current liquidity\n        params.liquidity = pos.liquidity;\n        (uint256 amount0Principal, uint256 amount1Principal) = NPMCaller.decreaseLiquidity(npm, params);\n        // Collect the tokens owed and deduct transaction fees\n        (amount0, amount1) = _collectMinusFees(tokenId, token0, token1, amount0Principal, amount1Principal, feePips);\n    }\n\n    /// @dev Internal remove liquidity abstraction\n    function _removeLiquidity(\n        INPM.DecreaseLiquidityParams memory params,\n        uint256 feePips\n    ) private returns (uint256, uint256) {\n        uint256 tokenId = params.tokenId;\n        (address token0, address token1, uint256 amount0, uint256 amount1) = _removeAndCollect(params, feePips);\n        address owner = NPMCaller.ownerOf(npm, tokenId);\n        if (amount0 != 0) refund(token0, owner, amount0);\n        if (amount1 != 0) refund(token1, owner, amount1);\n        _burn(tokenId);\n        return (amount0, amount1);\n    }\n\n    /// @dev Internal function to remove liquidity and swap to a single token\n    function _removeLiquiditySingle(\n        INPM.DecreaseLiquidityParams memory params,\n        bool zeroForOne,\n        uint256 feePips,\n        bytes calldata swapData\n    ) private returns (uint256 amount) {\n        uint256 tokenId = params.tokenId;\n        Position memory pos = _positions(tokenId);\n        // Update `params.liquidity` to the current liquidity\n        params.liquidity = pos.liquidity;\n        amount = _decreaseCollectSingle(params, pos, zeroForOne, feePips, swapData);\n        _burn(tokenId);\n    }\n\n    /// @dev Internal reinvest abstraction\n    function _reinvest(\n        INPM.IncreaseLiquidityParams memory params,\n        uint256 feePips,\n        bytes calldata swapData\n    ) private returns (uint128, uint256, uint256) {\n        Position memory pos = _positions(params.tokenId);\n        PoolKey memory poolKey = castPoolKey(pos);\n        uint256 amount0;\n        uint256 amount1;\n        {\n            // Calculate the principal amounts\n            (uint160 sqrtPriceX96, ) = V3PoolCallee.wrap(computeAddressSorted(poolKey)).sqrtPriceX96AndTick();\n            (amount0, amount1) = LiquidityAmounts.getAmountsForLiquidity(\n                sqrtPriceX96,\n                pos.tickLower.getSqrtRatioAtTick(),\n                pos.tickUpper.getSqrtRatioAtTick(),\n                pos.liquidity\n            );\n        }\n        // Collect the tokens owed then deduct transaction fees\n        (amount0, amount1) = _collectMinusFees(params.tokenId, pos.token0, pos.token1, amount0, amount1, feePips);\n        // Perform optimal swap and update `params`\n        (params.amount0Desired, params.amount1Desired) = _optimalSwap(\n            poolKey,\n            pos.tickLower,\n            pos.tickUpper,\n            amount0,\n            amount1,\n            swapData\n        );\n        return _increaseLiquidity(params, pos.token0, pos.token1);\n    }\n\n    /// @dev Internal rebalance abstraction\n    function _rebalance(\n        INPM.MintParams memory params,\n        uint256 tokenId,\n        uint256 feePips,\n        bytes calldata swapData\n    ) private returns (uint256 newTokenId, uint128 liquidity, uint256 amount0, uint256 amount1) {\n        // Remove liquidity and collect the tokens owed\n        (, , amount0, amount1) = _removeAndCollect(\n            INPM.DecreaseLiquidityParams({\n                tokenId: tokenId,\n                liquidity: 0, // Updated in `_removeAndCollect`\n                amount0Min: 0,\n                amount1Min: 0,\n                deadline: params.deadline\n            }),\n            feePips\n        );\n        // Update `recipient` to the current owner\n        params.recipient = NPMCaller.ownerOf(npm, tokenId);\n        // Perform optimal swap\n        (params.amount0Desired, params.amount1Desired) = _optimalSwap(\n            castPoolKey(params),\n            params.tickLower,\n            params.tickUpper,\n            amount0,\n            amount1,\n            swapData\n        );\n        // `token0` and `token1` are assumed to be the same as the old position while fee tier may change.\n        (newTokenId, liquidity, amount0, amount1) = _mint(params);\n    }\n\n    /// @notice Approve of a specific token ID for spending by this contract via signature if necessary\n    /// @param tokenId The ID of the token that is being approved for spending\n    /// @param deadline The deadline timestamp by which the call must be mined for the approve to work\n    /// @param v The recovery byte of the signature\n    /// @param r Half of the ECDSA signature pair\n    /// @param s Half of the ECDSA signature pair\n    function selfPermitIfNecessary(uint256 tokenId, uint256 deadline, uint8 v, bytes32 r, bytes32 s) internal {\n        if (NPMCaller.getApproved(npm, tokenId) == address(this)) return;\n        if (NPMCaller.isApprovedForAll(npm, NPMCaller.ownerOf(npm, tokenId), address(this))) return;\n        NPMCaller.permit(npm, address(this), tokenId, deadline, v, r, s);\n    }\n\n    /************************************************\n     *  LIQUIDITY MANAGEMENT\n     ***********************************************/\n\n    /// @inheritdoc IAutoman\n    function mint(\n        INPM.MintParams memory params\n    ) external payable returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1) {\n        pullAndApprove(params.token0, params.token1, params.amount0Desired, params.amount1Desired);\n        (tokenId, liquidity, amount0, amount1) = _mint(params);\n        emit Mint(tokenId);\n    }\n\n    /// @inheritdoc IAutoman\n    function mintOptimal(\n        INPM.MintParams memory params,\n        bytes calldata swapData\n    ) external payable returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1) {\n        PoolKey memory poolKey = castPoolKey(params);\n        uint256 amount0Desired = params.amount0Desired;\n        uint256 amount1Desired = params.amount1Desired;\n        // Pull tokens\n        if (amount0Desired != 0) pay(poolKey.token0, msg.sender, address(this), amount0Desired);\n        if (amount1Desired != 0) pay(poolKey.token1, msg.sender, address(this), amount1Desired);\n        // Perform optimal swap after which the amounts desired are updated\n        (params.amount0Desired, params.amount1Desired) = _optimalSwap(\n            poolKey,\n            params.tickLower,\n            params.tickUpper,\n            amount0Desired,\n            amount1Desired,\n            swapData\n        );\n        (tokenId, liquidity, amount0, amount1) = _mint(params);\n        emit Mint(tokenId);\n    }\n\n    /// @inheritdoc IAutoman\n    function increaseLiquidity(\n        INPM.IncreaseLiquidityParams memory params\n    ) external payable returns (uint128 liquidity, uint256 amount0, uint256 amount1) {\n        uint256 tokenId = params.tokenId;\n        Position memory pos = _positions(tokenId);\n        address token0 = pos.token0;\n        address token1 = pos.token1;\n        pullAndApprove(token0, token1, params.amount0Desired, params.amount1Desired);\n        (liquidity, amount0, amount1) = _increaseLiquidity(params, token0, token1);\n        emit IncreaseLiquidity(tokenId);\n    }\n\n    /// @inheritdoc IAutoman\n    function increaseLiquidityOptimal(\n        INPM.IncreaseLiquidityParams memory params,\n        bytes calldata swapData\n    ) external payable returns (uint128 liquidity, uint256 amount0, uint256 amount1) {\n        Position memory pos = _positions(params.tokenId);\n        address token0 = pos.token0;\n        address token1 = pos.token1;\n        uint256 amount0Desired = params.amount0Desired;\n        uint256 amount1Desired = params.amount1Desired;\n        // Pull tokens\n        if (amount0Desired != 0) pay(token0, msg.sender, address(this), amount0Desired);\n        if (amount1Desired != 0) pay(token1, msg.sender, address(this), amount1Desired);\n        // Perform optimal swap after which the amounts desired are updated\n        (params.amount0Desired, params.amount1Desired) = _optimalSwap(\n            castPoolKey(pos),\n            pos.tickLower,\n            pos.tickUpper,\n            amount0Desired,\n            amount1Desired,\n            swapData\n        );\n        (liquidity, amount0, amount1) = _increaseLiquidity(params, token0, token1);\n        emit IncreaseLiquidity(params.tokenId);\n    }\n\n    /// @inheritdoc IAutoman\n    function decreaseLiquidity(\n        INPM.DecreaseLiquidityParams memory params,\n        uint256 feePips\n    ) external returns (uint256 amount0, uint256 amount1) {\n        checkFeeSanity(feePips);\n        uint256 tokenId = params.tokenId;\n        checkAuthorizedForToken(tokenId);\n        (amount0, amount1) = _decreaseLiquidity(params, feePips);\n        emit DecreaseLiquidity(tokenId);\n    }\n\n    /// @inheritdoc IAutoman\n    function decreaseLiquidity(\n        INPM.DecreaseLiquidityParams memory params,\n        uint256 feePips,\n        uint256 permitDeadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external returns (uint256 amount0, uint256 amount1) {\n        checkFeeSanity(feePips);\n        uint256 tokenId = params.tokenId;\n        checkAuthorizedForToken(tokenId);\n        selfPermitIfNecessary(tokenId, permitDeadline, v, r, s);\n        (amount0, amount1) = _decreaseLiquidity(params, feePips);\n        emit DecreaseLiquidity(tokenId);\n    }\n\n    /// @inheritdoc IAutoman\n    function decreaseLiquiditySingle(\n        INPM.DecreaseLiquidityParams memory params,\n        bool zeroForOne,\n        uint256 feePips,\n        bytes calldata swapData\n    ) external returns (uint256 amount) {\n        checkFeeSanity(feePips);\n        uint256 tokenId = params.tokenId;\n        checkAuthorizedForToken(tokenId);\n        amount = _decreaseLiquiditySingle(params, zeroForOne, feePips, swapData);\n        emit DecreaseLiquidity(tokenId);\n    }\n\n    /// @inheritdoc IAutoman\n    function decreaseLiquiditySingle(\n        INPM.DecreaseLiquidityParams memory params,\n        bool zeroForOne,\n        uint256 feePips,\n        bytes calldata swapData,\n        uint256 permitDeadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external returns (uint256 amount) {\n        checkFeeSanity(feePips);\n        uint256 tokenId = params.tokenId;\n        checkAuthorizedForToken(tokenId);\n        selfPermitIfNecessary(tokenId, permitDeadline, v, r, s);\n        amount = _decreaseLiquiditySingle(params, zeroForOne, feePips, swapData);\n        emit DecreaseLiquidity(tokenId);\n    }\n\n    /// @inheritdoc IAutoman\n    function removeLiquidity(\n        INPM.DecreaseLiquidityParams memory params,\n        uint256 feePips\n    ) external returns (uint256 amount0, uint256 amount1) {\n        checkFeeSanity(feePips);\n        uint256 tokenId = params.tokenId;\n        checkAuthorizedForToken(tokenId);\n        (amount0, amount1) = _removeLiquidity(params, feePips);\n        emit RemoveLiquidity(tokenId);\n    }\n\n    /// @inheritdoc IAutoman\n    function removeLiquidity(\n        INPM.DecreaseLiquidityParams memory params,\n        uint256 feePips,\n        uint256 permitDeadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external returns (uint256 amount0, uint256 amount1) {\n        checkFeeSanity(feePips);\n        uint256 tokenId = params.tokenId;\n        checkAuthorizedForToken(tokenId);\n        selfPermitIfNecessary(tokenId, permitDeadline, v, r, s);\n        (amount0, amount1) = _removeLiquidity(params, feePips);\n        emit RemoveLiquidity(tokenId);\n    }\n\n    /// @inheritdoc IAutoman\n    function removeLiquiditySingle(\n        INPM.DecreaseLiquidityParams memory params,\n        bool zeroForOne,\n        uint256 feePips,\n        bytes calldata swapData\n    ) external returns (uint256 amount) {\n        checkFeeSanity(feePips);\n        uint256 tokenId = params.tokenId;\n        checkAuthorizedForToken(tokenId);\n        amount = _removeLiquiditySingle(params, zeroForOne, feePips, swapData);\n        emit RemoveLiquidity(tokenId);\n    }\n\n    /// @inheritdoc IAutoman\n    function removeLiquiditySingle(\n        INPM.DecreaseLiquidityParams memory params,\n        bool zeroForOne,\n        uint256 feePips,\n        bytes calldata swapData,\n        uint256 permitDeadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external returns (uint256 amount) {\n        checkFeeSanity(feePips);\n        uint256 tokenId = params.tokenId;\n        checkAuthorizedForToken(tokenId);\n        selfPermitIfNecessary(tokenId, permitDeadline, v, r, s);\n        amount = _removeLiquiditySingle(params, zeroForOne, feePips, swapData);\n        emit RemoveLiquidity(tokenId);\n    }\n\n    /// @inheritdoc IAutoman\n    function reinvest(\n        INPM.IncreaseLiquidityParams memory params,\n        uint256 feePips,\n        bytes calldata swapData\n    ) external returns (uint128 liquidity, uint256 amount0, uint256 amount1) {\n        checkFeeSanity(feePips);\n        uint256 tokenId = params.tokenId;\n        checkAuthorizedForToken(tokenId);\n        (liquidity, amount0, amount1) = _reinvest(params, feePips, swapData);\n        emit Reinvest(tokenId);\n    }\n\n    /// @inheritdoc IAutoman\n    function reinvest(\n        INPM.IncreaseLiquidityParams memory params,\n        uint256 feePips,\n        bytes calldata swapData,\n        uint256 permitDeadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external returns (uint128 liquidity, uint256 amount0, uint256 amount1) {\n        checkFeeSanity(feePips);\n        uint256 tokenId = params.tokenId;\n        checkAuthorizedForToken(tokenId);\n        selfPermitIfNecessary(tokenId, permitDeadline, v, r, s);\n        (liquidity, amount0, amount1) = _reinvest(params, feePips, swapData);\n        emit Reinvest(tokenId);\n    }\n\n    /// @inheritdoc IAutoman\n    function rebalance(\n        INPM.MintParams memory params,\n        uint256 tokenId,\n        uint256 feePips,\n        bytes calldata swapData\n    ) external returns (uint256 newTokenId, uint128 liquidity, uint256 amount0, uint256 amount1) {\n        checkFeeSanity(feePips);\n        checkAuthorizedForToken(tokenId);\n        (newTokenId, liquidity, amount0, amount1) = _rebalance(params, tokenId, feePips, swapData);\n        emit Rebalance(newTokenId);\n    }\n\n    /// @inheritdoc IAutoman\n    function rebalance(\n        INPM.MintParams memory params,\n        uint256 tokenId,\n        uint256 feePips,\n        bytes calldata swapData,\n        uint256 permitDeadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external returns (uint256 newTokenId, uint128 liquidity, uint256 amount0, uint256 amount1) {\n        checkFeeSanity(feePips);\n        checkAuthorizedForToken(tokenId);\n        selfPermitIfNecessary(tokenId, permitDeadline, v, r, s);\n        (newTokenId, liquidity, amount0, amount1) = _rebalance(params, tokenId, feePips, swapData);\n        emit Rebalance(newTokenId);\n    }\n}\n"
      },
      "src/base/SwapRouter.sol": {
        "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.18;\n\nimport \"solady/src/utils/SafeTransferLib.sol\";\nimport {ERC20Callee} from \"../libraries/ERC20Caller.sol\";\nimport {INonfungiblePositionManager} from \"@aperture_finance/uni-v3-lib/src/interfaces/INonfungiblePositionManager.sol\";\nimport {PoolKey} from \"@aperture_finance/uni-v3-lib/src/PoolKey.sol\";\nimport {PoolAddress} from \"@aperture_finance/uni-v3-lib/src/PoolAddress.sol\";\nimport {PoolAddressPancakeSwapV3} from \"@aperture_finance/uni-v3-lib/src/PoolAddressPancakeSwapV3.sol\";\nimport {TernaryLib} from \"@aperture_finance/uni-v3-lib/src/TernaryLib.sol\";\nimport {OptimalSwap, TickMath, V3PoolCallee} from \"../libraries/OptimalSwap.sol\";\nimport {PCSV3Immutables, UniV3Immutables} from \"./Immutables.sol\";\nimport {Payments} from \"./Payments.sol\";\nimport \"./Callback.sol\";\n\n/// @title Optimal Swap Router\n/// @author Aperture Finance\n/// @dev This router swaps through an aggregator to get to approximately the optimal ratio to add liquidity in a UniV3-style\n/// pool, then swaps the tokens to the optimal ratio to add liquidity in the same pool.\nabstract contract SwapRouter is Payments {\n    using SafeTransferLib for address;\n    using TernaryLib for bool;\n    using TickMath for int24;\n\n    /// @dev Literal numbers used in sqrtPriceLimitX96 = zeroForOne ? MIN_SQRT_RATIO + 1 : MAX_SQRT_RATIO - 1\n    /// = (MAX_SQRT_RATIO - 1) ^ ((MIN_SQRT_RATIO + 1 ^ MAX_SQRT_RATIO - 1) * zeroForOne)\n    uint160 internal constant MAX_SQRT_RATIO_LESS_ONE = 1461446703485210103287273052203988822378723970342 - 1;\n    /// @dev MIN_SQRT_RATIO + 1 ^ MAX_SQRT_RATIO - 1\n    uint160 internal constant XOR_SQRT_RATIO =\n        (4295128739 + 1) ^ (1461446703485210103287273052203988822378723970342 - 1);\n\n    /// @notice Deterministically computes the pool address given the pool key\n    /// @param poolKey The pool key\n    /// @return pool The contract address of the pool\n    function computeAddressSorted(PoolKey memory poolKey) internal view virtual returns (address pool);\n\n    /// @dev Make a direct `exactIn` pool swap\n    /// @param poolKey The pool key containing the token addresses and fee tier\n    /// @param pool The address of the pool\n    /// @param amountIn The amount of token to be swapped\n    /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0\n    /// @return amountOut The amount of token received after swap\n    function _poolSwap(\n        PoolKey memory poolKey,\n        address pool,\n        uint256 amountIn,\n        bool zeroForOne\n    ) internal returns (uint256 amountOut) {\n        if (amountIn != 0) {\n            uint256 wordBeforePoolKey;\n            bytes memory data;\n            assembly (\"memory-safe\") {\n                // Equivalent to `data = abi.encode(poolKey)`\n                data := sub(poolKey, 0x20)\n                wordBeforePoolKey := mload(data)\n                mstore(data, 0x60)\n            }\n            uint160 sqrtPriceLimitX96;\n            // Equivalent to `sqrtPriceLimitX96 = zeroForOne ? MIN_SQRT_RATIO + 1 : MAX_SQRT_RATIO - 1`\n            assembly {\n                sqrtPriceLimitX96 := xor(MAX_SQRT_RATIO_LESS_ONE, mul(XOR_SQRT_RATIO, zeroForOne))\n            }\n            (int256 amount0Delta, int256 amount1Delta) = V3PoolCallee.wrap(pool).swap(\n                address(this),\n                zeroForOne,\n                int256(amountIn),\n                sqrtPriceLimitX96,\n                data\n            );\n            unchecked {\n                amountOut = 0 - zeroForOne.ternary(uint256(amount1Delta), uint256(amount0Delta));\n            }\n            assembly (\"memory-safe\") {\n                // Restore the memory word before `poolKey`\n                mstore(data, wordBeforePoolKey)\n            }\n        }\n    }\n\n    /// @dev Make an `exactIn` swap through a whitelisted external router\n    /// @param poolKey The pool key containing the token addresses and fee tier\n    /// @param router The address of the external router\n    /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0\n    /// @param swapData The address of the external router and call data, not abi-encoded\n    /// @return amountOut The amount of token received after swap\n    function _routerSwap(\n        PoolKey memory poolKey,\n        address router,\n        bool zeroForOne,\n        bytes calldata swapData\n    ) internal returns (uint256 amountOut) {\n        (address tokenIn, address tokenOut) = zeroForOne.switchIf(poolKey.token1, poolKey.token0);\n        uint256 balanceBefore = ERC20Callee.wrap(tokenOut).balanceOf(address(this));\n        // Approve `router` to spend `tokenIn`\n        tokenIn.safeApprove(router, type(uint256).max);\n        /*\n            If `swapData` is encoded as `abi.encode(router, data)`, the memory layout will be:\n            0x00         : 0x20         : 0x40         : 0x60         : 0x80\n            total length : router       : 0x40 (offset): data length  : data\n            Instead, we encode it as:\n            ```\n            bytes memory swapData = abi.encodePacked(router, data);\n            ```\n            So the memory layout will be:\n            0x00         : 0x20         : 0x34\n            total length : router       : data\n            To decode it in memory, one can use:\n            ```\n            bytes memory data;\n            assembly {\n                router := shr(96, mload(add(swapData, 0x20)))\n                data := add(swapData, 0x14)\n                mstore(data, sub(mload(swapData), 0x14))\n            }\n            ```\n            knowing that `data.length == swapData.length - 20`.\n        */\n        assembly (\"memory-safe\") {\n            let fmp := mload(0x40)\n            // Strip the first 20 bytes of `swapData` which is the router address.\n            let calldataLength := sub(swapData.length, 20)\n            calldatacopy(fmp, add(swapData.offset, 20), calldataLength)\n            // Ignore the return data unless an error occurs\n            if iszero(call(gas(), router, 0, fmp, calldataLength, 0, 0)) {\n                returndatacopy(0, 0, returndatasize())\n                // Bubble up the revert reason.\n                revert(0, returndatasize())\n            }\n        }\n        // Reset approval\n        tokenIn.safeApprove(router, 0);\n        uint256 balanceAfter = ERC20Callee.wrap(tokenOut).balanceOf(address(this));\n        unchecked {\n            amountOut = balanceAfter - balanceBefore;\n        }\n    }\n\n    /// @dev Swap tokens to the optimal ratio to add liquidity in the same pool\n    /// @param poolKey The pool key containing the token addresses and fee tier\n    /// @param tickLower The lower tick of the position in which to add liquidity\n    /// @param tickUpper The upper tick of the position in which to add liquidity\n    /// @param amount0Desired The desired amount of token0 to be spent\n    /// @param amount1Desired The desired amount of token1 to be spent\n    /// @return amount0 The amount of token0 after swap\n    /// @return amount1 The amount of token1 after swap\n    function _optimalSwapWithPool(\n        PoolKey memory poolKey,\n        int24 tickLower,\n        int24 tickUpper,\n        uint256 amount0Desired,\n        uint256 amount1Desired\n    ) internal returns (uint256 amount0, uint256 amount1) {\n        address pool = computeAddressSorted(poolKey);\n        (uint256 amountIn, , bool zeroForOne, ) = OptimalSwap.getOptimalSwap(\n            V3PoolCallee.wrap(pool),\n            tickLower,\n            tickUpper,\n            amount0Desired,\n            amount1Desired\n        );\n        uint256 amountOut = _poolSwap(poolKey, pool, amountIn, zeroForOne);\n        unchecked {\n            // amount0 = amount0Desired + zeroForOne ? - amountIn : amountOut\n            // amount1 = amount1Desired + zeroForOne ? amountOut : - amountIn\n            (amount0, amount1) = zeroForOne.switchIf(amountOut, 0 - amountIn);\n            amount0 += amount0Desired;\n            amount1 += amount1Desired;\n        }\n    }\n\n    /// @dev Swap tokens to the optimal ratio to add liquidity with an external router\n    /// @param poolKey The pool key containing the token addresses and fee tier\n    /// @param router The address of the external router\n    /// @param tickLower The lower tick of the position in which to add liquidity\n    /// @param tickUpper The upper tick of the position in which to add liquidity\n    /// @param amount0Desired The desired amount of token0 to be spent\n    /// @param amount1Desired The desired amount of token1 to be spent\n    /// @return amount0 The amount of token0 after swap\n    /// @return amount1 The amount of token1 after swap\n    function _optimalSwapWithRouter(\n        PoolKey memory poolKey,\n        address router,\n        int24 tickLower,\n        int24 tickUpper,\n        uint256 amount0Desired,\n        uint256 amount1Desired,\n        bytes calldata swapData\n    ) internal returns (uint256 amount0, uint256 amount1) {\n        (uint160 sqrtPriceX96, ) = V3PoolCallee.wrap(computeAddressSorted(poolKey)).sqrtPriceX96AndTick();\n        bool zeroForOne = OptimalSwap.isZeroForOne(\n            amount0Desired,\n            amount1Desired,\n            sqrtPriceX96,\n            tickLower.getSqrtRatioAtTick(),\n            tickUpper.getSqrtRatioAtTick()\n        );\n        _routerSwap(poolKey, router, zeroForOne, swapData);\n        amount0 = ERC20Callee.wrap(poolKey.token0).balanceOf(address(this));\n        amount1 = ERC20Callee.wrap(poolKey.token1).balanceOf(address(this));\n    }\n}\n\nabstract contract UniV3SwapRouter is SwapRouter, UniswapV3Callback {\n    function computeAddressSorted(PoolKey memory poolKey) internal view override returns (address pool) {\n        pool = PoolAddress.computeAddressSorted(factory, poolKey);\n    }\n}\n\nabstract contract PCSV3SwapRouter is SwapRouter, PancakeV3Callback {\n    function computeAddressSorted(PoolKey memory poolKey) internal view override returns (address pool) {\n        pool = PoolAddressPancakeSwapV3.computeAddressSorted(deployer, poolKey);\n    }\n}\n"
      },
      "node_modules/solady/src/utils/SafeTransferLib.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.4;\n\n/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.\n/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol)\n/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)\n/// @author Permit2 operations from (https://github.com/Uniswap/permit2/blob/main/src/libraries/Permit2Lib.sol)\n///\n/// @dev Note:\n/// - For ETH transfers, please use `forceSafeTransferETH` for DoS protection.\n/// - For ERC20s, this implementation won't check that a token has code,\n///   responsibility is delegated to the caller.\nlibrary SafeTransferLib {\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                       CUSTOM ERRORS                        */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev The ETH transfer has failed.\n    error ETHTransferFailed();\n\n    /// @dev The ERC20 `transferFrom` has failed.\n    error TransferFromFailed();\n\n    /// @dev The ERC20 `transfer` has failed.\n    error TransferFailed();\n\n    /// @dev The ERC20 `approve` has failed.\n    error ApproveFailed();\n\n    /// @dev The Permit2 operation has failed.\n    error Permit2Failed();\n\n    /// @dev The Permit2 amount must be less than `2**160 - 1`.\n    error Permit2AmountOverflow();\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                         CONSTANTS                          */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Suggested gas stipend for contract receiving ETH that disallows any storage writes.\n    uint256 internal constant GAS_STIPEND_NO_STORAGE_WRITES = 2300;\n\n    /// @dev Suggested gas stipend for contract receiving ETH to perform a few\n    /// storage reads and writes, but low enough to prevent griefing.\n    uint256 internal constant GAS_STIPEND_NO_GRIEF = 100000;\n\n    /// @dev The unique EIP-712 domain domain separator for the DAI token contract.\n    bytes32 internal constant DAI_DOMAIN_SEPARATOR =\n        0xdbb8cf42e1ecb028be3f3dbc922e1d878b963f411dc388ced501601c60f7c6f7;\n\n    /// @dev The address for the WETH9 contract on Ethereum mainnet.\n    address internal constant WETH9 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;\n\n    /// @dev The canonical Permit2 address.\n    /// [Github](https://github.com/Uniswap/permit2)\n    /// [Etherscan](https://etherscan.io/address/0x000000000022D473030F116dDEE9F6B43aC78BA3)\n    address internal constant PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                       ETH OPERATIONS                       */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    // If the ETH transfer MUST succeed with a reasonable gas budget, use the force variants.\n    //\n    // The regular variants:\n    // - Forwards all remaining gas to the target.\n    // - Reverts if the target reverts.\n    // - Reverts if the current contract has insufficient balance.\n    //\n    // The force variants:\n    // - Forwards with an optional gas stipend\n    //   (defaults to `GAS_STIPEND_NO_GRIEF`, which is sufficient for most cases).\n    // - If the target reverts, or if the gas stipend is exhausted,\n    //   creates a temporary contract to force send the ETH via `SELFDESTRUCT`.\n    //   Future compatible with `SENDALL`: https://eips.ethereum.org/EIPS/eip-4758.\n    // - Reverts if the current contract has insufficient balance.\n    //\n    // The try variants:\n    // - Forwards with a mandatory gas stipend.\n    // - Instead of reverting, returns whether the transfer succeeded.\n\n    /// @dev Sends `amount` (in wei) ETH to `to`.\n    function safeTransferETH(address to, uint256 amount) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            if iszero(call(gas(), to, amount, codesize(), 0x00, codesize(), 0x00)) {\n                mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.\n                revert(0x1c, 0x04)\n            }\n        }\n    }\n\n    /// @dev Sends all the ETH in the current contract to `to`.\n    function safeTransferAllETH(address to) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Transfer all the ETH and check if it succeeded or not.\n            if iszero(call(gas(), to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {\n                mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.\n                revert(0x1c, 0x04)\n            }\n        }\n    }\n\n    /// @dev Force sends `amount` (in wei) ETH to `to`, with a `gasStipend`.\n    function forceSafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            if lt(selfbalance(), amount) {\n                mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.\n                revert(0x1c, 0x04)\n            }\n            if iszero(call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)) {\n                mstore(0x00, to) // Store the address in scratch space.\n                mstore8(0x0b, 0x73) // Opcode `PUSH20`.\n                mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.\n                if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.\n            }\n        }\n    }\n\n    /// @dev Force sends all the ETH in the current contract to `to`, with a `gasStipend`.\n    function forceSafeTransferAllETH(address to, uint256 gasStipend) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            if iszero(call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {\n                mstore(0x00, to) // Store the address in scratch space.\n                mstore8(0x0b, 0x73) // Opcode `PUSH20`.\n                mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.\n                if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.\n            }\n        }\n    }\n\n    /// @dev Force sends `amount` (in wei) ETH to `to`, with `GAS_STIPEND_NO_GRIEF`.\n    function forceSafeTransferETH(address to, uint256 amount) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            if lt(selfbalance(), amount) {\n                mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.\n                revert(0x1c, 0x04)\n            }\n            if iszero(call(GAS_STIPEND_NO_GRIEF, to, amount, codesize(), 0x00, codesize(), 0x00)) {\n                mstore(0x00, to) // Store the address in scratch space.\n                mstore8(0x0b, 0x73) // Opcode `PUSH20`.\n                mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.\n                if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.\n            }\n        }\n    }\n\n    /// @dev Force sends all the ETH in the current contract to `to`, with `GAS_STIPEND_NO_GRIEF`.\n    function forceSafeTransferAllETH(address to) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // forgefmt: disable-next-item\n            if iszero(call(GAS_STIPEND_NO_GRIEF, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {\n                mstore(0x00, to) // Store the address in scratch space.\n                mstore8(0x0b, 0x73) // Opcode `PUSH20`.\n                mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.\n                if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.\n            }\n        }\n    }\n\n    /// @dev Sends `amount` (in wei) ETH to `to`, with a `gasStipend`.\n    function trySafeTransferETH(address to, uint256 amount, uint256 gasStipend)\n        internal\n        returns (bool success)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            success := call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)\n        }\n    }\n\n    /// @dev Sends all the ETH in the current contract to `to`, with a `gasStipend`.\n    function trySafeTransferAllETH(address to, uint256 gasStipend)\n        internal\n        returns (bool success)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            success := call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)\n        }\n    }\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                      ERC20 OPERATIONS                      */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Sends `amount` of ERC20 `token` from `from` to `to`.\n    /// Reverts upon failure.\n    ///\n    /// The `from` account must have at least `amount` approved for\n    /// the current contract to manage.\n    function safeTransferFrom(address token, address from, address to, uint256 amount) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let m := mload(0x40) // Cache the free memory pointer.\n            mstore(0x60, amount) // Store the `amount` argument.\n            mstore(0x40, to) // Store the `to` argument.\n            mstore(0x2c, shl(96, from)) // Store the `from` argument.\n            mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`.\n            // Perform the transfer, reverting upon failure.\n            if iszero(\n                and( // The arguments of `and` are evaluated from right to left.\n                    or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.\n                    call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)\n                )\n            ) {\n                mstore(0x00, 0x7939f424) // `TransferFromFailed()`.\n                revert(0x1c, 0x04)\n            }\n            mstore(0x60, 0) // Restore the zero slot to zero.\n            mstore(0x40, m) // Restore the free memory pointer.\n        }\n    }\n\n    /// @dev Sends `amount` of ERC20 `token` from `from` to `to`.\n    ///\n    /// The `from` account must have at least `amount` approved for the current contract to manage.\n    function trySafeTransferFrom(address token, address from, address to, uint256 amount)\n        internal\n        returns (bool success)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let m := mload(0x40) // Cache the free memory pointer.\n            mstore(0x60, amount) // Store the `amount` argument.\n            mstore(0x40, to) // Store the `to` argument.\n            mstore(0x2c, shl(96, from)) // Store the `from` argument.\n            mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`.\n            success :=\n                and( // The arguments of `and` are evaluated from right to left.\n                    or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.\n                    call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)\n                )\n            mstore(0x60, 0) // Restore the zero slot to zero.\n            mstore(0x40, m) // Restore the free memory pointer.\n        }\n    }\n\n    /// @dev Sends all of ERC20 `token` from `from` to `to`.\n    /// Reverts upon failure.\n    ///\n    /// The `from` account must have their entire balance approved for the current contract to manage.\n    function safeTransferAllFrom(address token, address from, address to)\n        internal\n        returns (uint256 amount)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let m := mload(0x40) // Cache the free memory pointer.\n            mstore(0x40, to) // Store the `to` argument.\n            mstore(0x2c, shl(96, from)) // Store the `from` argument.\n            mstore(0x0c, 0x70a08231000000000000000000000000) // `balanceOf(address)`.\n            // Read the balance, reverting upon failure.\n            if iszero(\n                and( // The arguments of `and` are evaluated from right to left.\n                    gt(returndatasize(), 0x1f), // At least 32 bytes returned.\n                    staticcall(gas(), token, 0x1c, 0x24, 0x60, 0x20)\n                )\n            ) {\n                mstore(0x00, 0x7939f424) // `TransferFromFailed()`.\n                revert(0x1c, 0x04)\n            }\n            mstore(0x00, 0x23b872dd) // `transferFrom(address,address,uint256)`.\n            amount := mload(0x60) // The `amount` is already at 0x60. We'll need to return it.\n            // Perform the transfer, reverting upon failure.\n            if iszero(\n                and( // The arguments of `and` are evaluated from right to left.\n                    or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.\n                    call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)\n                )\n            ) {\n                mstore(0x00, 0x7939f424) // `TransferFromFailed()`.\n                revert(0x1c, 0x04)\n            }\n            mstore(0x60, 0) // Restore the zero slot to zero.\n            mstore(0x40, m) // Restore the free memory pointer.\n        }\n    }\n\n    /// @dev Sends `amount` of ERC20 `token` from the current contract to `to`.\n    /// Reverts upon failure.\n    function safeTransfer(address token, address to, uint256 amount) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            mstore(0x14, to) // Store the `to` argument.\n            mstore(0x34, amount) // Store the `amount` argument.\n            mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.\n            // Perform the transfer, reverting upon failure.\n            if iszero(\n                and( // The arguments of `and` are evaluated from right to left.\n                    or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.\n                    call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)\n                )\n            ) {\n                mstore(0x00, 0x90b8ec18) // `TransferFailed()`.\n                revert(0x1c, 0x04)\n            }\n            mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.\n        }\n    }\n\n    /// @dev Sends all of ERC20 `token` from the current contract to `to`.\n    /// Reverts upon failure.\n    function safeTransferAll(address token, address to) internal returns (uint256 amount) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            mstore(0x00, 0x70a08231) // Store the function selector of `balanceOf(address)`.\n            mstore(0x20, address()) // Store the address of the current contract.\n            // Read the balance, reverting upon failure.\n            if iszero(\n                and( // The arguments of `and` are evaluated from right to left.\n                    gt(returndatasize(), 0x1f), // At least 32 bytes returned.\n                    staticcall(gas(), token, 0x1c, 0x24, 0x34, 0x20)\n                )\n            ) {\n                mstore(0x00, 0x90b8ec18) // `TransferFailed()`.\n                revert(0x1c, 0x04)\n            }\n            mstore(0x14, to) // Store the `to` argument.\n            amount := mload(0x34) // The `amount` is already at 0x34. We'll need to return it.\n            mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.\n            // Perform the transfer, reverting upon failure.\n            if iszero(\n                and( // The arguments of `and` are evaluated from right to left.\n                    or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.\n                    call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)\n                )\n            ) {\n                mstore(0x00, 0x90b8ec18) // `TransferFailed()`.\n                revert(0x1c, 0x04)\n            }\n            mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.\n        }\n    }\n\n    /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.\n    /// Reverts upon failure.\n    function safeApprove(address token, address to, uint256 amount) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            mstore(0x14, to) // Store the `to` argument.\n            mstore(0x34, amount) // Store the `amount` argument.\n            mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.\n            // Perform the approval, reverting upon failure.\n            if iszero(\n                and( // The arguments of `and` are evaluated from right to left.\n                    or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.\n                    call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)\n                )\n            ) {\n                mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`.\n                revert(0x1c, 0x04)\n            }\n            mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.\n        }\n    }\n\n    /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.\n    /// If the initial attempt to approve fails, attempts to reset the approved amount to zero,\n    /// then retries the approval again (some tokens, e.g. USDT, requires this).\n    /// Reverts upon failure.\n    function safeApproveWithRetry(address token, address to, uint256 amount) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            mstore(0x14, to) // Store the `to` argument.\n            mstore(0x34, amount) // Store the `amount` argument.\n            mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.\n            // Perform the approval, retrying upon failure.\n            if iszero(\n                and( // The arguments of `and` are evaluated from right to left.\n                    or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.\n                    call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)\n                )\n            ) {\n                mstore(0x34, 0) // Store 0 for the `amount`.\n                mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.\n                pop(call(gas(), token, 0, 0x10, 0x44, codesize(), 0x00)) // Reset the approval.\n                mstore(0x34, amount) // Store back the original `amount`.\n                // Retry the approval, reverting upon failure.\n                if iszero(\n                    and(\n                        or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.\n                        call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)\n                    )\n                ) {\n                    mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`.\n                    revert(0x1c, 0x04)\n                }\n            }\n            mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.\n        }\n    }\n\n    /// @dev Returns the amount of ERC20 `token` owned by `account`.\n    /// Returns zero if the `token` does not exist.\n    function balanceOf(address token, address account) internal view returns (uint256 amount) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            mstore(0x14, account) // Store the `account` argument.\n            mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`.\n            amount :=\n                mul( // The arguments of `mul` are evaluated from right to left.\n                    mload(0x20),\n                    and( // The arguments of `and` are evaluated from right to left.\n                        gt(returndatasize(), 0x1f), // At least 32 bytes returned.\n                        staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20)\n                    )\n                )\n        }\n    }\n\n    /// @dev Sends `amount` of ERC20 `token` from `from` to `to`.\n    /// If the initial attempt fails, try to use Permit2 to transfer the token.\n    /// Reverts upon failure.\n    ///\n    /// The `from` account must have at least `amount` approved for the current contract to manage.\n    function safeTransferFrom2(address token, address from, address to, uint256 amount) internal {\n        if (!trySafeTransferFrom(token, from, to, amount)) {\n            permit2TransferFrom(token, from, to, amount);\n        }\n    }\n\n    /// @dev Sends `amount` of ERC20 `token` from `from` to `to` via Permit2.\n    /// Reverts upon failure.\n    function permit2TransferFrom(address token, address from, address to, uint256 amount)\n        internal\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let m := mload(0x40)\n            mstore(add(m, 0x74), shr(96, shl(96, token)))\n            mstore(add(m, 0x54), amount)\n            mstore(add(m, 0x34), to)\n            mstore(add(m, 0x20), shl(96, from))\n            // `transferFrom(address,address,uint160,address)`.\n            mstore(m, 0x36c78516000000000000000000000000)\n            let p := mul(PERMIT2, iszero(shr(160, amount)))\n            if iszero(mul(call(gas(), p, 0, add(m, 0x10), 0x84, codesize(), 0x00), extcodesize(p)))\n            {\n                mstore(0x00, 0x7939f4248757f0fd) // `TransferFromFailed()` or `Permit2AmountOverflow()`.\n                revert(add(0x18, shl(2, iszero(p))), 0x04)\n            }\n        }\n    }\n\n    /// @dev Permit a user to spend a given amount of\n    /// another user's tokens via native EIP-2612 permit if possible, falling\n    /// back to Permit2 if native permit fails or is not implemented on the token.\n    function permit2(\n        address token,\n        address owner,\n        address spender,\n        uint256 amount,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) internal {\n        bool success;\n        /// @solidity memory-safe-assembly\n        assembly {\n            for {} shl(96, xor(token, WETH9)) {} {\n                mstore(0x00, 0x3644e515) // `DOMAIN_SEPARATOR()`.\n                if iszero(\n                    and( // The arguments of `and` are evaluated from right to left.\n                        lt(iszero(mload(0x00)), eq(returndatasize(), 0x20)), // Returns 1 non-zero word.\n                        // Gas stipend to limit gas burn for tokens that don't refund gas when\n                        // an non-existing function is called. 5K should be enough for a SLOAD.\n                        staticcall(5000, token, 0x1c, 0x04, 0x00, 0x20)\n                    )\n                ) { break }\n                let m := mload(0x40)\n                mstore(add(m, 0x34), spender)\n                mstore(add(m, 0x20), shl(96, owner))\n                mstore(add(m, 0x74), deadline)\n                if eq(mload(0x00), DAI_DOMAIN_SEPARATOR) {\n                    mstore(0x14, owner)\n                    mstore(0x00, 0x7ecebe00000000000000000000000000) // `nonces(address)`.\n                    mstore(add(m, 0x94), staticcall(gas(), token, 0x10, 0x24, add(m, 0x54), 0x20))\n                    mstore(m, 0x8fcbaf0c000000000000000000000000) // `IDAIPermit.permit`.\n                    // `nonces` is already at `add(m, 0x54)`.\n                    // `1` is already stored at `add(m, 0x94)`.\n                    mstore(add(m, 0xb4), and(0xff, v))\n                    mstore(add(m, 0xd4), r)\n                    mstore(add(m, 0xf4), s)\n                    success := call(gas(), token, 0, add(m, 0x10), 0x104, codesize(), 0x00)\n                    break\n                }\n                mstore(m, 0xd505accf000000000000000000000000) // `IERC20Permit.permit`.\n                mstore(add(m, 0x54), amount)\n                mstore(add(m, 0x94), and(0xff, v))\n                mstore(add(m, 0xb4), r)\n                mstore(add(m, 0xd4), s)\n                success := call(gas(), token, 0, add(m, 0x10), 0xe4, codesize(), 0x00)\n                break\n            }\n        }\n        if (!success) simplePermit2(token, owner, spender, amount, deadline, v, r, s);\n    }\n\n    /// @dev Simple permit on the Permit2 contract.\n    function simplePermit2(\n        address token,\n        address owner,\n        address spender,\n        uint256 amount,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let m := mload(0x40)\n            mstore(m, 0x927da105) // `allowance(address,address,address)`.\n            {\n                let addressMask := shr(96, not(0))\n                mstore(add(m, 0x20), and(addressMask, owner))\n                mstore(add(m, 0x40), and(addressMask, token))\n                mstore(add(m, 0x60), and(addressMask, spender))\n                mstore(add(m, 0xc0), and(addressMask, spender))\n            }\n            let p := mul(PERMIT2, iszero(shr(160, amount)))\n            if iszero(\n                and( // The arguments of `and` are evaluated from right to left.\n                    gt(returndatasize(), 0x5f), // Returns 3 words: `amount`, `expiration`, `nonce`.\n                    staticcall(gas(), p, add(m, 0x1c), 0x64, add(m, 0x60), 0x60)\n                )\n            ) {\n                mstore(0x00, 0x6b836e6b8757f0fd) // `Permit2Failed()` or `Permit2AmountOverflow()`.\n                revert(add(0x18, shl(2, iszero(p))), 0x04)\n            }\n            mstore(m, 0x2b67b570) // `Permit2.permit` (PermitSingle variant).\n            // `owner` is already `add(m, 0x20)`.\n            // `token` is already at `add(m, 0x40)`.\n            mstore(add(m, 0x60), amount)\n            mstore(add(m, 0x80), 0xffffffffffff) // `expiration = type(uint48).max`.\n            // `nonce` is already at `add(m, 0xa0)`.\n            // `spender` is already at `add(m, 0xc0)`.\n            mstore(add(m, 0xe0), deadline)\n            mstore(add(m, 0x100), 0x100) // `signature` offset.\n            mstore(add(m, 0x120), 0x41) // `signature` length.\n            mstore(add(m, 0x140), r)\n            mstore(add(m, 0x160), s)\n            mstore(add(m, 0x180), shl(248, v))\n            if iszero(call(gas(), p, 0, add(m, 0x1c), 0x184, codesize(), 0x00)) {\n                mstore(0x00, 0x6b836e6b) // `Permit2Failed()`.\n                revert(0x1c, 0x04)\n            }\n        }\n    }\n}\n"
      },
      "node_modules/@openzeppelin/contracts/access/Ownable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)\n\npragma solidity ^0.8.20;\n\nimport {Context} from \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * The initial owner is set to the address provided by the deployer. This can\n * later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n    address private _owner;\n\n    /**\n     * @dev The caller account is not authorized to perform an operation.\n     */\n    error OwnableUnauthorizedAccount(address account);\n\n    /**\n     * @dev The owner is not a valid owner account. (eg. `address(0)`)\n     */\n    error OwnableInvalidOwner(address owner);\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.\n     */\n    constructor(address initialOwner) {\n        if (initialOwner == address(0)) {\n            revert OwnableInvalidOwner(address(0));\n        }\n        _transferOwnership(initialOwner);\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        if (owner() != _msgSender()) {\n            revert OwnableUnauthorizedAccount(_msgSender());\n        }\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        if (newOwner == address(0)) {\n            revert OwnableInvalidOwner(address(0));\n        }\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n}\n"
      },
      "node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n\n    /**\n     * @dev Returns the value of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the value of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves a `value` amount of tokens from the caller's account to `to`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address to, uint256 value) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n     * caller's tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender's allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 value) external returns (bool);\n\n    /**\n     * @dev Moves a `value` amount of tokens from `from` to `to` using the\n     * allowance mechanism. `value` is then deducted from the caller's\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address from, address to, uint256 value) external returns (bool);\n}\n"
      },
      "node_modules/@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\nimport './pool/IUniswapV3PoolImmutables.sol';\nimport './pool/IUniswapV3PoolState.sol';\nimport './pool/IUniswapV3PoolDerivedState.sol';\nimport './pool/IUniswapV3PoolActions.sol';\nimport './pool/IUniswapV3PoolOwnerActions.sol';\nimport './pool/IUniswapV3PoolEvents.sol';\n\n/// @title The interface for a Uniswap V3 Pool\n/// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform\n/// to the ERC20 specification\n/// @dev The pool interface is broken up into many smaller pieces\ninterface IUniswapV3Pool is\n    IUniswapV3PoolImmutables,\n    IUniswapV3PoolState,\n    IUniswapV3PoolDerivedState,\n    IUniswapV3PoolActions,\n    IUniswapV3PoolOwnerActions,\n    IUniswapV3PoolEvents\n{\n\n}\n"
      },
      "node_modules/@aperture_finance/uni-v3-lib/src/interfaces/INonfungiblePositionManager.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.8.0;\n\nimport {IERC721Metadata} from \"@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol\";\nimport {IERC721Enumerable} from \"@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol\";\n\nimport {IPoolInitializer} from \"@uniswap/v3-periphery/contracts/interfaces/IPoolInitializer.sol\";\nimport {IERC721Permit} from \"@uniswap/v3-periphery/contracts/interfaces/IERC721Permit.sol\";\nimport {IPeripheryPayments} from \"@uniswap/v3-periphery/contracts/interfaces/IPeripheryPayments.sol\";\nimport {IPeripheryImmutableState} from \"@uniswap/v3-periphery/contracts/interfaces/IPeripheryImmutableState.sol\";\n\n/// @title Non-fungible token for positions\n/// @notice Wraps Uniswap V3 positions in a non-fungible token interface which allows for them to be transferred\n/// and authorized.\ninterface INonfungiblePositionManager is\n    IPoolInitializer,\n    IPeripheryPayments,\n    IPeripheryImmutableState,\n    IERC721Metadata,\n    IERC721Enumerable,\n    IERC721Permit\n{\n    /// @notice Emitted when liquidity is increased for a position NFT\n    /// @dev Also emitted when a token is minted\n    /// @param tokenId The ID of the token for which liquidity was increased\n    /// @param liquidity The amount by which liquidity for the NFT position was increased\n    /// @param amount0 The amount of token0 that was paid for the increase in liquidity\n    /// @param amount1 The amount of token1 that was paid for the increase in liquidity\n    event IncreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);\n    /// @notice Emitted when liquidity is decreased for a position NFT\n    /// @param tokenId The ID of the token for which liquidity was decreased\n    /// @param liquidity The amount by which liquidity for the NFT position was decreased\n    /// @param amount0 The amount of token0 that was accounted for the decrease in liquidity\n    /// @param amount1 The amount of token1 that was accounted for the decrease in liquidity\n    event DecreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);\n    /// @notice Emitted when tokens are collected for a position NFT\n    /// @dev The amounts reported may not be exactly equivalent to the amounts transferred, due to rounding behavior\n    /// @param tokenId The ID of the token for which underlying tokens were collected\n    /// @param recipient The address of the account that received the collected tokens\n    /// @param amount0 The amount of token0 owed to the position that was collected\n    /// @param amount1 The amount of token1 owed to the position that was collected\n    event Collect(uint256 indexed tokenId, address recipient, uint256 amount0, uint256 amount1);\n\n    /// @notice Returns the position information associated with a given token ID.\n    /// @dev Throws if the token ID is not valid.\n    /// @param tokenId The ID of the token that represents the position\n    /// @return nonce The nonce for permits\n    /// @return operator The address that is approved for spending\n    /// @return token0 The address of the token0 for a specific pool\n    /// @return token1 The address of the token1 for a specific pool\n    /// @return fee The fee associated with the pool\n    /// @return tickLower The lower end of the tick range for the position\n    /// @return tickUpper The higher end of the tick range for the position\n    /// @return liquidity The liquidity of the position\n    /// @return feeGrowthInside0LastX128 The fee growth of token0 as of the last action on the individual position\n    /// @return feeGrowthInside1LastX128 The fee growth of token1 as of the last action on the individual position\n    /// @return tokensOwed0 The uncollected amount of token0 owed to the position as of the last computation\n    /// @return tokensOwed1 The uncollected amount of token1 owed to the position as of the last computation\n    function positions(\n        uint256 tokenId\n    )\n        external\n        view\n        returns (\n            uint96 nonce,\n            address operator,\n            address token0,\n            address token1,\n            uint24 fee,\n            int24 tickLower,\n            int24 tickUpper,\n            uint128 liquidity,\n            uint256 feeGrowthInside0LastX128,\n            uint256 feeGrowthInside1LastX128,\n            uint128 tokensOwed0,\n            uint128 tokensOwed1\n        );\n\n    struct MintParams {\n        address token0;\n        address token1;\n        uint24 fee;\n        int24 tickLower;\n        int24 tickUpper;\n        uint256 amount0Desired;\n        uint256 amount1Desired;\n        uint256 amount0Min;\n        uint256 amount1Min;\n        address recipient;\n        uint256 deadline;\n    }\n\n    /// @notice Creates a new position wrapped in a NFT\n    /// @dev Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized\n    /// a method does not exist, i.e. the pool is assumed to be initialized.\n    /// @param params The params necessary to mint a position, encoded as `MintParams` in calldata\n    /// @return tokenId The ID of the token that represents the minted position\n    /// @return liquidity The amount of liquidity for this position\n    /// @return amount0 The amount of token0\n    /// @return amount1 The amount of token1\n    function mint(\n        MintParams calldata params\n    ) external payable returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);\n\n    struct IncreaseLiquidityParams {\n        uint256 tokenId;\n        uint256 amount0Desired;\n        uint256 amount1Desired;\n        uint256 amount0Min;\n        uint256 amount1Min;\n        uint256 deadline;\n    }\n\n    /// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender`\n    /// @param params tokenId The ID of the token for which liquidity is being increased,\n    /// amount0Desired The desired amount of token0 to be spent,\n    /// amount1Desired The desired amount of token1 to be spent,\n    /// amount0Min The minimum amount of token0 to spend, which serves as a slippage check,\n    /// amount1Min The minimum amount of token1 to spend, which serves as a slippage check,\n    /// deadline The time by which the transaction must be included to effect the change\n    /// @return liquidity The new liquidity amount as a result of the increase\n    /// @return amount0 The amount of token0 to acheive resulting liquidity\n    /// @return amount1 The amount of token1 to acheive resulting liquidity\n    function increaseLiquidity(\n        IncreaseLiquidityParams calldata params\n    ) external payable returns (uint128 liquidity, uint256 amount0, uint256 amount1);\n\n    struct DecreaseLiquidityParams {\n        uint256 tokenId;\n        uint128 liquidity;\n        uint256 amount0Min;\n        uint256 amount1Min;\n        uint256 deadline;\n    }\n\n    /// @notice Decreases the amount of liquidity in a position and accounts it to the position\n    /// @param params tokenId The ID of the token for which liquidity is being decreased,\n    /// amount The amount by which liquidity will be decreased,\n    /// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,\n    /// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,\n    /// deadline The time by which the transaction must be included to effect the change\n    /// @return amount0 The amount of token0 accounted to the position's tokens owed\n    /// @return amount1 The amount of token1 accounted to the position's tokens owed\n    function decreaseLiquidity(\n        DecreaseLiquidityParams calldata params\n    ) external payable returns (uint256 amount0, uint256 amount1);\n\n    struct CollectParams {\n        uint256 tokenId;\n        address recipient;\n        uint128 amount0Max;\n        uint128 amount1Max;\n    }\n\n    /// @notice Collects up to a maximum amount of fees owed to a specific position to the recipient\n    /// @param params tokenId The ID of the NFT for which tokens are being collected,\n    /// recipient The account that should receive the tokens,\n    /// amount0Max The maximum amount of token0 to collect,\n    /// amount1Max The maximum amount of token1 to collect\n    /// @return amount0 The amount of fees collected in token0\n    /// @return amount1 The amount of fees collected in token1\n    function collect(CollectParams calldata params) external payable returns (uint256 amount0, uint256 amount1);\n\n    /// @notice Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens\n    /// must be collected first.\n    /// @param tokenId The ID of the token that is being burned\n    function burn(uint256 tokenId) external payable;\n}\n\n/// @title Non-fungible token for PancakeSwap V3 positions\n/// @notice Wraps PCSV3 positions in a non-fungible token interface which allows for them to be transferred\n/// and authorized.\ninterface IPCSV3NonfungiblePositionManager is INonfungiblePositionManager {\n    /// @return Returns the address of the PancakeSwap V3 deployer\n    function deployer() external view returns (address);\n}\n"
      },
      "node_modules/@aperture_finance/uni-v3-lib/src/LiquidityAmounts.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.8.4;\n\nimport \"@uniswap/v3-core/contracts/libraries/FixedPoint96.sol\";\nimport \"./FullMath.sol\";\nimport \"./SafeCast.sol\";\nimport \"./TernaryLib.sol\";\nimport \"./UnsafeMath.sol\";\n\n/// @title Liquidity amount functions\n/// @author Aperture Finance\n/// @author Modified from Uniswap (https://github.com/uniswap/v3-periphery/blob/main/contracts/libraries/LiquidityAmounts.sol)\n/// @notice Provides functions for computing liquidity amounts from token amounts and prices\nlibrary LiquidityAmounts {\n    using UnsafeMath for *;\n    using SafeCast for uint256;\n\n    /// @notice Computes the amount of liquidity received for a given amount of token0 and price range\n    /// @dev Calculates amount0 * (sqrt(upper) * sqrt(lower)) / (sqrt(upper) - sqrt(lower))\n    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary\n    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary\n    /// @param amount0 The amount0 being sent in\n    /// @return liquidity The amount of returned liquidity\n    function getLiquidityForAmount0(\n        uint160 sqrtRatioAX96,\n        uint160 sqrtRatioBX96,\n        uint256 amount0\n    ) internal pure returns (uint128 liquidity) {\n        (sqrtRatioAX96, sqrtRatioBX96) = TernaryLib.sort2(sqrtRatioAX96, sqrtRatioBX96);\n        uint256 intermediate = FullMath.mulDiv96(sqrtRatioAX96, sqrtRatioBX96);\n        return FullMath.mulDiv(amount0, intermediate, sqrtRatioBX96.sub(sqrtRatioAX96)).toUint128();\n    }\n\n    /// @notice Computes the amount of liquidity received for a given amount of token1 and price range\n    /// @dev Calculates amount1 / (sqrt(upper) - sqrt(lower)).\n    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary\n    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary\n    /// @param amount1 The amount1 being sent in\n    /// @return liquidity The amount of returned liquidity\n    function getLiquidityForAmount1(\n        uint160 sqrtRatioAX96,\n        uint160 sqrtRatioBX96,\n        uint256 amount1\n    ) internal pure returns (uint128 liquidity) {\n        (sqrtRatioAX96, sqrtRatioBX96) = TernaryLib.sort2(sqrtRatioAX96, sqrtRatioBX96);\n        return FullMath.mulDiv(amount1, FixedPoint96.Q96, sqrtRatioBX96.sub(sqrtRatioAX96)).toUint128();\n    }\n\n    /// @notice Computes the maximum amount of liquidity received for a given amount of token0, token1, the current\n    /// pool prices and the prices at the tick boundaries\n    /// @param sqrtRatioX96 A sqrt price representing the current pool prices\n    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary\n    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary\n    /// @param amount0 The amount of token0 being sent in\n    /// @param amount1 The amount of token1 being sent in\n    /// @return liquidity The maximum amount of liquidity received\n    function getLiquidityForAmounts(\n        uint160 sqrtRatioX96,\n        uint160 sqrtRatioAX96,\n        uint160 sqrtRatioBX96,\n        uint256 amount0,\n        uint256 amount1\n    ) internal pure returns (uint128 liquidity) {\n        (sqrtRatioAX96, sqrtRatioBX96) = TernaryLib.sort2(sqrtRatioAX96, sqrtRatioBX96);\n\n        if (sqrtRatioX96 <= sqrtRatioAX96) {\n            liquidity = getLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, amount0);\n        } else if (sqrtRatioX96 < sqrtRatioBX96) {\n            uint128 liquidity0 = getLiquidityForAmount0(sqrtRatioX96, sqrtRatioBX96, amount0);\n            uint128 liquidity1 = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioX96, amount1);\n            // liquidity = min(liquidity0, liquidity1);\n            assembly {\n                liquidity := xor(liquidity0, mul(xor(liquidity0, liquidity1), lt(liquidity1, liquidity0)))\n            }\n        } else {\n            liquidity = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1);\n        }\n    }\n\n    /// @notice Computes the amount of token0 for a given amount of liquidity and a price range\n    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary\n    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary\n    /// @param liquidity The liquidity being valued\n    /// @return amount0 The amount of token0\n    function getAmount0ForLiquidity(\n        uint160 sqrtRatioAX96,\n        uint160 sqrtRatioBX96,\n        uint128 liquidity\n    ) internal pure returns (uint256 amount0) {\n        (sqrtRatioAX96, sqrtRatioBX96) = TernaryLib.sort2(sqrtRatioAX96, sqrtRatioBX96);\n        return\n            FullMath\n                .mulDiv(uint256(liquidity) << FixedPoint96.RESOLUTION, sqrtRatioBX96.sub(sqrtRatioAX96), sqrtRatioBX96)\n                .div(sqrtRatioAX96);\n    }\n\n    /// @notice Computes the amount of token1 for a given amount of liquidity and a price range\n    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary\n    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary\n    /// @param liquidity The liquidity being valued\n    /// @return amount1 The amount of token1\n    function getAmount1ForLiquidity(\n        uint160 sqrtRatioAX96,\n        uint160 sqrtRatioBX96,\n        uint128 liquidity\n    ) internal pure returns (uint256 amount1) {\n        (sqrtRatioAX96, sqrtRatioBX96) = TernaryLib.sort2(sqrtRatioAX96, sqrtRatioBX96);\n        return FullMath.mulDiv96(liquidity, sqrtRatioBX96.sub(sqrtRatioAX96));\n    }\n\n    /// @notice Computes the token0 and token1 value for a given amount of liquidity, the current\n    /// pool prices and the prices at the tick boundaries\n    /// @param sqrtRatioX96 A sqrt price representing the current pool prices\n    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary\n    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary\n    /// @param liquidity The liquidity being valued\n    /// @return amount0 The amount of token0\n    /// @return amount1 The amount of token1\n    function getAmountsForLiquidity(\n        uint160 sqrtRatioX96,\n        uint160 sqrtRatioAX96,\n        uint160 sqrtRatioBX96,\n        uint128 liquidity\n    ) internal pure returns (uint256 amount0, uint256 amount1) {\n        (sqrtRatioAX96, sqrtRatioBX96) = TernaryLib.sort2(sqrtRatioAX96, sqrtRatioBX96);\n\n        if (sqrtRatioX96 <= sqrtRatioAX96) {\n            amount0 = getAmount0ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity);\n        } else if (sqrtRatioX96 < sqrtRatioBX96) {\n            amount0 = getAmount0ForLiquidity(sqrtRatioX96, sqrtRatioBX96, liquidity);\n            amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioX96, liquidity);\n        } else {\n            amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity);\n        }\n    }\n}\n"
      },
      "node_modules/@aperture_finance/uni-v3-lib/src/NPMCaller.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.8.0;\n\nimport \"@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol\";\nimport {INonfungiblePositionManager as INPM, IERC721Permit, IPeripheryImmutableState} from \"./interfaces/INonfungiblePositionManager.sol\";\n\n// details about the uniswap position\nstruct PositionFull {\n    // the nonce for permits\n    uint96 nonce;\n    // the address that is approved for spending this token\n    address operator;\n    address token0;\n    address token1;\n    // The pool's fee in hundredths of a bip, i.e. 1e-6\n    uint24 fee;\n    // the tick range of the position\n    int24 tickLower;\n    int24 tickUpper;\n    // the liquidity of the position\n    uint128 liquidity;\n    // the fee growth of the aggregate position as of the last action on the individual position\n    uint256 feeGrowthInside0LastX128;\n    uint256 feeGrowthInside1LastX128;\n    // how many uncollected tokens are owed to the position, as of the last computation\n    uint128 tokensOwed0;\n    uint128 tokensOwed1;\n}\n\nstruct Position {\n    address token0;\n    address token1;\n    // The pool's fee in hundredths of a bip, i.e. 1e-6\n    uint24 fee;\n    // the tick range of the position\n    int24 tickLower;\n    int24 tickUpper;\n    // the liquidity of the position\n    uint128 liquidity;\n}\n\n/// @title Uniswap v3 Nonfungible Position Manager Caller\n/// @author Aperture Finance\n/// @notice Gas efficient library to call `INonfungiblePositionManager` assuming it exists.\n/// @dev Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.\n/// However, this is safe because \"Note that you do not need to update the free memory pointer if there is no following\n/// allocation, but you can only use memory starting from the current offset given by the free memory pointer.\"\n/// according to https://docs.soliditylang.org/en/latest/assembly.html#memory-safety.\n/// When bubbling up the revert reason, it is safe to overwrite the free memory pointer 0x40 and the zero pointer 0x60\n/// before exiting because a contract obtains a freshly cleared instance of memory for each message call.\nlibrary NPMCaller {\n    /// @dev Makes a staticcall to the NPM with only the selector and returns a memory word.\n    function staticcall_0i_1o(INPM npm, bytes4 selector) internal view returns (uint256 res) {\n        assembly (\"memory-safe\") {\n            // Write the function selector into memory.\n            mstore(0, selector)\n            // We use 4 because of the length of our calldata.\n            // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.\n            if iszero(staticcall(gas(), npm, 0, 4, 0, 0x20)) {\n                revert(0, 0)\n            }\n            res := mload(0)\n        }\n    }\n\n    /// @dev Makes a staticcall to the NPM with one argument and returns a memory word.\n    function staticcall_1i_1o(INPM npm, bytes4 selector, uint256 arg) internal view returns (uint256 res) {\n        assembly (\"memory-safe\") {\n            // Write the abi-encoded calldata into memory.\n            mstore(0, selector)\n            mstore(4, arg)\n            // We use 36 because of the length of our calldata.\n            // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.\n            if iszero(staticcall(gas(), npm, 0, 0x24, 0, 0x20)) {\n                returndatacopy(0, 0, returndatasize())\n                // Bubble up the revert reason.\n                revert(0, returndatasize())\n            }\n            res := mload(0)\n        }\n    }\n\n    /// @dev Makes a staticcall to the NPM with two arguments and returns a memory word.\n    function staticcall_2i_1o(\n        INPM npm,\n        bytes4 selector,\n        uint256 arg0,\n        uint256 arg1\n    ) internal view returns (uint256 res) {\n        assembly (\"memory-safe\") {\n            // Write the abi-encoded calldata into memory.\n            mstore(0, selector)\n            mstore(4, arg0)\n            mstore(0x24, arg1)\n            // We use 68 because of the length of our calldata.\n            // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.\n            if iszero(staticcall(gas(), npm, 0, 0x44, 0, 0x20)) {\n                returndatacopy(0, 0, returndatasize())\n                // Bubble up the revert reason.\n                revert(0, returndatasize())\n            }\n            res := mload(0)\n            // Clear first 4 bytes of the free memory pointer.\n            mstore(0x24, 0)\n        }\n    }\n\n    /// @notice Count all NFTs assigned to an owner\n    /// @dev NFTs assigned to the zero address are considered invalid, and this\n    /// function throws for queries about the zero address.\n    /// @param npm Uniswap v3 Nonfungible Position Manager\n    /// @param owner An address for whom to query the balance\n    /// @return amount The number of NFTs owned by `owner`, possibly zero\n    function balanceOf(INPM npm, address owner) internal view returns (uint256 amount) {\n        uint256 _owner;\n        assembly {\n            _owner := owner\n        }\n        amount = staticcall_1i_1o(npm, IERC721.balanceOf.selector, _owner);\n    }\n\n    /// @dev Returns a token ID owned by `owner` at a given `index` of its token list.\n    /// @param npm Uniswap v3 Nonfungible Position Manager\n    /// @param owner The address that owns the NFTs\n    /// @param index The index of the token ID\n    function tokenOfOwnerByIndex(INPM npm, address owner, uint256 index) internal view returns (uint256 tokenId) {\n        uint256 _owner;\n        assembly {\n            _owner := owner\n        }\n        tokenId = staticcall_2i_1o(npm, IERC721Enumerable.tokenOfOwnerByIndex.selector, _owner, index);\n    }\n\n    /// @dev Returns the total amount of tokens stored by the contract.\n    function totalSupply(INPM npm) internal view returns (uint256 amount) {\n        amount = staticcall_0i_1o(npm, IERC721Enumerable.totalSupply.selector);\n    }\n\n    /// @notice Find the owner of an NFT\n    /// @dev NFTs assigned to zero address are considered invalid, and queries\n    /// about them do throw.\n    /// @param npm Uniswap v3 Nonfungible Position Manager\n    /// @param tokenId The identifier for an NFT\n    /// @return owner The address of the owner of the NFT\n    function ownerOf(INPM npm, uint256 tokenId) internal view returns (address owner) {\n        uint256 res = staticcall_1i_1o(npm, IERC721.ownerOf.selector, tokenId);\n        assembly {\n            owner := res\n        }\n    }\n\n    /// @notice Get the approved address for a single NFT\n    /// @dev Throws if `tokenId` is not a valid NFT.\n    /// @param npm Uniswap v3 Nonfungible Position Manager\n    /// @param tokenId The NFT to find the approved address for\n    /// @return operator The approved address for this NFT, or the zero address if there is none\n    function getApproved(INPM npm, uint256 tokenId) internal view returns (address operator) {\n        uint256 res = staticcall_1i_1o(npm, IERC721.getApproved.selector, tokenId);\n        assembly {\n            operator := res\n        }\n    }\n\n    /// @notice Change or reaffirm the approved address for an NFT\n    /// @dev The zero address indicates there is no approved address.\n    /// Throws unless `msg.sender` is the current NFT owner, or an authorized\n    /// operator of the current owner.\n    /// @param npm Uniswap v3 Nonfungible Position Manager\n    /// @param spender The new approved NFT controller\n    /// @param tokenId The NFT to approve\n    function approve(INPM npm, address spender, uint256 tokenId) internal {\n        bytes4 selector = IERC721.approve.selector;\n        assembly (\"memory-safe\") {\n            // Write the abi-encoded calldata into memory.\n            mstore(0, selector)\n            mstore(4, spender)\n            mstore(0x24, tokenId)\n            // We use 68 because of the length of our calldata.\n            if iszero(call(gas(), npm, 0, 0, 0x44, 0, 0)) {\n                returndatacopy(0, 0, returndatasize())\n                // Bubble up the revert reason.\n                revert(0, returndatasize())\n            }\n            // Clear first 4 bytes of the free memory pointer.\n            mstore(0x24, 0)\n        }\n    }\n\n    /// @notice Query if an address is an authorized operator for another address\n    /// @param npm Uniswap v3 Nonfungible Position Manager\n    /// @param owner The address that owns the NFTs\n    /// @param operator The address that acts on behalf of the owner\n    /// @return isApproved True if `operator` is an approved operator for `owner`, false otherwise\n    function isApprovedForAll(INPM npm, address owner, address operator) internal view returns (bool isApproved) {\n        uint256 _owner;\n        uint256 _operator;\n        assembly {\n            _owner := owner\n            _operator := operator\n        }\n        uint256 res = staticcall_2i_1o(npm, IERC721.isApprovedForAll.selector, _owner, _operator);\n        assembly {\n            isApproved := res\n        }\n    }\n\n    /// @notice Enable or disable approval for a third party (\"operator\") to manage\n    /// all of `msg.sender`'s assets\n    /// @dev Emits the ApprovalForAll event. The contract MUST allow\n    /// multiple operators per owner.\n    /// @param operator Address to add to the set of authorized operators\n    /// @param approved True if the operator is approved, false to revoke approval\n    function setApprovalForAll(INPM npm, address operator, bool approved) internal {\n        bytes4 selector = IERC721.setApprovalForAll.selector;\n        assembly (\"memory-safe\") {\n            // Write the abi-encoded calldata into memory.\n            mstore(0, selector)\n            mstore(4, operator)\n            mstore(0x24, approved)\n            // We use 68 because of the length of our calldata.\n            if iszero(call(gas(), npm, 0, 0, 0x44, 0, 0)) {\n                returndatacopy(0, 0, returndatasize())\n                // Bubble up the revert reason.\n                revert(0, returndatasize())\n            }\n            // Clear first 4 bytes of the free memory pointer.\n            mstore(0x24, 0)\n        }\n    }\n\n    /// @dev Equivalent to `INonfungiblePositionManager.factory`\n    /// @param npm Nonfungible position manager\n    function factory(INPM npm) internal view returns (address f) {\n        uint256 res = staticcall_0i_1o(npm, IPeripheryImmutableState.factory.selector);\n        assembly {\n            f := res\n        }\n    }\n\n    /// @dev Equivalent to `INonfungiblePositionManager.positions(tokenId)`\n    /// @param npm Uniswap v3 Nonfungible Position Manager\n    /// @param tokenId The ID of the token that represents the position\n    function positionsFull(INPM npm, uint256 tokenId) internal view returns (PositionFull memory pos) {\n        bytes4 selector = INPM.positions.selector;\n        assembly (\"memory-safe\") {\n            // Write the abi-encoded calldata into memory.\n            mstore(0, selector)\n            mstore(4, tokenId)\n            // We use 36 because of the length of our calldata.\n            // We copy up to 384 bytes of return data at pos's pointer.\n            if iszero(staticcall(gas(), npm, 0, 0x24, pos, 0x180)) {\n                // Bubble up the revert reason.\n                revert(pos, returndatasize())\n            }\n        }\n    }\n\n    /// @dev Equivalent to `INonfungiblePositionManager.positions(tokenId)`\n    /// @param npm Uniswap v3 Nonfungible Position Manager\n    /// @param tokenId The ID of the token that represents the position\n    function positions(INPM npm, uint256 tokenId) internal view returns (Position memory pos) {\n        bytes4 selector = INPM.positions.selector;\n        assembly (\"memory-safe\") {\n            // Write the abi-encoded calldata into memory.\n            mstore(0, selector)\n            mstore(4, tokenId)\n            // We use 36 because of the length of our calldata.\n            // We copy up to 256 bytes of return data at `pos` which is the free memory pointer.\n            if iszero(staticcall(gas(), npm, 0, 0x24, pos, 0x100)) {\n                // Bubble up the revert reason.\n                revert(pos, returndatasize())\n            }\n            // Move the free memory pointer to the end of the struct.\n            mstore(0x40, add(pos, 0x100))\n            // Skip the first two struct members.\n            pos := add(pos, 0x40)\n        }\n    }\n\n    /// @dev Equivalent to `INonfungiblePositionManager.mint`\n    /// @param npm Uniswap v3 Nonfungible Position Manager\n    /// @param params The parameters for minting a position\n    function mint(\n        INPM npm,\n        INPM.MintParams memory params\n    ) internal returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1) {\n        uint32 selector = uint32(INPM.mint.selector);\n        assembly (\"memory-safe\") {\n            // Cache the free memory pointer.\n            let fmp := mload(0x40)\n            // Cache the memory word before `params`.\n            let memBeforeParams := sub(params, 0x20)\n            let wordBeforeParams := mload(memBeforeParams)\n            // Write the function selector 4 bytes before `params`.\n            mstore(memBeforeParams, selector)\n            // We use 356 because of the length of our calldata.\n            // We copy up to 128 bytes of return data at the free memory pointer.\n            if iszero(call(gas(), npm, 0, sub(params, 4), 0x164, 0, 0x80)) {\n                // Bubble up the revert reason.\n                revert(0, returndatasize())\n            }\n            // Read the return data.\n            tokenId := mload(0)\n            liquidity := mload(0x20)\n            amount0 := mload(0x40)\n            amount1 := mload(0x60)\n            // Restore the free memory pointer, zero pointer and memory word before `params`.\n            // `memBeforeParams` >= 0x60 so restore it after `mload`.\n            mstore(memBeforeParams, wordBeforeParams)\n            mstore(0x40, fmp)\n            mstore(0x60, 0)\n        }\n    }\n\n    /// @dev Equivalent to `INonfungiblePositionManager.increaseLiquidity`\n    /// @param npm Uniswap v3 Nonfungible Position Manager\n    /// @param params The parameters for increasing liquidity in a position\n    function increaseLiquidity(\n        INPM npm,\n        INPM.IncreaseLiquidityParams memory params\n    ) internal returns (uint128 liquidity, uint256 amount0, uint256 amount1) {\n        uint32 selector = uint32(INPM.increaseLiquidity.selector);\n        assembly (\"memory-safe\") {\n            // Cache the free memory pointer.\n            let fmp := mload(0x40)\n            // Cache the memory word before `params`.\n            let memBeforeParams := sub(params, 0x20)\n            let wordBeforeParams := mload(memBeforeParams)\n            // Write the function selector 4 bytes before `params`.\n            mstore(memBeforeParams, selector)\n            // We use 196 because of the length of our calldata.\n            // We copy up to 96 bytes of return data at the free memory pointer.\n            if iszero(call(gas(), npm, 0, sub(params, 4), 0xc4, 0, 0x60)) {\n                returndatacopy(0, 0, returndatasize())\n                // Bubble up the revert reason.\n                revert(0, returndatasize())\n            }\n            // Restore the memory word before `params`.\n            mstore(memBeforeParams, wordBeforeParams)\n            // Read the return data.\n            liquidity := mload(0)\n            amount0 := mload(0x20)\n            amount1 := mload(0x40)\n            // Restore the free memory pointer.\n            mstore(0x40, fmp)\n        }\n    }\n\n    /// @dev Equivalent to `INonfungiblePositionManager.decreaseLiquidity`\n    /// @param npm Uniswap v3 Nonfungible Position Manager\n    /// @param params The parameters for decreasing liquidity in a position\n    function decreaseLiquidity(\n        INPM npm,\n        INPM.DecreaseLiquidityParams memory params\n    ) internal returns (uint256 amount0, uint256 amount1) {\n        uint32 selector = uint32(INPM.decreaseLiquidity.selector);\n        assembly (\"memory-safe\") {\n            // Cache the memory word before `params`.\n            let memBeforeParams := sub(params, 0x20)\n            let wordBeforeParams := mload(memBeforeParams)\n            // Write the function selector 4 bytes before `params`.\n            mstore(memBeforeParams, selector)\n            // We use 164 because of the length of our calldata.\n            // We use 0 and 64 to copy up to 64 bytes of return data into the scratch space.\n            if iszero(call(gas(), npm, 0, sub(params, 4), 0xa4, 0, 0x40)) {\n                returndatacopy(0, 0, returndatasize())\n                // Bubble up the revert reason.\n                revert(0, returndatasize())\n            }\n            // Restore the memory word before `params`.\n            mstore(memBeforeParams, wordBeforeParams)\n            // Read the return data.\n            amount0 := mload(0)\n            amount1 := mload(0x20)\n        }\n    }\n\n    /// @dev Equivalent to `INonfungiblePositionManager.burn`\n    /// @param npm Uniswap v3 Nonfungible Position Manager\n    /// @param tokenId The token ID of the position to burn\n    function burn(INPM npm, uint256 tokenId) internal {\n        bytes4 selector = INPM.burn.selector;\n        assembly (\"memory-safe\") {\n            // Write the abi-encoded calldata into memory.\n            mstore(0, selector)\n            mstore(4, tokenId)\n            // We use 36 because of the length of our calldata.\n            if iszero(call(gas(), npm, 0, 0, 0x24, 0, 0)) {\n                returndatacopy(0, 0, returndatasize())\n                // Bubble up the revert reason.\n                revert(0, returndatasize())\n            }\n        }\n    }\n\n    /// @dev Equivalent to `INonfungiblePositionManager.collect`\n    /// @param npm Uniswap v3 Nonfungible Position Manager\n    /// @param tokenId The token ID of the position to collect fees for\n    /// @param recipient The address that receives the fees\n    function collect(INPM npm, uint256 tokenId, address recipient) internal returns (uint256 amount0, uint256 amount1) {\n        bytes4 selector = INPM.collect.selector;\n        assembly (\"memory-safe\") {\n            // Get a pointer to some free memory.\n            let fmp := mload(0x40)\n            mstore(fmp, selector)\n            mstore(add(fmp, 4), tokenId)\n            mstore(add(fmp, 0x24), recipient)\n            // amount0Max = amount1Max = type(uint128).max\n            mstore(add(fmp, 0x44), 0xffffffffffffffffffffffffffffffff)\n            mstore(add(fmp, 0x64), 0xffffffffffffffffffffffffffffffff)\n            // We use 132 because of the length of our calldata.\n            // We use 0 and 64 to copy up to 64 bytes of return data into the scratch space.\n            if iszero(call(gas(), npm, 0, fmp, 0x84, 0, 0x40)) {\n                returndatacopy(0, 0, returndatasize())\n                // Bubble up the revert reason.\n                revert(0, returndatasize())\n            }\n            amount0 := mload(0)\n            amount1 := mload(0x20)\n        }\n    }\n\n    /// @dev Equivalent to `INonfungiblePositionManager.permit`\n    /// @param npm Uniswap v3 Nonfungible Position Manager\n    /// @param spender The account that is being approved\n    /// @param tokenId The ID of the token that is being approved for spending\n    /// @param deadline The deadline timestamp by which the call must be mined for the approve to work\n    /// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s`\n    /// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s`\n    /// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v`\n    function permit(\n        INPM npm,\n        address spender,\n        uint256 tokenId,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) internal {\n        bytes4 selector = IERC721Permit.permit.selector;\n        assembly (\"memory-safe\") {\n            // Get a pointer to some free memory.\n            let fmp := mload(0x40)\n            mstore(fmp, selector)\n            mstore(add(fmp, 4), spender)\n            mstore(add(fmp, 0x24), tokenId)\n            mstore(add(fmp, 0x44), deadline)\n            mstore(add(fmp, 0x64), v)\n            mstore(add(fmp, 0x84), r)\n            mstore(add(fmp, 0xa4), s)\n            // We use 196 because of the length of our calldata.\n            if iszero(call(gas(), npm, 0, fmp, 0xc4, 0, 0)) {\n                returndatacopy(0, 0, returndatasize())\n                // Bubble up the revert reason.\n                revert(0, returndatasize())\n            }\n        }\n    }\n}\n"
      },
      "node_modules/@aperture_finance/uni-v3-lib/src/PoolKey.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @notice The identifying key of a liquidity pool\nstruct PoolKey {\n    address token0;\n    address token1;\n    uint24 fee;\n}\n"
      },
      "src/interfaces/IAutoman.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.0;\n\nimport \"@pancakeswap/v3-core/contracts/interfaces/callback/IPancakeV3SwapCallback.sol\";\nimport \"@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol\";\nimport {INonfungiblePositionManager as INPM} from \"@aperture_finance/uni-v3-lib/src/interfaces/INonfungiblePositionManager.sol\";\nimport {V3PoolCallee} from \"@aperture_finance/uni-v3-lib/src/PoolCaller.sol\";\nimport {IPCSV3Immutables, IUniV3Immutables} from \"./IImmutables.sol\";\n\n/// @title Interface for the Uniswap v3 Automation Manager\ninterface IAutoman {\n    /************************************************\n     *  EVENTS\n     ***********************************************/\n\n    event FeeConfigSet(address feeCollector, uint96 feeLimitPips);\n    event ControllersSet(address[] controllers, bool[] statuses);\n    event SwapRoutersSet(address[] routers, bool[] statuses);\n    event Mint(uint256 indexed tokenId);\n    event IncreaseLiquidity(uint256 indexed tokenId);\n    event DecreaseLiquidity(uint256 indexed tokenId);\n    event RemoveLiquidity(uint256 indexed tokenId);\n    event Reinvest(uint256 indexed tokenId);\n    event Rebalance(uint256 indexed tokenId);\n\n    /************************************************\n     *  ERRORS\n     ***********************************************/\n\n    error NotApproved();\n    error InvalidSwapRouter();\n    error NotWhitelistedRouter();\n    error InsufficientAmount();\n    error FeeLimitExceeded();\n\n    /// @notice Get swap amount, output amount, swap direction for double-sided optimal deposit\n    /// @param pool Uniswap v3 pool\n    /// @param tickLower The lower tick of the position in which to add liquidity\n    /// @param tickUpper The upper tick of the position in which to add liquidity\n    /// @param amount0Desired The desired amount of token0 to be spent\n    /// @param amount1Desired The desired amount of token1 to be spent\n    /// @return amountIn The optimal swap amount\n    /// @return amountOut Expected output amount\n    /// @return zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0\n    /// @return sqrtPriceX96 The sqrt(price) after the swap\n    function getOptimalSwap(\n        V3PoolCallee pool,\n        int24 tickLower,\n        int24 tickUpper,\n        uint256 amount0Desired,\n        uint256 amount1Desired\n    ) external view returns (uint256 amountIn, uint256 amountOut, bool zeroForOne, uint160 sqrtPriceX96);\n\n    /// @notice Creates a new position wrapped in a NFT\n    /// @dev Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized\n    /// a method does not exist, i.e. the pool is assumed to be initialized.\n    /// @param params The params necessary to mint a position, encoded as `MintParams` in calldata\n    /// token0 The address of the token0 for a specific pool\n    /// token1 The address of the token1 for a specific pool\n    /// fee The fee associated with the pool\n    /// tickLower The lower tick of the position in which to add liquidity\n    /// tickUpper The upper tick of the position in which to add liquidity\n    /// amount0Desired The desired amount of token0 to be spent\n    /// amount1Desired The desired amount of token1 to be spent\n    /// amount0Min The minimum amount of token0 to spend, which serves as a slippage check\n    /// amount1Min The minimum amount of token1 to spend, which serves as a slippage check\n    /// recipient The recipient of the minted position\n    /// deadline The time by which the transaction must be included to effect the change\n    /// @return tokenId The ID of the token that represents the minted position\n    /// @return liquidity The amount of liquidity for this position\n    /// @return amount0 The amount of token0 spent\n    /// @return amount1 The amount of token1 spent\n    function mint(\n        INPM.MintParams memory params\n    ) external payable returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);\n\n    /// @notice Creates a new position wrapped in a NFT using optimal swap\n    /// @dev Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized\n    /// a method does not exist, i.e. the pool is assumed to be initialized.\n    /// @param params The params necessary to mint a position, encoded as `MintParams` in calldata\n    /// token0 The address of the token0 for a specific pool\n    /// token1 The address of the token1 for a specific pool\n    /// fee The fee associated with the pool\n    /// tickLower The lower tick of the position in which to add liquidity\n    /// tickUpper The upper tick of the position in which to add liquidity\n    /// amount0Desired The desired amount of token0 to be spent\n    /// amount1Desired The desired amount of token1 to be spent\n    /// amount0Min The minimum amount of token0 to spend, which serves as a slippage check\n    /// amount1Min The minimum amount of token1 to spend, which serves as a slippage check\n    /// recipient The recipient of the minted position\n    /// deadline The time by which the transaction must be included to effect the change\n    /// @param swapData The address of the external router and call data\n    /// @return tokenId The ID of the token that represents the minted position\n    /// @return liquidity The amount of liquidity for this position\n    /// @return amount0 The amount of token0 spent\n    /// @return amount1 The amount of token1 spent\n    function mintOptimal(\n        INPM.MintParams memory params,\n        bytes calldata swapData\n    ) external payable returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);\n\n    /// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender`\n    /// @dev Anyone can increase the liquidity of a position, but the caller must pay the tokens\n    /// @param params tokenId The ID of the token for which liquidity is being increased,\n    /// amount0Desired The desired amount of token0 to be spent,\n    /// amount1Desired The desired amount of token1 to be spent,\n    /// amount0Min The minimum amount of token0 to spend, which serves as a slippage check,\n    /// amount1Min The minimum amount of token1 to spend, which serves as a slippage check,\n    /// deadline The time by which the transaction must be included to effect the change\n    /// @return liquidity The new liquidity amount as a result of the increase\n    /// @return amount0 The amount of token0 to achieve resulting liquidity\n    /// @return amount1 The amount of token1 to achieve resulting liquidity\n    function increaseLiquidity(\n        INPM.IncreaseLiquidityParams memory params\n    ) external payable returns (uint128 liquidity, uint256 amount0, uint256 amount1);\n\n    /// @notice Increases the amount of liquidity in a position using optimal swap\n    /// @dev Anyone can increase the liquidity of a position, but the caller must pay the tokens\n    /// @param params tokenId The ID of the token for which liquidity is being increased,\n    /// amount0Desired The desired amount of token0 to be spent,\n    /// amount1Desired The desired amount of token1 to be spent,\n    /// amount0Min The minimum amount of token0 to spend, which serves as a slippage check,\n    /// amount1Min The minimum amount of token1 to spend, which serves as a slippage check,\n    /// deadline The time by which the transaction must be included to effect the change\n    /// @param swapData The address of the external router and call data\n    /// @return liquidity The new liquidity amount as a result of the increase\n    /// @return amount0 The amount of token0 to achieve resulting liquidity\n    /// @return amount1 The amount of token1 to achieve resulting liquidity\n    function increaseLiquidityOptimal(\n        INPM.IncreaseLiquidityParams memory params,\n        bytes calldata swapData\n    ) external payable returns (uint128 liquidity, uint256 amount0, uint256 amount1);\n\n    /// @notice Decreases the amount of liquidity in a position and accounts it to the position\n    /// @dev Slippage check is delegated to `NonfungiblePositionManager` via `DecreaseLiquidityParams`.\n    /// It is applied on the principal amounts excluding trading fees.\n    /// @param params tokenId The ID of the token for which liquidity is being decreased,\n    /// liquidity The amount by which liquidity will be decreased,\n    /// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,\n    /// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,\n    /// deadline The time by which the transaction must be included to effect the change\n    /// @param feePips The fee in pips to be collected\n    /// @return amount0 The amount of token0 returned minus fees\n    /// @return amount1 The amount of token1 returned minus fees\n    function decreaseLiquidity(\n        INPM.DecreaseLiquidityParams memory params,\n        uint256 feePips\n    ) external returns (uint256 amount0, uint256 amount1);\n\n    /// @notice Decreases the amount of liquidity in a position and accounts it to the position using permit\n    /// @dev Slippage check is delegated to `NonfungiblePositionManager` via `DecreaseLiquidityParams`.\n    /// It is applied on the principal amounts excluding trading fees.\n    /// @param params tokenId The ID of the token for which liquidity is being decreased,\n    /// liquidity The amount by which liquidity will be decreased,\n    /// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,\n    /// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,\n    /// deadline The time by which the transaction must be included to effect the change\n    /// @param feePips The fee in pips to be collected\n    /// @param permitDeadline The deadline of the permit signature\n    /// @param v The recovery byte of the signature\n    /// @param r Half of the ECDSA signature pair\n    /// @param s Half of the ECDSA signature pair\n    /// @return amount0 The amount of token0 returned minus fees\n    /// @return amount1 The amount of token1 returned minus fees\n    function decreaseLiquidity(\n        INPM.DecreaseLiquidityParams memory params,\n        uint256 feePips,\n        uint256 permitDeadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external returns (uint256 amount0, uint256 amount1);\n\n    /// @notice Decreases the amount of liquidity in a position and swaps to a single token\n    /// @dev Slippage check is enforced by specifying `amount0Min` when `token0` is the target token\n    /// and `amount1Min` otherwise, applied after transaction fees.\n    /// @param params tokenId The ID of the token for which liquidity is being decreased,\n    /// liquidity The amount by which liquidity will be decreased,\n    /// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,\n    /// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,\n    /// deadline The time by which the transaction must be included to effect the change\n    /// @param zeroForOne True if token0 is being swapped for token1, false otherwise\n    /// @param feePips The fee in pips to be collected\n    /// @param swapData The address of the external router and call data\n    /// @return amount The total amount of desired token returned minus fees\n    function decreaseLiquiditySingle(\n        INPM.DecreaseLiquidityParams memory params,\n        bool zeroForOne,\n        uint256 feePips,\n        bytes calldata swapData\n    ) external returns (uint256 amount);\n\n    /// @notice Decreases the amount of liquidity in a position and swaps to a single token using permit\n    /// @dev Slippage check is enforced by specifying `amount0Min` when `token0` is the target token\n    /// and `amount1Min` otherwise, applied after transaction fees.\n    /// @param params tokenId The ID of the token for which liquidity is being decreased,\n    /// liquidity The amount by which liquidity will be decreased,\n    /// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,\n    /// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,\n    /// deadline The time by which the transaction must be included to effect the change\n    /// @param zeroForOne True if token0 is being swapped for token1, false otherwise\n    /// @param feePips The fee in pips to be collected\n    /// @param swapData The address of the external router and call data\n    /// @param permitDeadline The deadline of the permit signature\n    /// @param v The recovery byte of the signature\n    /// @param r Half of the ECDSA signature pair\n    /// @param s Half of the ECDSA signature pair\n    /// @return amount The total amount of desired token returned minus fees\n    function decreaseLiquiditySingle(\n        INPM.DecreaseLiquidityParams memory params,\n        bool zeroForOne,\n        uint256 feePips,\n        bytes calldata swapData,\n        uint256 permitDeadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external returns (uint256 amount);\n\n    /// @notice Removes all liquidity from a position\n    /// @dev Slippage check is delegated to `NonfungiblePositionManager` via `DecreaseLiquidityParams`.\n    /// It is applied on the principal amounts excluding trading fees.\n    /// @param params tokenId The ID of the token for which liquidity is being removed,\n    /// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,\n    /// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,\n    /// deadline The time by which the transaction must be included to effect the change\n    /// @param feePips The fee in pips to be collected\n    /// @return amount0 The amount of token0 returned minus fees\n    /// @return amount1 The amount of token1 returned minus fees\n    function removeLiquidity(\n        INPM.DecreaseLiquidityParams memory params,\n        uint256 feePips\n    ) external returns (uint256 amount0, uint256 amount1);\n\n    /// @notice Removes all liquidity from a position using permit\n    /// @dev Slippage check is delegated to `NonfungiblePositionManager` via `DecreaseLiquidityParams`.\n    /// It is applied on the principal amounts excluding trading fees.\n    /// @param params tokenId The ID of the token for which liquidity is being removed,\n    /// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,\n    /// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,\n    /// deadline The time by which the transaction must be included to effect the change\n    /// @param feePips The fee in pips to be collected\n    /// @param permitDeadline The deadline of the permit signature\n    /// @param v The recovery byte of the signature\n    /// @param r Half of the ECDSA signature pair\n    /// @param s Half of the ECDSA signature pair\n    /// @return amount0 The amount of token0 returned minus fees\n    /// @return amount1 The amount of token1 returned minus fees\n    function removeLiquidity(\n        INPM.DecreaseLiquidityParams memory params,\n        uint256 feePips,\n        uint256 permitDeadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external returns (uint256 amount0, uint256 amount1);\n\n    /// @notice Removes all liquidity from a position and swaps to a single token\n    /// @dev Slippage check is enforced by specifying `amount0Min` when `token0` is the target token\n    /// and `amount1Min` otherwise, applied after transaction fees.\n    /// @param params tokenId The ID of the token for which liquidity is being removed,\n    /// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,\n    /// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,\n    /// deadline The time by which the transaction must be included to effect the change\n    /// @param zeroForOne True if token0 is being swapped for token1, false otherwise\n    /// @param feePips The fee in pips to be collected\n    /// @param swapData The address of the external router and call data\n    /// @return amount The total amount of desired token returned minus fees\n    function removeLiquiditySingle(\n        INPM.DecreaseLiquidityParams memory params,\n        bool zeroForOne,\n        uint256 feePips,\n        bytes calldata swapData\n    ) external returns (uint256 amount);\n\n    /// @notice Removes all liquidity from a position and swaps to a single token using permit\n    /// @dev Slippage check is enforced by specifying `amount0Min` when `token0` is the target token\n    /// and `amount1Min` otherwise, applied after transaction fees.\n    /// @param params tokenId The ID of the token for which liquidity is being removed,\n    /// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,\n    /// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,\n    /// deadline The time by which the transaction must be included to effect the change\n    /// @param zeroForOne True if token0 is being swapped for token1, false otherwise\n    /// @param feePips The fee in pips to be collected\n    /// @param swapData The address of the external router and call data\n    /// @param permitDeadline The deadline of the permit signature\n    /// @param v The recovery byte of the signature\n    /// @param r Half of the ECDSA signature pair\n    /// @param s Half of the ECDSA signature pair\n    /// @return amount The total amount of desired token returned minus fees\n    function removeLiquiditySingle(\n        INPM.DecreaseLiquidityParams memory params,\n        bool zeroForOne,\n        uint256 feePips,\n        bytes calldata swapData,\n        uint256 permitDeadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external returns (uint256 amount);\n\n    /// @notice Reinvests all fees owed to a specific position to the same position using optimal swap\n    /// @param params tokenId The ID of the token for which liquidity is being increased,\n    /// amount0Desired The desired amount of token0 to be spent,\n    /// amount1Desired The desired amount of token1 to be spent,\n    /// amount0Min The minimum amount of token0 to spend, which serves as a slippage check,\n    /// amount1Min The minimum amount of token1 to spend, which serves as a slippage check,\n    /// deadline The time by which the transaction must be included to effect the change\n    /// @param feePips The fee in pips to be collected\n    /// @param swapData The address of the external router and call data\n    /// @return liquidity The new liquidity amount as a result of the increase\n    /// @return amount0 The amount of token0 to achieve resulting liquidity\n    /// @return amount1 The amount of token1 to achieve resulting liquidity\n    function reinvest(\n        INPM.IncreaseLiquidityParams memory params,\n        uint256 feePips,\n        bytes calldata swapData\n    ) external returns (uint128 liquidity, uint256 amount0, uint256 amount1);\n\n    /// @notice Reinvests all fees owed to a specific position to the same position using optimal swap and permit\n    /// @param params tokenId The ID of the token for which liquidity is being increased,\n    /// amount0Desired The desired amount of token0 to be spent,\n    /// amount1Desired The desired amount of token1 to be spent,\n    /// amount0Min The minimum amount of token0 to spend, which serves as a slippage check,\n    /// amount1Min The minimum amount of token1 to spend, which serves as a slippage check,\n    /// deadline The time by which the transaction must be included to effect the change\n    /// @param feePips The fee in pips to be collected\n    /// @param swapData The address of the external router and call data\n    /// @param permitDeadline The deadline of the permit signature\n    /// @param v The recovery byte of the signature\n    /// @param r Half of the ECDSA signature pair\n    /// @param s Half of the ECDSA signature pair\n    /// @return liquidity The new liquidity amount as a result of the increase\n    /// @return amount0 The amount of token0 to achieve resulting liquidity\n    /// @return amount1 The amount of token1 to achieve resulting liquidity\n    function reinvest(\n        INPM.IncreaseLiquidityParams memory params,\n        uint256 feePips,\n        bytes calldata swapData,\n        uint256 permitDeadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external returns (uint128 liquidity, uint256 amount0, uint256 amount1);\n\n    /// @notice Rebalances a position to a new tick range\n    /// @param params The params of the target position after rebalance\n    /// token0 The address of the token0 for a specific pool\n    /// token1 The address of the token1 for a specific pool\n    /// fee The fee associated with the pool\n    /// tickLower The lower tick of the position in which to add liquidity\n    /// tickUpper The upper tick of the position in which to add liquidity\n    /// amount0Desired The desired amount of token0 to be spent\n    /// amount1Desired The desired amount of token1 to be spent\n    /// amount0Min The minimum amount of token0 to spend, which serves as a slippage check\n    /// amount1Min The minimum amount of token1 to spend, which serves as a slippage check\n    /// recipient The recipient of the minted position\n    /// deadline The time by which the transaction must be included to effect the change\n    /// @param tokenId The ID of the position to rebalance\n    /// @param feePips The fee in pips to be collected\n    /// @param swapData The address of the external router and call data\n    /// @return newTokenId The ID of the new position\n    /// @return liquidity The amount of liquidity in the new position\n    /// @return amount0 The amount of token0 in the new position\n    /// @return amount1 The amount of token1 in the new position\n    function rebalance(\n        INPM.MintParams memory params,\n        uint256 tokenId,\n        uint256 feePips,\n        bytes calldata swapData\n    ) external returns (uint256 newTokenId, uint128 liquidity, uint256 amount0, uint256 amount1);\n\n    /// @notice Rebalances a position to a new tick range using permit\n    /// @param params The params of the target position after rebalance\n    /// token0 The address of the token0 for a specific pool\n    /// token1 The address of the token1 for a specific pool\n    /// fee The fee associated with the pool\n    /// tickLower The lower tick of the position in which to add liquidity\n    /// tickUpper The upper tick of the position in which to add liquidity\n    /// amount0Desired The desired amount of token0 to be spent\n    /// amount1Desired The desired amount of token1 to be spent\n    /// amount0Min The minimum amount of token0 to spend, which serves as a slippage check\n    /// amount1Min The minimum amount of token1 to spend, which serves as a slippage check\n    /// recipient The recipient of the minted position\n    /// deadline The time by which the transaction must be included to effect the change\n    /// @param tokenId The ID of the position to rebalance\n    /// @param feePips The fee in pips to be collected\n    /// @param swapData The address of the external router and call data\n    /// @param permitDeadline The deadline of the permit signature\n    /// @param v The recovery byte of the signature\n    /// @param r Half of the ECDSA signature pair\n    /// @param s Half of the ECDSA signature pair\n    /// @return newTokenId The ID of the new position\n    /// @return liquidity The amount of liquidity in the new position\n    /// @return amount0 The amount of token0 in the new position\n    /// @return amount1 The amount of token1 in the new position\n    function rebalance(\n        INPM.MintParams memory params,\n        uint256 tokenId,\n        uint256 feePips,\n        bytes calldata swapData,\n        uint256 permitDeadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external returns (uint256 newTokenId, uint128 liquidity, uint256 amount0, uint256 amount1);\n}\n\ninterface IUniV3Automan is IAutoman, IUniV3Immutables, IUniswapV3SwapCallback {}\ninterface IPCSV3Automan is IAutoman, IPCSV3Immutables, IPancakeV3SwapCallback {}\n"
      },
      "src/libraries/OptimalSwap.sol": {
        "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity >=0.8.8;\n\nimport \"@aperture_finance/uni-v3-lib/src/SwapMath.sol\";\nimport \"@aperture_finance/uni-v3-lib/src/TickBitmap.sol\";\nimport \"@aperture_finance/uni-v3-lib/src/TickMath.sol\";\n\n/// @title Optimal Swap Library\n/// @author Aperture Finance\n/// @notice Optimal library for optimal double-sided Uniswap v3 liquidity provision using closed form solution\nlibrary OptimalSwap {\n    using TickMath for int24;\n    using FullMath for uint256;\n    using UnsafeMath for uint256;\n\n    uint256 internal constant MAX_FEE_PIPS = 1e6;\n\n    error Invalid_Pool();\n    error Invalid_Tick_Range();\n    error Math_Overflow();\n\n    struct SwapState {\n        // liquidity in range after swap, accessible by `mload(state)`\n        uint128 liquidity;\n        // sqrt(price) after swap, accessible by `mload(add(state, 0x20))`\n        uint256 sqrtPriceX96;\n        // tick after swap, accessible by `mload(add(state, 0x40))`\n        int24 tick;\n        // The desired amount of token0 to add liquidity, `mload(add(state, 0x60))`\n        uint256 amount0Desired;\n        // The desired amount of token1 to add liquidity, `mload(add(state, 0x80))`\n        uint256 amount1Desired;\n        // sqrt(price) at the lower tick, `mload(add(state, 0xa0))`\n        uint256 sqrtRatioLowerX96;\n        // sqrt(price) at the upper tick, `mload(add(state, 0xc0))`\n        uint256 sqrtRatioUpperX96;\n        // the fee taken from the input amount, expressed in hundredths of a bip\n        // accessible by `mload(add(state, 0xe0))`\n        uint256 feePips;\n        // the tick spacing of the pool, accessible by `mload(add(state, 0x100))`\n        int24 tickSpacing;\n    }\n\n    /// @notice Get swap amount, output amount, swap direction for double-sided optimal deposit\n    /// @dev Given the elegant analytic solution and custom optimizations to Uniswap libraries,\n    /// the amount of gas is at the order of 10k depending on the swap amount and the number of ticks crossed,\n    /// an order of magnitude less than that achieved by binary search, which can be calculated on-chain.\n    /// @param pool Uniswap v3 pool\n    /// @param tickLower The lower tick of the position in which to add liquidity\n    /// @param tickUpper The upper tick of the position in which to add liquidity\n    /// @param amount0Desired The desired amount of token0 to be spent\n    /// @param amount1Desired The desired amount of token1 to be spent\n    /// @return amountIn The optimal swap amount\n    /// @return amountOut Expected output amount\n    /// @return zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0\n    /// @return sqrtPriceX96 The sqrt(price) after the swap\n    function getOptimalSwap(\n        V3PoolCallee pool,\n        int24 tickLower,\n        int24 tickUpper,\n        uint256 amount0Desired,\n        uint256 amount1Desired\n    ) internal view returns (uint256 amountIn, uint256 amountOut, bool zeroForOne, uint160 sqrtPriceX96) {\n        if (amount0Desired == 0 && amount1Desired == 0) return (0, 0, false, 0);\n        if (tickLower >= tickUpper || tickLower < TickMath.MIN_TICK || tickUpper > TickMath.MAX_TICK)\n            revert Invalid_Tick_Range();\n        // Ensure the pool exists.\n        assembly (\"memory-safe\") {\n            let poolCodeSize := extcodesize(pool)\n            if iszero(poolCodeSize) {\n                // revert Invalid_Pool()\n                mstore(0, 0x01ac05a5)\n                revert(0x1c, 0x04)\n            }\n        }\n        // intermediate state cache\n        SwapState memory state;\n        // Populate `SwapState` with hardcoded offsets.\n        {\n            int24 tick;\n            (sqrtPriceX96, tick) = pool.sqrtPriceX96AndTick();\n            assembly (\"memory-safe\") {\n                // state.tick = tick\n                mstore(add(state, 0x40), tick)\n            }\n        }\n        {\n            uint128 liquidity = pool.liquidity();\n            uint256 feePips = pool.fee();\n            int24 tickSpacing = pool.tickSpacing();\n            assembly (\"memory-safe\") {\n                // state.liquidity = liquidity\n                mstore(state, liquidity)\n                // state.sqrtPriceX96 = sqrtPriceX96\n                mstore(add(state, 0x20), sqrtPriceX96)\n                // state.amount0Desired = amount0Desired\n                mstore(add(state, 0x60), amount0Desired)\n                // state.amount1Desired = amount1Desired\n                mstore(add(state, 0x80), amount1Desired)\n                // state.feePips = feePips\n                mstore(add(state, 0xe0), feePips)\n                // state.tickSpacing = tickSpacing\n                mstore(add(state, 0x100), tickSpacing)\n            }\n        }\n        uint160 sqrtRatioLowerX96 = tickLower.getSqrtRatioAtTick();\n        uint160 sqrtRatioUpperX96 = tickUpper.getSqrtRatioAtTick();\n        assembly (\"memory-safe\") {\n            // state.sqrtRatioLowerX96 = sqrtRatioLowerX96\n            mstore(add(state, 0xa0), sqrtRatioLowerX96)\n            // state.sqrtRatioUpperX96 = sqrtRatioUpperX96\n            mstore(add(state, 0xc0), sqrtRatioUpperX96)\n        }\n        zeroForOne = isZeroForOne(amount0Desired, amount1Desired, sqrtPriceX96, sqrtRatioLowerX96, sqrtRatioUpperX96);\n        // Simulate optimal swap by crossing ticks until the direction reverses.\n        crossTicks(pool, state, sqrtPriceX96, zeroForOne);\n        // Active liquidity at the last tick of optimal swap\n        uint128 liquidityLast;\n        // sqrt(price) at the last tick of optimal swap\n        uint160 sqrtPriceLastTickX96;\n        // Remaining amount of token0 to add liquidity at the last tick\n        uint256 amount0LastTick;\n        // Remaining amount of token1 to add liquidity at the last tick\n        uint256 amount1LastTick;\n        assembly (\"memory-safe\") {\n            // liquidityLast = state.liquidity\n            liquidityLast := mload(state)\n            // sqrtPriceLastTickX96 = state.sqrtPriceX96\n            sqrtPriceLastTickX96 := mload(add(state, 0x20))\n            // amount0LastTick = state.amount0Desired\n            amount0LastTick := mload(add(state, 0x60))\n            // amount1LastTick = state.amount1Desired\n            amount1LastTick := mload(add(state, 0x80))\n        }\n        unchecked {\n            if (!zeroForOne) {\n                // The last tick is out of range. There are two cases:\n                // 1. There is not enough token1 to swap to reach the lower tick.\n                // 2. There is no initialized tick between the last tick and the lower tick.\n                if (sqrtPriceLastTickX96 < sqrtRatioLowerX96) {\n                    sqrtPriceX96 = SqrtPriceMath.getNextSqrtPriceFromAmount1RoundingDown(\n                        sqrtPriceLastTickX96,\n                        liquidityLast,\n                        amount1LastTick.mulDiv(MAX_FEE_PIPS - state.feePips, MAX_FEE_PIPS),\n                        true\n                    );\n                    // The final price is out of range. Simply consume all token1.\n                    if (sqrtPriceX96 < sqrtRatioLowerX96) {\n                        amountIn = amount1Desired;\n                    }\n                    // Swap to the lower tick and update the state.\n                    else {\n                        amount1LastTick -= SqrtPriceMath\n                            .getAmount1Delta(sqrtPriceLastTickX96, sqrtRatioLowerX96, liquidityLast, true)\n                            .mulDiv(MAX_FEE_PIPS, MAX_FEE_PIPS - state.feePips);\n                        amount0LastTick += SqrtPriceMath.getAmount0Delta(\n                            sqrtPriceLastTickX96,\n                            sqrtRatioLowerX96,\n                            liquidityLast,\n                            false\n                        );\n                        sqrtPriceLastTickX96 = sqrtRatioLowerX96;\n                        state.sqrtPriceX96 = sqrtPriceLastTickX96;\n                        state.amount0Desired = amount0LastTick;\n                        state.amount1Desired = amount1LastTick;\n                    }\n                }\n                // The final price is in range. Use the closed form solution.\n                if (sqrtPriceLastTickX96 >= sqrtRatioLowerX96) {\n                    sqrtPriceX96 = solveOptimalOneForZero(state);\n                    amountIn =\n                        amount1Desired -\n                        amount1LastTick +\n                        SqrtPriceMath.getAmount1Delta(sqrtPriceX96, sqrtPriceLastTickX96, liquidityLast, true).mulDiv(\n                            MAX_FEE_PIPS,\n                            MAX_FEE_PIPS - state.feePips\n                        );\n                }\n                amountOut =\n                    amount0LastTick -\n                    amount0Desired +\n                    SqrtPriceMath.getAmount0Delta(sqrtPriceX96, sqrtPriceLastTickX96, liquidityLast, false);\n            } else {\n                // The last tick is out of range. There are two cases:\n                // 1. There is not enough token0 to swap to reach the upper tick.\n                // 2. There is no initialized tick between the last tick and the upper tick.\n                if (sqrtPriceLastTickX96 > sqrtRatioUpperX96) {\n                    sqrtPriceX96 = SqrtPriceMath.getNextSqrtPriceFromAmount0RoundingUp(\n                        sqrtPriceLastTickX96,\n                        liquidityLast,\n                        amount0LastTick.mulDiv(MAX_FEE_PIPS - state.feePips, MAX_FEE_PIPS),\n                        true\n                    );\n                    // The final price is out of range. Simply consume all token0.\n                    if (sqrtPriceX96 >= sqrtRatioUpperX96) {\n                        amountIn = amount0Desired;\n                    }\n                    // Swap to the upper tick and update the state.\n                    else {\n                        amount0LastTick -= SqrtPriceMath\n                            .getAmount0Delta(sqrtRatioUpperX96, sqrtPriceLastTickX96, liquidityLast, true)\n                            .mulDiv(MAX_FEE_PIPS, MAX_FEE_PIPS - state.feePips);\n                        amount1LastTick += SqrtPriceMath.getAmount1Delta(\n                            sqrtRatioUpperX96,\n                            sqrtPriceLastTickX96,\n                            liquidityLast,\n                            false\n                        );\n                        sqrtPriceLastTickX96 = sqrtRatioUpperX96;\n                        state.sqrtPriceX96 = sqrtPriceLastTickX96;\n                        state.amount0Desired = amount0LastTick;\n                        state.amount1Desired = amount1LastTick;\n                    }\n                }\n                // The final price is in range. Use the closed form solution.\n                if (sqrtPriceLastTickX96 <= sqrtRatioUpperX96) {\n                    sqrtPriceX96 = solveOptimalZeroForOne(state);\n                    amountIn =\n                        amount0Desired -\n                        amount0LastTick +\n                        SqrtPriceMath.getAmount0Delta(sqrtPriceX96, sqrtPriceLastTickX96, liquidityLast, true).mulDiv(\n                            MAX_FEE_PIPS,\n                            MAX_FEE_PIPS - state.feePips\n                        );\n                }\n                amountOut =\n                    amount1LastTick -\n                    amount1Desired +\n                    SqrtPriceMath.getAmount1Delta(sqrtPriceX96, sqrtPriceLastTickX96, liquidityLast, false);\n            }\n        }\n    }\n\n    /// @dev Check if the remaining amount is enough to cross the next initialized tick.\n    // If so, check whether the swap direction changes for optimal deposit. If so, we swap too much and the final sqrt\n    // price must be between the current tick and the next tick. Otherwise the next tick must be crossed.\n    function crossTicks(V3PoolCallee pool, SwapState memory state, uint160 sqrtPriceX96, bool zeroForOne) private view {\n        // the next tick to swap to from the current tick in the swap direction\n        int24 tickNext;\n        // Ensure the initial `wordPos` doesn't coincide with the starting tick's.\n        int16 wordPos = type(int16).min;\n        // a word in `pool.tickBitmap`\n        uint256 tickWord;\n\n        do {\n            (tickNext, wordPos, tickWord) = TickBitmap.nextInitializedTick(\n                pool,\n                state.tick,\n                state.tickSpacing,\n                zeroForOne,\n                wordPos,\n                tickWord\n            );\n            // sqrt(price) for the next tick (1/0)\n            uint160 sqrtPriceNextX96 = tickNext.getSqrtRatioAtTick();\n            // The desired amount of token0 to add liquidity after swap\n            uint256 amount0Desired;\n            // The desired amount of token1 to add liquidity after swap\n            uint256 amount1Desired;\n\n            unchecked {\n                if (!zeroForOne) {\n                    // Abuse `amount1Desired` to store `amountIn` to avoid stack too deep errors.\n                    (sqrtPriceX96, amount1Desired, amount0Desired) = SwapMath.computeSwapStepExactIn(\n                        uint160(state.sqrtPriceX96),\n                        sqrtPriceNextX96,\n                        state.liquidity,\n                        state.amount1Desired,\n                        state.feePips\n                    );\n                    amount0Desired = state.amount0Desired + amount0Desired;\n                    amount1Desired = state.amount1Desired - amount1Desired;\n                } else {\n                    // Abuse `amount0Desired` to store `amountIn` to avoid stack too deep errors.\n                    (sqrtPriceX96, amount0Desired, amount1Desired) = SwapMath.computeSwapStepExactIn(\n                        uint160(state.sqrtPriceX96),\n                        sqrtPriceNextX96,\n                        state.liquidity,\n                        state.amount0Desired,\n                        state.feePips\n                    );\n                    amount0Desired = state.amount0Desired - amount0Desired;\n                    amount1Desired = state.amount1Desired + amount1Desired;\n                }\n            }\n\n            // If the remaining amount is large enough to consume the current tick and the optimal swap direction\n            // doesn't change, continue crossing ticks.\n            if (sqrtPriceX96 != sqrtPriceNextX96) break;\n            if (\n                isZeroForOne(\n                    amount0Desired,\n                    amount1Desired,\n                    sqrtPriceX96,\n                    state.sqrtRatioLowerX96,\n                    state.sqrtRatioUpperX96\n                ) != zeroForOne\n            ) {\n                break;\n            } else {\n                int128 liquidityNet = pool.liquidityNet(tickNext);\n                assembly (\"memory-safe\") {\n                    // If we're moving leftward, we interpret `liquidityNet` as the opposite sign.\n                    // If zeroForOne, liquidityNet = -liquidityNet = ~liquidityNet + 1 = -1 ^ liquidityNet + 1.\n                    // Therefore, liquidityNet = -zeroForOne ^ liquidityNet + zeroForOne.\n                    liquidityNet := add(zeroForOne, xor(sub(0, zeroForOne), liquidityNet))\n                    // `liquidity` is the first in `SwapState`\n                    mstore(state, add(mload(state), liquidityNet))\n                    // state.sqrtPriceX96 = sqrtPriceX96\n                    mstore(add(state, 0x20), sqrtPriceX96)\n                    // state.tick = zeroForOne ? tickNext - 1 : tickNext\n                    mstore(add(state, 0x40), sub(tickNext, zeroForOne))\n                    // state.amount0Desired = amount0Desired\n                    mstore(add(state, 0x60), amount0Desired)\n                    // state.amount1Desired = amount1Desired\n                    mstore(add(state, 0x80), amount1Desired)\n                }\n            }\n        } while (true);\n    }\n\n    /// @dev Analytic solution for optimal swap between two nearest initialized ticks swapping token0 to token1\n    /// @param state Pool state at the last tick of optimal swap\n    /// @return sqrtPriceFinalX96 sqrt(price) after optimal swap\n    function solveOptimalZeroForOne(SwapState memory state) private pure returns (uint160 sqrtPriceFinalX96) {\n        /**\n         * root = (sqrt(b^2 + 4ac) + b) / 2a\n         * `a` is in the order of `amount0Desired`. `b` is in the order of `liquidity`.\n         * `c` is in the order of `amount1Desired`.\n         * `a`, `b`, `c` are signed integers in two's complement but typed as unsigned to avoid unnecessary casting.\n         */\n        uint256 a;\n        uint256 b;\n        uint256 c;\n        uint256 sqrtPriceX96;\n        unchecked {\n            uint256 liquidity;\n            uint256 sqrtRatioLowerX96;\n            uint256 sqrtRatioUpperX96;\n            uint256 feePips;\n            uint256 FEE_COMPLEMENT;\n            assembly (\"memory-safe\") {\n                // liquidity = state.liquidity\n                liquidity := mload(state)\n                // sqrtPriceX96 = state.sqrtPriceX96\n                sqrtPriceX96 := mload(add(state, 0x20))\n                // sqrtRatioLowerX96 = state.sqrtRatioLowerX96\n                sqrtRatioLowerX96 := mload(add(state, 0xa0))\n                // sqrtRatioUpperX96 = state.sqrtRatioUpperX96\n                sqrtRatioUpperX96 := mload(add(state, 0xc0))\n                // feePips = state.feePips\n                feePips := mload(add(state, 0xe0))\n                // FEE_COMPLEMENT = MAX_FEE_PIPS - feePips\n                FEE_COMPLEMENT := sub(MAX_FEE_PIPS, feePips)\n            }\n            {\n                uint256 a0;\n                assembly (\"memory-safe\") {\n                    // amount0Desired = state.amount0Desired\n                    let amount0Desired := mload(add(state, 0x60))\n                    let liquidityX96 := shl(96, liquidity)\n                    // a = amount0Desired + liquidity / ((1 - f) * sqrtPrice) - liquidity / sqrtRatioUpper\n                    a0 := add(amount0Desired, div(mul(MAX_FEE_PIPS, liquidityX96), mul(FEE_COMPLEMENT, sqrtPriceX96)))\n                    a := sub(a0, div(liquidityX96, sqrtRatioUpperX96))\n                    // `a` is always positive and greater than `amount0Desired`.\n                    if iszero(gt(a, amount0Desired)) {\n                        // revert Math_Overflow()\n                        mstore(0, 0x20236808)\n                        revert(0x1c, 0x04)\n                    }\n                }\n                b = a0.mulDiv96(sqrtRatioLowerX96);\n                assembly {\n                    b := add(div(mul(feePips, liquidity), FEE_COMPLEMENT), b)\n                }\n            }\n            {\n                // c = amount1Desired + liquidity * sqrtPrice - liquidity * sqrtRatioLower / (1 - f)\n                uint256 c0 = liquidity.mulDiv96(sqrtPriceX96);\n                assembly (\"memory-safe\") {\n                    // c0 = amount1Desired + liquidity * sqrtPrice\n                    c0 := add(mload(add(state, 0x80)), c0)\n                }\n                c = c0 - liquidity.mulDiv96((MAX_FEE_PIPS * sqrtRatioLowerX96) / FEE_COMPLEMENT);\n                b -= c0.mulDiv(FixedPoint96.Q96, sqrtRatioUpperX96);\n            }\n            assembly {\n                a := shl(1, a)\n                c := shl(1, c)\n            }\n        }\n        // Given a root exists, the following calculations cannot realistically overflow/underflow.\n        unchecked {\n            uint256 numerator = FullMath.sqrt(b * b + a * c) + b;\n            assembly {\n                // `numerator` and `a` must be positive so use `div`.\n                sqrtPriceFinalX96 := div(shl(96, numerator), a)\n            }\n        }\n        // The final price must be less than or equal to the price at the last tick.\n        // However the calculated price may increase if the ratio is close to optimal.\n        assembly {\n            // sqrtPriceFinalX96 = min(sqrtPriceFinalX96, sqrtPriceX96)\n            sqrtPriceFinalX96 := xor(\n                sqrtPriceX96,\n                mul(xor(sqrtPriceX96, sqrtPriceFinalX96), lt(sqrtPriceFinalX96, sqrtPriceX96))\n            )\n        }\n    }\n\n    /// @dev Analytic solution for optimal swap between two nearest initialized ticks swapping token1 to token0\n    /// @param state Pool state at the last tick of optimal swap\n    /// @return sqrtPriceFinalX96 sqrt(price) after optimal swap\n    function solveOptimalOneForZero(SwapState memory state) private pure returns (uint160 sqrtPriceFinalX96) {\n        /**\n         * root = (sqrt(b^2 + 4ac) + b) / 2a\n         * `a` is in the order of `amount0Desired`. `b` is in the order of `liquidity`.\n         * `c` is in the order of `amount1Desired`.\n         * `a`, `b`, `c` are signed integers in two's complement but typed as unsigned to avoid unnecessary casting.\n         */\n        uint256 a;\n        uint256 b;\n        uint256 c;\n        uint256 sqrtPriceX96;\n        unchecked {\n            uint256 liquidity;\n            uint256 sqrtRatioLowerX96;\n            uint256 sqrtRatioUpperX96;\n            uint256 feePips;\n            uint256 FEE_COMPLEMENT;\n            assembly (\"memory-safe\") {\n                // liquidity = state.liquidity\n                liquidity := mload(state)\n                // sqrtPriceX96 = state.sqrtPriceX96\n                sqrtPriceX96 := mload(add(state, 0x20))\n                // sqrtRatioLowerX96 = state.sqrtRatioLowerX96\n                sqrtRatioLowerX96 := mload(add(state, 0xa0))\n                // sqrtRatioUpperX96 = state.sqrtRatioUpperX96\n                sqrtRatioUpperX96 := mload(add(state, 0xc0))\n                // feePips = state.feePips\n                feePips := mload(add(state, 0xe0))\n                // FEE_COMPLEMENT = MAX_FEE_PIPS - feePips\n                FEE_COMPLEMENT := sub(MAX_FEE_PIPS, feePips)\n            }\n            {\n                // a = state.amount0Desired + liquidity / sqrtPrice - liquidity / ((1 - f) * sqrtRatioUpper)\n                uint256 a0;\n                assembly (\"memory-safe\") {\n                    let liquidityX96 := shl(96, liquidity)\n                    // a0 = state.amount0Desired + liquidity / sqrtPrice\n                    a0 := add(mload(add(state, 0x60)), div(liquidityX96, sqrtPriceX96))\n                    a := sub(a0, div(mul(MAX_FEE_PIPS, liquidityX96), mul(FEE_COMPLEMENT, sqrtRatioUpperX96)))\n                }\n                b = a0.mulDiv96(sqrtRatioLowerX96);\n                assembly {\n                    b := sub(b, div(mul(feePips, liquidity), FEE_COMPLEMENT))\n                }\n            }\n            {\n                // c = amount1Desired + liquidity * sqrtPrice / (1 - f) - liquidity * sqrtRatioLower\n                uint256 c0 = liquidity.mulDiv96((MAX_FEE_PIPS * sqrtPriceX96) / FEE_COMPLEMENT);\n                uint256 amount1Desired;\n                assembly (\"memory-safe\") {\n                    // amount1Desired = state.amount1Desired\n                    amount1Desired := mload(add(state, 0x80))\n                    // c0 = amount1Desired + liquidity * sqrtPrice / (1 - f)\n                    c0 := add(amount1Desired, c0)\n                }\n                c = c0 - liquidity.mulDiv96(sqrtRatioLowerX96);\n                assembly (\"memory-safe\") {\n                    // `c` is always positive and greater than `amount1Desired`.\n                    if iszero(gt(c, amount1Desired)) {\n                        // revert Math_Overflow()\n                        mstore(0, 0x20236808)\n                        revert(0x1c, 0x04)\n                    }\n                }\n                b -= c0.mulDiv(FixedPoint96.Q96, state.sqrtRatioUpperX96);\n            }\n            assembly {\n                a := shl(1, a)\n                c := shl(1, c)\n            }\n        }\n        // Given a root exists, the following calculations cannot realistically overflow/underflow.\n        unchecked {\n            uint256 numerator = FullMath.sqrt(b * b + a * c) + b;\n            assembly {\n                // `numerator` and `a` may be negative so use `sdiv`.\n                sqrtPriceFinalX96 := sdiv(shl(96, numerator), a)\n            }\n        }\n        // The final price must be greater than or equal to the price at the last tick.\n        // However the calculated price may decrease if the ratio is close to optimal.\n        assembly {\n            // sqrtPriceFinalX96 = max(sqrtPriceFinalX96, sqrtPriceX96)\n            sqrtPriceFinalX96 := xor(\n                sqrtPriceX96,\n                mul(xor(sqrtPriceX96, sqrtPriceFinalX96), gt(sqrtPriceFinalX96, sqrtPriceX96))\n            )\n        }\n    }\n\n    /// @dev Swap direction to achieve optimal deposit when the current price is in range\n    /// @param amount0Desired The desired amount of token0 to be spent\n    /// @param amount1Desired The desired amount of token1 to be spent\n    /// @param sqrtPriceX96 sqrt(price) at the last tick of optimal swap\n    /// @param sqrtRatioLowerX96 The lower sqrt(price) of the position in which to add liquidity\n    /// @param sqrtRatioUpperX96 The upper sqrt(price) of the position in which to add liquidity\n    /// @return The direction of the swap, true for token0 to token1, false for token1 to token0\n    function isZeroForOneInRange(\n        uint256 amount0Desired,\n        uint256 amount1Desired,\n        uint256 sqrtPriceX96,\n        uint256 sqrtRatioLowerX96,\n        uint256 sqrtRatioUpperX96\n    ) private pure returns (bool) {\n        // amount0 = liquidity * (sqrt(upper) - sqrt(current)) / (sqrt(upper) * sqrt(current))\n        // amount1 = liquidity * (sqrt(current) - sqrt(lower))\n        // amount0 * amount1 = liquidity * (sqrt(upper) - sqrt(current)) / (sqrt(upper) * sqrt(current)) * amount1\n        //     = liquidity * (sqrt(current) - sqrt(lower)) * amount0\n        unchecked {\n            return\n                amount0Desired.mulDiv96(sqrtPriceX96).mulDiv96(sqrtPriceX96 - sqrtRatioLowerX96) >\n                amount1Desired.mulDiv(sqrtRatioUpperX96 - sqrtPriceX96, sqrtRatioUpperX96);\n        }\n    }\n\n    /// @dev Swap direction to achieve optimal deposit\n    /// @param amount0Desired The desired amount of token0 to be spent\n    /// @param amount1Desired The desired amount of token1 to be spent\n    /// @param sqrtPriceX96 sqrt(price) at the last tick of optimal swap\n    /// @param sqrtRatioLowerX96 The lower sqrt(price) of the position in which to add liquidity\n    /// @param sqrtRatioUpperX96 The upper sqrt(price) of the position in which to add liquidity\n    /// @return The direction of the swap, true for token0 to token1, false for token1 to token0\n    function isZeroForOne(\n        uint256 amount0Desired,\n        uint256 amount1Desired,\n        uint256 sqrtPriceX96,\n        uint256 sqrtRatioLowerX96,\n        uint256 sqrtRatioUpperX96\n    ) internal pure returns (bool) {\n        // If the current price is below `sqrtRatioLowerX96`, only token0 is required.\n        if (sqrtPriceX96 <= sqrtRatioLowerX96) return false;\n        // If the current tick is above `sqrtRatioUpperX96`, only token1 is required.\n        else if (sqrtPriceX96 >= sqrtRatioUpperX96) return true;\n        else\n            return\n                isZeroForOneInRange(amount0Desired, amount1Desired, sqrtPriceX96, sqrtRatioLowerX96, sqrtRatioUpperX96);\n    }\n}\n"
      },
      "src/libraries/ERC20Caller.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// User defined value types are introduced in Solidity v0.8.8.\n// https://blog.soliditylang.org/2021/09/27/user-defined-value-types/\npragma solidity ^0.8.8;\n\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\ntype ERC20Callee is address;\nusing ERC20Caller for ERC20Callee global;\n\n/// @title ERC20 Caller\n/// @author Aperture Finance\n/// @notice Gas efficient library to call ERC20 token assuming the token exists\nlibrary ERC20Caller {\n    /// @dev Equivalent to `IERC20.totalSupply`\n    /// @param token ERC20 token\n    function totalSupply(ERC20Callee token) internal view returns (uint256 amount) {\n        bytes4 selector = IERC20.totalSupply.selector;\n        assembly (\"memory-safe\") {\n            // Write the function selector into memory.\n            mstore(0, selector)\n            // We use 4 because of the length of our calldata.\n            // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.\n            // `totalSupply` should never revert according to the ERC20 standard.\n            if iszero(staticcall(gas(), token, 0, 4, 0, 0x20)) {\n                revert(0, 0)\n            }\n            amount := mload(0)\n        }\n    }\n\n    /// @dev Equivalent to `IERC20.balanceOf`\n    /// @param token ERC20 token\n    /// @param account Account to check balance of\n    function balanceOf(ERC20Callee token, address account) internal view returns (uint256 amount) {\n        bytes4 selector = IERC20.balanceOf.selector;\n        assembly (\"memory-safe\") {\n            // Write the abi-encoded calldata into memory.\n            mstore(0, selector)\n            mstore(4, account)\n            // We use 36 because of the length of our calldata.\n            // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.\n            // `balanceOf` should never revert according to the ERC20 standard.\n            if iszero(staticcall(gas(), token, 0, 0x24, 0, 0x20)) {\n                revert(0, 0)\n            }\n            amount := mload(0)\n        }\n    }\n\n    /// @dev Equivalent to `IERC20.allowance`\n    /// @param token ERC20 token\n    /// @param owner Owner of the tokens\n    /// @param spender Spender of the tokens\n    function allowance(ERC20Callee token, address owner, address spender) internal view returns (uint256 amount) {\n        bytes4 selector = IERC20.allowance.selector;\n        assembly (\"memory-safe\") {\n            // Write the abi-encoded calldata into memory.\n            mstore(0, selector)\n            mstore(4, owner)\n            mstore(0x24, spender)\n            // We use 68 because of the length of our calldata.\n            // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.\n            // `allowance` should never revert according to the ERC20 standard.\n            if iszero(staticcall(gas(), token, 0, 0x44, 0, 0x20)) {\n                revert(0, 0)\n            }\n            amount := mload(0)\n            // Clear first 4 bytes of the free memory pointer.\n            mstore(0x24, 0)\n        }\n    }\n\n    /// @dev Equivalent to `IERC20Metadata.decimals` with 18 as fallback\n    /// @param token ERC20 token\n    function decimals(ERC20Callee token) internal view returns (uint8 d) {\n        bytes4 selector = IERC20Metadata.decimals.selector;\n        assembly (\"memory-safe\") {\n            // Store 18 to memory to use as fallback.\n            mstore(0, 18)\n            // Write the function selector into memory.\n            mstore(0x20, selector)\n            let success := staticcall(gas(), token, 0x20, 4, 0x20, 0x20)\n            // Read from 0x20 if the call was successful, otherwise read from 0.\n            d := mload(shl(5, success))\n        }\n    }\n}\n"
      },
      "node_modules/@aperture_finance/uni-v3-lib/src/PoolAddress.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\nimport \"./PoolKey.sol\";\nimport \"./TernaryLib.sol\";\n\n/// @title Provides functions for deriving a pool address from the factory, tokens, and the fee\n/// @author Aperture Finance\n/// @author Modified from Uniswap (https://github.com/uniswap/v3-periphery/blob/main/contracts/libraries/PoolAddress.sol)\n/// @dev Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.\n/// However, this is safe because \"Note that you do not need to update the free memory pointer if there is no following\n/// allocation, but you can only use memory starting from the current offset given by the free memory pointer.\"\n/// according to https://docs.soliditylang.org/en/latest/assembly.html#memory-safety.\nlibrary PoolAddress {\n    bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54;\n\n    /// @notice Returns PoolKey: the ordered tokens with the matched fee levels\n    /// @param tokenA The first token of a pool, unsorted\n    /// @param tokenB The second token of a pool, unsorted\n    /// @param fee The fee level of the pool\n    /// @return key The pool details with ordered token0 and token1 assignments\n    function getPoolKey(address tokenA, address tokenB, uint24 fee) internal pure returns (PoolKey memory key) {\n        (tokenA, tokenB) = TernaryLib.sort2(tokenA, tokenB);\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Must inline this for best performance\n            mstore(key, tokenA)\n            mstore(add(key, 0x20), tokenB)\n            mstore(add(key, 0x40), fee)\n        }\n    }\n\n    /// @notice Returns PoolKey: the ordered tokens with the matched fee levels\n    /// @param token0 The first token of a pool, already sorted\n    /// @param token1 The second token of a pool, already sorted\n    /// @param fee The fee level of the pool\n    /// @return key The pool details with ordered token0 and token1 assignments\n    function getPoolKeySorted(address token0, address token1, uint24 fee) internal pure returns (PoolKey memory key) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            mstore(key, token0)\n            mstore(add(key, 0x20), token1)\n            mstore(add(key, 0x40), fee)\n        }\n    }\n\n    /// @notice Deterministically computes the pool address given the factory and PoolKey\n    /// @param factory The Uniswap V3 factory contract address\n    /// @param key The PoolKey\n    /// @return pool The contract address of the V3 pool\n    function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) {\n        require(key.token0 < key.token1);\n        return computeAddressSorted(factory, key);\n    }\n\n    /// @notice Deterministically computes the pool address given the factory and PoolKey\n    /// @dev Assumes PoolKey is sorted\n    /// @param factory The Uniswap V3 factory contract address\n    /// @param key The PoolKey\n    /// @return pool The contract address of the V3 pool\n    function computeAddressSorted(address factory, PoolKey memory key) internal pure returns (address pool) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Cache the free memory pointer.\n            let fmp := mload(0x40)\n            // abi.encodePacked(hex'ff', factory, poolHash, POOL_INIT_CODE_HASH)\n            // Prefix the factory address with 0xff.\n            mstore(0, or(factory, 0xff0000000000000000000000000000000000000000))\n            mstore(0x20, keccak256(key, 0x60))\n            mstore(0x40, POOL_INIT_CODE_HASH)\n            // Compute the CREATE2 pool address and clean the upper bits.\n            pool := and(keccak256(0x0b, 0x55), 0xffffffffffffffffffffffffffffffffffffffff)\n            // Restore the free memory pointer.\n            mstore(0x40, fmp)\n        }\n    }\n\n    /// @notice Deterministically computes the pool address given the factory, tokens, and the fee\n    /// @param factory The Uniswap V3 factory contract address\n    /// @param tokenA One of the tokens in the pool, unsorted\n    /// @param tokenB The other token in the pool, unsorted\n    /// @param fee The fee tier of the pool\n    function computeAddress(\n        address factory,\n        address tokenA,\n        address tokenB,\n        uint24 fee\n    ) internal pure returns (address pool) {\n        (tokenA, tokenB) = TernaryLib.sort2(tokenA, tokenB);\n        return computeAddressSorted(factory, tokenA, tokenB, fee);\n    }\n\n    /// @notice Deterministically computes the pool address given the factory, tokens, and the fee\n    /// @dev Assumes tokens are sorted\n    /// @param factory The Uniswap V3 factory contract address\n    /// @param token0 The first token of a pool, already sorted\n    /// @param token1 The second token of a pool, already sorted\n    /// @param fee The fee tier of the pool\n    function computeAddressSorted(\n        address factory,\n        address token0,\n        address token1,\n        uint24 fee\n    ) internal pure returns (address pool) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Cache the free memory pointer.\n            let fmp := mload(0x40)\n            // Hash the pool key.\n            mstore(0, token0)\n            mstore(0x20, token1)\n            mstore(0x40, fee)\n            let poolHash := keccak256(0, 0x60)\n            // abi.encodePacked(hex'ff', factory, poolHash, POOL_INIT_CODE_HASH)\n            // Prefix the factory address with 0xff.\n            mstore(0, or(factory, 0xff0000000000000000000000000000000000000000))\n            mstore(0x20, poolHash)\n            mstore(0x40, POOL_INIT_CODE_HASH)\n            // Compute the CREATE2 pool address and clean the upper bits.\n            pool := and(keccak256(0x0b, 0x55), 0xffffffffffffffffffffffffffffffffffffffff)\n            // Restore the free memory pointer.\n            mstore(0x40, fmp)\n        }\n    }\n\n    /// @notice Deterministically computes the pool address given the factory and PoolKey\n    /// @dev Uses PoolKey in calldata and assumes PoolKey is sorted\n    /// @param factory The Uniswap V3 factory contract address\n    /// @param key The abi encoded PoolKey of the V3 pool\n    /// @return pool The contract address of the V3 pool\n    function computeAddressCalldata(address factory, bytes calldata key) internal pure returns (address pool) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Cache the free memory pointer.\n            let fmp := mload(0x40)\n            // Hash the pool key.\n            calldatacopy(0, key.offset, 0x60)\n            let poolHash := keccak256(0, 0x60)\n            // abi.encodePacked(hex'ff', factory, poolHash, POOL_INIT_CODE_HASH)\n            // Prefix the factory address with 0xff.\n            mstore(0, or(factory, 0xff0000000000000000000000000000000000000000))\n            mstore(0x20, poolHash)\n            mstore(0x40, POOL_INIT_CODE_HASH)\n            // Compute the CREATE2 pool address and clean the upper bits.\n            pool := and(keccak256(0x0b, 0x55), 0xffffffffffffffffffffffffffffffffffffffff)\n            // Restore the free memory pointer.\n            mstore(0x40, fmp)\n        }\n    }\n}\n"
      },
      "node_modules/@aperture_finance/uni-v3-lib/src/PoolAddressPancakeSwapV3.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\nimport \"./PoolKey.sol\";\nimport \"./TernaryLib.sol\";\n\n/// @title Provides functions for deriving a pool address from the deployer, tokens, and the fee\n/// @author Aperture Finance\n/// @author Modified from PancakeSwapV3 (https://www.npmjs.com/package/@pancakeswap/v3-periphery?activeTab=code and look for contracts/libraries/PoolAddress.sol)\n/// @dev Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.\n/// However, this is safe because \"Note that you do not need to update the free memory pointer if there is no following\n/// allocation, but you can only use memory starting from the current offset given by the free memory pointer.\"\n/// according to https://docs.soliditylang.org/en/latest/assembly.html#memory-safety.\nlibrary PoolAddressPancakeSwapV3 {\n    bytes32 internal constant POOL_INIT_CODE_HASH = 0x6ce8eb472fa82df5469c6ab6d485f17c3ad13c8cd7af59b3d4a8026c5ce0f7e2;\n\n    /// @notice Returns PoolKey: the ordered tokens with the matched fee levels\n    /// @param tokenA The first token of a pool, unsorted\n    /// @param tokenB The second token of a pool, unsorted\n    /// @param fee The fee level of the pool\n    /// @return key The pool details with ordered token0 and token1 assignments\n    function getPoolKey(address tokenA, address tokenB, uint24 fee) internal pure returns (PoolKey memory key) {\n        (tokenA, tokenB) = TernaryLib.sort2(tokenA, tokenB);\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Must inline this for best performance\n            mstore(key, tokenA)\n            mstore(add(key, 0x20), tokenB)\n            mstore(add(key, 0x40), fee)\n        }\n    }\n\n    /// @notice Returns PoolKey: the ordered tokens with the matched fee levels\n    /// @param token0 The first token of a pool, already sorted\n    /// @param token1 The second token of a pool, already sorted\n    /// @param fee The fee level of the pool\n    /// @return key The pool details with ordered token0 and token1 assignments\n    function getPoolKeySorted(address token0, address token1, uint24 fee) internal pure returns (PoolKey memory key) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            mstore(key, token0)\n            mstore(add(key, 0x20), token1)\n            mstore(add(key, 0x40), fee)\n        }\n    }\n\n    /// @notice Deterministically computes the pool address given the deployer and PoolKey\n    /// @param deployer The PancakeSwapV3 deployer contract address\n    /// @param key The PoolKey\n    /// @return pool The contract address of the V3 pool\n    function computeAddress(address deployer, PoolKey memory key) internal pure returns (address pool) {\n        require(key.token0 < key.token1);\n        return computeAddressSorted(deployer, key);\n    }\n\n    /// @notice Deterministically computes the pool address given the deployer and PoolKey\n    /// @dev Assumes PoolKey is sorted\n    /// @param deployer The PancakeSwapV3 deployer contract address\n    /// @param key The PoolKey\n    /// @return pool The contract address of the V3 pool\n    function computeAddressSorted(address deployer, PoolKey memory key) internal pure returns (address pool) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Cache the free memory pointer.\n            let fmp := mload(0x40)\n            // abi.encodePacked(hex'ff', deployer, poolHash, POOL_INIT_CODE_HASH)\n            // Prefix the deployer address with 0xff.\n            mstore(0, or(deployer, 0xff0000000000000000000000000000000000000000))\n            mstore(0x20, keccak256(key, 0x60))\n            mstore(0x40, POOL_INIT_CODE_HASH)\n            // Compute the CREATE2 pool address and clean the upper bits.\n            pool := and(keccak256(0x0b, 0x55), 0xffffffffffffffffffffffffffffffffffffffff)\n            // Restore the free memory pointer.\n            mstore(0x40, fmp)\n        }\n    }\n\n    /// @notice Deterministically computes the pool address given the deployer, tokens, and the fee\n    /// @param deployer The PancakeSwapV3 deployer contract address\n    /// @param tokenA One of the tokens in the pool, unsorted\n    /// @param tokenB The other token in the pool, unsorted\n    /// @param fee The fee tier of the pool\n    function computeAddress(\n        address deployer,\n        address tokenA,\n        address tokenB,\n        uint24 fee\n    ) internal pure returns (address pool) {\n        (tokenA, tokenB) = TernaryLib.sort2(tokenA, tokenB);\n        return computeAddressSorted(deployer, tokenA, tokenB, fee);\n    }\n\n    /// @notice Deterministically computes the pool address given the deployer, tokens, and the fee\n    /// @dev Assumes tokens are sorted\n    /// @param deployer The PancakeSwapV3 deployer contract address\n    /// @param token0 The first token of a pool, already sorted\n    /// @param token1 The second token of a pool, already sorted\n    /// @param fee The fee tier of the pool\n    function computeAddressSorted(\n        address deployer,\n        address token0,\n        address token1,\n        uint24 fee\n    ) internal pure returns (address pool) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Cache the free memory pointer.\n            let fmp := mload(0x40)\n            // Hash the pool key.\n            mstore(0, token0)\n            mstore(0x20, token1)\n            mstore(0x40, fee)\n            let poolHash := keccak256(0, 0x60)\n            // abi.encodePacked(hex'ff', deployer, poolHash, POOL_INIT_CODE_HASH)\n            // Prefix the deployer address with 0xff.\n            mstore(0, or(deployer, 0xff0000000000000000000000000000000000000000))\n            mstore(0x20, poolHash)\n            mstore(0x40, POOL_INIT_CODE_HASH)\n            // Compute the CREATE2 pool address and clean the upper bits.\n            pool := and(keccak256(0x0b, 0x55), 0xffffffffffffffffffffffffffffffffffffffff)\n            // Restore the free memory pointer.\n            mstore(0x40, fmp)\n        }\n    }\n\n    /// @notice Deterministically computes the pool address given the deployer and PoolKey\n    /// @dev Uses PoolKey in calldata and assumes PoolKey is sorted\n    /// @param deployer The PancakeSwapV3 deployer contract address\n    /// @param key The abi encoded PoolKey of the V3 pool\n    /// @return pool The contract address of the V3 pool\n    function computeAddressCalldata(address deployer, bytes calldata key) internal pure returns (address pool) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Cache the free memory pointer.\n            let fmp := mload(0x40)\n            // Hash the pool key.\n            calldatacopy(0, key.offset, 0x60)\n            let poolHash := keccak256(0, 0x60)\n            // abi.encodePacked(hex'ff', deployer, poolHash, POOL_INIT_CODE_HASH)\n            // Prefix the deployer address with 0xff.\n            mstore(0, or(deployer, 0xff0000000000000000000000000000000000000000))\n            mstore(0x20, poolHash)\n            mstore(0x40, POOL_INIT_CODE_HASH)\n            // Compute the CREATE2 pool address and clean the upper bits.\n            pool := and(keccak256(0x0b, 0x55), 0xffffffffffffffffffffffffffffffffffffffff)\n            // Restore the free memory pointer.\n            mstore(0x40, fmp)\n        }\n    }\n}\n"
      },
      "node_modules/@aperture_finance/uni-v3-lib/src/TernaryLib.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.5.0;\n\n/// @title Library for efficient ternary operations\n/// @author Aperture Finance\nlibrary TernaryLib {\n    /// @notice Equivalent to the ternary operator: `condition ? a : b`\n    function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256 res) {\n        assembly {\n            res := xor(b, mul(xor(a, b), condition))\n        }\n    }\n\n    /// @notice Equivalent to the ternary operator: `condition ? a : b`\n    function ternary(bool condition, address a, address b) internal pure returns (address res) {\n        assembly {\n            res := xor(b, mul(xor(a, b), condition))\n        }\n    }\n\n    /// @notice Equivalent to: `uint256(x < 0 ? -x : x)`\n    function abs(int256 x) internal pure returns (uint256 y) {\n        assembly {\n            // mask = 0 if x >= 0 else -1\n            let mask := sub(0, slt(x, 0))\n            // If x >= 0, |x| = x = 0 ^ x\n            // If x < 0, |x| = ~~|x| = ~(-|x| - 1) = ~(x - 1) = -1 ^ (x - 1)\n            // Either case, |x| = mask ^ (x + mask)\n            y := xor(mask, add(mask, x))\n        }\n    }\n\n    /// @notice Equivalent to: `a < b ? a : b`\n    function min(uint256 a, uint256 b) internal pure returns (uint256 res) {\n        assembly {\n            res := xor(b, mul(xor(a, b), lt(a, b)))\n        }\n    }\n\n    /// @notice Equivalent to: `a > b ? a : b`\n    function max(uint256 a, uint256 b) internal pure returns (uint256 res) {\n        assembly {\n            res := xor(b, mul(xor(a, b), gt(a, b)))\n        }\n    }\n\n    /// @notice Equivalent to: `condition ? (b, a) : (a, b)`\n    function switchIf(bool condition, uint256 a, uint256 b) internal pure returns (uint256, uint256) {\n        assembly {\n            let diff := mul(xor(a, b), condition)\n            a := xor(a, diff)\n            b := xor(b, diff)\n        }\n        return (a, b);\n    }\n\n    /// @notice Equivalent to: `condition ? (b, a) : (a, b)`\n    function switchIf(bool condition, address a, address b) internal pure returns (address, address) {\n        assembly {\n            let diff := mul(xor(a, b), condition)\n            a := xor(a, diff)\n            b := xor(b, diff)\n        }\n        return (a, b);\n    }\n\n    /// @notice Sorts two addresses and returns them in ascending order\n    function sort2(address a, address b) internal pure returns (address, address) {\n        assembly {\n            let diff := mul(xor(a, b), lt(b, a))\n            a := xor(a, diff)\n            b := xor(b, diff)\n        }\n        return (a, b);\n    }\n\n    /// @notice Sorts two uint160s and returns them in ascending order\n    function sort2(uint160 a, uint160 b) internal pure returns (uint160, uint160) {\n        assembly {\n            let diff := mul(xor(a, b), lt(b, a))\n            a := xor(a, diff)\n            b := xor(b, diff)\n        }\n        return (a, b);\n    }\n}\n"
      },
      "src/base/Immutables.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity ^0.8.18;\n\nimport {INonfungiblePositionManager as INPM, IPCSV3NonfungiblePositionManager as IPCSV3NPM} from \"@aperture_finance/uni-v3-lib/src/interfaces/INonfungiblePositionManager.sol\";\nimport \"../interfaces/IImmutables.sol\";\n\n/// @title Immutable state\n/// @notice Immutable state used by periphery contracts\nabstract contract Immutables is IImmutables {\n    /// @notice Nonfungible Position Manager\n    INPM public immutable npm;\n    /// @notice Wrapped ETH\n    address payable public immutable override WETH9;\n\n    constructor(INPM nonfungiblePositionManager) payable {\n        npm = nonfungiblePositionManager;\n        WETH9 = payable(nonfungiblePositionManager.WETH9());\n    }\n}\n\n/// @title UniswapV3 Immutable state\n/// @notice Immutable state used by UniV3 periphery contracts\nabstract contract UniV3Immutables is Immutables, IUniV3Immutables {\n    /// @notice Uniswap v3 Factory\n    address public immutable factory;\n\n    constructor(INPM nonfungiblePositionManager) payable Immutables(nonfungiblePositionManager) {\n        factory = nonfungiblePositionManager.factory();\n    }\n}\n\n/// @title PancakeSwapV3 Immutable state\n/// @notice Immutable state used by PCSV3 periphery contracts\nabstract contract PCSV3Immutables is Immutables, IPCSV3Immutables {\n    /// @notice PancakeSwap v3 Deployer\n    address public immutable deployer;\n\n    constructor(IPCSV3NPM nonfungiblePositionManager) payable Immutables(nonfungiblePositionManager) {\n        deployer = nonfungiblePositionManager.deployer();\n    }\n}\n"
      },
      "src/base/Payments.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity ^0.8.18;\n\nimport \"solady/src/utils/SafeTransferLib.sol\";\nimport {ERC20Callee} from \"../libraries/ERC20Caller.sol\";\nimport {WETHCallee} from \"../libraries/WETHCaller.sol\";\nimport {Immutables} from \"./Immutables.sol\";\n\nabstract contract Payments is Immutables {\n    using SafeTransferLib for address;\n\n    error NotWETH9();\n    error MismatchETH();\n\n    receive() external payable {\n        if (msg.sender != WETH9) revert NotWETH9();\n    }\n\n    /// @notice Pays an amount of ETH or ERC20 to a recipient\n    /// @param token The token to pay\n    /// @param payer The entity that must pay\n    /// @param recipient The address that will receive the payment\n    /// @param value The amount to pay\n    function pay(address token, address payer, address recipient, uint256 value) internal {\n        // Receive native ETH\n        if (token == WETH9 && msg.value != 0) {\n            if (value != msg.value) revert MismatchETH();\n            // Wrap it\n            WETHCallee.wrap(WETH9).deposit(value);\n            // Already received native ETH so return\n            if (recipient == address(this)) return;\n        }\n        if (payer == address(this)) {\n            // Send token to recipient\n            token.safeTransfer(recipient, value);\n        } else {\n            // pull payment\n            token.safeTransferFrom(payer, recipient, value);\n        }\n    }\n\n    /// @dev Refunds an amount of ETH or ERC20 to a recipient, only called with balance the contract already has\n    /// @param token The token to pay\n    /// @param recipient The address that will receive the payment\n    /// @param value The amount to pay\n    function refund(address token, address recipient, uint256 value) internal {\n        if (token == WETH9) {\n            // Unwrap WETH\n            WETHCallee.wrap(WETH9).withdraw(value);\n            // Send native ETH to recipient\n            recipient.safeTransferETH(value);\n        } else {\n            token.safeTransfer(recipient, value);\n        }\n    }\n\n    /// @dev Pulls tokens from caller and approves NonfungiblePositionManager to spend\n    function pullAndApprove(address token0, address token1, uint256 amount0Desired, uint256 amount1Desired) internal {\n        if (amount0Desired != 0) {\n            pay(token0, msg.sender, address(this), amount0Desired);\n            token0.safeApprove(address(npm), amount0Desired);\n        }\n        if (amount1Desired != 0) {\n            pay(token1, msg.sender, address(this), amount1Desired);\n            token1.safeApprove(address(npm), amount1Desired);\n        }\n    }\n}\n"
      },
      "src/base/Callback.sol": {
        "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.18;\n\nimport \"@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol\";\nimport \"@pancakeswap/v3-core/contracts/interfaces/callback/IPancakeV3SwapCallback.sol\";\nimport {CallbackValidation} from \"@aperture_finance/uni-v3-lib/src/CallbackValidation.sol\";\nimport {CallbackValidationPancakeSwapV3} from \"@aperture_finance/uni-v3-lib/src/CallbackValidationPancakeSwapV3.sol\";\nimport \"./Immutables.sol\";\nimport \"./Payments.sol\";\n\nabstract contract UniswapV3Callback is Payments, UniV3Immutables, IUniswapV3SwapCallback {\n    /// @inheritdoc IUniswapV3SwapCallback\n    function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) external {\n        // Only accept callbacks from an official Uniswap V3 pool\n        address pool = CallbackValidation.verifyCallbackCalldata(factory, data);\n        if (amount0Delta > 0) {\n            address token0;\n            assembly {\n                token0 := calldataload(data.offset)\n            }\n            pay(token0, address(this), pool, uint256(amount0Delta));\n        } else {\n            address token1;\n            assembly {\n                token1 := calldataload(add(data.offset, 0x20))\n            }\n            pay(token1, address(this), pool, uint256(amount1Delta));\n        }\n    }\n}\n\nabstract contract PancakeV3Callback is Payments, PCSV3Immutables, IPancakeV3SwapCallback {\n    /// @inheritdoc IPancakeV3SwapCallback\n    function pancakeV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) external {\n        // Only accept callbacks from an official PCS V3 pool\n        address pool = CallbackValidationPancakeSwapV3.verifyCallbackCalldata(deployer, data);\n        if (amount0Delta > 0) {\n            address token0;\n            assembly {\n                token0 := calldataload(data.offset)\n            }\n            pay(token0, address(this), pool, uint256(amount0Delta));\n        } else {\n            address token1;\n            assembly {\n                token1 := calldataload(add(data.offset, 0x20))\n            }\n            pay(token1, address(this), pool, uint256(amount1Delta));\n        }\n    }\n}\n"
      },
      "node_modules/@openzeppelin/contracts/utils/Context.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    function _contextSuffixLength() internal view virtual returns (uint256) {\n        return 0;\n    }\n}\n"
      },
      "node_modules/@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolImmutables.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Pool state that never changes\n/// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values\ninterface IUniswapV3PoolImmutables {\n    /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface\n    /// @return The contract address\n    function factory() external view returns (address);\n\n    /// @notice The first of the two tokens of the pool, sorted by address\n    /// @return The token contract address\n    function token0() external view returns (address);\n\n    /// @notice The second of the two tokens of the pool, sorted by address\n    /// @return The token contract address\n    function token1() external view returns (address);\n\n    /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6\n    /// @return The fee\n    function fee() external view returns (uint24);\n\n    /// @notice The pool tick spacing\n    /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive\n    /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ...\n    /// This value is an int24 to avoid casting even though it is always positive.\n    /// @return The tick spacing\n    function tickSpacing() external view returns (int24);\n\n    /// @notice The maximum amount of position liquidity that can use any tick in the range\n    /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and\n    /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool\n    /// @return The max amount of liquidity per tick\n    function maxLiquidityPerTick() external view returns (uint128);\n}\n"
      },
      "node_modules/@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolState.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Pool state that can change\n/// @notice These methods compose the pool's state, and can change with any frequency including multiple times\n/// per transaction\ninterface IUniswapV3PoolState {\n    /// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas\n    /// when accessed externally.\n    /// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value\n    /// tick The current tick of the pool, i.e. according to the last tick transition that was run.\n    /// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick\n    /// boundary.\n    /// observationIndex The index of the last oracle observation that was written,\n    /// observationCardinality The current maximum number of observations stored in the pool,\n    /// observationCardinalityNext The next maximum number of observations, to be updated when the observation.\n    /// feeProtocol The protocol fee for both tokens of the pool.\n    /// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0\n    /// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee.\n    /// unlocked Whether the pool is currently locked to reentrancy\n    function slot0()\n        external\n        view\n        returns (\n            uint160 sqrtPriceX96,\n            int24 tick,\n            uint16 observationIndex,\n            uint16 observationCardinality,\n            uint16 observationCardinalityNext,\n            uint8 feeProtocol,\n            bool unlocked\n        );\n\n    /// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool\n    /// @dev This value can overflow the uint256\n    function feeGrowthGlobal0X128() external view returns (uint256);\n\n    /// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool\n    /// @dev This value can overflow the uint256\n    function feeGrowthGlobal1X128() external view returns (uint256);\n\n    /// @notice The amounts of token0 and token1 that are owed to the protocol\n    /// @dev Protocol fees will never exceed uint128 max in either token\n    function protocolFees() external view returns (uint128 token0, uint128 token1);\n\n    /// @notice The currently in range liquidity available to the pool\n    /// @dev This value has no relationship to the total liquidity across all ticks\n    function liquidity() external view returns (uint128);\n\n    /// @notice Look up information about a specific tick in the pool\n    /// @param tick The tick to look up\n    /// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or\n    /// tick upper,\n    /// liquidityNet how much liquidity changes when the pool price crosses the tick,\n    /// feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0,\n    /// feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1,\n    /// tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick\n    /// secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick,\n    /// secondsOutside the seconds spent on the other side of the tick from the current tick,\n    /// initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false.\n    /// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0.\n    /// In addition, these values are only relative and must be used only in comparison to previous snapshots for\n    /// a specific position.\n    function ticks(int24 tick)\n        external\n        view\n        returns (\n            uint128 liquidityGross,\n            int128 liquidityNet,\n            uint256 feeGrowthOutside0X128,\n            uint256 feeGrowthOutside1X128,\n            int56 tickCumulativeOutside,\n            uint160 secondsPerLiquidityOutsideX128,\n            uint32 secondsOutside,\n            bool initialized\n        );\n\n    /// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information\n    function tickBitmap(int16 wordPosition) external view returns (uint256);\n\n    /// @notice Returns the information about a position by the position's key\n    /// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper\n    /// @return _liquidity The amount of liquidity in the position,\n    /// Returns feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke,\n    /// Returns feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke,\n    /// Returns tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke,\n    /// Returns tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke\n    function positions(bytes32 key)\n        external\n        view\n        returns (\n            uint128 _liquidity,\n            uint256 feeGrowthInside0LastX128,\n            uint256 feeGrowthInside1LastX128,\n            uint128 tokensOwed0,\n            uint128 tokensOwed1\n        );\n\n    /// @notice Returns data about a specific observation index\n    /// @param index The element of the observations array to fetch\n    /// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time\n    /// ago, rather than at a specific index in the array.\n    /// @return blockTimestamp The timestamp of the observation,\n    /// Returns tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp,\n    /// Returns secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp,\n    /// Returns initialized whether the observation has been initialized and the values are safe to use\n    function observations(uint256 index)\n        external\n        view\n        returns (\n            uint32 blockTimestamp,\n            int56 tickCumulative,\n            uint160 secondsPerLiquidityCumulativeX128,\n            bool initialized\n        );\n}\n"
      },
      "node_modules/@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolDerivedState.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Pool state that is not stored\n/// @notice Contains view functions to provide information about the pool that is computed rather than stored on the\n/// blockchain. The functions here may have variable gas costs.\ninterface IUniswapV3PoolDerivedState {\n    /// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp\n    /// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing\n    /// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick,\n    /// you must call it with secondsAgos = [3600, 0].\n    /// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in\n    /// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.\n    /// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned\n    /// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp\n    /// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block\n    /// timestamp\n    function observe(uint32[] calldata secondsAgos)\n        external\n        view\n        returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);\n\n    /// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range\n    /// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed.\n    /// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first\n    /// snapshot is taken and the second snapshot is taken.\n    /// @param tickLower The lower tick of the range\n    /// @param tickUpper The upper tick of the range\n    /// @return tickCumulativeInside The snapshot of the tick accumulator for the range\n    /// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range\n    /// @return secondsInside The snapshot of seconds per liquidity for the range\n    function snapshotCumulativesInside(int24 tickLower, int24 tickUpper)\n        external\n        view\n        returns (\n            int56 tickCumulativeInside,\n            uint160 secondsPerLiquidityInsideX128,\n            uint32 secondsInside\n        );\n}\n"
      },
      "node_modules/@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolActions.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Permissionless pool actions\n/// @notice Contains pool methods that can be called by anyone\ninterface IUniswapV3PoolActions {\n    /// @notice Sets the initial price for the pool\n    /// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value\n    /// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96\n    function initialize(uint160 sqrtPriceX96) external;\n\n    /// @notice Adds liquidity for the given recipient/tickLower/tickUpper position\n    /// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback\n    /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends\n    /// on tickLower, tickUpper, the amount of liquidity, and the current price.\n    /// @param recipient The address for which the liquidity will be created\n    /// @param tickLower The lower tick of the position in which to add liquidity\n    /// @param tickUpper The upper tick of the position in which to add liquidity\n    /// @param amount The amount of liquidity to mint\n    /// @param data Any data that should be passed through to the callback\n    /// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback\n    /// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback\n    function mint(\n        address recipient,\n        int24 tickLower,\n        int24 tickUpper,\n        uint128 amount,\n        bytes calldata data\n    ) external returns (uint256 amount0, uint256 amount1);\n\n    /// @notice Collects tokens owed to a position\n    /// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.\n    /// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or\n    /// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the\n    /// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.\n    /// @param recipient The address which should receive the fees collected\n    /// @param tickLower The lower tick of the position for which to collect fees\n    /// @param tickUpper The upper tick of the position for which to collect fees\n    /// @param amount0Requested How much token0 should be withdrawn from the fees owed\n    /// @param amount1Requested How much token1 should be withdrawn from the fees owed\n    /// @return amount0 The amount of fees collected in token0\n    /// @return amount1 The amount of fees collected in token1\n    function collect(\n        address recipient,\n        int24 tickLower,\n        int24 tickUpper,\n        uint128 amount0Requested,\n        uint128 amount1Requested\n    ) external returns (uint128 amount0, uint128 amount1);\n\n    /// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position\n    /// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0\n    /// @dev Fees must be collected separately via a call to #collect\n    /// @param tickLower The lower tick of the position for which to burn liquidity\n    /// @param tickUpper The upper tick of the position for which to burn liquidity\n    /// @param amount How much liquidity to burn\n    /// @return amount0 The amount of token0 sent to the recipient\n    /// @return amount1 The amount of token1 sent to the recipient\n    function burn(\n        int24 tickLower,\n        int24 tickUpper,\n        uint128 amount\n    ) external returns (uint256 amount0, uint256 amount1);\n\n    /// @notice Swap token0 for token1, or token1 for token0\n    /// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback\n    /// @param recipient The address to receive the output of the swap\n    /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0\n    /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)\n    /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this\n    /// value after the swap. If one for zero, the price cannot be greater than this value after the swap\n    /// @param data Any data to be passed through to the callback\n    /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive\n    /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive\n    function swap(\n        address recipient,\n        bool zeroForOne,\n        int256 amountSpecified,\n        uint160 sqrtPriceLimitX96,\n        bytes calldata data\n    ) external returns (int256 amount0, int256 amount1);\n\n    /// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback\n    /// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback\n    /// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling\n    /// with 0 amount{0,1} and sending the donation amount(s) from the callback\n    /// @param recipient The address which will receive the token0 and token1 amounts\n    /// @param amount0 The amount of token0 to send\n    /// @param amount1 The amount of token1 to send\n    /// @param data Any data to be passed through to the callback\n    function flash(\n        address recipient,\n        uint256 amount0,\n        uint256 amount1,\n        bytes calldata data\n    ) external;\n\n    /// @notice Increase the maximum number of price and liquidity observations that this pool will store\n    /// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to\n    /// the input observationCardinalityNext.\n    /// @param observationCardinalityNext The desired minimum number of observations for the pool to store\n    function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;\n}\n"
      },
      "node_modules/@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolOwnerActions.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Permissioned pool actions\n/// @notice Contains pool methods that may only be called by the factory owner\ninterface IUniswapV3PoolOwnerActions {\n    /// @notice Set the denominator of the protocol's % share of the fees\n    /// @param feeProtocol0 new protocol fee for token0 of the pool\n    /// @param feeProtocol1 new protocol fee for token1 of the pool\n    function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external;\n\n    /// @notice Collect the protocol fee accrued to the pool\n    /// @param recipient The address to which collected protocol fees should be sent\n    /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1\n    /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0\n    /// @return amount0 The protocol fee collected in token0\n    /// @return amount1 The protocol fee collected in token1\n    function collectProtocol(\n        address recipient,\n        uint128 amount0Requested,\n        uint128 amount1Requested\n    ) external returns (uint128 amount0, uint128 amount1);\n}\n"
      },
      "node_modules/@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolEvents.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Events emitted by a pool\n/// @notice Contains all events emitted by the pool\ninterface IUniswapV3PoolEvents {\n    /// @notice Emitted exactly once by a pool when #initialize is first called on the pool\n    /// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize\n    /// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96\n    /// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool\n    event Initialize(uint160 sqrtPriceX96, int24 tick);\n\n    /// @notice Emitted when liquidity is minted for a given position\n    /// @param sender The address that minted the liquidity\n    /// @param owner The owner of the position and recipient of any minted liquidity\n    /// @param tickLower The lower tick of the position\n    /// @param tickUpper The upper tick of the position\n    /// @param amount The amount of liquidity minted to the position range\n    /// @param amount0 How much token0 was required for the minted liquidity\n    /// @param amount1 How much token1 was required for the minted liquidity\n    event Mint(\n        address sender,\n        address indexed owner,\n        int24 indexed tickLower,\n        int24 indexed tickUpper,\n        uint128 amount,\n        uint256 amount0,\n        uint256 amount1\n    );\n\n    /// @notice Emitted when fees are collected by the owner of a position\n    /// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees\n    /// @param owner The owner of the position for which fees are collected\n    /// @param tickLower The lower tick of the position\n    /// @param tickUpper The upper tick of the position\n    /// @param amount0 The amount of token0 fees collected\n    /// @param amount1 The amount of token1 fees collected\n    event Collect(\n        address indexed owner,\n        address recipient,\n        int24 indexed tickLower,\n        int24 indexed tickUpper,\n        uint128 amount0,\n        uint128 amount1\n    );\n\n    /// @notice Emitted when a position's liquidity is removed\n    /// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect\n    /// @param owner The owner of the position for which liquidity is removed\n    /// @param tickLower The lower tick of the position\n    /// @param tickUpper The upper tick of the position\n    /// @param amount The amount of liquidity to remove\n    /// @param amount0 The amount of token0 withdrawn\n    /// @param amount1 The amount of token1 withdrawn\n    event Burn(\n        address indexed owner,\n        int24 indexed tickLower,\n        int24 indexed tickUpper,\n        uint128 amount,\n        uint256 amount0,\n        uint256 amount1\n    );\n\n    /// @notice Emitted by the pool for any swaps between token0 and token1\n    /// @param sender The address that initiated the swap call, and that received the callback\n    /// @param recipient The address that received the output of the swap\n    /// @param amount0 The delta of the token0 balance of the pool\n    /// @param amount1 The delta of the token1 balance of the pool\n    /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96\n    /// @param liquidity The liquidity of the pool after the swap\n    /// @param tick The log base 1.0001 of price of the pool after the swap\n    event Swap(\n        address indexed sender,\n        address indexed recipient,\n        int256 amount0,\n        int256 amount1,\n        uint160 sqrtPriceX96,\n        uint128 liquidity,\n        int24 tick\n    );\n\n    /// @notice Emitted by the pool for any flashes of token0/token1\n    /// @param sender The address that initiated the swap call, and that received the callback\n    /// @param recipient The address that received the tokens from flash\n    /// @param amount0 The amount of token0 that was flashed\n    /// @param amount1 The amount of token1 that was flashed\n    /// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee\n    /// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee\n    event Flash(\n        address indexed sender,\n        address indexed recipient,\n        uint256 amount0,\n        uint256 amount1,\n        uint256 paid0,\n        uint256 paid1\n    );\n\n    /// @notice Emitted by the pool for increases to the number of observations that can be stored\n    /// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index\n    /// just before a mint/swap/burn.\n    /// @param observationCardinalityNextOld The previous value of the next observation cardinality\n    /// @param observationCardinalityNextNew The updated value of the next observation cardinality\n    event IncreaseObservationCardinalityNext(\n        uint16 observationCardinalityNextOld,\n        uint16 observationCardinalityNextNew\n    );\n\n    /// @notice Emitted when the protocol fee is changed by the pool\n    /// @param feeProtocol0Old The previous value of the token0 protocol fee\n    /// @param feeProtocol1Old The previous value of the token1 protocol fee\n    /// @param feeProtocol0New The updated value of the token0 protocol fee\n    /// @param feeProtocol1New The updated value of the token1 protocol fee\n    event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New);\n\n    /// @notice Emitted when the collected protocol fees are withdrawn by the factory owner\n    /// @param sender The address that collects the protocol fees\n    /// @param recipient The address that receives the collected protocol fees\n    /// @param amount0 The amount of token0 protocol fees that is withdrawn\n    /// @param amount0 The amount of token1 protocol fees that is withdrawn\n    event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1);\n}\n"
      },
      "node_modules/@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Metadata.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC721} from \"../IERC721.sol\";\n\n/**\n * @title ERC-721 Non-Fungible Token Standard, optional metadata extension\n * @dev See https://eips.ethereum.org/EIPS/eip-721\n */\ninterface IERC721Metadata is IERC721 {\n    /**\n     * @dev Returns the token collection name.\n     */\n    function name() external view returns (string memory);\n\n    /**\n     * @dev Returns the token collection symbol.\n     */\n    function symbol() external view returns (string memory);\n\n    /**\n     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\n     */\n    function tokenURI(uint256 tokenId) external view returns (string memory);\n}\n"
      },
      "node_modules/@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Enumerable.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC721} from \"../IERC721.sol\";\n\n/**\n * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension\n * @dev See https://eips.ethereum.org/EIPS/eip-721\n */\ninterface IERC721Enumerable is IERC721 {\n    /**\n     * @dev Returns the total amount of tokens stored by the contract.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns a token ID owned by `owner` at a given `index` of its token list.\n     * Use along with {balanceOf} to enumerate all of ``owner``'s tokens.\n     */\n    function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);\n\n    /**\n     * @dev Returns a token ID at a given `index` of all the tokens stored by the contract.\n     * Use along with {totalSupply} to enumerate all tokens.\n     */\n    function tokenByIndex(uint256 index) external view returns (uint256);\n}\n"
      },
      "node_modules/@uniswap/v3-periphery/contracts/interfaces/IPoolInitializer.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.7.5;\npragma abicoder v2;\n\n/// @title Creates and initializes V3 Pools\n/// @notice Provides a method for creating and initializing a pool, if necessary, for bundling with other methods that\n/// require the pool to exist.\ninterface IPoolInitializer {\n    /// @notice Creates a new pool if it does not exist, then initializes if not initialized\n    /// @dev This method can be bundled with others via IMulticall for the first action (e.g. mint) performed against a pool\n    /// @param token0 The contract address of token0 of the pool\n    /// @param token1 The contract address of token1 of the pool\n    /// @param fee The fee amount of the v3 pool for the specified token pair\n    /// @param sqrtPriceX96 The initial square root price of the pool as a Q64.96 value\n    /// @return pool Returns the pool address based on the pair of tokens and fee, will return the newly created pool address if necessary\n    function createAndInitializePoolIfNecessary(\n        address token0,\n        address token1,\n        uint24 fee,\n        uint160 sqrtPriceX96\n    ) external payable returns (address pool);\n}\n"
      },
      "node_modules/@uniswap/v3-periphery/contracts/interfaces/IERC721Permit.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.7.5;\n\nimport '@openzeppelin/contracts/token/ERC721/IERC721.sol';\n\n/// @title ERC721 with permit\n/// @notice Extension to ERC721 that includes a permit function for signature based approvals\ninterface IERC721Permit is IERC721 {\n    /// @notice The permit typehash used in the permit signature\n    /// @return The typehash for the permit\n    function PERMIT_TYPEHASH() external pure returns (bytes32);\n\n    /// @notice The domain separator used in the permit signature\n    /// @return The domain seperator used in encoding of permit signature\n    function DOMAIN_SEPARATOR() external view returns (bytes32);\n\n    /// @notice Approve of a specific token ID for spending by spender via signature\n    /// @param spender The account that is being approved\n    /// @param tokenId The ID of the token that is being approved for spending\n    /// @param deadline The deadline timestamp by which the call must be mined for the approve to work\n    /// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s`\n    /// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s`\n    /// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v`\n    function permit(\n        address spender,\n        uint256 tokenId,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external payable;\n}\n"
      },
      "node_modules/@uniswap/v3-periphery/contracts/interfaces/IPeripheryPayments.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.7.5;\n\n/// @title Periphery Payments\n/// @notice Functions to ease deposits and withdrawals of ETH\ninterface IPeripheryPayments {\n    /// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH.\n    /// @dev The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users.\n    /// @param amountMinimum The minimum amount of WETH9 to unwrap\n    /// @param recipient The address receiving ETH\n    function unwrapWETH9(uint256 amountMinimum, address recipient) external payable;\n\n    /// @notice Refunds any ETH balance held by this contract to the `msg.sender`\n    /// @dev Useful for bundling with mint or increase liquidity that uses ether, or exact output swaps\n    /// that use ether for the input amount\n    function refundETH() external payable;\n\n    /// @notice Transfers the full amount of a token held by this contract to recipient\n    /// @dev The amountMinimum parameter prevents malicious contracts from stealing the token from users\n    /// @param token The contract address of the token which will be transferred to `recipient`\n    /// @param amountMinimum The minimum amount of token required for a transfer\n    /// @param recipient The destination address of the token\n    function sweepToken(\n        address token,\n        uint256 amountMinimum,\n        address recipient\n    ) external payable;\n}\n"
      },
      "node_modules/@uniswap/v3-periphery/contracts/interfaces/IPeripheryImmutableState.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Immutable state\n/// @notice Functions that return immutable state of the router\ninterface IPeripheryImmutableState {\n    /// @return Returns the address of the Uniswap V3 factory\n    function factory() external view returns (address);\n\n    /// @return Returns the address of WETH9\n    function WETH9() external view returns (address);\n}\n"
      },
      "node_modules/@uniswap/v3-core/contracts/libraries/FixedPoint96.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.4.0;\n\n/// @title FixedPoint96\n/// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format)\n/// @dev Used in SqrtPriceMath.sol\nlibrary FixedPoint96 {\n    uint8 internal constant RESOLUTION = 96;\n    uint256 internal constant Q96 = 0x1000000000000000000000000;\n}\n"
      },
      "node_modules/@aperture_finance/uni-v3-lib/src/FullMath.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.4;\n\nimport \"solady/src/utils/FixedPointMathLib.sol\";\n\n/// @title Contains 512-bit math functions\n/// @author Aperture Finance\n/// @author Modified from Uniswap (https://github.com/uniswap/v3-core/blob/main/contracts/libraries/FullMath.sol)\n/// @author Credit to Solady (https://github.com/vectorized/solady/blob/main/src/utils/FixedPointMathLib.sol)\n/// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision\n/// @dev Handles \"phantom overflow\" i.e., allows multiplication and division where an intermediate value overflows 256 bits\nlibrary FullMath {\n    /// @dev The full precision multiply-divide operation failed, either due\n    /// to the result being larger than 256 bits, or a division by a zero.\n    error FullMulDivFailed();\n\n    /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\n    /// @param a The multiplicand\n    /// @param b The multiplier\n    /// @param denominator The divisor\n    /// @return result The 256-bit result\n    /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv\n    function mulDiv(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256) {\n        return FixedPointMathLib.fullMulDiv(a, b, denominator);\n    }\n\n    /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\n    /// @param a The multiplicand\n    /// @param b The multiplier\n    /// @param denominator The divisor\n    /// @return result The 256-bit result\n    function mulDivRoundingUp(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256) {\n        return FixedPointMathLib.fullMulDivUp(a, b, denominator);\n    }\n\n    /// @notice Calculates x * y / 2^96 with full precision.\n    function mulDiv96(uint256 x, uint256 y) internal pure returns (uint256 result) {\n        assembly (\"memory-safe\") {\n            // 512-bit multiply `[prod1 prod0] = x * y`.\n            // Compute the product mod `2**256` and mod `2**256 - 1`\n            // then use the Chinese Remainder Theorem to reconstruct\n            // the 512 bit result. The result is stored in two 256\n            // variables such that `product = prod1 * 2**256 + prod0`.\n\n            // Least significant 256 bits of the product.\n            let prod0 := mul(x, y)\n            let mm := mulmod(x, y, not(0))\n            // Most significant 256 bits of the product.\n            let prod1 := sub(mm, add(prod0, lt(mm, prod0)))\n\n            // Make sure the result is less than `2**256`.\n            if iszero(gt(0x1000000000000000000000000, prod1)) {\n                // Store the function selector of `FullMulDivFailed()`.\n                mstore(0x00, 0xae47f702)\n                // Revert with (offset, size).\n                revert(0x1c, 0x04)\n            }\n\n            // Divide [prod1 prod0] by 2^96.\n            result := or(shr(96, prod0), shl(160, prod1))\n        }\n    }\n\n    /// @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\n    function sqrt(uint256 x) internal pure returns (uint256) {\n        return FixedPointMathLib.sqrt(x);\n    }\n}\n"
      },
      "node_modules/@aperture_finance/uni-v3-lib/src/SafeCast.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.8.4;\n\n/// @title Safe casting methods\n/// @author Aperture Finance\n/// @author Modified from Uniswap (https://github.com/uniswap/v3-core/blob/main/contracts/libraries/SafeCast.sol)\n/// @notice Contains methods for safely casting between types\nlibrary SafeCast {\n    /// @notice Cast a uint256 to a uint160, revert on overflow\n    /// @param y The uint256 to be downcasted\n    /// @return z The downcasted integer, now type uint160\n    function toUint160(uint256 y) internal pure returns (uint160 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            if shr(160, y) {\n                revert(0, 0)\n            }\n            z := y\n        }\n    }\n\n    /// @notice Cast a uint256 to a uint128, revert on overflow\n    /// @param y The uint256 to be downcasted\n    /// @return z The downcasted integer, now type uint128\n    function toUint128(uint256 y) internal pure returns (uint128 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            if shr(128, y) {\n                revert(0, 0)\n            }\n            z := y\n        }\n    }\n\n    /// @notice Cast a int256 to a int128, revert on overflow or underflow\n    /// @param y The int256 to be downcasted\n    /// @return z The downcasted integer, now type int128\n    function toInt128(int256 y) internal pure returns (int128 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            if sub(y, signextend(15, y)) {\n                revert(0, 0)\n            }\n            z := y\n        }\n    }\n\n    /// @notice Cast a uint256 to a int256, revert on overflow\n    /// @param y The uint256 to be casted\n    /// @return z The casted integer, now type int256\n    function toInt256(uint256 y) internal pure returns (int256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            if shr(255, y) {\n                revert(0, 0)\n            }\n            z := y\n        }\n    }\n\n    /// @notice Cast a uint256 to a int128, revert on overflow\n    /// @param y The uint256 to be downcasted\n    /// @return z The downcasted integer, now type int128\n    function toInt128(uint256 y) internal pure returns (int128 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            if shr(127, y) {\n                revert(0, 0)\n            }\n            z := y\n        }\n    }\n}\n"
      },
      "node_modules/@aperture_finance/uni-v3-lib/src/UnsafeMath.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Math functions that do not check inputs or outputs\n/// @author Aperture Finance\n/// @author Modified from Uniswap (https://github.com/uniswap/v3-core/blob/main/contracts/libraries/UnsafeMath.sol)\n/// @notice Contains methods that perform common math functions but do not do any overflow or underflow checks\nlibrary UnsafeMath {\n    function add(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        assembly {\n            z := add(x, y)\n        }\n    }\n\n    function sub(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        assembly {\n            z := sub(x, y)\n        }\n    }\n\n    function mul(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        assembly {\n            z := mul(x, y)\n        }\n    }\n\n    function div(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        assembly {\n            z := div(x, y)\n        }\n    }\n\n    /// @notice Returns ceil(x / y)\n    /// @dev division by 0 has unspecified behavior, and must be checked externally\n    /// @param x The dividend\n    /// @param y The divisor\n    /// @return z The quotient, ceil(x / y)\n    function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        assembly {\n            z := add(div(x, y), gt(mod(x, y), 0))\n        }\n    }\n}\n"
      },
      "node_modules/@pancakeswap/v3-core/contracts/interfaces/callback/IPancakeV3SwapCallback.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Callback for IPancakeV3PoolActions#swap\n/// @notice Any contract that calls IPancakeV3PoolActions#swap must implement this interface\ninterface IPancakeV3SwapCallback {\n    /// @notice Called to `msg.sender` after executing a swap via IPancakeV3Pool#swap.\n    /// @dev In the implementation you must pay the pool tokens owed for the swap.\n    /// The caller of this method must be checked to be a PancakeV3Pool deployed by the canonical PancakeV3Factory.\n    /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.\n    /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by\n    /// the end of the swap. If positive, the callback must send that amount of token0 to the pool.\n    /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by\n    /// the end of the swap. If positive, the callback must send that amount of token1 to the pool.\n    /// @param data Any data passed through by the caller via the IPancakeV3PoolActions#swap call\n    function pancakeV3SwapCallback(\n        int256 amount0Delta,\n        int256 amount1Delta,\n        bytes calldata data\n    ) external;\n}\n"
      },
      "node_modules/@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Callback for IUniswapV3PoolActions#swap\n/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface\ninterface IUniswapV3SwapCallback {\n    /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.\n    /// @dev In the implementation you must pay the pool tokens owed for the swap.\n    /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.\n    /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.\n    /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by\n    /// the end of the swap. If positive, the callback must send that amount of token0 to the pool.\n    /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by\n    /// the end of the swap. If positive, the callback must send that amount of token1 to the pool.\n    /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call\n    function uniswapV3SwapCallback(\n        int256 amount0Delta,\n        int256 amount1Delta,\n        bytes calldata data\n    ) external;\n}\n"
      },
      "node_modules/@aperture_finance/uni-v3-lib/src/PoolCaller.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\n// User defined value types are introduced in Solidity v0.8.8.\n// https://blog.soliditylang.org/2021/09/27/user-defined-value-types/\npragma solidity >=0.8.8;\n\nimport \"@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol\";\n\ntype V3PoolCallee is address;\nusing PoolCaller for V3PoolCallee global;\n\n/// @title Uniswap v3 Pool Caller\n/// @author Aperture Finance\n/// @notice Gas efficient library to call `IUniswapV3Pool` assuming the pool exists.\n/// @dev Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.\n/// However, this is safe because \"Note that you do not need to update the free memory pointer if there is no following\n/// allocation, but you can only use memory starting from the current offset given by the free memory pointer.\"\n/// according to https://docs.soliditylang.org/en/latest/assembly.html#memory-safety.\nlibrary PoolCaller {\n    /// @dev Makes a staticcall to a pool with only the selector and returns a memory word.\n    function staticcall_0i_1o(V3PoolCallee pool, bytes4 selector) internal view returns (uint256 res) {\n        assembly (\"memory-safe\") {\n            // Write the function selector into memory.\n            mstore(0, selector)\n            // We use 4 because of the length of our calldata.\n            // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.\n            if iszero(staticcall(gas(), pool, 0, 4, 0, 0x20)) {\n                revert(0, 0)\n            }\n            res := mload(0)\n        }\n    }\n\n    /// @dev Makes a staticcall to a pool with only the selector and returns two memory words.\n    function staticcall_0i_2o(V3PoolCallee pool, bytes4 selector) internal view returns (uint256 res0, uint256 res1) {\n        assembly (\"memory-safe\") {\n            // Write the function selector into memory.\n            mstore(0, selector)\n            // We use 4 because of the length of our calldata.\n            // We use 0 and 64 to copy up to 64 bytes of return data into the scratch space.\n            if iszero(staticcall(gas(), pool, 0, 4, 0, 0x40)) {\n                revert(0, 0)\n            }\n            res0 := mload(0)\n            res1 := mload(0x20)\n        }\n    }\n\n    /// @dev Makes a staticcall to a pool with one argument.\n    function staticcall_1i_0o(\n        V3PoolCallee pool,\n        bytes4 selector,\n        uint256 arg,\n        uint256 out,\n        uint256 outsize\n    ) internal view {\n        assembly (\"memory-safe\") {\n            // Write the abi-encoded calldata into memory.\n            mstore(0, selector)\n            mstore(4, arg)\n            // We use 36 because of the length of our calldata.\n            if iszero(staticcall(gas(), pool, 0, 0x24, out, outsize)) {\n                revert(0, 0)\n            }\n        }\n    }\n\n    /// @dev Equivalent to `IUniswapV3Pool.fee`\n    /// @param pool Uniswap v3 pool\n    function fee(V3PoolCallee pool) internal view returns (uint24 f) {\n        uint256 res = staticcall_0i_1o(pool, IUniswapV3PoolImmutables.fee.selector);\n        assembly {\n            f := res\n        }\n    }\n\n    /// @dev Equivalent to `IUniswapV3Pool.tickSpacing`\n    /// @param pool Uniswap v3 pool\n    function tickSpacing(V3PoolCallee pool) internal view returns (int24 ts) {\n        uint256 res = staticcall_0i_1o(pool, IUniswapV3PoolImmutables.tickSpacing.selector);\n        assembly {\n            ts := res\n        }\n    }\n\n    /// @dev Equivalent to `IUniswapV3Pool.slot0`\n    /// @param pool Uniswap v3 pool\n    function slot0(\n        V3PoolCallee pool\n    )\n        internal\n        view\n        returns (\n            uint160 sqrtPriceX96,\n            int24 tick,\n            uint16 observationIndex,\n            uint16 observationCardinality,\n            uint16 observationCardinalityNext,\n            uint8 feeProtocol,\n            bool unlocked\n        )\n    {\n        bytes4 selector = IUniswapV3PoolState.slot0.selector;\n        assembly (\"memory-safe\") {\n            // Get a pointer to some free memory.\n            let fmp := mload(0x40)\n            // Write the function selector into memory.\n            mstore(0, selector)\n            // We use 4 because of the length of our calldata.\n            // We copy up to 224 bytes of return data after fmp.\n            if iszero(staticcall(gas(), pool, 0, 4, fmp, 0xe0)) {\n                revert(0, 0)\n            }\n            sqrtPriceX96 := mload(fmp)\n            tick := mload(add(fmp, 0x20))\n            observationIndex := mload(add(fmp, 0x40))\n            observationCardinality := mload(add(fmp, 0x60))\n            observationCardinalityNext := mload(add(fmp, 0x80))\n            feeProtocol := mload(add(fmp, 0xa0))\n            unlocked := mload(add(fmp, 0xc0))\n        }\n    }\n\n    /// @dev Equivalent to `(uint160 sqrtPriceX96, int24 tick, , , , , ) = pool.slot0()`\n    /// @param pool Uniswap v3 pool\n    function sqrtPriceX96AndTick(V3PoolCallee pool) internal view returns (uint160 sqrtPriceX96, int24 tick) {\n        (uint256 res0, uint256 res1) = staticcall_0i_2o(pool, IUniswapV3PoolState.slot0.selector);\n        assembly {\n            sqrtPriceX96 := res0\n            tick := res1\n        }\n    }\n\n    /// @dev Equivalent to `IUniswapV3Pool.feeGrowthGlobal0X128`\n    /// @param pool Uniswap v3 pool\n    function feeGrowthGlobal0X128(V3PoolCallee pool) internal view returns (uint256 f) {\n        f = staticcall_0i_1o(pool, IUniswapV3PoolState.feeGrowthGlobal0X128.selector);\n    }\n\n    /// @dev Equivalent to `IUniswapV3Pool.feeGrowthGlobal1X128`\n    /// @param pool Uniswap v3 pool\n    function feeGrowthGlobal1X128(V3PoolCallee pool) internal view returns (uint256 f) {\n        f = staticcall_0i_1o(pool, IUniswapV3PoolState.feeGrowthGlobal1X128.selector);\n    }\n\n    /// @dev Equivalent to `IUniswapV3Pool.protocolFees`\n    /// @param pool Uniswap v3 pool\n    function protocolFees(V3PoolCallee pool) internal view returns (uint128 token0, uint128 token1) {\n        (uint256 res0, uint256 res1) = staticcall_0i_2o(pool, IUniswapV3PoolState.protocolFees.selector);\n        assembly {\n            token0 := res0\n            token1 := res1\n        }\n    }\n\n    /// @dev Equivalent to `IUniswapV3Pool.liquidity`\n    /// @param pool Uniswap v3 pool\n    function liquidity(V3PoolCallee pool) internal view returns (uint128 l) {\n        uint256 res = staticcall_0i_1o(pool, IUniswapV3PoolState.liquidity.selector);\n        assembly {\n            l := res\n        }\n    }\n\n    // info stored for each initialized individual tick\n    struct TickInfo {\n        // the total position liquidity that references this tick\n        uint128 liquidityGross;\n        // amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left),\n        int128 liquidityNet;\n        // fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)\n        // only has relative meaning, not absolute — the value depends on when the tick is initialized\n        uint256 feeGrowthOutside0X128;\n        uint256 feeGrowthOutside1X128;\n        // the cumulative tick value on the other side of the tick\n        int56 tickCumulativeOutside;\n        // the seconds per unit of liquidity on the _other_ side of this tick (relative to the current tick)\n        // only has relative meaning, not absolute — the value depends on when the tick is initialized\n        uint160 secondsPerLiquidityOutsideX128;\n        // the seconds spent on the other side of the tick (relative to the current tick)\n        // only has relative meaning, not absolute — the value depends on when the tick is initialized\n        uint32 secondsOutside;\n        // true iff the tick is initialized, i.e. the value is exactly equivalent to the expression liquidityGross != 0\n        // these 8 bits are set to prevent fresh sstores when crossing newly initialized ticks\n        bool initialized;\n    }\n\n    /// @dev Equivalent to `IUniswapV3Pool.ticks`\n    /// @param pool Uniswap v3 pool\n    function ticks(V3PoolCallee pool, int24 tick) internal view returns (TickInfo memory info) {\n        uint256 _tick;\n        uint256 out;\n        assembly {\n            // Pad int24 to 32 bytes.\n            _tick := signextend(2, tick)\n            out := info\n        }\n        // We copy up to 256 bytes of return data at info's pointer.\n        staticcall_1i_0o(pool, IUniswapV3PoolState.ticks.selector, _tick, out, 0x100);\n    }\n\n    /// @dev Equivalent to `( , int128 liquidityNet, , , , , , ) = pool.ticks(tick)`\n    /// @param pool Uniswap v3 pool\n    function liquidityNet(V3PoolCallee pool, int24 tick) internal view returns (int128 ln) {\n        uint256 _tick;\n        assembly {\n            // Pad int24 to 32 bytes.\n            _tick := signextend(2, tick)\n        }\n        // We use 0 and 64 to copy up to 64 bytes of return data into the scratch space.\n        staticcall_1i_0o(pool, IUniswapV3PoolState.ticks.selector, _tick, 0, 0x40);\n        assembly (\"memory-safe\") {\n            ln := mload(0x20)\n        }\n    }\n\n    /// @dev Equivalent to `IUniswapV3Pool.tickBitmap`\n    /// @param pool Uniswap v3 pool\n    /// @param wordPos The key in the mapping containing the word in which the bit is stored\n    function tickBitmap(V3PoolCallee pool, int16 wordPos) internal view returns (uint256 tickWord) {\n        uint256 _wordPos;\n        assembly {\n            // Pad int16 to 32 bytes.\n            _wordPos := signextend(1, wordPos)\n        }\n        // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.\n        staticcall_1i_0o(pool, IUniswapV3PoolState.tickBitmap.selector, _wordPos, 0, 0x20);\n        assembly (\"memory-safe\") {\n            tickWord := mload(0)\n        }\n    }\n\n    // info stored for each user's position\n    struct PositionInfo {\n        // the amount of liquidity owned by this position\n        uint128 liquidity;\n        // fee growth per unit of liquidity as of the last update to liquidity or fees owed\n        uint256 feeGrowthInside0LastX128;\n        uint256 feeGrowthInside1LastX128;\n        // the fees owed to the position owner in token0/token1\n        uint128 tokensOwed0;\n        uint128 tokensOwed1;\n    }\n\n    /// @dev Equivalent to `IUniswapV3Pool.positions`\n    /// @param pool Uniswap v3 pool\n    /// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper\n    function positions(V3PoolCallee pool, bytes32 key) internal view returns (PositionInfo memory info) {\n        uint256 out;\n        assembly {\n            out := info\n        }\n        // We copy up to 160 bytes of return data at info's pointer.\n        staticcall_1i_0o(pool, IUniswapV3PoolState.positions.selector, uint256(key), out, 0xa0);\n    }\n\n    /// @dev Equivalent to `IUniswapV3Pool.observations`\n    /// @param pool Uniswap v3 pool\n    /// @param index The element of the observations array to fetch\n    /// @return blockTimestamp The timestamp of the observation,\n    /// @return tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp,\n    /// @return secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp,\n    /// @return initialized whether the observation has been initialized and the values are safe to use\n    function observations(\n        V3PoolCallee pool,\n        uint256 index\n    )\n        internal\n        view\n        returns (\n            uint32 blockTimestamp,\n            int56 tickCumulative,\n            uint160 secondsPerLiquidityCumulativeX128,\n            bool initialized\n        )\n    {\n        uint256 fmp;\n        assembly (\"memory-safe\") {\n            // Get a pointer to some free memory.\n            fmp := mload(0x40)\n        }\n        // We copy up to 128 bytes of return data at the free memory pointer.\n        staticcall_1i_0o(pool, IUniswapV3PoolState.observations.selector, index, fmp, 0x80);\n        assembly (\"memory-safe\") {\n            blockTimestamp := mload(fmp)\n            tickCumulative := mload(add(fmp, 0x20))\n            secondsPerLiquidityCumulativeX128 := mload(add(fmp, 0x40))\n            initialized := mload(add(fmp, 0x60))\n        }\n    }\n\n    /// @dev Equivalent to `IUniswapV3Pool.swap`\n    /// @notice Swap token0 for token1, or token1 for token0\n    /// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback\n    /// @param pool Uniswap v3 pool\n    /// @param recipient The address to receive the output of the swap\n    /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0\n    /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)\n    /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this\n    /// value after the swap. If one for zero, the price cannot be greater than this value after the swap\n    /// @param data Any data to be passed through to the callback\n    /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive\n    /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive\n    function swap(\n        V3PoolCallee pool,\n        address recipient,\n        bool zeroForOne,\n        int256 amountSpecified,\n        uint160 sqrtPriceLimitX96,\n        bytes memory data\n    ) internal returns (int256 amount0, int256 amount1) {\n        bytes4 selector = IUniswapV3PoolActions.swap.selector;\n        assembly (\"memory-safe\") {\n            // Get a pointer to some free memory.\n            let fmp := mload(0x40)\n            mstore(fmp, selector)\n            mstore(add(fmp, 4), recipient)\n            mstore(add(fmp, 0x24), zeroForOne)\n            mstore(add(fmp, 0x44), amountSpecified)\n            mstore(add(fmp, 0x64), sqrtPriceLimitX96)\n            // Use 160 for the offset of `data` in calldata.\n            mstore(add(fmp, 0x84), 0xa0)\n            // length = data.length + 32\n            let length := add(mload(data), 0x20)\n            // Call the identity precompile 0x04 to copy `data` into calldata.\n            pop(staticcall(gas(), 0x04, data, length, add(fmp, 0xa4), length))\n            // We use `196 + data.length` for the length of our calldata.\n            // We use 0 and 64 to copy up to 64 bytes of return data into the scratch space.\n            if iszero(\n                and(\n                    // The arguments of `and` are evaluated from right to left.\n                    eq(returndatasize(), 0x40), // Ensure `returndatasize` is 64.\n                    call(gas(), pool, 0, fmp, add(0xa4, length), 0, 0x40)\n                )\n            ) {\n                // It is safe to overwrite the free memory pointer 0x40 and the zero pointer 0x60 here before exiting\n                // because a contract obtains a freshly cleared instance of memory for each message call.\n                returndatacopy(0, 0, returndatasize())\n                // Bubble up the revert reason.\n                revert(0, returndatasize())\n            }\n            // Read the return data.\n            amount0 := mload(0)\n            amount1 := mload(0x20)\n        }\n    }\n}\n"
      },
      "src/interfaces/IImmutables.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.0;\n\nimport \"@aperture_finance/uni-v3-lib/src/interfaces/INonfungiblePositionManager.sol\";\n\n/// @title Immutables of the UniV3-style DEX Automation Manager\ninterface IImmutables {\n    /// @notice Uniswap v3 Position Manager\n    function npm() external view returns (INonfungiblePositionManager);\n\n    /// @return Returns the address of WETH9\n    function WETH9() external view returns (address payable);\n}\n\ninterface IUniV3Immutables is IImmutables {\n    /// @return Returns the address of the Uniswap V3 factory\n    function factory() external view returns (address);\n}\n\ninterface IPCSV3Immutables is IImmutables {\n    /// @return Returns the address of the PancakeSwap V3 deployer\n    function deployer() external view returns (address);\n}\n"
      },
      "node_modules/@aperture_finance/uni-v3-lib/src/SwapMath.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.8.4;\n\nimport \"./SqrtPriceMath.sol\";\n\n/// @title Computes the result of a swap within ticks\n/// @author Aperture Finance\n/// @author Modified from Uniswap (https://github.com/uniswap/v3-core/blob/main/contracts/libraries/SwapMath.sol)\n/// @notice Contains methods for computing the result of a swap within a single tick price range, i.e., a single tick.\nlibrary SwapMath {\n    uint256 internal constant MAX_FEE_PIPS = 1e6;\n\n    /// @notice Computes the sqrt price target for the next swap step\n    /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0\n    /// @param sqrtPriceNextX96 The Q64.96 sqrt price for the next initialized tick\n    /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this\n    /// value after the swap. If one for zero, the price cannot be greater than this value after the swap\n    /// @return sqrtRatioTargetX96 The price target for the next swap step\n    function getSqrtRatioTarget(\n        bool zeroForOne,\n        uint160 sqrtPriceNextX96,\n        uint160 sqrtPriceLimitX96\n    ) internal pure returns (uint160 sqrtRatioTargetX96) {\n        assembly {\n            // a flag to toggle between sqrtPriceNextX96 and sqrtPriceLimitX96\n            // when zeroForOne == true, nextOrLimit reduces to sqrtPriceNextX96 > sqrtPriceLimitX96\n            // sqrtRatioTargetX96 = max(sqrtPriceNextX96, sqrtPriceLimitX96)\n            // when zeroForOne == false, nextOrLimit reduces to sqrtPriceNextX96 <= sqrtPriceLimitX96\n            // sqrtRatioTargetX96 = min(sqrtPriceNextX96, sqrtPriceLimitX96)\n            let nextOrLimit := xor(gt(sqrtPriceNextX96, sqrtPriceLimitX96), iszero(zeroForOne))\n            let symDiff := xor(sqrtPriceNextX96, sqrtPriceLimitX96)\n            sqrtRatioTargetX96 := xor(sqrtPriceLimitX96, mul(symDiff, nextOrLimit))\n        }\n    }\n\n    /// @notice Computes the result of swapping some amount in, or amount out, given the parameters of the swap\n    /// @dev The fee, plus the amount in, will never exceed the amount remaining if the swap's `amountSpecified` is positive\n    /// @param sqrtRatioCurrentX96 The current sqrt price of the pool\n    /// @param sqrtRatioTargetX96 The price that cannot be exceeded, from which the direction of the swap is inferred\n    /// @param liquidity The usable liquidity\n    /// @param amountRemaining How much input or output amount is remaining to be swapped in/out\n    /// @param feePips The fee taken from the input amount, expressed in hundredths of a bip\n    /// @return sqrtRatioNextX96 The price after swapping the amount in/out, not to exceed the price target\n    /// @return amountIn The amount to be swapped in, of either token0 or token1, based on the direction of the swap\n    /// @return amountOut The amount to be received, of either token0 or token1, based on the direction of the swap\n    /// @return feeAmount The amount of input that will be taken as a fee\n    function computeSwapStep(\n        uint160 sqrtRatioCurrentX96,\n        uint160 sqrtRatioTargetX96,\n        uint128 liquidity,\n        int256 amountRemaining,\n        uint24 feePips\n    ) internal pure returns (uint160 sqrtRatioNextX96, uint256 amountIn, uint256 amountOut, uint256 feeAmount) {\n        unchecked {\n            bool zeroForOne = sqrtRatioCurrentX96 >= sqrtRatioTargetX96;\n            uint256 feeComplement = MAX_FEE_PIPS - feePips;\n            bool exactOut = amountRemaining < 0;\n            uint256 amountRemainingAbs;\n\n            if (!exactOut) {\n                assembly {\n                    amountRemainingAbs := amountRemaining\n                }\n                uint256 amountRemainingLessFee = FullMath.mulDiv(amountRemainingAbs, feeComplement, MAX_FEE_PIPS);\n                amountIn = zeroForOne\n                    ? SqrtPriceMath.getAmount0Delta(sqrtRatioTargetX96, sqrtRatioCurrentX96, liquidity, true)\n                    : SqrtPriceMath.getAmount1Delta(sqrtRatioCurrentX96, sqrtRatioTargetX96, liquidity, true);\n                if (amountRemainingLessFee >= amountIn) {\n                    // `amountIn` is capped by the target price\n                    sqrtRatioNextX96 = sqrtRatioTargetX96;\n                    feeAmount = FullMath.mulDivRoundingUp(amountIn, feePips, feeComplement);\n                } else {\n                    // exhaust the remaining amount\n                    amountIn = amountRemainingLessFee;\n                    sqrtRatioNextX96 = SqrtPriceMath.getNextSqrtPriceFromInput(\n                        sqrtRatioCurrentX96,\n                        liquidity,\n                        amountIn,\n                        zeroForOne\n                    );\n                    // we didn't reach the target, so take the remainder of the maximum input as fee\n                    feeAmount = amountRemainingAbs - amountIn;\n                }\n                amountOut = zeroForOne\n                    ? SqrtPriceMath.getAmount1Delta(sqrtRatioNextX96, sqrtRatioCurrentX96, liquidity, false)\n                    : SqrtPriceMath.getAmount0Delta(sqrtRatioCurrentX96, sqrtRatioNextX96, liquidity, false);\n            } else {\n                amountOut = zeroForOne\n                    ? SqrtPriceMath.getAmount1Delta(sqrtRatioTargetX96, sqrtRatioCurrentX96, liquidity, false)\n                    : SqrtPriceMath.getAmount0Delta(sqrtRatioCurrentX96, sqrtRatioTargetX96, liquidity, false);\n                assembly {\n                    amountRemainingAbs := sub(0, amountRemaining)\n                }\n                if (amountRemainingAbs >= amountOut) {\n                    // `amountOut` is capped by the target price\n                    sqrtRatioNextX96 = sqrtRatioTargetX96;\n                } else {\n                    // cap the output amount to not exceed the remaining output amount\n                    amountOut = amountRemainingAbs;\n                    sqrtRatioNextX96 = SqrtPriceMath.getNextSqrtPriceFromOutput(\n                        sqrtRatioCurrentX96,\n                        liquidity,\n                        amountOut,\n                        zeroForOne\n                    );\n                }\n                amountIn = zeroForOne\n                    ? SqrtPriceMath.getAmount0Delta(sqrtRatioNextX96, sqrtRatioCurrentX96, liquidity, true)\n                    : SqrtPriceMath.getAmount1Delta(sqrtRatioCurrentX96, sqrtRatioNextX96, liquidity, true);\n                feeAmount = FullMath.mulDivRoundingUp(amountIn, feePips, feeComplement);\n            }\n        }\n    }\n\n    /// @notice Computes the result of swapping some amount in given the parameters of the swap\n    /// @dev The fee, plus the amount in, will never exceed the amount remaining if the swap's `amountSpecified` is positive\n    /// @param sqrtRatioCurrentX96 The current sqrt price of the pool\n    /// @param sqrtRatioTargetX96 The price that cannot be exceeded, from which the direction of the swap is inferred\n    /// @param liquidity The usable liquidity\n    /// @param amountRemaining How much input amount is remaining to be swapped in\n    /// @param feePips The fee taken from the input amount, expressed in hundredths of a bip\n    /// @return sqrtRatioNextX96 The price after swapping the amount in, not to exceed the price target\n    /// @return amountIn The amount to be swapped in, of either token0 or token1, based on the direction of the swap\n    /// @return amountOut The amount to be received, of either token0 or token1, based on the direction of the swap\n    function computeSwapStepExactIn(\n        uint160 sqrtRatioCurrentX96,\n        uint160 sqrtRatioTargetX96,\n        uint128 liquidity,\n        uint256 amountRemaining,\n        uint256 feePips\n    ) internal pure returns (uint160 sqrtRatioNextX96, uint256 amountIn, uint256 amountOut) {\n        bool zeroForOne = sqrtRatioCurrentX96 >= sqrtRatioTargetX96;\n        uint256 feeComplement = UnsafeMath.sub(MAX_FEE_PIPS, feePips);\n        uint256 amountRemainingLessFee = FullMath.mulDiv(amountRemaining, feeComplement, MAX_FEE_PIPS);\n        amountIn = zeroForOne\n            ? SqrtPriceMath.getAmount0Delta(sqrtRatioTargetX96, sqrtRatioCurrentX96, liquidity, true)\n            : SqrtPriceMath.getAmount1Delta(sqrtRatioCurrentX96, sqrtRatioTargetX96, liquidity, true);\n        if (amountRemainingLessFee >= amountIn) {\n            // `amountIn` is capped by the target price\n            sqrtRatioNextX96 = sqrtRatioTargetX96;\n            // add the fee amount\n            amountIn = FullMath.mulDivRoundingUp(amountIn, MAX_FEE_PIPS, feeComplement);\n        } else {\n            // exhaust the remaining amount\n            amountIn = amountRemaining;\n            sqrtRatioNextX96 = SqrtPriceMath.getNextSqrtPriceFromInput(\n                sqrtRatioCurrentX96,\n                liquidity,\n                amountRemainingLessFee,\n                zeroForOne\n            );\n        }\n        amountOut = zeroForOne\n            ? SqrtPriceMath.getAmount1Delta(sqrtRatioNextX96, sqrtRatioCurrentX96, liquidity, false)\n            : SqrtPriceMath.getAmount0Delta(sqrtRatioCurrentX96, sqrtRatioNextX96, liquidity, false);\n    }\n\n    /// @notice Computes the result of swapping some amount out, given the parameters of the swap\n    /// @param sqrtRatioCurrentX96 The current sqrt price of the pool\n    /// @param sqrtRatioTargetX96 The price that cannot be exceeded, from which the direction of the swap is inferred\n    /// @param liquidity The usable liquidity\n    /// @param amountRemaining How much output amount is remaining to be swapped out\n    /// @param feePips The fee taken from the input amount, expressed in hundredths of a bip\n    /// @return sqrtRatioNextX96 The price after swapping the amount out, not to exceed the price target\n    /// @return amountIn The amount to be swapped in, of either token0 or token1, based on the direction of the swap\n    /// @return amountOut The amount to be received, of either token0 or token1, based on the direction of the swap\n    function computeSwapStepExactOut(\n        uint160 sqrtRatioCurrentX96,\n        uint160 sqrtRatioTargetX96,\n        uint128 liquidity,\n        uint256 amountRemaining,\n        uint256 feePips\n    ) internal pure returns (uint160 sqrtRatioNextX96, uint256 amountIn, uint256 amountOut) {\n        bool zeroForOne = sqrtRatioCurrentX96 >= sqrtRatioTargetX96;\n        amountOut = zeroForOne\n            ? SqrtPriceMath.getAmount1Delta(sqrtRatioTargetX96, sqrtRatioCurrentX96, liquidity, false)\n            : SqrtPriceMath.getAmount0Delta(sqrtRatioCurrentX96, sqrtRatioTargetX96, liquidity, false);\n        if (amountRemaining >= amountOut) {\n            // `amountOut` is capped by the target price\n            sqrtRatioNextX96 = sqrtRatioTargetX96;\n        } else {\n            // cap the output amount to not exceed the remaining output amount\n            amountOut = amountRemaining;\n            sqrtRatioNextX96 = SqrtPriceMath.getNextSqrtPriceFromOutput(\n                sqrtRatioCurrentX96,\n                liquidity,\n                amountRemaining,\n                zeroForOne\n            );\n        }\n        amountIn = FullMath.mulDivRoundingUp(\n            zeroForOne\n                ? SqrtPriceMath.getAmount0Delta(sqrtRatioNextX96, sqrtRatioCurrentX96, liquidity, true)\n                : SqrtPriceMath.getAmount1Delta(sqrtRatioCurrentX96, sqrtRatioNextX96, liquidity, true),\n            MAX_FEE_PIPS,\n            UnsafeMath.sub(MAX_FEE_PIPS, feePips)\n        );\n    }\n}\n"
      },
      "node_modules/@aperture_finance/uni-v3-lib/src/TickBitmap.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.8.8;\n\nimport \"./BitMath.sol\";\nimport \"./PoolCaller.sol\";\n\n/// @title Packed tick initialized state library\n/// @author Aperture Finance\n/// @author Modified from Uniswap (https://github.com/uniswap/v3-core/blob/main/contracts/libraries/TickBitmap.sol)\n/// @notice Stores a packed mapping of tick index to its initialized state\n/// @dev The mapping uses int16 for keys since ticks are represented as int24 and there are 256 (2^8) values per word.\nlibrary TickBitmap {\n    /// @dev round towards negative infinity\n    function compress(int24 tick, int24 tickSpacing) internal pure returns (int24 compressed) {\n        // compressed = tick / tickSpacing;\n        // if (tick < 0 && tick % tickSpacing != 0) compressed--;\n        assembly {\n            compressed := sub(\n                sdiv(tick, tickSpacing),\n                // if (tick < 0 && tick % tickSpacing != 0) then tick % tickSpacing < 0, vice versa\n                slt(smod(tick, tickSpacing), 0)\n            )\n        }\n    }\n\n    /// @notice Computes the word position and the bit position given a tick.\n    /// @param tick The tick for which to compute the position\n    /// @return wordPos The key in the mapping containing the word in which the bit is stored\n    /// @return bitPos The bit position in the word where the flag is stored\n    function position(int24 tick) private pure returns (int16 wordPos, uint8 bitPos) {\n        assembly {\n            // signed arithmetic shift right\n            wordPos := sar(8, tick)\n            bitPos := and(tick, 255)\n        }\n    }\n\n    /// @notice Flips the initialized state for a given tick from false to true, or vice versa\n    /// @param self The mapping in which to flip the tick\n    /// @param tick The tick to flip\n    /// @param tickSpacing The spacing between usable ticks\n    function flipTick(mapping(int16 => uint256) storage self, int24 tick, int24 tickSpacing) internal {\n        assembly (\"memory-safe\") {\n            // ensure that the tick is spaced\n            if smod(tick, tickSpacing) {\n                revert(0, 0)\n            }\n            tick := sdiv(tick, tickSpacing)\n            // calculate the storage slot corresponding to the tick\n            // wordPos = tick >> 8\n            mstore(0, sar(8, tick))\n            mstore(0x20, self.slot)\n            // the slot of self[wordPos] is keccak256(abi.encode(wordPos, self.slot))\n            let slot := keccak256(0, 0x40)\n            // mask = 1 << bitPos = 1 << (tick % 256)\n            // self[wordPos] ^= mask\n            sstore(slot, xor(sload(slot), shl(and(tick, 255), 1)))\n        }\n    }\n\n    /// @notice Returns the next initialized tick contained in the same word (or adjacent word) as the tick that is either\n    /// to the left (less than or equal to) or right (greater than) of the given tick\n    /// @param self The mapping in which to compute the next initialized tick\n    /// @param tick The starting tick\n    /// @param tickSpacing The spacing between usable ticks\n    /// @param lte Whether to search for the next initialized tick to the left (less than or equal to the starting tick)\n    /// @return next The next initialized or uninitialized tick up to 256 ticks away from the current tick\n    /// @return initialized Whether the next tick is initialized, as the function only searches within up to 256 ticks\n    function nextInitializedTickWithinOneWord(\n        mapping(int16 => uint256) storage self,\n        int24 tick,\n        int24 tickSpacing,\n        bool lte\n    ) internal view returns (int24 next, bool initialized) {\n        int24 compressed = compress(tick, tickSpacing);\n        uint256 masked;\n\n        if (lte) {\n            (int16 wordPos, uint8 bitPos) = position(compressed);\n            // all the 1s at or to the right of the current bitPos\n            // mask = (1 << (bitPos + 1)) - 1\n            // (bitPos + 1) may be 256 but fine\n            // masked = self[wordPos] & mask\n            assembly (\"memory-safe\") {\n                mstore(0, wordPos)\n                mstore(0x20, self.slot)\n                let mask := sub(shl(add(bitPos, 1), 1), 1)\n                masked := and(sload(keccak256(0, 0x40)), mask)\n                initialized := gt(masked, 0)\n            }\n\n            // if there are no initialized ticks to the right of or at the current tick, return rightmost in the word\n            // overflow/underflow is possible, but prevented externally by limiting both tickSpacing and tick\n            if (initialized) {\n                uint8 msb = BitMath.mostSignificantBit(masked);\n                assembly {\n                    next := mul(add(sub(compressed, bitPos), msb), tickSpacing)\n                }\n            } else {\n                assembly {\n                    next := mul(sub(compressed, bitPos), tickSpacing)\n                }\n            }\n        } else {\n            // start from the word of the next tick, since the current tick state doesn't matter\n            unchecked {\n                ++compressed;\n            }\n            (int16 wordPos, uint8 bitPos) = position(compressed);\n            // all the 1s at or to the left of the bitPos\n            // mask = ~((1 << bitPos) - 1)\n            // masked = self[wordPos] & mask\n            assembly (\"memory-safe\") {\n                mstore(0, wordPos)\n                mstore(0x20, self.slot)\n                let mask := not(sub(shl(bitPos, 1), 1))\n                masked := and(sload(keccak256(0, 0x40)), mask)\n                initialized := gt(masked, 0)\n            }\n\n            // if there are no initialized ticks to the left of the current tick, return leftmost in the word\n            // overflow/underflow is possible, but prevented externally by limiting both tickSpacing and tick\n            if (initialized) {\n                uint8 lsb = BitMath.leastSignificantBit(masked);\n                assembly {\n                    next := mul(add(sub(compressed, bitPos), lsb), tickSpacing)\n                }\n            } else {\n                assembly {\n                    next := mul(add(sub(compressed, bitPos), 255), tickSpacing)\n                }\n            }\n        }\n    }\n\n    /// @notice Returns the next initialized tick contained in the same word (or adjacent word) as the tick that is either\n    /// to the left (less than or equal to) or right (greater than) of the given tick\n    /// @param pool Uniswap v3 pool\n    /// @param tick The starting tick\n    /// @param tickSpacing The spacing between usable ticks\n    /// @param lte Whether to search for the next initialized tick to the left (less than or equal to the starting tick)\n    /// @param lastWordPos The last accessed word position in the Bitmap. Set it to `type(int16).min` for the first call.\n    /// @param lastWord The last accessed word in the Bitmap\n    /// @return next The next initialized or uninitialized tick up to 256 ticks away from the current tick\n    /// @return initialized Whether the next tick is initialized, as the function only searches within up to 256 ticks\n    /// @return wordPos The word position of the next initialized tick in the Bitmap\n    /// @return tickWord The word of the next initialized tick in the Bitmap\n    function nextInitializedTickWithinOneWord(\n        V3PoolCallee pool,\n        int24 tick,\n        int24 tickSpacing,\n        bool lte,\n        int16 lastWordPos,\n        uint256 lastWord\n    ) internal view returns (int24 next, bool initialized, int16 wordPos, uint256 tickWord) {\n        int24 compressed = compress(tick, tickSpacing);\n        uint8 bitPos;\n        uint256 masked;\n\n        if (lte) {\n            (wordPos, bitPos) = position(compressed);\n            // Reuse the same word if the position doesn't change\n            tickWord = wordPos == lastWordPos ? lastWord : pool.tickBitmap(wordPos);\n            // all the 1s at or to the right of the current bitPos\n            // mask = (1 << (bitPos + 1)) - 1\n            // (bitPos + 1) may be 256 but fine\n            assembly {\n                let mask := sub(shl(add(bitPos, 1), 1), 1)\n                masked := and(tickWord, mask)\n                initialized := gt(masked, 0)\n            }\n\n            // if there are no initialized ticks to the right of or at the current tick, return rightmost in the word\n            // overflow/underflow is possible, but prevented externally by limiting both tickSpacing and tick\n            if (!initialized) {\n                assembly {\n                    next := mul(sub(compressed, bitPos), tickSpacing)\n                }\n            } else {\n                uint8 msb = BitMath.mostSignificantBit(masked);\n                assembly {\n                    next := mul(add(sub(compressed, bitPos), msb), tickSpacing)\n                }\n            }\n        } else {\n            // start from the word of the next tick, since the current tick state doesn't matter\n            unchecked {\n                (wordPos, bitPos) = position(++compressed);\n            }\n            // Reuse the same word if the position doesn't change\n            tickWord = wordPos == lastWordPos ? lastWord : pool.tickBitmap(wordPos);\n            // all the 1s at or to the left of the bitPos\n            // mask = ~((1 << bitPos) - 1)\n            assembly {\n                let mask := not(sub(shl(bitPos, 1), 1))\n                masked := and(tickWord, mask)\n                initialized := gt(masked, 0)\n            }\n\n            // if there are no initialized ticks to the left of the current tick, return leftmost in the word\n            // overflow/underflow is possible, but prevented externally by limiting both tickSpacing and tick\n            if (!initialized) {\n                assembly {\n                    next := mul(add(sub(compressed, bitPos), 255), tickSpacing)\n                }\n            } else {\n                uint8 lsb = BitMath.leastSignificantBit(masked);\n                assembly {\n                    next := mul(add(sub(compressed, bitPos), lsb), tickSpacing)\n                }\n            }\n        }\n    }\n\n    /// @notice Returns the next initialized tick not limited to the same word as the tick that is either\n    /// to the left (less than or equal to) or right (greater than) of the given tick\n    /// @dev It is assumed that the next initialized tick exists.\n    /// @param pool Uniswap v3 pool\n    /// @param tick The starting tick\n    /// @param tickSpacing The spacing between usable ticks\n    /// @param lte Whether to search for the next initialized tick to the left (less than or equal to the starting tick)\n    /// @param lastWordPos The last accessed word position in the Bitmap. Set it to `type(int16).min` for the first call.\n    /// @param lastWord The last accessed word in the Bitmap\n    /// @return next The next initialized tick\n    /// @return wordPos The word position of the next initialized tick in the Bitmap\n    /// @return tickWord The word of the next initialized tick in the Bitmap\n    function nextInitializedTick(\n        V3PoolCallee pool,\n        int24 tick,\n        int24 tickSpacing,\n        bool lte,\n        int16 lastWordPos,\n        uint256 lastWord\n    ) internal view returns (int24 next, int16 wordPos, uint256 tickWord) {\n        int24 compressed = compress(tick, tickSpacing);\n        uint8 bitPos;\n        uint256 masked;\n        uint8 sb;\n        if (lte) {\n            (wordPos, bitPos) = position(compressed);\n            // Reuse the same word if the position doesn't change\n            tickWord = wordPos == lastWordPos ? lastWord : pool.tickBitmap(wordPos);\n            // all the 1s at or to the right of the current bitPos\n            // mask = (1 << (bitPos + 1)) - 1\n            // (bitPos + 1) may be 256 but fine\n            assembly {\n                let mask := sub(shl(add(bitPos, 1), 1), 1)\n                masked := and(tickWord, mask)\n            }\n            while (masked == 0) {\n                // Always query the next word to the left\n                unchecked {\n                    masked = tickWord = pool.tickBitmap(--wordPos);\n                }\n            }\n            sb = BitMath.mostSignificantBit(masked);\n        } else {\n            // start from the word of the next tick, since the current tick state doesn't matter\n            // overflow/underflow is possible, but prevented externally by limiting both tickSpacing and tick\n            unchecked {\n                (wordPos, bitPos) = position(++compressed);\n            }\n            // Reuse the same word if the position doesn't change\n            tickWord = wordPos == lastWordPos ? lastWord : pool.tickBitmap(wordPos);\n            // all the 1s at or to the left of the bitPos\n            // mask = ~((1 << bitPos) - 1)\n            assembly {\n                let mask := not(sub(shl(bitPos, 1), 1))\n                masked := and(tickWord, mask)\n            }\n            while (masked == 0) {\n                // Always query the next word to the right\n                unchecked {\n                    masked = tickWord = pool.tickBitmap(++wordPos);\n                }\n            }\n            sb = BitMath.leastSignificantBit(masked);\n        }\n        assembly {\n            // next = (wordPos * 256 + sb) * tickSpacing\n            next := mul(add(shl(8, wordPos), sb), tickSpacing)\n        }\n    }\n}\n"
      },
      "node_modules/@aperture_finance/uni-v3-lib/src/TickMath.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\nimport \"./TernaryLib.sol\";\n\n/// @title Math library for computing sqrt prices from ticks and vice versa\n/// @author Aperture Finance\n/// @author Modified from Uniswap (https://github.com/uniswap/v3-core/blob/main/contracts/libraries/TickMath.sol)\n/// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports\n/// prices between 2**-128 and 2**128\nlibrary TickMath {\n    /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128\n    int24 internal constant MIN_TICK = -887272;\n    /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128\n    int24 internal constant MAX_TICK = 887272;\n\n    /// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK)\n    uint160 internal constant MIN_SQRT_RATIO = 4295128739;\n    /// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK)\n    uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342;\n    /// @dev A threshold used for optimized bounds check, equals `MAX_SQRT_RATIO - MIN_SQRT_RATIO - 1`\n    uint160 internal constant MAX_SQRT_RATIO_MINUS_MIN_SQRT_RATIO_MINUS_ONE =\n        1461446703485210103287273052203988822378723970342 - 4295128739 - 1;\n\n    /// @notice Calculates sqrt(1.0001^tick) * 2^96\n    /// @dev Throws if |tick| > max tick\n    /// @param tick The input tick for the above formula\n    /// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0)\n    /// at the given tick\n    function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) {\n        unchecked {\n            int256 tick256;\n            assembly {\n                // sign extend to make tick an int256 in twos complement\n                tick256 := signextend(2, tick)\n            }\n            uint256 absTick = TernaryLib.abs(tick256);\n            /// @solidity memory-safe-assembly\n            assembly {\n                // Equivalent: if (absTick > MAX_TICK) revert(\"T\");\n                if gt(absTick, MAX_TICK) {\n                    // selector \"Error(string)\", [0x1c, 0x20)\n                    mstore(0, 0x08c379a0)\n                    // abi encoding offset\n                    mstore(0x20, 0x20)\n                    // reason string length 1 and 'T', [0x5f, 0x61)\n                    mstore(0x41, 0x0154)\n                    // 4 byte selector + 32 byte offset + 32 byte length + 1 byte reason\n                    revert(0x1c, 0x45)\n                }\n            }\n\n            // Equivalent: ratio = 2**128 / sqrt(1.0001) if absTick & 0x1 else 1 << 128\n            uint256 ratio;\n            assembly {\n                ratio := and(\n                    shr(\n                        // 128 if absTick & 0x1 else 0\n                        shl(7, and(absTick, 0x1)),\n                        // upper 128 bits of 2**256 / sqrt(1.0001) where the 128th bit is 1\n                        0xfffcb933bd6fad37aa2d162d1a59400100000000000000000000000000000000\n                    ),\n                    0x1ffffffffffffffffffffffffffffffff // mask lower 129 bits\n                )\n            }\n            // Iterate through 1th to 19th bit of absTick because MAX_TICK < 2**20\n            // Equivalent to:\n            //      for i in range(1, 20):\n            //          if absTick & 2 ** i:\n            //              ratio = ratio * (2 ** 128 / 1.0001 ** (2 ** (i - 1))) / 2 ** 128\n            if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128;\n            if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128;\n            if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128;\n            if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128;\n            if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128;\n            if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128;\n            if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128;\n            if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128;\n            if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128;\n            if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128;\n            if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128;\n            if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128;\n            if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128;\n            if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128;\n            if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128;\n            if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128;\n            if (absTick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128;\n            if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128;\n            if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128;\n\n            // if (tick > 0) ratio = type(uint256).max / ratio;\n            assembly {\n                if sgt(tick256, 0) {\n                    ratio := div(not(0), ratio)\n                }\n            }\n\n            // this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96.\n            // we then downcast because we know the result always fits within 160 bits due to our tick input constraint\n            // we round up in the division so getTickAtSqrtRatio of the output price is always consistent\n            assembly {\n                sqrtPriceX96 := shr(32, add(ratio, 0xffffffff))\n            }\n        }\n    }\n\n    /// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio\n    /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may\n    /// ever return.\n    /// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96\n    /// @return tick The greatest tick for which the ratio is less than or equal to the input ratio\n    function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) {\n        // Equivalent: if (sqrtPriceX96 < MIN_SQRT_RATIO || sqrtPriceX96 >= MAX_SQRT_RATIO) revert(\"R\");\n        // second inequality must be >= because the price can never reach the price at the max tick\n        /// @solidity memory-safe-assembly\n        assembly {\n            // if sqrtPriceX96 < MIN_SQRT_RATIO, the `sub` underflows and `gt` is true\n            // if sqrtPriceX96 >= MAX_SQRT_RATIO, sqrtPriceX96 - MIN_SQRT_RATIO > MAX_SQRT_RATIO - MIN_SQRT_RATIO - 1\n            if gt(sub(sqrtPriceX96, MIN_SQRT_RATIO), MAX_SQRT_RATIO_MINUS_MIN_SQRT_RATIO_MINUS_ONE) {\n                // selector \"Error(string)\", [0x1c, 0x20)\n                mstore(0, 0x08c379a0)\n                // abi encoding offset\n                mstore(0x20, 0x20)\n                // reason string length 1 and 'R', [0x5f, 0x61)\n                mstore(0x41, 0x0152)\n                // 4 byte selector + 32 byte offset + 32 byte length + 1 byte reason\n                revert(0x1c, 0x45)\n            }\n        }\n\n        // Find the most significant bit of `sqrtPriceX96`, 160 > msb >= 32.\n        uint8 msb;\n        assembly {\n            let x := sqrtPriceX96\n            msb := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))\n            msb := or(msb, shl(6, lt(0xffffffffffffffff, shr(msb, x))))\n            msb := or(msb, shl(5, lt(0xffffffff, shr(msb, x))))\n            msb := or(msb, shl(4, lt(0xffff, shr(msb, x))))\n            msb := or(msb, shl(3, lt(0xff, shr(msb, x))))\n            msb := or(\n                msb,\n                byte(\n                    and(0x1f, shr(shr(msb, x), 0x8421084210842108cc6318c6db6d54be)),\n                    0x0706060506020504060203020504030106050205030304010505030400000000\n                )\n            )\n        }\n\n        // 2**(msb - 95) > sqrtPrice >= 2**(msb - 96)\n        // the integer part of log_2(sqrtPrice) * 2**64 = (msb - 96) << 64, 8.64 number\n        int256 log_2X64;\n        assembly {\n            log_2X64 := shl(64, sub(msb, 96))\n\n            // Get the first 128 significant figures of `sqrtPriceX96`.\n            // r = sqrtPriceX96 / 2**(msb - 127), where 2**128 > r >= 2**127\n            // sqrtPrice = 2**(msb - 96) * r / 2**127, in floating point math\n            // Shift left first because 160 > msb >= 32. If we shift right first, we'll lose precision.\n            let r := shr(sub(msb, 31), shl(96, sqrtPriceX96))\n\n            // Approximate `log_2X64` to 14 binary digits after decimal\n            // log_2X64 = (msb - 96) * 2**64 + f_0 * 2**63 + f_1 * 2**62 + ......\n            // sqrtPrice**2 = 2**(2 * (msb - 96)) * (r / 2**127)**2 = 2**(2 * log_2X64 / 2**64) = 2**(2 * (msb - 96) + f_0)\n            // 2**f_0 = (r / 2**127)**2 = r**2 / 2**255 * 2\n            // f_0 = 1 if (r**2 >= 2**255) else 0\n            // sqrtPrice**2 = 2**(2 * (msb - 96) + f_0) * r**2 / 2**(254 + f_0) = 2**(2 * (msb - 96) + f_0) * r' / 2**127\n            // r' = r**2 / 2**(127 + f_0)\n            // sqrtPrice**4 = 2**(4 * (msb - 96) + 2 * f_0) * (r' / 2**127)**2\n            //     = 2**(4 * log_2X64 / 2**64) = 2**(4 * (msb - 96) + 2 * f_0 + f_1)\n            // 2**(f_1) = (r' / 2**127)**2\n            // f_1 = 1 if (r'**2 >= 2**255) else 0\n\n            // Check whether r >= sqrt(2) * 2**127\n            // 2**256 > r**2 >= 2**254\n            let square := mul(r, r)\n            // f = (r**2 >= 2**255)\n            let f := slt(square, 0)\n            // r = r**2 >> 128 if r**2 >= 2**255 else r**2 >> 127\n            r := shr(add(127, f), square)\n            log_2X64 := or(shl(63, f), log_2X64)\n\n            square := mul(r, r)\n            f := slt(square, 0)\n            r := shr(add(127, f), square)\n            log_2X64 := or(shl(62, f), log_2X64)\n\n            square := mul(r, r)\n            f := slt(square, 0)\n            r := shr(add(127, f), square)\n            log_2X64 := or(shl(61, f), log_2X64)\n\n            square := mul(r, r)\n            f := slt(square, 0)\n            r := shr(add(127, f), square)\n            log_2X64 := or(shl(60, f), log_2X64)\n\n            square := mul(r, r)\n            f := slt(square, 0)\n            r := shr(add(127, f), square)\n            log_2X64 := or(shl(59, f), log_2X64)\n\n            square := mul(r, r)\n            f := slt(square, 0)\n            r := shr(add(127, f), square)\n            log_2X64 := or(shl(58, f), log_2X64)\n\n            square := mul(r, r)\n            f := slt(square, 0)\n            r := shr(add(127, f), square)\n            log_2X64 := or(shl(57, f), log_2X64)\n\n            square := mul(r, r)\n            f := slt(square, 0)\n            r := shr(add(127, f), square)\n            log_2X64 := or(shl(56, f), log_2X64)\n\n            square := mul(r, r)\n            f := slt(square, 0)\n            r := shr(add(127, f), square)\n            log_2X64 := or(shl(55, f), log_2X64)\n\n            square := mul(r, r)\n            f := slt(square, 0)\n            r := shr(add(127, f), square)\n            log_2X64 := or(shl(54, f), log_2X64)\n\n            square := mul(r, r)\n            f := slt(square, 0)\n            r := shr(add(127, f), square)\n            log_2X64 := or(shl(53, f), log_2X64)\n\n            square := mul(r, r)\n            f := slt(square, 0)\n            r := shr(add(127, f), square)\n            log_2X64 := or(shl(52, f), log_2X64)\n\n            square := mul(r, r)\n            f := slt(square, 0)\n            r := shr(add(127, f), square)\n            log_2X64 := or(shl(51, f), log_2X64)\n\n            log_2X64 := or(shl(50, slt(mul(r, r), 0)), log_2X64)\n        }\n\n        // sqrtPrice = sqrt(1.0001^tick)\n        // tick = log_{sqrt(1.0001)}(sqrtPrice) = log_2(sqrtPrice) / log_2(sqrt(1.0001))\n        // 2**64 / log_2(sqrt(1.0001)) = 255738958999603826347141\n        int24 tickLow;\n        int24 tickHi;\n        assembly {\n            let log_sqrt10001 := mul(log_2X64, 255738958999603826347141) // 128.128 number\n            tickLow := shr(128, sub(log_sqrt10001, 3402992956809132418596140100660247210))\n            tickHi := shr(128, add(log_sqrt10001, 291339464771989622907027621153398088495))\n        }\n\n        // Equivalent: tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow;\n        if (tickLow != tickHi) {\n            uint160 sqrtRatioAtTickHi = getSqrtRatioAtTick(tickHi);\n            assembly {\n                tick := sub(tickHi, gt(sqrtRatioAtTickHi, sqrtPriceX96))\n            }\n        } else {\n            tick = tickHi;\n        }\n    }\n}\n"
      },
      "node_modules/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n */\ninterface IERC20Metadata is IERC20 {\n    /**\n     * @dev Returns the name of the token.\n     */\n    function name() external view returns (string memory);\n\n    /**\n     * @dev Returns the symbol of the token.\n     */\n    function symbol() external view returns (string memory);\n\n    /**\n     * @dev Returns the decimals places of the token.\n     */\n    function decimals() external view returns (uint8);\n}\n"
      },
      "src/libraries/WETHCaller.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// User defined value types are introduced in Solidity v0.8.8.\n// https://blog.soliditylang.org/2021/09/27/user-defined-value-types/\npragma solidity ^0.8.8;\n\nimport {WETH} from \"solady/src/tokens/WETH.sol\";\n\ntype WETHCallee is address;\nusing WETHCaller for WETHCallee global;\n\n/// @title WETH Caller\n/// @author Aperture Finance\n/// @notice Gas efficient library to call WETH assuming the contract exists.\nlibrary WETHCaller {\n    /// @dev Equivalent to `WETH.deposit`\n    /// @param weth WETH contract\n    /// @param value Amount of ETH to deposit\n    function deposit(WETHCallee weth, uint256 value) internal {\n        bytes4 selector = WETH.deposit.selector;\n        assembly (\"memory-safe\") {\n            // Write the function selector into memory.\n            mstore(0, selector)\n            // We use 4 because of the length of our calldata.\n            if iszero(call(gas(), weth, value, 0, 4, 0, 0)) {\n                revert(0, 0)\n            }\n        }\n    }\n\n    /// @dev Equivalent to `WETH.withdraw`\n    /// @param weth WETH contract\n    /// @param amount Amount of WETH to withdraw\n    function withdraw(WETHCallee weth, uint256 amount) internal {\n        bytes4 selector = WETH.withdraw.selector;\n        assembly (\"memory-safe\") {\n            // Write the function selector into memory.\n            mstore(0, selector)\n            mstore(4, amount)\n            // We use 36 because of the length of our calldata.\n            if iszero(call(gas(), weth, 0, 0, 0x24, 0, 0)) {\n                revert(0, 0)\n            }\n        }\n    }\n}\n"
      },
      "node_modules/@aperture_finance/uni-v3-lib/src/CallbackValidation.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\nimport \"@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol\";\nimport \"./PoolAddress.sol\";\n\n/// @notice Provides validation for callbacks from Uniswap V3 Pools\n/// @author Aperture Finance\n/// @author Modified from Uniswap (https://github.com/uniswap/v3-periphery/blob/main/contracts/libraries/CallbackValidation.sol)\nlibrary CallbackValidation {\n    /// @notice Returns the address of a valid Uniswap V3 Pool\n    /// @param factory The contract address of the Uniswap V3 factory\n    /// @param tokenA The contract address of either token0 or token1\n    /// @param tokenB The contract address of the other token\n    /// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip\n    /// @return pool The V3 pool contract address\n    function verifyCallback(\n        address factory,\n        address tokenA,\n        address tokenB,\n        uint24 fee\n    ) internal view returns (IUniswapV3Pool pool) {\n        pool = IUniswapV3Pool(PoolAddress.computeAddress(factory, tokenA, tokenB, fee));\n        require(msg.sender == address(pool));\n    }\n\n    /// @notice Returns the address of a valid Uniswap V3 Pool\n    /// @param factory The contract address of the Uniswap V3 factory\n    /// @param poolKey The identifying key of the V3 pool\n    /// @return pool The V3 pool contract address\n    function verifyCallback(address factory, PoolKey memory poolKey) internal view returns (IUniswapV3Pool pool) {\n        pool = IUniswapV3Pool(PoolAddress.computeAddressSorted(factory, poolKey));\n        require(msg.sender == address(pool));\n    }\n\n    /// @notice Returns the address of a valid Uniswap V3 Pool\n    /// @param factory The contract address of the Uniswap V3 factory\n    /// @param poolKey The abi encoded PoolKey of the V3 pool\n    /// @return pool The V3 pool contract address\n    function verifyCallbackCalldata(address factory, bytes calldata poolKey) internal view returns (address pool) {\n        pool = PoolAddress.computeAddressCalldata(factory, poolKey);\n        require(msg.sender == pool);\n    }\n}\n"
      },
      "node_modules/@aperture_finance/uni-v3-lib/src/CallbackValidationPancakeSwapV3.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\nimport \"@pancakeswap/v3-core/contracts/interfaces/IPancakeV3Pool.sol\";\nimport \"./PoolAddressPancakeSwapV3.sol\";\n\n/// @notice Provides validation for callbacks from PancakeSwapV3 Pools\n/// @author Aperture Finance\n/// @author Modified from PancakeSwapV3 (https://www.npmjs.com/package/@pancakeswap/v3-periphery?activeTab=code and look for contracts/libraries/CallbackValidation.sol)\nlibrary CallbackValidationPancakeSwapV3 {\n    /// @notice Returns the address of a valid PancakeSwapV3 Pool\n    /// @param deployer The contract address of the PancakeSwapV3 deployer\n    /// @param tokenA The contract address of either token0 or token1\n    /// @param tokenB The contract address of the other token\n    /// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip\n    /// @return pool The V3 pool contract address\n    function verifyCallback(\n        address deployer,\n        address tokenA,\n        address tokenB,\n        uint24 fee\n    ) internal view returns (IPancakeV3Pool pool) {\n        pool = IPancakeV3Pool(PoolAddressPancakeSwapV3.computeAddress(deployer, tokenA, tokenB, fee));\n        require(msg.sender == address(pool));\n    }\n\n    /// @notice Returns the address of a valid PancakeSwapV3 Pool\n    /// @param deployer The contract address of the PancakeSwapV3 deployer\n    /// @param poolKey The identifying key of the V3 pool\n    /// @return pool The V3 pool contract address\n    function verifyCallback(address deployer, PoolKey memory poolKey) internal view returns (IPancakeV3Pool pool) {\n        pool = IPancakeV3Pool(PoolAddressPancakeSwapV3.computeAddressSorted(deployer, poolKey));\n        require(msg.sender == address(pool));\n    }\n\n    /// @notice Returns the address of a valid PancakeSwapV3 Pool\n    /// @param deployer The contract address of the PancakeSwapV3 deployer\n    /// @param poolKey The abi encoded PoolKey of the V3 pool\n    /// @return pool The V3 pool contract address\n    function verifyCallbackCalldata(address deployer, bytes calldata poolKey) internal view returns (address pool) {\n        pool = PoolAddressPancakeSwapV3.computeAddressCalldata(deployer, poolKey);\n        require(msg.sender == pool);\n    }\n}\n"
      },
      "node_modules/@openzeppelin/contracts/token/ERC721/IERC721.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Required interface of an ERC721 compliant contract.\n */\ninterface IERC721 is IERC165 {\n    /**\n     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\n\n    /**\n     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\n     */\n    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\n\n    /**\n     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.\n     */\n    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\n\n    /**\n     * @dev Returns the number of tokens in ``owner``'s account.\n     */\n    function balanceOf(address owner) external view returns (uint256 balance);\n\n    /**\n     * @dev Returns the owner of the `tokenId` token.\n     *\n     * Requirements:\n     *\n     * - `tokenId` must exist.\n     */\n    function ownerOf(uint256 tokenId) external view returns (address owner);\n\n    /**\n     * @dev Safely transfers `tokenId` token from `from` to `to`.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `tokenId` token must exist and be owned by `from`.\n     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon\n     *   a safe transfer.\n     *\n     * Emits a {Transfer} event.\n     */\n    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;\n\n    /**\n     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\n     * are aware of the ERC721 protocol to prevent tokens from being forever locked.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `tokenId` token must exist and be owned by `from`.\n     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or\n     *   {setApprovalForAll}.\n     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon\n     *   a safe transfer.\n     *\n     * Emits a {Transfer} event.\n     */\n    function safeTransferFrom(address from, address to, uint256 tokenId) external;\n\n    /**\n     * @dev Transfers `tokenId` token from `from` to `to`.\n     *\n     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721\n     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must\n     * understand this adds an external call which potentially creates a reentrancy vulnerability.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `tokenId` token must be owned by `from`.\n     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address from, address to, uint256 tokenId) external;\n\n    /**\n     * @dev Gives permission to `to` to transfer `tokenId` token to another account.\n     * The approval is cleared when the token is transferred.\n     *\n     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.\n     *\n     * Requirements:\n     *\n     * - The caller must own the token or be an approved operator.\n     * - `tokenId` must exist.\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address to, uint256 tokenId) external;\n\n    /**\n     * @dev Approve or remove `operator` as an operator for the caller.\n     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.\n     *\n     * Requirements:\n     *\n     * - The `operator` cannot be the address zero.\n     *\n     * Emits an {ApprovalForAll} event.\n     */\n    function setApprovalForAll(address operator, bool approved) external;\n\n    /**\n     * @dev Returns the account approved for `tokenId` token.\n     *\n     * Requirements:\n     *\n     * - `tokenId` must exist.\n     */\n    function getApproved(uint256 tokenId) external view returns (address operator);\n\n    /**\n     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\n     *\n     * See {setApprovalForAll}\n     */\n    function isApprovedForAll(address owner, address operator) external view returns (bool);\n}\n"
      },
      "node_modules/solady/src/utils/FixedPointMathLib.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.4;\n\n/// @notice Arithmetic library with operations for fixed-point numbers.\n/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/FixedPointMathLib.sol)\n/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol)\nlibrary FixedPointMathLib {\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                       CUSTOM ERRORS                        */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev The operation failed, as the output exceeds the maximum value of uint256.\n    error ExpOverflow();\n\n    /// @dev The operation failed, as the output exceeds the maximum value of uint256.\n    error FactorialOverflow();\n\n    /// @dev The operation failed, due to an overflow.\n    error RPowOverflow();\n\n    /// @dev The mantissa is too big to fit.\n    error MantissaOverflow();\n\n    /// @dev The operation failed, due to an multiplication overflow.\n    error MulWadFailed();\n\n    /// @dev The operation failed, due to an multiplication overflow.\n    error SMulWadFailed();\n\n    /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.\n    error DivWadFailed();\n\n    /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.\n    error SDivWadFailed();\n\n    /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.\n    error MulDivFailed();\n\n    /// @dev The division failed, as the denominator is zero.\n    error DivFailed();\n\n    /// @dev The full precision multiply-divide operation failed, either due\n    /// to the result being larger than 256 bits, or a division by a zero.\n    error FullMulDivFailed();\n\n    /// @dev The output is undefined, as the input is less-than-or-equal to zero.\n    error LnWadUndefined();\n\n    /// @dev The input outside the acceptable domain.\n    error OutOfDomain();\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                         CONSTANTS                          */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev The scalar of ETH and most ERC20s.\n    uint256 internal constant WAD = 1e18;\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*              SIMPLIFIED FIXED POINT OPERATIONS             */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Equivalent to `(x * y) / WAD` rounded down.\n    function mulWad(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Equivalent to `require(y == 0 || x <= type(uint256).max / y)`.\n            if mul(y, gt(x, div(not(0), y))) {\n                mstore(0x00, 0xbac65e5b) // `MulWadFailed()`.\n                revert(0x1c, 0x04)\n            }\n            z := div(mul(x, y), WAD)\n        }\n    }\n\n    /// @dev Equivalent to `(x * y) / WAD` rounded down.\n    function sMulWad(int256 x, int256 y) internal pure returns (int256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := mul(x, y)\n            // Equivalent to `require((x == 0 || z / x == y) && !(x == -1 && y == type(int256).min))`.\n            if iszero(gt(or(iszero(x), eq(sdiv(z, x), y)), lt(not(x), eq(y, shl(255, 1))))) {\n                mstore(0x00, 0xedcd4dd4) // `SMulWadFailed()`.\n                revert(0x1c, 0x04)\n            }\n            z := sdiv(z, WAD)\n        }\n    }\n\n    /// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks.\n    function rawMulWad(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := div(mul(x, y), WAD)\n        }\n    }\n\n    /// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks.\n    function rawSMulWad(int256 x, int256 y) internal pure returns (int256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := sdiv(mul(x, y), WAD)\n        }\n    }\n\n    /// @dev Equivalent to `(x * y) / WAD` rounded up.\n    function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Equivalent to `require(y == 0 || x <= type(uint256).max / y)`.\n            if mul(y, gt(x, div(not(0), y))) {\n                mstore(0x00, 0xbac65e5b) // `MulWadFailed()`.\n                revert(0x1c, 0x04)\n            }\n            z := add(iszero(iszero(mod(mul(x, y), WAD))), div(mul(x, y), WAD))\n        }\n    }\n\n    /// @dev Equivalent to `(x * y) / WAD` rounded up, but without overflow checks.\n    function rawMulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := add(iszero(iszero(mod(mul(x, y), WAD))), div(mul(x, y), WAD))\n        }\n    }\n\n    /// @dev Equivalent to `(x * WAD) / y` rounded down.\n    function divWad(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Equivalent to `require(y != 0 && (WAD == 0 || x <= type(uint256).max / WAD))`.\n            if iszero(mul(y, iszero(mul(WAD, gt(x, div(not(0), WAD)))))) {\n                mstore(0x00, 0x7c5f487d) // `DivWadFailed()`.\n                revert(0x1c, 0x04)\n            }\n            z := div(mul(x, WAD), y)\n        }\n    }\n\n    /// @dev Equivalent to `(x * WAD) / y` rounded down.\n    function sDivWad(int256 x, int256 y) internal pure returns (int256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := mul(x, WAD)\n            // Equivalent to `require(y != 0 && ((x * WAD) / WAD == x))`.\n            if iszero(and(iszero(iszero(y)), eq(sdiv(z, WAD), x))) {\n                mstore(0x00, 0x5c43740d) // `SDivWadFailed()`.\n                revert(0x1c, 0x04)\n            }\n            z := sdiv(mul(x, WAD), y)\n        }\n    }\n\n    /// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks.\n    function rawDivWad(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := div(mul(x, WAD), y)\n        }\n    }\n\n    /// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks.\n    function rawSDivWad(int256 x, int256 y) internal pure returns (int256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := sdiv(mul(x, WAD), y)\n        }\n    }\n\n    /// @dev Equivalent to `(x * WAD) / y` rounded up.\n    function divWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Equivalent to `require(y != 0 && (WAD == 0 || x <= type(uint256).max / WAD))`.\n            if iszero(mul(y, iszero(mul(WAD, gt(x, div(not(0), WAD)))))) {\n                mstore(0x00, 0x7c5f487d) // `DivWadFailed()`.\n                revert(0x1c, 0x04)\n            }\n            z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y))\n        }\n    }\n\n    /// @dev Equivalent to `(x * WAD) / y` rounded up, but without overflow and divide by zero checks.\n    function rawDivWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y))\n        }\n    }\n\n    /// @dev Equivalent to `x` to the power of `y`.\n    /// because `x ** y = (e ** ln(x)) ** y = e ** (ln(x) * y)`.\n    function powWad(int256 x, int256 y) internal pure returns (int256) {\n        // Using `ln(x)` means `x` must be greater than 0.\n        return expWad((lnWad(x) * y) / int256(WAD));\n    }\n\n    /// @dev Returns `exp(x)`, denominated in `WAD`.\n    /// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln\n    function expWad(int256 x) internal pure returns (int256 r) {\n        unchecked {\n            // When the result is less than 0.5 we return zero.\n            // This happens when `x <= (log(1e-18) * 1e18) ~ -4.15e19`.\n            if (x <= -41446531673892822313) return r;\n\n            /// @solidity memory-safe-assembly\n            assembly {\n                // When the result is greater than `(2**255 - 1) / 1e18` we can not represent it as\n                // an int. This happens when `x >= floor(log((2**255 - 1) / 1e18) * 1e18) ≈ 135`.\n                if iszero(slt(x, 135305999368893231589)) {\n                    mstore(0x00, 0xa37bfec9) // `ExpOverflow()`.\n                    revert(0x1c, 0x04)\n                }\n            }\n\n            // `x` is now in the range `(-42, 136) * 1e18`. Convert to `(-42, 136) * 2**96`\n            // for more intermediate precision and a binary basis. This base conversion\n            // is a multiplication by 1e18 / 2**96 = 5**18 / 2**78.\n            x = (x << 78) / 5 ** 18;\n\n            // Reduce range of x to (-½ ln 2, ½ ln 2) * 2**96 by factoring out powers\n            // of two such that exp(x) = exp(x') * 2**k, where k is an integer.\n            // Solving this gives k = round(x / log(2)) and x' = x - k * log(2).\n            int256 k = ((x << 96) / 54916777467707473351141471128 + 2 ** 95) >> 96;\n            x = x - k * 54916777467707473351141471128;\n\n            // `k` is in the range `[-61, 195]`.\n\n            // Evaluate using a (6, 7)-term rational approximation.\n            // `p` is made monic, we'll multiply by a scale factor later.\n            int256 y = x + 1346386616545796478920950773328;\n            y = ((y * x) >> 96) + 57155421227552351082224309758442;\n            int256 p = y + x - 94201549194550492254356042504812;\n            p = ((p * y) >> 96) + 28719021644029726153956944680412240;\n            p = p * x + (4385272521454847904659076985693276 << 96);\n\n            // We leave `p` in `2**192` basis so we don't need to scale it back up for the division.\n            int256 q = x - 2855989394907223263936484059900;\n            q = ((q * x) >> 96) + 50020603652535783019961831881945;\n            q = ((q * x) >> 96) - 533845033583426703283633433725380;\n            q = ((q * x) >> 96) + 3604857256930695427073651918091429;\n            q = ((q * x) >> 96) - 14423608567350463180887372962807573;\n            q = ((q * x) >> 96) + 26449188498355588339934803723976023;\n\n            /// @solidity memory-safe-assembly\n            assembly {\n                // Div in assembly because solidity adds a zero check despite the unchecked.\n                // The q polynomial won't have zeros in the domain as all its roots are complex.\n                // No scaling is necessary because p is already `2**96` too large.\n                r := sdiv(p, q)\n            }\n\n            // r should be in the range `(0.09, 0.25) * 2**96`.\n\n            // We now need to multiply r by:\n            // - The scale factor `s ≈ 6.031367120`.\n            // - The `2**k` factor from the range reduction.\n            // - The `1e18 / 2**96` factor for base conversion.\n            // We do this all at once, with an intermediate result in `2**213`\n            // basis, so the final right shift is always by a positive amount.\n            r = int256(\n                (uint256(r) * 3822833074963236453042738258902158003155416615667) >> uint256(195 - k)\n            );\n        }\n    }\n\n    /// @dev Returns `ln(x)`, denominated in `WAD`.\n    /// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln\n    function lnWad(int256 x) internal pure returns (int256 r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // We want to convert `x` from `10**18` fixed point to `2**96` fixed point.\n            // We do this by multiplying by `2**96 / 10**18`. But since\n            // `ln(x * C) = ln(x) + ln(C)`, we can simply do nothing here\n            // and add `ln(2**96 / 10**18)` at the end.\n\n            // Compute `k = log2(x) - 96`, `r = 159 - k = 255 - log2(x) = 255 ^ log2(x)`.\n            r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))\n            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))\n            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))\n            r := or(r, shl(4, lt(0xffff, shr(r, x))))\n            r := or(r, shl(3, lt(0xff, shr(r, x))))\n            // We place the check here for more optimal stack operations.\n            if iszero(sgt(x, 0)) {\n                mstore(0x00, 0x1615e638) // `LnWadUndefined()`.\n                revert(0x1c, 0x04)\n            }\n            // forgefmt: disable-next-item\n            r := xor(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),\n                0xf8f9f9faf9fdfafbf9fdfcfdfafbfcfef9fafdfafcfcfbfefafafcfbffffffff))\n\n            // Reduce range of x to (1, 2) * 2**96\n            // ln(2^k * x) = k * ln(2) + ln(x)\n            x := shr(159, shl(r, x))\n\n            // Evaluate using a (8, 8)-term rational approximation.\n            // `p` is made monic, we will multiply by a scale factor later.\n            // forgefmt: disable-next-item\n            let p := sub( // This heavily nested expression is to avoid stack-too-deep for via-ir.\n                sar(96, mul(add(43456485725739037958740375743393,\n                sar(96, mul(add(24828157081833163892658089445524,\n                sar(96, mul(add(3273285459638523848632254066296,\n                    x), x))), x))), x)), 11111509109440967052023855526967)\n            p := sub(sar(96, mul(p, x)), 45023709667254063763336534515857)\n            p := sub(sar(96, mul(p, x)), 14706773417378608786704636184526)\n            p := sub(mul(p, x), shl(96, 795164235651350426258249787498))\n            // We leave `p` in `2**192` basis so we don't need to scale it back up for the division.\n\n            // `q` is monic by convention.\n            let q := add(5573035233440673466300451813936, x)\n            q := add(71694874799317883764090561454958, sar(96, mul(x, q)))\n            q := add(283447036172924575727196451306956, sar(96, mul(x, q)))\n            q := add(401686690394027663651624208769553, sar(96, mul(x, q)))\n            q := add(204048457590392012362485061816622, sar(96, mul(x, q)))\n            q := add(31853899698501571402653359427138, sar(96, mul(x, q)))\n            q := add(909429971244387300277376558375, sar(96, mul(x, q)))\n\n            // `p / q` is in the range `(0, 0.125) * 2**96`.\n\n            // Finalization, we need to:\n            // - Multiply by the scale factor `s = 5.549…`.\n            // - Add `ln(2**96 / 10**18)`.\n            // - Add `k * ln(2)`.\n            // - Multiply by `10**18 / 2**96 = 5**18 >> 78`.\n\n            // The q polynomial is known not to have zeros in the domain.\n            // No scaling required because p is already `2**96` too large.\n            p := sdiv(p, q)\n            // Multiply by the scaling factor: `s * 5**18 * 2**96`, base is now `5**18 * 2**192`.\n            p := mul(1677202110996718588342820967067443963516166, p)\n            // Add `ln(2) * k * 5**18 * 2**192`.\n            // forgefmt: disable-next-item\n            p := add(mul(16597577552685614221487285958193947469193820559219878177908093499208371, sub(159, r)), p)\n            // Add `ln(2**96 / 10**18) * 5**18 * 2**192`.\n            p := add(600920179829731861736702779321621459595472258049074101567377883020018308, p)\n            // Base conversion: mul `2**18 / 2**192`.\n            r := sar(174, p)\n        }\n    }\n\n    /// @dev Returns `W_0(x)`, denominated in `WAD`.\n    /// See: https://en.wikipedia.org/wiki/Lambert_W_function\n    /// a.k.a. Product log function. This is an approximation of the principal branch.\n    function lambertW0Wad(int256 x) internal pure returns (int256 w) {\n        // forgefmt: disable-next-item\n        unchecked {\n            if ((w = x) <= -367879441171442322) revert OutOfDomain(); // `x` less than `-1/e`.\n            int256 wad = int256(WAD);\n            int256 p = x;\n            uint256 c; // Whether we need to avoid catastrophic cancellation.\n            uint256 i = 4; // Number of iterations.\n            if (w <= 0x1ffffffffffff) {\n                if (-0x4000000000000 <= w) {\n                    i = 1; // Inputs near zero only take one step to converge.\n                } else if (w <= -0x3ffffffffffffff) {\n                    i = 32; // Inputs near `-1/e` take very long to converge.\n                }\n            } else if (w >> 63 == 0) {\n                /// @solidity memory-safe-assembly\n                assembly {\n                    // Inline log2 for more performance, since the range is small.\n                    let v := shr(49, w)\n                    let l := shl(3, lt(0xff, v))\n                    l := add(or(l, byte(and(0x1f, shr(shr(l, v), 0x8421084210842108cc6318c6db6d54be)),\n                        0x0706060506020504060203020504030106050205030304010505030400000000)), 49)\n                    w := sdiv(shl(l, 7), byte(sub(l, 31), 0x0303030303030303040506080c13))\n                    c := gt(l, 60)\n                    i := add(2, add(gt(l, 53), c))\n                }\n            } else {\n                int256 ll = lnWad(w = lnWad(w));\n                /// @solidity memory-safe-assembly\n                assembly {\n                    // `w = ln(x) - ln(ln(x)) + b * ln(ln(x)) / ln(x)`.\n                    w := add(sdiv(mul(ll, 1023715080943847266), w), sub(w, ll))\n                    i := add(3, iszero(shr(68, x)))\n                    c := iszero(shr(143, x))\n                }\n                if (c == 0) {\n                    do { // If `x` is big, use Newton's so that intermediate values won't overflow.\n                        int256 e = expWad(w);\n                        /// @solidity memory-safe-assembly\n                        assembly {\n                            let t := mul(w, div(e, wad))\n                            w := sub(w, sdiv(sub(t, x), div(add(e, t), wad)))\n                        }\n                        if (p <= w) break;\n                        p = w;\n                    } while (--i != 0);\n                    /// @solidity memory-safe-assembly\n                    assembly {\n                        w := sub(w, sgt(w, 2))\n                    }\n                    return w;\n                }\n            }\n            do { // Otherwise, use Halley's for faster convergence.\n                int256 e = expWad(w);\n                /// @solidity memory-safe-assembly\n                assembly {\n                    let t := add(w, wad)\n                    let s := sub(mul(w, e), mul(x, wad))\n                    w := sub(w, sdiv(mul(s, wad), sub(mul(e, t), sdiv(mul(add(t, wad), s), add(t, t)))))\n                }\n                if (p <= w) break;\n                p = w;\n            } while (--i != c);\n            /// @solidity memory-safe-assembly\n            assembly {\n                w := sub(w, sgt(w, 2))\n            }\n            // For certain ranges of `x`, we'll use the quadratic-rate recursive formula of\n            // R. Iacono and J.P. Boyd for the last iteration, to avoid catastrophic cancellation.\n            if (c != 0) {\n                int256 t = w | 1;\n                /// @solidity memory-safe-assembly\n                assembly {\n                    x := sdiv(mul(x, wad), t)\n                }\n                x = (t * (wad + lnWad(x)));\n                /// @solidity memory-safe-assembly\n                assembly {\n                    w := sdiv(x, add(wad, t))\n                }\n            }\n        }\n    }\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                  GENERAL NUMBER UTILITIES                  */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Calculates `floor(x * y / d)` with full precision.\n    /// Throws if result overflows a uint256 or when `d` is zero.\n    /// Credit to Remco Bloemen under MIT license: https://2π.com/21/muldiv\n    function fullMulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 result) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            for {} 1 {} {\n                // 512-bit multiply `[p1 p0] = x * y`.\n                // Compute the product mod `2**256` and mod `2**256 - 1`\n                // then use the Chinese Remainder Theorem to reconstruct\n                // the 512 bit result. The result is stored in two 256\n                // variables such that `product = p1 * 2**256 + p0`.\n\n                // Least significant 256 bits of the product.\n                result := mul(x, y) // Temporarily use `result` as `p0` to save gas.\n                let mm := mulmod(x, y, not(0))\n                // Most significant 256 bits of the product.\n                let p1 := sub(mm, add(result, lt(mm, result)))\n\n                // Handle non-overflow cases, 256 by 256 division.\n                if iszero(p1) {\n                    if iszero(d) {\n                        mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.\n                        revert(0x1c, 0x04)\n                    }\n                    result := div(result, d)\n                    break\n                }\n\n                // Make sure the result is less than `2**256`. Also prevents `d == 0`.\n                if iszero(gt(d, p1)) {\n                    mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.\n                    revert(0x1c, 0x04)\n                }\n\n                /*------------------- 512 by 256 division --------------------*/\n\n                // Make division exact by subtracting the remainder from `[p1 p0]`.\n                // Compute remainder using mulmod.\n                let r := mulmod(x, y, d)\n                // `t` is the least significant bit of `d`.\n                // Always greater or equal to 1.\n                let t := and(d, sub(0, d))\n                // Divide `d` by `t`, which is a power of two.\n                d := div(d, t)\n                // Invert `d mod 2**256`\n                // Now that `d` is an odd number, it has an inverse\n                // modulo `2**256` such that `d * inv = 1 mod 2**256`.\n                // Compute the inverse by starting with a seed that is correct\n                // correct for four bits. That is, `d * inv = 1 mod 2**4`.\n                let inv := xor(2, mul(3, d))\n                // Now use Newton-Raphson iteration to improve the precision.\n                // Thanks to Hensel's lifting lemma, this also works in modular\n                // arithmetic, doubling the correct bits in each step.\n                inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**8\n                inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**16\n                inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**32\n                inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**64\n                inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**128\n                result :=\n                    mul(\n                        // Divide [p1 p0] by the factors of two.\n                        // Shift in bits from `p1` into `p0`. For this we need\n                        // to flip `t` such that it is `2**256 / t`.\n                        or(\n                            mul(sub(p1, gt(r, result)), add(div(sub(0, t), t), 1)),\n                            div(sub(result, r), t)\n                        ),\n                        // inverse mod 2**256\n                        mul(inv, sub(2, mul(d, inv)))\n                    )\n                break\n            }\n        }\n    }\n\n    /// @dev Calculates `floor(x * y / d)` with full precision, rounded up.\n    /// Throws if result overflows a uint256 or when `d` is zero.\n    /// Credit to Uniswap-v3-core under MIT license:\n    /// https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/FullMath.sol\n    function fullMulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 result) {\n        result = fullMulDiv(x, y, d);\n        /// @solidity memory-safe-assembly\n        assembly {\n            if mulmod(x, y, d) {\n                result := add(result, 1)\n                if iszero(result) {\n                    mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.\n                    revert(0x1c, 0x04)\n                }\n            }\n        }\n    }\n\n    /// @dev Returns `floor(x * y / d)`.\n    /// Reverts if `x * y` overflows, or `d` is zero.\n    function mulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Equivalent to require(d != 0 && (y == 0 || x <= type(uint256).max / y))\n            if iszero(mul(d, iszero(mul(y, gt(x, div(not(0), y)))))) {\n                mstore(0x00, 0xad251c27) // `MulDivFailed()`.\n                revert(0x1c, 0x04)\n            }\n            z := div(mul(x, y), d)\n        }\n    }\n\n    /// @dev Returns `ceil(x * y / d)`.\n    /// Reverts if `x * y` overflows, or `d` is zero.\n    function mulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Equivalent to require(d != 0 && (y == 0 || x <= type(uint256).max / y))\n            if iszero(mul(d, iszero(mul(y, gt(x, div(not(0), y)))))) {\n                mstore(0x00, 0xad251c27) // `MulDivFailed()`.\n                revert(0x1c, 0x04)\n            }\n            z := add(iszero(iszero(mod(mul(x, y), d))), div(mul(x, y), d))\n        }\n    }\n\n    /// @dev Returns `ceil(x / d)`.\n    /// Reverts if `d` is zero.\n    function divUp(uint256 x, uint256 d) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            if iszero(d) {\n                mstore(0x00, 0x65244e4e) // `DivFailed()`.\n                revert(0x1c, 0x04)\n            }\n            z := add(iszero(iszero(mod(x, d))), div(x, d))\n        }\n    }\n\n    /// @dev Returns `max(0, x - y)`.\n    function zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := mul(gt(x, y), sub(x, y))\n        }\n    }\n\n    /// @dev Exponentiate `x` to `y` by squaring, denominated in base `b`.\n    /// Reverts if the computation overflows.\n    function rpow(uint256 x, uint256 y, uint256 b) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := mul(b, iszero(y)) // `0 ** 0 = 1`. Otherwise, `0 ** n = 0`.\n            if x {\n                z := xor(b, mul(xor(b, x), and(y, 1))) // `z = isEven(y) ? scale : x`\n                let half := shr(1, b) // Divide `b` by 2.\n                // Divide `y` by 2 every iteration.\n                for { y := shr(1, y) } y { y := shr(1, y) } {\n                    let xx := mul(x, x) // Store x squared.\n                    let xxRound := add(xx, half) // Round to the nearest number.\n                    // Revert if `xx + half` overflowed, or if `x ** 2` overflows.\n                    if or(lt(xxRound, xx), shr(128, x)) {\n                        mstore(0x00, 0x49f7642b) // `RPowOverflow()`.\n                        revert(0x1c, 0x04)\n                    }\n                    x := div(xxRound, b) // Set `x` to scaled `xxRound`.\n                    // If `y` is odd:\n                    if and(y, 1) {\n                        let zx := mul(z, x) // Compute `z * x`.\n                        let zxRound := add(zx, half) // Round to the nearest number.\n                        // If `z * x` overflowed or `zx + half` overflowed:\n                        if or(xor(div(zx, x), z), lt(zxRound, zx)) {\n                            // Revert if `x` is non-zero.\n                            if iszero(iszero(x)) {\n                                mstore(0x00, 0x49f7642b) // `RPowOverflow()`.\n                                revert(0x1c, 0x04)\n                            }\n                        }\n                        z := div(zxRound, b) // Return properly scaled `zxRound`.\n                    }\n                }\n            }\n        }\n    }\n\n    /// @dev Returns the square root of `x`.\n    function sqrt(uint256 x) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // `floor(sqrt(2**15)) = 181`. `sqrt(2**15) - 181 = 2.84`.\n            z := 181 // The \"correct\" value is 1, but this saves a multiplication later.\n\n            // This segment is to get a reasonable initial estimate for the Babylonian method. With a bad\n            // start, the correct # of bits increases ~linearly each iteration instead of ~quadratically.\n\n            // Let `y = x / 2**r`. We check `y >= 2**(k + 8)`\n            // but shift right by `k` bits to ensure that if `x >= 256`, then `y >= 256`.\n            let r := shl(7, lt(0xffffffffffffffffffffffffffffffffff, x))\n            r := or(r, shl(6, lt(0xffffffffffffffffff, shr(r, x))))\n            r := or(r, shl(5, lt(0xffffffffff, shr(r, x))))\n            r := or(r, shl(4, lt(0xffffff, shr(r, x))))\n            z := shl(shr(1, r), z)\n\n            // Goal was to get `z*z*y` within a small factor of `x`. More iterations could\n            // get y in a tighter range. Currently, we will have y in `[256, 256*(2**16))`.\n            // We ensured `y >= 256` so that the relative difference between `y` and `y+1` is small.\n            // That's not possible if `x < 256` but we can just verify those cases exhaustively.\n\n            // Now, `z*z*y <= x < z*z*(y+1)`, and `y <= 2**(16+8)`, and either `y >= 256`, or `x < 256`.\n            // Correctness can be checked exhaustively for `x < 256`, so we assume `y >= 256`.\n            // Then `z*sqrt(y)` is within `sqrt(257)/sqrt(256)` of `sqrt(x)`, or about 20bps.\n\n            // For `s` in the range `[1/256, 256]`, the estimate `f(s) = (181/1024) * (s+1)`\n            // is in the range `(1/2.84 * sqrt(s), 2.84 * sqrt(s))`,\n            // with largest error when `s = 1` and when `s = 256` or `1/256`.\n\n            // Since `y` is in `[256, 256*(2**16))`, let `a = y/65536`, so that `a` is in `[1/256, 256)`.\n            // Then we can estimate `sqrt(y)` using\n            // `sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2**18`.\n\n            // There is no overflow risk here since `y < 2**136` after the first branch above.\n            z := shr(18, mul(z, add(shr(r, x), 65536))) // A `mul()` is saved from starting `z` at 181.\n\n            // Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough.\n            z := shr(1, add(z, div(x, z)))\n            z := shr(1, add(z, div(x, z)))\n            z := shr(1, add(z, div(x, z)))\n            z := shr(1, add(z, div(x, z)))\n            z := shr(1, add(z, div(x, z)))\n            z := shr(1, add(z, div(x, z)))\n            z := shr(1, add(z, div(x, z)))\n\n            // If `x+1` is a perfect square, the Babylonian method cycles between\n            // `floor(sqrt(x))` and `ceil(sqrt(x))`. This statement ensures we return floor.\n            // See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division\n            z := sub(z, lt(div(x, z), z))\n        }\n    }\n\n    /// @dev Returns the cube root of `x`.\n    /// Credit to bout3fiddy and pcaversaccio under AGPLv3 license:\n    /// https://github.com/pcaversaccio/snekmate/blob/main/src/utils/Math.vy\n    function cbrt(uint256 x) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))\n            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))\n            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))\n            r := or(r, shl(4, lt(0xffff, shr(r, x))))\n            r := or(r, shl(3, lt(0xff, shr(r, x))))\n\n            z := div(shl(div(r, 3), shl(lt(0xf, shr(r, x)), 0xf)), xor(7, mod(r, 3)))\n\n            z := div(add(add(div(x, mul(z, z)), z), z), 3)\n            z := div(add(add(div(x, mul(z, z)), z), z), 3)\n            z := div(add(add(div(x, mul(z, z)), z), z), 3)\n            z := div(add(add(div(x, mul(z, z)), z), z), 3)\n            z := div(add(add(div(x, mul(z, z)), z), z), 3)\n            z := div(add(add(div(x, mul(z, z)), z), z), 3)\n            z := div(add(add(div(x, mul(z, z)), z), z), 3)\n\n            z := sub(z, lt(div(x, mul(z, z)), z))\n        }\n    }\n\n    /// @dev Returns the square root of `x`, denominated in `WAD`.\n    function sqrtWad(uint256 x) internal pure returns (uint256 z) {\n        unchecked {\n            z = 10 ** 9;\n            if (x <= type(uint256).max / 10 ** 36 - 1) {\n                x *= 10 ** 18;\n                z = 1;\n            }\n            z *= sqrt(x);\n        }\n    }\n\n    /// @dev Returns the cube root of `x`, denominated in `WAD`.\n    function cbrtWad(uint256 x) internal pure returns (uint256 z) {\n        unchecked {\n            z = 10 ** 12;\n            if (x <= (type(uint256).max / 10 ** 36) * 10 ** 18 - 1) {\n                if (x >= type(uint256).max / 10 ** 36) {\n                    x *= 10 ** 18;\n                    z = 10 ** 6;\n                } else {\n                    x *= 10 ** 36;\n                    z = 1;\n                }\n            }\n            z *= cbrt(x);\n        }\n    }\n\n    /// @dev Returns the factorial of `x`.\n    function factorial(uint256 x) internal pure returns (uint256 result) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            if iszero(lt(x, 58)) {\n                mstore(0x00, 0xaba0f2a2) // `FactorialOverflow()`.\n                revert(0x1c, 0x04)\n            }\n            for { result := 1 } x { x := sub(x, 1) } { result := mul(result, x) }\n        }\n    }\n\n    /// @dev Returns the log2 of `x`.\n    /// Equivalent to computing the index of the most significant bit (MSB) of `x`.\n    /// Returns 0 if `x` is zero.\n    function log2(uint256 x) internal pure returns (uint256 r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))\n            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))\n            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))\n            r := or(r, shl(4, lt(0xffff, shr(r, x))))\n            r := or(r, shl(3, lt(0xff, shr(r, x))))\n            // forgefmt: disable-next-item\n            r := or(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),\n                0x0706060506020504060203020504030106050205030304010505030400000000))\n        }\n    }\n\n    /// @dev Returns the log2 of `x`, rounded up.\n    /// Returns 0 if `x` is zero.\n    function log2Up(uint256 x) internal pure returns (uint256 r) {\n        r = log2(x);\n        /// @solidity memory-safe-assembly\n        assembly {\n            r := add(r, lt(shl(r, 1), x))\n        }\n    }\n\n    /// @dev Returns the log10 of `x`.\n    /// Returns 0 if `x` is zero.\n    function log10(uint256 x) internal pure returns (uint256 r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            if iszero(lt(x, 100000000000000000000000000000000000000)) {\n                x := div(x, 100000000000000000000000000000000000000)\n                r := 38\n            }\n            if iszero(lt(x, 100000000000000000000)) {\n                x := div(x, 100000000000000000000)\n                r := add(r, 20)\n            }\n            if iszero(lt(x, 10000000000)) {\n                x := div(x, 10000000000)\n                r := add(r, 10)\n            }\n            if iszero(lt(x, 100000)) {\n                x := div(x, 100000)\n                r := add(r, 5)\n            }\n            r := add(r, add(gt(x, 9), add(gt(x, 99), add(gt(x, 999), gt(x, 9999)))))\n        }\n    }\n\n    /// @dev Returns the log10 of `x`, rounded up.\n    /// Returns 0 if `x` is zero.\n    function log10Up(uint256 x) internal pure returns (uint256 r) {\n        r = log10(x);\n        /// @solidity memory-safe-assembly\n        assembly {\n            r := add(r, lt(exp(10, r), x))\n        }\n    }\n\n    /// @dev Returns the log256 of `x`.\n    /// Returns 0 if `x` is zero.\n    function log256(uint256 x) internal pure returns (uint256 r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))\n            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))\n            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))\n            r := or(r, shl(4, lt(0xffff, shr(r, x))))\n            r := or(shr(3, r), lt(0xff, shr(r, x)))\n        }\n    }\n\n    /// @dev Returns the log256 of `x`, rounded up.\n    /// Returns 0 if `x` is zero.\n    function log256Up(uint256 x) internal pure returns (uint256 r) {\n        r = log256(x);\n        /// @solidity memory-safe-assembly\n        assembly {\n            r := add(r, lt(shl(shl(3, r), 1), x))\n        }\n    }\n\n    /// @dev Returns the scientific notation format `mantissa * 10 ** exponent` of `x`.\n    /// Useful for compressing prices (e.g. using 25 bit mantissa and 7 bit exponent).\n    function sci(uint256 x) internal pure returns (uint256 mantissa, uint256 exponent) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            mantissa := x\n            if mantissa {\n                if iszero(mod(mantissa, 1000000000000000000000000000000000)) {\n                    mantissa := div(mantissa, 1000000000000000000000000000000000)\n                    exponent := 33\n                }\n                if iszero(mod(mantissa, 10000000000000000000)) {\n                    mantissa := div(mantissa, 10000000000000000000)\n                    exponent := add(exponent, 19)\n                }\n                if iszero(mod(mantissa, 1000000000000)) {\n                    mantissa := div(mantissa, 1000000000000)\n                    exponent := add(exponent, 12)\n                }\n                if iszero(mod(mantissa, 1000000)) {\n                    mantissa := div(mantissa, 1000000)\n                    exponent := add(exponent, 6)\n                }\n                if iszero(mod(mantissa, 10000)) {\n                    mantissa := div(mantissa, 10000)\n                    exponent := add(exponent, 4)\n                }\n                if iszero(mod(mantissa, 100)) {\n                    mantissa := div(mantissa, 100)\n                    exponent := add(exponent, 2)\n                }\n                if iszero(mod(mantissa, 10)) {\n                    mantissa := div(mantissa, 10)\n                    exponent := add(exponent, 1)\n                }\n            }\n        }\n    }\n\n    /// @dev Convenience function for packing `x` into a smaller number using `sci`.\n    /// The `mantissa` will be in bits [7..255] (the upper 249 bits).\n    /// The `exponent` will be in bits [0..6] (the lower 7 bits).\n    /// Use `SafeCastLib` to safely ensure that the `packed` number is small\n    /// enough to fit in the desired unsigned integer type:\n    /// ```\n    ///     uint32 packed = SafeCastLib.toUint32(FixedPointMathLib.packSci(777 ether));\n    /// ```\n    function packSci(uint256 x) internal pure returns (uint256 packed) {\n        (x, packed) = sci(x); // Reuse for `mantissa` and `exponent`.\n        /// @solidity memory-safe-assembly\n        assembly {\n            if shr(249, x) {\n                mstore(0x00, 0xce30380c) // `MantissaOverflow()`.\n                revert(0x1c, 0x04)\n            }\n            packed := or(shl(7, x), packed)\n        }\n    }\n\n    /// @dev Convenience function for unpacking a packed number from `packSci`.\n    function unpackSci(uint256 packed) internal pure returns (uint256 unpacked) {\n        unchecked {\n            unpacked = (packed >> 7) * 10 ** (packed & 0x7f);\n        }\n    }\n\n    /// @dev Returns the average of `x` and `y`.\n    function avg(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        unchecked {\n            z = (x & y) + ((x ^ y) >> 1);\n        }\n    }\n\n    /// @dev Returns the average of `x` and `y`.\n    function avg(int256 x, int256 y) internal pure returns (int256 z) {\n        unchecked {\n            z = (x >> 1) + (y >> 1) + (x & y & 1);\n        }\n    }\n\n    /// @dev Returns the absolute value of `x`.\n    function abs(int256 x) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := xor(sub(0, shr(255, x)), add(sub(0, shr(255, x)), x))\n        }\n    }\n\n    /// @dev Returns the absolute distance between `x` and `y`.\n    function dist(int256 x, int256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := xor(mul(xor(sub(y, x), sub(x, y)), sgt(x, y)), sub(y, x))\n        }\n    }\n\n    /// @dev Returns the minimum of `x` and `y`.\n    function min(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := xor(x, mul(xor(x, y), lt(y, x)))\n        }\n    }\n\n    /// @dev Returns the minimum of `x` and `y`.\n    function min(int256 x, int256 y) internal pure returns (int256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := xor(x, mul(xor(x, y), slt(y, x)))\n        }\n    }\n\n    /// @dev Returns the maximum of `x` and `y`.\n    function max(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := xor(x, mul(xor(x, y), gt(y, x)))\n        }\n    }\n\n    /// @dev Returns the maximum of `x` and `y`.\n    function max(int256 x, int256 y) internal pure returns (int256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := xor(x, mul(xor(x, y), sgt(y, x)))\n        }\n    }\n\n    /// @dev Returns `x`, bounded to `minValue` and `maxValue`.\n    function clamp(uint256 x, uint256 minValue, uint256 maxValue)\n        internal\n        pure\n        returns (uint256 z)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := xor(x, mul(xor(x, minValue), gt(minValue, x)))\n            z := xor(z, mul(xor(z, maxValue), lt(maxValue, z)))\n        }\n    }\n\n    /// @dev Returns `x`, bounded to `minValue` and `maxValue`.\n    function clamp(int256 x, int256 minValue, int256 maxValue) internal pure returns (int256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := xor(x, mul(xor(x, minValue), sgt(minValue, x)))\n            z := xor(z, mul(xor(z, maxValue), slt(maxValue, z)))\n        }\n    }\n\n    /// @dev Returns greatest common divisor of `x` and `y`.\n    function gcd(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            for { z := x } y {} {\n                let t := y\n                y := mod(z, y)\n                z := t\n            }\n        }\n    }\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                   RAW NUMBER OPERATIONS                    */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Returns `x + y`, without checking for overflow.\n    function rawAdd(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        unchecked {\n            z = x + y;\n        }\n    }\n\n    /// @dev Returns `x + y`, without checking for overflow.\n    function rawAdd(int256 x, int256 y) internal pure returns (int256 z) {\n        unchecked {\n            z = x + y;\n        }\n    }\n\n    /// @dev Returns `x - y`, without checking for underflow.\n    function rawSub(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        unchecked {\n            z = x - y;\n        }\n    }\n\n    /// @dev Returns `x - y`, without checking for underflow.\n    function rawSub(int256 x, int256 y) internal pure returns (int256 z) {\n        unchecked {\n            z = x - y;\n        }\n    }\n\n    /// @dev Returns `x * y`, without checking for overflow.\n    function rawMul(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        unchecked {\n            z = x * y;\n        }\n    }\n\n    /// @dev Returns `x * y`, without checking for overflow.\n    function rawMul(int256 x, int256 y) internal pure returns (int256 z) {\n        unchecked {\n            z = x * y;\n        }\n    }\n\n    /// @dev Returns `x / y`, returning 0 if `y` is zero.\n    function rawDiv(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := div(x, y)\n        }\n    }\n\n    /// @dev Returns `x / y`, returning 0 if `y` is zero.\n    function rawSDiv(int256 x, int256 y) internal pure returns (int256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := sdiv(x, y)\n        }\n    }\n\n    /// @dev Returns `x % y`, returning 0 if `y` is zero.\n    function rawMod(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := mod(x, y)\n        }\n    }\n\n    /// @dev Returns `x % y`, returning 0 if `y` is zero.\n    function rawSMod(int256 x, int256 y) internal pure returns (int256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := smod(x, y)\n        }\n    }\n\n    /// @dev Returns `(x + y) % d`, return 0 if `d` if zero.\n    function rawAddMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := addmod(x, y, d)\n        }\n    }\n\n    /// @dev Returns `(x * y) % d`, return 0 if `d` if zero.\n    function rawMulMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := mulmod(x, y, d)\n        }\n    }\n}\n"
      },
      "node_modules/@aperture_finance/uni-v3-lib/src/SqrtPriceMath.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.8.4;\n\nimport \"@uniswap/v3-core/contracts/libraries/FixedPoint96.sol\";\n\nimport \"./FullMath.sol\";\nimport \"./SafeCast.sol\";\nimport \"./TernaryLib.sol\";\nimport \"./UnsafeMath.sol\";\n\n/// @title Functions based on Q64.96 sqrt price and liquidity\n/// @author Aperture Finance\n/// @author Modified from Uniswap (https://github.com/uniswap/v3-core/blob/main/contracts/libraries/SqrtPriceMath.sol)\n/// @notice Contains the math that uses square root of price as a Q64.96 and liquidity to compute deltas\nlibrary SqrtPriceMath {\n    using UnsafeMath for *;\n    using SafeCast for uint256;\n\n    /// @notice Gets the next sqrt price given a delta of token0\n    /// @dev Always rounds up, because in the exact output case (increasing price) we need to move the price at least\n    /// far enough to get the desired output amount, and in the exact input case (decreasing price) we need to move the\n    /// price less in order to not send too much output.\n    /// The most precise formula for this is liquidity * sqrtPX96 / (liquidity +- amount * sqrtPX96),\n    /// if this is impossible because of overflow, we calculate liquidity / (liquidity / sqrtPX96 +- amount).\n    /// @param sqrtPX96 The starting price, i.e. before accounting for the token0 delta\n    /// @param liquidity The amount of usable liquidity\n    /// @param amount How much of token0 to add or remove from virtual reserves\n    /// @param add Whether to add or remove the amount of token0\n    /// @return The price after adding or removing amount, depending on add\n    function getNextSqrtPriceFromAmount0RoundingUp(\n        uint160 sqrtPX96,\n        uint128 liquidity,\n        uint256 amount,\n        bool add\n    ) internal pure returns (uint160) {\n        // we short circuit amount == 0 because the result is otherwise not guaranteed to equal the input price\n        if (amount == 0) return sqrtPX96;\n        uint256 numerator1 = uint256(liquidity) << FixedPoint96.RESOLUTION;\n\n        if (add) {\n            unchecked {\n                uint256 product = amount * sqrtPX96;\n                // checks for overflow\n                if (product.div(amount) == sqrtPX96) {\n                    // denominator = liquidity + amount * sqrtPX96\n                    uint256 denominator = numerator1 + product;\n                    // checks for overflow\n                    if (denominator >= numerator1)\n                        // always fits in 160 bits\n                        return uint160(FullMath.mulDivRoundingUp(numerator1, sqrtPX96, denominator));\n                }\n            }\n\n            // liquidity / (liquidity / sqrtPX96 + amount)\n            return uint160(numerator1.divRoundingUp(numerator1.div(sqrtPX96) + amount));\n        } else {\n            uint256 denominator;\n            assembly (\"memory-safe\") {\n                // if the product overflows, we know the denominator underflows\n                // in addition, we must check that the denominator does not underflow\n                let product := mul(amount, sqrtPX96)\n                if iszero(and(eq(div(product, amount), sqrtPX96), gt(numerator1, product))) {\n                    revert(0, 0)\n                }\n                denominator := sub(numerator1, product)\n            }\n            return FullMath.mulDivRoundingUp(numerator1, sqrtPX96, denominator).toUint160();\n        }\n    }\n\n    /// @notice Gets the next sqrt price given a delta of token1\n    /// @dev Always rounds down, because in the exact output case (decreasing price) we need to move the price at least\n    /// far enough to get the desired output amount, and in the exact input case (increasing price) we need to move the\n    /// price less in order to not send too much output.\n    /// The formula we compute is within <1 wei of the lossless version: sqrtPX96 +- amount / liquidity\n    /// @param sqrtPX96 The starting price, i.e., before accounting for the token1 delta\n    /// @param liquidity The amount of usable liquidity\n    /// @param amount How much of token1 to add, or remove, from virtual reserves\n    /// @param add Whether to add, or remove, the amount of token1\n    /// @return nextSqrtPrice The price after adding or removing `amount`\n    function getNextSqrtPriceFromAmount1RoundingDown(\n        uint160 sqrtPX96,\n        uint128 liquidity,\n        uint256 amount,\n        bool add\n    ) internal pure returns (uint160 nextSqrtPrice) {\n        // if we're adding (subtracting), rounding down requires rounding the quotient down (up)\n        // in both cases, avoid a mulDiv for most inputs\n        if (add) {\n            uint256 quotient = (\n                amount <= type(uint160).max\n                    ? (amount << FixedPoint96.RESOLUTION).div(liquidity)\n                    : FullMath.mulDiv(amount, FixedPoint96.Q96, liquidity)\n            );\n\n            nextSqrtPrice = (sqrtPX96 + quotient).toUint160();\n        } else {\n            uint256 quotient = (\n                amount <= type(uint160).max\n                    ? (amount << FixedPoint96.RESOLUTION).divRoundingUp(liquidity)\n                    : FullMath.mulDivRoundingUp(amount, FixedPoint96.Q96, liquidity)\n            );\n            assembly (\"memory-safe\") {\n                if iszero(gt(sqrtPX96, quotient)) {\n                    revert(0, 0)\n                }\n                // always fits 160 bits\n                nextSqrtPrice := sub(sqrtPX96, quotient)\n            }\n        }\n    }\n\n    /// @notice Gets the next sqrt price given an input amount of token0 or token1\n    /// @dev Throws if price or liquidity are 0, or if the next price is out of bounds\n    /// @param sqrtPX96 The starting price, i.e., before accounting for the input amount\n    /// @param liquidity The amount of usable liquidity\n    /// @param amountIn How much of token0, or token1, is being swapped in\n    /// @param zeroForOne Whether the amount in is token0 or token1\n    /// @return sqrtQX96 The price after adding the input amount to token0 or token1\n    function getNextSqrtPriceFromInput(\n        uint160 sqrtPX96,\n        uint128 liquidity,\n        uint256 amountIn,\n        bool zeroForOne\n    ) internal pure returns (uint160 sqrtQX96) {\n        assembly (\"memory-safe\") {\n            if or(iszero(sqrtPX96), iszero(liquidity)) {\n                revert(0, 0)\n            }\n        }\n        // round to make sure that we don't pass the target price\n        return\n            zeroForOne\n                ? getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amountIn, true)\n                : getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amountIn, true);\n    }\n\n    /// @notice Gets the next sqrt price given an output amount of token0 or token1\n    /// @dev Throws if price or liquidity are 0 or the next price is out of bounds\n    /// @param sqrtPX96 The starting price before accounting for the output amount\n    /// @param liquidity The amount of usable liquidity\n    /// @param amountOut How much of token0, or token1, is being swapped out\n    /// @param zeroForOne Whether the amount out is token0 or token1\n    /// @return sqrtQX96 The price after removing the output amount of token0 or token1\n    function getNextSqrtPriceFromOutput(\n        uint160 sqrtPX96,\n        uint128 liquidity,\n        uint256 amountOut,\n        bool zeroForOne\n    ) internal pure returns (uint160 sqrtQX96) {\n        assembly (\"memory-safe\") {\n            if or(iszero(sqrtPX96), iszero(liquidity)) {\n                revert(0, 0)\n            }\n        }\n        // round to make sure that we pass the target price\n        return\n            zeroForOne\n                ? getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amountOut, false)\n                : getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amountOut, false);\n    }\n\n    /// @notice Gets the amount0 delta between two prices\n    /// @dev Calculates liquidity / sqrt(lower) - liquidity / sqrt(upper),\n    /// i.e. liquidity * (sqrt(upper) - sqrt(lower)) / (sqrt(upper) * sqrt(lower))\n    /// @param sqrtRatioAX96 A sqrt price assumed to be lower otherwise swapped\n    /// @param sqrtRatioBX96 Another sqrt price\n    /// @param liquidity The amount of usable liquidity\n    /// @param roundUp Whether to round the amount up or down\n    /// @return amount0 Amount of token0 required to cover a position of size liquidity between the two passed prices\n    function getAmount0Delta(\n        uint160 sqrtRatioAX96,\n        uint160 sqrtRatioBX96,\n        uint128 liquidity,\n        bool roundUp\n    ) internal pure returns (uint256 amount0) {\n        (sqrtRatioAX96, sqrtRatioBX96) = TernaryLib.sort2(sqrtRatioAX96, sqrtRatioBX96);\n        assembly (\"memory-safe\") {\n            if iszero(sqrtRatioAX96) {\n                revert(0, 0)\n            }\n        }\n        uint256 numerator1 = uint256(liquidity) << FixedPoint96.RESOLUTION;\n        uint256 numerator2 = sqrtRatioBX96.sub(sqrtRatioAX96);\n        /**\n         * Equivalent to:\n         *   roundUp\n         *       ? FullMath.mulDivRoundingUp(numerator1, numerator2, sqrtRatioBX96).divRoundingUp(sqrtRatioAX96)\n         *       : FullMath.mulDiv(numerator1, numerator2, sqrtRatioBX96) / sqrtRatioAX96;\n         * If `md = mulDiv(n1, n2, srb) == mulDivRoundingUp(n1, n2, srb)`, then `mulmod(n1, n2, srb) == 0`.\n         * Add `roundUp && md % sra > 0` to `div(md, sra)`.\n         * If `md = mulDiv(n1, n2, srb)` and `mulDivRoundingUp(n1, n2, srb)` differs by 1 and `sra > 0`,\n         * then `(md + 1).divRoundingUp(sra) == md.div(sra) + 1` whether `sra` fully divides `md` or not.\n         */\n        uint256 mulDivResult = FullMath.mulDiv(numerator1, numerator2, sqrtRatioBX96);\n        assembly {\n            amount0 := add(\n                div(mulDivResult, sqrtRatioAX96),\n                and(gt(or(mod(mulDivResult, sqrtRatioAX96), mulmod(numerator1, numerator2, sqrtRatioBX96)), 0), roundUp)\n            )\n        }\n    }\n\n    /// @notice Gets the amount1 delta between two prices\n    /// @dev Calculates liquidity * (sqrt(upper) - sqrt(lower))\n    /// @param sqrtRatioAX96 A sqrt price assumed to be lower otherwise swapped\n    /// @param sqrtRatioBX96 Another sqrt price\n    /// @param liquidity The amount of usable liquidity\n    /// @param roundUp Whether to round the amount up, or down\n    /// @return amount1 Amount of token1 required to cover a position of size liquidity between the two passed prices\n    function getAmount1Delta(\n        uint160 sqrtRatioAX96,\n        uint160 sqrtRatioBX96,\n        uint128 liquidity,\n        bool roundUp\n    ) internal pure returns (uint256 amount1) {\n        (sqrtRatioAX96, sqrtRatioBX96) = TernaryLib.sort2(sqrtRatioAX96, sqrtRatioBX96);\n        uint256 numerator = sqrtRatioBX96.sub(sqrtRatioAX96);\n        uint256 denominator = FixedPoint96.Q96;\n        /**\n         * Equivalent to:\n         *   amount1 = roundUp\n         *       ? FullMath.mulDivRoundingUp(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96)\n         *       : FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96);\n         * Cannot overflow because `type(uint128).max * type(uint160).max >> 96 < (1 << 192)`.\n         */\n        amount1 = FullMath.mulDiv96(liquidity, numerator);\n        assembly {\n            amount1 := add(amount1, and(gt(mulmod(liquidity, numerator, denominator), 0), roundUp))\n        }\n    }\n\n    /// @notice Helper that gets signed token0 delta\n    /// @param sqrtRatioAX96 A sqrt price\n    /// @param sqrtRatioBX96 Another sqrt price\n    /// @param liquidity The change in liquidity for which to compute the amount0 delta\n    /// @return amount0 Amount of token0 corresponding to the passed liquidityDelta between the two prices\n    function getAmount0Delta(\n        uint160 sqrtRatioAX96,\n        uint160 sqrtRatioBX96,\n        int128 liquidity\n    ) internal pure returns (int256 amount0) {\n        /**\n         * Equivalent to:\n         *   amount0 = liquidity < 0\n         *       ? -getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(-liquidity), false).toInt256()\n         *       : getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(liquidity), true).toInt256();\n         */\n        bool sign;\n        uint256 mask;\n        uint128 liquidityAbs;\n        assembly {\n            // In case the upper bits are not clean.\n            liquidity := signextend(15, liquidity)\n            // sign = 1 if liquidity >= 0 else 0\n            sign := iszero(slt(liquidity, 0))\n            // mask = 0 if liquidity >= 0 else -1\n            mask := sub(sign, 1)\n            liquidityAbs := xor(mask, add(mask, liquidity))\n        }\n        // amount0Abs = liquidity / sqrt(lower) - liquidity / sqrt(upper) < type(uint224).max\n        // always fits in 224 bits, no need for toInt256()\n        uint256 amount0Abs = getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, liquidityAbs, sign);\n        assembly {\n            // If liquidity >= 0, amount0 = |amount0| = 0 ^ |amount0|\n            // If liquidity < 0, amount0 = -|amount0| = ~|amount0| + 1 = (-1) ^ |amount0| - (-1)\n            amount0 := sub(xor(amount0Abs, mask), mask)\n        }\n    }\n\n    /// @notice Helper that gets signed token1 delta\n    /// @param sqrtRatioAX96 A sqrt price\n    /// @param sqrtRatioBX96 Another sqrt price\n    /// @param liquidity The change in liquidity for which to compute the amount1 delta\n    /// @return amount1 Amount of token1 corresponding to the passed liquidityDelta between the two prices\n    function getAmount1Delta(\n        uint160 sqrtRatioAX96,\n        uint160 sqrtRatioBX96,\n        int128 liquidity\n    ) internal pure returns (int256 amount1) {\n        /**\n         * Equivalent to:\n         *   amount1 = liquidity < 0\n         *       ? -getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(-liquidity), false).toInt256()\n         *       : getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(liquidity), true).toInt256();\n         */\n        bool sign;\n        uint256 mask;\n        uint128 liquidityAbs;\n        assembly {\n            // In case the upper bits are not clean.\n            liquidity := signextend(15, liquidity)\n            // sign = 1 if liquidity >= 0 else 0\n            sign := iszero(slt(liquidity, 0))\n            // mask = 0 if liquidity >= 0 else -1\n            mask := sub(sign, 1)\n            liquidityAbs := xor(mask, add(mask, liquidity))\n        }\n        // amount1Abs = liquidity * (sqrt(upper) - sqrt(lower)) < type(uint192).max\n        // always fits in 192 bits, no need for toInt256()\n        uint256 amount1Abs = getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, liquidityAbs, sign);\n        assembly {\n            // If liquidity >= 0, amount1 = |amount1| = 0 ^ |amount1|\n            // If liquidity < 0, amount1 = -|amount1| = ~|amount1| + 1 = (-1) ^ |amount1| - (-1)\n            amount1 := sub(xor(amount1Abs, mask), mask)\n        }\n    }\n}\n"
      },
      "node_modules/@aperture_finance/uni-v3-lib/src/BitMath.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.5.0;\n\n/// @title BitMath\n/// @author Aperture Finance\n/// @author Modified from Solady (https://github.com/vectorized/solady/blob/main/src/utils/LibBit.sol)\n/// @dev This library provides functionality for computing bit properties of an unsigned integer\nlibrary BitMath {\n    /// @notice Returns the index of the most significant bit of the number,\n    ///     where the least significant bit is at index 0 and the most significant bit is at index 255\n    /// @dev The function satisfies the property:\n    ///     If x == 0, r == 0. Otherwise\n    ///     x >= 2**mostSignificantBit(x) and x < 2**(mostSignificantBit(x)+1)\n    /// @param x the value for which to compute the most significant bit\n    /// @return r the index of the most significant bit\n    function mostSignificantBit(uint256 x) internal pure returns (uint8 r) {\n        assembly {\n            // r = x >= 2**128 ? 128 : 0\n            r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))\n            // r += (x >> r) >= 2**64 ? 64 : 0\n            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))\n            // r += (x >> r) >= 2**32 ? 32 : 0\n            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))\n            r := or(r, shl(4, lt(0xffff, shr(r, x))))\n            r := or(r, shl(3, lt(0xff, shr(r, x))))\n            r := or(\n                r,\n                byte(\n                    and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),\n                    0x0706060506020504060203020504030106050205030304010505030400000000\n                )\n            )\n        }\n    }\n\n    /// @notice Returns the index of the least significant bit of the number,\n    ///     where the least significant bit is at index 0 and the most significant bit is at index 255\n    /// @dev The function satisfies the property:\n    ///     If x == 0, r == 0. Otherwise\n    ///     (x & 2**leastSignificantBit(x)) != 0 and (x & (2**(leastSignificantBit(x)) - 1)) == 0)\n    /// @param x the value for which to compute the least significant bit\n    /// @return r the index of the least significant bit\n    function leastSignificantBit(uint256 x) internal pure returns (uint8 r) {\n        assembly {\n            // Isolate the least significant bit, x = x & -x = x & (~x + 1)\n            x := and(x, sub(0, x))\n\n            // r = x >= 2**128 ? 128 : 0\n            r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))\n            // r += (x >> r) >= 2**64 ? 64 : 0\n            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))\n            // r += (x >> r) >= 2**32 ? 32 : 0\n            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))\n\n            // For the remaining 32 bits, use a De Bruijn lookup.\n            // https://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup\n            r := or(\n                r,\n                byte(\n                    and(div(0xd76453e0, shr(r, x)), 0x1f),\n                    0x001f0d1e100c1d070f090b19131c1706010e11080a1a141802121b1503160405\n                )\n            )\n        }\n    }\n}\n"
      },
      "node_modules/solady/src/tokens/WETH.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.4;\n\nimport {ERC20} from \"./ERC20.sol\";\n\n/// @notice Simple Wrapped Ether implementation.\n/// @author Solady (https://github.com/vectorized/solady/blob/main/src/tokens/WETH.sol)\n/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/WETH.sol)\n/// @author Inspired by WETH9 (https://github.com/dapphub/ds-weth/blob/master/src/weth9.sol)\ncontract WETH is ERC20 {\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                       CUSTOM ERRORS                        */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev The ETH transfer has failed.\n    error ETHTransferFailed();\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                           EVENTS                           */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Emitted when `amount` is deposited from `from`.\n    event Deposit(address indexed from, uint256 amount);\n\n    /// @dev Emitted when `amount` is withdrawn to `to`.\n    event Withdrawal(address indexed to, uint256 amount);\n\n    /// @dev `keccak256(bytes(\"Deposit(address,uint256)\"))`.\n    uint256 private constant _DEPOSIT_EVENT_SIGNATURE =\n        0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c;\n\n    /// @dev `keccak256(bytes(\"Withdrawal(address,uint256)\"))`.\n    uint256 private constant _WITHDRAWAL_EVENT_SIGNATURE =\n        0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65;\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                       ERC20 METADATA                       */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Returns the name of the token.\n    function name() public view virtual override returns (string memory) {\n        return \"Wrapped Ether\";\n    }\n\n    /// @dev Returns the symbol of the token.\n    function symbol() public view virtual override returns (string memory) {\n        return \"WETH\";\n    }\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                            WETH                            */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Deposits `amount` ETH of the caller and mints `amount` WETH to the caller.\n    ///\n    /// Emits a {Deposit} event.\n    function deposit() public payable virtual {\n        _mint(msg.sender, msg.value);\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Emit the {Deposit} event.\n            mstore(0x00, callvalue())\n            log2(0x00, 0x20, _DEPOSIT_EVENT_SIGNATURE, caller())\n        }\n    }\n\n    /// @dev Burns `amount` WETH of the caller and sends `amount` ETH to the caller.\n    ///\n    /// Emits a {Withdrawal} event.\n    function withdraw(uint256 amount) public virtual {\n        _burn(msg.sender, amount);\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Emit the {Withdrawal} event.\n            mstore(0x00, amount)\n            log2(0x00, 0x20, _WITHDRAWAL_EVENT_SIGNATURE, caller())\n            // Transfer the ETH and check if it succeeded or not.\n            if iszero(call(gas(), caller(), amount, codesize(), 0x00, codesize(), 0x00)) {\n                mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.\n                revert(0x1c, 0x04)\n            }\n        }\n    }\n\n    /// @dev Equivalent to `deposit()`.\n    receive() external payable virtual {\n        deposit();\n    }\n}\n"
      },
      "node_modules/@pancakeswap/v3-core/contracts/interfaces/IPancakeV3Pool.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\nimport './pool/IPancakeV3PoolImmutables.sol';\nimport './pool/IPancakeV3PoolState.sol';\nimport './pool/IPancakeV3PoolDerivedState.sol';\nimport './pool/IPancakeV3PoolActions.sol';\nimport './pool/IPancakeV3PoolOwnerActions.sol';\nimport './pool/IPancakeV3PoolEvents.sol';\n\n/// @title The interface for a PancakeSwap V3 Pool\n/// @notice A PancakeSwap pool facilitates swapping and automated market making between any two assets that strictly conform\n/// to the ERC20 specification\n/// @dev The pool interface is broken up into many smaller pieces\ninterface IPancakeV3Pool is\n    IPancakeV3PoolImmutables,\n    IPancakeV3PoolState,\n    IPancakeV3PoolDerivedState,\n    IPancakeV3PoolActions,\n    IPancakeV3PoolOwnerActions,\n    IPancakeV3PoolEvents\n{\n\n}\n"
      },
      "node_modules/@openzeppelin/contracts/utils/introspection/IERC165.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n    /**\n     * @dev Returns true if this contract implements the interface defined by\n     * `interfaceId`. See the corresponding\n     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n     * to learn more about how these ids are created.\n     *\n     * This function call must use less than 30 000 gas.\n     */\n    function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n"
      },
      "node_modules/solady/src/tokens/ERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.4;\n\n/// @notice Simple ERC20 + EIP-2612 implementation.\n/// @author Solady (https://github.com/vectorized/solady/blob/main/src/tokens/ERC20.sol)\n/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)\n/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol)\n///\n/// @dev Note:\n/// - The ERC20 standard allows minting and transferring to and from the zero address,\n///   minting and transferring zero tokens, as well as self-approvals.\n///   For performance, this implementation WILL NOT revert for such actions.\n///   Please add any checks with overrides if desired.\n/// - The `permit` function uses the ecrecover precompile (0x1).\n///\n/// If you are overriding:\n/// - NEVER violate the ERC20 invariant:\n///   the total sum of all balances must be equal to `totalSupply()`.\n/// - Check that the overridden function is actually used in the function you want to\n///   change the behavior of. Much of the code has been manually inlined for performance.\nabstract contract ERC20 {\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                       CUSTOM ERRORS                        */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev The total supply has overflowed.\n    error TotalSupplyOverflow();\n\n    /// @dev The allowance has overflowed.\n    error AllowanceOverflow();\n\n    /// @dev The allowance has underflowed.\n    error AllowanceUnderflow();\n\n    /// @dev Insufficient balance.\n    error InsufficientBalance();\n\n    /// @dev Insufficient allowance.\n    error InsufficientAllowance();\n\n    /// @dev The permit is invalid.\n    error InvalidPermit();\n\n    /// @dev The permit has expired.\n    error PermitExpired();\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                           EVENTS                           */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Emitted when `amount` tokens is transferred from `from` to `to`.\n    event Transfer(address indexed from, address indexed to, uint256 amount);\n\n    /// @dev Emitted when `amount` tokens is approved by `owner` to be used by `spender`.\n    event Approval(address indexed owner, address indexed spender, uint256 amount);\n\n    /// @dev `keccak256(bytes(\"Transfer(address,address,uint256)\"))`.\n    uint256 private constant _TRANSFER_EVENT_SIGNATURE =\n        0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef;\n\n    /// @dev `keccak256(bytes(\"Approval(address,address,uint256)\"))`.\n    uint256 private constant _APPROVAL_EVENT_SIGNATURE =\n        0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925;\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                          STORAGE                           */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev The storage slot for the total supply.\n    uint256 private constant _TOTAL_SUPPLY_SLOT = 0x05345cdf77eb68f44c;\n\n    /// @dev The balance slot of `owner` is given by:\n    /// ```\n    ///     mstore(0x0c, _BALANCE_SLOT_SEED)\n    ///     mstore(0x00, owner)\n    ///     let balanceSlot := keccak256(0x0c, 0x20)\n    /// ```\n    uint256 private constant _BALANCE_SLOT_SEED = 0x87a211a2;\n\n    /// @dev The allowance slot of (`owner`, `spender`) is given by:\n    /// ```\n    ///     mstore(0x20, spender)\n    ///     mstore(0x0c, _ALLOWANCE_SLOT_SEED)\n    ///     mstore(0x00, owner)\n    ///     let allowanceSlot := keccak256(0x0c, 0x34)\n    /// ```\n    uint256 private constant _ALLOWANCE_SLOT_SEED = 0x7f5e9f20;\n\n    /// @dev The nonce slot of `owner` is given by:\n    /// ```\n    ///     mstore(0x0c, _NONCES_SLOT_SEED)\n    ///     mstore(0x00, owner)\n    ///     let nonceSlot := keccak256(0x0c, 0x20)\n    /// ```\n    uint256 private constant _NONCES_SLOT_SEED = 0x38377508;\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                         CONSTANTS                          */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev `(_NONCES_SLOT_SEED << 16) | 0x1901`.\n    uint256 private constant _NONCES_SLOT_SEED_WITH_SIGNATURE_PREFIX = 0x383775081901;\n\n    /// @dev `keccak256(\"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\")`.\n    bytes32 private constant _DOMAIN_TYPEHASH =\n        0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f;\n\n    /// @dev `keccak256(\"1\")`.\n    bytes32 private constant _VERSION_HASH =\n        0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6;\n\n    /// @dev `keccak256(\"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)\")`.\n    bytes32 private constant _PERMIT_TYPEHASH =\n        0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                       ERC20 METADATA                       */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Returns the name of the token.\n    function name() public view virtual returns (string memory);\n\n    /// @dev Returns the symbol of the token.\n    function symbol() public view virtual returns (string memory);\n\n    /// @dev Returns the decimals places of the token.\n    function decimals() public view virtual returns (uint8) {\n        return 18;\n    }\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                           ERC20                            */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Returns the amount of tokens in existence.\n    function totalSupply() public view virtual returns (uint256 result) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            result := sload(_TOTAL_SUPPLY_SLOT)\n        }\n    }\n\n    /// @dev Returns the amount of tokens owned by `owner`.\n    function balanceOf(address owner) public view virtual returns (uint256 result) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            mstore(0x0c, _BALANCE_SLOT_SEED)\n            mstore(0x00, owner)\n            result := sload(keccak256(0x0c, 0x20))\n        }\n    }\n\n    /// @dev Returns the amount of tokens that `spender` can spend on behalf of `owner`.\n    function allowance(address owner, address spender)\n        public\n        view\n        virtual\n        returns (uint256 result)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            mstore(0x20, spender)\n            mstore(0x0c, _ALLOWANCE_SLOT_SEED)\n            mstore(0x00, owner)\n            result := sload(keccak256(0x0c, 0x34))\n        }\n    }\n\n    /// @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n    ///\n    /// Emits a {Approval} event.\n    function approve(address spender, uint256 amount) public virtual returns (bool) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Compute the allowance slot and store the amount.\n            mstore(0x20, spender)\n            mstore(0x0c, _ALLOWANCE_SLOT_SEED)\n            mstore(0x00, caller())\n            sstore(keccak256(0x0c, 0x34), amount)\n            // Emit the {Approval} event.\n            mstore(0x00, amount)\n            log3(0x00, 0x20, _APPROVAL_EVENT_SIGNATURE, caller(), shr(96, mload(0x2c)))\n        }\n        return true;\n    }\n\n    /// @dev Transfer `amount` tokens from the caller to `to`.\n    ///\n    /// Requirements:\n    /// - `from` must at least have `amount`.\n    ///\n    /// Emits a {Transfer} event.\n    function transfer(address to, uint256 amount) public virtual returns (bool) {\n        _beforeTokenTransfer(msg.sender, to, amount);\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Compute the balance slot and load its value.\n            mstore(0x0c, _BALANCE_SLOT_SEED)\n            mstore(0x00, caller())\n            let fromBalanceSlot := keccak256(0x0c, 0x20)\n            let fromBalance := sload(fromBalanceSlot)\n            // Revert if insufficient balance.\n            if gt(amount, fromBalance) {\n                mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.\n                revert(0x1c, 0x04)\n            }\n            // Subtract and store the updated balance.\n            sstore(fromBalanceSlot, sub(fromBalance, amount))\n            // Compute the balance slot of `to`.\n            mstore(0x00, to)\n            let toBalanceSlot := keccak256(0x0c, 0x20)\n            // Add and store the updated balance of `to`.\n            // Will not overflow because the sum of all user balances\n            // cannot exceed the maximum uint256 value.\n            sstore(toBalanceSlot, add(sload(toBalanceSlot), amount))\n            // Emit the {Transfer} event.\n            mstore(0x20, amount)\n            log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, caller(), shr(96, mload(0x0c)))\n        }\n        _afterTokenTransfer(msg.sender, to, amount);\n        return true;\n    }\n\n    /// @dev Transfers `amount` tokens from `from` to `to`.\n    ///\n    /// Note: Does not update the allowance if it is the maximum uint256 value.\n    ///\n    /// Requirements:\n    /// - `from` must at least have `amount`.\n    /// - The caller must have at least `amount` of allowance to transfer the tokens of `from`.\n    ///\n    /// Emits a {Transfer} event.\n    function transferFrom(address from, address to, uint256 amount) public virtual returns (bool) {\n        _beforeTokenTransfer(from, to, amount);\n        /// @solidity memory-safe-assembly\n        assembly {\n            let from_ := shl(96, from)\n            // Compute the allowance slot and load its value.\n            mstore(0x20, caller())\n            mstore(0x0c, or(from_, _ALLOWANCE_SLOT_SEED))\n            let allowanceSlot := keccak256(0x0c, 0x34)\n            let allowance_ := sload(allowanceSlot)\n            // If the allowance is not the maximum uint256 value.\n            if add(allowance_, 1) {\n                // Revert if the amount to be transferred exceeds the allowance.\n                if gt(amount, allowance_) {\n                    mstore(0x00, 0x13be252b) // `InsufficientAllowance()`.\n                    revert(0x1c, 0x04)\n                }\n                // Subtract and store the updated allowance.\n                sstore(allowanceSlot, sub(allowance_, amount))\n            }\n            // Compute the balance slot and load its value.\n            mstore(0x0c, or(from_, _BALANCE_SLOT_SEED))\n            let fromBalanceSlot := keccak256(0x0c, 0x20)\n            let fromBalance := sload(fromBalanceSlot)\n            // Revert if insufficient balance.\n            if gt(amount, fromBalance) {\n                mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.\n                revert(0x1c, 0x04)\n            }\n            // Subtract and store the updated balance.\n            sstore(fromBalanceSlot, sub(fromBalance, amount))\n            // Compute the balance slot of `to`.\n            mstore(0x00, to)\n            let toBalanceSlot := keccak256(0x0c, 0x20)\n            // Add and store the updated balance of `to`.\n            // Will not overflow because the sum of all user balances\n            // cannot exceed the maximum uint256 value.\n            sstore(toBalanceSlot, add(sload(toBalanceSlot), amount))\n            // Emit the {Transfer} event.\n            mstore(0x20, amount)\n            log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, from_), shr(96, mload(0x0c)))\n        }\n        _afterTokenTransfer(from, to, amount);\n        return true;\n    }\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                          EIP-2612                          */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev For more performance, override to return the constant value\n    /// of `keccak256(bytes(name()))` if `name()` will never change.\n    function _constantNameHash() internal view virtual returns (bytes32 result) {}\n\n    /// @dev Returns the current nonce for `owner`.\n    /// This value is used to compute the signature for EIP-2612 permit.\n    function nonces(address owner) public view virtual returns (uint256 result) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Compute the nonce slot and load its value.\n            mstore(0x0c, _NONCES_SLOT_SEED)\n            mstore(0x00, owner)\n            result := sload(keccak256(0x0c, 0x20))\n        }\n    }\n\n    /// @dev Sets `value` as the allowance of `spender` over the tokens of `owner`,\n    /// authorized by a signed approval by `owner`.\n    ///\n    /// Emits a {Approval} event.\n    function permit(\n        address owner,\n        address spender,\n        uint256 value,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) public virtual {\n        bytes32 nameHash = _constantNameHash();\n        //  We simply calculate it on-the-fly to allow for cases where the `name` may change.\n        if (nameHash == bytes32(0)) nameHash = keccak256(bytes(name()));\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Revert if the block timestamp is greater than `deadline`.\n            if gt(timestamp(), deadline) {\n                mstore(0x00, 0x1a15a3cc) // `PermitExpired()`.\n                revert(0x1c, 0x04)\n            }\n            let m := mload(0x40) // Grab the free memory pointer.\n            // Clean the upper 96 bits.\n            owner := shr(96, shl(96, owner))\n            spender := shr(96, shl(96, spender))\n            // Compute the nonce slot and load its value.\n            mstore(0x0e, _NONCES_SLOT_SEED_WITH_SIGNATURE_PREFIX)\n            mstore(0x00, owner)\n            let nonceSlot := keccak256(0x0c, 0x20)\n            let nonceValue := sload(nonceSlot)\n            // Prepare the domain separator.\n            mstore(m, _DOMAIN_TYPEHASH)\n            mstore(add(m, 0x20), nameHash)\n            mstore(add(m, 0x40), _VERSION_HASH)\n            mstore(add(m, 0x60), chainid())\n            mstore(add(m, 0x80), address())\n            mstore(0x2e, keccak256(m, 0xa0))\n            // Prepare the struct hash.\n            mstore(m, _PERMIT_TYPEHASH)\n            mstore(add(m, 0x20), owner)\n            mstore(add(m, 0x40), spender)\n            mstore(add(m, 0x60), value)\n            mstore(add(m, 0x80), nonceValue)\n            mstore(add(m, 0xa0), deadline)\n            mstore(0x4e, keccak256(m, 0xc0))\n            // Prepare the ecrecover calldata.\n            mstore(0x00, keccak256(0x2c, 0x42))\n            mstore(0x20, and(0xff, v))\n            mstore(0x40, r)\n            mstore(0x60, s)\n            let t := staticcall(gas(), 1, 0, 0x80, 0x20, 0x20)\n            // If the ecrecover fails, the returndatasize will be 0x00,\n            // `owner` will be checked if it equals the hash at 0x00,\n            // which evaluates to false (i.e. 0), and we will revert.\n            // If the ecrecover succeeds, the returndatasize will be 0x20,\n            // `owner` will be compared against the returned address at 0x20.\n            if iszero(eq(mload(returndatasize()), owner)) {\n                mstore(0x00, 0xddafbaef) // `InvalidPermit()`.\n                revert(0x1c, 0x04)\n            }\n            // Increment and store the updated nonce.\n            sstore(nonceSlot, add(nonceValue, t)) // `t` is 1 if ecrecover succeeds.\n            // Compute the allowance slot and store the value.\n            // The `owner` is already at slot 0x20.\n            mstore(0x40, or(shl(160, _ALLOWANCE_SLOT_SEED), spender))\n            sstore(keccak256(0x2c, 0x34), value)\n            // Emit the {Approval} event.\n            log3(add(m, 0x60), 0x20, _APPROVAL_EVENT_SIGNATURE, owner, spender)\n            mstore(0x40, m) // Restore the free memory pointer.\n            mstore(0x60, 0) // Restore the zero pointer.\n        }\n    }\n\n    /// @dev Returns the EIP-712 domain separator for the EIP-2612 permit.\n    function DOMAIN_SEPARATOR() public view virtual returns (bytes32 result) {\n        bytes32 nameHash = _constantNameHash();\n        //  We simply calculate it on-the-fly to allow for cases where the `name` may change.\n        if (nameHash == bytes32(0)) nameHash = keccak256(bytes(name()));\n        /// @solidity memory-safe-assembly\n        assembly {\n            let m := mload(0x40) // Grab the free memory pointer.\n            mstore(m, _DOMAIN_TYPEHASH)\n            mstore(add(m, 0x20), nameHash)\n            mstore(add(m, 0x40), _VERSION_HASH)\n            mstore(add(m, 0x60), chainid())\n            mstore(add(m, 0x80), address())\n            result := keccak256(m, 0xa0)\n        }\n    }\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                  INTERNAL MINT FUNCTIONS                   */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Mints `amount` tokens to `to`, increasing the total supply.\n    ///\n    /// Emits a {Transfer} event.\n    function _mint(address to, uint256 amount) internal virtual {\n        _beforeTokenTransfer(address(0), to, amount);\n        /// @solidity memory-safe-assembly\n        assembly {\n            let totalSupplyBefore := sload(_TOTAL_SUPPLY_SLOT)\n            let totalSupplyAfter := add(totalSupplyBefore, amount)\n            // Revert if the total supply overflows.\n            if lt(totalSupplyAfter, totalSupplyBefore) {\n                mstore(0x00, 0xe5cfe957) // `TotalSupplyOverflow()`.\n                revert(0x1c, 0x04)\n            }\n            // Store the updated total supply.\n            sstore(_TOTAL_SUPPLY_SLOT, totalSupplyAfter)\n            // Compute the balance slot and load its value.\n            mstore(0x0c, _BALANCE_SLOT_SEED)\n            mstore(0x00, to)\n            let toBalanceSlot := keccak256(0x0c, 0x20)\n            // Add and store the updated balance.\n            sstore(toBalanceSlot, add(sload(toBalanceSlot), amount))\n            // Emit the {Transfer} event.\n            mstore(0x20, amount)\n            log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, 0, shr(96, mload(0x0c)))\n        }\n        _afterTokenTransfer(address(0), to, amount);\n    }\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                  INTERNAL BURN FUNCTIONS                   */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Burns `amount` tokens from `from`, reducing the total supply.\n    ///\n    /// Emits a {Transfer} event.\n    function _burn(address from, uint256 amount) internal virtual {\n        _beforeTokenTransfer(from, address(0), amount);\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Compute the balance slot and load its value.\n            mstore(0x0c, _BALANCE_SLOT_SEED)\n            mstore(0x00, from)\n            let fromBalanceSlot := keccak256(0x0c, 0x20)\n            let fromBalance := sload(fromBalanceSlot)\n            // Revert if insufficient balance.\n            if gt(amount, fromBalance) {\n                mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.\n                revert(0x1c, 0x04)\n            }\n            // Subtract and store the updated balance.\n            sstore(fromBalanceSlot, sub(fromBalance, amount))\n            // Subtract and store the updated total supply.\n            sstore(_TOTAL_SUPPLY_SLOT, sub(sload(_TOTAL_SUPPLY_SLOT), amount))\n            // Emit the {Transfer} event.\n            mstore(0x00, amount)\n            log3(0x00, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, shl(96, from)), 0)\n        }\n        _afterTokenTransfer(from, address(0), amount);\n    }\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                INTERNAL TRANSFER FUNCTIONS                 */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Moves `amount` of tokens from `from` to `to`.\n    function _transfer(address from, address to, uint256 amount) internal virtual {\n        _beforeTokenTransfer(from, to, amount);\n        /// @solidity memory-safe-assembly\n        assembly {\n            let from_ := shl(96, from)\n            // Compute the balance slot and load its value.\n            mstore(0x0c, or(from_, _BALANCE_SLOT_SEED))\n            let fromBalanceSlot := keccak256(0x0c, 0x20)\n            let fromBalance := sload(fromBalanceSlot)\n            // Revert if insufficient balance.\n            if gt(amount, fromBalance) {\n                mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.\n                revert(0x1c, 0x04)\n            }\n            // Subtract and store the updated balance.\n            sstore(fromBalanceSlot, sub(fromBalance, amount))\n            // Compute the balance slot of `to`.\n            mstore(0x00, to)\n            let toBalanceSlot := keccak256(0x0c, 0x20)\n            // Add and store the updated balance of `to`.\n            // Will not overflow because the sum of all user balances\n            // cannot exceed the maximum uint256 value.\n            sstore(toBalanceSlot, add(sload(toBalanceSlot), amount))\n            // Emit the {Transfer} event.\n            mstore(0x20, amount)\n            log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, from_), shr(96, mload(0x0c)))\n        }\n        _afterTokenTransfer(from, to, amount);\n    }\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                INTERNAL ALLOWANCE FUNCTIONS                */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Updates the allowance of `owner` for `spender` based on spent `amount`.\n    function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Compute the allowance slot and load its value.\n            mstore(0x20, spender)\n            mstore(0x0c, _ALLOWANCE_SLOT_SEED)\n            mstore(0x00, owner)\n            let allowanceSlot := keccak256(0x0c, 0x34)\n            let allowance_ := sload(allowanceSlot)\n            // If the allowance is not the maximum uint256 value.\n            if add(allowance_, 1) {\n                // Revert if the amount to be transferred exceeds the allowance.\n                if gt(amount, allowance_) {\n                    mstore(0x00, 0x13be252b) // `InsufficientAllowance()`.\n                    revert(0x1c, 0x04)\n                }\n                // Subtract and store the updated allowance.\n                sstore(allowanceSlot, sub(allowance_, amount))\n            }\n        }\n    }\n\n    /// @dev Sets `amount` as the allowance of `spender` over the tokens of `owner`.\n    ///\n    /// Emits a {Approval} event.\n    function _approve(address owner, address spender, uint256 amount) internal virtual {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let owner_ := shl(96, owner)\n            // Compute the allowance slot and store the amount.\n            mstore(0x20, spender)\n            mstore(0x0c, or(owner_, _ALLOWANCE_SLOT_SEED))\n            sstore(keccak256(0x0c, 0x34), amount)\n            // Emit the {Approval} event.\n            mstore(0x00, amount)\n            log3(0x00, 0x20, _APPROVAL_EVENT_SIGNATURE, shr(96, owner_), shr(96, mload(0x2c)))\n        }\n    }\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                     HOOKS TO OVERRIDE                      */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Hook that is called before any transfer of tokens.\n    /// This includes minting and burning.\n    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}\n\n    /// @dev Hook that is called after any transfer of tokens.\n    /// This includes minting and burning.\n    function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}\n}\n"
      },
      "node_modules/@pancakeswap/v3-core/contracts/interfaces/pool/IPancakeV3PoolImmutables.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Pool state that never changes\n/// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values\ninterface IPancakeV3PoolImmutables {\n    /// @notice The contract that deployed the pool, which must adhere to the IPancakeV3Factory interface\n    /// @return The contract address\n    function factory() external view returns (address);\n\n    /// @notice The first of the two tokens of the pool, sorted by address\n    /// @return The token contract address\n    function token0() external view returns (address);\n\n    /// @notice The second of the two tokens of the pool, sorted by address\n    /// @return The token contract address\n    function token1() external view returns (address);\n\n    /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6\n    /// @return The fee\n    function fee() external view returns (uint24);\n\n    /// @notice The pool tick spacing\n    /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive\n    /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ...\n    /// This value is an int24 to avoid casting even though it is always positive.\n    /// @return The tick spacing\n    function tickSpacing() external view returns (int24);\n\n    /// @notice The maximum amount of position liquidity that can use any tick in the range\n    /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and\n    /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool\n    /// @return The max amount of liquidity per tick\n    function maxLiquidityPerTick() external view returns (uint128);\n}\n"
      },
      "node_modules/@pancakeswap/v3-core/contracts/interfaces/pool/IPancakeV3PoolState.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Pool state that can change\n/// @notice These methods compose the pool's state, and can change with any frequency including multiple times\n/// per transaction\ninterface IPancakeV3PoolState {\n    /// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas\n    /// when accessed externally.\n    /// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value\n    /// tick The current tick of the pool, i.e. according to the last tick transition that was run.\n    /// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick\n    /// boundary.\n    /// observationIndex The index of the last oracle observation that was written,\n    /// observationCardinality The current maximum number of observations stored in the pool,\n    /// observationCardinalityNext The next maximum number of observations, to be updated when the observation.\n    /// feeProtocol The protocol fee for both tokens of the pool.\n    /// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0\n    /// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee.\n    /// unlocked Whether the pool is currently locked to reentrancy\n    function slot0()\n        external\n        view\n        returns (\n            uint160 sqrtPriceX96,\n            int24 tick,\n            uint16 observationIndex,\n            uint16 observationCardinality,\n            uint16 observationCardinalityNext,\n            uint32 feeProtocol,\n            bool unlocked\n        );\n\n    /// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool\n    /// @dev This value can overflow the uint256\n    function feeGrowthGlobal0X128() external view returns (uint256);\n\n    /// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool\n    /// @dev This value can overflow the uint256\n    function feeGrowthGlobal1X128() external view returns (uint256);\n\n    /// @notice The amounts of token0 and token1 that are owed to the protocol\n    /// @dev Protocol fees will never exceed uint128 max in either token\n    function protocolFees() external view returns (uint128 token0, uint128 token1);\n\n    /// @notice The currently in range liquidity available to the pool\n    /// @dev This value has no relationship to the total liquidity across all ticks\n    function liquidity() external view returns (uint128);\n\n    /// @notice Look up information about a specific tick in the pool\n    /// @param tick The tick to look up\n    /// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or\n    /// tick upper,\n    /// liquidityNet how much liquidity changes when the pool price crosses the tick,\n    /// feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0,\n    /// feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1,\n    /// tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick\n    /// secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick,\n    /// secondsOutside the seconds spent on the other side of the tick from the current tick,\n    /// initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false.\n    /// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0.\n    /// In addition, these values are only relative and must be used only in comparison to previous snapshots for\n    /// a specific position.\n    function ticks(int24 tick)\n        external\n        view\n        returns (\n            uint128 liquidityGross,\n            int128 liquidityNet,\n            uint256 feeGrowthOutside0X128,\n            uint256 feeGrowthOutside1X128,\n            int56 tickCumulativeOutside,\n            uint160 secondsPerLiquidityOutsideX128,\n            uint32 secondsOutside,\n            bool initialized\n        );\n\n    /// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information\n    function tickBitmap(int16 wordPosition) external view returns (uint256);\n\n    /// @notice Returns the information about a position by the position's key\n    /// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper\n    /// @return _liquidity The amount of liquidity in the position,\n    /// Returns feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke,\n    /// Returns feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke,\n    /// Returns tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke,\n    /// Returns tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke\n    function positions(bytes32 key)\n        external\n        view\n        returns (\n            uint128 _liquidity,\n            uint256 feeGrowthInside0LastX128,\n            uint256 feeGrowthInside1LastX128,\n            uint128 tokensOwed0,\n            uint128 tokensOwed1\n        );\n\n    /// @notice Returns data about a specific observation index\n    /// @param index The element of the observations array to fetch\n    /// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time\n    /// ago, rather than at a specific index in the array.\n    /// @return blockTimestamp The timestamp of the observation,\n    /// Returns tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp,\n    /// Returns secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp,\n    /// Returns initialized whether the observation has been initialized and the values are safe to use\n    function observations(uint256 index)\n        external\n        view\n        returns (\n            uint32 blockTimestamp,\n            int56 tickCumulative,\n            uint160 secondsPerLiquidityCumulativeX128,\n            bool initialized\n        );\n}\n"
      },
      "node_modules/@pancakeswap/v3-core/contracts/interfaces/pool/IPancakeV3PoolDerivedState.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Pool state that is not stored\n/// @notice Contains view functions to provide information about the pool that is computed rather than stored on the\n/// blockchain. The functions here may have variable gas costs.\ninterface IPancakeV3PoolDerivedState {\n    /// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp\n    /// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing\n    /// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick,\n    /// you must call it with secondsAgos = [3600, 0].\n    /// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in\n    /// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.\n    /// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned\n    /// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp\n    /// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block\n    /// timestamp\n    function observe(uint32[] calldata secondsAgos)\n        external\n        view\n        returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);\n\n    /// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range\n    /// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed.\n    /// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first\n    /// snapshot is taken and the second snapshot is taken.\n    /// @param tickLower The lower tick of the range\n    /// @param tickUpper The upper tick of the range\n    /// @return tickCumulativeInside The snapshot of the tick accumulator for the range\n    /// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range\n    /// @return secondsInside The snapshot of seconds per liquidity for the range\n    function snapshotCumulativesInside(int24 tickLower, int24 tickUpper)\n        external\n        view\n        returns (\n            int56 tickCumulativeInside,\n            uint160 secondsPerLiquidityInsideX128,\n            uint32 secondsInside\n        );\n}\n"
      },
      "node_modules/@pancakeswap/v3-core/contracts/interfaces/pool/IPancakeV3PoolActions.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Permissionless pool actions\n/// @notice Contains pool methods that can be called by anyone\ninterface IPancakeV3PoolActions {\n    /// @notice Sets the initial price for the pool\n    /// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value\n    /// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96\n    function initialize(uint160 sqrtPriceX96) external;\n\n    /// @notice Adds liquidity for the given recipient/tickLower/tickUpper position\n    /// @dev The caller of this method receives a callback in the form of IPancakeV3MintCallback#pancakeV3MintCallback\n    /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends\n    /// on tickLower, tickUpper, the amount of liquidity, and the current price.\n    /// @param recipient The address for which the liquidity will be created\n    /// @param tickLower The lower tick of the position in which to add liquidity\n    /// @param tickUpper The upper tick of the position in which to add liquidity\n    /// @param amount The amount of liquidity to mint\n    /// @param data Any data that should be passed through to the callback\n    /// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback\n    /// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback\n    function mint(\n        address recipient,\n        int24 tickLower,\n        int24 tickUpper,\n        uint128 amount,\n        bytes calldata data\n    ) external returns (uint256 amount0, uint256 amount1);\n\n    /// @notice Collects tokens owed to a position\n    /// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.\n    /// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or\n    /// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the\n    /// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.\n    /// @param recipient The address which should receive the fees collected\n    /// @param tickLower The lower tick of the position for which to collect fees\n    /// @param tickUpper The upper tick of the position for which to collect fees\n    /// @param amount0Requested How much token0 should be withdrawn from the fees owed\n    /// @param amount1Requested How much token1 should be withdrawn from the fees owed\n    /// @return amount0 The amount of fees collected in token0\n    /// @return amount1 The amount of fees collected in token1\n    function collect(\n        address recipient,\n        int24 tickLower,\n        int24 tickUpper,\n        uint128 amount0Requested,\n        uint128 amount1Requested\n    ) external returns (uint128 amount0, uint128 amount1);\n\n    /// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position\n    /// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0\n    /// @dev Fees must be collected separately via a call to #collect\n    /// @param tickLower The lower tick of the position for which to burn liquidity\n    /// @param tickUpper The upper tick of the position for which to burn liquidity\n    /// @param amount How much liquidity to burn\n    /// @return amount0 The amount of token0 sent to the recipient\n    /// @return amount1 The amount of token1 sent to the recipient\n    function burn(\n        int24 tickLower,\n        int24 tickUpper,\n        uint128 amount\n    ) external returns (uint256 amount0, uint256 amount1);\n\n    /// @notice Swap token0 for token1, or token1 for token0\n    /// @dev The caller of this method receives a callback in the form of IPancakeV3SwapCallback#pancakeV3SwapCallback\n    /// @param recipient The address to receive the output of the swap\n    /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0\n    /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)\n    /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this\n    /// value after the swap. If one for zero, the price cannot be greater than this value after the swap\n    /// @param data Any data to be passed through to the callback\n    /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive\n    /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive\n    function swap(\n        address recipient,\n        bool zeroForOne,\n        int256 amountSpecified,\n        uint160 sqrtPriceLimitX96,\n        bytes calldata data\n    ) external returns (int256 amount0, int256 amount1);\n\n    /// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback\n    /// @dev The caller of this method receives a callback in the form of IPancakeV3FlashCallback#pancakeV3FlashCallback\n    /// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling\n    /// with 0 amount{0,1} and sending the donation amount(s) from the callback\n    /// @param recipient The address which will receive the token0 and token1 amounts\n    /// @param amount0 The amount of token0 to send\n    /// @param amount1 The amount of token1 to send\n    /// @param data Any data to be passed through to the callback\n    function flash(\n        address recipient,\n        uint256 amount0,\n        uint256 amount1,\n        bytes calldata data\n    ) external;\n\n    /// @notice Increase the maximum number of price and liquidity observations that this pool will store\n    /// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to\n    /// the input observationCardinalityNext.\n    /// @param observationCardinalityNext The desired minimum number of observations for the pool to store\n    function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;\n}\n"
      },
      "node_modules/@pancakeswap/v3-core/contracts/interfaces/pool/IPancakeV3PoolOwnerActions.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Permissioned pool actions\n/// @notice Contains pool methods that may only be called by the factory owner\ninterface IPancakeV3PoolOwnerActions {\n    /// @notice Set the denominator of the protocol's % share of the fees\n    /// @param feeProtocol0 new protocol fee for token0 of the pool\n    /// @param feeProtocol1 new protocol fee for token1 of the pool\n    function setFeeProtocol(uint32 feeProtocol0, uint32 feeProtocol1) external;\n\n    /// @notice Collect the protocol fee accrued to the pool\n    /// @param recipient The address to which collected protocol fees should be sent\n    /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1\n    /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0\n    /// @return amount0 The protocol fee collected in token0\n    /// @return amount1 The protocol fee collected in token1\n    function collectProtocol(\n        address recipient,\n        uint128 amount0Requested,\n        uint128 amount1Requested\n    ) external returns (uint128 amount0, uint128 amount1);\n\n    /// @notice Set the LM pool to enable liquidity mining\n    function setLmPool(address lmPool) external;\n}\n"
      },
      "node_modules/@pancakeswap/v3-core/contracts/interfaces/pool/IPancakeV3PoolEvents.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Events emitted by a pool\n/// @notice Contains all events emitted by the pool\ninterface IPancakeV3PoolEvents {\n    /// @notice Emitted exactly once by a pool when #initialize is first called on the pool\n    /// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize\n    /// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96\n    /// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool\n    event Initialize(uint160 sqrtPriceX96, int24 tick);\n\n    /// @notice Emitted when liquidity is minted for a given position\n    /// @param sender The address that minted the liquidity\n    /// @param owner The owner of the position and recipient of any minted liquidity\n    /// @param tickLower The lower tick of the position\n    /// @param tickUpper The upper tick of the position\n    /// @param amount The amount of liquidity minted to the position range\n    /// @param amount0 How much token0 was required for the minted liquidity\n    /// @param amount1 How much token1 was required for the minted liquidity\n    event Mint(\n        address sender,\n        address indexed owner,\n        int24 indexed tickLower,\n        int24 indexed tickUpper,\n        uint128 amount,\n        uint256 amount0,\n        uint256 amount1\n    );\n\n    /// @notice Emitted when fees are collected by the owner of a position\n    /// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees\n    /// @param owner The owner of the position for which fees are collected\n    /// @param tickLower The lower tick of the position\n    /// @param tickUpper The upper tick of the position\n    /// @param amount0 The amount of token0 fees collected\n    /// @param amount1 The amount of token1 fees collected\n    event Collect(\n        address indexed owner,\n        address recipient,\n        int24 indexed tickLower,\n        int24 indexed tickUpper,\n        uint128 amount0,\n        uint128 amount1\n    );\n\n    /// @notice Emitted when a position's liquidity is removed\n    /// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect\n    /// @param owner The owner of the position for which liquidity is removed\n    /// @param tickLower The lower tick of the position\n    /// @param tickUpper The upper tick of the position\n    /// @param amount The amount of liquidity to remove\n    /// @param amount0 The amount of token0 withdrawn\n    /// @param amount1 The amount of token1 withdrawn\n    event Burn(\n        address indexed owner,\n        int24 indexed tickLower,\n        int24 indexed tickUpper,\n        uint128 amount,\n        uint256 amount0,\n        uint256 amount1\n    );\n\n    /// @notice Emitted by the pool for any swaps between token0 and token1\n    /// @param sender The address that initiated the swap call, and that received the callback\n    /// @param recipient The address that received the output of the swap\n    /// @param amount0 The delta of the token0 balance of the pool\n    /// @param amount1 The delta of the token1 balance of the pool\n    /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96\n    /// @param liquidity The liquidity of the pool after the swap\n    /// @param tick The log base 1.0001 of price of the pool after the swap\n    /// @param protocolFeesToken0 The protocol fee of token0 in the swap\n    /// @param protocolFeesToken1 The protocol fee of token1 in the swap\n    event Swap(\n        address indexed sender,\n        address indexed recipient,\n        int256 amount0,\n        int256 amount1,\n        uint160 sqrtPriceX96,\n        uint128 liquidity,\n        int24 tick,\n        uint128 protocolFeesToken0,\n        uint128 protocolFeesToken1\n    );\n\n    /// @notice Emitted by the pool for any flashes of token0/token1\n    /// @param sender The address that initiated the swap call, and that received the callback\n    /// @param recipient The address that received the tokens from flash\n    /// @param amount0 The amount of token0 that was flashed\n    /// @param amount1 The amount of token1 that was flashed\n    /// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee\n    /// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee\n    event Flash(\n        address indexed sender,\n        address indexed recipient,\n        uint256 amount0,\n        uint256 amount1,\n        uint256 paid0,\n        uint256 paid1\n    );\n\n    /// @notice Emitted by the pool for increases to the number of observations that can be stored\n    /// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index\n    /// just before a mint/swap/burn.\n    /// @param observationCardinalityNextOld The previous value of the next observation cardinality\n    /// @param observationCardinalityNextNew The updated value of the next observation cardinality\n    event IncreaseObservationCardinalityNext(\n        uint16 observationCardinalityNextOld,\n        uint16 observationCardinalityNextNew\n    );\n\n    /// @notice Emitted when the protocol fee is changed by the pool\n    /// @param feeProtocol0Old The previous value of the token0 protocol fee\n    /// @param feeProtocol1Old The previous value of the token1 protocol fee\n    /// @param feeProtocol0New The updated value of the token0 protocol fee\n    /// @param feeProtocol1New The updated value of the token1 protocol fee\n    event SetFeeProtocol(\n        uint32 feeProtocol0Old,\n        uint32 feeProtocol1Old,\n        uint32 feeProtocol0New,\n        uint32 feeProtocol1New\n    );\n\n    /// @notice Emitted when the collected protocol fees are withdrawn by the factory owner\n    /// @param sender The address that collects the protocol fees\n    /// @param recipient The address that receives the collected protocol fees\n    /// @param amount0 The amount of token0 protocol fees that is withdrawn\n    /// @param amount0 The amount of token1 protocol fees that is withdrawn\n    event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1);\n}\n"
      }
    },
    "settings": {
      "remappings": [
        "@aperture_finance/uni-v3-lib/=node_modules/@aperture_finance/uni-v3-lib/",
        "@pancakeswap/=node_modules/@pancakeswap/",
        "@openzeppelin/=node_modules/@openzeppelin/",
        "@uniswap/=node_modules/@uniswap/",
        "solady/=node_modules/solady/",
        "forge-std/=lib/forge-std/src/",
        "ds-test/=lib/forge-std/lib/ds-test/src/"
      ],
      "optimizer": {
        "enabled": true,
        "runs": 4194304
      },
      "metadata": {
        "useLiteralContent": false,
        "bytecodeHash": "none",
        "appendCBOR": true
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "abi"
          ]
        }
      },
      "evmVersion": "paris",
      "viaIR": true,
      "libraries": {}
    }
  }}