> ## Documentation Index
> Fetch the complete documentation index at: https://creator-a1160a86.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# LiquidityBookServices

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**

**config** `ILiquidityBookConfig` *required*

**properties**

**mode** `MODE`

The mode of the SDK. Can be `TESTNET`, `DEVNET`, or `MAINNET`.

**options** `object`

**properties**

**rpcUrl** `string`

The URL of the RPC endpoint.

**commitmentOrConfig** `Commitment | ConnectionConfig`

The commitment or connection configuration.

***

## Properties

### `lbConfig`

The public key of the Liquidity Book program configuration.

**Returns**

**Returns** `PublicKey`

The public key of the configuration.

### `hooksConfig`

The public key of the hooks program configuration.

**Returns**

**Returns** `PublicKey`

The public key of the configuration.

***

## Methods

### getPairAccount

Retrieves the account information for a given liquidity pair.

**Parameters**

**pair** `PublicKey` *required*

The public key of the liquidity pair.

**Returns**

**Returns** `Promise\<PairAccount\>`

**properties**

**bump** `number[]`

The bump of the pair account.

**liquidityBookConfig** `PublicKey`

The public key of the liquidity book configuration.

**binStep** `number`

The bin step of the pair.

**binStepSeed** `number[]`

The bin step seed of the pair.

**tokenMintX** `PublicKey`

The public key of the X token mint.

**tokenMintY** `PublicKey`

The public key of the Y token mint.

**staticFeeParameters** `StaticFeeParameters`

The static fee parameters of the pair.

**activeId** `number`

The active ID of the pair.

**dynamicFeeParameters** `DynamicFeeParameters`

The dynamic fee parameters of the pair.

**protocolFeesX** `BN`

The protocol fees for the X token.

**protocolFeesY** `BN`

The protocol fees for the Y token.

**hook** `PublicKey | null`

The public key of the hook, or null if there is no hook.

### getPositionAccount

Retrieves the account information for a given position.

**Parameters**

**position** `PublicKey` *required*

The public key of the position.

**Returns**

**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**

**params** `GetBinArrayParams` *required*

**properties**

**binArrayIndex** `number`

The index of the bin array.

**pair** `PublicKey`

The public key of the pair.

**payer** `PublicKey`

The public key of the payer.

**transaction** `Transaction`

The transaction to add the instruction to.

**Returns**

**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**

**params** `GetBinsArrayInfoParams` *required*

**properties**

**binArrayIndex** `number`

The index of the bin array.

**pair** `PublicKey`

The public key of the pair.

**payer** `PublicKey`

The public key of the payer.

**Returns**

**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**

**params** `GetBinsReserveParams` *required*

**properties**

**position** `PublicKey`

The public key of the position.

**pair** `PublicKey`

The public key of the pair.

**payer** `PublicKey`

The public key of the payer.

**Returns**

**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**

**params** `CreatePairWithConfigParams` *required*

**properties**

**tokenBase** `object`

**properties**

**decimal** `number`

The decimal of the base token.

**mintAddress** `string`

The mint address of the base token.

**tokenQuote** `object`

**properties**

**decimal** `number`

The decimal of the quote token.

**mintAddress** `string`

The mint address of the quote token.

**binStep** `number`

The bin step of the pair.

**ratePrice** `number`

The rate price of the pair.

**payer** `PublicKey`

The public key of the payer.

**Returns**

**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**

**params** `CreatePositionParams` *required*

**properties**

**payer** `PublicKey`

The public key of the payer.

**relativeBinIdLeft** `number`

The relative bin ID of the left side of the position.

**relativeBinIdRight** `number`

The relative bin ID of the right side of the position.

**pair** `PublicKey`

The public key of the pair.

**binArrayIndex** `number`

The index of the bin array.

**positionMint** `PublicKey`

The public key of the position mint.

**transaction** `Transaction`

The transaction to add the instruction to.

**Returns**

**Returns** `Promise\<\{ position: string \}\>`

A promise that resolves to an object containing the position public key.

### addLiquidityIntoPosition

Adds liquidity into an existing position.

**Parameters**

**params** `AddLiquidityIntoPositionParams` *required*

**properties**

**positionMint** `PublicKey`

The public key of the position mint.

**payer** `PublicKey`

The public key of the payer.

**pair** `PublicKey`

The public key of the pair.

**transaction** `Transaction`

The transaction to add the instruction to.

**liquidityDistribution** `Distribution[]`

The distribution of liquidity.

**amountY** `number`

The amount of Y token to add.

**amountX** `number`

The amount of X token to add.

**binArrayLower** `PublicKey`

The public key of the lower bin array.

**binArrayUpper** `PublicKey`

The public key of the upper bin array.

**Returns**

**Returns** `Promise\<void\>`

A promise that resolves when the liquidity has been added.

### removeMultipleLiquidity

Removes liquidity from multiple positions.

**Parameters**

**params** `RemoveMultipleLiquidityParams` *required*

**properties**

**maxPositionList** `object[]`

The list of positions to remove liquidity from.

