Pool Functions
create
Creates an instance of the DLMM pool given the pool address. Function- The pool addresses can be fetched from the DLMM API https://dlmm-api.meteora.ag/pair/all
- The
opt
parameter is optional and can be used to specify the cluster and program ID.
createMultiple
Creates multiple instances of the DLMM pool given the pool addresses. Function- The pool addresses can be fetched from the DLMM API https://dlmm-api.meteora.ag/pair/all
- The
opt
parameter is optional and can be used to specify the cluster and program ID.
createCustomizablePermissionlessLbPair
Creates a customizable permissionless LB pair. This function only supports token program. Function- If Alpha Vault is enabled, the program will deterministically whitelist the alpha vault to swap before the pool start trading. Check: https://github.com/MeteoraAg/alpha-vault-sdk
initialize{Prorata|Fcfs}Vault
method to create the alpha vault.
createCustomizablePermissionlessLbPair2
Creates a customizable permissionless LB pair with specified parameters. This function supports both token and token2022 programs. Function- This creates a customizable permissionless pair that supports both token and token2022 programs
- The active bin ID represents the starting price of the pool
- Fee is specified in basis points (100 = 1%)
createLbPair
Creates a new liquidity pair that supports only token program. Function- Throws an error if the pair already exists
- Only supports token program
createLbPair2
Creates a new liquidity pair that supports both token and token2022 programs. Function- Throws an error if the pair already exists
- Supports both token and token2022 programs
initializePositionAndAddLiquidityByStrategy
Initializes a new position and adds liquidity using a specified strategy. FunctionpositionPubKey
: The public key of the position account. (usually usenew Keypair()
)totalXAmount
: The total amount of token X to be added to the liquidity pool.totalYAmount
: The total amount of token Y to be added to the liquidity pool.strategy
: The strategy parameters to be used for the liquidity pool (Can usecalculateStrategyParameter
to calculate).user
: The public key of the user account.slippage
: The slippage percentage to be used for the liquidity pool.
addLiquidityByStrategy
Adds liquidity to an existing position using a specified strategy. FunctionpositionPubKey
: The public key of the position account. (usually usenew Keypair()
)totalXAmount
: The total amount of token X to be added to the liquidity pool.totalYAmount
: The total amount of token Y to be added to the liquidity pool.strategy
: The strategy parameters to be used for the liquidity pool (Can usecalculateStrategyParameter
to calculate).user
: The public key of the user account.slippage
: The slippage percentage to be used for the liquidity pool.
removeLiquidity
Removes liquidity from a position with options to claim rewards and close the position. Functionuser
: The public key of the user account.position
: The public key of the position account.fromBinId
: The ID of the starting bin to remove liquidity from. Must within position range.toBinId
: The ID of the ending bin to remove liquidity from. Must within position range.liquiditiesBpsToRemove
: An array of numbers (percentage) that represent the liquidity to remove from each bin.shouldClaimAndClose
: A boolean flag that indicates whether to claim rewards and close the position.
swapQuote
Returns a quote for a swap operation. FunctioninAmount
: Amount of lamport to swap inswapForY
: Swap token X to Y when it is true, else reversed.allowedSlippage
: Allowed slippage for the swap. Expressed in BPS. To convert from slippage percentage to BPS unit: SLIPPAGE_PERCENTAGE * 100binArrays
: binArrays for swapQuote.isPartialFill
: Flag to check whether the the swapQuote is partial fill, default = false.maxExtraBinArrays
: Maximum number of extra binArrays to return
swapQuoteExactOut
Returns a quote for a swap with exact output amount. FunctionoutAmount
: Amount of lamport to swap outswapForY
: Swap token X to Y when it is true, else reversed.allowedSlippage
: Allowed slippage for the swap. Expressed in BPS. To convert from slippage percentage to BPS unit: SLIPPAGE_PERCENTAGE * 100binArrays
: binArrays for swapQuote.maxExtraBinArrays
: Maximum number of extra binArrays to return
swapExactOut
Executes a swap operation with exact output amount. FunctioninToken
: The public key of the input token mint.outToken
: The public key of the output token mint.outAmount
: The exact amount of output token to receive.maxInAmount
: The maximum amount of input token to spend.lbPair
: The public key of the liquidity pool.user
: The public key of the user account.binArraysPubkey
: The public key of the bin arrays involved in the swap.
swapWithPriceImpact
Executes a swap with price impact constraints. FunctioninToken
: The public key of the token to be swapped in.outToken
: The public key of the token to be swapped out.inAmount
: The amount of token to be swapped in.priceImpact
: Accepted price impact bps.lbPair
: The public key of the liquidity pool.user
: The public key of the user account.binArraysPubkey
: Array of bin arrays involved in the swap
swap
Executes a swap operation. FunctioninToken
: The public key of the token to be swapped in.outToken
: The public key of the token to be swapped out.inAmount
: The amount of token to be swapped in.minOutAmount
: The minimum amount of token to be swapped out.lbPair
: The public key of the liquidity pool.user
: The public key of the user account.binArraysPubkey
: Array of bin arrays involved in the swap
claimLMReward
Claims liquidity mining rewards for a specific position. Function- This function is only available for LB pairs with liqudiity mining rewards.
claimAllLMRewards
Claims all liquidity mining rewards for multiple positions. Function- This function is only available for LB pairs with liqudiity mining rewards.
claimSwapFee
Claims swap fees earned by a specific position. Function- The function
claimSwapFee
is used to claim swap fees for a specific position owned by a specific owner.
claimAllSwapFee
Claims swap fees for multiple positions. Function- The
claimAllSwapFee
function to claim swap fees for multiple positions owned by a specific owner.
claimAllRewards
Claims all rewards (both LM rewards and swap fees) for multiple positions. Function- The
claimAllRewards
function to claim swap fees and LM rewards for multiple positions owned by a specific owner.
claimAllRewardsByPosition
Claims all rewards (both LM rewards and swap fees) for a specific position. Function- The function
claimAllRewardsByPosition
allows a user to claim all rewards for a specific
closePosition
Closes a position and recovers the rent. Function- The function
closePosition
is used to close a position owned by a specific owner.
closePositionIfEmpty
Closes a position if it is empty, otherwise does nothing. Function- The function
closePositionIfEmpty
is used to close a position owned by a specific owner if it is empty.
quoteCreatePosition
Quotes the cost of creating a position with a given strategy. Function- The function
quoteCreatePosition
is used to quote the cost of creating a position with a given strategy.
createEmptyPosition
Creates an empty position and initializes the corresponding bin arrays if needed. Function- The function
createEmptyPosition
is used to create an empty position with specified min/max bin IDs.
seedLiquidity
Creates multiple grouped instructions. The grouped instructions will be [init ata + send lamport for token provde], [initialize bin array + initialize position instructions] and [deposit instruction]. Each grouped instructions can be executed parallelly. Functionowner
: The public key of the positions owner.seedAmount
: Lamport amount to be seeded to the pool.minPrice
: Start price in UI formatmaxPrice
: End price in UI formatbase
: Base keytxPayer
: Account rental fee payerfeeOwner
: Fee owner key. Default to position owneroperator
: Operator keylockReleasePoint
: Timelock. Point (slot/timestamp) the position can withdraw the liquidity,shouldSeedPositionOwner
(optional): Whether to send 1 lamport amount of token X to the position owner to prove ownership.
seedLiquiditySingleBin
Seeds liquidity into a single bin at a specific price. Functionpayer
: The public key of the tx payer.base
: Base keyseedAmount
: Token X lamport amount to be seeded to the pool.price
: TokenX/TokenY Price in UI formatroundingUp
: Whether to round up the pricepositionOwner
: The owner of the positionfeeOwner
: Position fee owneroperator
: Operator of the position. Operator able to manage the position on behalf of the position owner. However, liquidity withdrawal issue by the operator can only send to the position owner.lockReleasePoint
: The lock release point of the position.shouldSeedPositionOwner
(optional): Whether to send 1 lamport amount of token X to the position owner to prove ownership.
initializeBinArrays
Initializes bin arrays for the given bin array indexes if they weren’t initialized. Function- The function
initializeBinArrays
is used to initialize bin arrays for the given bin array indexes if they weren’t initialized.
initializePositionByOperator
Initializes a position with an operator that can manage it on behalf of the owner. FunctionlowerBinId
: Lower bin ID of the position. This represent the lowest price of the positionpositionWidth
: Width of the position. This will decide the upper bin id of the position, which represents the highest price of the position. UpperBinId = lowerBinId + positionWidthowner
: Owner of the position.operator
: Operator of the position. Operator able to manage the position on behalf of the position owner. However, liquidity withdrawal issue by the operator can only send to the position owner.base
: Base keyfeeOwner
: Owner of the fees earned by the position.payer
: Payer for the position account rental.lockReleasePoint
: The lock release point of the position.
setPairStatusPermissionless
Sets the status of a permissionless LB pair to either enabled or disabled. Function- Requires
creator_pool_on_off_control
to be true and typeCustomizablePermissionless
- Pool creator can enable/disable anytime before activation
- After activation, creator can only enable the pair
setActivationPoint
Sets the activation point for the LB pair. Function- The function
setActivationPoint
is used to set the activation point for the LB pair.
setPairStatus
Sets the pair status (enabled/disabled) for admin-controlled pairs. Function- The function
setPairStatus
is used to set the pair status for admin-controlled pairs.
State Functions
getLbPairs
Retrieves all LB pair accounts for the DLMM program. Function- The function
getLbPairs
is used to retrieve all LB pair accounts for the DLMM program.
getCustomizablePermissionlessLbPairIfExists
Retrieves the public key of a customizable permissionless LB pair if it exists. FunctiongetPosition
Retrieves position information for a given position public key. Function- The function
getPosition
retrieves position information for a given public key and processes it using various data to return aLbPosition
object.
getAllPresetParameters
Retrieves all preset parameter accounts for the DLMM program. Function- The function
getAllPresetParameters
is used to retrieve all preset parameter accounts for the DLMM program.
getAllLbPairPositionsByUser
Retrieves all LB pair positions for a given user. Function- The function
getAllLbPairPositionsByUser
is used to retrieve all LB pair positions for a given user.
refetchStates
Refetches and updates the current state of the DLMM instance. Function- The function
refetchStates
is used to refetch and update the current state of the DLMM instance.
getBinArrays
Returns all bin arrays for the current LB pair. Function- The function
getBinArrays
is used to retrieve all bin arrays for the current LB pair.
getBinArrayForSwap
Retrieves bin arrays needed for a swap operation. Function- The function
getBinArrayAroundActiveBin
retrieves a specified number ofBinArrayAccount
objects from the blockchain, based on the active bin and its surrounding bin arrays.
getFeeInfo
Calculates and returns fee information for the pool. Function- The function
getFeeInfo
calculates and returns the base fee rate percentage, maximum fee rate percentage, and protocol fee percentage.
getDynamicFee
Calculates the current dynamic fee for the pool. Function- The function
getDynamicFee
retrieves the current dynamic fee for the pool.
getEmissionRate
Returns the emission rates for LM rewards. Function- The function
getEmissionRate
retrieves the emission rates for LM rewards.
getBinsAroundActiveBin
Retrieves bins around the active bin within specified ranges. Function- The function
getBinsAroundActiveBin
retrieves a specified number of bins to the left and right of the active bin and returns them along with the active bin ID.
getBinsBetweenMinAndMaxPrice
Retrieves bins within a specified price range. Function- The function
getBinsBetweenMinAndMaxPrice
retrieves a list of bins within a specified price range.
getBinsBetweenLowerAndUpperBound
Retrieves bins between specified bin IDs. Function- The function
getBinsBetweenLowerAndUpperBound
retrieves a list of bins between a lower and upper bin ID and returns the active bin ID and the list of bins.
getActiveBin
Retrieves information about the currently active bin. Function- The function retrieves the active bin ID and its corresponding price.
getPositionsByUserAndLbPair
Retrieves positions by user for the current LB pair. Function- The function
getPositionsByUserAndLbPair
retrieves positions by user and LB pair, including active bin and user positions.
getPairPubkeyIfExists
Retrieves the public key of an LB pair if it exists. Function- The function
getPairPubkeyIfExists
retrieves the public key of an LB pair if it exists.
getMaxPriceInBinArrays
Gets the maximum price from the provided bin arrays. Function- The function
getMaxPriceInBinArrays
retrieves the maximum price from the provided bin arrays.
getLbPairLockInfo
Retrieves all pair positions that have locked liquidity. Function- The function
getLbPairLockInfo
retrieves all pair positions that have locked liquidity.
canSyncWithMarketPrice
Checks if the pool can sync with a given market price. Function- The function
canSyncWithMarketPrice
checks if the pool can sync with a given market price.
isSwapDisabled
Checks if swapping is disabled for a given swap initiator. Function- Returns true if pair status is disabled
- For permissioned pairs, checks activation time and pre-activation settings
- Considers special pre-activation swap addresses
Helper Functions
syncWithMarketPrice
Synchronizes the pool with a given market price. Function- The
syncWithMarketPrice
function is used to sync the liquidity pool with the market price.
toPricePerLamport
Converts a real price of bin to a lamport value Function- The
toPricePerLamport
function is used to convert a real price of bin to a lamport value.
fromPricePerLamport
Converts a price per lamport value to a real price of bin Function- The
fromPricePerLamport
function is used to convert a price per lamport value to a real price of bin.