@meteora-ag/dlmm 1.0.39-rc.3 → 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.mjs CHANGED
@@ -1231,11 +1231,6 @@ var IDL = {
1231
1231
  isMut: true,
1232
1232
  isSigner: false
1233
1233
  },
1234
- {
1235
- name: "feeOwner",
1236
- isMut: false,
1237
- isSigner: true
1238
- },
1239
1234
  {
1240
1235
  name: "tokenXProgram",
1241
1236
  isMut: false,
@@ -9087,10 +9082,9 @@ var DLMM = class {
9087
9082
  swapForY,
9088
9083
  activeId,
9089
9084
  this.lbPair,
9090
- this.binArrayBitmapExtension?.account,
9085
+ this.binArrayBitmapExtension?.account ?? null,
9091
9086
  binArrays
9092
9087
  );
9093
- console.log("\u{1F680} ~ DLMM ~ binArrayAccountToSwap:", binArrayAccountToSwap);
9094
9088
  if (binArrayAccountToSwap == null) {
9095
9089
  throw new Error("Insufficient liquidity");
9096
9090
  }
@@ -9904,27 +9898,31 @@ var DLMM = class {
9904
9898
  lastValidBlockHeight
9905
9899
  }).add(syncWithMarketPriceTx);
9906
9900
  }
9907
- async getLastPrice() {
9908
- const { price } = await this.getActiveBin();
9909
- const binArrays = await this.getBinArrays();
9910
- let count = 0;
9911
- let binPriceWithLastLiquidity = price;
9912
- while (count <= binArrays.length - 1) {
9913
- const binArray = binArrays[count];
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
+ );
9906
+ let count = sortedBinArrays.length - 1;
9907
+ let binPriceWithLastLiquidity;
9908
+ while (count >= 0) {
9909
+ const binArray = sortedBinArrays[count];
9914
9910
  if (binArray) {
9915
- const bins = binArray.account.bins;
9916
- if (bins[bins.length - 1].liquiditySupply.gt(new BN9(0))) {
9917
- count++;
9911
+ const bins = binArray.account.bins.reverse();
9912
+ if (bins.every(({ amountX }) => amountX.isZero())) {
9913
+ count--;
9918
9914
  } else {
9919
- const lastBinWithLiquidityIndex = bins.findIndex(
9920
- ({ liquiditySupply }) => liquiditySupply.isZero()
9915
+ const lastBinWithLiquidityIndex = bins.findLastIndex(
9916
+ ({ amountX }) => !amountX.isZero()
9921
9917
  );
9922
- binPriceWithLastLiquidity = bins[lastBinWithLiquidityIndex - 1].price.toString();
9923
- count = binArrays.length;
9918
+ binPriceWithLastLiquidity = bins[lastBinWithLiquidityIndex].price.toString();
9919
+ count = -1;
9924
9920
  }
9925
9921
  }
9926
9922
  }
9927
- return binPriceWithLastLiquidity;
9923
+ return this.fromPricePerLamport(
9924
+ Number(binPriceWithLastLiquidity) / (2 ** 64 - 1)
9925
+ );
9928
9926
  }
9929
9927
  /** Private static method */
9930
9928
  static async getBinArrays(program, lbPairPubkey) {