@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.d.ts CHANGED
@@ -4932,6 +4932,7 @@ declare class DLMM {
4932
4932
  * @returns a Promise that resolves to an array of BinArrayAccount objects.
4933
4933
  */
4934
4934
  getBinArrays(): Promise<BinArrayAccount[]>;
4935
+ getBinArraysWithLiquidity(): Promise<BinArray>;
4935
4936
  /**
4936
4937
  * The function `getBinArrayAroundActiveBin` retrieves a specified number of `BinArrayAccount`
4937
4938
  * objects from the blockchain, based on the active bin and its surrounding bin arrays.
@@ -5311,7 +5312,7 @@ declare class DLMM {
5311
5312
  * @returns {Promise<Transaction>}
5312
5313
  */
5313
5314
  syncWithMarketPrice(marketPrice: number, owner: PublicKey): Promise<Transaction>;
5314
- getMaxPrice(binArrays?: BinArrayAccount[]): Promise<string>;
5315
+ getMaxPrice(binArrayAccount: BinArray): Promise<string>;
5315
5316
  /** Private static method */
5316
5317
  private static getBinArrays;
5317
5318
  private static getClaimableLMReward;
@@ -5357,7 +5358,7 @@ declare function getBinArrayLowerUpperBinId(binArrayIndex: BN): BN[];
5357
5358
  declare function isBinIdWithinBinArray(activeId: BN, binArrayIndex: BN): boolean;
5358
5359
  declare function getBinFromBinArray(binId: number, binArray: BinArray): Bin;
5359
5360
  declare function findNextBinArrayIndexWithLiquidity(swapForY: boolean, activeId: BN, lbPairState: LbPair, binArrayBitmapExtension: BinArrayBitmapExtension | null): BN | null;
5360
- declare function findNextBinArrayWithLiquidity(swapForY: boolean, activeBinId: BN, lbPairState: LbPair, binArrayBitmapExtension: BinArrayBitmapExtension, binArrays: BinArrayAccount[]): BinArrayAccount | null;
5361
+ declare function findNextBinArrayWithLiquidity(swapForY: boolean, activeBinId: BN, lbPairState: LbPair, binArrayBitmapExtension: BinArrayBitmapExtension | null, binArrays: BinArrayAccount[]): BinArrayAccount | null;
5361
5362
 
5362
5363
  declare function getPriceOfBinByBinId(binId: number, binStep: number): Decimal;
5363
5364
  /** private */
package/dist/index.js 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 (0, _anchor.BN)(this.lbPair.parameters.maxBinId),
7528
+ this.lbPair,
7529
+ _nullishCoalesce(_optionalChain([this, 'access', _54 => _54.binArrayBitmapExtension, 'optionalAccess', _55 => _55.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.
@@ -7539,7 +7556,7 @@ var DLMM = class {
7539
7556
  swapForY,
7540
7557
  new (0, _anchor.BN)(activeIdToLoop),
7541
7558
  this.lbPair,
7542
- _nullishCoalesce(_optionalChain([this, 'access', _54 => _54.binArrayBitmapExtension, 'optionalAccess', _55 => _55.account]), () => ( null))
7559
+ _nullishCoalesce(_optionalChain([this, 'access', _56 => _56.binArrayBitmapExtension, 'optionalAccess', _57 => _57.account]), () => ( null))
7543
7560
  );
7544
7561
  if (binArrayIndex === null)
7545
7562
  shouldStop = true;
@@ -8975,7 +8992,7 @@ var DLMM = class {
8975
8992
  swapForY,
8976
8993
  activeId,
8977
8994
  this.lbPair,
8978
- _optionalChain([this, 'access', _56 => _56.binArrayBitmapExtension, 'optionalAccess', _57 => _57.account]),
8995
+ _optionalChain([this, 'access', _58 => _58.binArrayBitmapExtension, 'optionalAccess', _59 => _59.account]),
8979
8996
  binArrays
8980
8997
  );
8981
8998
  if (binArrayAccountToSwap == null) {
@@ -9082,7 +9099,7 @@ var DLMM = class {
9082
9099
  swapForY,
9083
9100
  activeId,
9084
9101
  this.lbPair,
9085
- _nullishCoalesce(_optionalChain([this, 'access', _58 => _58.binArrayBitmapExtension, 'optionalAccess', _59 => _59.account]), () => ( null)),
9102
+ _nullishCoalesce(_optionalChain([this, 'access', _60 => _60.binArrayBitmapExtension, 'optionalAccess', _61 => _61.account]), () => ( null)),
9086
9103
  binArrays
9087
9104
  );
9088
9105
  if (binArrayAccountToSwap == null) {
@@ -9808,7 +9825,7 @@ var DLMM = class {
9808
9825
  swapForY,
9809
9826
  new (0, _anchor.BN)(activeBinId),
9810
9827
  this.lbPair,
9811
- _nullishCoalesce(_optionalChain([this, 'access', _60 => _60.binArrayBitmapExtension, 'optionalAccess', _61 => _61.account]), () => ( null))
9828
+ _nullishCoalesce(_optionalChain([this, 'access', _62 => _62.binArrayBitmapExtension, 'optionalAccess', _63 => _63.account]), () => ( null))
9812
9829
  );
9813
9830
  if (toBinArrayIndex === null)
9814
9831
  return true;
@@ -9845,7 +9862,7 @@ var DLMM = class {
9845
9862
  swapForY,
9846
9863
  new (0, _anchor.BN)(activeBinId),
9847
9864
  this.lbPair,
9848
- _nullishCoalesce(_optionalChain([this, 'access', _62 => _62.binArrayBitmapExtension, 'optionalAccess', _63 => _63.account]), () => ( null))
9865
+ _nullishCoalesce(_optionalChain([this, 'access', _64 => _64.binArrayBitmapExtension, 'optionalAccess', _65 => _65.account]), () => ( null))
9849
9866
  );
9850
9867
  const accountsToFetch = [];
9851
9868
  const [binArrayBitMapExtensionPubkey] = deriveBinArrayBitmapExtension(
@@ -9876,13 +9893,13 @@ var DLMM = class {
9876
9893
  let fromBinArray = null;
9877
9894
  let toBinArray = null;
9878
9895
  let binArrayBitmapExtension = null;
9879
- if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _64 => _64[0]])) {
9896
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _66 => _66[0]])) {
9880
9897
  binArrayBitmapExtension = binArrayBitMapExtensionPubkey;
9881
9898
  }
9882
- if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _65 => _65[1]])) {
9899
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _67 => _67[1]])) {
9883
9900
  fromBinArray = fromBinArrayPubkey;
9884
9901
  }
9885
- if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _66 => _66[2]]) && !!toBinArrayIndex) {
9902
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _68 => _68[2]]) && !!toBinArrayIndex) {
9886
9903
  toBinArray = toBinArrayPubkey;
9887
9904
  }
9888
9905
  const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
@@ -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
  );
@@ -10520,7 +10521,7 @@ var DLMMError = class extends Error {
10520
10521
  const anchorError = _anchor.AnchorError.parse(
10521
10522
  JSON.parse(JSON.stringify(error)).logs
10522
10523
  );
10523
- if (_optionalChain([anchorError, 'optionalAccess', _67 => _67.program, 'access', _68 => _68.toBase58, 'call', _69 => _69()]) === LBCLMM_PROGRAM_IDS["mainnet-beta"]) {
10524
+ if (_optionalChain([anchorError, 'optionalAccess', _69 => _69.program, 'access', _70 => _70.toBase58, 'call', _71 => _71()]) === LBCLMM_PROGRAM_IDS["mainnet-beta"]) {
10524
10525
  _errorCode = anchorError.error.errorCode.number;
10525
10526
  _errorName = anchorError.error.errorCode.code;
10526
10527
  _errorMessage = anchorError.error.errorMessage;