**payer** `PublicKey`

The public key of the payer.

**type** `string`

The type of removal. Can be `removeBoth`, `removeBaseToken`, or `removeQuoteToken`.

**pair** `PublicKey`

The public key of the pair.

**tokenMintX** `PublicKey`

The public key of the X token mint.

**tokenMintY** `PublicKey`

The public key of the Y token mint.

**activeId** `number`

The active ID of the pair.

**Returns**

**Returns** `Promise\<RemoveMultipleLiquidityResponse\>`

**properties**

**txs** `Transaction[]`

The transactions to remove liquidity.

**txCreateAccount** `Transaction`

The transaction to create the account.

**txCloseAccount** `Transaction`

The transaction to close the account.

**positionClosed** `object[]`

The list of closed positions.

### swap

Performs a swap between two tokens.

**Parameters**

**params** `SwapParams` *required*

**properties**

**tokenMintX** `PublicKey`

The public key of the X token mint.

**tokenMintY** `PublicKey`

The public key of the Y token mint.

**amount** `bigint`

The amount to swap.

**otherAmountOffset** `bigint`

The other amount offset.

**swapForY** `boolean`

Whether to swap for the Y token.

**isExactInput** `boolean`

Whether the input amount is exact.

**pair** `PublicKey`

The public key of the pair.

**hook** `PublicKey`

The public key of the hook.

**payer** `PublicKey`

The public key of the payer.

**Returns**

**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**

**params** `GetTokenOutputParams` *required*

**properties**

**pair** `PublicKey`

The public key of the pair.

**tokenBase** `PublicKey`

The public key of the base token.

**tokenQuote** `PublicKey`

The public key of the quote token.

**amount** `bigint`

The amount to swap.

**swapForY** `boolean`

Whether to swap for the Y token.

**isExactInput** `boolean`

Whether the input amount is exact.

**tokenBaseDecimal** `number`

The decimal of the base token.

**tokenQuoteDecimal** `number`

The decimal of the quote token.

**slippage** `number`

The slippage tolerance.

**Returns**

**Returns** `Promise\<GetTokenOutputResponse\>`

**properties**

**amountIn** `bigint`

The amount in.

**amountOut** `bigint`

The amount out.

**priceImpact** `number`

The price impact.

**amount** `bigint`

The amount.

**otherAmountOffset** `bigint`

The other amount offset.

### getMaxAmountOutWithFee

Calculates the maximum possible output amount for a given input amount, considering the current pool state and fees.

**Parameters**

**pairAddress** `PublicKey` *required*

The public key of the liquidity pair.

**amount** `number` *required*

The input amount.

**swapForY** `boolean` *required*

Whether to swap for the Y token.

**decimalBase** `number` *required*

The decimals of the base token.

**decimalQuote** `number` *required*

The decimals of the quote token.

**Returns**

**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**

**Returns** `string`

The name of the DEX.

### getDexProgramId

Returns the program ID of the DEX.

**Returns**

**Returns** `PublicKey`

The program ID of the DEX.

### fetchPoolAddresses

Fetches the addresses of all liquidity pools.

**Returns**

**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**

**params** `UserPositionsParams` *required*

**properties**

**payer** `PublicKey`

The public key of the payer.

**pair** `PublicKey`

The public key of the pair.

**Returns**

**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**

**params** `object` *required*

An object containing the parameters for the quote.

**Returns**

**Returns** `Promise\<GetTokenOutputResponse\>`

**properties**

**amountIn** `bigint`

The amount in.

**amountOut** `bigint`

The amount out.

**priceImpact** `number`

The price impact.

**amount** `bigint`

The amount.

**otherAmountOffset** `bigint`

The other amount offset.

### fetchPoolMetadata

Fetches the metadata for a given liquidity pool.

**Parameters**

**pair** `string` *required*

The public key of the liquidity pair.

**Returns**

**Returns** `Promise\<PoolMetadata\>`

**properties**

**poolAddress** `string`

The public key of the liquidity pair.

**baseMint** `string`

The mint address of the base token.

**baseReserve** `string`

The reserve of the base token.

**quoteMint** `string`

The mint address of the quote token.

**quoteReserve** `string`

The reserve of the quote token.

**tradeFee** `number`

The trade fee.

**extra** `object`

**properties**

**hook** `string`

The hook of the pair.

**tokenQuoteDecimal** `number`

The decimal of the quote token.

**tokenBaseDecimal** `number`

The decimal of the base token.

### getPairVaultInfo

Retrieves the vault information for a given token and pair.

**Parameters**

**params** `object` *required*

An object containing the parameters for retrieving the vault info.

**Returns**

**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**

**params** `GetUserVaultInfoParams` *required*

**properties**

**tokenAddress** `PublicKey`

The public key of the token address.

**payer** `PublicKey`

The public key of the payer.

**transaction** `Transaction`

The transaction to add the instruction to.

**Returns**

**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**

**postTxFunction** `(address: string) =\> Promise\<void\>` *required*

The callback function to execute when a new pool is created.

**Returns**

**Returns** `void`


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.