@meteora-ag/dlmm 1.0.39-rc.33 → 1.0.39-rc.35

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/README.md CHANGED
@@ -233,4 +233,4 @@ try {
233
233
  | `claimAllRewards` | Claim swap fees and LM rewards for multiple positions owned by a specific owner | `Promise<Transaction[]>` |
234
234
  | `syncWithMarketPrice` | Sync the pool current active bin to match nearest market price bin | `Promise<Transaction>` |
235
235
  | `getPairPubkeyIfExists` | Get existing pool address given parameter, if not return null | `Promise<PublicKey \| null>` |
236
- | `getMaxPrice` | Get max price of the last bin that has liquidity on the ask side | `Promise<string \| null>` |
236
+ | `getMaxPriceInBinArrays` | Get max price of the last bin that has liquidity given bin arrays | `Promise<string \| null>` |
package/dist/index.js CHANGED
@@ -5848,6 +5848,10 @@ function findSetBit(startIndex, endIndex, binArrayBitmapExtension) {
5848
5848
  const binArrayOffset = getBinArrayOffset(i);
5849
5849
  const bitmapOffset = getBitmapOffset(i);
5850
5850
  const bitmapChunks = i > 0 ? binArrayBitmapExtension.positiveBinArrayBitmap[bitmapOffset] : binArrayBitmapExtension.negativeBinArrayBitmap[bitmapOffset];
5851
+ console.log(
5852
+ "\u{1F680} ~ bitmapChunks:",
5853
+ _optionalChain([bitmapChunks, 'optionalAccess', _18 => _18.map, 'call', _19 => _19((b) => b.toString())])
5854
+ );
5851
5855
  const bitmap = buildBitmapFromU64Arrays(bitmapChunks, 1 /* U512 */);
5852
5856
  if (bitmap.testn(binArrayOffset)) {
5853
5857
  return i;
@@ -5946,6 +5950,12 @@ function findNextBinArrayIndexWithLiquidity(swapForY, activeId, lbPairState, bin
5946
5950
  startBinArrayIndex = BIN_ARRAY_BITMAP_SIZE;
5947
5951
  }
5948
5952
  } else {
5953
+ console.log(
5954
+ ">>>> finNext",
5955
+ startBinArrayIndex.toNumber(),
5956
+ maxBinArrayIndex.toNumber(),
5957
+ binArrayBitmapExtension
5958
+ );
5949
5959
  const binArrayIndex = findSetBit(
5950
5960
  startBinArrayIndex.toNumber(),
5951
5961
  maxBinArrayIndex.toNumber(),
@@ -6512,7 +6522,7 @@ async function getTokensMintFromPoolAddress(connection, poolAddress, opt) {
6512
6522
  );
6513
6523
  const program = new (0, _anchor.Program)(
6514
6524
  IDL,
6515
- LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _18 => _18.cluster]), () => ( "mainnet-beta"))],
6525
+ LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _20 => _20.cluster]), () => ( "mainnet-beta"))],
6516
6526
  provider
6517
6527
  );
6518
6528
  const poolAccount = await program.account.lbPair.fetchNullable(
@@ -6586,7 +6596,7 @@ async function getTokenBalance(conn, tokenAccount) {
6586
6596
  var parseLogs = (eventParser, logs) => {
6587
6597
  if (!logs.length)
6588
6598
  throw new Error("No logs found");
6589
- for (const event of _optionalChain([eventParser, 'optionalAccess', _19 => _19.parseLogs, 'call', _20 => _20(logs)])) {
6599
+ for (const event of _optionalChain([eventParser, 'optionalAccess', _21 => _21.parseLogs, 'call', _22 => _22(logs)])) {
6590
6600
  return event.data;
6591
6601
  }
6592
6602
  throw new Error("No events found");
@@ -6682,13 +6692,13 @@ var DLMM = class {
6682
6692
  );
6683
6693
  const program = new (0, _anchor.Program)(
6684
6694
  IDL,
6685
- LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _21 => _21.cluster]), () => ( "mainnet-beta"))],
6695
+ LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _23 => _23.cluster]), () => ( "mainnet-beta"))],
6686
6696
  provider
