@meteora-ag/dlmm 1.0.39-rc.30 → 1.0.39-rc.32

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
@@ -5311,7 +5311,7 @@ declare class DLMM {
5311
5311
  * @returns {Promise<Transaction>}
5312
5312
  */
5313
5313
  syncWithMarketPrice(marketPrice: number, owner: PublicKey): Promise<Transaction>;
5314
- getMaxPrice(binArrayAccount: BinArray): Promise<string>;
5314
+ getMaxPrice(binArrayAccounts: BinArrayAccount[]): Promise<string>;
5315
5315
  /** Private static method */
5316
5316
  private static getBinArrays;
5317
5317
  private static getClaimableLMReward;
package/dist/index.js CHANGED
@@ -9898,12 +9898,28 @@ var DLMM = class {
9898
9898
  lastValidBlockHeight
9899
9899
  }).add(syncWithMarketPriceTx);
9900
9900
  }
9901
- async getMaxPrice(binArrayAccount) {
9902
- const { bins } = binArrayAccount;
9903
- const lastBinWithLiquidityIndex = bins.findLastIndex(
9904
- ({ amountX }) => !amountX.isZero()
9901
+ async getMaxPrice(binArrayAccounts) {
9902
+ const binArrays = binArrayAccounts || await this.getBinArrayForSwap(false);
9903
+ const sortedBinArrays = binArrays.sort(
9904
+ ({ account: { index: indexA } }, { account: { index: indexB } }) => indexA.toNumber() - indexB.toNumber()
9905
9905
  );
9906
- const binPriceWithLastLiquidity = bins[lastBinWithLiquidityIndex].price.toString();
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.bins.reverse();
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
+ }
9907
9923
  return this.fromPricePerLamport(
9908
9924
  Number(binPriceWithLastLiquidity) / (2 ** 64 - 1)
9909
9925
  );