@streamflow/stream 11.1.0-alpha.p335.6615f0a → 11.1.0-alpha.p335.b571df3

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.
@@ -185,6 +185,7 @@ var Contract = class {
185
185
  this.pauseCumulative = stream.pauseCumulative;
186
186
  this.lastRateChangeTime = stream.lastRateChangeTime.toNumber();
187
187
  this.fundsUnlockedAtLastRateChange = stream.fundsUnlockedAtLastRateChange;
188
+ this.oldMetadata = stream.oldMetadata;
188
189
  this.type = buildStreamType(this);
189
190
  this.isAligned = false;
190
191
  }
@@ -229,6 +230,7 @@ var STREAM_STRUCT_OFFSET_SENDER = 49;
229
230
  var STREAM_STRUCT_OFFSET_RECIPIENT = 113;
230
231
  var STREAM_STRUCT_OFFSET_MINT = 177;
231
232
  var STREAM_STRUCT_OFFSET_CLOSED = 671;
233
+ var STREAM_STRUCT_OFFSET_OLD_METADATA_KEY = 714;
232
234
  var MAX_SAFE_UNIX_TIME_VALUE2 = 864e10;
233
235
  var WITHDRAW_AVAILABLE_AMOUNT = new BN3__default.default("18446744073709551615");
234
236
  var ALIGNED_PRECISION_FACTOR_POW2 = 9;
@@ -269,6 +271,7 @@ var TEST_ORACLE_DISCRIMINATOR = [198, 49, 63, 134, 232, 251, 168, 28];
269
271
  var CONTRACT_SEED = buffer.Buffer.from("contract", "utf-8");
270
272
  var ESCROW_SEED = buffer.Buffer.from("strm", "utf-8");
271
273
  var TEST_ORACLE_SEED = buffer.Buffer.from("test-oracle", "utf-8");
274
+ var REPOPULATED_METADATA_SEED = buffer.Buffer.from("strm-rep", "utf-8");
272
275
  var STREAMFLOW_TREASURY_PUBLIC_KEY = new web3_js.PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
273
276
  var WITHDRAWOR = "wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u";
274
277
  var WITHDRAWOR_PUBLIC_KEY = new web3_js.PublicKey(WITHDRAWOR);
@@ -377,7 +380,12 @@ var streamLayout = BufferLayout__namespace.struct([
377
380
  BufferLayout__namespace.blob(8, "current_pause_start"),
378
381
  BufferLayout__namespace.blob(8, "pause_cumulative"),
379
382
  BufferLayout__namespace.blob(8, "last_rate_change_time"),
380
- BufferLayout__namespace.blob(8, "funds_unlocked_at_last_rate_change")
383
+ BufferLayout__namespace.blob(8, "funds_unlocked_at_last_rate_change"),
384
+ BufferLayout__namespace.u32("creation_fee"),
385
+ BufferLayout__namespace.u8("creation_fee_claimed"),
386
+ BufferLayout__namespace.u32("auto_claim_fee"),
387
+ BufferLayout__namespace.u8("auto_claim_fee_claimed"),
388
+ BufferLayout__namespace.blob(32, "old_metadata")
381
389
  ]);
