@meteora-ag/dlmm 1.0.19-abc123.2 → 1.0.19

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
@@ -5059,7 +5059,7 @@ declare class DLMM {
5059
5059
  /** private */
5060
5060
  declare function derivePresetParameter(binStep: BN, programId: PublicKey): [PublicKey, number];
5061
5061
  declare function deriveLbPair(tokenX: PublicKey, tokenY: PublicKey, binStep: BN, programId: PublicKey): [PublicKey, number];
5062
- declare function checkPoolExists(connection: Connection, tokenX: PublicKey, tokenY: PublicKey, binStep: BN, programId: PublicKey): Promise<boolean>;
5062
+ declare function checkPoolExists(connection: Connection, tokenX: PublicKey, tokenY: PublicKey, binStep: BN, programId: PublicKey): Promise<PublicKey | false>;
5063
5063
  declare function deriveOracle(lbPair: PublicKey, programId: PublicKey): [PublicKey, number];
5064
5064
  declare function derivePosition(mint: PublicKey, programId: PublicKey): [PublicKey, number];
5065
5065
  declare function deriveBinArray(lbPair: PublicKey, index: BN, programId: PublicKey): [PublicKey, number];
package/dist/index.js CHANGED
@@ -4560,33 +4560,55 @@ function derivePresetParameter(binStep, programId) {
4560
4560
  function deriveLbPair(tokenX, tokenY, binStep, programId) {
4561
4561
  const [minKey, maxKey] = sortTokenMints(tokenX, tokenY);
4562
4562
  return _web3js.PublicKey.findProgramAddressSync(
4563
- [minKey.toBuffer(), maxKey.toBuffer(), new Uint8Array(binStep.toArrayLike(Buffer, "le", 2))],
4563
+ [
4564
+ minKey.toBuffer(),
4565
+ maxKey.toBuffer(),
4566
+ new Uint8Array(binStep.toArrayLike(Buffer, "le", 2))
4567
+ ],
4564
4568
  programId
4565
4569
  );
4566
4570
  }
4567
4571
  async function checkPoolExists(connection, tokenX, tokenY, binStep, programId) {
4568
- const [lbPairKey] = deriveLbPair(tokenX, tokenY, binStep, programId);
4569
- const dlmm = await DLMM.create(connection, lbPairKey);
4570
- const { activeId } = await dlmm.program.account.lbPair.fetch(lbPairKey);
4571
- return !!activeId;
4572
+ try {
4573
+ const [lbPairKey] = deriveLbPair(tokenX, tokenY, binStep, programId);
4574
+ const dlmm = await DLMM.create(connection, lbPairKey);
4575
+ await dlmm.program.account.lbPair.fetch(lbPairKey);
4576
+ return lbPairKey;
4577
+ } catch (e2) {
4578
+ return false;
4579
+ }
4572
4580
  }
4573
4581
  function deriveOracle(lbPair, programId) {
4574
- return _web3js.PublicKey.findProgramAddressSync([Buffer.from("oracle"), lbPair.toBytes()], programId);
4582
+ return _web3js.PublicKey.findProgramAddressSync(
4583
+ [Buffer.from("oracle"), lbPair.toBytes()],
4584
+ programId
4585
+ );
4575
4586
  }
4576
4587
  function derivePosition(mint, programId) {
4577
- return _web3js.PublicKey.findProgramAddressSync([Buffer.from("position"), mint.toBuffer()], programId);
4588
+ return _web3js.PublicKey.findProgramAddressSync(
4589
+ [Buffer.from("position"), mint.toBuffer()],
4590
+ programId
4591
+ );
4578
4592
  }
4579
4593
  function deriveBinArray(lbPair, index, programId) {
4580
4594
  let binArrayBytes;
4581
4595
  if (index.isNeg()) {
4582
- binArrayBytes = new Uint8Array(index.toTwos(64).toBuffer("le", 8));
4596
+ binArrayBytes = new Uint8Array(
4597
+ index.toTwos(64).toArrayLike(Buffer, "le", 8)
4598
+ );
4583
4599
  } else {
4584
- binArrayBytes = new Uint8Array(index.toBuffer("le", 8));
4600
+ binArrayBytes = new Uint8Array(index.toArrayLike(Buffer, "le", 8));
4585
4601
  }
4586
- return _web3js.PublicKey.findProgramAddressSync([Buffer.from("bin_array"), lbPair.toBytes(), binArrayBytes], programId);
4602
+ return _web3js.PublicKey.findProgramAddressSync(
4603
+ [Buffer.from("bin_array"), lbPair.toBytes(), binArrayBytes],
4604
+ programId
4605
+ );
4587
4606
  }
4588
4607
  function deriveReserve(token, lbPair, programId) {
4589
- return _web3js.PublicKey.findProgramAddressSync([lbPair.toBuffer(), token.toBuffer()], programId);
4608
+ return _web3js.PublicKey.findProgramAddressSync(
4609
+ [lbPair.toBuffer(), token.toBuffer()],
4610
+ programId
4611
+ );
4590
4612
  }
4591
4613
 
4592
4614
  // src/dlmm/helpers/binArray.ts