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:
Compute token amounts to deposit
Invoke the relevant on‑chain instruction
Creating a New Position
To create a new liquidity position, you'll need to:
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 binrelative_bin_id_right: The rightmost bin ID relative to the active bin
Call the
create_positioninstruction with these parametersAfter creating the position, you can add liquidity using the
increase_positioninstruction
Example Implementation
Increasing an Existing Position
To add more liquidity to an existing position:
Calculate the amounts of tokens X and Y to add
Define the liquidity distribution across bins
Call the
increase_positioninstruction with:amountX: Amount of token X to addamountY: Amount of token Y to addliquidityDistribution: Array ofBinLiquidityDistributionobjects 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