@streamflow/stream 9.2.0 → 9.2.1-alpha.p321.02efd07

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.
@@ -463,6 +463,10 @@ declare class SolanaStreamClient extends BaseStreamClient {
463
463
  * @returns Record of stream data
464
464
  */
465
465
  searchStreams(data: ISearchStreams): Promise<IProgramAccount<Stream>[]>;
466
+ private decodeStreamsFromAccounts;
467
+ private collectAlignedEntries;
468
+ private fetchAlignedProxiesByEntries;
469
+ private mapDecodedToProgramAccounts;
466
470
  /**
467
471
  * Attempts updating the stream auto withdrawal params and amount per period
468
472
  * @param {IUpdateData} data - Update parameters including stream ID and new settings
@@ -6269,20 +6269,41 @@ var SolanaStreamClient = class extends BaseStreamClient {
6269
6269
  const accounts = await this.connection.getProgramAccounts(this.programId, {
6270
6270
  filters
6271
6271
  });
6272
- const mapped = await Promise.all(
6273
- accounts.map(async ({ pubkey, account }) => {
6274
- const stream = decodeStream(account.data);
6275
- if (this.isAlignedUnlock(pubkey, stream.sender)) {
6276
- const alignedProxy = await this.alignedProxyProgram.account.contract.fetch(
6277
- deriveContractPDA(this.alignedProxyProgram.programId, pubkey)
6278
- );
6279
- common.invariant(alignedProxy, "Couldn't get aligned proxy account info");
6280
- return { publicKey: pubkey, account: new AlignedContract(stream, alignedProxy) };
6281
- }
6282
- return { publicKey: pubkey, account: new Contract2(stream) };
6283
- })
6284
- );
6285
- return mapped;
6272
+ const decoded = this.decodeStreamsFromAccounts(accounts);
6273
+ const alignedEntries = this.collectAlignedEntries(decoded);
6274
+ const alignedProxies = await this.fetchAlignedProxiesByEntries(alignedEntries);
6275
+ return this.mapDecodedToProgramAccounts(decoded, alignedEntries, alignedProxies);
6276
+ }
6277
+ decodeStreamsFromAccounts(accounts) {
6278
+ return accounts.map(({ pubkey, account }) => ({
6279
+ pubkey,
6280
+ stream: decodeStream(account.data)
6281
+ }));
6282
+ }
6283
+ collectAlignedEntries(decoded) {
6284
+ const entries = [];
6285
+ decoded.forEach(({ pubkey, stream }, index) => {
6286
+ if (this.isAlignedUnlock(pubkey, stream.sender)) {
6287
+ entries.push({ index, pda: deriveContractPDA(this.alignedProxyProgram.programId, pubkey) });
6288
+ }
6289
+ });
6290
+ return entries;
6291
+ }
6292
+ async fetchAlignedProxiesByEntries(aligned) {
6293
+ if (aligned.length === 0) return [];
6294
+ const res = await this.alignedProxyProgram.account.contract.fetchMultiple(aligned.map((a) => a.pda));
6295
+ return res;
6296
+ }
6297
+ mapDecodedToProgramAccounts(decoded, alignedEntries, alignedProxies) {
6298
+ return decoded.map(({ pubkey, stream }, idx) => {
6299
+ const alignedIdx = alignedEntries.findIndex((a) => a.index === idx);
6300
+ if (alignedIdx !== -1) {
6301
+ const alignedProxy = alignedProxies[alignedIdx];
6302
+ common.invariant(alignedProxy, "Couldn't get aligned proxy account info");
6303
+ return { publicKey: pubkey, account: new AlignedContract(stream, alignedProxy) };
6304
+ }
6305
+ return { publicKey: pubkey, account: new Contract2(stream) };
6306
+ });
6286
6307
  }
6287
6308
  /**
6288
6309
  * Attempts updating the stream auto withdrawal params and amount per period