@@ -21,6 +21,9 @@ error ZeroAddress();
2121/// @dev Zero value when it has to be different from zero.
2222error ZeroValue ();
2323
24+ /// @dev The contract is already initialized.
25+ error AlreadyInitialized ();
26+
2427/// @dev Value overflow.
2528/// @param provided Overflow value.
2629/// @param max Maximum possible value.
@@ -41,11 +44,24 @@ error RangeBounds(int24 low, int24 center, int24 high);
4144error ReentrancyGuard ();
4245
4346interface INeighborhoodScanner {
47+ /// @dev Optimizes liquidity amounts by widening up provided ticks using binary search + neighborhood search.
48+ /// @notice 1. Adjusts extreme boundaries, if required.
49+ /// 2. Looks for correct boundaries and adjusts tick spacings accordingly.
50+ /// 3. Fixes one of ticks and executed binary + neighborhood search if scan option is true.
51+ /// Ensures non-zero intermediate for amount0 formula without linear loops.
52+ /// @param sqrtP Center sqrt price.
53+ /// @param ticks Ticks array.
54+ /// @param tickSpacing Tick spacing.
55+ /// @param initialAmounts Initial amounts array.
56+ /// @param scan True if binary and neighborhood ticks search for optimal liquidity is requested, false otherwise.
57+ /// @return loHi Optimized ticks.
58+ /// @return liquidity Corresponding liquidity.
59+ /// @return amountsDesired Corresponding desired amounts.
4460 function optimizeLiquidityAmounts (
45- uint160 centerSqrtPriceX96 ,
61+ uint160 sqrtP ,
4662 int24 [] memory ticks ,
4763 int24 tickSpacing ,
48- uint256 [] memory balances ,
64+ uint256 [] memory initialAmounts ,
4965 bool scan
5066 ) external pure returns (int24 [] memory loHi , uint128 liquidity , uint256 [] memory amountsDesired );
5167}
@@ -57,6 +73,7 @@ interface INeighborhoodScanner {
5773abstract contract LiquidityManagerCore is ERC721TokenReceiver {
5874 event OwnerUpdated (address indexed owner );
5975 event ImplementationUpdated (address indexed implementation );
76+ event MaxSlippageUpdated (uint256 maxSlippage );
6077 event ConvertedToV3 (address indexed pool , uint256 indexed positionId , address [] tokens , uint256 [] amounts , uint256 liquidiy , bool scan );
6178 event RangesChanged (address indexed pool , uint256 indexed positionId , address [] tokens , uint256 [] amounts , uint256 liquidiy , bool scan );
6279 event UtilityAmountsManaged (address indexed olas , address indexed token , uint256 olasAmount , uint256 tokenAmount , bool olasBurnOrTransfer );
@@ -114,39 +131,30 @@ abstract contract LiquidityManagerCore is ERC721TokenReceiver {
114131 /// @param _positionManagerV3 Uniswap V3 position manager address.
115132 /// @param _neighborhoodScanner Neighborhood ticks scanner.
116133 /// @param _observationCardinality Observation cardinality for fresh pools.
117- /// @param _maxSlippage Max slippage for operations.
118134 constructor (
119135 address _olas ,
120136 address _treasury ,
121137 address _positionManagerV3 ,
122138 address _neighborhoodScanner ,
123- uint16 _observationCardinality ,
124- uint16 _maxSlippage
139+ uint16 _observationCardinality
125140 ) {
126- owner = msg .sender ;
127-
128141 // Check for zero addresses
129142 if (_olas == address (0 ) || _treasury == address (0 ) || _positionManagerV3 == address (0 ) ||
130143 _neighborhoodScanner == address (0 ))
131144 {
132145 revert ZeroAddress ();
133146 }
134147
135- // Check for zero values
136- if (_maxSlippage == 0 || _observationCardinality == 0 ) {
148+ // Check for zero value
149+ if (_observationCardinality == 0 ) {
137150 revert ZeroValue ();
138151 }
139- // Check for max value
140- if (_maxSlippage > MAX_BPS) {
141- revert Overflow (_maxSlippage, MAX_BPS);
142- }
143152
144153 olas = _olas;
145154 treasury = _treasury;
146155 positionManagerV3 = _positionManagerV3;
147156 neighborhoodScanner = _neighborhoodScanner;
148157 observationCardinality = _observationCardinality;
149- maxSlippage = _maxSlippage;
150158
151159 // Get V3 factory address
152160 factoryV3 = IUniswapV3 (positionManagerV3).factory ();
@@ -475,8 +483,24 @@ abstract contract LiquidityManagerCore is ERC721TokenReceiver {
475483 }
476484
477485 /// @dev Initialization function.
478- function initialize () external {
486+ /// @param _maxSlippage Max slippage for operations.
487+ function initialize (uint16 _maxSlippage ) external {
488+ if (owner != address (0 )) {
489+ revert AlreadyInitialized ();
490+ }
491+
492+ // Check for zero value
493+ if (_maxSlippage == 0 ) {
494+ revert ZeroValue ();
495+ }
496+ // Check for max value
497+ if (_maxSlippage > MAX_BPS) {
498+ revert Overflow (_maxSlippage, MAX_BPS);
499+ }
479500
501+ maxSlippage = _maxSlippage;
502+
503+ owner = msg .sender ;
480504 }
481505
482506 /// @dev Changes the owner address.
@@ -517,6 +541,23 @@ abstract contract LiquidityManagerCore is ERC721TokenReceiver {
517541 emit ImplementationUpdated (implementation);
518542 }
519543
544+ /// @dev Changes max slippage value.
545+ /// @param newMaxSlippage New max slippage value.
546+ function changeMaxSlippage (uint16 newMaxSlippage ) external {
547+ // Check for the contract ownership
548+ if (msg .sender != owner) {
549+ revert OwnerOnly (msg .sender , owner);
550+ }
551+
552+ // Check for zero value
553+ if (newMaxSlippage == 0 ) {
554+ revert ZeroValue ();
555+ }
556+
557+ maxSlippage = newMaxSlippage;
558+ emit MaxSlippageUpdated (newMaxSlippage);
559+ }
560+
520561 /// @dev Converts token amounts to V3 liquidity: from balances, or from V2 liquidity, or both.
521562 /// @param tokens Token addresses.
522563 /// @param v2Pool V2 pool hash / address.
0 commit comments