@meteora-ag/dlmm 1.9.12 → 1.9.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -44,7 +44,7 @@ const dlmmPool = await DLMM.createMultiple(connection, [USDC_USDT_POOL, ...]);
44
44
  const activeBin = await dlmmPool.getActiveBin();
45
45
  const activeBinPriceLamport = activeBin.price;
46
46
  const activeBinPricePerToken = dlmmPool.fromPricePerLamport(
47
- Number(activeBin.price)
47
+ Number(activeBin.price),
48
48
  );
49
49
  ```
50
50
 
@@ -64,7 +64,7 @@ const totalYAmount = autoFillYByStrategy(
64
64
  activeBin.yAmount,
65
65
  minBinId,
66
66
  maxBinId,
67
- StrategyType.Spot // can be StrategyType.Spot, StrategyType.BidAsk, StrategyType.Curve
67
+ StrategyType.Spot, // can be StrategyType.Spot, StrategyType.BidAsk, StrategyType.Curve
68
68
  );
69
69
  const newBalancePosition = new Keypair();
70
70
 
@@ -86,7 +86,7 @@ try {
86
86
  const createBalancePositionTxHash = await sendAndConfirmTransaction(
87
87
  connection,
88
88
  createPositionTx,
89
- [user, newBalancePosition]
89
+ [user, newBalancePosition],
90
90
  );
91
91
  } catch (error) {}
92
92
  ```
@@ -120,7 +120,7 @@ try {
120
120
  const createBalancePositionTxHash = await sendAndConfirmTransaction(
121
121
  connection,
122
122
  createPositionTx,
123
- [user, newImbalancePosition]
123
+ [user, newImbalancePosition],
124
124
  );
125
125
  } catch (error) {}
126
126
  ```
@@ -154,7 +154,7 @@ try {
154
154
  const createOneSidePositionTxHash = await sendAndConfirmTransaction(
155
155
  connection,
156
156
  createPositionTx,
157
- [user, newOneSidePosition]
157
+ [user, newOneSidePosition],
158
158
  );
159
159
  } catch (error) {}
160
160
  ```
@@ -163,7 +163,7 @@ try {
163
163
 
164
164
  ```ts
165
165
  const { userPositions } = await dlmmPool.getPositionsByUserAndLbPair(
166
- user.publicKey
166
+ user.publicKey,
167
167
  );
168
168
  const binData = userPositions[0].positionData.positionBinData;
169
169
  ```
@@ -184,7 +184,7 @@ const totalYAmount = autoFillYByStrategy(
184
184
  activeBin.yAmount,
185
185
  minBinId,
186
186
  maxBinId,
187
- StrategyType.Spot // can be StrategyType.Spot, StrategyType.BidAsk, StrategyType.Curve
187
+ StrategyType.Spot, // can be StrategyType.Spot, StrategyType.BidAsk, StrategyType.Curve
188
188
  );
189
189
 
190
190
  // Add Liquidity to existing position
@@ -204,7 +204,7 @@ try {
204
204
  const addLiquidityTxHash = await sendAndConfirmTransaction(
205
205
  connection,
206
206
  addLiquidityTx,
207
- [user]
207
+ [user],
208
208
  );
209
209
  } catch (error) {}
210
210
  ```
@@ -213,11 +213,11 @@ try {
213
213
 
214
214
  ```ts
215
215
  const userPosition = userPositions.find(({ publicKey }) =>
216
- publicKey.equals(newBalancePosition.publicKey)
216
+ publicKey.equals(newBalancePosition.publicKey),
217
217
  );
218
218
  // Remove Liquidity
219
219
  const binIdsToRemove = userPosition.positionData.positionBinData.map(
220
- (bin) => bin.binId
220
+ (bin) => bin.binId,
221
221
  );
222
222
  const removeLiquidityTx = await dlmmPool.removeLiquidity({
223
223
  position: userPosition.publicKey,
@@ -225,7 +225,7 @@ const removeLiquidityTx = await dlmmPool.removeLiquidity({
225
225
  fromBinId: binIdsToRemove[0],
226
226
  toBinId: binIdsToRemove[binIdsToRemove.length - 1],
227
227
  liquiditiesBpsToRemove: new Array(binIdsToRemove.length).fill(
228
- new BN(100 * 100)
228
+ new BN(100 * 100),
229
229
  ), // 100% (range from 0 to 100)
230
230
  shouldClaimAndClose: true, // should claim swap fee and close position together
231
231
  });
@@ -238,7 +238,7 @@ try {
238
238
  connection,
239
239
  tx,
240
240
  [user],
241
- { skipPreflight: false, preflightCommitment: "singleGossip" }
241
+ { skipPreflight: false, preflightCommitment: "singleGossip" },
242
242
  );
243
243
  }
244
244
  } catch (error) {}
@@ -258,7 +258,7 @@ async function claimFee(dlmmPool: DLMM) {
258
258
  const claimFeeTxHash = await sendAndConfirmTransaction(
259
259
  connection,
260
260
  claimFeeTx,
261
- [user]
261
+ [user],
262
262
  );
263
263
  }
264
264
  } catch (error) {}
@@ -278,7 +278,7 @@ try {
278
278
  connection,
279
279
  closePositionTx,
280
280
  [user],
281
- { skipPreflight: false, preflightCommitment: "singleGossip" }
281
+ { skipPreflight: false, preflightCommitment: "singleGossip" },
282
282
  );
283
283
  } catch (error) {}
