Minting LP Tokens
Last modified:
Minting LP Tokens
When liquidity is added to a CenturionDEX v3 pool, the protocol mints an LP position NFT rather than a fungible LP token. In canonical notation, the inputs required for this operation are the owner address, the liquidity increment , and the price range of the position, specified by its lower and upper tick indexes and , or equivalently by the corresponding price interval . These parameters determine both the identity of the position and the amount of liquidity that is being added to it.
The pool-level mint flow (including _modifyPosition) is implemented as follows:
/// @inheritdoc ICenturionV3PoolActions
/// @dev noDelegateCall is applied indirectly via _modifyPosition
function mint(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount,
bytes calldata data
) external override lock returns (uint256 amount0, uint256 amount1) {
require(amount > 0);
(, int256 amount0Int, int256 amount1Int) =
_modifyPosition(
ModifyPositionParams({
owner: recipient,
tickLower: tickLower,
tickUpper: tickUpper,
liquidityDelta: int256(amount).toInt128()
})
);
amount0 = uint256(amount0Int);
amount1 = uint256(amount1Int);
uint256 balance0Before;
uint256 balance1Before;
if (amount0 > 0) balance0Before = balance0();
if (amount1 > 0) balance1Before = balance1();
ICenturionV3MintCallback(msg.sender).centurionV3MintCallback(amount0, amount1, data);
if (amount0 > 0) require(balance0Before.add(amount0) <= balance0(), 'M0');
if (amount1 > 0) require(balance1Before.add(amount1) <= balance1(), 'M1');
emit Mint(msg.sender, recipient, tickLower, tickUpper, amount, amount0, amount1);
}