@meteora-ag/dlmm 1.4.1 → 1.4.3-rc.0

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
@@ -5767,6 +5767,7 @@ declare class DLMM {
5767
5767
  */
5768
5768
  static getLbPairs(connection: Connection, opt?: Opt): Promise<LbPairAccount[]>;
5769
5769
  static getPairPubkeyIfExists(connection: Connection, tokenX: PublicKey, tokenY: PublicKey, binStep: BN, baseFactor: BN, opt?: Opt): Promise<PublicKey | null>;
5770
+ static getCustomizablePermissionlessLbPairIfExists(connection: Connection, tokenX: PublicKey, tokenY: PublicKey, opt?: Opt): Promise<PublicKey | null>;
5770
5771
  /**
5771
5772
  * The `create` function is a static method that creates a new instance of the `DLMM` class
5772
5773
  * @param {Connection} connection - The `connection` parameter is an instance of the `Connection`
package/dist/index.js CHANGED
@@ -6643,7 +6643,7 @@ function derivePosition(lbPair, base, lowerBinId, width, programId) {
6643
6643
  lbPair.toBuffer(),
6644
6644
  base.toBuffer(),
6645
6645
  lowerBinIdBytes,
6646
- new Uint8Array(width.toBuffer("le", 4))
6646
+ new Uint8Array(width.toArrayLike(Buffer, "le", 4))
6647
6647
  ],
6648
6648
  programId
6649
6649
  );
@@ -7889,6 +7889,32 @@ var DLMM = class {
7889
7889
  return null;
7890
7890
  }
7891
7891
  }
7892
+ static async getCustomizablePermissionlessLbPairIfExists(connection, tokenX, tokenY, opt) {
7893
+ const cluster = _optionalChain([opt, 'optionalAccess', _36 => _36.cluster]) || "mainnet-beta";
7894
+ const provider = new (0, _anchor.AnchorProvider)(
7895
+ connection,
7896
+ {},
7897
+ _anchor.AnchorProvider.defaultOptions()
7898
+ );
7899
+ const program = new (0, _anchor.Program)(
7900
+ IDL,
7901
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _37 => _37.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
7902
+ provider
7903
+ );
7904
+ try {
7905
+ const [lpPair] = deriveCustomizablePermissionlessLbPair(
7906
+ tokenX,
7907
+ tokenY,
7908
+ program.programId
7909
+ );
7910
+ const account = await program.account.lbPair.fetchNullable(lpPair);
7911
+ if (account)
7912
+ return lpPair;
7913
+ return null;
7914
+ } catch (error) {
7915
+ return null;
7916
+ }
7917
+ }
7892
7918
  /**
7893
7919
  * The `create` function is a static method that creates a new instance of the `DLMM` class
7894
7920
  * @param {Connection} connection - The `connection` parameter is an instance of the `Connection`
@@ -7899,7 +7925,7 @@ var DLMM = class {
7899
7925
  * @returns The `create` function returns a `Promise` that resolves to a `DLMM` object.
7900
7926
  */
7901
7927
  static async create(connection, dlmm, opt) {
7902
- const cluster = _optionalChain([opt, 'optionalAccess', _36 => _36.cluster]) || "mainnet-beta";
7928
+ const cluster = _optionalChain([opt, 'optionalAccess', _38 => _38.cluster]) || "mainnet-beta";
7903
7929
  const provider = new (0, _anchor.AnchorProvider)(
7904
7930
  connection,
7905
7931
  {},
@@ -7907,7 +7933,7 @@ var DLMM = class {
7907
7933
  );
7908
7934
  const program = new (0, _anchor.Program)(
7909
7935
  IDL,
7910
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _37 => _37.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
7936
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _39 => _39.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
7911
7937
  provider
7912
7938
  );
7913
7939
  const binArrayBitMapExtensionPubkey = deriveBinArrayBitmapExtension(
@@ -7923,14 +7949,14 @@ var DLMM = class {
7923
7949
  connection,
7924
7950
  accountsToFetch
7925
7951
  );
7926
- const lbPairAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _38 => _38[0], 'optionalAccess', _39 => _39.data]);
7952
+ const lbPairAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _40 => _40[0], 'optionalAccess', _41 => _41.data]);
7927
7953
  if (!lbPairAccountInfoBuffer)
