@meteora-ag/dlmm 1.9.2 → 1.9.3

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
@@ -15649,6 +15649,71 @@ async function chunkedGetMultipleAccountInfos(connection, pks, chunkSize = 100)
15649
15649
  )).flat();
15650
15650
  return accountInfos;
15651
15651
  }
15652
+ async function chunkedGetProgramAccounts(connection, programId, filters, chunkSize = 100, onChunkFetched, isParallelExecution = false) {
15653
+ const accountsWithoutData = await connection.getProgramAccounts(programId, {
15654
+ filters,
15655
+ dataSlice: { offset: 0, length: 0 }
15656
+ });
15657
+ if (accountsWithoutData.length === 0) {
15658
+ return [];
15659
+ }
15660
+ const pubkeys = accountsWithoutData.map((account) => account.pubkey);
15661
+ const totalAccounts = pubkeys.length;
15662
+ const chunkedPks = chunks(pubkeys, chunkSize);
15663
+ const totalChunks = chunkedPks.length;
15664
+ let chunksLoaded = 0;
15665
+ let accountsLoaded = 0;
15666
+ const chunkResults = new Array(totalChunks);
15667
+ const processChunk = async (chunk, chunkIndex) => {
15668
+ const chunkAccountInfos = await connection.getMultipleAccountsInfo(chunk);
15669
+ chunkResults[chunkIndex] = chunkAccountInfos;
15670
+ if (onChunkFetched) {
15671
+ const chunkAccounts = [];
15672
+ const startIdx = chunkIndex * chunkSize;
15673
+ for (let i = 0; i < chunkAccountInfos.length; i++) {
15674
+ const accountInfo = chunkAccountInfos[i];
15675
+ if (accountInfo) {
15676
+ chunkAccounts.push({
15677
+ pubkey: pubkeys[startIdx + i],
15678
+ account: accountInfo
15679
+ });
15680
+ }
15681
+ }
15682
+ chunksLoaded++;
15683
+ accountsLoaded += chunkAccounts.length;
15684
+ onChunkFetched(chunkAccounts, {
15685
+ chunksLoaded,
15686
+ totalChunks,
15687
+ accountsLoaded,
15688
+ totalAccounts
15689
+ });
15690
+ }
15691
+ };
15692
+ if (isParallelExecution) {
15693
+ await Promise.all(
15694
+ chunkedPks.map((chunk, chunkIndex) => processChunk(chunk, chunkIndex))
15695
+ );
15696
+ } else {
15697
+ for (let chunkIndex = 0; chunkIndex < chunkedPks.length; chunkIndex++) {
15698
+ await processChunk(chunkedPks[chunkIndex], chunkIndex);
15699
+ }
15700
+ }
15701
+ const result = [];
15702
+ for (let chunkIndex = 0; chunkIndex < chunkResults.length; chunkIndex++) {
15703
+ const chunkAccountInfos = chunkResults[chunkIndex];
15704
+ const startIdx = chunkIndex * chunkSize;
15705
+ for (let i = 0; i < chunkAccountInfos.length; i++) {
15706
+ const accountInfo = chunkAccountInfos[i];
15707
+ if (accountInfo) {
15708
+ result.push({
15709
+ pubkey: pubkeys[startIdx + i],
15710
+ account: accountInfo
15711
+ });
15712
+ }
15713
+ }
15714
+ }
15715
+ return result;
15716
+ }
15652
15717
  var getEstimatedComputeUnitUsageWithBuffer = async (connection, instructions, feePayer, buffer, altAddress) => {
15653
15718
  if (!buffer) {
15654
15719
  buffer = 0.1;
@@ -16669,17 +16734,20 @@ var DLMM = class {
16669
16734
  * class, which represents the connection to the Solana blockchain.
16670
16735
  * @param {PublicKey} userPubKey - The user's wallet public key.
16671
16736
  * @param {Opt} [opt] - An optional object that contains additional options for the function.
16737
+ * @param {GetPositionsOpt} [getPositionsOpt] - Optional settings for chunked position fetching
16672
16738
  * @returns The function `getAllLbPairPositionsByUser` returns a `Promise` that resolves to a `Map`
16673
16739
  * object. The `Map` object contains key-value pairs, where the key is a string representing the LB
16674
16740
  * Pair account, and the value is an object of PositionInfo
16675
16741
  */
16676
- static async getAllLbPairPositionsByUser(connection, userPubKey, opt) {
16742
+ static async getAllLbPairPositionsByUser(connection, userPubKey, opt, getPositionsOpt) {
16677
16743
  const program = createProgram(connection, opt);
16678
- const positionsV2 = await program.provider.connection.getProgramAccounts(
16744
+ const positionsV2 = await chunkedGetProgramAccounts(
16745
+ program.provider.connection,
16679
16746
  program.programId,
16680
- {
16681
- filters: [positionV2Filter(), positionOwnerFilter(userPubKey)]
16682
- }
16747
+ [positionV2Filter(), positionOwnerFilter(userPubKey)],
16748
+ getPositionsOpt?.chunkSize,
16749
+ getPositionsOpt?.onChunkFetched,
16750
+ getPositionsOpt?.isParallelExecution
16683
16751
  );
16684
16752
  const positionWrappers = [
16685
16753
  ...positionsV2.map((p) => wrapPosition(program, p.pubkey, p.account))
@@ -16873,16 +16941,19 @@ var DLMM = class {
16873
16941
  * The function `getLbPairLockInfo` retrieves all pair positions that has locked liquidity.
16874
16942
  * @param {number} [lockDurationOpt] - An optional value indicating the minimum position lock duration that the function should return.
16875
16943
  * Depending on the lbPair activationType, the param should be a number of seconds or a number of slots.
16944
+ * @param {GetPositionsOpt} [getPositionsOpt] - Optional settings for chunked position fetching
16876
16945
  * @returns The function `getLbPairLockInfo` returns a `Promise` that resolves to a `PairLockInfo`
16877
16946
  * object. The `PairLockInfo` object contains an array of `PositionLockInfo` objects.
16878
16947
  */
16879
- async getLbPairLockInfo(lockDurationOpt) {
16948
+ async getLbPairLockInfo(lockDurationOpt, getPositionsOpt) {
16880
16949
  const lockDuration = lockDurationOpt | 0;
16881
- const positionAccounts = await this.program.provider.connection.getProgramAccounts(
16950
+ const positionAccounts = await chunkedGetProgramAccounts(
16951
+ this.program.provider.connection,
16882
16952
  this.program.programId,
16883
- {
16884
- filters: [positionLbPairFilter(this.pubkey)]
16885
- }
16953
+ [positionLbPairFilter(this.pubkey)],
16954
+ getPositionsOpt?.chunkSize,
16955
+ getPositionsOpt?.onChunkFetched,
16956
+ getPositionsOpt?.isParallelExecution
16886
16957
  );
16887
16958
  const lbPairPositions = positionAccounts.map((acc) => {
16888
16959
  return wrapPosition(this.program, acc.pubkey, acc.account);
@@ -17776,24 +17847,27 @@ var DLMM = class {
17776
17847
  * `PublicKey`. It represents the public key of a user. If no `userPubKey` is provided, the function
17777
17848
  * will return an object with an empty `userPositions` array and the active bin information obtained
17778
17849
  * from the `getActive
17850
+ * @param {GetPositionsOpt} [getPositionsOpt] - Optional settings for chunked position fetching
17779
17851
  * @returns The function `getPositionsByUserAndLbPair` returns a Promise that resolves to an object
17780
17852
  * with two properties:
17781
17853
  * - "activeBin" which is an object with two properties: "binId" and "price". The value of "binId"
17782
17854
  * is the active bin ID of the lbPair, and the value of "price" is the price of the active bin.
17783
17855
  * - "userPositions" which is an array of Position objects.
17784
17856
  */
17785
- async getPositionsByUserAndLbPair(userPubKey) {
17857
+ async getPositionsByUserAndLbPair(userPubKey, getPositionsOpt) {
17786
17858
  const promiseResults = await Promise.all([
17787
17859
  this.getActiveBin(),
17788
- userPubKey && this.program.provider.connection.getProgramAccounts(
17860
+ userPubKey && chunkedGetProgramAccounts(
17861
+ this.program.provider.connection,
17789
17862
  this.program.programId,
17790
- {
17791
- filters: [
17792
- positionV2Filter(),
17793
- positionOwnerFilter(userPubKey),
17794
- positionLbPairFilter(this.pubkey)
17795
- ]
17796
- }
17863
+ [
17864
+ positionV2Filter(),
17865
+ positionOwnerFilter(userPubKey),
17866
+ positionLbPairFilter(this.pubkey)
17867
+ ],
17868
+ getPositionsOpt?.chunkSize,
17869
+ getPositionsOpt?.onChunkFetched,
17870
+ getPositionsOpt?.isParallelExecution
17797
17871
  )
17798
17872
  ]);
17799
17873
  const [activeBin, positionsV2] = promiseResults;
@@ -22300,6 +22374,7 @@ export {
22300
22374
  chunkedFetchMultipleBinArrayBitmapExtensionAccount,
22301
22375
  chunkedFetchMultiplePoolAccount,
22302
22376
  chunkedGetMultipleAccountInfos,
22377
+ chunkedGetProgramAccounts,
22303
22378
  chunks,
22304
22379
  computeFee,
22305
22380
  computeFeeFromAmount,