284
284
  ```
@@ -295,7 +295,7 @@ const swapQuote = await dlmmPool.swapQuote(
295
295
  swapAmount,
296
296
  swapYtoX,
297
297
  new BN(1),
298
- binArrays
298
+ binArrays,
299
299
  );
300
300
 
301
301
  // Swap
@@ -318,15 +318,17 @@ try {
318
318
 
319
319
  ## Static functions
320
320
 
321
- | Function | Description | Return |
322
- | ----------------------------- | ---------------------------------------------------------------------------------- | ------------------------------------ |
323
- | `create` | Given the DLMM address, create an instance to access the state and functions | `Promise<DLMM>` |
324
- | `createMultiple` | Given a list of DLMM addresses, create instances to access the state and functions | `Promise<Array<DLMM>>` |
325
- | `getAllPresetParameters` | Get all the preset params (use to create DLMM pool) | `Promise<PresetParams>` |
326
- | `createPermissionLbPair` | Create DLMM Pool | `Promise<Transcation>` |
327
- | `getClaimableLMReward` | Get Claimable LM reward for a position | `Promise<LMRewards>` |
328
- | `getClaimableSwapFee` | Get Claimable Swap Fee for a position | `Promise<SwapFee>` |
329
- | `getAllLbPairPositionsByUser` | Get user's all positions for all DLMM pools | `Promise<Map<string, PositionInfo>>` |
321
+ | Function | Description | Return |
322
+ | ----------------------------------- | ---------------------------------------------------------------------------------- | ------------------------------------ |
323
+ | `create` | Given the DLMM address, create an instance to access the state and functions | `Promise<DLMM>` |
324
+ | `createMultiple` | Given a list of DLMM addresses, create instances to access the state and functions | `Promise<Array<DLMM>>` |
325
+ | `getAllPresetParameters` | Get all the preset params (use to create DLMM pool) | `Promise<PresetParams>` |
326
+ | `createPermissionLbPair` | Create DLMM Pool | `Promise<Transcation>` |
327
+ | `getClaimableLMReward` | Get Claimable LM reward for a position | `Promise<LMRewards>` |
328
+ | `getClaimableSwapFee` | Get Claimable Swap Fee for a position | `Promise<SwapFee>` |
329
+ | `getAllLbPairPositionsByUser` | Get user's all positions for all DLMM pools | `Promise<Map<string, PositionInfo>>` |
330
+ | `getPositionsByUserAndTokenAddress` | Get user's positions across all DLMM pools that contain a given token mint | `Promise<Map<string, PositionInfo>>` |
331
+ | `getLimitOrdersByUserAndTokenAddress` | Get user's limit orders across all DLMM pools that contain a given token mint, grouped by LB pair | `Promise<Map<string, LimitOrderInfo>>` |
330
332
 
331
333
  ## DLMM instance functions
332
334
 
package/dist/index.d.ts CHANGED
@@ -12303,6 +12303,13 @@ interface PositionInfo {
12303
12303
  tokenY: TokenReserve;
12304
12304
  lbPairPositionsData: Array<LbPosition>;
12305
12305
  }
12306
+ interface LimitOrderInfo {
12307
+ publicKey: PublicKey;
12308
+ lbPair: LbPair;
12309
+ tokenX: TokenReserve;
12310
+ tokenY: TokenReserve;
12311
+ limitOrders: Array<ParsedLimitOrderWithPubkey>;
12312
+ }
12306
12313
  interface FeeInfo {
12307
12314
  baseFeeRatePercentage: Decimal;
12308
12315
  maxFeeRatePercentage: Decimal;
@@ -13564,6 +13571,36 @@ declare class DLMM {
13564
13571
  * Pair account, and the value is an object of PositionInfo
13565
13572
  */
13566
13573
  static getAllLbPairPositionsByUser(connection: Connection, userPubKey: PublicKey, opt?: Opt, getPositionsOpt?: GetPositionsOpt): Promise<Map<string, PositionInfo>>;
13574
+ /**
13575
+ * The function `getPositionsByUserAndTokenAddress` retrieves all of a user's positions across every
13576
+ * DLMM pool that includes the given token mint as either the X or Y token.
13577
+ * @param {Connection} connection - The `connection` parameter is an instance of the `Connection`
13578
+ * class, which represents the connection to the Solana blockchain.
13579
+ * @param {PublicKey} userPubKey - The user's wallet public key.
13580
+ * @param {PublicKey} tokenMint - The token mint used to filter pools. Only positions in pools whose
13581
+ * `tokenXMint` or `tokenYMint` matches this mint are returned.
13582
+ * @param {Opt} [opt] - An optional object that contains additional options for the function.
13583
+ * @param {GetPositionsOpt} [getPositionsOpt] - Optional settings for chunked position fetching
13584
+ * @returns The function `getPositionsByUserAndTokenAddress` returns a `Promise` that resolves to a
13585
+ * `Map` object. The `Map` object contains key-value pairs, where the key is a string representing the
13586
+ * LB Pair account, and the value is an object of PositionInfo. Only pools containing `tokenMint` are
13587
+ * included.
13588
+ */
13589
+ static getPositionsByUserAndTokenAddress(connection: Connection, userPubKey: PublicKey, tokenMint: PublicKey, opt?: Opt, getPositionsOpt?: GetPositionsOpt): Promise<Map<string, PositionInfo>>;
13590
+ /**
13591
+ * The function `getLimitOrdersByUserAndTokenAddress` retrieves all of a user's limit orders across
13592
+ * every DLMM pool that includes the given token mint as either the X or Y token.
13593
+ * @param {Connection} connection - The `connection` parameter is an instance of the `Connection`
13594
+ * class, which represents the connection to the Solana blockchain.
13595
+ * @param {PublicKey} userPubKey - The user's wallet public key.
13596
+ * @param {PublicKey} tokenMint - The token mint used to filter pools. Only limit orders in pools
13597
+ * whose `tokenXMint` or `tokenYMint` matches this mint are returned.
13598
+ * @param {Opt} [opt] - An optional object that contains additional options for the function.
13599
+ * @returns The function `getLimitOrdersByUserAndTokenAddress` returns a `Promise` that resolves to a
13600
+ * `Map` object keyed by LB Pair account (base58), where each value is a `LimitOrderInfo` containing
13601
+ * the LB pair state, token reserves, and the parsed limit orders for that pool.
13602
+ */
13603
+ static getLimitOrdersByUserAndTokenAddress(connection: Connection, userPubKey: PublicKey, tokenMint: PublicKey, opt?: Opt): Promise<Map<string, LimitOrderInfo>>;
13567
13604
  static getPricePerLamport(tokenXDecimal: number, tokenYDecimal: number, price: number): string;
13568
13605
  static getBinIdFromPrice(price: string | number | Decimal, binStep: number, min: boolean): number;
13569
13606
  /**
@@ -26426,4 +26463,4 @@ declare const limitOrderFilter: () => GetProgramAccountsFilter;
26426
26463
  declare const limitOrderOwnerFilter: (owner: PublicKey) => GetProgramAccountsFilter;
26427
26464
  declare const limitOrderLbPairFilter: (lbPair: PublicKey) => GetProgramAccountsFilter;
26428
26465
 
26429
- export { ADMIN, ALT_ADDRESS, AccountName, ActionType, ActivationType, AmountIntoBin, BASIS_POINT_MAX, BIN_ARRAY_BITMAP_FEE, BIN_ARRAY_BITMAP_FEE_BN, BIN_ARRAY_BITMAP_SIZE, BIN_ARRAY_DEFAULT_VERSION, BIN_ARRAY_FEE, BIN_ARRAY_FEE_BN, BidAskParameters, Bin, BinAndAmount, BinArray, BinArrayAccount, BinArrayBitmapExtension, BinArrayBitmapExtensionAccount, BinLiquidity, BinLiquidityDistribution, BinLiquidityReduction, BitmapType, ChunkCallback, ChunkCallbackInfo, ClmmProgram, Clock, ClockLayout, CollectFeeMode, CompressedBinDepositAmount, CompressedBinDepositAmounts, ConcreteFunctionType, CreateRebalancePositionParams, DEFAULT_BIN_PER_POSITION, DLMMError, DlmmSdkError, DynamicOracle, EXTENSION_BINARRAY_BITMAP_SIZE, EmissionRate, ExtendedPositionBinData, FEE_PRECISION, FeeInfo, FeeMode, FunctionType, GetOrCreateATAResponse, GetPositionsOpt, IAccountsCache, IDL, IDynamicOracle, ILM_BASE, IPosition, InitCustomizablePermissionlessPairIx, InitPermissionPairIx, InitializeMultiplePositionAndAddLiquidityByStrategyResponse, InitializeMultiplePositionAndAddLiquidityByStrategyResponse2, LBCLMM_PROGRAM_IDS, LIMIT_ORDER_BIN_DATA_SIZE, LIMIT_ORDER_FEE_SHARE, LIMIT_ORDER_MIN_SIZE, LMRewards, LbClmm, LbPair, LbPairAccount, LbPosition, LimitOrder, LimitOrderBinData, LimitOrderStatus, LiquidityOneSideParameter, LiquidityParameter, LiquidityParameterByStrategy, LiquidityParameterByStrategyOneSide, LiquidityParameterByWeight, LiquidityStrategyParameterBuilder, LiquidityStrategyParameters, MAX_ACTIVE_BIN_SLIPPAGE, MAX_BINS_PER_POSITION, MAX_BIN_ARRAY_SIZE, MAX_BIN_ID_PER_BIN_STEP, MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX, MAX_BIN_PER_LIMIT_ORDER, MAX_CLAIM_ALL_ALLOWED, MAX_EXTRA_BIN_ARRAYS, MAX_FEE_RATE, MAX_RESIZE_LENGTH, MEMO_PROGRAM_ID, Network, Observation, Opt, Oracle, POOL_FEE, POOL_FEE_BN, POSITION_BIN_DATA_SIZE, POSITION_FEE, POSITION_FEE_BN, POSITION_MAX_LENGTH, POSITION_MIN_SIZE, PRECISION, PairLockInfo, PairStatus, PairType, ParsedLimitOrderWithPubkey, PlaceLimitOrderParams, PositionBinData, PositionData, PositionInfo, PositionLockInfo, PositionPermission, PositionV2, PositionV2Wrapper, PositionVersion, PresetParameter, PresetParameter2, ProgramStrategyParameter, ProgramStrategyType, REBALANCE_POSITION_PADDING, RebalanceAddLiquidityParam, RebalancePosition, RebalancePositionBinArrayRentalCostQuote, RebalancePositionResponse, RebalanceRemoveLiquidityParam, RebalanceWithDeposit, RebalanceWithWithdraw, RemainingAccountInfo, RemainingAccountsInfoSlice, ResizeSide, ResizeSideEnum, RewardInfo, RewardInfos, Rounding, SCALE, SCALE_OFFSET, SIMULATION_USER, SeedLiquidityCostBreakdown, SeedLiquidityResponse, SeedLiquiditySingleBinResponse, ShrinkMode, SimulateRebalanceResp, Strategy, StrategyParameters, StrategyType, SwapExactOutParams, SwapFee, SwapParams, SwapQuote, SwapQuoteExactOut, SwapWithPriceImpactParams, TInitializeMultiplePositionAndAddLiquidityParamsByStrategy, TInitializePositionAndAddLiquidityParams, TInitializePositionAndAddLiquidityParamsByStrategy, TOKEN_ACCOUNT_FEE, TOKEN_ACCOUNT_FEE_BN, TQuoteCreatePositionParams, TokenReserve, TwapResult, U64_MAX, UserFeeInfo, UserRewardInfo, autoFillXByStrategy, autoFillXByWeight, autoFillYByStrategy, autoFillYByWeight, binArrayLbPairFilter, binDeltaToMinMaxBinId, binIdToBinArrayIndex, buildBitFlagAndNegateStrategyParameters, buildLiquidityStrategyParameters, calculateBidAskDistribution, calculateNormalDistribution, calculatePositionSize, calculateSpotDistribution, calculateTransferFeeExcludedAmount, calculateTransferFeeIncludedAmount, capSlippagePercentage, chunkBinRange, chunkBinRangeIntoExtendedPositions, chunkDepositWithRebalanceEndpoint, chunkPositionBinRange, chunkedFetchMultipleBinArrayBitmapExtensionAccount, chunkedFetchMultiplePoolAccount, chunkedGetMultipleAccountInfos, chunkedGetProgramAccounts, chunks, compressBinAmount, computeBaseFactorFromFeeBps, computeFee, computeFeeFromAmount, computeProtocolFee, createProgram, decodeAccount, decodeExtendedPosition, decodeRewardPerTokenStored, DLMM as default, deriveBinArray, deriveBinArrayBitmapExtension, deriveCustomizablePermissionlessLbPair, deriveEventAuthority, deriveLbPair, deriveLbPair2, deriveLbPairWithPresetParamWithIndexKey, deriveOperator, deriveOracle, derivePermissionLbPair, derivePlaceHolderAccountMeta, derivePosition, derivePresetParameter, derivePresetParameter2, derivePresetParameterWithIndex, deriveReserve, deriveRewardVault, deriveTokenBadge, distributeAmountToCompressedBinsByRatio, encodePositionPermissions, enumerateBins, findNextBinArrayIndexWithLiquidity, findNextBinArrayWithLiquidity, findOptimumDecompressMultiplier, fromWeightDistributionToAmount, fromWeightDistributionToAmountOneSide, generateAmountForBinRange, generateBinAmount, getAccountDiscriminator, getAmountIn, getAmountInBinsAskSide, getAmountInBinsBidSide, getAmountOut, getAndCapMaxActiveBinSlippage, getAutoFillAmountByRebalancedPosition, getBaseFee, getBinArrayAccountMetasCoverage, getBinArrayIndexesCoverage, getBinArrayInfoForNonContiguousBinIds, getBinArrayKeysCoverage, getBinArrayLowerUpperBinId, getBinArraysRequiredByPositionRange, getBinCount, getBinFromBinArray, getBinIdIndexInBinArray, getBinMaxAmountOut, getC, getEstimatedComputeUnitIxWithBuffer, getEstimatedComputeUnitUsageWithBuffer, getExcludedFeeAmount, getExtendedPositionBinCount, getExtraAccountMetasForTransferHook, getFeeMode, getIncludedFeeAmount, getLimitOrderLiquidity, getLiquidityStrategyParameterBuilder, getMultipleMintsExtraAccountMetasForTransferHook, getOrCreateATAInstruction, getPositionCount, getPositionCountByBinCount, getPositionExpandRentExemption, getPositionLowerUpperBinIdWithLiquidity, getPositionRentExemption, getPriceOfBinByBinId, getQPriceBaseFactor, getQPriceFromId, getRebalanceBinArrayIndexesAndBitmapCoverage, getSlippageMaxAmount, getSlippageMinAmount, getTokenBalance, getTokenDecimals, getTokenProgramId, getTokensMintFromPoolAddress, getTotalFee, getVariableFee, isBinIdWithinBinArray, isOverflowDefaultBinArrayBitmap, isPositionNoFee, isPositionNoReward, isSupportLimitOrder, limitOrderFilter, limitOrderLbPairFilter, limitOrderOwnerFilter, mulDiv, mulShr, parseLogs, positionLbPairFilter, positionOwnerFilter, positionV2Filter, presetParameter2BaseFactorFilter, presetParameter2BaseFeePowerFactor, presetParameter2BinStepFilter, range, resetUninvolvedLiquidityParams, sParameters, shlDiv, splitFee, suggestBalancedXParametersFromY, suggestBalancedYParametersFromX, swapExactInQuoteAtBin, swapExactOutQuoteAtBin, toAmountAskSide, toAmountBidSide, toAmountBothSide, toAmountIntoBins, toAmountsBothSideByStrategy, toStrategyParameters, toWeightDistribution, unwrapSOLInstruction, vParameters, wrapOracle, wrapPosition, wrapSOLInstruction };
26466
+ export { ADMIN, ALT_ADDRESS, AccountName, ActionType, ActivationType, AmountIntoBin, BASIS_POINT_MAX, BIN_ARRAY_BITMAP_FEE, BIN_ARRAY_BITMAP_FEE_BN, BIN_ARRAY_BITMAP_SIZE, BIN_ARRAY_DEFAULT_VERSION, BIN_ARRAY_FEE, BIN_ARRAY_FEE_BN, BidAskParameters, Bin, BinAndAmount, BinArray, BinArrayAccount, BinArrayBitmapExtension, BinArrayBitmapExtensionAccount, BinLiquidity, BinLiquidityDistribution, BinLiquidityReduction, BitmapType, ChunkCallback, ChunkCallbackInfo, ClmmProgram, Clock, ClockLayout, CollectFeeMode, CompressedBinDepositAmount, CompressedBinDepositAmounts, ConcreteFunctionType, CreateRebalancePositionParams, DEFAULT_BIN_PER_POSITION, DLMMError, DlmmSdkError, DynamicOracle, EXTENSION_BINARRAY_BITMAP_SIZE, EmissionRate, ExtendedPositionBinData, FEE_PRECISION, FeeInfo, FeeMode, FunctionType, GetOrCreateATAResponse, GetPositionsOpt, IAccountsCache, IDL, IDynamicOracle, ILM_BASE, IPosition, InitCustomizablePermissionlessPairIx, InitPermissionPairIx, InitializeMultiplePositionAndAddLiquidityByStrategyResponse, InitializeMultiplePositionAndAddLiquidityByStrategyResponse2, LBCLMM_PROGRAM_IDS, LIMIT_ORDER_BIN_DATA_SIZE, LIMIT_ORDER_FEE_SHARE, LIMIT_ORDER_MIN_SIZE, LMRewards, LbClmm, LbPair, LbPairAccount, LbPosition, LimitOrder, LimitOrderBinData, LimitOrderInfo, LimitOrderStatus, LiquidityOneSideParameter, LiquidityParameter, LiquidityParameterByStrategy, LiquidityParameterByStrategyOneSide, LiquidityParameterByWeight, LiquidityStrategyParameterBuilder, LiquidityStrategyParameters, MAX_ACTIVE_BIN_SLIPPAGE, MAX_BINS_PER_POSITION, MAX_BIN_ARRAY_SIZE, MAX_BIN_ID_PER_BIN_STEP, MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX, MAX_BIN_PER_LIMIT_ORDER, MAX_CLAIM_ALL_ALLOWED, MAX_EXTRA_BIN_ARRAYS, MAX_FEE_RATE, MAX_RESIZE_LENGTH, MEMO_PROGRAM_ID, Network, Observation, Opt, Oracle, POOL_FEE, POOL_FEE_BN, POSITION_BIN_DATA_SIZE, POSITION_FEE, POSITION_FEE_BN, POSITION_MAX_LENGTH, POSITION_MIN_SIZE, PRECISION, PairLockInfo, PairStatus, PairType, ParsedLimitOrderWithPubkey, PlaceLimitOrderParams, PositionBinData, PositionData, PositionInfo, PositionLockInfo, PositionPermission, PositionV2, PositionV2Wrapper, PositionVersion, PresetParameter, PresetParameter2, ProgramStrategyParameter, ProgramStrategyType, REBALANCE_POSITION_PADDING, RebalanceAddLiquidityParam, RebalancePosition, RebalancePositionBinArrayRentalCostQuote, RebalancePositionResponse, RebalanceRemoveLiquidityParam, RebalanceWithDeposit, RebalanceWithWithdraw, RemainingAccountInfo, RemainingAccountsInfoSlice, ResizeSide, ResizeSideEnum, RewardInfo, RewardInfos, Rounding, SCALE, SCALE_OFFSET, SIMULATION_USER, SeedLiquidityCostBreakdown, SeedLiquidityResponse, SeedLiquiditySingleBinResponse, ShrinkMode, SimulateRebalanceResp, Strategy, StrategyParameters, StrategyType, SwapExactOutParams, SwapFee, SwapParams, SwapQuote, SwapQuoteExactOut, SwapWithPriceImpactParams, TInitializeMultiplePositionAndAddLiquidityParamsByStrategy, TInitializePositionAndAddLiquidityParams, TInitializePositionAndAddLiquidityParamsByStrategy, TOKEN_ACCOUNT_FEE, TOKEN_ACCOUNT_FEE_BN, TQuoteCreatePositionParams, TokenReserve, TwapResult, U64_MAX, UserFeeInfo, UserRewardInfo, autoFillXByStrategy, autoFillXByWeight, autoFillYByStrategy, autoFillYByWeight, binArrayLbPairFilter, binDeltaToMinMaxBinId, binIdToBinArrayIndex, buildBitFlagAndNegateStrategyParameters, buildLiquidityStrategyParameters, calculateBidAskDistribution, calculateNormalDistribution, calculatePositionSize, calculateSpotDistribution, calculateTransferFeeExcludedAmount, calculateTransferFeeIncludedAmount, capSlippagePercentage, chunkBinRange, chunkBinRangeIntoExtendedPositions, chunkDepositWithRebalanceEndpoint, chunkPositionBinRange, chunkedFetchMultipleBinArrayBitmapExtensionAccount, chunkedFetchMultiplePoolAccount, chunkedGetMultipleAccountInfos, chunkedGetProgramAccounts, chunks, compressBinAmount, computeBaseFactorFromFeeBps, computeFee, computeFeeFromAmount, computeProtocolFee, createProgram, decodeAccount, decodeExtendedPosition, decodeRewardPerTokenStored, DLMM as default, deriveBinArray, deriveBinArrayBitmapExtension, deriveCustomizablePermissionlessLbPair, deriveEventAuthority, deriveLbPair, deriveLbPair2, deriveLbPairWithPresetParamWithIndexKey, deriveOperator, deriveOracle, derivePermissionLbPair, derivePlaceHolderAccountMeta, derivePosition, derivePresetParameter, derivePresetParameter2, derivePresetParameterWithIndex, deriveReserve, deriveRewardVault, deriveTokenBadge, distributeAmountToCompressedBinsByRatio, encodePositionPermissions, enumerateBins, findNextBinArrayIndexWithLiquidity, findNextBinArrayWithLiquidity, findOptimumDecompressMultiplier, fromWeightDistributionToAmount, fromWeightDistributionToAmountOneSide, generateAmountForBinRange, generateBinAmount, getAccountDiscriminator, getAmountIn, getAmountInBinsAskSide, getAmountInBinsBidSide, getAmountOut, getAndCapMaxActiveBinSlippage, getAutoFillAmountByRebalancedPosition, getBaseFee, getBinArrayAccountMetasCoverage, getBinArrayIndexesCoverage, getBinArrayInfoForNonContiguousBinIds, getBinArrayKeysCoverage, getBinArrayLowerUpperBinId, getBinArraysRequiredByPositionRange, getBinCount, getBinFromBinArray, getBinIdIndexInBinArray, getBinMaxAmountOut, getC, getEstimatedComputeUnitIxWithBuffer, getEstimatedComputeUnitUsageWithBuffer, getExcludedFeeAmount, getExtendedPositionBinCount, getExtraAccountMetasForTransferHook, getFeeMode, getIncludedFeeAmount, getLimitOrderLiquidity, getLiquidityStrategyParameterBuilder, getMultipleMintsExtraAccountMetasForTransferHook, getOrCreateATAInstruction, getPositionCount, getPositionCountByBinCount, getPositionExpandRentExemption, getPositionLowerUpperBinIdWithLiquidity, getPositionRentExemption, getPriceOfBinByBinId, getQPriceBaseFactor, getQPriceFromId, getRebalanceBinArrayIndexesAndBitmapCoverage, getSlippageMaxAmount, getSlippageMinAmount, getTokenBalance, getTokenDecimals, getTokenProgramId, getTokensMintFromPoolAddress, getTotalFee, getVariableFee, isBinIdWithinBinArray, isOverflowDefaultBinArrayBitmap, isPositionNoFee, isPositionNoReward, isSupportLimitOrder, limitOrderFilter, limitOrderLbPairFilter, limitOrderOwnerFilter, mulDiv, mulShr, parseLogs, positionLbPairFilter, positionOwnerFilter, positionV2Filter, presetParameter2BaseFactorFilter, presetParameter2BaseFeePowerFactor, presetParameter2BinStepFilter, range, resetUninvolvedLiquidityParams, sParameters, shlDiv, splitFee, suggestBalancedXParametersFromY, suggestBalancedYParametersFromX, swapExactInQuoteAtBin, swapExactOutQuoteAtBin, toAmountAskSide, toAmountBidSide, toAmountBothSide, toAmountIntoBins, toAmountsBothSideByStrategy, toStrategyParameters, toWeightDistribution, unwrapSOLInstruction, vParameters, wrapOracle, wrapPosition, wrapSOLInstruction };
package/dist/index.js CHANGED
@@ -16748,6 +16748,242 @@ var DLMM = class {
16748
16748
  }
16749
16749
  return positionsMap;
16750
16750
  }
16751
+ /**
16752
+ * The function `getPositionsByUserAndTokenAddress` retrieves all of a user's positions across every
16753
+ * DLMM pool that includes the given token mint as either the X or Y token.
16754
+ * @param {Connection} connection - The `connection` parameter is an instance of the `Connection`
16755
+ * class, which represents the connection to the Solana blockchain.
16756
+ * @param {PublicKey} userPubKey - The user's wallet public key.
16757
+ * @param {PublicKey} tokenMint - The token mint used to filter pools. Only positions in pools whose
16758
+ * `tokenXMint` or `tokenYMint` matches this mint are returned.
16759
+ * @param {Opt} [opt] - An optional object that contains additional options for the function.
16760
+ * @param {GetPositionsOpt} [getPositionsOpt] - Optional settings for chunked position fetching
16761
+ * @returns The function `getPositionsByUserAndTokenAddress` returns a `Promise` that resolves to a
16762
+ * `Map` object. The `Map` object contains key-value pairs, where the key is a string representing the
16763
+ * LB Pair account, and the value is an object of PositionInfo. Only pools containing `tokenMint` are
16764
+ * included.
16765
+ */
16766
+ static async getPositionsByUserAndTokenAddress(connection, userPubKey, tokenMint, opt, getPositionsOpt) {
16767
+ const allPositions = await DLMM.getAllLbPairPositionsByUser(
16768
+ connection,
16769
+ userPubKey,
16770
+ opt,
16771
+ getPositionsOpt
16772
+ );
16773
+ const targetMint = tokenMint.toBase58();
16774
+ const filteredPositions = /* @__PURE__ */ new Map();
16775
+ for (const [lbPairKey, positionInfo] of allPositions) {
16776
+ const tokenXMint = positionInfo.lbPair.tokenXMint.toBase58();
16777
+ const tokenYMint = positionInfo.lbPair.tokenYMint.toBase58();
16778
+ if (tokenXMint === targetMint || tokenYMint === targetMint) {
16779
+ filteredPositions.set(lbPairKey, positionInfo);
16780
+ }
16781
+ }
16782
+ return filteredPositions;
16783
+ }
16784
+ /**
16785
+ * The function `getLimitOrdersByUserAndTokenAddress` retrieves all of a user's limit orders across
16786
+ * every DLMM pool that includes the given token mint as either the X or Y token.
16787
+ * @param {Connection} connection - The `connection` parameter is an instance of the `Connection`
16788
+ * class, which represents the connection to the Solana blockchain.
16789
+ * @param {PublicKey} userPubKey - The user's wallet public key.
16790
+ * @param {PublicKey} tokenMint - The token mint used to filter pools. Only limit orders in pools
16791
+ * whose `tokenXMint` or `tokenYMint` matches this mint are returned.
16792
+ * @param {Opt} [opt] - An optional object that contains additional options for the function.
16793
+ * @returns The function `getLimitOrdersByUserAndTokenAddress` returns a `Promise` that resolves to a
16794
+ * `Map` object keyed by LB Pair account (base58), where each value is a `LimitOrderInfo` containing
16795
+ * the LB pair state, token reserves, and the parsed limit orders for that pool.
16796
+ */
16797
+ static async getLimitOrdersByUserAndTokenAddress(connection, userPubKey, tokenMint, opt) {
16798
+ const program = createProgram(connection, opt);
16799
+ const limitOrderAccounts = await chunkedGetProgramAccounts(
16800
+ program.provider.connection,
16801
+ program.programId,
16802
+ [limitOrderFilter(), limitOrderOwnerFilter(userPubKey)]
16803
+ );
16804
+ const limitOrderWrappers = limitOrderAccounts.map(
16805
+ ({ pubkey, account }) => wrapLimitOrder(program, pubkey, account)
16806
+ );
16807
+ if (limitOrderWrappers.length === 0) {
16808
+ return /* @__PURE__ */ new Map();
16809
+ }
16810
+ const lbPairKeys = Array.from(
16811
+ new Set(limitOrderWrappers.map((lo) => lo.lbPair().toBase58()))
16812
+ ).map((key) => new (0, _web3js.PublicKey)(key));
16813
+ const lbPairAccInfos = await chunkedGetMultipleAccountInfos(
16814
+ connection,
16815
+ lbPairKeys
16816
+ );
16817
+ const lbPairMap = /* @__PURE__ */ new Map();
16818
+ lbPairKeys.forEach((lbPairPubkey, i) => {
16819
+ const accInfo = lbPairAccInfos[i];
16820
+ if (!accInfo) {
16821
+ throw new Error(`LB Pair account ${lbPairPubkey.toBase58()} not found`);
16822
+ }
16823
+ lbPairMap.set(
16824
+ lbPairPubkey.toBase58(),
16825
+ decodeAccount(program, "lbPair", accInfo.data)
16826
+ );
16827
+ });
16828
+ const targetMint = tokenMint.toBase58();
16829
+ const matchingLbPairKeys = lbPairKeys.filter((lbPairPubkey) => {
16830
+ const lbPairState = lbPairMap.get(lbPairPubkey.toBase58());
16831
+ return lbPairState.tokenXMint.toBase58() === targetMint || lbPairState.tokenYMint.toBase58() === targetMint;
16832
+ });
16833
+ if (matchingLbPairKeys.length === 0) {
16834
+ return /* @__PURE__ */ new Map();
16835
+ }
16836
+ const matchingLbPairSet = new Set(
16837
+ matchingLbPairKeys.map((key) => key.toBase58())
16838
+ );
16839
+ const matchingLimitOrders = limitOrderWrappers.filter(
16840
+ (lo) => matchingLbPairSet.has(lo.lbPair().toBase58())
16841
+ );
16842
+ const reserveAndMintKeys = matchingLbPairKeys.map((lbPairPubkey) => {
16843
+ const { reserveX, reserveY, tokenXMint, tokenYMint } = lbPairMap.get(
16844
+ lbPairPubkey.toBase58()
16845
+ );
16846
+ return [reserveX, reserveY, tokenXMint, tokenYMint];
16847
+ }).flat();
16848
+ const binArrayPubkeySet = /* @__PURE__ */ new Set();
16849
+ matchingLimitOrders.forEach((lo) => {
16850
+ lo.getBinArrayKeysCoverage(program.programId).forEach((key) => {
16851
+ binArrayPubkeySet.add(key.toBase58());
16852
+ });
16853
+ });
16854
+ const binArrayKeys = Array.from(binArrayPubkeySet).map(
16855
+ (key) => new (0, _web3js.PublicKey)(key)
16856
+ );
16857
+ const [clockAccInfo, ...rest] = await chunkedGetMultipleAccountInfos(
16858
+ connection,
16859
+ [_web3js.SYSVAR_CLOCK_PUBKEY, ...binArrayKeys, ...reserveAndMintKeys]
16860
+ );
16861
+ const binArraysAccInfo = rest.slice(0, binArrayKeys.length);
16862
+ const reserveAndMintAccInfo = rest.slice(binArrayKeys.length);
16863
+ const clock = ClockLayout.decode(clockAccInfo.data);
16864
+ const binArrayMap = /* @__PURE__ */ new Map();
16865
+ binArrayKeys.forEach((binArrayPubkey, i) => {
16866
+ const accInfo = binArraysAccInfo[i];
16867
+ if (accInfo) {
16868
+ binArrayMap.set(
16869
+ binArrayPubkey.toBase58(),
16870
+ decodeAccount(program, "binArray", accInfo.data)
16871
+ );
16872
+ }
16873
+ });
16874
+ const seenMints = /* @__PURE__ */ new Set();
16875
+ const mintsWithAccount = matchingLbPairKeys.flatMap((lbPairPubkey, idx) => {
16876
+ const { tokenXMint, tokenYMint } = lbPairMap.get(
16877
+ lbPairPubkey.toBase58()
16878
+ );
16879
+ const index = idx * 4;
16880
+ return [
16881
+ {
16882
+ mintAddress: tokenXMint,
16883
+ mintAccountInfo: reserveAndMintAccInfo[index + 2]
16884
+ },
16885
+ {
16886
+ mintAddress: tokenYMint,
16887
+ mintAccountInfo: reserveAndMintAccInfo[index + 3]
16888
+ }
16889
+ ];
16890
+ }).filter(({ mintAddress, mintAccountInfo }) => {
16891
+ if (!mintAccountInfo || seenMints.has(mintAddress.toBase58())) {
16892
+ return false;
16893
+ }
16894
+ seenMints.add(mintAddress.toBase58());
16895
+ return true;
16896
+ });
16897
+ const mintHookAccountsMap = await getMultipleMintsExtraAccountMetasForTransferHook(
16898
+ connection,
16899
+ mintsWithAccount
16900
+ );
16901
+ const lbPairTokenMap = /* @__PURE__ */ new Map();
16902
+ matchingLbPairKeys.forEach((lbPairPubkey, idx) => {
16903
+ const index = idx * 4;
16904
+ const reserveXAccount = reserveAndMintAccInfo[index];
16905
+ const reserveYAccount = reserveAndMintAccInfo[index + 1];
16906
+ const mintXAccount = reserveAndMintAccInfo[index + 2];
16907
+ const mintYAccount = reserveAndMintAccInfo[index + 3];
16908
+ if (!reserveXAccount || !reserveYAccount) {
16909
+ throw new Error(
16910
+ `Reserve account for LB Pair ${lbPairPubkey.toBase58()} not found`
16911
+ );
16912
+ }
16913
+ if (!mintXAccount || !mintYAccount) {
16914
+ throw new Error(
16915
+ `Mint account for LB Pair ${lbPairPubkey.toBase58()} not found`
16916
+ );
16917
+ }
16918
+ const lbPairState = lbPairMap.get(lbPairPubkey.toBase58());
16919
+ const reserveAccX = _spltoken.AccountLayout.decode(reserveXAccount.data);
16920
+ const reserveAccY = _spltoken.AccountLayout.decode(reserveYAccount.data);
16921
+ const mintX = _spltoken.unpackMint.call(void 0,
16922
+ reserveAccX.mint,
16923
+ mintXAccount,
16924
+ mintXAccount.owner
16925
+ );
16926
+ const mintY = _spltoken.unpackMint.call(void 0,
16927
+ reserveAccY.mint,
16928
+ mintYAccount,
16929
+ mintYAccount.owner
16930
+ );
16931
+ const { tokenXProgram, tokenYProgram } = getTokenProgramId(lbPairState);
16932
+ const tokenX = {
16933
+ publicKey: lbPairState.tokenXMint,
16934
+ reserve: lbPairState.reserveX,
16935
+ amount: reserveAccX.amount,
16936
+ mint: mintX,
16937
+ owner: tokenXProgram,
16938
+ transferHookAccountMetas: _nullishCoalesce(mintHookAccountsMap.get(lbPairState.tokenXMint.toBase58()), () => ( []))
16939
+ };
16940
+ const tokenY = {
16941
+ publicKey: lbPairState.tokenYMint,
16942
+ reserve: lbPairState.reserveY,
16943
+ amount: reserveAccY.amount,
16944
+ mint: mintY,
16945
+ owner: tokenYProgram,
16946
+ transferHookAccountMetas: _nullishCoalesce(mintHookAccountsMap.get(lbPairState.tokenYMint.toBase58()), () => ( []))
16947
+ };
16948
+ lbPairTokenMap.set(lbPairPubkey.toBase58(), {
16949
+ tokenX,
16950
+ tokenY,
16951
+ mintX,
16952
+ mintY
16953
+ });
16954
+ });
16955
+ const limitOrdersMap = /* @__PURE__ */ new Map();
16956
+ for (const lo of matchingLimitOrders) {
16957
+ const lbPairKey = lo.lbPair().toBase58();
16958
+ const lbPairState = lbPairMap.get(lbPairKey);
16959
+ const { tokenX, tokenY, mintX, mintY } = lbPairTokenMap.get(lbPairKey);
16960
+ const parsedLo = lo.parseInfo(
16961
+ program.programId,
16962
+ lbPairState,
16963
+ mintX,
16964
+ mintY,
16965
+ clock,
16966
+ binArrayMap
16967
+ );
16968
+ const entry = {
16969
+ publicKey: lo.address(),
16970
+ limitOrderData: parsedLo
16971
+ };
16972
+ const existing = limitOrdersMap.get(lbPairKey);
16973
+ if (existing) {
16974
+ existing.limitOrders.push(entry);
16975
+ } else {
16976
+ limitOrdersMap.set(lbPairKey, {
16977
+ publicKey: lo.lbPair(),
16978
+ lbPair: lbPairState,
16979
+ tokenX,
16980
+ tokenY,
16981
+ limitOrders: [entry]
16982
+ });
16983
+ }
16984
+ }
16985
+ return limitOrdersMap;
16986
+ }
16751
16987
  static getPricePerLamport(tokenXDecimal, tokenYDecimal, price) {
16752
16988
  return new (0, _decimaljs2.default)(price).mul(new (0, _decimaljs2.default)(10 ** (tokenYDecimal - tokenXDecimal))).toString();
16753
16989
  }