{
    "Function": "_getPremiaDeltas",
    "File": "contracts/SemiFungiblePositionManager.sol",
    "Parent Contracts": [
        "contracts/multicall/Multicall.sol",
        "contracts/tokens/ERC1155Minimal.sol"
    ],
    "High-Level Calls": [
        "LeftRight",
        "LeftRight",
        "LeftRight",
        "Math",
        "LeftRight",
        "LeftRight",
        "Math",
        "LeftRight",
        "LeftRight",
        "LeftRight",
        "Math",
        "Math",
        "LeftRight",
        "Math",
        "LeftRight",
        "LeftRight",
        "LeftRight",
        "Math",
        "LeftRight",
        "LeftRight"
    ],
    "Internal Calls": [],
    "Library Calls": [
        "toLeftSlot",
        "rightSlot",
        "mulDiv",
        "toUint128",
        "mulDiv",
        "toUint128",
        "leftSlot",
        "mulDiv",
        "toUint128",
        "toRightSlot",
        "toLeftSlot",
        "mulDiv",
        "toUint128",
        "leftSlot",
        "rightSlot",
        "mulDiv",
        "mulDiv",
        "toUint128",
        "toUint128",
        "toRightSlot"
    ],
    "Low-Level Calls": [],
    "Code": "function _getPremiaDeltas(\n        uint256 currentLiquidity,\n        int256 collectedAmounts\n    ) private pure returns (uint256 deltaPremiumOwed, uint256 deltaPremiumGross) {\n        // extract liquidity values\n        uint256 removedLiquidity = currentLiquidity.leftSlot();\n        uint256 netLiquidity = currentLiquidity.rightSlot();\n\n        // premia spread equations are graphed and documented here: https://www.desmos.com/calculator/mdeqob2m04\n        // explains how we get from the premium per liquidity (calculated here) to the total premia collected and the multiplier\n        // as well as how the value of VEGOID affects the premia\n        // note that the \"base\" premium is just a common factor shared between the owed (long) and gross (short)\n        // premia, and is only seperated to simplify the calculation\n        // (the graphed equations include this factor without separating it)\n        unchecked {\n            uint256 totalLiquidity = netLiquidity + removedLiquidity;\n\n            uint128 premium0X64_base;\n            uint128 premium1X64_base;\n\n            {\n                uint128 collected0 = uint128(collectedAmounts.rightSlot());\n                uint128 collected1 = uint128(collectedAmounts.leftSlot());\n\n                // compute the base premium as collected * total / net^2 (from Eqn 3)\n                premium0X64_base = Math\n                    .mulDiv(collected0, totalLiquidity * 2 ** 64, netLiquidity ** 2)\n                    .toUint128();\n                premium1X64_base = Math\n                    .mulDiv(collected1, totalLiquidity * 2 ** 64, netLiquidity ** 2)\n                    .toUint128();\n            }\n\n            {\n                uint128 premium0X64_owed;\n                uint128 premium1X64_owed;\n                {\n                    // compute the owed premium (from Eqn 3)\n                    uint256 numerator = netLiquidity + (removedLiquidity / 2 ** VEGOID);\n\n                    premium0X64_owed = Math\n                        .mulDiv(premium0X64_base, numerator, totalLiquidity)\n                        .toUint128();\n                    premium1X64_owed = Math\n                        .mulDiv(premium1X64_base, numerator, totalLiquidity)\n                        .toUint128();\n\n                    deltaPremiumOwed = uint256(0).toRightSlot(premium0X64_owed).toLeftSlot(\n                        premium1X64_owed\n                    );\n                }\n            }\n\n            {\n                uint128 premium0X64_gross;\n                uint128 premium1X64_gross;\n                {\n                    // compute the gross premium (from Eqn 4)\n                    uint256 numerator = totalLiquidity ** 2 -\n                        totalLiquidity *\n                        removedLiquidity +\n                        ((removedLiquidity ** 2) / 2 ** (VEGOID));\n                    premium0X64_gross = Math\n                        .mulDiv(premium0X64_base, numerator, totalLiquidity ** 2)\n                        .toUint128();\n                    premium1X64_gross = Math\n                        .mulDiv(premium1X64_base, numerator, totalLiquidity ** 2)\n                        .toUint128();\n                    deltaPremiumGross = uint256(0).toRightSlot(premium0X64_gross).toLeftSlot(\n                        premium1X64_gross\n                    );\n                }\n            }\n        }\n    }"
}