@streamflow/stream 7.0.0-alpha.9 → 7.0.1

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.
Files changed (61) hide show
  1. package/README.md +22 -17
  2. package/dist/cjs/__tests__/aptos/streamClient.spec.js +4 -4
  3. package/dist/cjs/aptos/types.js +12 -12
  4. package/dist/cjs/aptos/utils.js +2 -3
  5. package/dist/cjs/common/constants.js +4 -3
  6. package/dist/cjs/common/contractUtils.js +23 -7
  7. package/dist/cjs/common/types.js +30 -1
  8. package/dist/cjs/common/utils.js +23 -20
  9. package/dist/cjs/evm/StreamClient.js +7 -7
  10. package/dist/cjs/evm/types.js +12 -12
  11. package/dist/cjs/evm/utils.js +1 -2
  12. package/dist/cjs/solana/StreamClient.js +399 -152
  13. package/dist/cjs/solana/constants.js +29 -1
  14. package/dist/cjs/solana/descriptor/idl/streamflow_aligned_unlocks.json +1471 -0
  15. package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.js +2 -0
  16. package/dist/cjs/solana/index.js +2 -1
  17. package/dist/cjs/solana/instructions.js +18 -19
  18. package/dist/cjs/solana/lib/derive-accounts.js +17 -0
  19. package/dist/cjs/solana/{utils.js → lib/utils.js} +32 -39
  20. package/dist/cjs/solana/types.js +26 -3
  21. package/dist/cjs/sui/StreamClient.js +1 -1
  22. package/dist/cjs/sui/types.js +12 -12
  23. package/dist/cjs/sui/utils.js +1 -2
  24. package/dist/cjs/sui/wallet.js +2 -2
  25. package/dist/esm/__tests__/aptos/streamClient.spec.js +4 -4
  26. package/dist/esm/aptos/types.d.ts +14 -14
  27. package/dist/esm/aptos/types.js +13 -13
  28. package/dist/esm/common/constants.d.ts +3 -2
  29. package/dist/esm/common/constants.js +3 -2
  30. package/dist/esm/common/contractUtils.d.ts +18 -15
  31. package/dist/esm/common/contractUtils.js +19 -6
  32. package/dist/esm/common/types.d.ts +112 -57
  33. package/dist/esm/common/types.js +29 -0
  34. package/dist/esm/common/utils.d.ts +11 -11
  35. package/dist/esm/common/utils.js +19 -16
  36. package/dist/esm/evm/StreamClient.d.ts +2 -2
  37. package/dist/esm/evm/StreamClient.js +7 -7
  38. package/dist/esm/evm/types.d.ts +14 -14
  39. package/dist/esm/evm/types.js +13 -13
  40. package/dist/esm/solana/StreamClient.d.ts +27 -16
  41. package/dist/esm/solana/StreamClient.js +402 -154
  42. package/dist/esm/solana/constants.d.ts +14 -1
  43. package/dist/esm/solana/constants.js +29 -1
  44. package/dist/esm/solana/descriptor/idl/streamflow_aligned_unlocks.json +1471 -0
  45. package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.d.ts +1272 -0
  46. package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.js +1 -0
  47. package/dist/esm/solana/index.d.ts +2 -1
  48. package/dist/esm/solana/index.js +2 -1
  49. package/dist/esm/solana/instructions.d.ts +17 -17
  50. package/dist/esm/solana/instructions.js +18 -19
  51. package/dist/esm/solana/layout.d.ts +0 -1
  52. package/dist/esm/solana/lib/derive-accounts.d.ts +4 -0
  53. package/dist/esm/solana/lib/derive-accounts.js +11 -0
  54. package/dist/esm/solana/{utils.d.ts → lib/utils.d.ts} +1 -4
  55. package/dist/esm/solana/{utils.js → lib/utils.js} +28 -34
  56. package/dist/esm/solana/types.d.ts +67 -40
  57. package/dist/esm/solana/types.js +32 -4
  58. package/dist/esm/sui/StreamClient.js +1 -1
  59. package/dist/esm/sui/types.d.ts +14 -14
  60. package/dist/esm/sui/types.js +13 -13
  61. package/package.json +11 -9
@@ -1,24 +1,30 @@
1
1
  // Latest version of the SDK that does not use Anchor. It supports raw instructions.
2
- import BigNumber from "bignumber.js";
2
+ import BN from "bn.js";
3
3
  import { Buffer } from "buffer";
4
4
  import { ASSOCIATED_TOKEN_PROGRAM_ID, NATIVE_MINT } from "@solana/spl-token";
5
5
  import { Connection, Keypair, PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY, TransactionMessage, VersionedTransaction, } from "@solana/web3.js";
6
6
  import { ata, checkOrCreateAtaBatch, signAndExecuteTransaction, getProgramAccounts, prepareWrappedAccount, prepareTransaction, prepareBaseInstructions, getMintAndProgram, executeTransaction, executeMultipleTransactions, buildSendThrottler, } from "@streamflow/common/solana";
7
7
  import * as borsh from "borsh";
