@meteora-ag/dlmm 1.9.3 → 1.9.4

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/dist/index.d.ts CHANGED
@@ -10436,7 +10436,7 @@ declare function getTokenBalance(conn: Connection, tokenAccount: PublicKey): Pro
10436
10436
  declare const parseLogs: <T>(eventParser: EventParser, logs: string[]) => T;
10437
10437
  declare const wrapSOLInstruction: (from: PublicKey, to: PublicKey, amount: bigint) => TransactionInstruction[];
10438
10438
  declare const unwrapSOLInstruction: (owner: PublicKey, allowOwnerOffCurve?: boolean) => Promise<TransactionInstruction>;
10439
- declare function chunkedGetMultipleAccountInfos(connection: Connection, pks: PublicKey[], chunkSize?: number): Promise<AccountInfo<Buffer<ArrayBufferLike>>[]>;
10439
+ declare function chunkedGetMultipleAccountInfos(connection: Connection, pks: PublicKey[], chunkSize?: number): Promise<AccountInfo<Buffer>[]>;
10440
10440
  /**
10441
10441
  * Fetches program accounts in a chunked manner to handle large result sets.
10442
10442
  *
package/dist/index.js CHANGED
@@ -19145,25 +19145,37 @@ var DLMM = class {
19145
19145
  const owner = positionState.owner();
19146
19146
  const feeOwner = positionState.feeOwner();
19147
19147
  const liquidityShares = positionState.liquidityShares();
19148
- const liqudityShareWithBinId = liquidityShares.map((share, i) => {
19148
+ const feeInfos = positionState.feeInfos();
19149
+ const rewardInfos = positionState.rewardInfos();
19150
+ const binDataWithBinId = liquidityShares.map((share, i) => {
19151
+ const feeInfo = feeInfos[i];
19152
+ const rewardInfo = rewardInfos[i];
19153
+ const hasFees = feeInfo && (!feeInfo.feeXPending.isZero() || !feeInfo.feeYPending.isZero());
19154
+ const hasRewards = rewardInfo && rewardInfo.rewardPendings.some((pending) => !pending.isZero());
19149
19155
  return {
19150
19156
  share,
19151
- binId: positionState.lowerBinId().add(new (0, _anchor.BN)(i))
19157
+ binId: positionState.lowerBinId().add(new (0, _anchor.BN)(i)),
19158
+ hasFeesOrRewards: hasFees || hasRewards
19152
19159
  };
19153
19160
  });
19154
- const binIdsWithLiquidity = liqudityShareWithBinId.filter((bin) => {
19161
+ const binIdsWithLiquidity = binDataWithBinId.filter((bin) => {
19155
19162
  return !bin.share.isZero();
19156
19163
  });
19157
- if (binIdsWithLiquidity.length == 0) {
19164
+ const binIdsWithLiquidityOrFees = binDataWithBinId.filter((bin) => {
19165
+ return !bin.share.isZero() || bin.hasFeesOrRewards;
19166
+ });
19167
+ const hasLiquidity = binIdsWithLiquidity.length > 0;
19168
+ if (!hasLiquidity && !shouldClaimAndClose) {
19158
19169
  throw new Error("No liquidity to remove");
19159
19170
  }
19160
- const lowerBinIdWithLiquidity = binIdsWithLiquidity[0].binId.toNumber();
19161
- const upperBinIdWithLiquidity = binIdsWithLiquidity[binIdsWithLiquidity.length - 1].binId.toNumber();
19162
- if (fromBinId < lowerBinIdWithLiquidity) {
19163
- fromBinId = lowerBinIdWithLiquidity;
19171
+ const activeBins = shouldClaimAndClose ? binIdsWithLiquidityOrFees : binIdsWithLiquidity;
19172
+ const lowerActiveBinId = activeBins[0].binId.toNumber();
19173
+ const upperActiveBinId = activeBins[activeBins.length - 1].binId.toNumber();
19174
+ if (fromBinId < lowerActiveBinId) {
19175
+ fromBinId = lowerActiveBinId;
19164
19176
  }
19165
- if (toBinId > upperBinIdWithLiquidity) {
19166
- toBinId = upperBinIdWithLiquidity;
19177
+ if (toBinId > upperActiveBinId) {
19178
+ toBinId = upperActiveBinId;
19167
19179
  }
19168
19180
  const walletToReceiveFee = feeOwner.equals(_web3js.PublicKey.default) ? user : feeOwner;
19169
19181
  const userTokenX = _spltoken.getAssociatedTokenAddressSync.call(void 0,
@@ -19301,28 +19313,28 @@ var DLMM = class {
19301
19313
  preInstructions.push(createUserTokenXIx);
19302
19314
  preInstructions.push(createUserTokenYIx);
19303
19315
  const binArrayBitmapExtension = this.binArrayBitmapExtension ? this.binArrayBitmapExtension.publicKey : this.program.programId;
19304
- const removeLiquidityTx = await this.program.methods.removeLiquidityByRange2(lowerBinId, upperBinId, bps.toNumber(), {
19305
- slices
19306
- }).accountsPartial({
19307
- position,
19308
- lbPair,
19309
- userTokenX,
19310
- userTokenY,
19311
- reserveX: this.lbPair.reserveX,
19312
- reserveY: this.lbPair.reserveY,
19313
- tokenXMint: this.tokenX.publicKey,
19314
- tokenYMint: this.tokenY.publicKey,
19315
- binArrayBitmapExtension,
19316
- tokenXProgram: this.tokenX.owner,
19317
- tokenYProgram: this.tokenY.owner,
19318
- sender: user,
19319
- memoProgram: MEMO_PROGRAM_ID
19320
- }).remainingAccounts(transferHookAccounts).remainingAccounts(binArrayAccountsMeta).instruction();
19321
- const instructions = [
19322
- ...preInstructions,
19323
- removeLiquidityTx,
19324
- ...postInstructions
19325
- ];
19316
+ const instructions = [...preInstructions];
19317
+ if (hasLiquidity) {
19318
+ const removeLiquidityTx = await this.program.methods.removeLiquidityByRange2(lowerBinId, upperBinId, bps.toNumber(), {
19319
+ slices
19320
+ }).accountsPartial({
19321
+ position,
19322
+ lbPair,
19323
+ userTokenX,
19324
+ userTokenY,
19325
+ reserveX: this.lbPair.reserveX,
19326
+ reserveY: this.lbPair.reserveY,
19327
+ tokenXMint: this.tokenX.publicKey,
19328
+ tokenYMint: this.tokenY.publicKey,
19329
+ binArrayBitmapExtension,
19330
+ tokenXProgram: this.tokenX.owner,
19331
+ tokenYProgram: this.tokenY.owner,
19332
+ sender: user,
19333
+ memoProgram: MEMO_PROGRAM_ID
19334
+ }).remainingAccounts(transferHookAccounts).remainingAccounts(binArrayAccountsMeta).instruction();
19335
+ instructions.push(removeLiquidityTx);
19336
+ }
19337
+ instructions.push(...postInstructions);
19326
19338
  groupedInstructions.push(instructions);
19327
19339
  }
19328
19340
  const groupedInstructionsWithCUIx = await Promise.all(