Skip to main content
The LiquidityBookServices class is the main entry point for interacting with the Saros DLMM SDK. It provides methods for creating and managing liquidity pools, positions, and performing swaps.

Constructor

new LiquidityBookServices

Creates a new instance of the LiquidityBookServices class. Parameters
ILiquidityBookConfig
required

Properties

lbConfig

The public key of the Liquidity Book program configuration. Returns
PublicKey
The public key of the configuration.

hooksConfig

The public key of the hooks program configuration. Returns
PublicKey
The public key of the configuration.

Methods

getPairAccount

Retrieves the account information for a given liquidity pair. Parameters
PublicKey
required
The public key of the liquidity pair.
Returns
Promise<PairAccount>

getPositionAccount

Retrieves the account information for a given position. Parameters
PublicKey
required
The public key of the position.
Returns
Promise<any>
A promise that resolves to the position account information.

getBinArray

Retrieves the bin array for a given pair and bin array index. If the bin array is not initialized, it will be initialized if a transaction and payer are provided. Parameters
GetBinArrayParams
required
Returns
Promise<PublicKey>
A promise that resolves to the public key of the bin array.

getBinArrayInfo

Retrieve active bins array and the next or previous bins array Parameters
GetBinsArrayInfoParams
required
Returns
Promise<{ bins: any[]; resultIndex: number }>
A promise that resolves to an object containing the bins and the result index.

getBinsReserveInformation

This function calculates and returns the reserve amounts (X and Y) for each bin within a specified liquidity position. It fetches position details, retrieves the relevant bin arrays, and then computes the reserves based on the liquidity shares held in the position. Parameters
GetBinsReserveParams
required
Returns
Promise<GetBinsReserveResponse[]>
A promise that resolves to an array of objects containing the reserve information for each bin.

createPairWithConfig

Creates a new liquidity pair with the given configuration. Parameters
CreatePairWithConfigParams
required
Returns
Promise<object>
A promise that resolves to an object containing the transaction, pair public key, bin array public keys, hooks config, and active bin.

createPosition

Creates a new liquidity position. Parameters
CreatePositionParams
required
Returns
Promise<{ position: string }>
A promise that resolves to an object containing the position public key.

addLiquidityIntoPosition

Adds liquidity into an existing position. Parameters
AddLiquidityIntoPositionParams
required
Returns
Promise<void>
A promise that resolves when the liquidity has been added.

removeMultipleLiquidity

Removes liquidity from multiple positions. Parameters
RemoveMultipleLiquidityParams
required
Returns
Promise<RemoveMultipleLiquidityResponse>

swap

Performs a swap between two tokens. Parameters
SwapParams
required
Returns
Promise<Transaction>
A promise that resolves to the swap transaction.

getQuote

Calculates the estimated output amount for a swap, considering slippage and price impact. Parameters
GetTokenOutputParams
required
Returns
Promise<GetTokenOutputResponse>

getMaxAmountOutWithFee

Calculates the maximum possible output amount for a given input amount, considering the current pool state and fees. Parameters
PublicKey
required
The public key of the liquidity pair.
number
required
The input amount.
boolean
required
Whether to swap for the Y token.
number
required
The decimals of the base token.
number
required
The decimals of the quote token.
Returns
Promise<{ maxAmountOut: number; price: number }>
A promise that resolves to an object containing the maximum output amount and the price.

getDexName

Returns the name of the DEX. Returns
string
The name of the DEX.

getDexProgramId

Returns the program ID of the DEX. Returns
PublicKey
The program ID of the DEX.

fetchPoolAddresses

Fetches the addresses of all liquidity pools. Returns
Promise<string[]>
A promise that resolves to an array of pool addresses.

getUserPositions

Fetches the liquidity positions for a given user and pair. Parameters
UserPositionsParams
required
Returns
Promise<any[]>
A promise that resolves to an array of position information objects.

quote

Retrieves a quote for a swap. This is a convenience method that wraps getQuote. Parameters
object
required
An object containing the parameters for the quote.
Returns
Promise<GetTokenOutputResponse>

fetchPoolMetadata

Fetches the metadata for a given liquidity pool. Parameters
string
required
The public key of the liquidity pair.
Returns
Promise<PoolMetadata>

getPairVaultInfo

Retrieves the vault information for a given token and pair. Parameters
object
required
An object containing the parameters for retrieving the vault info.
Returns
Promise<PublicKey>
A promise that resolves to the public key of the pair vault.

getUserVaultInfo

Retrievess the vault information for a given token and user. Parameters
GetUserVaultInfoParams
required
Returns
Promise<PublicKey>
A promise that resolves to the public key of the user vault.

listenNewPoolAddress

Listens for new liquidity pool creation events and executes a callback function when a new pool is created. Parameters
(address: string) => Promise<void>
required
The callback function to execute when a new pool is created.
Returns
void