8
- import { Contract, } from "./types.js";
9
- import { decodeStream, extractSolanaErrorCode, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, } from "./utils.js";
10
- import { PROGRAM_ID, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, TX_FINALITY_CONFIRMED, WITHDRAWOR_PUBLIC_KEY, FEE_ORACLE_PUBLIC_KEY, DEFAULT_STREAMFLOW_FEE, PARTNER_ORACLE_PROGRAM_ID, FEES_METADATA_SEED, PARTNERS_SCHEMA, STREAM_STRUCT_OFFSETS, } from "./constants.js";
8
+ import { Program } from "@coral-xyz/anchor";
9
+ import { getBN } from "@streamflow/common";
10
+ import { Contract, AlignedContract, } from "./types.js";
11
+ import { decodeStream, extractSolanaErrorCode, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, } from "./lib/utils.js";
12
+ import { PROGRAM_ID, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, TX_FINALITY_CONFIRMED, WITHDRAWOR_PUBLIC_KEY, FEE_ORACLE_PUBLIC_KEY, DEFAULT_STREAMFLOW_FEE, PARTNER_ORACLE_PROGRAM_ID, FEES_METADATA_SEED, PARTNERS_SCHEMA, STREAM_STRUCT_OFFSETS, ORIGINAL_CONTRACT_SENDER_OFFSET, ALIGNED_PRECISION_FACTOR_POW, ALIGNED_COMPUTE_LIMIT, } from "./constants.js";
11
13
  import { withdrawStreamInstruction, cancelStreamInstruction, transferStreamInstruction, topupStreamInstruction, createStreamInstruction, createUncheckedStreamInstruction, updateStreamInstruction, } from "./instructions.js";
12
14
  import { ICluster, StreamDirection, StreamType, } from "../common/types.js";
13
15
  import { BaseStreamClient } from "../common/BaseStreamClient.js";
14
16
  import { calculateTotalAmountToDeposit } from "../common/utils.js";
15
17
  import { WITHDRAW_AVAILABLE_AMOUNT } from "../common/constants.js";
18
+ import StreamflowAlignedUnlocksIDL from "./descriptor/idl/streamflow_aligned_unlocks.json";
19
+ import { deriveContractPDA, deriveEscrowPDA, deriveTestOraclePDA } from "./lib/derive-accounts.js";
20
+ import { isCreateAlignedStreamData } from "../common/contractUtils.js";
16
21
  const METADATA_ACC_SIZE = 1104;
