Burning LP Tokens
Last modified:
Burning LP Tokens
The owner of an LP position in a CenturionDEX v3 pool may also remove liquidity. When this occurs, the protocol reduces the liquidity of the position, burns the corresponding portion of the LP position token, and returns to the liquidity provider the appropriate amounts of the two pool assets. In addition, any fees that have accrued since the last fee collection are also credited to the position owner.
The burn operation reuses the (_modifyPosition) function discussed earlier. In this case, the liquidity change is passed as a negative quantity, reflecting the fact that liquidity is being removed rather than added.
/// @inheritdoc ICenturionV3PoolActions
/// @dev noDelegateCall is applied indirectly via _modifyPosition
function burn(
int24 tickLower,
int24 tickUpper,
uint128 amount
) external override lock returns (uint256 amount0, uint256 amount1) {
(Position.Info storage position, int256 amount0Int, int256 amount1Int) =
_modifyPosition(
ModifyPositionParams({
owner: msg.sender,
tickLower: tickLower,
tickUpper: tickUpper,
liquidityDelta: -int256(amount).toInt128()
})
);
amount0 = uint256(-amount0Int);
amount1 = uint256(-amount1Int);
if (amount0 > 0 || amount1 > 0) {
(position.tokensOwed0, position.tokensOwed1) = (
position.tokensOwed0 + uint128(amount0),
position.tokensOwed1 + uint128(amount1)
);
}
emit Burn(msg.sender, tickLower, tickUpper, amount, amount0, amount1);
}