@meteora-ag/dlmm 1.1.4 → 1.2.1

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.mjs CHANGED
@@ -8938,6 +8938,41 @@ var DLMM = class {
8938
8938
  positionCost
8939
8939
  };
8940
8940
  }
8941
+ /**
8942
+ * Creates an empty position and initializes the corresponding bin arrays if needed.
8943
+ * @param param0 The settings of the requested new position.
8944
+ * @returns A promise that resolves into a transaction for creating the requested position.
8945
+ */
8946
+ async createEmptyPosition({
8947
+ positionPubKey,
8948
+ minBinId,
8949
+ maxBinId,
8950
+ user
8951
+ }) {
8952
+ const setComputeUnitLimitIx = computeBudgetIx();
8953
+ const createPositionIx = await this.program.methods.initializePosition(minBinId, maxBinId - minBinId + 1).accounts({
8954
+ payer: user,
8955
+ position: positionPubKey,
8956
+ lbPair: this.pubkey,
8957
+ owner: user
8958
+ }).instruction();
8959
+ const lowerBinArrayIndex = binIdToBinArrayIndex(new BN9(minBinId));
8960
+ const upperBinArrayIndex = BN9.max(
8961
+ lowerBinArrayIndex.add(new BN9(1)),
8962
+ binIdToBinArrayIndex(new BN9(maxBinId))
8963
+ );
8964
+ const createBinArrayIxs = await this.createBinArraysIfNeeded(
8965
+ upperBinArrayIndex,
8966
+ lowerBinArrayIndex,
8967
+ user
8968
+ );
8969
+ const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
8970
+ return new Transaction({
8971
+ blockhash,
8972
+ lastValidBlockHeight,
8973
+ feePayer: user
8974
+ }).add(setComputeUnitLimitIx, createPositionIx, ...createBinArrayIxs);
8975
+ }
8941
8976
  /**
8942
8977
  * The function `initializePositionAndAddLiquidityByStrategy` function is used to initializes a position and adds liquidity
8943
8978
  * @param {TInitializePositionAndAddLiquidityParamsByStrategy}
@@ -9776,74 +9811,6 @@ var DLMM = class {
9776
9811
  }).add(removeLiquidityTx);
9777
9812
  }
9778
9813
  }
9779
- async removeLiquiditySingleSide({
9780
- user,
9781
- position,
9782
- binIds,
9783
- removeLiquidityForY = false
9784
- }) {
9785
- const { lbPair, lowerBinId, owner, feeOwner } = await this.program.account.positionV2.fetch(position);
9786
- const { reserveX, reserveY, tokenXMint, tokenYMint } = await this.program.account.lbPair.fetch(lbPair);
9787
- const lowerBinArrayIndex = binIdToBinArrayIndex(new BN9(lowerBinId));
9788
- const upperBinArrayIndex = lowerBinArrayIndex.add(new BN9(1));
9789
- const [binArrayLower] = deriveBinArray(
9790
- lbPair,
9791
- lowerBinArrayIndex,
9792
- this.program.programId
9793
- );
9794
- const [binArrayUpper] = deriveBinArray(
9795
- lbPair,
9796
- upperBinArrayIndex,
9797
- this.program.programId
9798
- );
9799
- const preInstructions = [];
9800
- const setComputeUnitLimitIx = computeBudgetIx();
9801
- preInstructions.push(setComputeUnitLimitIx);
9802
- const { ataPubKey: userToken, ix: createPayerTokenIx } = removeLiquidityForY ? await getOrCreateATAInstruction(
9803
- this.program.provider.connection,
9804
- this.tokenY.publicKey,
9805
- owner,
9806
- user
9807
- ) : await getOrCreateATAInstruction(
9808
- this.program.provider.connection,
9809
- this.tokenX.publicKey,
9810
- owner,
9811
- user
9812
- );
9813
- createPayerTokenIx && preInstructions.push(createPayerTokenIx);
9814
- const postInstructions = [];
9815
- const shouldUnwrapSOL = removeLiquidityForY && this.tokenY.publicKey.equals(NATIVE_MINT2) || !removeLiquidityForY && this.tokenX.publicKey.equals(NATIVE_MINT2);
9816
- if (shouldUnwrapSOL) {
9817
- const closeWrappedSOLIx = await unwrapSOLInstruction(user);
9818
- closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
9819
- }
9820
- const minBinId = Math.min(...binIds);
9821
- const maxBinId = Math.max(...binIds);
9822
- const minBinArrayIndex = binIdToBinArrayIndex(new BN9(minBinId));
9823
- const maxBinArrayIndex = binIdToBinArrayIndex(new BN9(maxBinId));
9824
- const useExtension = isOverflowDefaultBinArrayBitmap(minBinArrayIndex) || isOverflowDefaultBinArrayBitmap(maxBinArrayIndex);
9825
- const binArrayBitmapExtension = useExtension ? deriveBinArrayBitmapExtension(this.pubkey, this.program.programId)[0] : null;
9826
- const reserve = removeLiquidityForY ? reserveY : reserveX;
9827
- const tokenMint = removeLiquidityForY ? tokenYMint : tokenXMint;
9828
- const removeLiquiditySingleSideTx = await this.program.methods.removeLiquiditySingleSide().accounts({
9829
- position,
9830
- lbPair,
9831
- binArrayBitmapExtension,
9832
- userToken,
9833
- reserve,
9834
- tokenMint,
9835
- binArrayLower,
9836
- binArrayUpper,
9837
- sender: user,
9838
- tokenProgram: TOKEN_PROGRAM_ID2
9839
- }).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
9840
- const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
9841
- return new Transaction({
9842
- blockhash,
9843
- lastValidBlockHeight,
9844
- feePayer: user
9845
- }).add(removeLiquiditySingleSideTx);
9846
- }
9847
9814
  /**
9848
9815
  * The `closePosition` function closes a position
9849
9816
  * @param