Skip to main content

1. Overview of Adjusting Liquidity

The SDK functions for increasing or decreasing liquidity work similarly, enabling you to modify the liquidity of an existing position. You can specify the liquidity directly or provide amounts of token A or token B to increase or decrease liquidity. With these functions, you can:
  • Increase liquidity to potentially earn more fees as trading volume grows.
  • Decrease liquidity to reduce exposure or withdraw profits.

2. Getting Started Guide

Once you’ve opened a position in an Orca Whirlpool, you may need to adjust the amount of liquidity you’ve provided to align with market conditions or your strategy. Whether you want to add more liquidity to capture additional fees or withdraw liquidity to reduce exposure or realize profits, the Whirlpools SDK provides functions for both. This guide explains how to use the SDK functions to increase and decrease the liquidity in your position. The SDK also provides quote functions (ex. increaseLiquidityQuoteByInputToken, decreaseLiquidityQuoteByLiquidity) to help estimate the tokenIn/Out from the liquidity operation.

Using Whirlpool Client

Use the Position class from the WhirlpoolClient to fetch and manage your liquidity. Read below for more on the relationship between quote and the transaction.
TypeScript

The Manual Way

For each instruction, calculate the following values:
  • liquidityAmount - The total amount of liquidity you would like to deposit/withdraw into your position.
  • tokenMax A, B (increase_liquidity) - The maximum amount of token X to add to the position. Note the value here is shifted by the decimal places of the token.
  • tokenMin A, B (decrease_liquidity) - The minimum amount of token X to withdraw from the position. Note the value here is shifted by the decimal places of the token.

Getting a Quote

The Typescript SDK provides several quote functions to help generate an estimate based on common user input values.

Increase liquidity quote by input token amount

Given a desired amount of input token (A or B), you can use the quote utility function increaseLiquidityQuoteByInputTokenWithParams to calculate the liquidityAmount and other tokenMax value required to deposit the desired amount of token into the position. The quote amount will differ based on the current price (tick) and the desired tick boundaries for the position. The price environment may change from the time of quote to the actual processing of the increase_liquidity ix. Use the slippage tolerance to adjust the quote values to balance your risk of ix failure and total tokens to deposit.
TypeScript

Decrease liquidity quote by input token amount

Given the liquidity amount, use the decreaseLiquidityQuoteByLiquidityWithParams util function to get an estimate on what’s the minimum token A & B you can expect from the decrease_liquidity instruction call. Like increase_liquidity, use the slippage tolerance to adjust the quote values to balance your risk of ix failure and total tokens to deposit.
TypeScript

3. Usage example

You are creating a bot to manage investors’ funds and want to optimize returns. Such a bot could rebalance liquidity based on market signals to maintain a specific target price range or to optimize fee collection during periods of high volatility.

4. Next steps

After adjusting liquidity, you can:
  • Monitor Performance: Track your adjusted position to evaluate its performance and earned fees.
  • Harvest Rewards: Collect any earned fees and rewards without closing your position.
  • Make Further Adjustments: Depending on market conditions, continue to adjust liquidity as needed to maximize returns or manage risk.
By using the SDK to adjust liquidity, you gain flexibility in managing your positions and optimizing your liquidity provision strategy.

Common Errors

  • LiquidityZero (0x177c) - Provided liquidity amount is zero.
  • LiquidityTooHigh (0x177d) - Provided liquidity exceeds u128::max.
  • TokenMaxExceeded (0x1781) - The required token to perform this operation exceeds the user defined amount in increase_liquidity.
  • TokenMinSubceeded (0x1782) - The required token to perform this operation subceeds the user defined amount in decrease_liquidity.
  • TickNotFound (0x1779) - The provided tick array accounts do not contain the tick specified in the position.
  • ConstraintRaw (0x7d3) - TokenVault, TokenAccount mints does not match the values in the provided whirlpool.