@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 +1 -1
- package/dist/index.js +44 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -11
package/dist/index.mjs
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
|
|
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 BN21(i))
|
|
19157
|
+
binId: positionState.lowerBinId().add(new BN21(i)),
|
|
19158
|
+
hasFeesOrRewards: hasFees || hasRewards
|
|
19152
19159
|
};
|
|
19153
19160
|
});
|
|
19154
|
-
const binIdsWithLiquidity =
|
|
19161
|
+
const binIdsWithLiquidity = binDataWithBinId.filter((bin) => {
|
|
19155
19162
|
return !bin.share.isZero();
|
|
19156
19163
|
});
|
|
19157
|
-
|
|
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
|
|
19161
|
-
const
|
|
19162
|
-
|
|
19163
|
-
|
|
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 >
|
|
19166
|
-
toBinId =
|
|
19177
|
+
if (toBinId > upperActiveBinId) {
|
|
19178
|
+
toBinId = upperActiveBinId;
|
|
19167
19179
|
}
|
|
19168
19180
|
const walletToReceiveFee = feeOwner.equals(PublicKey10.default) ? user : feeOwner;
|
|
19169
19181
|
const userTokenX = getAssociatedTokenAddressSync2(
|
|
@@ -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
|
|
19305
|
-
|
|
19306
|
-
|
|
19307
|
-
|
|
19308
|
-
|
|
19309
|
-
|
|
19310
|
-
|
|
19311
|
-
|
|
19312
|
-
|
|
19313
|
-
|
|
19314
|
-
|
|
19315
|
-
|
|
19316
|
-
|
|
19317
|
-
|
|
19318
|
-
|
|
19319
|
-
|
|
19320
|
-
|
|
19321
|
-
|
|
19322
|
-
|
|
19323
|
-
removeLiquidityTx
|
|
19324
|
-
|
|
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(
|