1. Overview of Closing a Position
When using the SDK to fully close a liquidity position, you generate all the necessary instructions. It performs the following key actions:- Collect Fees: Retrieves any fees earned from trades involving your liquidity.
- Collect Rewards: Retrieves any rewards you’ve accumulated for the pool.
- Decrease Liquidity: Removes any remaining liquidity in the position.
- Close Position: Closes the position and returns the tokens in your account.
2. Getting Started Guide
Closing a Position
TheWhirlpoolClient version of closePosition will automatically call decrease_liquidity and close_position for you. Note that you still have to manually call collect_fees and collect_reward to make sure the position is empty.
TypeScript
3. Usage Example
Suppose your trading strategy predicts that the current price range will lead to divergence loss, and you need to close the position to avoid further losses. Using the SDK, you can generate the instructions to collect all accumulated fees, rewards, and remove liquidity to prevent further losses.4. Next Steps
After closing a position, you can:- Open a New Position: If you want to redeploy your capital, you can open a new position in a different price range or pool.
- Fetch All Positions: Check all your remaining positions to manage your overall liquidity strategy.
- Reinvest the funds from the closed position into other opportunities based on market conditions.
Common Errors
ClosePositionNotEmpty(0x1775) - Position still has liquidity in it. Withdraw all before calling this instruction.
