@meteora-ag/dlmm 1.4.10 → 1.4.11

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
@@ -8268,7 +8268,7 @@ declare class DLMM {
8268
8268
  claimSwapFee({ owner, position, }: {
8269
8269
  owner: PublicKey;
8270
8270
  position: LbPosition;
8271
- }): Promise<Transaction>;
8271
+ }): Promise<Transaction | null>;
8272
8272
  /**
8273
8273
  * The `claimAllSwapFee` function to claim swap fees for multiple positions owned by a specific owner.
8274
8274
  * @param
package/dist/index.js CHANGED
@@ -10183,14 +10183,11 @@ function getBinArrayAccountMetasCoverage(lowerBinId, upperBinId, lbPair, program
10183
10183
  }
10184
10184
  );
10185
10185
  }
10186
- function getPositionLowerUpperBinIdWithLiquidity(position) {
10187
- const binWithLiquidity = position.positionBinData.filter(
10188
- (b) => !new (0, _bnjs2.default)(b.binLiquidity).isZero()
10189
- );
10190
- return binWithLiquidity.length > 0 ? {
10191
- lowerBinId: new (0, _bnjs2.default)(binWithLiquidity[0].binId),
10192
- upperBinId: new (0, _bnjs2.default)(binWithLiquidity[binWithLiquidity.length - 1].binId)
10193
- } : null;
10186
+ function isPositionNoFee(position) {
10187
+ return position.feeX.isZero() && position.feeY.isZero();
10188
+ }
10189
+ function isPositionNoReward(position) {
10190
+ return position.rewardOne.isZero() && position.rewardTwo.isZero();
10194
10191
  }
10195
10192
 
10196
10193
  // src/dlmm/index.ts
@@ -13635,6 +13632,9 @@ var DLMM = class {
13635
13632
  owner,
13636
13633
  position
13637
13634
  }) {
13635
+ if (isPositionNoReward(position.positionData)) {
13636
+ throw new Error("No LM reward to claim");
13637
+ }
13638
13638
  const claimTransactions = await this.createClaimBuildMethod({
13639
13639
  owner,
13640
13640
  position
@@ -13666,6 +13666,9 @@ var DLMM = class {
13666
13666
  owner,
13667
13667
  positions
13668
13668
  }) {
13669
+ if (positions.every((position) => isPositionNoReward(position.positionData))) {
13670
+ throw new Error("No LM reward to claim");
13671
+ }
13669
13672
  const claimAllTxs = (await Promise.all(
13670
13673
  positions.filter(
13671
13674
  ({ positionData: { rewardOne, rewardTwo } }) => !rewardOne.isZero() || !rewardTwo.isZero()
@@ -13738,6 +13741,9 @@ var DLMM = class {
13738
13741
  owner,
13739
13742
  position
13740
13743
  }) {
13744
+ if (isPositionNoFee(position.positionData)) {
13745
+ throw new Error("No fee to claim");
13746
+ }
13741
13747
  const claimFeeTx = await this.createClaimSwapFeeMethod({ owner, position });
13742
13748
  const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
13743
13749
  const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
@@ -13762,6 +13768,9 @@ var DLMM = class {
13762
13768
  owner,
13763
13769
  positions
13764
13770
  }) {
13771
+ if (positions.every((position) => isPositionNoFee(position.positionData))) {
13772
+ throw new Error("No fee to claim");
13773
+ }
13765
13774
  const claimAllTxs = (await Promise.all(
13766
13775
  positions.filter(
13767
13776
  ({ positionData: { feeX, feeY } }) => !feeX.isZero() || !feeY.isZero()
@@ -13809,6 +13818,9 @@ var DLMM = class {
13809
13818
  owner,
13810
13819
  position
13811
13820
  }) {
13821
+ if (isPositionNoFee(position.positionData) && isPositionNoReward(position.positionData)) {
13822
+ throw new Error("No fee/reward to claim");
13823
+ }
13812
13824
  const claimAllSwapFeeTxs = await this.createClaimSwapFeeMethod({
13813
13825
  owner,
13814
13826
  position
@@ -15034,15 +15046,10 @@ var DLMM = class {
15034
15046
  owner,
15035
15047
  position
15036
15048
  }) {
15037
- const maybeClaimableBinRange = getPositionLowerUpperBinIdWithLiquidity(
15038
- position.positionData
15039
- );
15040
- if (!maybeClaimableBinRange)
15041
- return [];
15042
- const { lowerBinId, upperBinId } = maybeClaimableBinRange;
15049
+ const { lowerBinId, upperBinId } = position.positionData;
15043
15050
  const binArrayAccountsMeta = getBinArrayAccountMetasCoverage(
15044
- lowerBinId,
15045
- upperBinId,
15051
+ new (0, _anchor.BN)(lowerBinId),
15052
+ new (0, _anchor.BN)(upperBinId),
15046
15053
  this.pubkey,
15047
15054
  this.program.programId
15048
15055
  );
@@ -15060,7 +15067,7 @@ var DLMM = class {
15060
15067
  );
15061
15068
  ix && preInstructions.push(ix);
15062
15069
  const { slices, accounts: transferHookAccounts } = this.getPotentialToken2022IxDataAndAccounts(1 /* Reward */, i);
15063
- const claimTransaction = await this.program.methods.claimReward2(new (0, _anchor.BN)(i), lowerBinId.toNumber(), upperBinId.toNumber(), {
15070
+ const claimTransaction = await this.program.methods.claimReward2(new (0, _anchor.BN)(i), lowerBinId, upperBinId, {
15064
15071
  slices
15065
15072
  }).accounts({
15066
15073
  lbPair: this.pubkey,
@@ -15080,15 +15087,10 @@ var DLMM = class {
15080
15087
  owner,
15081
15088
  position
15082
15089
  }) {
15083
- const maybeClaimableBinRange = getPositionLowerUpperBinIdWithLiquidity(
15084
- position.positionData
15085
- );
15086
- if (!maybeClaimableBinRange)
15087
- return;
15088
- const { lowerBinId, upperBinId } = maybeClaimableBinRange;
15090
+ const { lowerBinId, upperBinId } = position.positionData;
15089
15091
  const binArrayAccountsMeta = getBinArrayAccountMetasCoverage(
15090
- lowerBinId,
15091
- upperBinId,
15092
+ new (0, _anchor.BN)(lowerBinId),
15093
+ new (0, _anchor.BN)(upperBinId),
15092
15094
  this.pubkey,
15093
15095
  this.program.programId
15094
15096
  );
@@ -15125,7 +15127,7 @@ var DLMM = class {
15125
15127
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
15126
15128
  }
15127
15129
  const { slices, accounts: transferHookAccounts } = this.getPotentialToken2022IxDataAndAccounts(0 /* Liquidity */);
15128
- const claimFeeTx = await this.program.methods.claimFee2(lowerBinId.toNumber(), upperBinId.toNumber(), {
15130
+ const claimFeeTx = await this.program.methods.claimFee2(lowerBinId, upperBinId, {
15129
15131
  slices
15130
15132
  }).accounts({
15131
15133
  lbPair: this.pubkey,