@meteora-ag/dlmm 1.3.12 → 1.3.13

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.mjs CHANGED
@@ -8345,6 +8345,117 @@ var DLMM = class {
8345
8345
  const binId = new Decimal5(price).log().dividedBy(new Decimal5(1).add(binStepNum).log());
8346
8346
  return (min ? binId.floor() : binId.ceil()).toNumber();
8347
8347
  }
8348
+ /**
8349
+ * The function `getLbPairLockInfo` retrieves all pair positions that has locked liquidity.
8350
+ * @param {number} [lockDurationOpt] - An optional value indicating the minimum position lock duration that the function should return.
8351
+ * Depending on the lbPair activationType, the param should be a number of seconds or a number of slots.
8352
+ * @returns The function `getLbPairLockInfo` returns a `Promise` that resolves to a `PairLockInfo`
8353
+ * object. The `PairLockInfo` object contains an array of `PositionLockInfo` objects.
8354
+ */
8355
+ async getLbPairLockInfo(lockDurationOpt) {
8356
+ const lockDuration = lockDurationOpt | 0;
8357
+ const lbPairPositions = await this.program.account.positionV2.all([
8358
+ {
8359
+ memcmp: {
8360
+ bytes: bs58.encode(this.pubkey.toBuffer()),
8361
+ offset: 8
8362
+ }
8363
+ }
8364
+ ]);
8365
+ const clockAccInfo = await this.program.provider.connection.getAccountInfo(SYSVAR_CLOCK_PUBKEY);
8366
+ const clock = ClockLayout.decode(clockAccInfo.data);
8367
+ const currentPoint = this.lbPair.activationType == 0 /* Slot */ ? clock.slot : clock.unixTimestamp;
8368
+ const minLockReleasePoint = currentPoint.add(new BN10(lockDuration));
8369
+ const positionsWithLock = lbPairPositions.filter((p) => p.account.lockReleasePoint.gt(minLockReleasePoint));
8370
+ if (positionsWithLock.length == 0) {
8371
+ return {
8372
+ positions: []
8373
+ };
8374
+ }
8375
+ const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
8376
+ positionsWithLock.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
8377
+ const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
8378
+ const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinId));
8379
+ const [lowerBinArrayPubKey] = deriveBinArray(
8380
+ this.pubkey,
8381
+ lowerBinArrayIndex,
8382
+ this.program.programId
8383
+ );
8384
+ const [upperBinArrayPubKey] = deriveBinArray(
8385
+ this.pubkey,
8386
+ upperBinArrayIndex,
8387
+ this.program.programId
8388
+ );
8389
+ binArrayPubkeySetV2.add(lowerBinArrayPubKey.toBase58());
8390
+ binArrayPubkeySetV2.add(upperBinArrayPubKey.toBase58());
8391
+ });
8392
+ const binArrayPubkeyArrayV2 = Array.from(binArrayPubkeySetV2).map(
8393
+ (pubkey) => new PublicKey7(pubkey)
8394
+ );
8395
+ const binArraysAccInfo = await chunkedGetMultipleAccountInfos(
8396
+ this.program.provider.connection,
8397
+ binArrayPubkeyArrayV2
8398
+ );
8399
+ const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
8400
+ for (let i = 0; i < binArraysAccInfo.length; i++) {
8401
+ const binArrayPubkey = binArrayPubkeyArrayV2[i];
8402
+ const binArrayAccBufferV2 = binArraysAccInfo[i];
8403
+ if (!binArrayAccBufferV2)
8404
+ throw new Error(
8405
+ `Bin Array account ${binArrayPubkey.toBase58()} not found`
8406
+ );
8407
+ const binArrayAccInfo = this.program.coder.accounts.decode(
8408
+ "binArray",
8409
+ binArrayAccBufferV2.data
8410
+ );
8411
+ positionBinArraysMapV2.set(binArrayPubkey.toBase58(), binArrayAccInfo);
8412
+ }
8413
+ const positionsLockInfo = await Promise.all(
8414
+ positionsWithLock.map(async ({ publicKey, account }) => {
8415
+ const { lowerBinId, upperBinId, feeOwner } = account;
8416
+ const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
8417
+ const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinId));
8418
+ const [lowerBinArrayPubKey] = deriveBinArray(
8419
+ this.pubkey,
8420
+ lowerBinArrayIndex,
8421
+ this.program.programId
8422
+ );
8423
+ const [upperBinArrayPubKey] = deriveBinArray(
8424
+ this.pubkey,
8425
+ upperBinArrayIndex,
8426
+ this.program.programId
8427
+ );
8428
+ const lowerBinArray = positionBinArraysMapV2.get(
8429
+ lowerBinArrayPubKey.toBase58()
8430
+ );
8431
+ const upperBinArray = positionBinArraysMapV2.get(
8432
+ upperBinArrayPubKey.toBase58()
8433
+ );
8434
+ const positionData = await DLMM.processPosition(
8435
+ this.program,
8436
+ 1 /* V2 */,
8437
+ this.lbPair,
8438
+ clock.unixTimestamp.toNumber(),
8439
+ account,
8440
+ this.tokenX.decimal,
8441
+ this.tokenY.decimal,
8442
+ lowerBinArray,
8443
+ upperBinArray,
8444
+ feeOwner
8445
+ );
8446
+ return {
8447
+ positionAddress: publicKey,
8448
+ owner: account.owner,
8449
+ lockReleasePoint: account.lockReleasePoint.toNumber(),
8450
+ tokenXAmount: positionData.totalXAmount,
8451
+ tokenYAmount: positionData.totalYAmount
8452
+ };
8453
+ })
8454
+ );
8455
+ return {
8456
+ positions: positionsLockInfo
8457
+ };
8458
+ }
8348
8459
  /** Public methods */
8349
8460
  static async createPermissionLbPair(connection, binStep, tokenX, tokenY, activeId, baseKey, creatorKey, feeBps, activationType, opt) {
8350
8461
  const provider = new AnchorProvider2(