@streamflow/stream 11.0.0 → 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.
@@ -166,6 +166,8 @@ interface LinearStream {
166
166
  pauseCumulative: BN;
167
167
  lastRateChangeTime: number;
168
168
  fundsUnlockedAtLastRateChange: BN;
169
+ oldMetadata: PublicKey;
170
+ metadata: PublicKey;
169
171
  type: StreamType;
170
172
  unlocked(currentTimestamp: number): BN;
171
173
  remaining(decimals: number): number;
@@ -395,9 +397,11 @@ declare class Contract implements LinearStream {
395
397
  pauseCumulative: BN;
396
398
  lastRateChangeTime: number;
397
399
  fundsUnlockedAtLastRateChange: BN;
400
+ oldMetadata: PublicKey;
401
+ metadata: PublicKey;
398
402
  type: StreamType;
399
403
  isAligned: boolean;
400
- constructor(stream: DecodedStream);
404
+ constructor(stream: DecodedStream, metadata: PublicKey);
401
405
  unlocked(currentTimestamp: number): BN;
402
406
  remaining(decimals: number): number;
403
407
  }
@@ -418,7 +422,7 @@ declare class AlignedContract extends Contract implements AlignedStream {
418
422
  expiryTime: number;
419
423
  expiryPercentage: number;
420
424
  floorPrice: number;
421
- constructor(stream: DecodedStream, alignedProxy: AlignedUnlocksContract);
425
+ constructor(stream: DecodedStream, metadata: PublicKey, alignedProxy: AlignedUnlocksContract);
422
426
  }
423
427
  interface DecodedStream {
424
428
  magic: BN;
@@ -463,6 +467,7 @@ interface DecodedStream {
463
467
  pauseCumulative: BN;
464
468
  lastRateChangeTime: BN;
465
469
  fundsUnlockedAtLastRateChange: BN;
470
+ oldMetadata: PublicKey;
466
471
  }
467
472
  interface MetadataRecipientHashMap {
468
473
  [metadataPubKey: string]: IRecipient;
@@ -733,6 +738,7 @@ declare class SolanaStreamClient {
733
738
  * @returns Stream data
734
739
  */
735
740
  getOne({ id }: IGetOneData): Promise<Stream>;
741
+ private decodeStreamAccount;
736
742
  /**
737
743
  * Fetch all aligned outgoing streams/contracts by the provided public key.
738
744
  * @param {string} sender - Sender public key
@@ -801,9 +807,10 @@ declare class SolanaStreamClient {
801
807
  */
802
808
  extractErrorCode(err: Error): string | null;
803
809
  /**
804
- * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
810
+ * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA.
811
+ * For migrated streams, the PDA was derived from the old metadata key.
805
812
  */
806
- isAlignedUnlock(streamPublicKey: PublicKey, senderPublicKey: PublicKey): boolean;
813
+ isAlignedUnlock(streamPublicKey: PublicKey, senderPublicKey: PublicKey, oldMetadata?: PublicKey): boolean;
807
814
  private flatBuildCreateMultipleTransactionInstructions;
808
815
  /**
809
816
  * Utility function to generate metadata for a Contract or return existing Pubkey
@@ -816,6 +823,12 @@ declare class SolanaStreamClient {
816
823
  private applyCustomAfterInstructions;
817
824
  }
818
825
 
826
+ /**
827
+ * Returns the key that should be used for PDA derivation.
828
+ * For migrated streams, the aligned proxy PDA was derived from the original (old) metadata key,
829
+ * so we need to use that instead of the current stream pubkey.
830
+ */
831
+ declare const getOriginalMetadataKey: (streamPubkey: PublicKey, oldMetadata: PublicKey) => PublicKey;
819
832
  /**
820
833
  * Calculate total amount of a Contract including all fees.
821
834
  * - first we convert fee floating to a BN with up to 4 decimals precision
@@ -1058,6 +1071,7 @@ declare const STREAM_STRUCT_OFFSET_SENDER = 49;
1058
1071
  declare const STREAM_STRUCT_OFFSET_RECIPIENT = 113;
1059
1072
  declare const STREAM_STRUCT_OFFSET_MINT = 177;
1060
1073
  declare const STREAM_STRUCT_OFFSET_CLOSED = 671;
1074
+ declare const STREAM_STRUCT_OFFSET_OLD_METADATA_KEY = 714;
1061
1075
  declare const MAX_SAFE_UNIX_TIME_VALUE = 8640000000000;
1062
1076
  declare const WITHDRAW_AVAILABLE_AMOUNT: BN;
1063
1077
  declare const ALIGNED_PRECISION_FACTOR_POW = 9;
@@ -1171,4 +1185,4 @@ declare const _default: {
1171
1185
  }[];
1172
1186
  };
1173
1187
 
1174
- export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, type Account, AlignedContract, AlignedProxyErrorCode, type AlignedStream, type AlignedStreamData, type AlignedUnlocksContract, type BatchItem, type BatchItemError, type BatchItemResult, type BatchItemSuccess, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, type ChangeOracleParams, type ClientCreationOptions, Contract, ContractErrorCode, type CreateParams, type CreateTestOracleParams, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, type DecodedStream, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, type IAlignedStreamConfig, type IBaseStreamConfig, type ICancelData, type ICreateAlignedStreamData, type ICreateExt, type ICreateLinearStreamData, type ICreateMultiError, type ICreateMultipleAlignedStreamData, type ICreateMultipleLinearStreamData, type ICreateMultipleStreamData, type ICreateResult, type ICreateStreamData, type ICreateStreamExt, type ICreateStreamInstructions, type IFees, type IGetAllData, type IGetFeesData, type IGetOneData, type IInteractData, type IInteractStreamExt, type IMultiTransactionResult, type IPrepareCreateStreamExt, type IPrepareStreamExt, type IRecipient, type ISearchStreams, type ITopUpData, type ITopUpStreamExt, type ITransactionExtWithInstructions, type ITransactionResult, type ITransferData, type IUpdateData, type IWithdrawData, type InstructionGenerator, type LinearStream, MAX_SAFE_UNIX_TIME_VALUE, type MetadataRecipientHashMap, ORIGINAL_CONTRACT_SENDER_OFFSET, type OracleType, type OracleTypeName, PARTNERS_SCHEMA, PARTNER_ORACLE_PROGRAM_ID, PARTNER_SCHEMA, PROGRAM_ID, SOLANA_ERROR_MAP, SOLANA_ERROR_MATCH_REGEX, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSETS, STREAM_STRUCT_OFFSET_CLOSED, STREAM_STRUCT_OFFSET_MINT, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, SolanaStreamClient, type Stream, type StreamClientOptions, StreamDirection, StreamType, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, type TestOracle, type TransactionSchedulingOptions, type UpdateTestOracleParams, WITHDRAWOR, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, createStreamInstruction, createUncheckedStreamInstruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveTestOraclePDA, extractSolanaErrorCode, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isTokenLock, isVesting, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, _default as timelockIDL, topupStreamInstruction, transferStreamInstruction, updateStreamInstruction, withdrawStreamInstruction };
1188
+ export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, type Account, AlignedContract, AlignedProxyErrorCode, type AlignedStream, type AlignedStreamData, type AlignedUnlocksContract, type BatchItem, type BatchItemError, type BatchItemResult, type BatchItemSuccess, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, type ChangeOracleParams, type ClientCreationOptions, Contract, ContractErrorCode, type CreateParams, type CreateTestOracleParams, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, type DecodedStream, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, type IAlignedStreamConfig, type IBaseStreamConfig, type ICancelData, type ICreateAlignedStreamData, type ICreateExt, type ICreateLinearStreamData, type ICreateMultiError, type ICreateMultipleAlignedStreamData, type ICreateMultipleLinearStreamData, type ICreateMultipleStreamData, type ICreateResult, type ICreateStreamData, type ICreateStreamExt, type ICreateStreamInstructions, type IFees, type IGetAllData, type IGetFeesData, type IGetOneData, type IInteractData, type IInteractStreamExt, type IMultiTransactionResult, type IPrepareCreateStreamExt, type IPrepareStreamExt, type IRecipient, type ISearchStreams, type ITopUpData, type ITopUpStreamExt, type ITransactionExtWithInstructions, type ITransactionResult, type ITransferData, type IUpdateData, type IWithdrawData, type InstructionGenerator, type LinearStream, MAX_SAFE_UNIX_TIME_VALUE, type MetadataRecipientHashMap, ORIGINAL_CONTRACT_SENDER_OFFSET, type OracleType, type OracleTypeName, PARTNERS_SCHEMA, PARTNER_ORACLE_PROGRAM_ID, PARTNER_SCHEMA, PROGRAM_ID, SOLANA_ERROR_MAP, SOLANA_ERROR_MATCH_REGEX, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSETS, STREAM_STRUCT_OFFSET_CLOSED, STREAM_STRUCT_OFFSET_MINT, STREAM_STRUCT_OFFSET_OLD_METADATA_KEY, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, SolanaStreamClient, type Stream, type StreamClientOptions, StreamDirection, StreamType, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, type TestOracle, type TransactionSchedulingOptions, type UpdateTestOracleParams, WITHDRAWOR, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, createStreamInstruction, createUncheckedStreamInstruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveTestOraclePDA, extractSolanaErrorCode, getOriginalMetadataKey, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isTokenLock, isVesting, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, _default as timelockIDL, topupStreamInstruction, transferStreamInstruction, updateStreamInstruction, withdrawStreamInstruction };
@@ -3,7 +3,7 @@ import bs58 from 'bs58';
3
3
  import { Buffer } from 'buffer';
4
4
  import { NATIVE_MINT, ASSOCIATED_TOKEN_PROGRAM_ID } from '@solana/spl-token';
5
5
  import { PublicKey, TransactionInstruction, Connection, Keypair, SYSVAR_RENT_PUBKEY, SystemProgram, TransactionMessage, VersionedTransaction } from '@solana/web3.js';
6
- import { ICluster, getNumberFromBN, isSignerKeypair, isSignerWallet, executeTransaction, ContractError, buildSendThrottler, assertHasPublicKey, prepareWrappedAccount, prepareTransaction, signAndExecuteTransaction, invariant, getMintAndProgram, prepareBaseInstructions, getBN, ata, createVersionedTransaction, executeMultipleTransactions, getMultipleAccountsInfoBatched, getProgramAccounts, checkOrCreateAtaBatch } from '@streamflow/common';
6
+ import { ICluster, getNumberFromBN, isSignerKeypair, isSignerWallet, executeTransaction, ContractError, buildSendThrottler, assertHasPublicKey, prepareWrappedAccount, prepareTransaction, signAndExecuteTransaction, invariant, getMintAndProgram, prepareBaseInstructions, getBN, ata, createVersionedTransaction, executeMultipleTransactions, pk, getMultipleAccountsInfoBatched, getProgramAccounts, checkOrCreateAtaBatch } from '@streamflow/common';
7
7
  export { ContractError, ICluster, getBN, getNumberFromBN } from '@streamflow/common';
8
8
  import * as borsh from 'borsh';
9
9
  import { Program } from '@coral-xyz/anchor';
@@ -116,7 +116,7 @@ var AlignedProxyErrorCode = /* @__PURE__ */ ((AlignedProxyErrorCode2) => {
116
116
  return AlignedProxyErrorCode2;
117
117
  })(AlignedProxyErrorCode || {});
118
118
  var Contract = class {
119
- constructor(stream) {
119
+ constructor(stream, metadata) {
120
120
  this.magic = stream.magic.toNumber();
121
121
  this.version = stream.version.toNumber();
122
122
  this.createdAt = stream.createdAt.toNumber();
@@ -159,6 +159,8 @@ var Contract = class {
159
159
  this.pauseCumulative = stream.pauseCumulative;
160
160
  this.lastRateChangeTime = stream.lastRateChangeTime.toNumber();
161
161
  this.fundsUnlockedAtLastRateChange = stream.fundsUnlockedAtLastRateChange;
162
+ this.oldMetadata = stream.oldMetadata;
163
+ this.metadata = metadata;
162
164
  this.type = buildStreamType(this);
163
165
  this.isAligned = false;
164
166
  }
@@ -173,8 +175,8 @@ var Contract = class {
173
175
  }
174
176
  };
175
177
  var AlignedContract = class extends Contract {
176
- constructor(stream, alignedProxy) {
177
- super(stream);
178
+ constructor(stream, metadata, alignedProxy) {
179
+ super(stream, metadata);
178
180
  this.minPrice = getNumberFromBN(alignedProxy.minPrice, ALIGNED_PRECISION_FACTOR_POW);
179
181
  this.maxPrice = getNumberFromBN(alignedProxy.maxPrice, ALIGNED_PRECISION_FACTOR_POW);
180
182
  this.minPercentage = getNumberFromBN(alignedProxy.minPercentage, ALIGNED_PRECISION_FACTOR_POW);
@@ -203,6 +205,7 @@ var STREAM_STRUCT_OFFSET_SENDER = 49;
203
205
  var STREAM_STRUCT_OFFSET_RECIPIENT = 113;
204
206
  var STREAM_STRUCT_OFFSET_MINT = 177;
205
207
  var STREAM_STRUCT_OFFSET_CLOSED = 671;
208
+ var STREAM_STRUCT_OFFSET_OLD_METADATA_KEY = 714;
206
209
  var MAX_SAFE_UNIX_TIME_VALUE2 = 864e10;
207
210
  var WITHDRAW_AVAILABLE_AMOUNT = new BN3("18446744073709551615");
208
211
  var ALIGNED_PRECISION_FACTOR_POW2 = 9;
@@ -351,7 +354,12 @@ var streamLayout = BufferLayout.struct([
351
354
  BufferLayout.blob(8, "current_pause_start"),
352
355
  BufferLayout.blob(8, "pause_cumulative"),
353
356
  BufferLayout.blob(8, "last_rate_change_time"),
354
- BufferLayout.blob(8, "funds_unlocked_at_last_rate_change")
357
+ BufferLayout.blob(8, "funds_unlocked_at_last_rate_change"),
358
+ BufferLayout.u32("creation_fee"),
359
+ BufferLayout.u8("creation_fee_claimed"),
360
+ BufferLayout.u32("auto_claim_fee"),
361
+ BufferLayout.u8("auto_claim_fee_claimed"),
362
+ BufferLayout.blob(32, "old_metadata")
355
363
  ]);
356
364
  BufferLayout.struct([
357
365
  BufferLayout.blob(32, "pubkey"),
@@ -462,6 +470,12 @@ var encodeUpdateStream = (values, data) => {
462
470
  var topupStreamLayout = BufferLayout.struct([
463
471
  BufferLayout.blob(8, "amount")
464
472
  ]);
473
+ var getOriginalMetadataKey = (streamPubkey, oldMetadata) => {
474
+ if (PublicKey.default.equals(oldMetadata)) {
475
+ return streamPubkey;
476
+ }
477
+ return oldMetadata;
478
+ };
465
479
  var FEE_PRECISION = 4;
466
480
  var FEE_NORMALIZER = 10 ** FEE_PRECISION;
467
481
  var FEE_MULTIPLIER = new BN3(10 ** 6);
@@ -515,7 +529,8 @@ var decodeStream = (buf) => {
515
529
  currentPauseStart: new BN3(raw.current_pause_start, LE),
516
530
  pauseCumulative: new BN3(raw.pause_cumulative, LE),
517
531
  lastRateChangeTime: new BN3(raw.last_rate_change_time, LE),
518
- fundsUnlockedAtLastRateChange: new BN3(raw.funds_unlocked_at_last_rate_change, LE)
532
+ fundsUnlockedAtLastRateChange: new BN3(raw.funds_unlocked_at_last_rate_change, LE),
533
+ oldMetadata: new PublicKey(raw.old_metadata)
519
534
  };
520
535
  };
521
536
  async function signAllTransactionWithRecipients(sender, items) {
@@ -3319,8 +3334,8 @@ var SolanaStreamClient = class {
3319
3334
  if (!account) {
3320
3335
  throw new Error("Impossible to cancel a stream contract that does not exist");
3321
3336
  }
3322
- const { sender: senderPublicKey } = decodeStream(account.data);
3323
- const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, senderPublicKey);
3337
+ const decoded = decodeStream(account.data);
3338
+ const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, decoded.sender, decoded.oldMetadata);
3324
3339
  const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.prepareCancelLinearStream(cancelData, extParams);
3325
3340
  return ixs;
3326
3341
  }
@@ -3542,20 +3557,38 @@ var SolanaStreamClient = class {
3542
3557
  async getOne({ id }) {
3543
3558
  const streamPublicKey = new PublicKey(id);
3544
3559
  const escrow = await this.connection.getAccountInfo(streamPublicKey, TX_FINALITY_CONFIRMED);
3545
- if (!escrow?.data) {
3560
+ if (escrow?.data) {
3561
+ return this.decodeStreamAccount(streamPublicKey, escrow.data);
3562
+ }
3563
+ const migrated = await this.connection.getProgramAccounts(this.programId, {
3564
+ filters: [
3565
+ { dataSize: METADATA_ACC_SIZE },
3566
+ {
3567
+ memcmp: {
3568
+ offset: STREAM_STRUCT_OFFSET_OLD_METADATA_KEY,
3569
+ bytes: id
3570
+ }
3571
+ }
3572
+ ]
3573
+ });
3574
+ if (migrated.length === 0) {
3546
3575
  throw new Error("Couldn't get account info.");
3547
3576
  }
3548
- const stream = decodeStream(escrow.data);
3549
- if (this.isAlignedUnlock(streamPublicKey, stream.sender)) {
3577
+ return this.decodeStreamAccount(migrated[0].pubkey, migrated[0].account.data);
3578
+ }
3579
+ async decodeStreamAccount(pubkey, data) {
3580
+ const stream = decodeStream(data);
3581
+ const metadataKey = getOriginalMetadataKey(pubkey, stream.oldMetadata);
3582
+ if (this.isAlignedUnlock(pubkey, stream.sender, stream.oldMetadata)) {
3550
3583
  const alignedProxy = await this.alignedProxyProgram.account.contract.fetch(
3551
- deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey)
3584
+ deriveContractPDA(this.alignedProxyProgram.programId, metadataKey)
3552
3585
  );
3553
3586
  if (!alignedProxy) {
3554
3587
  throw new Error("Couldn't get proxy account info.");
3555
3588
  }
3556
- return new AlignedContract(stream, alignedProxy);
3589
+ return new AlignedContract(stream, pk(pubkey), alignedProxy);
3557
3590
  }
3558
- return new Contract(stream);
3591
+ return new Contract(stream, pk(pubkey));
3559
3592
  }
3560
3593
  /**
3561
3594
  * Fetch all aligned outgoing streams/contracts by the provided public key.
@@ -3580,7 +3613,7 @@ var SolanaStreamClient = class {
3580
3613
  streamAccounts.forEach((account, index) => {
3581
3614
  if (account) {
3582
3615
  const alignedData = alignedOutgoingProgramAccounts[index].account;
3583
- streams[streamPubKeys[index].toBase58()] = new AlignedContract(decodeStream(account.data), alignedData);
3616
+ streams[streamPubKeys[index].toBase58()] = new AlignedContract(decodeStream(account.data), pk(streamPubKeys[index]), alignedData);
3584
3617
  }
3585
3618
  });
3586
3619
  return streams;
@@ -3588,15 +3621,18 @@ var SolanaStreamClient = class {
3588
3621
  async getIncomingAlignedStreams(streamRecord) {
3589
3622
  const streams = {};
3590
3623
  const alignedStreamsPubKeys = Object.keys(streamRecord);
3591
- const alignedProxyPDAs = alignedStreamsPubKeys.map(
3592
- (streamPubKey) => deriveContractPDA(this.alignedProxyProgram.programId, new PublicKey(streamPubKey))
3593
- );
3624
+ const alignedProxyPDAs = alignedStreamsPubKeys.map((streamPubKey) => {
3625
+ const pubkey = new PublicKey(streamPubKey);
3626
+ const metadataKey = getOriginalMetadataKey(pubkey, streamRecord[streamPubKey].oldMetadata);
3627
+ return deriveContractPDA(this.alignedProxyProgram.programId, metadataKey);
3628
+ });
3594
3629
  const alignedProxyAccounts = await getMultipleAccountsInfoBatched(this.connection, alignedProxyPDAs);
3595
3630
  alignedProxyAccounts.forEach((account, index) => {
3596
3631
  if (account && account.data.length === ALIGNED_METADATA_ACC_SIZE) {
3597
3632
  const alignedData = streamRecord[alignedStreamsPubKeys[index]];
3598
3633
  streams[alignedStreamsPubKeys[index]] = new AlignedContract(
3599
3634
  alignedData,
3635
+ pk(alignedStreamsPubKeys[index]),
3600
3636
  this.alignedProxyProgram.account.contract.coder.accounts.decode("contract", account.data)
3601
3637
  );
3602
3638
  }
@@ -3625,7 +3661,7 @@ var SolanaStreamClient = class {
3625
3661
  this.programId
3626
3662
  );
3627
3663
  outgoingStreamAccounts.forEach((account) => {
3628
- streams[account.pubkey.toBase58()] = new Contract(decodeStream(account.account.data));
3664
+ streams[account.pubkey.toBase58()] = new Contract(decodeStream(account.account.data), pk(account.pubkey));
3629
3665
  });
3630
3666
  if (shouldFetchAligned) {
3631
3667
  const alignedStreams = await this.getOutgoingAlignedStreams(address);
@@ -3642,10 +3678,10 @@ var SolanaStreamClient = class {
3642
3678
  const allIncomingStreams = allIncomingAccounts.map((account) => decodeStream(account.account.data));
3643
3679
  const alignedDecoded = {};
3644
3680
  allIncomingAccounts.forEach((account, index) => {
3645
- if (this.isAlignedUnlock(account.pubkey, allIncomingStreams[index].sender)) {
3681
+ if (this.isAlignedUnlock(account.pubkey, allIncomingStreams[index].sender, allIncomingStreams[index].oldMetadata)) {
3646
3682
  alignedDecoded[account.pubkey.toBase58()] = allIncomingStreams[index];
3647
3683
  } else {
3648
- streams[account.pubkey.toBase58()] = new Contract(allIncomingStreams[index]);
3684
+ streams[account.pubkey.toBase58()] = new Contract(allIncomingStreams[index], pk(account.pubkey));
3649
3685
  }
3650
3686
  });
3651
3687
  if (shouldFetchAligned) {
@@ -3687,8 +3723,9 @@ var SolanaStreamClient = class {
3687
3723
  collectAlignedEntries(decoded) {
3688
3724
  const entries = [];
3689
3725
  decoded.forEach(({ pubkey, stream }, index) => {
3690
- if (this.isAlignedUnlock(pubkey, stream.sender)) {
3691
- entries.push({ index, pda: deriveContractPDA(this.alignedProxyProgram.programId, pubkey) });
3726
+ if (this.isAlignedUnlock(pubkey, stream.sender, stream.oldMetadata)) {
3727
+ const metadataKey = getOriginalMetadataKey(pubkey, stream.oldMetadata);
3728
+ entries.push({ index, pda: deriveContractPDA(this.alignedProxyProgram.programId, metadataKey) });
3692
3729
  }
3693
3730
  });
3694
3731
  return entries;
@@ -3704,9 +3741,9 @@ var SolanaStreamClient = class {
3704
3741
  if (alignedIdx !== -1) {
3705
3742
  const alignedProxy = alignedProxies[alignedIdx];
3706
3743
  invariant(alignedProxy, "Couldn't get aligned proxy account info");
3707
- return { publicKey: pubkey, account: new AlignedContract(stream, alignedProxy) };
3744
+ return { publicKey: pubkey, account: new AlignedContract(stream, pk(pubkey), alignedProxy) };
3708
3745
  }
3709
- return { publicKey: pubkey, account: new Contract(stream) };
3746
+ return { publicKey: pubkey, account: new Contract(stream, pk(pubkey)) };
3710
3747
  });
3711
3748
  }
3712
3749
  /**
@@ -3748,8 +3785,8 @@ var SolanaStreamClient = class {
3748
3785
  const streamPublicKey = new PublicKey(data.id);
3749
3786
  const escrow = await this.connection.getAccountInfo(streamPublicKey);
3750
3787
  invariant(escrow, "Couldn't get account info");
3751
- const { sender: senderPublicKey } = decodeStream(escrow.data);
3752
- const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, senderPublicKey);
3788
+ const decoded = decodeStream(escrow.data);
3789
+ const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, decoded.sender, decoded.oldMetadata);
3753
3790
  if (isAlignedUnlock && (data.enableAutomaticWithdrawal !== void 0 || data.amountPerPeriod !== void 0)) {
3754
3791
  throw new Error("Automatic withdrawal and rate update are not possible in price-based vesting!");
3755
3792
  }
@@ -3840,10 +3877,12 @@ var SolanaStreamClient = class {
3840
3877
  return extractSolanaErrorCode(err.toString() ?? "Unknown error!", logs);
3841
3878
  }
3842
3879
  /**
3843
- * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
3880
+ * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA.
3881
+ * For migrated streams, the PDA was derived from the old metadata key.
3844
3882
  */
3845
- isAlignedUnlock(streamPublicKey, senderPublicKey) {
3846
- const pda = deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey);
3883
+ isAlignedUnlock(streamPublicKey, senderPublicKey, oldMetadata) {
3884
+ const metadataKey = oldMetadata ? getOriginalMetadataKey(streamPublicKey, oldMetadata) : streamPublicKey;
3885
+ const pda = deriveContractPDA(this.alignedProxyProgram.programId, metadataKey);
3847
3886
  return senderPublicKey.equals(pda);
3848
3887
  }
3849
3888
  async flatBuildCreateMultipleTransactionInstructions(data, extParams) {
@@ -4320,6 +4359,6 @@ var timelockIDL_default = {
4320
4359
  ]
4321
4360
  };
4322
4361
 
4323
- export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW2 as ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, AlignedContract, AlignedProxyErrorCode, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, Contract, ContractErrorCode, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, MAX_SAFE_UNIX_TIME_VALUE2 as MAX_SAFE_UNIX_TIME_VALUE, ORIGINAL_CONTRACT_SENDER_OFFSET, PARTNERS_SCHEMA, PARTNER_ORACLE_PROGRAM_ID, PARTNER_SCHEMA, PROGRAM_ID, SOLANA_ERROR_MAP, SOLANA_ERROR_MATCH_REGEX, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSETS, STREAM_STRUCT_OFFSET_CLOSED, STREAM_STRUCT_OFFSET_MINT, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, SolanaStreamClient, StreamDirection, StreamType, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, WITHDRAWOR, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, createStreamInstruction, createUncheckedStreamInstruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveTestOraclePDA, extractSolanaErrorCode, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isTokenLock, isVesting, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, timelockIDL_default as timelockIDL, topupStreamInstruction, transferStreamInstruction, updateStreamInstruction, withdrawStreamInstruction };
4362
+ export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW2 as ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, AlignedContract, AlignedProxyErrorCode, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, Contract, ContractErrorCode, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, MAX_SAFE_UNIX_TIME_VALUE2 as MAX_SAFE_UNIX_TIME_VALUE, ORIGINAL_CONTRACT_SENDER_OFFSET, PARTNERS_SCHEMA, PARTNER_ORACLE_PROGRAM_ID, PARTNER_SCHEMA, PROGRAM_ID, SOLANA_ERROR_MAP, SOLANA_ERROR_MATCH_REGEX, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSETS, STREAM_STRUCT_OFFSET_CLOSED, STREAM_STRUCT_OFFSET_MINT, STREAM_STRUCT_OFFSET_OLD_METADATA_KEY, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, SolanaStreamClient, StreamDirection, StreamType, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, WITHDRAWOR, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, createStreamInstruction, createUncheckedStreamInstruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveTestOraclePDA, extractSolanaErrorCode, getOriginalMetadataKey, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isTokenLock, isVesting, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, timelockIDL_default as timelockIDL, topupStreamInstruction, transferStreamInstruction, updateStreamInstruction, withdrawStreamInstruction };
4324
4363
  //# sourceMappingURL=index.js.map
4325
4364
  //# sourceMappingURL=index.js.map