Gathering detailed insights and metrics for @meteora-ag/dlmm-sdk-public
Gathering detailed insights and metrics for @meteora-ag/dlmm-sdk-public
Gathering detailed insights and metrics for @meteora-ag/dlmm-sdk-public
Gathering detailed insights and metrics for @meteora-ag/dlmm-sdk-public
npm install @meteora-ag/dlmm-sdk-public
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
NPM: https://www.npmjs.com/package/@meteora-ag/dlmm-sdk-public
SDK: https://github.com/MeteoraAg/dlmm-sdk
Discord: https://discord.com/channels/841152225564950528/864859354335412224
npm i @meteora-ag/dlmm-sdk-public @coral-xyz/anchor @solana/web3.js
1const USDC_USDT_POOL = new PublicKey('ARwi1S4DaiTG5DX7S4M4ZsrXqpMD1MrTmbu9ue2tpmEq') // You can get your desired pool address from the API https://dlmm-api.meteora.ag/pair/all 2const dlmmPool = await DLMM.create(connection, USDC_USDT_POOL, { 3 cluster: "devnet", 4}); 5 6// If you need to create multiple, can consider using `createMultiple` 7const dlmmPool = await DLMM.create(connection, [USDC_USDT_POOL, ...], { 8 cluster: "devnet", 9}); 10
1const activeBin = await dlmmPool.getActiveBin(); 2const activeBinPriceLamport = activeBin.price; 3const activeBinPricePerToken = dlmmPool.fromPricePerLamport( 4 Number(activeBin.price) 5);
1const TOTAL_RANGE_INTERVAL = 10; // 10 bins on each side of the active bin
2const bins = [activeBin.binId]; // Make sure bins is less than 70, as currently only support up to 70 bins for 1 position
3for (
4 let i = activeBin.binId;
5 i < activeBin.binId + TOTAL_RANGE_INTERVAL / 2;
6 i++
7) {
8 const rightNextBinId = i + 1;
9 const leftPrevBinId = activeBin.binId - (rightNextBinId - activeBin.binId);
10 bins.push(rightNextBinId);
11 bins.unshift(leftPrevBinId);
12}
13
14const activeBinPricePerToken = dlmmPool.fromPricePerLamport(
15 Number(activeBin.price)
16);
17const totalXAmount = new BN(100);
18const totalYAmount = totalXAmount.mul(new BN(Number(activeBinPricePerToken)));
19
20// Get spot distribution (You can calculate with other strategy `calculateSpotDistribution`, `calculateNormalDistribution`)
21const spotXYAmountDistribution = calculateSpotDistribution(
22 activeBin.binId,
23 bins
24);
25const newPosition = new Keypair();
26const createPositionTx =
27 await dlmmPool.initializePositionAndAddLiquidityByWeight({
28 positionPubKey: newPosition.publicKey,
29 lbPairPubKey: dlmmPool.pubkey,
30 user: user.publicKey,
31 totalXAmount,
32 totalYAmount,
33 xYAmountDistribution: spotXYAmountDistribution,
34 });
35
36try {
37 for (let tx of Array.isArray(createPositionTx)
38 ? createPositionTx
39 : [createPositionTx]) {
40 const createPositionTxHash = await sendAndConfirmTransaction(
41 connection,
42 tx,
43 [user, newPosition]
44 );
45 }
46} catch (error) {}
1const { userPositions } = await dlmmPool.getPositionsByUserAndLbPair( 2 user.publicKey 3); 4const binData = userPositions[0].positionData.positionBinData;
1const addLiquidityTx = await dlmmPool.addLiquidityByWeight({
2 positionPubKey: userPositions[0].publicKey,
3 lbPairPubKey: dlmmPool.pubkey,
4 user: user.publicKey,
5 totalXAmount,
6 totalYAmount,
7 xYAmountDistribution: spotXYAmountDistribution,
8});
9
10try {
11 for (let tx of Array.isArray(addLiquidityTx)
12 ? addLiquidityTx
13 : [addLiquidityTx]) {
14 const addLiquidityTxHash = await sendAndConfirmTransaction(connection, tx, [
15 user,
16 newPosition,
17 ]);
18 }
19} catch (error) {}
1const binIdsToRemove = userPositions[0].positionData.positionBinData.map( 2 (bin) => bin.binId 3); 4const removeLiquidityTx = await dlmmPool.removeLiquidity({ 5 position: userPositions[0].publicKey, 6 user: user.publicKey, 7 binIds: binIdsToRemove, 8 liquiditiesBpsToRemove: new Array(binIdsToRemove.length).fill( 9 new BN(100 * 100) 10 ), // 100% (range from 0 to 100) 11 shouldClaimAndClose: true, // should claim swap fee and close position together 12}); 13 14try { 15 for (let tx of Array.isArray(removeLiquidityTx) 16 ? removeLiquidityTx 17 : [removeLiquidityTx]) { 18 const removeLiquidityTxHash = await sendAndConfirmTransaction( 19 connection, 20 tx, 21 [user, newPosition] 22 ); 23 } 24} catch (error) {}
1const swapAmount = new BN(100); 2// Swap quote 3const swapQuote = await dlmmPool.swapQuote(swapAmount, true, new BN(10)); 4 5// Swap 6const swapTx = await dlmmPool.swap({ 7 inToken: dlmmPool.tokenX.publicKey, 8 binArraysPubkey: swapQuote.binArraysPubkey, 9 inAmount: swapAmount, 10 lbPair: dlmmPool.pubkey, 11 user: user.publicKey, 12 minOutAmount: swapQuote.minOutAmount, 13 outToken: dlmmPool.tokenY.publicKey, 14}); 15 16try { 17 const swapTxHash = await sendAndConfirmTransaction(connection, swapTx, [ 18 user, 19 ]); 20} catch (error) {}
Function | Description | Return |
---|---|---|
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>> |
getAllLbPairPositionsByUser | Given a list of DLMM addresses, create instances to access the state and functions | Promise<Map<string, PositionInfo>> |
Function | Description | Return |
---|---|---|
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[]> |
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>;}> |
initializePositionAndAddLiquidityByWeight | Initializes a position and adds liquidity | Promise<Transaction|Transaction[]> |
addLiquidityByWeight | 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[]> |
No vulnerabilities found.
No security vulnerabilities found.