{"_id":"@addrfarm/dlmm","name":"@addrfarm/dlmm","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@addrfarm/dlmm","version":"1.0.0","description":"<p align=\"center\"> <img align=\"center\" src=\"https://app.meteora.ag/icons/logo.svg\" width=\"180\" height=\"180\" /> </p> <br>","main":"./dist/index.js","module":"./dist/index.mjs","source":"./src/index.ts","types":"./dist/index.d.ts","scripts":{"build":"tsup","start":"npm run build -- --watch","test":"jest 'src/test/(ilm|sdk_token2022|sdk|single_bin|token_2022).test.ts'","unit-test":"jest src/test/calculate_distribution.test.ts","example":"dotenv -e .env npx ts-node src/examples/example.ts","start-server":"npx tsc && node dist/src/server/index.js"},"devDependencies":{"@babel/preset-env":"^7.22.5","@types/babar":"^0.2.1","@types/bn.js":"^5.1.5","@types/express":"^4.17.21","@types/gaussian":"^1.2.0","@types/jest":"^29.5.2","babar":"^0.2.3","babel-jest":"^29.5.0","dotenv-cli":"^7.2.1","jest":"^29.5.0","ts-jest":"^29.1.1","tsup":"^6.7.0","typescript":"^5.0.4"},"dependencies":{"@coral-xyz/anchor":"^0.28.0","@coral-xyz/borsh":"^0.28.0","@solana/buffer-layout":"^4.0.1","@solana/spl-token":"^0.4.6","@solana/web3.js":"^1.91.6","bn.js":"^5.2.1","decimal.js":"^10.4.2","express":"^4.19.2","gaussian":"^1.3.0"},"keywords":[],"author":{"name":"McSam"},"license":"ISC","_id":"@addrfarm/dlmm@1.0.0","gitHead":"9c4aeacf7ffabbbc68df0db7f2ed981847b12cfb","_nodeVersion":"23.8.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-tS76QU3THy/y8s3kUhfPygWWJBb5KYhH4XrNI7KxFX6SytnyTWE9WBpn7n2kRtRYuHCL66rQoPpryEsZe4sDrA==","shasum":"3992e57b9233cbb9ffac7a2950b5566e53f33e2c","tarball":"https://registry.npmjs.org/@addrfarm/dlmm/-/dlmm-1.0.0.tgz","fileCount":7,"unpackedSize":3142244,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIGsycOqVq5YEYri1mPuEVcmDDZPTj+mWfEb2BQpBjzZYAiAJQtPSwCOpFt+XOSp/WE+9H+FM4vsq7eWrf2f9Bac+Hw=="}]},"_npmUser":{"name":"jackyzxj","email":"zxj782819517@gmail.com"},"directories":{},"maintainers":[{"name":"jackyzxj","email":"zxj782819517@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/dlmm_1.0.0_1752569841714_0.3112961827429883"},"_hasShrinkwrap":false}},"time":{"created":"2025-07-15T08:57:21.656Z","1.0.0":"2025-07-15T08:57:22.004Z","modified":"2025-07-15T08:57:22.212Z"},"maintainers":[{"name":"jackyzxj","email":"zxj782819517@gmail.com"}],"description":"<p align=\"center\"> <img align=\"center\" src=\"https://app.meteora.ag/icons/logo.svg\" width=\"180\" height=\"180\" /> </p> <br>","keywords":[],"author":{"name":"McSam"},"license":"ISC","readme":"# DLMM SDK\n\n<p align=\"center\">\n<img align=\"center\" src=\"https://app.meteora.ag/icons/logo.svg\" width=\"180\" height=\"180\" />\n</p>\n<br>\n\n## Getting started\n\nNPM: https://www.npmjs.com/package/@meteora-ag/dlmm\n\nSDK: https://github.com/MeteoraAg/dlmm-sdk\n\n<!-- Docs: https://docs.mercurial.finance/mercurial-dynamic-yield-infra/ -->\n\nDiscord: https://discord.com/channels/841152225564950528/864859354335412224\n\n## Install\n\n1. Install deps\n\n```\nnpm i @meteora-ag/dlmm @coral-xyz/anchor @solana/web3.js\n```\n\n2. Initialize DLMM instance\n\n```ts\nimport DLMM from '@meteora-ag/dlmm'\n\nconst USDC_USDT_POOL = new PublicKey('ARwi1S4DaiTG5DX7S4M4ZsrXqpMD1MrTmbu9ue2tpmEq') // You can get your desired pool address from the API https://dlmm-api.meteora.ag/pair/all\nconst dlmmPool = await DLMM.create(connection, USDC_USDT_POOL);\n\n// If you need to create multiple, can consider using `createMultiple`\nconst dlmmPool = await DLMM.createMultiple(connection, [USDC_USDT_POOL, ...]);\n\n```\n\n3. To interact with the AmmImpl\n\n- Get Active Bin\n\n```ts\nconst activeBin = await dlmmPool.getActiveBin();\nconst activeBinPriceLamport = activeBin.price;\nconst activeBinPricePerToken = dlmmPool.fromPricePerLamport(\n  Number(activeBin.price)\n);\n```\n\n- Create Balance Position\n\n```ts\nconst TOTAL_RANGE_INTERVAL = 10; // 10 bins on each side of the active bin\nconst minBinId = activeBin.binId - TOTAL_RANGE_INTERVAL;\nconst maxBinId = activeBin.binId + TOTAL_RANGE_INTERVAL;\n\nconst totalXAmount = new BN(100 * 10 ** baseMint.decimals);\nconst totalYAmount = autoFillYByStrategy(\n  activeBin.binId,\n  dlmmPool.lbPair.binStep,\n  totalXAmount,\n  activeBin.xAmount,\n  activeBin.yAmount,\n  minBinId,\n  maxBinId,\n  StrategyType.Spot // can be StrategyType.Spot, StrategyType.BidAsk, StrategyType.Curve\n);\nconst newBalancePosition = new Keypair();\n\n// Create Position\nconst createPositionTx =\n  await dlmmPool.initializePositionAndAddLiquidityByStrategy({\n    positionPubKey: newBalancePosition.publicKey,\n    user: user.publicKey,\n    totalXAmount,\n    totalYAmount,\n    strategy: {\n      maxBinId,\n      minBinId,\n      strategyType: StrategyType.Spot, // can be StrategyType.Spot, StrategyType.BidAsk, StrategyType.Curve\n    },\n  });\n\ntry {\n  const createBalancePositionTxHash = await sendAndConfirmTransaction(\n    connection,\n    createPositionTx,\n    [user, newBalancePosition]\n  );\n} catch (error) {}\n```\n\n- Create Imbalance Position\n\n```ts\nconst TOTAL_RANGE_INTERVAL = 10; // 10 bins on each side of the active bin\nconst minBinId = activeBin.binId - TOTAL_RANGE_INTERVAL;\nconst maxBinId = activeBin.binId + TOTAL_RANGE_INTERVAL;\n\nconst totalXAmount = new BN(100 * 10 ** baseMint.decimals);\nconst totalYAmount = new BN(0.5 * 10 ** 9); // SOL\nconst newImbalancePosition = new Keypair();\n\n// Create Position\nconst createPositionTx =\n  await dlmmPool.initializePositionAndAddLiquidityByStrategy({\n    positionPubKey: newImbalancePosition.publicKey,\n    user: user.publicKey,\n    totalXAmount,\n    totalYAmount,\n    strategy: {\n      maxBinId,\n      minBinId,\n      strategyType: StrategyType.Spot, // can be StrategyType.Spot, StrategyType.BidAsk, StrategyType.Curve\n    },\n  });\n\ntry {\n  const createBalancePositionTxHash = await sendAndConfirmTransaction(\n    connection,\n    createPositionTx,\n    [user, newImbalancePosition]\n  );\n} catch (error) {}\n```\n\n- Create One Side Position\n\n```ts\nconst TOTAL_RANGE_INTERVAL = 10; // 10 bins on each side of the active bin\nconst minBinId = activeBin.binId;\nconst maxBinId = activeBin.binId + TOTAL_RANGE_INTERVAL * 2;\n\nconst totalXAmount = new BN(100 * 10 ** baseMint.decimals);\nconst totalYAmount = new BN(0);\nconst newOneSidePosition = new Keypair();\n\n// Create Position\nconst createPositionTx =\n  await dlmmPool.initializePositionAndAddLiquidityByStrategy({\n    positionPubKey: newOneSidePosition.publicKey,\n    user: user.publicKey,\n    totalXAmount,\n    totalYAmount,\n    strategy: {\n      maxBinId,\n      minBinId,\n      strategyType: StrategyType.Spot, // can be StrategyType.Spot, StrategyType.BidAsk, StrategyType.Curve\n    },\n  });\n\ntry {\n  const createOneSidePositionTxHash = await sendAndConfirmTransaction(\n    connection,\n    createPositionTx,\n    [user, newOneSidePosition]\n  );\n} catch (error) {}\n```\n\n- Get list of positions\n\n```ts\nconst { userPositions } = await dlmmPool.getPositionsByUserAndLbPair(\n  user.publicKey\n);\nconst binData = userPositions[0].positionData.positionBinData;\n```\n\n- Add liquidity to existing position\n\n```ts\nconst TOTAL_RANGE_INTERVAL = 10; // 10 bins on each side of the active bin\nconst minBinId = activeBin.binId - TOTAL_RANGE_INTERVAL;\nconst maxBinId = activeBin.binId + TOTAL_RANGE_INTERVAL;\n\nconst totalXAmount = new BN(100 * 10 ** baseMint.decimals);\nconst totalYAmount = autoFillYByStrategy(\n  activeBin.binId,\n  dlmmPool.lbPair.binStep,\n  totalXAmount,\n  activeBin.xAmount,\n  activeBin.yAmount,\n  minBinId,\n  maxBinId,\n  StrategyType.Spot // can be StrategyType.Spot, StrategyType.BidAsk, StrategyType.Curve\n);\n\n// Add Liquidity to existing position\nconst addLiquidityTx = await dlmmPool.addLiquidityByStrategy({\n  positionPubKey: newBalancePosition.publicKey,\n  user: user.publicKey,\n  totalXAmount,\n  totalYAmount,\n  strategy: {\n    maxBinId,\n    minBinId,\n    strategyType: StrategyType.Spot, // can be StrategyType.Spot, StrategyType.BidAsk, StrategyType.Curve\n  },\n});\n\ntry {\n  const addLiquidityTxHash = await sendAndConfirmTransaction(\n    connection,\n    addLiquidityTx,\n    [user]\n  );\n} catch (error) {}\n```\n\n- Remove Liquidity\n\n```ts\nconst userPosition = userPositions.find(({ publicKey }) =>\n  publicKey.equals(newBalancePosition.publicKey)\n);\n// Remove Liquidity\nconst binIdsToRemove = userPosition.positionData.positionBinData.map(\n  (bin) => bin.binId\n);\nconst removeLiquidityTx = await dlmmPool.removeLiquidity({\n  position: userPosition.publicKey,\n  user: user.publicKey,\n  fromBinId: binIdsToRemove[0],\n  toBinId: binIdsToRemove[binIdsToRemove.length - 1],\n  liquiditiesBpsToRemove: new Array(binIdsToRemove.length).fill(\n    new BN(100 * 100)\n  ), // 100% (range from 0 to 100)\n  shouldClaimAndClose: true, // should claim swap fee and close position together\n});\n\ntry {\n  for (let tx of Array.isArray(removeLiquidityTx)\n    ? removeLiquidityTx\n    : [removeLiquidityTx]) {\n    const removeBalanceLiquidityTxHash = await sendAndConfirmTransaction(\n      connection,\n      tx,\n      [user],\n      { skipPreflight: false, preflightCommitment: \"singleGossip\" }\n    );\n  }\n} catch (error) {}\n```\n\n- Claim Fee\n\n```ts\nasync function claimFee(dlmmPool: DLMM) {\n  const claimFeeTxs = await dlmmPool.claimAllSwapFee({\n    owner: user.publicKey,\n    positions: userPositions,\n  });\n\n  try {\n    for (const claimFeeTx of claimFeeTxs) {\n      const claimFeeTxHash = await sendAndConfirmTransaction(\n        connection,\n        claimFeeTx,\n        [user]\n      );\n    }\n  } catch (error) {}\n}\n```\n\n- Close Position\n\n```ts\nconst closePositionTx = await dlmmPool.closePosition({\n  owner: user.publicKey,\n  position: newBalancePosition.publicKey,\n});\n\ntry {\n  const closePositionTxHash = await sendAndConfirmTransaction(\n    connection,\n    closePositionTx,\n    [user],\n    { skipPreflight: false, preflightCommitment: \"singleGossip\" }\n  );\n} catch (error) {}\n```\n\n- Swap\n\n```ts\nconst swapAmount = new BN(0.1 * 10 ** 9);\n// Swap quote\nconst swapYtoX = true;\nconst binArrays = await dlmmPool.getBinArrayForSwap(swapYtoX);\n\nconst swapQuote = await dlmmPool.swapQuote(\n  swapAmount,\n  swapYtoX,\n  new BN(1),\n  binArrays\n);\n\n// Swap\nconst swapTx = await dlmmPool.swap({\n  inToken: dlmmPool.tokenX.publicKey,\n  binArraysPubkey: swapQuote.binArraysPubkey,\n  inAmount: swapAmount,\n  lbPair: dlmmPool.pubkey,\n  user: user.publicKey,\n  minOutAmount: swapQuote.minOutAmount,\n  outToken: dlmmPool.tokenY.publicKey,\n});\n\ntry {\n  const swapTxHash = await sendAndConfirmTransaction(connection, swapTx, [\n    user,\n  ]);\n} catch (error) {}\n```\n\n## Static functions\n\n| Function                      | Description                                                                        | Return                               |\n| ----------------------------- | ---------------------------------------------------------------------------------- | ------------------------------------ |\n| `create`                      | Given the DLMM address, create an instance to access the state and functions       | `Promise<DLMM>`                      |\n| `createMultiple`              | Given a list of DLMM addresses, create instances to access the state and functions | `Promise<Array<DLMM>>`               |\n| `getAllPresetParameters`      | Get all the preset params (use to create DLMM pool)                                | `Promise<PresetParams>`              |\n| `createPermissionLbPair`      | Create DLMM Pool                                                                   | `Promise<Transcation>`               |\n| `getClaimableLMReward`        | Get Claimable LM reward for a position                                             | `Promise<LMRewards>`                 |\n| `getClaimableSwapFee`         | Get Claimable Swap Fee for a position                                              | `Promise<SwapFee>`                   |\n| `getAllLbPairPositionsByUser` | Get user's all positions for all DLMM pools                                        | `Promise<Map<string, PositionInfo>>` |\n\n## DLMM instance functions\n\n| Function                                      | Description                                                                                                                   | Return                                                                                             |\n| --------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |\n| `refetchStates`                               | Update onchain state of DLMM instance. It's recommend to call this before interact with the program (Deposit/ Withdraw/ Swap) | `Promise<void>`                                                                                    |\n| `getBinArrays`                                | Retrieves List of Bin Arrays                                                                                                  | `Promise<BinArrayAccount[]>`                                                                       |\n| `getBinArrayForSwap`                          | Retrieves List of Bin Arrays for swap purpose                                                                                 | `Promise<BinArrayAccount[]>`                                                                       |\n| `getFeeInfo`                                  | Retrieves LbPair's fee info including `base fee`, `protocol fee` & `max fee`                                                  | `FeeInfo`                                                                                          |\n| `getDynamicFee`                               | Retrieves LbPair's dynamic fee                                                                                                | `Decimal`                                                                                          |\n| `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[] }>`                                             |\n| `getBinsBetweenMinAndMaxPrice`                | Retrieves a list of bins within a specified price                                                                             | `Promise<{ activeBin: number; bins: BinLiquidity[] }>`                                             |\n| `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[] }>`                                             |\n| `toPricePerLamport`                           | Converts a real price of bin to lamport price                                                                                 | `string`                                                                                           |\n| `fromPricePerLamport`                         | converts a price per lamport value to a real price of bin                                                                     | `string`                                                                                           |\n| `getActiveBin`                                | Retrieves the active bin ID and its corresponding price                                                                       | `Promise<{ binId: number; price: string }>`                                                        |\n| `getPriceOfBinByBinId`                        | Get the price of a bin based on its bin ID                                                                                    | `string`                                                                                           |\n| `getBinIdFromPrice`                           | get bin ID based on a given price and a boolean flag indicating whether to round down or up.                                  | `number`                                                                                           |\n| `getPositionsByUserAndLbPair`                 | Retrieves positions by user and LB pair, including active bin and user positions.                                             | `Promise<{ activeBin: { binId: any; price: string; }; userPositions: Array<Position>;}>`           |\n| `initializePositionAndAddLiquidityByStrategy` | Initializes a position and adds liquidity                                                                                     | `Promise<Transaction\\|Transaction[]>`                                                              |\n| `addLiquidityByStrategy`                      | Add liquidity to existing position                                                                                            | `Promise<Transaction\\|Transaction[]>`                                                              |\n| `removeLiquidity`                             | function is used to remove liquidity from a position, with the option to claim rewards and close the position.                | `Promise<Transaction\\|Transaction[]>`                                                              |\n| `closePosition`                               | Closes a position                                                                                                             | `Promise<Transaction\\|Transaction[]>`                                                              |\n| `swapQuote`                                   | Quote for a swap                                                                                                              | `SwapQuote`                                                                                        |\n| `swap`                                        | Swap token within the LbPair                                                                                                  | `Promise<Transaction>`                                                                             |\n| `claimLMReward`                               | Claim rewards for a specific position owned by a specific owner                                                               | `Promise<Transaction>`                                                                             |\n| `claimAllLMRewards`                           | Claim all liquidity mining rewards for a given owner and their positions.                                                     | `Promise<Transaction[]>`                                                                           |\n| `claimSwapFee`                                | Claim swap fees for a specific position owned by a specific owner                                                             | `Promise<Transaction>`                                                                             |\n| `claimAllSwapFee`                             | Claim swap fees for multiple positions owned by a specific owner                                                              | `Promise<Transaction>`                                                                             |\n| `claimAllRewards`                             | Claim swap fees and LM rewards for multiple positions owned by a specific owner                                               | `Promise<Transaction[]>`                                                                           |\n| `syncWithMarketPrice`                         | Sync the pool current active bin to match nearest market price bin                                                            | `Promise<Transaction>`                                                                             |\n| `getPairPubkeyIfExists`                       | Get existing pool address given parameter, if not return null                                                                 | `Promise<PublicKey                                                                       \\| null>` |\n| `getMaxPriceInBinArrays`                      | Get max price of the last bin that has liquidity given bin arrays                                                             | `Promise<string                                                                       \\| null>`    |\n","readmeFilename":"README.md","_rev":"1-b43328be1521b8efae588c9ee83d29df"}