Withdraw Liquidity
To withdraw a position's liquidity, withdrawLiquidity
is used. This function requires, as input:
positionId
-> id corresponding to the positionremovedLiquidity
-> amount of liquidity to be removed. It is possible to remove, at any time, any amount of liquidity from one's position (i.e not necessarily all of the liquidity).
withdrawLiquidity
internally calls the _withdrawReward
method, passing the positionId
and the required removedLiquidity
amount.
_withdrawReward
internally calls the _retrieveGen2LiquidityAndFees
method to remove the liquidity of the user's position from the NFT of the setup, by using the decreaseLiquidity
method of the nonfungiblePositionManager
(Uniswap v3):
If the liquidity withdrawn is equal to the position's liquidity (and thus the remaining position liquidity is 0), the position is automatically deleted from the setup and from the contract memory:
In this case, the _setupPositionsCount
is decreased by 1.
When the last position of a setup is closed, the setup is deactivated (see the Activate / Deactivate setups section to learn more), deleted from the memory of the contract and the setup NFT is burned:
Also, not only the farmer's liquidity is withdrawn but also his earned rewards and fees from the NFT too. See the Uniswap v3 NFT Management section to learn more.
Last updated