382
390
  BufferLayout__namespace.struct([
383
391
  BufferLayout__namespace.blob(32, "pubkey"),
@@ -488,6 +496,12 @@ var encodeUpdateStream = (values, data) => {
488
496
  var topupStreamLayout = BufferLayout__namespace.struct([
489
497
  BufferLayout__namespace.blob(8, "amount")
490
498
  ]);
499
+ var getMetadataKey = (streamPubkey, oldMetadata) => {
500
+ if (web3_js.PublicKey.default.equals(oldMetadata)) {
501
+ return streamPubkey;
502
+ }
503
+ return oldMetadata;
504
+ };
491
505
  var FEE_PRECISION = 4;
492
506
  var FEE_NORMALIZER = 10 ** FEE_PRECISION;
493
507
  var FEE_MULTIPLIER = new BN3__default.default(10 ** 6);
@@ -541,7 +555,8 @@ var decodeStream = (buf) => {
541
555
  currentPauseStart: new BN3__default.default(raw.current_pause_start, LE),
542
556
  pauseCumulative: new BN3__default.default(raw.pause_cumulative, LE),
543
557
  lastRateChangeTime: new BN3__default.default(raw.last_rate_change_time, LE),
544
- fundsUnlockedAtLastRateChange: new BN3__default.default(raw.funds_unlocked_at_last_rate_change, LE)
558
+ fundsUnlockedAtLastRateChange: new BN3__default.default(raw.funds_unlocked_at_last_rate_change, LE),
559
+ oldMetadata: new web3_js.PublicKey(raw.old_metadata)
545
560
  };
546
561
  };
547
562
  async function signAllTransactionWithRecipients(sender, items) {
@@ -2524,6 +2539,9 @@ var deriveEscrowPDA = (programId, streamMetadata) => {
2524
2539
  var deriveTestOraclePDA = (programId, mint, creator) => {
2525
2540
  return web3_js.PublicKey.findProgramAddressSync([TEST_ORACLE_SEED, mint.toBuffer(), creator.toBuffer()], programId)[0];
2526
2541
  };
2542
+ var deriveRepopulatedMetadataPDA = (programId, streamMetadata) => {
2543
+ return web3_js.PublicKey.findProgramAddressSync([REPOPULATED_METADATA_SEED, streamMetadata.toBuffer()], programId)[0];
2544
+ };
2527
2545
 
2528
2546
  // solana/StreamClient.ts
2529
2547
  var METADATA_ACC_SIZE = 1104;
@@ -3345,8 +3363,8 @@ var SolanaStreamClient = class {
3345
3363
  if (!account) {
3346
3364
  throw new Error("Impossible to cancel a stream contract that does not exist");
3347
3365
  }
3348
- const { sender: senderPublicKey } = decodeStream(account.data);
3349
- const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, senderPublicKey);
3366
+ const decoded = decodeStream(account.data);
3367
+ const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, decoded.sender, decoded.oldMetadata);
3350
3368
  const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.prepareCancelLinearStream(cancelData, extParams);
3351
3369
  return ixs;
3352
3370
  }
@@ -3568,13 +3586,31 @@ var SolanaStreamClient = class {
3568
3586
  async getOne({ id }) {
3569
3587
  const streamPublicKey = new web3_js.PublicKey(id);
3570
3588
  const escrow = await this.connection.getAccountInfo(streamPublicKey, TX_FINALITY_CONFIRMED);
3571
- if (!escrow?.data) {
3589
+ if (escrow?.data) {
3590
+ return this.decodeStreamAccount(streamPublicKey, escrow.data);
3591
+ }
3592
+ const migrated = await this.connection.getProgramAccounts(this.programId, {
3593
+ filters: [
3594
+ { dataSize: METADATA_ACC_SIZE },
3595
+ {
3596
+ memcmp: {
3597
+ offset: STREAM_STRUCT_OFFSET_OLD_METADATA_KEY,
3598
+ bytes: id
3599
+ }
3600
+ }
3601
+ ]
3602
+ });
3603
+ if (migrated.length === 0) {
3572
3604
  throw new Error("Couldn't get account info.");
3573
3605
  }
3574
- const stream = decodeStream(escrow.data);
3575
- if (this.isAlignedUnlock(streamPublicKey, stream.sender)) {
3606
+ return this.decodeStreamAccount(migrated[0].pubkey, migrated[0].account.data);
3607
+ }
3608
+ async decodeStreamAccount(pubkey, data) {
3609
+ const stream = decodeStream(data);
3610
+ const metadataKey = getMetadataKey(pubkey, stream.oldMetadata);
3611
+ if (this.isAlignedUnlock(pubkey, stream.sender, stream.oldMetadata)) {
3576
3612
  const alignedProxy = await this.alignedProxyProgram.account.contract.fetch(
3577
- deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey)
3613
+ deriveContractPDA(this.alignedProxyProgram.programId, metadataKey)
3578
3614
  );
3579
3615
  if (!alignedProxy) {
3580
3616
  throw new Error("Couldn't get proxy account info.");
@@ -3614,9 +3650,11 @@ var SolanaStreamClient = class {
3614
3650
  async getIncomingAlignedStreams(streamRecord) {
3615
3651
  const streams = {};
3616
3652
  const alignedStreamsPubKeys = Object.keys(streamRecord);
3617
- const alignedProxyPDAs = alignedStreamsPubKeys.map(
3618
- (streamPubKey) => deriveContractPDA(this.alignedProxyProgram.programId, new web3_js.PublicKey(streamPubKey))
3619
- );
3653
+ const alignedProxyPDAs = alignedStreamsPubKeys.map((streamPubKey) => {
3654
+ const pubkey = new web3_js.PublicKey(streamPubKey);
3655
+ const metadataKey = getMetadataKey(pubkey, streamRecord[streamPubKey].oldMetadata);
3656
+ return deriveContractPDA(this.alignedProxyProgram.programId, metadataKey);
3657
+ });
3620
3658
  const alignedProxyAccounts = await common.getMultipleAccountsInfoBatched(this.connection, alignedProxyPDAs);
3621
3659
  alignedProxyAccounts.forEach((account, index) => {
3622
3660
  if (account && account.data.length === ALIGNED_METADATA_ACC_SIZE) {
@@ -3668,7 +3706,7 @@ var SolanaStreamClient = class {
3668
3706
  const allIncomingStreams = allIncomingAccounts.map((account) => decodeStream(account.account.data));
3669
3707
  const alignedDecoded = {};
3670
3708
  allIncomingAccounts.forEach((account, index) => {
3671
- if (this.isAlignedUnlock(account.pubkey, allIncomingStreams[index].sender)) {
3709
+ if (this.isAlignedUnlock(account.pubkey, allIncomingStreams[index].sender, allIncomingStreams[index].oldMetadata)) {
3672
3710
  alignedDecoded[account.pubkey.toBase58()] = allIncomingStreams[index];
3673
3711
  } else {
3674
3712
  streams[account.pubkey.toBase58()] = new Contract(allIncomingStreams[index]);
@@ -3713,8 +3751,9 @@ var SolanaStreamClient = class {
3713
3751
  collectAlignedEntries(decoded) {
3714
3752
  const entries = [];
3715
3753
  decoded.forEach(({ pubkey, stream }, index) => {
3716
- if (this.isAlignedUnlock(pubkey, stream.sender)) {
3717
- entries.push({ index, pda: deriveContractPDA(this.alignedProxyProgram.programId, pubkey) });
3754
+ if (this.isAlignedUnlock(pubkey, stream.sender, stream.oldMetadata)) {
3755
+ const metadataKey = getMetadataKey(pubkey, stream.oldMetadata);
3756
+ entries.push({ index, pda: deriveContractPDA(this.alignedProxyProgram.programId, metadataKey) });
3718
3757
  }
3719
3758
  });
3720
3759
  return entries;
@@ -3774,8 +3813,8 @@ var SolanaStreamClient = class {
3774
3813
  const streamPublicKey = new web3_js.PublicKey(data.id);
3775
3814
  const escrow = await this.connection.getAccountInfo(streamPublicKey);
3776
3815
  common.invariant(escrow, "Couldn't get account info");
3777
- const { sender: senderPublicKey } = decodeStream(escrow.data);
3778
- const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, senderPublicKey);
3816
+ const decoded = decodeStream(escrow.data);
3817
+ const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, decoded.sender, decoded.oldMetadata);
3779
3818
  if (isAlignedUnlock && (data.enableAutomaticWithdrawal !== void 0 || data.amountPerPeriod !== void 0)) {
3780
3819
  throw new Error("Automatic withdrawal and rate update are not possible in price-based vesting!");
3781
3820
  }
@@ -3866,10 +3905,12 @@ var SolanaStreamClient = class {
3866
3905
  return extractSolanaErrorCode(err.toString() ?? "Unknown error!", logs);
3867
3906
  }
3868
3907
  /**
3869
- * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
3908
+ * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA.
3909
+ * For migrated streams, the PDA was derived from the old metadata key.
3870
3910
  */
3871
- isAlignedUnlock(streamPublicKey, senderPublicKey) {
3872
- const pda = deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey);
3911
+ isAlignedUnlock(streamPublicKey, senderPublicKey, oldMetadata) {
3912
+ const metadataKey = oldMetadata ? getMetadataKey(streamPublicKey, oldMetadata) : streamPublicKey;
3913
+ const pda = deriveContractPDA(this.alignedProxyProgram.programId, metadataKey);
3873
3914
  return senderPublicKey.equals(pda);
3874
3915
  }
3875
3916
  async flatBuildCreateMultipleTransactionInstructions(data, extParams) {
@@ -4386,12 +4427,14 @@ exports.PARTNERS_SCHEMA = PARTNERS_SCHEMA;
4386
4427
  exports.PARTNER_ORACLE_PROGRAM_ID = PARTNER_ORACLE_PROGRAM_ID;
4387
4428
  exports.PARTNER_SCHEMA = PARTNER_SCHEMA;
4388
4429
  exports.PROGRAM_ID = PROGRAM_ID;
4430
+ exports.REPOPULATED_METADATA_SEED = REPOPULATED_METADATA_SEED;
4389
4431
  exports.SOLANA_ERROR_MAP = SOLANA_ERROR_MAP;
4390
4432
  exports.SOLANA_ERROR_MATCH_REGEX = SOLANA_ERROR_MATCH_REGEX;
4391
4433
  exports.STREAMFLOW_TREASURY_PUBLIC_KEY = STREAMFLOW_TREASURY_PUBLIC_KEY;
4392
4434
  exports.STREAM_STRUCT_OFFSETS = STREAM_STRUCT_OFFSETS;
4393
4435
  exports.STREAM_STRUCT_OFFSET_CLOSED = STREAM_STRUCT_OFFSET_CLOSED;
4394
4436
  exports.STREAM_STRUCT_OFFSET_MINT = STREAM_STRUCT_OFFSET_MINT;
4437
+ exports.STREAM_STRUCT_OFFSET_OLD_METADATA_KEY = STREAM_STRUCT_OFFSET_OLD_METADATA_KEY;
4395
4438
  exports.STREAM_STRUCT_OFFSET_RECIPIENT = STREAM_STRUCT_OFFSET_RECIPIENT;
4396
4439
  exports.STREAM_STRUCT_OFFSET_SENDER = STREAM_STRUCT_OFFSET_SENDER;
4397
4440
  exports.SolanaStreamClient = SolanaStreamClient;
@@ -4413,8 +4456,10 @@ exports.decodeEndTime = decodeEndTime;
4413
4456
  exports.decodeStream = decodeStream;
4414
4457
  exports.deriveContractPDA = deriveContractPDA;
4415
4458
  exports.deriveEscrowPDA = deriveEscrowPDA;
4459
+ exports.deriveRepopulatedMetadataPDA = deriveRepopulatedMetadataPDA;
4416
4460
  exports.deriveTestOraclePDA = deriveTestOraclePDA;
4417
4461
  exports.extractSolanaErrorCode = extractSolanaErrorCode;
4462
+ exports.getMetadataKey = getMetadataKey;
4418
4463
  exports.handleContractError = handleContractError;
4419
4464
  exports.isAligned = isAligned;
4420
4465
  exports.isCliffCloseToDepositedAmount = isCliffCloseToDepositedAmount;