{
    "Function": "_validateAndForwardToAMM",
    "File": "contracts/SemiFungiblePositionManager.sol",
    "Parent Contracts": [
        "contracts/multicall/Multicall.sol",
        "contracts/tokens/ERC1155Minimal.sol"
    ],
    "High-Level Calls": [
        "TokenId",
        "IUniswapV3Pool",
        "LeftRight",
        "TokenId"
    ],
    "Internal Calls": [
        "revert UniswapPoolNotInitialized()",
        "swapInAMM",
        "_createPositionInAMM",
        "revert PriceBoundFail()",
        "revert OptionsBalanceZero()"
    ],
    "Library Calls": [
        "validate",
        "add",
        "flipToBurnToken"
    ],
    "Low-Level Calls": [],
    "Code": "function _validateAndForwardToAMM(\n        uint256 tokenId,\n        uint128 positionSize,\n        int24 tickLimitLow,\n        int24 tickLimitHigh,\n        bool isBurn\n    ) internal returns (int256 totalCollectedFromAMM, int256 totalMoved, int24 newTick) {\n        // Reverts if positionSize is 0 and user did not own the position before minting/burning\n        if (positionSize == 0) revert Errors.OptionsBalanceZero();\n\n        /// @dev the flipToBurnToken() function flips the isLong bits\n        if (isBurn) {\n            tokenId = tokenId.flipToBurnToken();\n        }\n\n        // Validate tokenId\n        // Extract univ3pool from the poolId map to Uniswap Pool\n        IUniswapV3Pool univ3pool = s_poolContext[tokenId.validate()].pool;\n\n        // Revert if the pool not been previously initialized\n        if (univ3pool == IUniswapV3Pool(address(0))) revert Errors.UniswapPoolNotInitialized();\n\n        bool swapAtMint;\n        {\n            if (tickLimitLow > tickLimitHigh) {\n                swapAtMint = true;\n                (tickLimitLow, tickLimitHigh) = (tickLimitHigh, tickLimitLow);\n            }\n        }\n        // initialize some variables returned by the _createPositionInAMM function\n        int256 itmAmounts;\n\n        {\n            // calls a function that loops through each leg of tokenId and mints/burns liquidity in Uni v3 pool\n            (totalMoved, totalCollectedFromAMM, itmAmounts) = _createPositionInAMM(\n                univ3pool,\n                tokenId,\n                positionSize,\n                isBurn\n            );\n        }\n\n        // if the in-the-money amount is not zero (i.e. positions were minted ITM) and the user did provide tick limits LOW > HIGH, then swap necessary amounts\n        if ((itmAmounts != 0) && (swapAtMint)) {\n            totalMoved = swapInAMM(univ3pool, itmAmounts).add(totalMoved);\n        }\n\n        // Get the current tick of the Uniswap pool, check slippage\n        (, newTick, , , , , ) = univ3pool.slot0();\n\n        if ((newTick >= tickLimitHigh) || (newTick <= tickLimitLow)) revert Errors.PriceBoundFail();\n\n        return (totalCollectedFromAMM, totalMoved, newTick);\n    }"
}