6687
6697
  );
6688
6698
  return program.account.lbPair.all();
6689
6699
  }
6690
6700
  static async getPairPubkeyIfExists(connection, tokenX, tokenY, binStep, baseFactor, opt) {
6691
- const cluster = _optionalChain([opt, 'optionalAccess', _22 => _22.cluster]) || "mainnet-beta";
6701
+ const cluster = _optionalChain([opt, 'optionalAccess', _24 => _24.cluster]) || "mainnet-beta";
6692
6702
  const provider = new (0, _anchor.AnchorProvider)(
6693
6703
  connection,
6694
6704
  {},
@@ -6731,7 +6741,7 @@ var DLMM = class {
6731
6741
  * @returns The `create` function returns a `Promise` that resolves to a `DLMM` object.
6732
6742
  */
6733
6743
  static async create(connection, dlmm, opt) {
6734
- const cluster = _optionalChain([opt, 'optionalAccess', _23 => _23.cluster]) || "mainnet-beta";
6744
+ const cluster = _optionalChain([opt, 'optionalAccess', _25 => _25.cluster]) || "mainnet-beta";
6735
6745
  const provider = new (0, _anchor.AnchorProvider)(
6736
6746
  connection,
6737
6747
  {},
@@ -6747,14 +6757,14 @@ var DLMM = class {
6747
6757
  connection,
6748
6758
  accountsToFetch
6749
6759
  );
6750
- const lbPairAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _24 => _24[0], 'optionalAccess', _25 => _25.data]);
6760
+ const lbPairAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _26 => _26[0], 'optionalAccess', _27 => _27.data]);
6751
6761
  if (!lbPairAccountInfoBuffer)
6752
6762
  throw new Error(`LB Pair account ${dlmm.toBase58()} not found`);
6753
6763
  const lbPairAccInfo = program.coder.accounts.decode(
6754
6764
  "lbPair",
6755
6765
  lbPairAccountInfoBuffer
6756
6766
  );
6757
- const binArrayBitMapAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _26 => _26[1], 'optionalAccess', _27 => _27.data]);
6767
+ const binArrayBitMapAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _28 => _28[1], 'optionalAccess', _29 => _29.data]);
6758
6768
  let binArrayBitMapExtensionAccInfo = null;
6759
6769
  if (binArrayBitMapAccountInfoBuffer) {
6760
6770
  binArrayBitMapExtensionAccInfo = program.coder.accounts.decode(
@@ -6818,7 +6828,7 @@ var DLMM = class {
6818
6828
  * objects.
6819
6829
  */
6820
6830
  static async createMultiple(connection, dlmmList, opt) {
6821
- const cluster = _optionalChain([opt, 'optionalAccess', _28 => _28.cluster]) || "mainnet-beta";
6831
+ const cluster = _optionalChain([opt, 'optionalAccess', _30 => _30.cluster]) || "mainnet-beta";
6822
6832
  const provider = new (0, _anchor.AnchorProvider)(
6823
6833
  connection,
6824
6834
  {},
@@ -6836,7 +6846,7 @@ var DLMM = class {
6836
6846
  const lbPairArraysMap = /* @__PURE__ */ new Map();
6837
6847
  for (let i = 0; i < dlmmList.length; i++) {
6838
6848
  const lbPairPubKey = dlmmList[i];
6839
- const lbPairAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _29 => _29[i], 'optionalAccess', _30 => _30.data]);
6849
+ const lbPairAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _31 => _31[i], 'optionalAccess', _32 => _32.data]);
6840
6850
  if (!lbPairAccountInfoBuffer)
6841
6851
  throw new Error(`LB Pair account ${lbPairPubKey.toBase58()} not found`);
6842
6852
  const binArrayAccInfo = program.coder.accounts.decode(
@@ -6849,7 +6859,7 @@ var DLMM = class {
6849
6859
  for (let i = dlmmList.length; i < accountsInfo.length; i++) {
6850
6860
  const index = i - dlmmList.length;
6851
6861
  const lbPairPubkey = dlmmList[index];
6852
- const binArrayBitMapAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _31 => _31[i], 'optionalAccess', _32 => _32.data]);
6862
+ const binArrayBitMapAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _33 => _33[i], 'optionalAccess', _34 => _34.data]);
6853
6863
  if (binArrayBitMapAccountInfoBuffer) {
6854
6864
  const binArrayBitMapExtensionAccInfo = program.coder.accounts.decode(
6855
6865
  "binArrayBitmapExtension",
@@ -6932,7 +6942,7 @@ var DLMM = class {
6932
6942
  );
6933
6943
  const program = new (0, _anchor.Program)(
6934
6944
  IDL,
6935
- LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _33 => _33.cluster]), () => ( "mainnet-beta"))],
6945
+ LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _35 => _35.cluster]), () => ( "mainnet-beta"))],
6936
6946
  provider
