@meteora-ag/dlmm 1.0.39-rc.27 → 1.0.39-rc.29

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
@@ -7521,6 +7521,23 @@ var DLMM = class {
7521
7521
  }
7522
7522
  ]);
7523
7523
  }
7524
+ async getBinArraysWithLiquidity() {
7525
+ const binArrayIndex = findNextBinArrayIndexWithLiquidity(
7526
+ false,
7527
+ new BN9(this.lbPair.parameters.maxBinId),
7528
+ this.lbPair,
7529
+ this.binArrayBitmapExtension?.account ?? null
7530
+ );
7531
+ const [binArrayPubkey] = deriveBinArray(
7532
+ this.pubkey,
7533
+ binArrayIndex,
7534
+ this.program.programId
7535
+ );
7536
+ const binArrayAccount = await this.program.account.binArray.fetch(
7537
+ binArrayPubkey
7538
+ );
7539
+ return binArrayAccount;
7540
+ }
7524
7541
  /**
7525
7542
  * The function `getBinArrayAroundActiveBin` retrieves a specified number of `BinArrayAccount`
7526
7543
  * objects from the blockchain, based on the active bin and its surrounding bin arrays.
@@ -9898,28 +9915,12 @@ var DLMM = class {
9898
9915
  lastValidBlockHeight
9899
9916
  }).add(syncWithMarketPriceTx);
9900
9917
  }
9901
- async getMaxPrice(binArrays) {
9902
- const _binArrays = binArrays || await this.getBinArrays();
9903
- const sortedBinArrays = _binArrays.sort(
9904
- ({ account: { index: indexA } }, { account: { index: indexB } }) => indexA.toNumber() - indexB.toNumber()
9918
+ async getMaxPrice(binArrayAccount) {
9919
+ const { bins } = binArrayAccount;
9920
+ const lastBinWithLiquidityIndex = bins.findLastIndex(
9921
+ ({ amountX }) => !amountX.isZero()
9905
9922
  );
9906
- let count = sortedBinArrays.length - 1;
9907
- let binPriceWithLastLiquidity;
9908
- while (count >= 0) {
9909
- const binArray = sortedBinArrays[count];
9910
- if (binArray) {
9911
- const { bins } = binArray.account;
9912
- if (bins.every(({ amountX }) => amountX.isZero())) {
9913
- count--;
9914
- } else {
9915
- const lastBinWithLiquidityIndex = bins.findLastIndex(
9916
- ({ amountX }) => !amountX.isZero()
9917
- );
9918
- binPriceWithLastLiquidity = bins[lastBinWithLiquidityIndex].price.toString();
9919
- count = -1;
9920
- }
9921
- }
9922
- }
9923
+ const binPriceWithLastLiquidity = bins[lastBinWithLiquidityIndex].price.toString();
9923
9924
  return this.fromPricePerLamport(
9924
9925
  Number(binPriceWithLastLiquidity) / (2 ** 64 - 1)
9925
9926
  );