{
    "Function": "getAccountPremium",
    "File": "contracts/SemiFungiblePositionManager.sol",
    "Parent Contracts": [
        "contracts/multicall/Multicall.sol",
        "contracts/tokens/ERC1155Minimal.sol"
    ],
    "High-Level Calls": [
        "LiquidityChunk",
        "LeftRight",
        "LeftRight",
        "LeftRight",
        "LeftRight",
        "FeesCalc",
        "LeftRight",
        "LeftRight"
    ],
    "Internal Calls": [
        "abi.encodePacked()",
        "keccak256(bytes)",
        "_getPremiaDeltas"
    ],
    "Library Calls": [
        "rightSlot",
        "createChunk",
        "add",
        "rightSlot",
        "sub",
        "add",
        "calculateAMMSwapFeesLiquidityChunk",
        "leftSlot"
    ],
    "Low-Level Calls": [],
    "Code": "function getAccountPremium(\n        address univ3pool,\n        address owner,\n        uint256 tokenType,\n        int24 tickLower,\n        int24 tickUpper,\n        int24 atTick,\n        uint256 isLong\n    ) external view returns (uint128 premiumToken0, uint128 premiumToken1) {\n        bytes32 positionKey = keccak256(\n            abi.encodePacked(address(univ3pool), owner, tokenType, tickLower, tickUpper)\n        );\n\n        // Extract the account liquidity for a given uniswap pool, owner, token type, and ticks\n        uint256 acctPremia = isLong == 1\n            ? s_accountPremiumOwed[positionKey]\n            : s_accountPremiumGross[positionKey];\n\n        // Compute the premium up to the current block (ie. after last touch until now). Do not proceed if atTick == type(int24).max = 8388608\n        if (atTick < type(int24).max) {\n            // unique key to identify the liquidity chunk in this uniswap pool\n            uint256 accountLiquidities = s_accountLiquidity[positionKey];\n            uint128 netLiquidity = accountLiquidities.rightSlot();\n            if (netLiquidity != 0) {\n                int256 amountToCollect;\n                {\n                    IUniswapV3Pool _univ3pool = IUniswapV3Pool(univ3pool);\n                    uint256 tempChunk = uint256(0).createChunk(tickLower, tickUpper, 0);\n                    // how much fees have been accumulated within the liquidity chunk since last time we updated this chunk?\n                    // Compute (currentFeesGrowth - oldFeesGrowth), the amount to collect\n                    // currentFeesGrowth (calculated from FeesCalc.calculateAMMSwapFeesLiquidityChunk) is (ammFeesCollectedPerLiquidity * liquidityChunk.liquidity())\n                    // oldFeesGrowth is the last stored update of fee growth within the position range in the past (feeGrowthRange*liquidityChunk.liquidity()) (s_accountFeesBase[positionKey])\n                    int256 feesBase = FeesCalc.calculateAMMSwapFeesLiquidityChunk(\n                        _univ3pool,\n                        atTick,\n                        netLiquidity,\n                        tempChunk\n                    );\n                    amountToCollect = feesBase.sub(s_accountFeesBase[positionKey]);\n                }\n\n                (uint256 deltaPremiumOwed, uint256 deltaPremiumGross) = _getPremiaDeltas(\n                    accountLiquidities,\n                    amountToCollect\n                );\n                // Extract the account liquidity for a given uniswap pool, owner, token type, and ticks\n                acctPremia = isLong == 1\n                    ? acctPremia.add(deltaPremiumOwed)\n                    : acctPremia.add(deltaPremiumGross);\n            }\n        }\n\n        premiumToken0 = acctPremia.rightSlot();\n        premiumToken1 = acctPremia.leftSlot();\n    }"
}