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).
1. cd ts-client
2. anchor localnet -- --features localnet
3. pnpm run test
Install
Install dependencies
You will need to first install these SDK dependencies in order for it to function properly
npm i @meteora-ag/dlmm @coral-xyz/anchor @solana/web3.js
Initialize DLMM instance
import DLMM from'@meteora-ag/dlmm'const USDC_USDT_POOL = new PublicKey('ARwi1S4DaiTG5DX7S4M4ZsrXqpMD1MrTmbu9ue2tpmEq') // You can get your desired pool address from the API https://dlmm-api.meteora.ag/pair/all
constdlmmPool=awaitDLMM.create(connection,USDC_USDT_POOL);// If you need to create multiple, can consider using `createMultiple`constdlmmPool=awaitDLMM.createMultiple(connection, [USDC_USDT_POOL,...]);
To interact with the AmmImpl
Changing Ammlmpl parameters to interact with the lb_pair / or pool
Get Active Bin
To get the active bin where the current pool price resides
constTOTAL_RANGE_INTERVAL=10; // 10 bins on each side of the active binconstminBinId=activeBin.bin_id -TOTAL_RANGE_INTERVAL;constmaxBinId=activeBin.bin_id +TOTAL_RANGE_INTERVAL;constactiveBinPricePerToken=dlmmPool.fromPricePerLamport(Number(activeBin.price));consttotalXAmount=newBN(100);consttotalYAmount=totalXAmount.mul(newBN(Number(activeBinPricePerToken)));// Create Position (Spot Balance deposit, Please refer ``example.ts` for more example)constcreatePositionTx=awaitdlmmPool.initializePositionAndAddLiquidityByStrategy({ positionPubKey:newBalancePosition.publicKey, user:user.publicKey, totalXAmount, totalYAmount, strategy: { maxBinId, minBinId, strategyType:StrategyType.SpotBalanced, }, });try {constcreateBalancePositionTxHash=awaitsendAndConfirmTransaction( connection, createPositionTx, [user, newBalancePosition] );} catch (error) {}
Get list of positions
To get the list of liquidity positions for a specified pair and pool