@streamflow/stream 7.0.0-alpha.13 → 7.0.0-alpha.15

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.
@@ -81,10 +81,13 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
81
81
  const { partner, amount } = data;
82
82
  const { isNative, sender } = extParams;
83
83
  const partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_js_1.WITHDRAWOR_PUBLIC_KEY;
84
+ const mintPublicKey = new web3_js_1.PublicKey(data.tokenId);
84
85
  if (!sender.publicKey) {
85
86
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
86
87
  }
87
- const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(data, extParams);
88
+ const ixs = await this.getCreateATAInstructions([constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, partnerPublicKey], mintPublicKey, sender, true);
89
+ const { ixs: createIxs, metadata, metadataPubKey } = await this.prepareCreateInstructions(data, extParams);
90
+ ixs.push(...createIxs);
88
91
  if (isNative) {
89
92
  const totalFee = await this.getTotalFee({
90
93
  address: partnerPublicKey.toString(),
@@ -128,6 +131,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
128
131
  computePrice,
129
132
  computeLimit: computeLimit ?? constants_js_1.ALIGNED_COMPUTE_LIMIT,
130
133
  });
134
+ ixs.push(...(await this.getCreateATAInstructions([recipientPublicKey], mintPublicKey, sender, true, tokenProgramId)));
131
135
  const encodedUIntArray = new TextEncoder().encode(streamName);
132
136
  const streamNameArray = Array.from(encodedUIntArray);
133
137
  const createIx = await this.alignedProxyProgram.methods
@@ -330,6 +334,8 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
330
334
  const batch = [];
331
335
  const instructionsBatch = [];
332
336
  const metadataPubKeys = metadataPubKeysExt || [];
337
+ const partnerPublicKey = data.partner ? new web3_js_1.PublicKey(data.partner) : constants_js_1.WITHDRAWOR_PUBLIC_KEY;
338
+ const mintPublicKey = new web3_js_1.PublicKey(data.tokenId);
333
339
  if (recipients.length === 0) {
334
340
  throw new Error("Recipients array is empty!");
335
341
  }
@@ -367,13 +373,17 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
367
373
  }
368
374
  batch.push({ tx, recipient });
369
375
  }
376
+ const prepareInstructions = await this.getCreateATAInstructions([constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, partnerPublicKey], mintPublicKey, sender, true);
370
377
  if (isNative) {
371
378
  const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new bn_js_1.default(0));
372
379
  const nativeInstructions = await (0, solana_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalDepositedAmount);
380
+ prepareInstructions.push(...nativeInstructions);
381
+ }
382
+ if (prepareInstructions.length > 0) {
373
383
  const messageV0 = new web3_js_1.TransactionMessage({
374
384
  payerKey: sender.publicKey,
375
385
  recentBlockhash: hash.blockhash,
376
- instructions: nativeInstructions,
386
+ instructions: prepareInstructions,
377
387
  }).compileToV0Message();
378
388
  const tx = new web3_js_1.VersionedTransaction(messageV0);
379
389
  batch.push({
@@ -382,7 +392,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
382
392
  });
383
393
  }
384
394
  const signedBatch = await (0, utils_js_1.signAllTransactionWithRecipients)(sender, batch);
385
- if (isNative) {
395
+ if (prepareInstructions.length > 0) {
386
396
  const prepareTx = signedBatch.pop();
387
397
  await (0, utils_js_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx, { hash, context }, { sendThrottler: this.sendThrottler });
388
398
  }
@@ -446,21 +456,22 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
446
456
  throw new Error("Couldn't get account info");
447
457
  }
448
458
  const data = (0, utils_js_1.decodeStream)(escrow.data);
