@meteora-ag/dlmm 1.1.5 → 1.2.2-rc.0

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
@@ -5689,6 +5689,17 @@ declare class DLMM {
5689
5689
  positionCount: number;
5690
5690
  positionCost: number;
5691
5691
  }>;
5692
+ /**
5693
+ * Creates an empty position and initializes the corresponding bin arrays if needed.
5694
+ * @param param0 The settings of the requested new position.
5695
+ * @returns A promise that resolves into a transaction for creating the requested position.
5696
+ */
5697
+ createEmptyPosition({ positionPubKey, minBinId, maxBinId, user, }: {
5698
+ positionPubKey: PublicKey;
5699
+ minBinId: number;
5700
+ maxBinId: number;
5701
+ user: PublicKey;
5702
+ }): Promise<Transaction>;
5692
5703
  /**
5693
5704
  * The function `initializePositionAndAddLiquidityByStrategy` function is used to initializes a position and adds liquidity
5694
5705
  * @param {TInitializePositionAndAddLiquidityParamsByStrategy}
@@ -5759,12 +5770,6 @@ declare class DLMM {
5759
5770
  bps: BN;
5760
5771
  shouldClaimAndClose?: boolean;
5761
5772
  }): Promise<Transaction | Transaction[]>;
5762
- removeLiquiditySingleSide({ user, position, binIds, removeLiquidityForY, }: {
5763
- user: PublicKey;
5764
- position: PublicKey;
5765
- binIds: number[];
5766
- removeLiquidityForY?: boolean;
5767
- }): Promise<Transaction | Transaction[]>;
5768
5773
  /**
5769
5774
  * The `closePosition` function closes a position
5770
5775
  * @param
package/dist/index.js 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 (0, _anchor.BN)(minBinId));
8960
+ const upperBinArrayIndex = _anchor.BN.max(
8961
+ lowerBinArrayIndex.add(new (0, _anchor.BN)(1)),
8962
+ binIdToBinArrayIndex(new (0, _anchor.BN)(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 (0, _web3js.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 (0, _anchor.BN)(lowerBinId));
9788
- const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(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(_spltoken.NATIVE_MINT) || !removeLiquidityForY && this.tokenX.publicKey.equals(_spltoken.NATIVE_MINT);
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 (0, _anchor.BN)(minBinId));
9823
- const maxBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(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: _spltoken.TOKEN_PROGRAM_ID
9839
- }).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
9840
- const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
9841
- return new (0, _web3js.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
@@ -11612,17 +11579,20 @@ var DLMM = class {
11612
11579
  ).map((idx) => new (0, _anchor.BN)(idx));
11613
11580
  const binArrays = [];
11614
11581
  for (const idx of binArrayIndexes) {
11615
- const [binArray] = deriveBinArray(
11582
+ const [binArrayPubKey] = deriveBinArray(
11616
11583
  this.pubkey,
11617
11584
  idx,
11618
11585
  this.program.programId
11619
11586
  );
11620
- const binArrayAccount = await this.program.provider.connection.getAccountInfo(binArray);
11621
- if (binArrayAccount === null) {
11622
- binArrays.push(binArray);
11623
- }
11587
+ binArrays.push(binArrayPubKey);
11624
11588
  }
11625
- return binArrays;
11589
+ const binArrayAccounts = await this.program.provider.connection.getMultipleAccountsInfo(binArrays);
11590
+ console.log(
11591
+ binArrays.map((binArray, index) => ({
11592
+ [binArray.toBase58()]: binArrayAccounts[index]
11593
+ }))
11594
+ );
11595
+ return binArrayAccounts.filter((binArray) => binArray === null);
11626
11596
  }
11627
11597
  async createBinArraysIfNeeded(upperBinArrayIndex, lowerBinArrayIndex, funder) {
11628
11598
  const ixs = [];