7928
7954
  throw new Error(`LB Pair account ${dlmm.toBase58()} not found`);
7929
7955
  const lbPairAccInfo = program.coder.accounts.decode(
7930
7956
  "lbPair",
7931
7957
  lbPairAccountInfoBuffer
7932
7958
  );
7933
- const binArrayBitMapAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _40 => _40[1], 'optionalAccess', _41 => _41.data]);
7959
+ const binArrayBitMapAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _42 => _42[1], 'optionalAccess', _43 => _43.data]);
7934
7960
  let binArrayBitMapExtensionAccInfo = null;
7935
7961
  if (binArrayBitMapAccountInfoBuffer) {
7936
7962
  binArrayBitMapExtensionAccInfo = program.coder.accounts.decode(
@@ -7938,7 +7964,7 @@ var DLMM = class {
7938
7964
  binArrayBitMapAccountInfoBuffer
7939
7965
  );
7940
7966
  }
7941
- const clockAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _42 => _42[2], 'optionalAccess', _43 => _43.data]);
7967
+ const clockAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _44 => _44[2], 'optionalAccess', _45 => _45.data]);
7942
7968
  if (!clockAccountInfoBuffer)
7943
7969
  throw new Error(`Clock account not found`);
7944
7970
  const clock = ClockLayout.decode(clockAccountInfoBuffer);
@@ -7999,7 +8025,7 @@ var DLMM = class {
7999
8025
  * objects.
8000
8026
  */
8001
8027
  static async createMultiple(connection, dlmmList, opt) {
8002
- const cluster = _optionalChain([opt, 'optionalAccess', _44 => _44.cluster]) || "mainnet-beta";
8028
+ const cluster = _optionalChain([opt, 'optionalAccess', _46 => _46.cluster]) || "mainnet-beta";
8003
8029
  const provider = new (0, _anchor.AnchorProvider)(
8004
8030
  connection,
8005
8031
  {},
@@ -8007,7 +8033,7 @@ var DLMM = class {
8007
8033
  );
8008
8034
  const program = new (0, _anchor.Program)(
8009
8035
  IDL,
8010
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _45 => _45.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
8036
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _47 => _47.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
8011
8037
  provider
8012
8038
  );
8013
8039
  const binArrayBitMapExtensions = dlmmList.map(
@@ -8023,14 +8049,14 @@ var DLMM = class {
8023
8049
  accountsToFetch
8024
8050
  );
8025
8051
  const clockAccount = accountsInfo.pop();
8026
- const clockAccountInfoBuffer = _optionalChain([clockAccount, 'optionalAccess', _46 => _46.data]);
8052
+ const clockAccountInfoBuffer = _optionalChain([clockAccount, 'optionalAccess', _48 => _48.data]);
8027
8053
  if (!clockAccountInfoBuffer)
8028
8054
  throw new Error(`Clock account not found`);
8029
8055
  const clock = ClockLayout.decode(clockAccountInfoBuffer);
8030
8056
  const lbPairArraysMap = /* @__PURE__ */ new Map();
8031
8057
  for (let i = 0; i < dlmmList.length; i++) {
8032
8058
  const lbPairPubKey = dlmmList[i];
8033
- const lbPairAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _47 => _47[i], 'optionalAccess', _48 => _48.data]);
8059
+ const lbPairAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _49 => _49[i], 'optionalAccess', _50 => _50.data]);
8034
8060
  if (!lbPairAccountInfoBuffer)
8035
8061
  throw new Error(`LB Pair account ${lbPairPubKey.toBase58()} not found`);
8036
8062
  const binArrayAccInfo = program.coder.accounts.decode(
@@ -8043,7 +8069,7 @@ var DLMM = class {
8043
8069
  for (let i = dlmmList.length; i < accountsInfo.length; i++) {
8044
8070
  const index = i - dlmmList.length;
8045
8071
  const lbPairPubkey = dlmmList[index];
8046
- const binArrayBitMapAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _49 => _49[i], 'optionalAccess', _50 => _50.data]);
8072
+ const binArrayBitMapAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _51 => _51[i], 'optionalAccess', _52 => _52.data]);
8047
8073
  if (binArrayBitMapAccountInfoBuffer) {
8048
8074
  const binArrayBitMapExtensionAccInfo = program.coder.accounts.decode(
8049
8075
  "binArrayBitmapExtension",
@@ -8127,7 +8153,7 @@ var DLMM = class {
8127
8153
  );
8128
8154
  const program = new (0, _anchor.Program)(
8129
8155
  IDL,
8130
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _51 => _51.programId]), () => ( LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _52 => _52.cluster]), () => ( "mainnet-beta"))])),
8156
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _53 => _53.programId]), () => ( LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _54 => _54.cluster]), () => ( "mainnet-beta"))])),
8131
8157
  provider
