@streamflow/stream 9.2.0-alpha.p0.5034440 → 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
@@ -5592,6 +5592,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
5592
5592
  const metadatas = [];
5593
5593
  const metadataToRecipient = {};
5594
5594
  const instructionsBatch = [];
5595
+ const metadataPubKeys = metadataPubKeysExt || [];
5595
5596
  const partnerPublicKey = data.partner ? new web3_js.PublicKey(data.partner) : WITHDRAWOR_PUBLIC_KEY;
5596
5597
  const mintPublicKey = new web3_js.PublicKey(data.tokenId);
5597
5598
  if (recipients.length === 0) {
@@ -5601,8 +5602,8 @@ var SolanaStreamClient = class extends BaseStreamClient {
5601
5602
  const recipientData = recipients[i];
5602
5603
  const createStreamData = { ...streamParams, ...recipientData };
5603
5604
  const createStreamExtParams = {
5604
- ...extParams,
5605
- metadataPubKeys: metadataPubKeysExt?.[i] ? [metadataPubKeysExt[i]] : void 0
5605
+ metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : void 0,
5606
+ ...extParams
5606
5607
  };
5607
5608
  const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(
5608
5609
  createStreamData,
@@ -6268,20 +6269,41 @@ var SolanaStreamClient = class extends BaseStreamClient {
6268
6269
  const accounts = await this.connection.getProgramAccounts(this.programId, {
6269
6270
  filters
6270
6271
  });
6271
- const mapped = await Promise.all(
6272
- accounts.map(async ({ pubkey, account }) => {
6273
- const stream = decodeStream(account.data);
6274
- if (this.isAlignedUnlock(pubkey, stream.sender)) {
6275
- const alignedProxy = await this.alignedProxyProgram.account.contract.fetch(
6276
- deriveContractPDA(this.alignedProxyProgram.programId, pubkey)
6277
- );
6278
- common.invariant(alignedProxy, "Couldn't get aligned proxy account info");
6279
- return { publicKey: pubkey, account: new AlignedContract(stream, alignedProxy) };
6280
- }
6281
- return { publicKey: pubkey, account: new Contract2(stream) };
6282
- })
6283
- );
6284
- 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
+ });
6285
6307
  }
6286
6308
  /**
6287
6309
  * Attempts updating the stream auto withdrawal params and amount per period