@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.
@@ -1,4 +1,4 @@
1
- export { Z as Account, a5 as AlignedContract, M as AlignedUnlocksContract, a8 as BatchItem, aa as BatchItemError, ab as BatchItemResult, a9 as BatchItemSuccess, U as ChangeOracleParams, y as ClientCreationOptions, a4 as Contract, R as CreateParams, V as CreateTestOracleParams, a6 as DecodedStream, $ as ICreateSolanaExt, a3 as ICreateStreamInstructions, I as ICreateStreamSolanaExt, a as IInteractStreamSolanaExt, a1 as IPrepareCreateStreamSolanaExt, a2 as IPrepareStreamSolanaExt, Y as ISearchStreams, b as ITopUpStreamSolanaExt, a0 as ITransactionSolanaExtWithInstructions, ac as InstructionGenerator, a7 as MetadataRecipientHashMap, N as OracleType, S as SolanaStreamClient, Q as TestOracle, X as UpdateTestOracleParams, ah as cancelStreamInstruction, x as constants, ad as createStreamInstruction, ae as createUncheckedStreamInstruction, z as decodeStream, J as deriveContractPDA, K as deriveEscrowPDA, L as deriveTestOraclePDA, H as extractSolanaErrorCode, G as sendAndConfirmStreamRawTransaction, B as signAllTransactionWithRecipients, _ as timelockIDL, aj as topupStreamInstruction, ai as transferStreamInstruction, ag as updateStreamInstruction, af as withdrawStreamInstruction } from '../index-DsFyl13W.js';
1
+ export { Z as Account, a5 as AlignedContract, M as AlignedUnlocksContract, a8 as BatchItem, aa as BatchItemError, ab as BatchItemResult, a9 as BatchItemSuccess, U as ChangeOracleParams, y as ClientCreationOptions, a4 as Contract, R as CreateParams, V as CreateTestOracleParams, a6 as DecodedStream, $ as ICreateSolanaExt, a3 as ICreateStreamInstructions, I as ICreateStreamSolanaExt, a as IInteractStreamSolanaExt, a1 as IPrepareCreateStreamSolanaExt, a2 as IPrepareStreamSolanaExt, Y as ISearchStreams, b as ITopUpStreamSolanaExt, a0 as ITransactionSolanaExtWithInstructions, ac as InstructionGenerator, a7 as MetadataRecipientHashMap, N as OracleType, S as SolanaStreamClient, Q as TestOracle, X as UpdateTestOracleParams, ah as cancelStreamInstruction, x as constants, ad as createStreamInstruction, ae as createUncheckedStreamInstruction, z as decodeStream, J as deriveContractPDA, K as deriveEscrowPDA, L as deriveTestOraclePDA, H as extractSolanaErrorCode, G as sendAndConfirmStreamRawTransaction, B as signAllTransactionWithRecipients, _ as timelockIDL, aj as topupStreamInstruction, ai as transferStreamInstruction, ag as updateStreamInstruction, af as withdrawStreamInstruction } from '../index-DLVKn7Ae.js';
2
2
  export { ContractError, IChain, ICluster } from '@streamflow/common';
3
3
  import 'p-queue';
4
4
  import '@solana/web3.js';
@@ -3649,20 +3649,41 @@ var SolanaStreamClient = class extends BaseStreamClient {
3649
3649
  const accounts = await this.connection.getProgramAccounts(this.programId, {
3650
3650
  filters
3651
3651
  });
3652
- const mapped = await Promise.all(
3653
- accounts.map(async ({ pubkey, account }) => {
3654
- const stream = decodeStream(account.data);
3655
- if (this.isAlignedUnlock(pubkey, stream.sender)) {
3656
- const alignedProxy = await this.alignedProxyProgram.account.contract.fetch(
3657
- deriveContractPDA(this.alignedProxyProgram.programId, pubkey)
3658
- );
3659
- invariant(alignedProxy, "Couldn't get aligned proxy account info");
3660
- return { publicKey: pubkey, account: new AlignedContract(stream, alignedProxy) };
3661
- }
3662
- return { publicKey: pubkey, account: new Contract(stream) };
3663
- })
3664
- );
3665
- return mapped;
3652
+ const decoded = this.decodeStreamsFromAccounts(accounts);
3653
+ const alignedEntries = this.collectAlignedEntries(decoded);
3654
+ const alignedProxies = await this.fetchAlignedProxiesByEntries(alignedEntries);
3655
+ return this.mapDecodedToProgramAccounts(decoded, alignedEntries, alignedProxies);
3656
+ }
3657
+ decodeStreamsFromAccounts(accounts) {
3658
+ return accounts.map(({ pubkey, account }) => ({
3659
+ pubkey,
3660
+ stream: decodeStream(account.data)
3661
+ }));
3662
+ }
3663
+ collectAlignedEntries(decoded) {
3664
+ const entries = [];
3665
+ decoded.forEach(({ pubkey, stream }, index) => {
3666
+ if (this.isAlignedUnlock(pubkey, stream.sender)) {
3667
+ entries.push({ index, pda: deriveContractPDA(this.alignedProxyProgram.programId, pubkey) });
3668
+ }
3669
+ });
3670
+ return entries;
3671
+ }
3672
+ async fetchAlignedProxiesByEntries(aligned) {
3673
+ if (aligned.length === 0) return [];
3674
+ const res = await this.alignedProxyProgram.account.contract.fetchMultiple(aligned.map((a) => a.pda));
3675
+ return res;
3676
+ }
3677
+ mapDecodedToProgramAccounts(decoded, alignedEntries, alignedProxies) {
3678
+ return decoded.map(({ pubkey, stream }, idx) => {
3679
+ const alignedIdx = alignedEntries.findIndex((a) => a.index === idx);
3680
+ if (alignedIdx !== -1) {
3681
+ const alignedProxy = alignedProxies[alignedIdx];
3682
+ invariant(alignedProxy, "Couldn't get aligned proxy account info");
3683
+ return { publicKey: pubkey, account: new AlignedContract(stream, alignedProxy) };
3684
+ }
3685
+ return { publicKey: pubkey, account: new Contract(stream) };
3686
+ });
3666
3687
  }
3667
3688
  /**
3668
3689
  * Attempts updating the stream auto withdrawal params and amount per period