{
    "Function": "getAmounts",
    "File": "src/libraries/SwapHelper.sol",
    "Parent Contracts": [],
    "High-Level Calls": [
        "Math512Bits",
        "Math512Bits",
        "Math512Bits",
        "FeeHelper",
        "FeeHelper",
        "Math512Bits",
        "FeeHelper",
        "BinHelper",
        "FeeHelper",
        "FeeHelper"
    ],
    "Internal Calls": [],
    "Library Calls": [
        "shiftDivRoundDown",
        "shiftDivRoundUp",
        "getFeeAmountFrom",
        "mulShiftRoundDown",
        "getPriceFromId",
        "updateVolatilityAccumulated",
        "getFeeAmountDistribution",
        "getFeeAmount",
        "getFeeAmountDistribution",
        "mulShiftRoundUp"
    ],
    "Low-Level Calls": [],
    "Code": "function getAmounts(\n        ILBPair.Bin memory bin,\n        FeeHelper.FeeParameters memory fp,\n        uint256 activeId,\n        bool swapForY,\n        uint256 amountIn\n    )\n        internal\n        pure\n        returns (\n            uint256 amountInToBin,\n            uint256 amountOutOfBin,\n            FeeHelper.FeesDistribution memory fees\n        )\n    {\n        uint256 _price = BinHelper.getPriceFromId(activeId, fp.binStep);\n\n        uint256 _reserve;\n        uint256 _maxAmountInToBin;\n        if (swapForY) {\n            _reserve = bin.reserveY;\n            _maxAmountInToBin = _reserve.shiftDivRoundUp(Constants.SCALE_OFFSET, _price);\n        } else {\n            _reserve = bin.reserveX;\n            _maxAmountInToBin = _price.mulShiftRoundUp(_reserve, Constants.SCALE_OFFSET);\n        }\n\n        fp.updateVolatilityAccumulated(activeId);\n        fees = fp.getFeeAmountDistribution(fp.getFeeAmount(_maxAmountInToBin));\n\n        if (_maxAmountInToBin + fees.total <= amountIn) {\n            amountInToBin = _maxAmountInToBin;\n            amountOutOfBin = _reserve;\n        } else {\n            fees = fp.getFeeAmountDistribution(fp.getFeeAmountFrom(amountIn));\n            amountInToBin = amountIn - fees.total;\n            amountOutOfBin = swapForY\n                ? _price.mulShiftRoundDown(amountInToBin, Constants.SCALE_OFFSET)\n                : amountInToBin.shiftDivRoundDown(Constants.SCALE_OFFSET, _price);\n            // Safety check in case rounding returns a higher value than expected\n            if (amountOutOfBin > _reserve) amountOutOfBin = _reserve;\n        }\n    }"
}