@meteora-ag/dlmm 1.0.39-rc.16 → 1.0.39-rc.18

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
@@ -5316,7 +5316,7 @@ declare class DLMM {
5316
5316
  * @returns {Promise<Transaction>}
5317
5317
  */
5318
5318
  syncWithMarketPrice(marketPrice: number, owner: PublicKey): Promise<Transaction>;
5319
- getLastPrice(minPrice: string): Promise<number>;
5319
+ getMaxPrice(minPrice: string, binArrays?: BinArrayAccount[]): Promise<number>;
5320
5320
  /** Private static method */
5321
5321
  private static getBinArrays;
5322
5322
  private static getClaimableLMReward;
package/dist/index.js CHANGED
@@ -9904,35 +9904,22 @@ var DLMM = class {
9904
9904
  lastValidBlockHeight
9905
9905
  }).add(syncWithMarketPriceTx);
9906
9906
  }
9907
- async getLastPrice(minPrice) {
9908
- const binArrays = await this.getBinArrays();
9909
- console.log(
9910
- "\u{1F680} ~ DLMM ~ getLastPrice ~ bins:",
9911
- binArrays.flatMap(
9912
- ({ account: { bins } }) => bins.map(({ amountX, amountY }) => ({
9913
- amountX: amountX.toString(),
9914
- amountY: amountY.toString()
9915
- }))
9916
- )
9917
- );
9918
- let count = 0;
9907
+ async getMaxPrice(minPrice, binArrays) {
9908
+ const _binArrays = binArrays || await this.getBinArrays();
9909
+ let count = _binArrays.length - 1;
9919
9910
  let binPriceWithLastLiquidity = minPrice;
9920
- while (count <= binArrays.length - 1) {
9921
- const binArray = binArrays[count];
9911
+ while (count >= 0) {
9912
+ const binArray = _binArrays[count];
9922
9913
  if (binArray) {
9923
9914
  const bins = binArray.account.bins;
9924
- if (bins.every(({ amountX }) => !amountX.isZero())) {
9915
+ if (bins.every(({ amountX }) => amountX.isZero())) {
9925
9916
  count--;
9926
9917
  } else {
9927
- const lastBinWithLiquidityIndex = bins.findIndex(
9928
- ({ liquiditySupply }) => liquiditySupply.isZero()
9929
- );
9930
- console.log(
9931
- bins[lastBinWithLiquidityIndex - 1].amountX.toString(),
9932
- bins[lastBinWithLiquidityIndex - 1].amountY.toString()
9918
+ const lastBinWithLiquidityIndex = bins.findLastIndex(
9919
+ ({ amountX }) => !amountX.isZero()
9933
9920
  );
9934
- binPriceWithLastLiquidity = bins[lastBinWithLiquidityIndex - 1].price.toString();
9935
- count = binArrays.length;
9921
+ binPriceWithLastLiquidity = bins[lastBinWithLiquidityIndex].price.toString();
9922
+ count = -1;
9936
9923
  }
9937
9924
  }
9938
9925
  }