Adjusting the Position: Part I
Last modified:
Modifying the Position: Part I
A central component of the minting and liquidity-management logic is the function _modifyPosition. This function is responsible for creating a new position when none exists and for updating an existing one when the owner adds or removes liquidity. In canonical notation, the data required to modify a position are the owner address, the tick interval , and the signed liquidity change , which may be positive when liquidity is added or negative when liquidity is removed. Thus, _modifyPosition serves as the main entry point for changing the state of a position.
The core parameter struct and the first part of _modifyPosition are:
struct ModifyPositionParams {
// the address that owns the position
address owner;
// the lower and upper tick of the position
int24 tickLower;
int24 tickUpper;
// any change in liquidity
int128 liquidityDelta;
}
/// @dev Effect some changes to a position
/// @param params the position details and the change to the position's liquidity to effect
/// @return position a storage pointer referencing the position with the given owner and tick range
/// @return amount0 the amount of token0 owed to the pool, negative if the pool should pay the recipient
/// @return amount1 the amount of token1 owed to the pool, negative if the pool should pay the recipient
function _modifyPosition(ModifyPositionParams memory params)
private
noDelegateCall
returns (
Position.Info storage position,
int256 amount0,
int256 amount1
)
{
checkTicks(params.tickLower, params.tickUpper);
Slot0 memory _slot0 = slot0; // SLOAD for gas optimization
position = _updatePosition(
params.owner,
params.tickLower,
params.tickUpper,
params.liquidityDelta,
_slot0.tick
);
// ... remaining _modifyPosition logic
}