Add liquidity

Oveview

This walkthrough demonstrates how to inject liquidity into a Saros DLMM liquidity pool through your frontend integration. The two primary flows are:

  • Opening a new position when none exists

  • Augmenting an existing position

Key steps in both flows:

  1. Compute token amounts to deposit

  2. Invoke the relevant on‑chain instruction

Creating a New Position

To create a new liquidity position, you'll need to:

  1. Determine the bin range for the position by specifying relative bin IDs from the active bin:

    • relative_bin_id_left: The leftmost bin ID relative to the active bin

    • relative_bin_id_right: The rightmost bin ID relative to the active bin

  2. Call the create_position instruction with these parameters

  3. After creating the position, you can add liquidity using the increase_position instruction

Example Implementation

Increasing an Existing Position

To add more liquidity to an existing position:

  1. Calculate the amounts of tokens X and Y to add

  2. Define the liquidity distribution across bins

  3. Call the increase_position instruction with:

    • amountX: Amount of token X to add

    • amountY: Amount of token Y to add

    • liquidityDistribution: Array of BinLiquidityDistribution objects specifying how to distribute liquidity across bins

Liquidity Distribution Format

The liquidityDistribution parameter is an array of objects with the following structure:

Notes:

  • The distribution values are in basis points (0-10000)

  • For bins with negative relative IDs, only token X can be distributed

  • For bins with positive relative IDs, only token Y can be distributed

  • The active bin (relativeBinId = 0) can receive both tokens

  • The sum of distributions should equal 10000 (100%)

Last updated