LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo@meteora-ag/dlmm (v1.9.3 in project)DLMM.create(connection, poolAddress) - get pool instancedlmm.initializePositionAndAddLiquidityByStrategy() - open position + add liquidity in one txdlmm.addLiquidityByStrategy({ positionPubKey, totalXAmount, totalYAmount, strategy: { minBinId, maxBinId, strategyType } })dlmm.removeLiquidity({ user, position, fromBinId, toBinId, bps, shouldClaimAndClose })dlmm.closePosition({ owner, position }) - close position account, recover rent| Instruction | Purpose |
|---|---|
initializePosition / initializePosition2 |
Create position account |
addLiquidityByStrategy / addLiquidityByStrategy2 |
Add liquidity with strategy |
removeLiquidity / removeLiquidityByRange / removeLiquidityByRange2 |
Remove liquidity |
closePosition / closePosition2 |
Close position account |
const DISCRIMINATORS = {
addLiquidity: [181, 157, 89, 67, 143, 182, 52, 72],
addLiquidityByStrategy: [7, 3, 150, 127, 148, 40, 61, 200],
addLiquidityByStrategy2: [3, 221, 149, 218, 111, 141, 118, 213],
addLiquidityByStrategyOneSide: [41, 5, 238, 175, 100, 225, 6, 205],
removeLiquidity: [80, 85, 209, 72, 24, 206, 177, 108],
removeLiquidityByRange: [26, 82, 102, 152, 240, 74, 105, 26],
removeLiquidityByRange2: [204, 2, 195, 145, 53, 145, 145, 205],
closePosition: [123, 134, 81, 0, 49, 68, 98, 98],
closePosition2: [174, 90, 35, 115, 186, 40, 147, 226],
initializePosition: [219, 192, 234, 71, 190, 191, 102, 80],
initializePosition2: [143, 19, 242, 145, 213, 15, 104, 115],
};
| Instruction | Accounts |
|---|---|
addLiquidityByStrategy |
[0] position, [1] lbPair, [11] sender |
addLiquidityByStrategy2 |
[0] position, [1] lbPair, [9] sender |
initializePosition |
[0] payer, [1] position, [2] lbPair, [3] owner |
removeLiquidity |
[0] position, [1] lbPair, [11] sender |
removeLiquidityByRange |
[0] position, [1] lbPair, [11] sender |
closePosition |
[0] position, [1] lbPair, [4] sender |
connection.onLogs(walletPubkey, callback, 'confirmed') per monitored walletgetTransaction(signature, { maxSupportedTransactionVersion: 0 })logsSubscribe mentions filter only supports ONE address per subscriptionBorshInstructionCoder from @coral-xyz/anchor with DLMM IDL@meteora-ag/dlmm packageinstructionCoder.decode(Buffer.from(ix.data)) returns { name, data }addLiquidityByStrategy on pool XfollowerAmount = leaderAmount * COPY_RATIOdlmm.initializePositionAndAddLiquidityByStrategy()removeLiquidity or closePositiondlmm.closePosition() if leader closedfollowerAmountX = leaderAmountX * (COPY_RATIO * 10000) / 10000
followerAmountY = leaderAmountY * (COPY_RATIO * 10000) / 10000
Using BN integer math to avoid floating point issues.
npm install prisma tsx @coral-xyz/anchor @types/bn.js --save-dev
@coral-xyz/anchor is already a transitive dep of @meteora-ag/dlmm but needs explicit install for types.