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

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
@@ -9898,28 +9898,26 @@ var DLMM = class {
9898
9898
  lastValidBlockHeight
9899
9899
  }).add(syncWithMarketPriceTx);
9900
9900
  }
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()
9901
+ async getMaxPrice() {
9902
+ const binArrayIndex = findNextBinArrayIndexWithLiquidity(
9903
+ false,
9904
+ new BN9(this.lbPair.parameters.maxBinId),
9905
+ this.lbPair,
9906
+ this.binArrayBitmapExtension?.account ?? null
9905
9907
  );
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
- }
9908
+ const [binArrayPubkey] = deriveBinArray(
9909
+ this.pubkey,
9910
+ binArrayIndex,
9911
+ this.program.programId
9912
+ );
9913
+ const binArrayAccount = await this.program.account.binArray.fetch(
9914
+ binArrayPubkey
9915
+ );
9916
+ const { bins } = binArrayAccount;
9917
+ const lastBinWithLiquidityIndex = bins.findLastIndex(
9918
+ ({ amountX }) => !amountX.isZero()
9919
+ );
9920
+ const binPriceWithLastLiquidity = bins[lastBinWithLiquidityIndex].price.toString();
9923
9921
  return this.fromPricePerLamport(
9924
9922
  Number(binPriceWithLastLiquidity) / (2 ** 64 - 1)
9925
9923
  );