8132
8158
  );
8133
8159
  const presetParameter = await program.account.presetParameter.all();
@@ -8145,7 +8171,7 @@ var DLMM = class {
8145
8171
  * Pair account, and the value is an object of PositionInfo
8146
8172
  */
8147
8173
  static async getAllLbPairPositionsByUser(connection, userPubKey, opt) {
8148
- const cluster = _optionalChain([opt, 'optionalAccess', _53 => _53.cluster]) || "mainnet-beta";
8174
+ const cluster = _optionalChain([opt, 'optionalAccess', _55 => _55.cluster]) || "mainnet-beta";
8149
8175
  const provider = new (0, _anchor.AnchorProvider)(
8150
8176
  connection,
8151
8177
  {},
@@ -8153,7 +8179,7 @@ var DLMM = class {
8153
8179
  );
8154
8180
  const program = new (0, _anchor.Program)(
8155
8181
  IDL,
8156
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _54 => _54.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
8182
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _56 => _56.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
8157
8183
  provider
8158
8184
  );
8159
8185
  const positionsV2 = await program.account.positionV2.all([
@@ -8287,8 +8313,8 @@ var DLMM = class {
8287
8313
  getTokenDecimals(program.provider.connection, lbPairAcc.tokenXMint),
8288
8314
  getTokenDecimals(program.provider.connection, lbPairAcc.tokenYMint)
8289
8315
  ]);
8290
- const reserveXBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _55 => _55.get, 'call', _56 => _56(lbPair.toBase58()), 'optionalAccess', _57 => _57.reserveX]), () => ( BigInt(0)));
8291
- const reserveYBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _58 => _58.get, 'call', _59 => _59(lbPair.toBase58()), 'optionalAccess', _60 => _60.reserveY]), () => ( BigInt(0)));
8316
+ const reserveXBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _57 => _57.get, 'call', _58 => _58(lbPair.toBase58()), 'optionalAccess', _59 => _59.reserveX]), () => ( BigInt(0)));
8317
+ const reserveYBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _60 => _60.get, 'call', _61 => _61(lbPair.toBase58()), 'optionalAccess', _62 => _62.reserveY]), () => ( BigInt(0)));
8292
8318
  const tokenX = {
8293
8319
  publicKey: lbPairAcc.tokenXMint,
8294
8320
  reserve: lbPairAcc.reserveX,
@@ -8334,7 +8360,7 @@ var DLMM = class {
8334
8360
  tokenX,
8335
8361
  tokenY,
8336
8362
  lbPairPositionsData: [
8337
- ..._nullishCoalesce(_optionalChain([positionsMap, 'access', _61 => _61.get, 'call', _62 => _62(lbPair.toBase58()), 'optionalAccess', _63 => _63.lbPairPositionsData]), () => ( [])),
8363
+ ..._nullishCoalesce(_optionalChain([positionsMap, 'access', _63 => _63.get, 'call', _64 => _64(lbPair.toBase58()), 'optionalAccess', _65 => _65.lbPairPositionsData]), () => ( [])),
8338
8364
  {
8339
8365
  publicKey: positionPubKey,
8340
8366
  positionData,
@@ -8474,7 +8500,7 @@ var DLMM = class {
8474
8500
  );
8475
8501
  const program = new (0, _anchor.Program)(
8476
8502
  IDL,
8477
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _64 => _64.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8503
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _66 => _66.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8478
8504
  provider
8479
8505
  );
8480
8506
  const [lbPair] = derivePermissionLbPair(
@@ -8523,7 +8549,7 @@ var DLMM = class {
8523
8549
  );
8524
8550
  const program = new (0, _anchor.Program)(
8525
8551
  IDL,
8526
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _65 => _65.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8552
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _67 => _67.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8527
8553
  provider
8528
8554
  );
8529
8555
  const [lbPair] = deriveCustomizablePermissionlessLbPair(
@@ -8573,7 +8599,7 @@ var DLMM = class {
8573
8599
  );
8574
8600
  const program = new (0, _anchor.Program)(
8575
8601
  IDL,
8576
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _66 => _66.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8602
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _68 => _68.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8577
8603
  provider
8578
8604
  );
8579
8605
  const existsPool = await this.getPairPubkeyIfExists(
@@ -8686,7 +8712,8 @@ var DLMM = class {
8686
8712
  * @returns a Promise that resolves to the transaction.
8687
8713
  */
8688
8714
  async setPairStatusPermissionless(enable, creator) {
8689
- const tx = await this.program.methods.setPairStatusPermissionless(Number(enable)).accounts({
8715
+ const status = enable ? 0 : 1;
8716
+ const tx = await this.program.methods.setPairStatusPermissionless(status).accounts({
8690
8717
  lbPair: this.pubkey,
8691
8718
  creator
8692
8719
  }).transaction();
@@ -8729,7 +8756,7 @@ var DLMM = class {
8729
8756
  swapForY,
8730
8757
  new (0, _anchor.BN)(activeIdToLoop),
8731
8758
  this.lbPair,
8732
- _nullishCoalesce(_optionalChain([this, 'access', _67 => _67.binArrayBitmapExtension, 'optionalAccess', _68 => _68.account]), () => ( null))
8759
+ _nullishCoalesce(_optionalChain([this, 'access', _69 => _69.binArrayBitmapExtension, 'optionalAccess', _70 => _70.account]), () => ( null))
8733
8760
  );
8734
8761
  if (binArrayIndex === null)
8735
8762
  shouldStop = true;
@@ -10220,7 +10247,7 @@ var DLMM = class {
10220
10247
  swapForY,
10221
10248
  activeId,
10222
10249
  this.lbPair,
10223
- _nullishCoalesce(_optionalChain([this, 'access', _69 => _69.binArrayBitmapExtension, 'optionalAccess', _70 => _70.account]), () => ( null)),
10250
+ _nullishCoalesce(_optionalChain([this, 'access', _71 => _71.binArrayBitmapExtension, 'optionalAccess', _72 => _72.account]), () => ( null)),
10224
10251
  binArrays
10225
10252
  );
10226
10253
  if (binArrayAccountToSwap == null) {
@@ -10280,7 +10307,7 @@ var DLMM = class {
10280
10307
  swapForY,
10281
10308
  activeId,
10282
10309
  this.lbPair,
10283
- _nullishCoalesce(_optionalChain([this, 'access', _71 => _71.binArrayBitmapExtension, 'optionalAccess', _72 => _72.account]), () => ( null)),
10310
+ _nullishCoalesce(_optionalChain([this, 'access', _73 => _73.binArrayBitmapExtension, 'optionalAccess', _74 => _74.account]), () => ( null)),
10284
10311
  binArrays
10285
10312
  );
10286
10313
  if (binArrayAccountToSwap == null) {
@@ -10364,7 +10391,7 @@ var DLMM = class {
10364
10391
  swapForY,
10365
10392
  activeId,
10366
10393
  this.lbPair,
10367
- _nullishCoalesce(_optionalChain([this, 'access', _73 => _73.binArrayBitmapExtension, 'optionalAccess', _74 => _74.account]), () => ( null)),
10394
+ _nullishCoalesce(_optionalChain([this, 'access', _75 => _75.binArrayBitmapExtension, 'optionalAccess', _76 => _76.account]), () => ( null)),
10368
10395
  binArrays
10369
10396
  );
10370
10397
  if (binArrayAccountToSwap == null) {
@@ -10442,7 +10469,7 @@ var DLMM = class {
10442
10469
  swapForY,
10443
10470
  activeId,
10444
10471
  this.lbPair,
10445
- _nullishCoalesce(_optionalChain([this, 'access', _75 => _75.binArrayBitmapExtension, 'optionalAccess', _76 => _76.account]), () => ( null)),
10472
+ _nullishCoalesce(_optionalChain([this, 'access', _77 => _77.binArrayBitmapExtension, 'optionalAccess', _78 => _78.account]), () => ( null)),
10446
10473
  binArrays
10447
10474
  );
10448
10475
  if (binArrayAccountToSwap == null) {
@@ -11181,13 +11208,6 @@ var DLMM = class {
11181
11208
  );
11182
11209
  }
11183
11210
  if (instructions.length > 1) {
11184
- instructions.push(
11185
- await getEstimatedComputeUnitIxWithBuffer(
11186
- this.program.provider.connection,
11187
- instructions,
11188
- payer
11189
- )
11190
- );
11191
11211
  initializeBinArraysAndPositionIxs.push(instructions);
11192
11212
  instructions = [];
11193
11213
  }
@@ -11648,7 +11668,7 @@ var DLMM = class {
11648
11668
  swapForY,
11649
11669
  new (0, _anchor.BN)(activeBinId),
11650
11670
  this.lbPair,
11651
- _nullishCoalesce(_optionalChain([this, 'access', _77 => _77.binArrayBitmapExtension, 'optionalAccess', _78 => _78.account]), () => ( null))
11671
+ _nullishCoalesce(_optionalChain([this, 'access', _79 => _79.binArrayBitmapExtension, 'optionalAccess', _80 => _80.account]), () => ( null))
11652
11672
  );
11653
11673
  if (toBinArrayIndex === null)
11654
11674
  return true;
@@ -11685,7 +11705,7 @@ var DLMM = class {
11685
11705
  swapForY,
11686
11706
  new (0, _anchor.BN)(activeBinId),
11687
11707
  this.lbPair,
11688
- _nullishCoalesce(_optionalChain([this, 'access', _79 => _79.binArrayBitmapExtension, 'optionalAccess', _80 => _80.account]), () => ( null))
11708
+ _nullishCoalesce(_optionalChain([this, 'access', _81 => _81.binArrayBitmapExtension, 'optionalAccess', _82 => _82.account]), () => ( null))
11689
11709
  );
11690
11710
  const accountsToFetch = [];
11691
11711
  const [binArrayBitMapExtensionPubkey] = deriveBinArrayBitmapExtension(
@@ -11716,13 +11736,13 @@ var DLMM = class {
11716
11736
  let fromBinArray = null;
11717
11737
  let toBinArray = null;
11718
11738
  let binArrayBitmapExtension = null;
11719
- if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _81 => _81[0]])) {
11739
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _83 => _83[0]])) {
11720
11740
  binArrayBitmapExtension = binArrayBitMapExtensionPubkey;
11721
11741
  }
11722
- if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _82 => _82[1]])) {
11742
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _84 => _84[1]])) {
11723
11743
  fromBinArray = fromBinArrayPubkey;
11724
11744
  }
11725
- if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _83 => _83[2]]) && !!toBinArrayIndex) {
11745
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _85 => _85[2]]) && !!toBinArrayIndex) {
11726
11746
  toBinArray = toBinArrayPubkey;
11727
11747
  }
11728
11748
  const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
@@ -12198,7 +12218,7 @@ var DLMM = class {
12198
12218
  const [lowerBinId2] = getBinArrayLowerUpperBinId(index);
12199
12219
  return bins.map((b, i) => [lowerBinId2.toNumber() + i, b]);
12200
12220
  }));
12201
- const version = _nullishCoalesce(_optionalChain([binArrays, 'access', _84 => _84.find, 'call', _85 => _85((binArray) => binArray != null), 'optionalAccess', _86 => _86.version]), () => ( 1));
12221
+ const version = _nullishCoalesce(_optionalChain([binArrays, 'access', _86 => _86.find, 'call', _87 => _87((binArray) => binArray != null), 'optionalAccess', _88 => _88.version]), () => ( 1));
12202
12222
  return Array.from(enumerateBins(
12203
12223
  binsById,
12204
12224
  lowerBinId,