Decrease liquidity
Decrease Liquidity
/// @notice A function that decreases the current liquidity by half. An example to show how to call the `decreaseLiquidity` function defined in periphery.
/// @param tokenId The id of the erc721 token
/// @return amount0 The amount received back in token0
/// @return amount1 The amount returned back in token1
function decreaseLiquidityInHalf(uint256 tokenId) external returns (uint256 amount0, uint256 amount1) {
// caller must be the owner of the NFT
require(msg.sender == deposits[tokenId].owner, 'Not the owner');
// get liquidity data for tokenId
uint128 liquidity = deposits[tokenId].liquidity;
uint128 halfLiquidity = liquidity / 2;
// amount0Min and amount1Min are price slippage checks
// if the amount received after burning is not greater than these minimums, transaction will fail
INonfungiblePositionManager.DecreaseLiquidityParams memory params =
INonfungiblePositionManager.DecreaseLiquidityParams({
tokenId: tokenId,
liquidity: halfLiquidity,
amount0Min: 0,
amount1Min: 0,
deadline: block.timestamp
});
(amount0, amount1) = nonfungiblePositionManager.decreaseLiquidity(params);
//send liquidity back to owner
_sendToOwner(tokenId, amount0, amount1);
}Sending Fees To The Calling Address
Last updated