6937
6947
  );
6938
6948
  const presetParameter = await program.account.presetParameter.all();
@@ -6950,7 +6960,7 @@ var DLMM = class {
6950
6960
  * Pair account, and the value is an object of PositionInfo
6951
6961
  */
6952
6962
  static async getAllLbPairPositionsByUser(connection, userPubKey, opt) {
6953
- const cluster = _optionalChain([opt, 'optionalAccess', _34 => _34.cluster]) || "mainnet-beta";
6963
+ const cluster = _optionalChain([opt, 'optionalAccess', _36 => _36.cluster]) || "mainnet-beta";
6954
6964
  const provider = new (0, _anchor.AnchorProvider)(
6955
6965
  connection,
6956
6966
  {},
@@ -7185,8 +7195,8 @@ var DLMM = class {
7185
7195
  const { mintXDecimal, mintYDecimal } = lbPairMintMap.get(
7186
7196
  lbPair.toBase58()
7187
7197
  );
7188
- const reserveXBalance = _nullishCoalesce(_optionalChain([lbPairReserveMap, 'access', _35 => _35.get, 'call', _36 => _36(lbPair.toBase58()), 'optionalAccess', _37 => _37.reserveX]), () => ( BigInt(0)));
7189
- const reserveYBalance = _nullishCoalesce(_optionalChain([lbPairReserveMap, 'access', _38 => _38.get, 'call', _39 => _39(lbPair.toBase58()), 'optionalAccess', _40 => _40.reserveY]), () => ( BigInt(0)));
7198
+ const reserveXBalance = _nullishCoalesce(_optionalChain([lbPairReserveMap, 'access', _37 => _37.get, 'call', _38 => _38(lbPair.toBase58()), 'optionalAccess', _39 => _39.reserveX]), () => ( BigInt(0)));
7199
+ const reserveYBalance = _nullishCoalesce(_optionalChain([lbPairReserveMap, 'access', _40 => _40.get, 'call', _41 => _41(lbPair.toBase58()), 'optionalAccess', _42 => _42.reserveY]), () => ( BigInt(0)));
7190
7200
  const tokenX = {
7191
7201
  publicKey: lbPairAcc.tokenXMint,
7192
7202
  reserve: lbPairAcc.reserveX,
@@ -7218,7 +7228,7 @@ var DLMM = class {
7218
7228
  tokenX,
7219
7229
  tokenY,
7220
7230
  lbPairPositionsData: [
7221
- ..._nullishCoalesce(_optionalChain([positionsMap, 'access', _41 => _41.get, 'call', _42 => _42(lbPair.toBase58()), 'optionalAccess', _43 => _43.lbPairPositionsData]), () => ( [])),
7231
+ ..._nullishCoalesce(_optionalChain([positionsMap, 'access', _43 => _43.get, 'call', _44 => _44(lbPair.toBase58()), 'optionalAccess', _45 => _45.lbPairPositionsData]), () => ( [])),
7222
7232
  {
7223
7233
  publicKey: positionPubKey,
7224
7234
  positionData,
@@ -7254,8 +7264,8 @@ var DLMM = class {
7254
7264
  getTokenDecimals(program.provider.connection, lbPairAcc.tokenXMint),
7255
7265
  getTokenDecimals(program.provider.connection, lbPairAcc.tokenYMint)
7256
7266
  ]);
7257
- const reserveXBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _44 => _44.get, 'call', _45 => _45(lbPair.toBase58()), 'optionalAccess', _46 => _46.reserveX]), () => ( BigInt(0)));
7258
- const reserveYBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _47 => _47.get, 'call', _48 => _48(lbPair.toBase58()), 'optionalAccess', _49 => _49.reserveY]), () => ( BigInt(0)));
7267
+ const reserveXBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _46 => _46.get, 'call', _47 => _47(lbPair.toBase58()), 'optionalAccess', _48 => _48.reserveX]), () => ( BigInt(0)));
7268
+ const reserveYBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _49 => _49.get, 'call', _50 => _50(lbPair.toBase58()), 'optionalAccess', _51 => _51.reserveY]), () => ( BigInt(0)));
7259
7269
  const tokenX = {
7260
7270
  publicKey: lbPairAcc.tokenXMint,
7261
7271
  reserve: lbPairAcc.reserveX,
@@ -7287,7 +7297,7 @@ var DLMM = class {
7287
7297
  tokenX,
7288
7298
  tokenY,
7289
7299
  lbPairPositionsData: [
7290
- ..._nullishCoalesce(_optionalChain([positionsMap, 'access', _50 => _50.get, 'call', _51 => _51(lbPair.toBase58()), 'optionalAccess', _52 => _52.lbPairPositionsData]), () => ( [])),
7300
+ ..._nullishCoalesce(_optionalChain([positionsMap, 'access', _52 => _52.get, 'call', _53 => _53(lbPair.toBase58()), 'optionalAccess', _54 => _54.lbPairPositionsData]), () => ( [])),
7291
7301
  {
7292
7302
  publicKey: positionPubKey,
7293
7303
  positionData,
@@ -7300,7 +7310,7 @@ var DLMM = class {
7300
7310
  return positionsMap;
7301
7311
  }
7302
7312
  static async migratePosition(connection, positions, newPositions, walletPubkey, opt) {
7303
- const cluster = _optionalChain([opt, 'optionalAccess', _53 => _53.cluster]) || "mainnet-beta";
7313
+ const cluster = _optionalChain([opt, 'optionalAccess', _55 => _55.cluster]) || "mainnet-beta";
7304
7314
  const provider = new (0, _anchor.AnchorProvider)(
7305
7315
  connection,
7306
7316
  {},
@@ -7539,7 +7549,7 @@ var DLMM = class {
7539
7549
  swapForY,
7540
7550
  new (0, _anchor.BN)(activeIdToLoop),
7541
7551
  this.lbPair,
7542
- _nullishCoalesce(_optionalChain([this, 'access', _54 => _54.binArrayBitmapExtension, 'optionalAccess', _55 => _55.account]), () => ( null))
7552
+ _nullishCoalesce(_optionalChain([this, 'access', _56 => _56.binArrayBitmapExtension, 'optionalAccess', _57 => _57.account]), () => ( null))
7543
7553
  );
7544
7554
  if (binArrayIndex === null)
7545
7555
  shouldStop = true;
@@ -8975,7 +8985,7 @@ var DLMM = class {
8975
8985
  swapForY,
8976
8986
  activeId,
8977
8987
  this.lbPair,
8978
- _optionalChain([this, 'access', _56 => _56.binArrayBitmapExtension, 'optionalAccess', _57 => _57.account]),
8988
+ _optionalChain([this, 'access', _58 => _58.binArrayBitmapExtension, 'optionalAccess', _59 => _59.account]),
8979
8989
  binArrays
8980
8990
  );
8981
8991
  if (binArrayAccountToSwap == null) {
@@ -9082,7 +9092,7 @@ var DLMM = class {
9082
9092
  swapForY,
9083
9093
  activeId,
9084
9094
  this.lbPair,
9085
- _nullishCoalesce(_optionalChain([this, 'access', _58 => _58.binArrayBitmapExtension, 'optionalAccess', _59 => _59.account]), () => ( null)),
9095
+ _nullishCoalesce(_optionalChain([this, 'access', _60 => _60.binArrayBitmapExtension, 'optionalAccess', _61 => _61.account]), () => ( null)),
9086
9096
  binArrays
9087
9097
  );
9088
9098
  if (binArrayAccountToSwap == null) {
@@ -9808,7 +9818,7 @@ var DLMM = class {
9808
9818
  swapForY,
9809
9819
  new (0, _anchor.BN)(activeBinId),
9810
9820
  this.lbPair,
9811
- _nullishCoalesce(_optionalChain([this, 'access', _60 => _60.binArrayBitmapExtension, 'optionalAccess', _61 => _61.account]), () => ( null))
9821
+ _nullishCoalesce(_optionalChain([this, 'access', _62 => _62.binArrayBitmapExtension, 'optionalAccess', _63 => _63.account]), () => ( null))
9812
9822
  );
9813
9823
  if (toBinArrayIndex === null)
9814
9824
  return true;
@@ -9845,7 +9855,7 @@ var DLMM = class {
9845
9855
  swapForY,
9846
9856
  new (0, _anchor.BN)(activeBinId),
9847
9857
  this.lbPair,
9848
- _nullishCoalesce(_optionalChain([this, 'access', _62 => _62.binArrayBitmapExtension, 'optionalAccess', _63 => _63.account]), () => ( null))
9858
+ _nullishCoalesce(_optionalChain([this, 'access', _64 => _64.binArrayBitmapExtension, 'optionalAccess', _65 => _65.account]), () => ( null))
9849
9859
  );
9850
9860
  const accountsToFetch = [];
9851
9861
  const [binArrayBitMapExtensionPubkey] = deriveBinArrayBitmapExtension(
@@ -9876,13 +9886,13 @@ var DLMM = class {
9876
9886
  let fromBinArray = null;
9877
9887
  let toBinArray = null;
9878
9888
  let binArrayBitmapExtension = null;
9879
- if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _64 => _64[0]])) {
9889
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _66 => _66[0]])) {
9880
9890
  binArrayBitmapExtension = binArrayBitMapExtensionPubkey;
9881
9891
  }
9882
- if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _65 => _65[1]])) {
9892
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _67 => _67[1]])) {
9883
9893
  fromBinArray = fromBinArrayPubkey;
9884
9894
  }
9885
- if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _66 => _66[2]]) && !!toBinArrayIndex) {
9895
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _68 => _68[2]]) && !!toBinArrayIndex) {
9886
9896
  toBinArray = toBinArrayPubkey;
9887
9897
  }
9888
9898
  const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
@@ -10519,7 +10529,7 @@ var DLMMError = class extends Error {
10519
10529
  const anchorError = _anchor.AnchorError.parse(
10520
10530
  JSON.parse(JSON.stringify(error)).logs
10521
10531
  );
10522
- if (_optionalChain([anchorError, 'optionalAccess', _67 => _67.program, 'access', _68 => _68.toBase58, 'call', _69 => _69()]) === LBCLMM_PROGRAM_IDS["mainnet-beta"]) {
10532
+ if (_optionalChain([anchorError, 'optionalAccess', _69 => _69.program, 'access', _70 => _70.toBase58, 'call', _71 => _71()]) === LBCLMM_PROGRAM_IDS["mainnet-beta"]) {
10523
10533
  _errorCode = anchorError.error.errorCode.number;
10524
10534
  _errorName = anchorError.error.errorCode.code;
10525
10535
  _errorMessage = anchorError.error.errorMessage;