Documentation Index
Fetch the complete documentation index at: https://docs.orca.so/llms.txt
Use this file to discover all available pages before exploring further.
Close a Position
- Rust
- TypeScript Kit
- TypeScript Legacy
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
To close a position and withdraw all liquidity, follow these steps:- RPC Client: Use a Solana RPC client to interact with the blockchain.
- Position Mint: Provide the mint address of the NFT representing your position. This NFT serves as proof of ownership and represents the liquidity in the position.
- Parameters for Liquidity: Define the parameters for decreasing liquidity. This can be specified as a liquidity amount or as specific token amounts.
- Slippage Tolerance: Set the maximum slippage tolerance (optional, defaults to 1%). Slippage refers to the difference between the expected token amounts you receive when closing a position and the actual amounts returned to your wallet. A lower slippage tolerance reduces the risk of receiving fewer tokens than expected but may lead to failed transactions if the market moves too quickly. For example, if you expect to receive 100 units of Token A and 1,000 units of Token B when closing your position, with a 1% slippage tolerance, the minimum amounts returned would be 99 Token A and 990 Token B.
- Authority: This can be your wallet, which will fund the pool initialization. If the authority is not specified, the default wallet will be used. You can configure the default wallet through the SDK.
- Create Instructions: Use the appropriate function to generate the necessary instructions.
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.
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
To close a position and withdraw all liquidity, follow these steps:- RPC Client: Use a Solana RPC client to interact with the blockchain.
- Position Mint: Provide the mint address of the NFT representing your position. This NFT serves as proof of ownership and represents the liquidity in the position.
- Parameters for Liquidity: Define the parameters for decreasing liquidity. This can be specified as a liquidity amount or as specific token amounts.
- Slippage Tolerance: Set the maximum slippage tolerance (optional, defaults to 1%). Slippage refers to the difference between the expected token amounts you receive when closing a position and the actual amounts returned to your wallet. A lower slippage tolerance reduces the risk of receiving fewer tokens than expected but may lead to failed transactions if the market moves too quickly. For example, if you expect to receive 100 units of Token A and 1,000 units of Token B when closing your position, with a 1% slippage tolerance, the minimum amounts returned would be 99 Token A and 990 Token B.
- Authority: This can be your wallet, which will fund the pool initialization. If the authority is not specified, the default wallet will be used. You can configure the default wallet through the SDK.
- Create Instructions: Use the appropriate function to generate the necessary instructions.
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.
Closing a Position
To close a position, you must first withdraw all liquidity and collect all fees and rewards from the position. You can then call theclosePosition instruction to close and burn the position NFT.
The parameters of closePosition are identical to the ones in openPosition.
Whirlpool Client - Sample Code
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.
Instruction - Sample Code
Common Errors
ClosePositionNotEmpty(0x1775) - Position still has liquidity in it. Withdraw all before calling this instruction.
