{
    "Function": "createLBPair",
    "File": "src/LBFactory.sol",
    "Parent Contracts": [
        "src/interfaces/ILBFactory.sol",
        "src/libraries/PendingOwnable.sol",
        "src/interfaces/IPendingOwnable.sol"
    ],
    "High-Level Calls": [
        "EnumerableSet"
    ],
    "Internal Calls": [
        "revert LBFactory__ImplementationNotSet()",
        "revert LBFactory__FunctionIsLockedForUsers(address)",
        "owner"
    ],
    "Library Calls": [
        "contains"
    ],
    "Low-Level Calls": [],
    "Code": "function createLBPair(\n        IERC20 _tokenX,\n        IERC20 _tokenY,\n        uint24 _activeId,\n        uint16 _binStep\n    ) external override returns (ILBPair _LBPair) {\n        address _owner = owner();\n        if (!creationUnlocked && msg.sender != _owner) revert LBFactory__FunctionIsLockedForUsers(msg.sender);\n\n        address _LBPairImplementation = LBPairImplementation;\n\n        if (_LBPairImplementation == address(0)) revert LBFactory__ImplementationNotSet();\n\n        if (!_quoteAssetWhitelist.contains(address(_tokenY))) revert LBFactory__QuoteAssetNotWhitelisted(_tokenY);\n\n        if (_tokenX == _tokenY) revert LBFactory__IdenticalAddresses(_tokenX);\n\n        // We sort token for storage efficiency, only one input needs to be stored\n        (IERC20 _tokenA, IERC20 _tokenB) = _sortTokens(_tokenX, _tokenY);\n        // single check is sufficient\n        if (address(_tokenA) == address(0)) revert LBFactory__AddressZero();\n        if (address(_LBPairsInfo[_tokenA][_tokenB][_binStep].LBPair) != address(0))\n            revert LBFactory__LBPairAlreadyExists(_tokenX, _tokenY, _binStep);\n\n        bytes32 _preset = _presets[_binStep];\n        if (_preset == bytes32(0)) revert LBFactory__BinStepHasNoPreset(_binStep);\n\n        uint256 _sampleLifetime = _preset.decode(type(uint16).max, 240);\n        // We remove the bits that are not part of the feeParameters\n        _preset &= bytes32(uint256(type(uint144).max));\n\n        bytes32 _salt = keccak256(abi.encode(_tokenA, _tokenB, _binStep));\n        _LBPair = ILBPair(Clones.cloneDeterministic(_LBPairImplementation, _salt));\n\n        _LBPair.initialize(_tokenX, _tokenY, _activeId, uint16(_sampleLifetime), _preset);\n\n        _LBPairsInfo[_tokenA][_tokenB][_binStep] = LBPairInformation({\n            binStep: _binStep,\n            LBPair: _LBPair,\n            createdByOwner: msg.sender == _owner,\n            ignoredForRouting: false\n        });\n\n        allLBPairs.push(_LBPair);\n\n        {\n            bytes32 _avLBPairBinSteps = _availableLBPairBinSteps[_tokenA][_tokenB];\n            // We add a 1 at bit `_binStep` as this binStep is now set\n            _avLBPairBinSteps = bytes32(uint256(_avLBPairBinSteps) | (1 << _binStep));\n\n            // Increase the number of lb pairs by 1\n            _avLBPairBinSteps = bytes32(uint256(_avLBPairBinSteps) + (1 << 248));\n\n            // Save the changes\n            _availableLBPairBinSteps[_tokenA][_tokenB] = _avLBPairBinSteps;\n        }\n\n        emit LBPairCreated(_tokenX, _tokenY, _binStep, _LBPair, allLBPairs.length - 1);\n\n        emit FeeParametersSet(\n            msg.sender,\n            _LBPair,\n            _binStep,\n            _preset.decode(type(uint16).max, 16),\n            _preset.decode(type(uint16).max, 32),\n            _preset.decode(type(uint16).max, 48),\n            _preset.decode(type(uint16).max, 64),\n            _preset.decode(type(uint24).max, 80),\n            _preset.decode(type(uint16).max, 104),\n            _preset.decode(type(uint24).max, 120)\n        );\n    }"
}