@streamflow/stream 11.0.1 → 11.0.2

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.
@@ -142,7 +142,7 @@ var AlignedProxyErrorCode = /* @__PURE__ */ ((AlignedProxyErrorCode2) => {
142
142
  return AlignedProxyErrorCode2;
143
143
  })(AlignedProxyErrorCode || {});
144
144
  var Contract = class {
145
- constructor(stream) {
145
+ constructor(stream, metadata) {
146
146
  this.magic = stream.magic.toNumber();
147
147
  this.version = stream.version.toNumber();
148
148
  this.createdAt = stream.createdAt.toNumber();
@@ -186,6 +186,7 @@ var Contract = class {
186
186
  this.lastRateChangeTime = stream.lastRateChangeTime.toNumber();
187
187
  this.fundsUnlockedAtLastRateChange = stream.fundsUnlockedAtLastRateChange;
188
188
  this.oldMetadata = stream.oldMetadata;
189
+ this.metadata = metadata;
189
190
  this.type = buildStreamType(this);
190
191
  this.isAligned = false;
191
192
  }
@@ -200,8 +201,8 @@ var Contract = class {
200
201
  }
201
202
  };
202
203
  var AlignedContract = class extends Contract {
203
- constructor(stream, alignedProxy) {
204
- super(stream);
204
+ constructor(stream, metadata, alignedProxy) {
205
+ super(stream, metadata);
205
206
  this.minPrice = common.getNumberFromBN(alignedProxy.minPrice, ALIGNED_PRECISION_FACTOR_POW);
206
207
  this.maxPrice = common.getNumberFromBN(alignedProxy.maxPrice, ALIGNED_PRECISION_FACTOR_POW);
207
208
  this.minPercentage = common.getNumberFromBN(alignedProxy.minPercentage, ALIGNED_PRECISION_FACTOR_POW);
@@ -495,7 +496,7 @@ var encodeUpdateStream = (values, data) => {
495
496
  var topupStreamLayout = BufferLayout__namespace.struct([
496
497
  BufferLayout__namespace.blob(8, "amount")
497
498
  ]);
498
- var getMetadataKey = (streamPubkey, oldMetadata) => {
499
+ var getOriginalMetadataKey = (streamPubkey, oldMetadata) => {
499
500
  if (web3_js.PublicKey.default.equals(oldMetadata)) {
500
501
  return streamPubkey;
501
502
  }
@@ -3603,7 +3604,7 @@ var SolanaStreamClient = class {
3603
3604
  }
3604
3605
  async decodeStreamAccount(pubkey, data) {
3605
3606
  const stream = decodeStream(data);
3606
- const metadataKey = getMetadataKey(pubkey, stream.oldMetadata);
3607
+ const metadataKey = getOriginalMetadataKey(pubkey, stream.oldMetadata);
3607
3608
  if (this.isAlignedUnlock(pubkey, stream.sender, stream.oldMetadata)) {
3608
3609
  const alignedProxy = await this.alignedProxyProgram.account.contract.fetch(
3609
3610
  deriveContractPDA(this.alignedProxyProgram.programId, metadataKey)
@@ -3611,9 +3612,9 @@ var SolanaStreamClient = class {
3611
3612
  if (!alignedProxy) {
3612
3613
  throw new Error("Couldn't get proxy account info.");
3613
3614
  }
3614
- return new AlignedContract(stream, alignedProxy);
3615
+ return new AlignedContract(stream, common.pk(pubkey), alignedProxy);
3615
3616
  }
3616
- return new Contract(stream);
3617
+ return new Contract(stream, common.pk(pubkey));
3617
3618
  }
3618
3619
  /**
3619
3620
  * Fetch all aligned outgoing streams/contracts by the provided public key.
@@ -3638,7 +3639,7 @@ var SolanaStreamClient = class {
3638
3639
  streamAccounts.forEach((account, index) => {
3639
3640
  if (account) {
3640
3641
  const alignedData = alignedOutgoingProgramAccounts[index].account;
3641
- streams[streamPubKeys[index].toBase58()] = new AlignedContract(decodeStream(account.data), alignedData);
3642
+ streams[streamPubKeys[index].toBase58()] = new AlignedContract(decodeStream(account.data), common.pk(streamPubKeys[index]), alignedData);
3642
3643
  }
3643
3644
  });
3644
3645
  return streams;
@@ -3648,7 +3649,7 @@ var SolanaStreamClient = class {
3648
3649
  const alignedStreamsPubKeys = Object.keys(streamRecord);
3649
3650
  const alignedProxyPDAs = alignedStreamsPubKeys.map((streamPubKey) => {
3650
3651
  const pubkey = new web3_js.PublicKey(streamPubKey);
3651
- const metadataKey = getMetadataKey(pubkey, streamRecord[streamPubKey].oldMetadata);
3652
+ const metadataKey = getOriginalMetadataKey(pubkey, streamRecord[streamPubKey].oldMetadata);
3652
3653
  return deriveContractPDA(this.alignedProxyProgram.programId, metadataKey);
3653
3654
  });
3654
3655
  const alignedProxyAccounts = await common.getMultipleAccountsInfoBatched(this.connection, alignedProxyPDAs);
@@ -3657,6 +3658,7 @@ var SolanaStreamClient = class {
3657
3658
  const alignedData = streamRecord[alignedStreamsPubKeys[index]];
3658
3659
  streams[alignedStreamsPubKeys[index]] = new AlignedContract(
3659
3660
  alignedData,
3661
+ common.pk(alignedStreamsPubKeys[index]),
3660
3662
  this.alignedProxyProgram.account.contract.coder.accounts.decode("contract", account.data)
3661
3663
  );
3662
3664
  }
@@ -3685,7 +3687,7 @@ var SolanaStreamClient = class {
3685
3687
  this.programId
3686
3688
  );
3687
3689
  outgoingStreamAccounts.forEach((account) => {
3688
- streams[account.pubkey.toBase58()] = new Contract(decodeStream(account.account.data));
3690
+ streams[account.pubkey.toBase58()] = new Contract(decodeStream(account.account.data), common.pk(account.pubkey));
3689
3691
  });
3690
3692
  if (shouldFetchAligned) {
3691
3693
  const alignedStreams = await this.getOutgoingAlignedStreams(address);
@@ -3705,7 +3707,7 @@ var SolanaStreamClient = class {
3705
3707
  if (this.isAlignedUnlock(account.pubkey, allIncomingStreams[index].sender, allIncomingStreams[index].oldMetadata)) {
3706
3708
  alignedDecoded[account.pubkey.toBase58()] = allIncomingStreams[index];
3707
3709
  } else {
3708
- streams[account.pubkey.toBase58()] = new Contract(allIncomingStreams[index]);
3710
+ streams[account.pubkey.toBase58()] = new Contract(allIncomingStreams[index], common.pk(account.pubkey));
3709
3711
  }
3710
3712
  });
3711
3713
  if (shouldFetchAligned) {
@@ -3748,7 +3750,7 @@ var SolanaStreamClient = class {
3748
3750
  const entries = [];
3749
3751
  decoded.forEach(({ pubkey, stream }, index) => {
3750
3752
  if (this.isAlignedUnlock(pubkey, stream.sender, stream.oldMetadata)) {
3751
- const metadataKey = getMetadataKey(pubkey, stream.oldMetadata);
3753
+ const metadataKey = getOriginalMetadataKey(pubkey, stream.oldMetadata);
3752
3754
  entries.push({ index, pda: deriveContractPDA(this.alignedProxyProgram.programId, metadataKey) });
3753
3755
  }
3754
3756
  });
@@ -3765,9 +3767,9 @@ var SolanaStreamClient = class {
3765
3767
  if (alignedIdx !== -1) {
3766
3768
  const alignedProxy = alignedProxies[alignedIdx];
3767
3769
  common.invariant(alignedProxy, "Couldn't get aligned proxy account info");
3768
- return { publicKey: pubkey, account: new AlignedContract(stream, alignedProxy) };
3770
+ return { publicKey: pubkey, account: new AlignedContract(stream, common.pk(pubkey), alignedProxy) };
3769
3771
  }
3770
- return { publicKey: pubkey, account: new Contract(stream) };
3772
+ return { publicKey: pubkey, account: new Contract(stream, common.pk(pubkey)) };
3771
3773
  });
3772
3774
  }
3773
3775
  /**
@@ -3905,7 +3907,7 @@ var SolanaStreamClient = class {
3905
3907
  * For migrated streams, the PDA was derived from the old metadata key.
3906
3908
  */
3907
3909
  isAlignedUnlock(streamPublicKey, senderPublicKey, oldMetadata) {
3908
- const metadataKey = oldMetadata ? getMetadataKey(streamPublicKey, oldMetadata) : streamPublicKey;
3910
+ const metadataKey = oldMetadata ? getOriginalMetadataKey(streamPublicKey, oldMetadata) : streamPublicKey;
3909
3911
  const pda = deriveContractPDA(this.alignedProxyProgram.programId, metadataKey);
3910
3912
  return senderPublicKey.equals(pda);
3911
3913
  }
@@ -4453,7 +4455,7 @@ exports.deriveContractPDA = deriveContractPDA;
4453
4455
  exports.deriveEscrowPDA = deriveEscrowPDA;
4454
4456
  exports.deriveTestOraclePDA = deriveTestOraclePDA;
4455
4457
  exports.extractSolanaErrorCode = extractSolanaErrorCode;
4456
- exports.getMetadataKey = getMetadataKey;
4458
+ exports.getOriginalMetadataKey = getOriginalMetadataKey;
4457
4459
  exports.handleContractError = handleContractError;
4458
4460
  exports.isAligned = isAligned;
4459
4461
  exports.isCliffCloseToDepositedAmount = isCliffCloseToDepositedAmount;