449
- const { tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, data.mint);
450
- const streamflowTreasuryTokens = await (0, solana_1.ata)(data.mint, constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
451
- const partnerTokens = await (0, solana_1.ata)(data.mint, data.partner, tokenProgramId);
452
- await this.checkAssociatedTokenAccounts(data, { invoker, checkTokenAccounts }, ixs, tokenProgramId);
453
- ixs.push((0, instructions_js_1.withdrawStreamInstruction)(amount, this.programId, {
459
+ const { sender, recipient, mint, streamflowTreasury, partner, recipientTokens, escrowTokens } = data;
460
+ const { tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, mint);
461
+ const streamflowTreasuryTokens = await (0, solana_1.ata)(mint, constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
462
+ const partnerTokens = await (0, solana_1.ata)(mint, partner, tokenProgramId);
463
+ const ataIx = await this.getCreateATAInstructions([sender, recipient, streamflowTreasury, partner], mint, invoker, checkTokenAccounts, tokenProgramId);
464
+ ixs.push(...ataIx, (0, instructions_js_1.withdrawStreamInstruction)(amount, this.programId, {
465
+ partner,
466
+ partnerTokens,
467
+ mint,
468
+ streamflowTreasuryTokens,
469
+ recipientTokens,
470
+ escrowTokens,
454
471
  authority: invoker.publicKey,
455
472
  recipient: invoker.publicKey,
456
- recipientTokens: data.recipientTokens,
457
473
  metadata: streamPublicKey,
458
- escrowTokens: data.escrowTokens,
459
474
  streamflowTreasury: constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
460
- streamflowTreasuryTokens,
461
- partner: data.partner,
462
- partnerTokens,
463
- mint: data.mint,
464
475
  tokenProgram: tokenProgramId,
465
476
  }));
466
477
  return ixs;
@@ -500,31 +511,29 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
500
511
  if (!escrowAcc?.data) {
501
512
  throw new Error("Couldn't get account info");
502
513
  }
503
- const streamflowProgramPublicKey = new web3_js_1.PublicKey(this.programId);
504
- const streamData = (0, utils_js_1.decodeStream)(escrowAcc?.data);
505
- const escrowPDA = (0, derive_accounts_js_1.deriveEscrowPDA)(streamflowProgramPublicKey, streamPublicKey);
506
- const { tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, streamData.mint);
507
- const partnerPublicKey = streamData.partner;
514
+ const streamData = (0, utils_js_1.decodeStream)(escrowAcc.data);
515
+ const { sender, recipient, mint, streamflowTreasury, partner, escrowTokens } = streamData;
516
+ const { tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, mint);
508
517
  const ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
509
518
  computePrice,
510
519
  computeLimit: computeLimit ?? constants_js_1.ALIGNED_COMPUTE_LIMIT,
511
520
  });
512
- await this.checkAssociatedTokenAccounts(streamData, { invoker, checkTokenAccounts }, ixs, tokenProgramId);
521
+ const ataIx = await this.getCreateATAInstructions([sender, recipient, partner, streamflowTreasury], mint, invoker, checkTokenAccounts, tokenProgramId);
513
522
  const cancelIx = await this.alignedProxyProgram.methods
514
523
  .cancel()
515
524
  .accountsPartial({
525
+ mint,
526
+ partner,
527
+ recipient,
528
+ escrowTokens,
516
529
  sender: invoker.publicKey,
517
530
  streamMetadata: streamPublicKey,
518
- escrowTokens: escrowPDA,
519
- recipient: streamData.recipient,
520
- partner: partnerPublicKey,
521
531
  streamflowTreasury: constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
522
- mint: streamData.mint,
523
532
  tokenProgram: tokenProgramId,
524
533
  streamflowProgram: this.programId,
525
534
  })
526
535
  .instruction();
527
- ixs.push(cancelIx);
536
+ ixs.push(...ataIx, cancelIx);
528
537
  return ixs;
529
538
  }
530
539
  /**
@@ -539,28 +548,29 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
539
548
  if (!escrowAcc?.data) {
540
549
  throw new Error("Couldn't get account info");
541
550
  }
542
- const data = (0, utils_js_1.decodeStream)(escrowAcc?.data);
543
- const { tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, data.mint);
544
- const streamflowTreasuryTokens = await (0, solana_1.ata)(data.mint, constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
545
- const partnerTokens = await (0, solana_1.ata)(data.mint, data.partner, tokenProgramId);
551
+ const data = (0, utils_js_1.decodeStream)(escrowAcc.data);
552
+ const { sender, recipient, partner, streamflowTreasury, mint, senderTokens, recipientTokens, escrowTokens } = data;
553
+ const { tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, mint);
554
+ const streamflowTreasuryTokens = await (0, solana_1.ata)(mint, constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
555
+ const partnerTokens = await (0, solana_1.ata)(mint, partner, tokenProgramId);
546
556
  const ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
547
557
  computePrice,
548
558
  computeLimit,
549
559
  });
550
- await this.checkAssociatedTokenAccounts(data, { invoker, checkTokenAccounts }, ixs, tokenProgramId);
551
- ixs.push((0, instructions_js_1.cancelStreamInstruction)(this.programId, {
560
+ const ixsAta = await this.getCreateATAInstructions([sender, recipient, partner, streamflowTreasury], mint, invoker, checkTokenAccounts, tokenProgramId);
561
+ ixs.push(...ixsAta, (0, instructions_js_1.cancelStreamInstruction)(this.programId, {
562
+ sender,
563
+ senderTokens,
564
+ recipient,
565
+ recipientTokens,
566
+ streamflowTreasuryTokens,
567
+ partner,
568
+ partnerTokens,
569
+ mint,
570
+ escrowTokens,
552
571
  authority: invoker.publicKey,
553
- sender: data.sender,
554
- senderTokens: data.senderTokens,
555
- recipient: data.recipient,
556
- recipientTokens: data.recipientTokens,
557
572
  metadata: streamPublicKey,
558
- escrowTokens: data.escrowTokens,
559
573
  streamflowTreasury: constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
560
- streamflowTreasuryTokens: streamflowTreasuryTokens,
561
- partner: data.partner,
562
- partnerTokens,
563
- mint: data.mint,
564
574
  tokenProgram: tokenProgramId,
565
575
  }));
566
576
  return ixs;
@@ -702,7 +712,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
702
712
  streamAccounts.forEach((account, index) => {
703
713
  if (account) {
704
714
  const alignedData = alignedOutgoingProgramAccounts[index].account;
705
- streams[alignedData.sender.toBase58()] = new types_js_1.AlignedContract((0, utils_js_1.decodeStream)(account.data), alignedData);
715
+ streams[streamPubKeys[index].toBase58()] = new types_js_1.AlignedContract((0, utils_js_1.decodeStream)(account.data), alignedData);
706
716
  }
707
717
  });
708
718
  return streams;
@@ -864,19 +874,15 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
864
874
  return senderPublicKey.equals(pda);
865
875
  }
866
876
  /**
867
- * Utility function that checks whether associated token accounts still exist and adds instructions to add them if not
877
+ * Returns insrtuctions for creating associated token accounts for the provided owners
868
878
  */
869
- async checkAssociatedTokenAccounts(data, { invoker, checkTokenAccounts }, ixs, programId) {
879
+ async getCreateATAInstructions(owners, mint, invoker, checkTokenAccounts, programId) {
870
880
  if (!checkTokenAccounts) {
871
- return;
872
- }
873
- const owners = Array.from(new Set([
874
- data.sender.toBase58(),
875
- data.recipient.toBase58(),
876
- data.partner.toBase58(),
877
- data.streamflowTreasury.toBase58(),
878
- ]), (address) => new web3_js_1.PublicKey(address));
879
- ixs.push(...(await (0, solana_1.checkOrCreateAtaBatch)(this.connection, owners, data.mint, invoker, programId)));
881
+ return [];
882
+ }
883
+ // filter out duplicate PublicKeys, otherwise transaction will fail
884
+ const uniqueOwners = Array.from(new Set(owners.map((owner) => owner.toBase58()))).map((pkString) => new web3_js_1.PublicKey(pkString));
885
+ return (0, solana_1.checkOrCreateAtaBatch)(this.connection, uniqueOwners, mint, invoker, programId);
880
886
  }
881
887
  }
882
888
  exports.SolanaStreamClient = SolanaStreamClient;
@@ -5,7 +5,7 @@ const web3_js_1 = require("@solana/web3.js");
5
5
  const buffer_1 = require("buffer");
6
6
  const types_js_1 = require("../common/types.js");
7
7
  exports.TX_FINALITY_CONFIRMED = "confirmed";
8
- exports.ORIGINAL_CONTRACT_SENDER_OFFSET = 16;
8
+ exports.ORIGINAL_CONTRACT_SENDER_OFFSET = 9;
9
9
  exports.STREAM_STRUCT_OFFSET_SENDER = 49;
10
10
  exports.STREAM_STRUCT_OFFSET_RECIPIENT = 113;
11
11
  exports.STREAM_STRUCT_OFFSET_MINT = 177;
@@ -124,7 +124,7 @@ export declare class SolanaStreamClient extends BaseStreamClient {
124
124
  */
125
125
  private isAlignedUnlock;
126
126
  /**
127
- * Utility function that checks whether associated token accounts still exist and adds instructions to add them if not
127
+ * Returns insrtuctions for creating associated token accounts for the provided owners
128
128
  */
129
- private checkAssociatedTokenAccounts;
129
+ private getCreateATAInstructions;
130
130
  }
@@ -57,10 +57,13 @@ export class SolanaStreamClient extends BaseStreamClient {
57
57
  const { partner, amount } = data;
58
58
  const { isNative, sender } = extParams;
59
59
  const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
60
+ const mintPublicKey = new PublicKey(data.tokenId);
60
61
  if (!sender.publicKey) {
61
62
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
62
63
  }
63
- const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(data, extParams);
64
+ const ixs = await this.getCreateATAInstructions([STREAMFLOW_TREASURY_PUBLIC_KEY, partnerPublicKey], mintPublicKey, sender, true);
65
+ const { ixs: createIxs, metadata, metadataPubKey } = await this.prepareCreateInstructions(data, extParams);
66
+ ixs.push(...createIxs);
64
67
  if (isNative) {
65
68
  const totalFee = await this.getTotalFee({
66
69
  address: partnerPublicKey.toString(),
@@ -104,6 +107,7 @@ export class SolanaStreamClient extends BaseStreamClient {
104
107
  computePrice,
105
108
  computeLimit: computeLimit ?? ALIGNED_COMPUTE_LIMIT,
106
109
  });
110
+ ixs.push(...(await this.getCreateATAInstructions([recipientPublicKey], mintPublicKey, sender, true, tokenProgramId)));
107
111
  const encodedUIntArray = new TextEncoder().encode(streamName);
108
112
  const streamNameArray = Array.from(encodedUIntArray);
109
113
  const createIx = await this.alignedProxyProgram.methods
@@ -306,6 +310,8 @@ export class SolanaStreamClient extends BaseStreamClient {
306
310
  const batch = [];
307
311
  const instructionsBatch = [];
308
312
  const metadataPubKeys = metadataPubKeysExt || [];
313
+ const partnerPublicKey = data.partner ? new PublicKey(data.partner) : WITHDRAWOR_PUBLIC_KEY;
314
+ const mintPublicKey = new PublicKey(data.tokenId);
309
315
  if (recipients.length === 0) {
310
316
  throw new Error("Recipients array is empty!");
311
317
  }
@@ -343,13 +349,17 @@ export class SolanaStreamClient extends BaseStreamClient {
343
349
  }
344
350
  batch.push({ tx, recipient });
345
351
  }
352
+ const prepareInstructions = await this.getCreateATAInstructions([STREAMFLOW_TREASURY_PUBLIC_KEY, partnerPublicKey], mintPublicKey, sender, true);
346
353
  if (isNative) {
347
354
  const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new BN(0));
348
355
  const nativeInstructions = await prepareWrappedAccount(this.connection, sender.publicKey, totalDepositedAmount);
356
+ prepareInstructions.push(...nativeInstructions);
357
+ }
358
+ if (prepareInstructions.length > 0) {
349
359
  const messageV0 = new TransactionMessage({
350
360
  payerKey: sender.publicKey,
351
361
  recentBlockhash: hash.blockhash,
352
- instructions: nativeInstructions,
362
+ instructions: prepareInstructions,
353
363
  }).compileToV0Message();
354
364
  const tx = new VersionedTransaction(messageV0);
355
365
  batch.push({
@@ -358,7 +368,7 @@ export class SolanaStreamClient extends BaseStreamClient {
358
368
  });
359
369
  }
360
370
  const signedBatch = await signAllTransactionWithRecipients(sender, batch);
361
- if (isNative) {
371
+ if (prepareInstructions.length > 0) {
362
372
  const prepareTx = signedBatch.pop();
363
373
  await sendAndConfirmStreamRawTransaction(this.connection, prepareTx, { hash, context }, { sendThrottler: this.sendThrottler });
364
374
  }
@@ -422,21 +432,22 @@ export class SolanaStreamClient extends BaseStreamClient {
422
432
  throw new Error("Couldn't get account info");
423
433
  }
424
434
  const data = decodeStream(escrow.data);
425
- const { tokenProgramId } = await getMintAndProgram(this.connection, data.mint);
426
- const streamflowTreasuryTokens = await ata(data.mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
427
- const partnerTokens = await ata(data.mint, data.partner, tokenProgramId);
428
- await this.checkAssociatedTokenAccounts(data, { invoker, checkTokenAccounts }, ixs, tokenProgramId);
429
- ixs.push(withdrawStreamInstruction(amount, this.programId, {
435
+ const { sender, recipient, mint, streamflowTreasury, partner, recipientTokens, escrowTokens } = data;
436
+ const { tokenProgramId } = await getMintAndProgram(this.connection, mint);
437
+ const streamflowTreasuryTokens = await ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
438
+ const partnerTokens = await ata(mint, partner, tokenProgramId);
439
+ const ataIx = await this.getCreateATAInstructions([sender, recipient, streamflowTreasury, partner], mint, invoker, checkTokenAccounts, tokenProgramId);
440
+ ixs.push(...ataIx, withdrawStreamInstruction(amount, this.programId, {
441
+ partner,
442
+ partnerTokens,
443
+ mint,
444
+ streamflowTreasuryTokens,
445
+ recipientTokens,
446
+ escrowTokens,
430
447
  authority: invoker.publicKey,
431
448
  recipient: invoker.publicKey,
432
- recipientTokens: data.recipientTokens,
433
449
  metadata: streamPublicKey,
434
- escrowTokens: data.escrowTokens,
435
450
  streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
436
- streamflowTreasuryTokens,
437
- partner: data.partner,
438
- partnerTokens,
439
- mint: data.mint,
440
451
  tokenProgram: tokenProgramId,
441
452
  }));
442
453
  return ixs;
@@ -476,31 +487,29 @@ export class SolanaStreamClient extends BaseStreamClient {
476
487
  if (!escrowAcc?.data) {
477
488
  throw new Error("Couldn't get account info");
478
489
  }
479
- const streamflowProgramPublicKey = new PublicKey(this.programId);
480
- const streamData = decodeStream(escrowAcc?.data);
481
- const escrowPDA = deriveEscrowPDA(streamflowProgramPublicKey, streamPublicKey);
482
- const { tokenProgramId } = await getMintAndProgram(this.connection, streamData.mint);
483
- const partnerPublicKey = streamData.partner;
490
+ const streamData = decodeStream(escrowAcc.data);
491
+ const { sender, recipient, mint, streamflowTreasury, partner, escrowTokens } = streamData;
492
+ const { tokenProgramId } = await getMintAndProgram(this.connection, mint);
484
493
  const ixs = prepareBaseInstructions(this.connection, {
485
494
  computePrice,
486
495
  computeLimit: computeLimit ?? ALIGNED_COMPUTE_LIMIT,
487
496
  });
488
- await this.checkAssociatedTokenAccounts(streamData, { invoker, checkTokenAccounts }, ixs, tokenProgramId);
497
+ const ataIx = await this.getCreateATAInstructions([sender, recipient, partner, streamflowTreasury], mint, invoker, checkTokenAccounts, tokenProgramId);
489
498
  const cancelIx = await this.alignedProxyProgram.methods
490
499
  .cancel()
491
500
  .accountsPartial({
501
+ mint,
502
+ partner,
503
+ recipient,
504
+ escrowTokens,
492
505
  sender: invoker.publicKey,
493
506
  streamMetadata: streamPublicKey,
494
- escrowTokens: escrowPDA,
495
- recipient: streamData.recipient,
496
- partner: partnerPublicKey,
497
507
  streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
498
- mint: streamData.mint,
499
508
  tokenProgram: tokenProgramId,
500
509
  streamflowProgram: this.programId,
501
510
  })
502
511
  .instruction();
503
- ixs.push(cancelIx);
512
+ ixs.push(...ataIx, cancelIx);
504
513
  return ixs;
505
514
  }
506
515
  /**
@@ -515,28 +524,29 @@ export class SolanaStreamClient extends BaseStreamClient {
515
524
  if (!escrowAcc?.data) {
516
525
  throw new Error("Couldn't get account info");
517
526
  }
518
- const data = decodeStream(escrowAcc?.data);
519
- const { tokenProgramId } = await getMintAndProgram(this.connection, data.mint);
520
- const streamflowTreasuryTokens = await ata(data.mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
521
- const partnerTokens = await ata(data.mint, data.partner, tokenProgramId);
527
+ const data = decodeStream(escrowAcc.data);
528
+ const { sender, recipient, partner, streamflowTreasury, mint, senderTokens, recipientTokens, escrowTokens } = data;
529
+ const { tokenProgramId } = await getMintAndProgram(this.connection, mint);
530
+ const streamflowTreasuryTokens = await ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
531
+ const partnerTokens = await ata(mint, partner, tokenProgramId);
522
532
  const ixs = prepareBaseInstructions(this.connection, {
523
533
  computePrice,
524
534
  computeLimit,
525
535
  });
526
- await this.checkAssociatedTokenAccounts(data, { invoker, checkTokenAccounts }, ixs, tokenProgramId);
527
- ixs.push(cancelStreamInstruction(this.programId, {
536
+ const ixsAta = await this.getCreateATAInstructions([sender, recipient, partner, streamflowTreasury], mint, invoker, checkTokenAccounts, tokenProgramId);
537
+ ixs.push(...ixsAta, cancelStreamInstruction(this.programId, {
538
+ sender,
539
+ senderTokens,
540
+ recipient,
541
+ recipientTokens,
542
+ streamflowTreasuryTokens,
543
+ partner,
544
+ partnerTokens,
545
+ mint,
546
+ escrowTokens,
528
547
  authority: invoker.publicKey,
529
- sender: data.sender,
530
- senderTokens: data.senderTokens,
531
- recipient: data.recipient,
532
- recipientTokens: data.recipientTokens,
533
548
  metadata: streamPublicKey,
534
- escrowTokens: data.escrowTokens,
535
549
  streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
536
- streamflowTreasuryTokens: streamflowTreasuryTokens,
537
- partner: data.partner,
538
- partnerTokens,
539
- mint: data.mint,
540
550
  tokenProgram: tokenProgramId,
541
551
  }));
542
552
  return ixs;
@@ -678,7 +688,7 @@ export class SolanaStreamClient extends BaseStreamClient {
678
688
  streamAccounts.forEach((account, index) => {
679
689
  if (account) {
680
690
  const alignedData = alignedOutgoingProgramAccounts[index].account;
681
- streams[alignedData.sender.toBase58()] = new AlignedContract(decodeStream(account.data), alignedData);
691
+ streams[streamPubKeys[index].toBase58()] = new AlignedContract(decodeStream(account.data), alignedData);
682
692
  }
683
693
  });
684
694
  return streams;
@@ -840,18 +850,14 @@ export class SolanaStreamClient extends BaseStreamClient {
840
850
  return senderPublicKey.equals(pda);
841
851
  }
842
852
  /**
843
- * Utility function that checks whether associated token accounts still exist and adds instructions to add them if not
853
+ * Returns insrtuctions for creating associated token accounts for the provided owners
844
854
  */
845
- async checkAssociatedTokenAccounts(data, { invoker, checkTokenAccounts }, ixs, programId) {
855
+ async getCreateATAInstructions(owners, mint, invoker, checkTokenAccounts, programId) {
846
856
  if (!checkTokenAccounts) {
847
- return;
848
- }
849
- const owners = Array.from(new Set([
850
- data.sender.toBase58(),
851
- data.recipient.toBase58(),
852
- data.partner.toBase58(),
853
- data.streamflowTreasury.toBase58(),
854
- ]), (address) => new PublicKey(address));
855
- ixs.push(...(await checkOrCreateAtaBatch(this.connection, owners, data.mint, invoker, programId)));
857
+ return [];
858
+ }
859
+ // filter out duplicate PublicKeys, otherwise transaction will fail
860
+ const uniqueOwners = Array.from(new Set(owners.map((owner) => owner.toBase58()))).map((pkString) => new PublicKey(pkString));
861
+ return checkOrCreateAtaBatch(this.connection, uniqueOwners, mint, invoker, programId);
856
862
  }
857
863
  }
@@ -3,7 +3,7 @@ import { PublicKey } from "@solana/web3.js";
3
3
  import { Buffer } from "buffer";
4
4
  import { ISearchStreams } from "./types.js";
5
5
  export declare const TX_FINALITY_CONFIRMED = "confirmed";
6
- export declare const ORIGINAL_CONTRACT_SENDER_OFFSET = 16;
6
+ export declare const ORIGINAL_CONTRACT_SENDER_OFFSET = 9;
7
7
  export declare const STREAM_STRUCT_OFFSET_SENDER = 49;
8
8
  export declare const STREAM_STRUCT_OFFSET_RECIPIENT = 113;
9
9
  export declare const STREAM_STRUCT_OFFSET_MINT = 177;
@@ -2,7 +2,7 @@ import { PublicKey } from "@solana/web3.js";
2
2
  import { Buffer } from "buffer";
3
3
  import { ICluster, SolanaContractErrorCode, SolanaAlignedProxyErrorCode } from "../common/types.js";
4
4
  export const TX_FINALITY_CONFIRMED = "confirmed";
5
- export const ORIGINAL_CONTRACT_SENDER_OFFSET = 16;
5
+ export const ORIGINAL_CONTRACT_SENDER_OFFSET = 9;
6
6
  export const STREAM_STRUCT_OFFSET_SENDER = 49;
7
7
  export const STREAM_STRUCT_OFFSET_RECIPIENT = 113;
8
8
  export const STREAM_STRUCT_OFFSET_MINT = 177;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "7.0.0-alpha.13",
3
+ "version": "7.0.0-alpha.15",
4
4
  "description": "JavaScript SDK to interact with Streamflow protocol.",
5
5
  "homepage": "https://github.com/streamflow-finance/js-sdk/",
6
6
  "main": "./dist/esm/index.js",
@@ -42,9 +42,9 @@
42
42
  "lint": "eslint --fix .",
43
43
  "prepublishOnly": "npm run lint && npm test && npm run build"
44
44
  },
45
- "gitHead": "1fe1f2d828e28cfd9e842bb4dd47c9756a39404f",
45
+ "gitHead": "04676451f16e1bed8f195651eabe4b3558143ee3",
46
46
  "devDependencies": {
47
- "@streamflow/eslint-config": "7.0.0-alpha.13",
47
+ "@streamflow/eslint-config": "7.0.0-alpha.15",
48
48
  "@types/bn.js": "5.1.1",
49
49
  "@types/ethereum-checksum-address": "^0.0.0",
50
50
  "date-fns": "2.28.0",
@@ -59,7 +59,7 @@
59
59
  "@solana/spl-token": "0.3.6",
60
60
  "@solana/wallet-adapter-base": "0.9.19",
61
61
  "@solana/web3.js": "1.90.2",
62
- "@streamflow/common": "7.0.0-alpha.13",
62
+ "@streamflow/common": "7.0.0-alpha.15",
63
63
  "@suiet/wallet-kit": "0.2.22",
64
64
  "aptos": "1.21.0",
65
65
  "bn.js": "5.2.1",