17
22
  export class SolanaStreamClient extends BaseStreamClient {
18
23
  connection;
19
24
  programId;
20
25
  commitment;
21
26
  sendThrottler;
27
+ alignedProxyProgram;
22
28
  /**
23
29
  * Create Stream instance
24
30
  */
@@ -28,6 +34,11 @@ export class SolanaStreamClient extends BaseStreamClient {
28
34
  this.connection = new Connection(clusterUrl, this.commitment);
29
35
  this.programId = programId !== "" ? new PublicKey(programId) : new PublicKey(PROGRAM_ID[cluster]);
30
36
  this.sendThrottler = sendThrottler ?? buildSendThrottler(sendRate);
37
+ const alignedUnlocksProgram = {
38
+ ...StreamflowAlignedUnlocksIDL,
39
+ address: StreamflowAlignedUnlocksIDL.address,
40
+ };
41
+ this.alignedProxyProgram = new Program(alignedUnlocksProgram, { connection: this.connection });
31
42
  }
32
43
  getConnection() {
33
44
  return this.connection;
@@ -43,7 +54,23 @@ export class SolanaStreamClient extends BaseStreamClient {
43
54
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
44
55
  */
45
56
  async create(data, extParams) {
46
- const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(data, extParams);
57
+ const { partner, amount } = data;
58
+ const { isNative, sender } = extParams;
59
+ const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
60
+ const mintPublicKey = new PublicKey(data.tokenId);
61
+ if (!sender.publicKey) {
62
+ throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
63
+ }
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);
67
+ if (isNative) {
68
+ const totalFee = await this.getTotalFee({
69
+ address: partnerPublicKey.toString(),
70
+ });
71
+ const totalAmount = calculateTotalAmountToDeposit(amount, totalFee);
72
+ ixs.push(...(await prepareWrappedAccount(this.connection, sender.publicKey, totalAmount)));
73
+ }
47
74
  const { tx, hash, context } = await prepareTransaction(this.connection, ixs, extParams.sender.publicKey, undefined, metadata);
48
75
  const signature = await signAndExecuteTransaction(this.connection, extParams.sender, tx, {
49
76
  hash,
@@ -52,11 +79,81 @@ export class SolanaStreamClient extends BaseStreamClient {
52
79
  }, { sendThrottler: this.sendThrottler });
53
80
  return { ixs, txId: signature, metadataId: metadataPubKey.toBase58() };
54
81
  }
82
+ async prepareCreateInstructions(streamParams, extParams) {
83
+ const { ixs, metadata, metadataPubKey } = isCreateAlignedStreamData(streamParams)
84
+ ? await this.prepareCreateAlignedUnlockInstructions(streamParams, extParams)
85
+ : await this.prepareCreateStreamInstructions(streamParams, extParams);
86
+ return { ixs, metadata, metadataPubKey };
87
+ }
88
+ async prepareCreateAlignedUnlockInstructions(streamParams, extParams) {
89
+ const { tokenId: mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, partner, recipient, cliffAmount, amountPerPeriod, amount: depositedAmount, name: streamName, minPrice, maxPercentage, minPercentage, maxPrice, skipInitial, tickSize, priceOracle, oracleType, } = streamParams;
90
+ const { isNative, sender, computeLimit, computePrice, metadataPubKeys } = extParams;
91
+ if (!sender.publicKey) {
92
+ throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
93
+ }
94
+ if (!priceOracle && oracleType && oracleType !== "none") {
95
+ throw new Error("Price oracle is required for the specified oracle type");
96
+ }
97
+ const recipientPublicKey = new PublicKey(recipient);
98
+ const mintPublicKey = isNative ? NATIVE_MINT : new PublicKey(mint);
99
+ const metadata = !metadataPubKeys ? Keypair.generate() : undefined;
100
+ const metadataPubKey = metadata ? metadata.publicKey : metadataPubKeys[0];
101
+ const { tokenProgramId } = await getMintAndProgram(this.connection, mintPublicKey);
102
+ const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
103
+ const streamflowProgramPublicKey = new PublicKey(this.programId);
104
+ const escrowPDA = deriveEscrowPDA(streamflowProgramPublicKey, metadataPubKey);
105
+ const oracle = priceOracle ?? deriveTestOraclePDA(this.alignedProxyProgram.programId, mintPublicKey, sender.publicKey);
106
+ const ixs = prepareBaseInstructions(this.connection, {
107
+ computePrice,
108
+ computeLimit: computeLimit ?? ALIGNED_COMPUTE_LIMIT,
109
+ });
110
+ ixs.push(...(await this.getCreateATAInstructions([recipientPublicKey], mintPublicKey, sender, true, tokenProgramId)));
111
+ const encodedUIntArray = new TextEncoder().encode(streamName);
112
+ const streamNameArray = Array.from(encodedUIntArray);
113
+ const createIx = await this.alignedProxyProgram.methods
114
+ .create({
115
+ startTime: new BN(start),
116
+ netAmountDeposited: depositedAmount,
117
+ period: new BN(period),
118
+ amountPerPeriod: amountPerPeriod,
119
+ cliff: new BN(cliff),
120
+ cliffAmount: cliffAmount,
121
+ transferableBySender,
122
+ transferableByRecipient,
123
+ cancelableByRecipient,
124
+ cancelableBySender,
125
+ canTopup,
126
+ oracleType: (!!oracleType ? { [oracleType]: {} } : { none: {} }),
127
+ streamName: streamNameArray,
128
+ minPrice: getBN(minPrice, ALIGNED_PRECISION_FACTOR_POW),
129
+ maxPrice: getBN(maxPrice, ALIGNED_PRECISION_FACTOR_POW),
130
+ minPercentage: getBN(minPercentage, ALIGNED_PRECISION_FACTOR_POW),
131
+ maxPercentage: getBN(maxPercentage, ALIGNED_PRECISION_FACTOR_POW),
132
+ tickSize: new BN(tickSize || 1),
133
+ skipInitial: skipInitial ?? false,
134
+ })
135
+ .accountsPartial({
136
+ sender: sender.publicKey,
137
+ streamMetadata: metadataPubKey,
138
+ escrowTokens: escrowPDA,
139
+ mint: mintPublicKey,
140
+ partner: partnerPublicKey,
141
+ recipient: recipientPublicKey,
142
+ withdrawor: WITHDRAWOR_PUBLIC_KEY,
143
+ feeOracle: FEE_ORACLE_PUBLIC_KEY,
144
+ priceOracle: oracle,
145
+ tokenProgram: tokenProgramId,
146
+ streamflowProgram: this.programId,
147
+ })
148
+ .instruction();
149
+ ixs.push(createIx);
150
+ return { ixs, metadata, metadataPubKey };
151
+ }
55
152
  /**
56
153
  * Creates a new stream/vesting contract.
57
154
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
58
155
  */
59
- async prepareCreateInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canPause, canUpdateRate, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal = false, withdrawalFrequency = 0, partner, }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
156
+ async prepareCreateStreamInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canPause, canUpdateRate, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal = false, withdrawalFrequency = 0, partner, }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
60
157
  if (!sender.publicKey) {
61
158
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
62
159
  }
@@ -74,20 +171,13 @@ export class SolanaStreamClient extends BaseStreamClient {
74
171
  const streamflowTreasuryTokens = await ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
75
172
  const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
76
173
  const partnerTokens = await ata(mintPublicKey, partnerPublicKey, tokenProgramId);
77
- if (isNative) {
78
- const totalFee = await this.getTotalFee({
79
- address: partner ?? sender.publicKey.toBase58(),
80
- });
81
- const totalAmount = calculateTotalAmountToDeposit(depositedAmount, totalFee);
82
- ixs.push(...(await prepareWrappedAccount(this.connection, sender.publicKey, totalAmount)));
83
- }
84
174
  ixs.push(createStreamInstruction({
85
- start: BigNumber(start),
175
+ start: new BN(start),
86
176
  depositedAmount,
87
- period: BigNumber(period),
177
+ period: new BN(period),
88
178
  amountPerPeriod,
89
- cliff: BigNumber(cliff),
90
- cliffAmount: BigNumber(cliffAmount),
179
+ cliff: new BN(cliff),
180
+ cliffAmount: new BN(cliffAmount),
91
181
  cancelableBySender,
92
182
  cancelableByRecipient,
93
183
  automaticWithdrawal,
@@ -97,7 +187,7 @@ export class SolanaStreamClient extends BaseStreamClient {
97
187
  canUpdateRate: !!canUpdateRate,
98
188
  canPause: !!canPause,
99
189
  name,
100
- withdrawFrequency: BigNumber(automaticWithdrawal ? withdrawalFrequency : period),
190
+ withdrawFrequency: new BN(automaticWithdrawal ? withdrawalFrequency : period),
101
191
  }, this.programId, {
102
192
  sender: sender.publicKey,
103
193
  senderTokens,
@@ -167,17 +257,17 @@ export class SolanaStreamClient extends BaseStreamClient {
167
257
  computeLimit,
168
258
  });
169
259
  if (isNative) {
170
- const totalFee = await this.getTotalFee({ address: partner ?? sender.publicKey.toBase58() });
260
+ const totalFee = await this.getTotalFee({ address: partnerPublicKey.toString() });
171
261
  const totalAmount = calculateTotalAmountToDeposit(depositedAmount, totalFee);
172
262
  ixs.push(...(await prepareWrappedAccount(this.connection, sender.publicKey, totalAmount)));
173
263
  }
174
264
  const createInstruction = createUncheckedStreamInstruction({
175
- start: BigNumber(start),
265
+ start: new BN(start),
176
266
  depositedAmount,
177
- period: BigNumber(period),
267
+ period: new BN(period),
178
268
  amountPerPeriod,
179
- cliff: BigNumber(cliff),
180
- cliffAmount: BigNumber(cliffAmount),
269
+ cliff: new BN(cliff),
270
+ cliffAmount: new BN(cliffAmount),
181
271
  cancelableBySender,
182
272
  cancelableByRecipient,
183
273
  automaticWithdrawal,
@@ -187,7 +277,7 @@ export class SolanaStreamClient extends BaseStreamClient {
187
277
  canUpdateRate: !!canUpdateRate,
188
278
  canPause: !!canPause,
189
279
  name,
190
- withdrawFrequency: BigNumber(automaticWithdrawal ? withdrawalFrequency : period),
280
+ withdrawFrequency: new BN(automaticWithdrawal ? withdrawalFrequency : period),
191
281
  recipient: recipientPublicKey,
192
282
  partner: partnerPublicKey,
193
283
  }, this.programId, {
@@ -210,26 +300,34 @@ export class SolanaStreamClient extends BaseStreamClient {
210
300
  * Creates multiple stream/vesting contracts.
211
301
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
212
302
  */
213
- async createMultiple(data, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
214
- const { recipients } = data;
215
- if (!sender.publicKey) {
216
- throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
217
- }
303
+ async createMultiple(data, extParams) {
304
+ const { recipients, ...streamParams } = data;
305
+ const { sender, metadataPubKeys: metadataPubKeysExt, isNative, computePrice, computeLimit } = extParams;
218
306
  const metadatas = [];
219
307
  const metadataToRecipient = {};
220
308
  const errors = [];
221
309
  const signatures = [];
222
310
  const batch = [];
223
311
  const instructionsBatch = [];
224
- metadataPubKeys = metadataPubKeys || [];
312
+ const metadataPubKeys = metadataPubKeysExt || [];
313
+ const partnerPublicKey = data.partner ? new PublicKey(data.partner) : WITHDRAWOR_PUBLIC_KEY;
314
+ const mintPublicKey = new PublicKey(data.tokenId);
315
+ if (recipients.length === 0) {
316
+ throw new Error("Recipients array is empty!");
317
+ }
318
+ if (!sender.publicKey) {
319
+ throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
320
+ }
225
321
  for (let i = 0; i < recipients.length; i++) {
226
322
  const recipientData = recipients[i];
227
- const { ixs, metadata, metadataPubKey } = await this.prepareStreamInstructions(recipientData, data, {
323
+ const createStreamData = { ...streamParams, ...recipientData };
324
+ const createStreamExtParams = {
228
325
  sender,
229
326
  metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : undefined,
230
327
  computePrice,
231
328
  computeLimit,
232
- });
329
+ };
330
+ const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(createStreamData, createStreamExtParams);
233
331
  metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
234
332
  metadatas.push(metadataPubKey.toBase58());
235
333
  instructionsBatch.push({
@@ -251,13 +349,17 @@ export class SolanaStreamClient extends BaseStreamClient {
251
349
  }
252
350
  batch.push({ tx, recipient });
253
351
  }
352
+ const prepareInstructions = await this.getCreateATAInstructions([STREAMFLOW_TREASURY_PUBLIC_KEY, partnerPublicKey], mintPublicKey, sender, true);
254
353
  if (isNative) {
255
- const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.plus(acc), BigNumber(0));
354
+ const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new BN(0));
256
355
  const nativeInstructions = await prepareWrappedAccount(this.connection, sender.publicKey, totalDepositedAmount);
356
+ prepareInstructions.push(...nativeInstructions);
357
+ }
358
+ if (prepareInstructions.length > 0) {
257
359
  const messageV0 = new TransactionMessage({
258
360
  payerKey: sender.publicKey,
259
361
  recentBlockhash: hash.blockhash,
260
- instructions: nativeInstructions,
362
+ instructions: prepareInstructions,
261
363
  }).compileToV0Message();
262
364
  const tx = new VersionedTransaction(messageV0);
263
365
  batch.push({
@@ -266,7 +368,7 @@ export class SolanaStreamClient extends BaseStreamClient {
266
368
  });
267
369
  }
268
370
  const signedBatch = await signAllTransactionWithRecipients(sender, batch);
269
- if (isNative) {
371
+ if (prepareInstructions.length > 0) {
270
372
  const prepareTx = signedBatch.pop();
271
373
  await sendAndConfirmStreamRawTransaction(this.connection, prepareTx, { hash, context }, { sendThrottler: this.sendThrottler });
272
374
  }
@@ -300,6 +402,102 @@ export class SolanaStreamClient extends BaseStreamClient {
300
402
  });
301
403
  return { txs: signatures, metadatas, metadataToRecipient, errors };
302
404
  }
405
+ /**
406
+ * Creates multiple stream/vesting contracts, and send all transactions sequentially.
407
+ * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
408
+ */
409
+ async createMultipleSequential(data, extParams) {
410
+ const { recipients, ...streamParams } = data;
411
+ const { sender, metadataPubKeys: metadataPubKeysExt, isNative, computePrice, computeLimit } = extParams;
412
+ const metadatas = [];
413
+ const metadataToRecipient = {};
414
+ const errors = [];
415
+ const signatures = [];
416
+ const batch = [];
417
+ const instructionsBatch = [];
418
+ const metadataPubKeys = metadataPubKeysExt || [];
419
+ const partnerPublicKey = data.partner ? new PublicKey(data.partner) : WITHDRAWOR_PUBLIC_KEY;
420
+ const mintPublicKey = new PublicKey(data.tokenId);
421
+ if (recipients.length === 0) {
422
+ throw new Error("Recipients array is empty!");
423
+ }
424
+ if (!sender.publicKey) {
425
+ throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
426
+ }
427
+ for (let i = 0; i < recipients.length; i++) {
428
+ const recipientData = recipients[i];
429
+ const createStreamData = { ...streamParams, ...recipientData };
430
+ const createStreamExtParams = {
431
+ sender,
432
+ metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : undefined,
433
+ computePrice,
434
+ computeLimit,
435
+ };
436
+ const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(createStreamData, createStreamExtParams);
437
+ metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
438
+ metadatas.push(metadataPubKey.toBase58());
439
+ instructionsBatch.push({
440
+ ixs,
441
+ metadata,
442
+ recipient: recipientData.recipient,
443
+ });
444
+ }
445
+ const { value: hash, context } = await this.connection.getLatestBlockhashAndContext();
446
+ for (const { ixs, metadata, recipient } of instructionsBatch) {
447
+ const messageV0 = new TransactionMessage({
448
+ payerKey: sender.publicKey,
449
+ recentBlockhash: hash.blockhash,
450
+ instructions: ixs,
451
+ }).compileToV0Message();
452
+ const tx = new VersionedTransaction(messageV0);
453
+ if (metadata) {
454
+ tx.sign([metadata]);
455
+ }
456
+ batch.push({ tx, recipient });
457
+ }
458
+ const prepareInstructions = await this.getCreateATAInstructions([STREAMFLOW_TREASURY_PUBLIC_KEY, partnerPublicKey], mintPublicKey, sender, true);
459
+ if (isNative) {
460
+ const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new BN(0));
461
+ const nativeInstructions = await prepareWrappedAccount(this.connection, sender.publicKey, totalDepositedAmount);
462
+ prepareInstructions.push(...nativeInstructions);
463
+ }
464
+ if (prepareInstructions.length > 0) {
465
+ const messageV0 = new TransactionMessage({
466
+ payerKey: sender.publicKey,
467
+ recentBlockhash: hash.blockhash,
468
+ instructions: prepareInstructions,
469
+ }).compileToV0Message();
470
+ const tx = new VersionedTransaction(messageV0);
471
+ batch.push({
472
+ tx,
473
+ recipient: sender.publicKey.toBase58(),
474
+ });
475
+ }
476
+ const signedBatch = await signAllTransactionWithRecipients(sender, batch);
477
+ if (prepareInstructions.length > 0) {
478
+ const prepareTx = signedBatch.pop();
479
+ await sendAndConfirmStreamRawTransaction(this.connection, prepareTx, { hash, context }, { sendThrottler: this.sendThrottler });
480
+ }
481
+ const responses = [];
482
+ for (const batchTx of signedBatch) {
483
+ responses.push(...(await Promise.allSettled([
484
+ executeTransaction(this.connection, batchTx.tx, { hash, context }, { sendThrottler: this.sendThrottler }),
485
+ ])));
486
+ }
487
+ responses.forEach((item, index) => {
488
+ if (item.status === "fulfilled") {
489
+ signatures.push(item.value);
490
+ }
491
+ else {
492
+ errors.push({
493
+ recipient: signedBatch[index].recipient,
494
+ error: item.reason,
495
+ contractErrorCode: this.extractErrorCode(item.reason) || undefined,
496
+ });
497
+ }
498
+ });
499
+ return { txs: signatures, metadatas, metadataToRecipient, errors };
500
+ }
303
501
  /**
304
502
  * Attempts withdrawing from the specified stream.
305
503
  */
@@ -330,21 +528,22 @@ export class SolanaStreamClient extends BaseStreamClient {
330
528
  throw new Error("Couldn't get account info");
331
529
  }
332
530
  const data = decodeStream(escrow.data);
333
- const { tokenProgramId } = await getMintAndProgram(this.connection, data.mint);
334
- const streamflowTreasuryTokens = await ata(data.mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
335
- const partnerTokens = await ata(data.mint, data.partner, tokenProgramId);
336
- await this.checkAssociatedTokenAccounts(data, { invoker, checkTokenAccounts }, ixs, tokenProgramId);
337
- ixs.push(withdrawStreamInstruction(amount, this.programId, {
531
+ const { sender, recipient, mint, streamflowTreasury, partner, recipientTokens, escrowTokens } = data;
532
+ const { tokenProgramId } = await getMintAndProgram(this.connection, mint);
533
+ const streamflowTreasuryTokens = await ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
534
+ const partnerTokens = await ata(mint, partner, tokenProgramId);
535
+ const ataIx = await this.getCreateATAInstructions([sender, recipient, streamflowTreasury, partner], mint, invoker, checkTokenAccounts, tokenProgramId);
536
+ ixs.push(...ataIx, withdrawStreamInstruction(amount, this.programId, {
537
+ partner,
538
+ partnerTokens,
539
+ mint,
540
+ streamflowTreasuryTokens,
541
+ recipientTokens,
542
+ escrowTokens,
338
543
  authority: invoker.publicKey,
339
544
  recipient: invoker.publicKey,
340
- recipientTokens: data.recipientTokens,
341
545
  metadata: streamPublicKey,
342
- escrowTokens: data.escrowTokens,
343
546
  streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
344
- streamflowTreasuryTokens,
345
- partner: data.partner,
346
- partnerTokens,
347
- mint: data.mint,
348
547
  tokenProgram: tokenProgramId,
349
548
  }));
350
549
  return ixs;
@@ -352,8 +551,8 @@ export class SolanaStreamClient extends BaseStreamClient {
352
551
  /**
353
552
  * Attempts canceling the specified stream.
354
553
  */
355
- async cancel({ id }, extParams) {
356
- const ixs = await this.prepareCancelInstructions({ id }, extParams);
554
+ async cancel(cancelData, extParams) {
555
+ const ixs = await this.prepareCancelInstructions(cancelData, extParams);
357
556
  const { tx, hash, context } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
358
557
  const signature = await signAndExecuteTransaction(this.connection, extParams.invoker, tx, {
359
558
  hash,
@@ -362,10 +561,57 @@ export class SolanaStreamClient extends BaseStreamClient {
362
561
  }, { sendThrottler: this.sendThrottler });
363
562
  return { ixs, txId: signature };
364
563
  }
564
+ async prepareCancelInstructions(cancelData, extParams) {
565
+ const streamPublicKey = new PublicKey(cancelData.id);
566
+ const account = await this.connection.getAccountInfo(streamPublicKey);
567
+ if (!account) {
568
+ throw new Error("Impossible to cancel a stream contract that does not exist");
569
+ }
570
+ const { sender: senderPublicKey } = decodeStream(account.data);
571
+ const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, senderPublicKey);
572
+ const ixs = isAlignedUnlock
573
+ ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams)
574
+ : await this.prepareCancelStreamInstructions(cancelData, extParams);
575
+ return ixs;
576
+ }
577
+ async prepareCancelAlignedUnlockInstructions({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
578
+ if (!invoker.publicKey) {
579
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
580
+ }
581
+ const streamPublicKey = new PublicKey(id);
582
+ const escrowAcc = await this.connection.getAccountInfo(streamPublicKey);
583
+ if (!escrowAcc?.data) {
584
+ throw new Error("Couldn't get account info");
585
+ }
586
+ const streamData = decodeStream(escrowAcc.data);
587
+ const { sender, recipient, mint, streamflowTreasury, partner, escrowTokens } = streamData;
588
+ const { tokenProgramId } = await getMintAndProgram(this.connection, mint);
589
+ const ixs = prepareBaseInstructions(this.connection, {
590
+ computePrice,
591
+ computeLimit: computeLimit ?? ALIGNED_COMPUTE_LIMIT,
592
+ });
593
+ const ataIx = await this.getCreateATAInstructions([sender, recipient, partner, streamflowTreasury], mint, invoker, checkTokenAccounts, tokenProgramId);
594
+ const cancelIx = await this.alignedProxyProgram.methods
595
+ .cancel()
596
+ .accountsPartial({
597
+ mint,
598
+ partner,
599
+ recipient,
600
+ escrowTokens,
601
+ sender: invoker.publicKey,
602
+ streamMetadata: streamPublicKey,
603
+ streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
604
+ tokenProgram: tokenProgramId,
605
+ streamflowProgram: this.programId,
606
+ })
607
+ .instruction();
608
+ ixs.push(...ataIx, cancelIx);
609
+ return ixs;
610
+ }
365
611
  /**
366
612
  * Creates Transaction Instructions for cancel
367
613
  */
368
- async prepareCancelInstructions({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
614
+ async prepareCancelStreamInstructions({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
369
615
  if (!invoker.publicKey) {
370
616
  throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
371
617
  }
@@ -374,28 +620,29 @@ export class SolanaStreamClient extends BaseStreamClient {
374
620
  if (!escrowAcc?.data) {
375
621
  throw new Error("Couldn't get account info");
376
622
  }
377
- const data = decodeStream(escrowAcc?.data);
378
- const { tokenProgramId } = await getMintAndProgram(this.connection, data.mint);
379
- const streamflowTreasuryTokens = await ata(data.mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
380
- const partnerTokens = await ata(data.mint, data.partner, tokenProgramId);
623
+ const data = decodeStream(escrowAcc.data);
624
+ const { sender, recipient, partner, streamflowTreasury, mint, senderTokens, recipientTokens, escrowTokens } = data;
625
+ const { tokenProgramId } = await getMintAndProgram(this.connection, mint);
626
+ const streamflowTreasuryTokens = await ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
627
+ const partnerTokens = await ata(mint, partner, tokenProgramId);
381
628
  const ixs = prepareBaseInstructions(this.connection, {
382
629
  computePrice,
383
630
  computeLimit,
384
631
  });
385
- await this.checkAssociatedTokenAccounts(data, { invoker, checkTokenAccounts }, ixs, tokenProgramId);
386
- ixs.push(cancelStreamInstruction(this.programId, {
632
+ const ixsAta = await this.getCreateATAInstructions([sender, recipient, partner, streamflowTreasury], mint, invoker, checkTokenAccounts, tokenProgramId);
633
+ ixs.push(...ixsAta, cancelStreamInstruction(this.programId, {
634
+ sender,
635
+ senderTokens,
636
+ recipient,
637
+ recipientTokens,
638
+ streamflowTreasuryTokens,
639
+ partner,
640
+ partnerTokens,
641
+ mint,
642
+ escrowTokens,
387
643
  authority: invoker.publicKey,
388
- sender: data.sender,
389
- senderTokens: data.senderTokens,
390
- recipient: data.recipient,
391
- recipientTokens: data.recipientTokens,
392
644
  metadata: streamPublicKey,
393
- escrowTokens: data.escrowTokens,
394
645
  streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
395
- streamflowTreasuryTokens: streamflowTreasuryTokens,
396
- partner: data.partner,
397
- partnerTokens,
398
- mint: data.mint,
399
646
  tokenProgram: tokenProgramId,
400
647
  }));
401
648
  return ixs;
@@ -504,11 +751,56 @@ export class SolanaStreamClient extends BaseStreamClient {
504
751
  * Fetch stream data by its id (address).
505
752
  */
506
753
  async getOne({ id }) {
507
- const escrow = await this.connection.getAccountInfo(new PublicKey(id), TX_FINALITY_CONFIRMED);
754
+ const streamPublicKey = new PublicKey(id);
755
+ const escrow = await this.connection.getAccountInfo(streamPublicKey, TX_FINALITY_CONFIRMED);
508
756
  if (!escrow?.data) {
509
757
  throw new Error("Couldn't get account info.");
510
758
  }
511
- return new Contract(decodeStream(escrow?.data));
759
+ const stream = decodeStream(escrow.data);
760
+ if (this.isAlignedUnlock(streamPublicKey, stream.sender)) {
761
+ const alignedProxy = await this.alignedProxyProgram.account.contract.fetch(deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey));
762
+ if (!alignedProxy) {
763
+ throw new Error("Couldn't get proxy account info.");
764
+ }
765
+ return new AlignedContract(stream, alignedProxy);
766
+ }
767
+ return new Contract(stream);
768
+ }
769
+ /**
770
+ * Fetch all aligned outgoing streams/contracts by the provided public key.
771
+ */
772
+ async getOutgoingAlignedStreams(sender) {
773
+ const streams = {};
774
+ const alignedOutgoingProgramAccounts = await this.alignedProxyProgram.account.contract.all([
775
+ {
776
+ memcmp: {
777
+ offset: ORIGINAL_CONTRACT_SENDER_OFFSET,
778
+ bytes: sender,
779
+ },
780
+ },
781
+ ]);
782
+ const streamPubKeys = alignedOutgoingProgramAccounts.map((account) => account.account.stream);
783
+ const streamAccounts = await this.connection.getMultipleAccountsInfo(streamPubKeys, TX_FINALITY_CONFIRMED);
784
+ streamAccounts.forEach((account, index) => {
785
+ if (account) {
786
+ const alignedData = alignedOutgoingProgramAccounts[index].account;
787
+ streams[streamPubKeys[index].toBase58()] = new AlignedContract(decodeStream(account.data), alignedData);
788
+ }
789
+ });
790
+ return streams;
791
+ }
792
+ async getIncomingAlignedStreams(streamRecord) {
793
+ const streams = {};
794
+ const alignedStreamsPubKeys = Object.keys(streamRecord);
795
+ const alignedProxyPDAs = alignedStreamsPubKeys.map((streamPubKey) => deriveContractPDA(this.alignedProxyProgram.programId, new PublicKey(streamPubKey)));
796
+ const alignedProxyAccounts = await this.alignedProxyProgram.account.contract.fetchMultiple(alignedProxyPDAs);
797
+ alignedProxyAccounts.forEach((account, index) => {
798
+ if (account) {
799
+ const alignedData = streamRecord[alignedStreamsPubKeys[index]];
800
+ streams[alignedStreamsPubKeys[index]] = new AlignedContract(alignedData, account);
801
+ }
802
+ });
803
+ return streams;
512
804
  }
513
805
  /**
514
806
  * Fetch streams/contracts by providing direction.
@@ -516,24 +808,39 @@ export class SolanaStreamClient extends BaseStreamClient {
516
808
  */
517
809
  async get({ address, type = StreamType.All, direction = StreamDirection.All, }) {
518
810
  const publicKey = new PublicKey(address);
519
- let accounts = [];
520
- //todo: we need to be smart with our layout so we minimize rpc calls to the chain
521
- if (direction === "all") {
522
- const outgoingAccounts = await getProgramAccounts(this.connection, publicKey, STREAM_STRUCT_OFFSET_SENDER, this.programId);
523
- const incomingAccounts = await getProgramAccounts(this.connection, publicKey, STREAM_STRUCT_OFFSET_RECIPIENT, this.programId);
524
- accounts = [...outgoingAccounts, ...incomingAccounts];
811
+ let streams = {};
812
+ // don't do unnecessary rpc calls if we are not querying for vesting streams
813
+ const shouldFetchAligned = type === StreamType.All || type === StreamType.Vesting;
814
+ if (direction !== StreamDirection.Incoming) {
815
+ const outgoingStreamAccounts = await getProgramAccounts(this.connection, publicKey, STREAM_STRUCT_OFFSET_SENDER, this.programId);
816
+ outgoingStreamAccounts.forEach((account) => {
817
+ streams[account.pubkey.toBase58()] = new Contract(decodeStream(account.account.data));
818
+ });
819
+ if (shouldFetchAligned) {
820
+ const alignedStreams = await this.getOutgoingAlignedStreams(address);
821
+ streams = { ...streams, ...alignedStreams };
822
+ }
525
823
  }
526
- else {
527
- const offset = direction === "outgoing" ? STREAM_STRUCT_OFFSET_SENDER : STREAM_STRUCT_OFFSET_RECIPIENT;
528
- accounts = await getProgramAccounts(this.connection, publicKey, offset, this.programId);
824
+ if (direction !== StreamDirection.Outgoing) {
825
+ const allIncomingAccounts = await getProgramAccounts(this.connection, publicKey, STREAM_STRUCT_OFFSET_RECIPIENT, this.programId);
826
+ const allIncomingStreams = allIncomingAccounts.map((account) => decodeStream(account.account.data));
827
+ const alignedDecoded = {};
828
+ // filter out aligned unlocks and store them in a separate object
829
+ allIncomingAccounts.forEach((account, index) => {
830
+ if (this.isAlignedUnlock(account.pubkey, allIncomingStreams[index].sender)) {
831
+ alignedDecoded[account.pubkey.toBase58()] = allIncomingStreams[index];
832
+ }
833
+ else {
834
+ streams[account.pubkey.toBase58()] = new Contract(allIncomingStreams[index]);
835
+ }
836
+ });
837
+ if (shouldFetchAligned) {
838
+ const incomingAlignedStreams = await this.getIncomingAlignedStreams(alignedDecoded);
839
+ streams = { ...streams, ...incomingAlignedStreams };
840
+ }
529
841
  }
530
- let streams = {};
531
- accounts.forEach((account) => {
532
- const decoded = new Contract(decodeStream(account.account.data));
533
- streams = { ...streams, [account.pubkey.toBase58()]: decoded };
534
- });
535
842
  const sortedStreams = Object.entries(streams).sort(([, stream1], [, stream2]) => stream2.start - stream1.start);
536
- if (type === "all")
843
+ if (type === StreamType.All)
537
844
  return sortedStreams;
538
845
  return sortedStreams.filter((stream) => stream[1].type === type);
539
846
  }
@@ -616,68 +923,6 @@ export class SolanaStreamClient extends BaseStreamClient {
616
923
  const logs = "logs" in err && Array.isArray(err.logs) ? err.logs : undefined;
617
924
  return extractSolanaErrorCode(err.toString() ?? "Unknown error!", logs);
618
925
  }
619
- /**
620
- * Forms instructions from params, creates a raw transaction and fetch recent blockhash.
621
- */
622
- async prepareStreamInstructions(recipient, streamParams, extParams) {
623
- const { tokenId: mint, start, period, cliff, canTopup, canUpdateRate, canPause, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal = false, withdrawalFrequency = 0, partner, } = streamParams;
624
- const { sender, metadataPubKeys, computeLimit, computePrice } = extParams;
625
- if (!sender.publicKey) {
626
- throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
627
- }
628
- const ixs = prepareBaseInstructions(this.connection, {
629
- computePrice,
630
- computeLimit,
631
- });
632
- const recipientPublicKey = new PublicKey(recipient.recipient);
633
- const mintPublicKey = new PublicKey(mint);
634
- const { metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys);
635
- const [escrowTokens] = PublicKey.findProgramAddressSync([Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId);
636
- const { tokenProgramId } = await getMintAndProgram(this.connection, mintPublicKey);
637
- const senderTokens = await ata(mintPublicKey, sender.publicKey, tokenProgramId);
638
- const recipientTokens = await ata(mintPublicKey, recipientPublicKey, tokenProgramId);
639
- const streamflowTreasuryTokens = await ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
640
- const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
641
- const partnerTokens = await ata(mintPublicKey, partnerPublicKey, tokenProgramId);
642
- ixs.push(createStreamInstruction({
643
- start: BigNumber(start),
644
- depositedAmount: recipient.amount,
645
- period: BigNumber(period),
646
- amountPerPeriod: recipient.amountPerPeriod,
647
- cliff: BigNumber(cliff),
648
- cliffAmount: BigNumber(recipient.cliffAmount),
649
- cancelableBySender,
650
- cancelableByRecipient,
651
- automaticWithdrawal,
652
- transferableBySender,
653
- transferableByRecipient,
654
- canTopup,
655
- canUpdateRate: !!canUpdateRate,
656
- canPause: !!canPause,
657
- name: recipient.name,
658
- withdrawFrequency: BigNumber(automaticWithdrawal ? withdrawalFrequency : period),
659
- }, this.programId, {
660
- sender: sender.publicKey,
661
- senderTokens,
662
- recipient: new PublicKey(recipient.recipient),
663
- metadata: metadataPubKey,
664
- escrowTokens,
665
- recipientTokens,
666
- streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
667
- streamflowTreasuryTokens: streamflowTreasuryTokens,
668
- partner: partnerPublicKey,
669
- partnerTokens: partnerTokens,
670
- mint: new PublicKey(mint),
671
- feeOracle: FEE_ORACLE_PUBLIC_KEY,
672
- rent: SYSVAR_RENT_PUBKEY,
673
- timelockProgram: this.programId,
674
- tokenProgram: tokenProgramId,
675
- associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
676
- withdrawor: WITHDRAWOR_PUBLIC_KEY,
677
- systemProgram: SystemProgram.programId,
678
- }));
679
- return { ixs, metadata, metadataPubKey };
680
- }
681
926
  /**
682
927
  * Utility function to generate metadata for a Contract or return existing Pubkey
683
928
  */
@@ -694,18 +939,21 @@ export class SolanaStreamClient extends BaseStreamClient {
694
939
  return { metadata, metadataPubKey };
695
940
  }
696
941
  /**
697
- * Utility function that checks whether associated token accounts still exist and adds instructions to add them if not
942
+ * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
698
943
  */
699
- async checkAssociatedTokenAccounts(data, { invoker, checkTokenAccounts }, ixs, programId) {
944
+ isAlignedUnlock(streamPublicKey, senderPublicKey) {
945
+ const pda = deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey);
946
+ return senderPublicKey.equals(pda);
947
+ }
948
+ /**
949
+ * Returns insrtuctions for creating associated token accounts for the provided owners
950
+ */
951
+ async getCreateATAInstructions(owners, mint, invoker, checkTokenAccounts, programId) {
700
952
  if (!checkTokenAccounts) {
701
- return;
702
- }
703
- const owners = Array.from(new Set([
704
- data.sender.toBase58(),
705
- data.recipient.toBase58(),
706
- data.partner.toBase58(),
707
- data.streamflowTreasury.toBase58(),
708
- ]), (address) => new PublicKey(address));
709
- ixs.push(...(await checkOrCreateAtaBatch(this.connection, owners, data.mint, invoker, programId)));
953
+ return [];
954
+ }
955
+ // filter out duplicate PublicKeys, otherwise transaction will fail
956
+ const uniqueOwners = Array.from(new Set(owners.map((owner) => owner.toBase58()))).map((pkString) => new PublicKey(pkString));
957
+ return checkOrCreateAtaBatch(this.connection, uniqueOwners, mint, invoker, programId);
710
958
  }
711
959
  }