DLMM TypeScript SDK
This Typescript SDK is meant to help developers easily integrate Meteora's DLMM pools into their protocols. This SDK uses the latest AddLiquidityByStrategy endpoint (instead of AddLiquidityByWeight).
Last updated
This Typescript SDK is meant to help developers easily integrate Meteora's DLMM pools into their protocols. This SDK uses the latest AddLiquidityByStrategy endpoint (instead of AddLiquidityByWeight).
Last updated
SDK on github: https://github.com/MeteoraAg/dlmm-sdk
Program ID: LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo
Devnet: https://devnet.meteora.ag/
You will need to first install these SDK dependencies in order for it to function properly
Below are the code examples of how you can change parameters for key DLMM actions and to interact with the lb_pair / or pool. To view other SDK files on github, click here.
To get the active bin where the current pool price resides
When creating a new liquidity position, there are a few different liquidity position scenarios to consider.
You can create a Balance Position, Imbalance Position, or One-Sided Position
For StrategyType: you can select StrategyType.Spot
, StrategyType.BidAsk
, or StrategyType.Curve
To create a new liquidity position with a Balance Position. This functions like enabling "Auto-Fill" on the user interface, which automatically calculates the required amount of Token Y to match the equivalent value of Token X when creating a position.
To create a new liquidity position with an Imbalance Position. This is similar to disabling "Auto-Fill" on the user interface, which allows users to manually specify the amount to be added for token X and token Y without maintaining an equal value balance between both assets.
To create a new one-sided/single-sided liquidity position with only one token added; typically used to DCA (dollar cost average) into or out of a position.
To get the list of liquidity positions for a specified pair and pool
To add liquidity to an existing liquidity position
To remove liquidity from an existing liquidity position
To claim all swap fees earned in your liquidity position so far
To close an existing liquidity position
To swap tokens within the specified liquidity pool
create
Given the DLMM address, create an instance to access the state and functions
Promise<DLMM>
createMultiple
Given a list of DLMM addresses, create instances to access the state and functions
Promise<Array<DLMM>>
getAllPresetParameters
Get all the preset params (use to create DLMM pool)
Promise<PresetParams>
createPermissionLbPair
Create DLMM Pool
Promise<Transcation>
getClaimableLMReward
Get Claimable LM reward for a position
Promise<LMRewards>
getClaimableSwapFee
Get Claimable Swap Fee for a position
Promise<SwapFee>
getAllLbPairPositionsByUser
Get user's all positions for all DLMM pools
Promise<Map<string, PositionInfo>>
refetchStates
Update onchain state of DLMM instance. It's recommend to call this before interact with the program (Deposit/ Withdraw/ Swap)
Promise<void>
getBinArrays
Retrieves List of Bin Arrays
Promise<BinArrayAccount[]>
getBinArrayForSwap
Retrieves List of Bin Arrays for swap purpose
Promise<BinArrayAccount[]>
getFeeInfo
Retrieves LbPair's fee info including base fee
, protocol fee
& max fee
FeeInfo
getDynamicFee
Retrieves LbPair's dynamic fee
Decimal
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.
Promise<{ activeBin: number; bins: BinLiquidity[] }>
getBinsBetweenMinAndMaxPrice
Retrieves a list of bins within a specified price
Promise<{ activeBin: number; bins: BinLiquidity[] }>
getBinsBetweenLowerAndUpperBound
retrieves a list of bins between a lower and upper bin ID and returns the active bin ID and the list of bins.
Promise<{ activeBin: number; bins: BinLiquidity[] }>
toPricePerLamport
Converts a real price of bin to lamport price
string
fromPricePerLamport
converts a price per lamport value to a real price of bin
string
getActiveBin
Retrieves the active bin ID and its corresponding price
Promise<{ binId: number; price: string }>
getPriceOfBinByBinId
Get the price of a bin based on its bin ID
string
getBinIdFromPrice
get bin ID based on a given price and a boolean flag indicating whether to round down or up.
number
getPositionsByUserAndLbPair
Retrieves positions by user and LB pair, including active bin and user positions.
Promise<{ activeBin: { binId: any; price: string; }; userPositions: Array<Position>;}>
initializePositionAndAddLiquidityByStrategy
Initializes a position and adds liquidity
Promise<Transaction|Transaction[]>
addLiquidityByStrategy
Add liquidity to existing position
Promise<Transaction|Transaction[]>
removeLiquidity
function is used to remove liquidity from a position, with the option to claim rewards and close the position.
Promise<Transaction|Transaction[]>
closePosition
Closes a position
Promise<Transaction|Transaction[]>
swapQuote
Quote for a swap
SwapQuote
swap
Swap token within the LbPair
Promise<Transaction>
claimLMReward
Claim rewards for a specific position owned by a specific owner
Promise<Transaction>
claimAllLMRewards
Claim all liquidity mining rewards for a given owner and their positions.
Promise<Transaction[]>
claimSwapFee
Claim swap fees for a specific position owned by a specific owner
Promise<Transaction>
claimAllSwapFee
Claim swap fees for multiple positions owned by a specific owner
Promise<Transaction>
claimAllRewards
Claim swap fees and LM rewards for multiple positions owned by a specific owner
Promise<Transaction[]>
syncWithMarketPrice
Sync the pool current active bin to match nearest market price bin
Promise<Transaction>
getPairPubkeyIfExists
Get existing pool address given parameter, if not return null
Promise<PublicKey | null>
getMaxPriceInBinArrays
Get max price of the last bin that has liquidity given bin arrays
Promise<string | null>