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 theLiquidityBookServices 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. ParametersPublicKey
required
The public key of the liquidity pair.
Promise<PairAccount>
getPositionAccount
Retrieves the account information for a given position. ParametersPublicKey
required
The public key of the position.
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. ParametersGetBinArrayParams
required
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 ParametersGetBinsArrayInfoParams
required
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. ParametersGetBinsReserveParams
required
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. ParametersCreatePairWithConfigParams
required
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. ParametersCreatePositionParams
required
Promise<{ position: string }>
A promise that resolves to an object containing the position public key.
addLiquidityIntoPosition
Adds liquidity into an existing position. ParametersAddLiquidityIntoPositionParams
required
Promise<void>
A promise that resolves when the liquidity has been added.
removeMultipleLiquidity
Removes liquidity from multiple positions. ParametersRemoveMultipleLiquidityParams
required
Promise<RemoveMultipleLiquidityResponse>
swap
Performs a swap between two tokens. ParametersSwapParams
required
Promise<Transaction>
A promise that resolves to the swap transaction.
getQuote
Calculates the estimated output amount for a swap, considering slippage and price impact. ParametersGetTokenOutputParams
required
Promise<GetTokenOutputResponse>
getMaxAmountOutWithFee
Calculates the maximum possible output amount for a given input amount, considering the current pool state and fees. ParametersPublicKey
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.
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. Returnsstring
The name of the DEX.
getDexProgramId
Returns the program ID of the DEX. ReturnsPublicKey
The program ID of the DEX.
fetchPoolAddresses
Fetches the addresses of all liquidity pools. ReturnsPromise<string[]>
A promise that resolves to an array of pool addresses.
getUserPositions
Fetches the liquidity positions for a given user and pair. ParametersUserPositionsParams
required
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 wrapsgetQuote.
Parameters
object
required
An object containing the parameters for the quote.
Promise<GetTokenOutputResponse>
fetchPoolMetadata
Fetches the metadata for a given liquidity pool. Parametersstring
required
The public key of the liquidity pair.
Promise<PoolMetadata>
getPairVaultInfo
Retrieves the vault information for a given token and pair. Parametersobject
required
An object containing the parameters for retrieving the vault info.
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. ParametersGetUserVaultInfoParams
required
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.
void
